From: Hannes Reinecke <hare@suse.de>
To: Yaohan Li <shunsheng1218@gmail.com>,
kbusch@kernel.org, axboe@kernel.dk, hch@lst.de, sagi@grimberg.me
Cc: jthumshirn@suse.de, mkp@kernel.org,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nvme: stop asynchronous event work before ANA teardown
Date: Tue, 10 Nov 2026 13:55:43 +0100 [thread overview]
Message-ID: <508595ec-0540-4534-afd4-44ef8ee01da6@suse.de> (raw)
In-Reply-To: <179378587000.73780.18152328009023418065@gmail.com>
On 11/4/26 10:51 AM, Yaohan Li wrote:
> nvme_mpath_stop() cancels ana_work, but the asynchronous event worker
> can enqueue ANA processing again while controller teardown is in
> progress. An ANA work item can therefore survive the final
> controller release and access freed memory.
>
> Cancel async_event_work during controller uninitialization, after the
> controller has stopped accepting new events, and cancel ana_work
> again before releasing its ANA resources. Draining only ana_work is
> not sufficient while the event worker can requeue it.
>
> The race was reproduced with the in-tree NVMe loop target and
> scheduling injection. Cancelling ANA work alone left reports; draining
> the event source and the ANA work together removed the reported
> use-after-free under the same test conditions.
>
> Fixes: 0d0b660f214dc ("nvme: add ANA support")
> Assisted-by: ZCode:GLM-4
> Signed-off-by: Yaohan Li <shunsheng1218@gmail.com>
> ---
> drivers/nvme/host/core.c | 9 +++++++++
> drivers/nvme/host/multipath.c | 7 +++++++
> 2 files changed, 16 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index a7a4d09644c13..017aae1189de1 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -5182,6 +5182,15 @@ EXPORT_SYMBOL_GPL(nvme_start_ctrl);
> void nvme_uninit_ctrl(struct nvme_ctrl *ctrl)
> {
> nvme_stop_keep_alive(ctrl);
> +
> + /*
> + * Stop the async event worker before the final put: it processes
> + * ANA change events by re-queueing ctrl->ana_work, which is
> + * embedded in ctrl and cancelled in nvme_free_ctrl(); a worker
> + * running past that point would re-queue it onto freed memory.
> + */
> + cancel_work_sync(&ctrl->async_event_work);
> +
> nvme_hwmon_exit(ctrl);
> nvme_fault_inject_fini(&ctrl->fault_inject);
> dev_pm_qos_hide_latency_tolerance(ctrl->device);
> diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
> index 9e0a0fd77c56e..44bd1a1ad5940 100644
> --- a/drivers/nvme/host/multipath.c
> +++ b/drivers/nvme/host/multipath.c
> @@ -1610,6 +1610,13 @@ int nvme_mpath_init_identify(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id)
>
> void nvme_mpath_uninit(struct nvme_ctrl *ctrl)
> {
> + /*
> + * nvme_mpath_stop() already cancelled ana_work, but an ANA async
> + * event completing after nvme_stop_ctrl() can have re-queued it.
> + * It is embedded in ctrl, which is freed after uninit.
> + */
> + cancel_work_sync(&ctrl->ana_work);
> +
> kvfree(ctrl->ana_log_buf);
> ctrl->ana_log_buf = NULL;
> ctrl->ana_log_size = 0;
Why can we schedule AENs when a controller teardown is active?
Shouldn't we rather disallow that instead of fixing the fallout?
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@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
prev parent reply other threads:[~2026-11-10 12:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 9:51 Yaohan Li
2026-11-05 7:55 ` Christoph Hellwig
2026-11-10 12:55 ` Hannes Reinecke [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=508595ec-0540-4534-afd4-44ef8ee01da6@suse.de \
--to=hare@suse.de \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=jthumshirn@suse.de \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=mkp@kernel.org \
--cc=sagi@grimberg.me \
--cc=shunsheng1218@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®