[PATCH V4 3/9] nvme: fix race condition between connected uevent and STARTED_ONCE flag
Hannes Reinecke
hare at suse.de
Mon May 11 02:47:30 PDT 2026
On 5/8/26 15:33, Maurizio Lombardi wrote:
> When a controller connects, nvme_start_ctrl() emits the
> "NVME_EVENT=connected" uevent and sets the NVME_CTRL_STARTED_ONCE flag.
> Currently, the uevent is emitted before the flag is set.
>
> This creates a race condition for userspace tools (like udev rules)
> that might rely on the "connected" event to configure sysfs attributes.
> Specifically, if a udev rule attempts to set the newly introduced
> `admin_timeout` attribute immediately after receiving the uevent,
> the sysfs store function might evaluate the NVME_CTRL_STARTED_ONCE
> bit before it is actually set, resulting in spurious -EBUSY error.
>
> Swap the order of operations in nvme_start_ctrl() so that the
> NVME_CTRL_STARTED_ONCE flag is set before the uevent is sent.
> This guarantees that the admin_timeout can already be changed
> when userspace is notified.
>
> Signed-off-by: Maurizio Lombardi <mlombard at redhat.com>
> ---
> drivers/nvme/host/core.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index b1bfcd0a0e5b..22be8cf5e982 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -5039,8 +5039,8 @@ void nvme_start_ctrl(struct nvme_ctrl *ctrl)
> nvme_mpath_update(ctrl);
> }
>
> - nvme_change_uevent(ctrl, "NVME_EVENT=connected");
> set_bit(NVME_CTRL_STARTED_ONCE, &ctrl->flags);
> + nvme_change_uevent(ctrl, "NVME_EVENT=connected");
> }
> EXPORT_SYMBOL_GPL(nvme_start_ctrl);
>
Reviewed-by: Hannes Reinecke <hare at kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list