All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: mr-083 <matthieu@minio.io>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, its@irrelevant.dk,
	kbusch@kernel.org, mr-083 <matthieu@min.io>
Subject: Re: [PATCH v4] hw/nvme: add namespace hotplug support
Date: Thu, 16 Apr 2026 15:42:34 -0400	[thread overview]
Message-ID: <20260416194234.GA258343@fedora> (raw)
In-Reply-To: <20260415173852.71135-1-matthieu@min.io>

[-- Attachment #1: Type: text/plain, Size: 2787 bytes --]

On Wed, Apr 15, 2026 at 07:38:52PM +0200, mr-083 wrote:
> Add hotplug support for nvme-ns devices on the NvmeBus. This enables
> NVMe namespace-level hot-add and hot-remove via device_add and
> device_del with proper Asynchronous Event Notification (AEN), so the
> guest kernel can react to namespace topology changes.
> 
> Mark nvme-ns devices as hotpluggable and register the NvmeBus as a
> hotplug handler with proper plug and unplug callbacks:
> 
> - plug: attach namespace to all started controllers and send an
>   Asynchronous Event Notification (AEN) with NS_ATTR_CHANGED so
>   the guest kernel rescans namespaces and adds the block device
> - unplug: drain in-flight I/O, detach from all controllers, send
>   AEN, then unrealize the device. The guest kernel rescans and
>   removes the block device.
> 
> The plug handler skips controllers that haven't started yet
> (qs_created == false) to avoid interfering with boot-time namespace
> attachment in nvme_start_ctrl().
> 
> The unplug handler drains in-flight I/O via nvme_ns_drain() before
> detaching the namespace from controllers, so pending requests can
> complete normally without touching freed state.
> 
> For symmetry with nvme_ns_realize() which sets subsys->namespaces[nsid],
> nvme_ns_unrealize() now clears that slot too making the namespace
> lifecycle complete.
> 
> Both the controller bus and subsystem bus are configured as hotplug
> handlers via qbus_set_bus_hotplug_handler() since nvme-ns devices
> may reparent to the subsystem bus during realize.
> 
> Example hot-swap sequence using the NVMe subsystem model:
> 
>   # Boot with: -device nvme-subsys,id=subsys0
>   #            -device nvme,id=ctrl0,subsys=subsys0
>   #            -device nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1
> 
>   device_del ns0             # guest receives AEN, removes /dev/nvme0n1
>   drive_del drv0
>   drive_add 0 file=disk.qcow2,format=qcow2,id=drv0,if=none
>   device_add nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1
>                               # guest receives AEN, adds /dev/nvme0n1
> 
> Tested with Linux 6.1 guest (NVMe driver processes AEN and rescans
> namespace list automatically).
> 
> Signed-off-by: Matthieu <matthieu@min.io>
> ---
>  hw/nvme/ctrl.c   | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/nvme/ns.c     |  8 +++++
>  hw/nvme/subsys.c |  2 ++
>  3 files changed, 98 insertions(+)

This is useful functionality because PCI hotplug is cumbersome as it
requires preallocating PCIe root ports at guest creation time. Users may
not know how many devices they will eventually hotplug, and so it's
convenient to hotplug multiple namespaces onto an existing NVMe PCI
controller.

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2026-04-16 19:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  6:01 [PATCH 0/2] NVMe namespace hotplug and drive reconnection support mr-083
2026-04-09  6:01 ` [PATCH 1/2] hw/nvme: add namespace hotplug support mr-083
2026-04-09  6:01 ` [PATCH 2/2] block/monitor: add drive_insert HMP command mr-083
2026-04-14 17:57   ` Stefan Hajnoczi
2026-04-14 18:02     ` Matthieu Rolla
2026-04-14 19:05       ` Warner Losh
2026-04-14 21:01         ` Matthieu Rolla
2026-04-15 10:48   ` Daniel P. Berrangé
2026-04-15 12:32     ` Matthieu Rolla
2026-04-16 19:52       ` Stefan Hajnoczi
2026-04-16 22:00         ` Matthieu Rolla
2026-04-15 12:33     ` Stefan Hajnoczi
2026-04-09 21:34 ` [PATCH v2] hw/nvme: add namespace hotplug support mr-083
2026-04-10 12:41   ` Stefan Hajnoczi
2026-04-10 14:30 ` [PATCH v3] " mr-083
2026-04-10 14:33   ` Matthieu Rolla
2026-04-10 20:14     ` Stefan Hajnoczi
2026-04-13 15:24       ` Matthieu Rolla
2026-04-13 17:17 ` [PATCH 0/2] NVMe namespace hotplug and drive reconnection support Klaus Jensen
2026-04-14 12:42   ` Stefan Hajnoczi
2026-04-14 13:36     ` Matthieu Rolla
2026-04-14 18:09       ` Keith Busch
2026-04-14 18:10       ` Stefan Hajnoczi
2026-04-14 18:14         ` Matthieu Rolla
2026-04-15 12:45           ` Stefan Hajnoczi
2026-04-15 17:39             ` Matthieu Rolla
2026-04-14 14:04     ` John Meneghini
2026-04-16 10:11       ` Nilay Shroff
2026-04-16 12:33         ` Matthieu Rolla
2026-04-14 14:42     ` Keith Busch
2026-04-15 17:38 ` [PATCH v4] hw/nvme: add namespace hotplug support mr-083
2026-04-16 19:42   ` Stefan Hajnoczi [this message]
2026-04-17  9:29   ` Klaus Jensen
2026-04-17  9:45     ` Matthieu Rolla

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=20260416194234.GA258343@fedora \
    --to=stefanha@redhat.com \
    --cc=its@irrelevant.dk \
    --cc=kbusch@kernel.org \
    --cc=matthieu@min.io \
    --cc=matthieu@minio.io \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.