Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.0/patches/2221321/?format=api
{ "id": 2221321, "url": "http://patchwork.ozlabs.org/api/1.0/patches/2221321/?format=api", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/1.0/projects/14/?format=api", "name": "QEMU Development", "link_name": "qemu-devel", "list_id": "qemu-devel.nongnu.org", "list_email": "qemu-devel@nongnu.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260409060155.94704-2-matthieu@min.io>", "date": "2026-04-09T06:01:53", "name": "[1/2] hw/nvme: add namespace hotplug support", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "089a6e1b9f1796a90356ea16f66613834e6a7dec", "submitter": { "id": 93098, "url": "http://patchwork.ozlabs.org/api/1.0/people/93098/?format=api", "name": "mr-083", "email": "matthieu@minio.io" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260409060155.94704-2-matthieu@min.io/mbox/", "series": [ { "id": 499253, "url": "http://patchwork.ozlabs.org/api/1.0/series/499253/?format=api", "date": "2026-04-09T06:01:52", "name": "NVMe namespace hotplug and drive reconnection support", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/499253/mbox/" } ], "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2221321/checks/", "tags": {}, "headers": { "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@legolas.ozlabs.org", "Authentication-Results": [ "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=minio.io header.i=@minio.io header.a=rsa-sha256\n header.s=minio header.b=QKEfJjZk;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)" ], "Received": [ "from lists.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4frtCv5N10z1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 09 Apr 2026 18:20:27 +1000 (AEST)", "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wAkbf-0006Lx-TB; Thu, 09 Apr 2026 04:19:19 -0400", "from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <matthieu@minio.io>) id 1wAiSi-0005mo-Mh\n for qemu-devel@nongnu.org; Thu, 09 Apr 2026 02:01:56 -0400", "from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <matthieu@minio.io>) id 1wAiSg-0006ph-Vt\n for qemu-devel@nongnu.org; Thu, 09 Apr 2026 02:01:56 -0400", "by mail-wr1-x42b.google.com with SMTP id\n ffacd0b85a97d-43d17bb1c65so239259f8f.0\n for <qemu-devel@nongnu.org>; Wed, 08 Apr 2026 23:01:54 -0700 (PDT)", "from localhost\n (2a01cb00141148004df9ec80d3fa1cac.ipv6.abo.wanadoo.fr.\n [2a01:cb00:1411:4800:4df9:ec80:d3fa:1cac])\n by smtp.gmail.com with UTF8SMTPSA id\n ffacd0b85a97d-43d1e4e5890sm62750308f8f.31.2026.04.08.23.01.52\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 08 Apr 2026 23:01:52 -0700 (PDT)" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=minio.io; s=minio; t=1775714513; x=1776319313; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=ef/IDwXK0GaH8OkKz0gZMKyBYmbEr0v7UmTk+WfXTa0=;\n b=QKEfJjZkxx9zjFv1mwhg0rTFwC4kiecz3v7DdoR7FRlUx2bPnTLNwY9zorxfVb1prg\n x+5bYjrWFMBxUx4aLvy0js33P3QFfMGzodYMqGwhiMR90c5Q/xtAWxlPWHimGW3RlaZr\n cDadRtt8bySzPlS1MNGkS58SMVFjnziHi9TQmyxaGZB/uaZqIc6ucx2M+PN1aFbzvbLv\n TyVSUNmiUk5dV445yr4LUIMdy9a84EumzI1yHm4gRH56kHwfDUlY7uatl7m3qcXZ/gRv\n A1FnHMaZI625B7hApFywl5YWaRKLmuSM238rX25Ye70agSUaH1/4qhhp0X9JJgIG/DVx\n eEmw==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775714513; x=1776319313;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=ef/IDwXK0GaH8OkKz0gZMKyBYmbEr0v7UmTk+WfXTa0=;\n b=T1p/hSMxzNGHSABr7RUQorG/zrnuEXiCF6Wi/pwe9z4a0Vuqh3d5J4i0W+xNzoTQzK\n QUiHFmvsHi862OcVxtbfbQFK+au1TaioO879mQNvE8IXH9SIxlJg6RQKJT/AwT3gGpk1\n SyifkHrs06TM+rL5SnHKq5BD0ck9B5FvZ2NwK71/oPzlLh+DExVmfArj6JSqo5bA9wJz\n CkoWZbIooVptzRnmwBJ+WC/VouqopDERo/iopuZ62K3d76wTokaZNu2HJ+23gkwRCC1+\n WrsFhtjWNjoNDfMNCS68xYJzRVee7BACMsVUIY1g9ga1QTMI8bW6GI27EB6milTsyjr+\n 0itQ==", "X-Gm-Message-State": "AOJu0YwU5USTYY6/lRi7AYads4nm7PJAo/oV9yKs/t/07URmaHpHcqY3\n Vi5GhpEhD6zl0sYfgor5+xpLSXyTJAB7dhiOjlCGdswmqWVpUhwHxfFGn438heSAvaOO7IqOLF5\n DLwdWnwbeOa4lJh/WAq+6D/FztuBrzQ5yUybEByLbkts3dXpIJN+c3ZB1L9HHrjivxphF58c1lT\n e/HbDDdgwkqUo5QJKmZfhkJsxyVRLH0QO51NQkjkg=", "X-Gm-Gg": "AeBDieuZvzLucpQPifSuuhRPhHGAR26GtYpc7KedrZ9AKpEjuyG4OpJK+9SNsQoAEr5\n 9XR54fPLRe1bohQ0FOUSesd0PfNC3TO617c6RJrcpZi1+759y5XXqy8dTiXVaF2XrNNryezbmGK\n /VNlbSdbBC3Ek5zQv3PMB7MnvmXrYsdsp6L/leg50qAn9zEgJIv3MweGkEU2qJqNvO/IZkkbLpV\n Y30i6h8Uud465+I3TLD5f1Eyb1gJYr6tzSifDN3Mp9KsRTv7/8Lieuni95qPFqMHPoLB5ZkeOfT\n 2JjqWjlGz0Cw6MlvD1BOCVmR/ZowbWxNuem29otHvQeacb1BhstAr3Q+2MQFnYfYDnht7vyL8sS\n Qk/rYQ3q2bUGbfMeeeFhSckPgpuT7aDAXncm9afZg+4g05WwHpKBD7ZXMPMJ2qhWaygx7ujXOkf\n SRsGwPeOzQCRXt/u0mxQ4MJJ/878M6Sq//MiJ40lca5sWWluBJd24iqQ4nd9OOHNBeeLE6a+1iS\n c6X4t2Pz0IOhfQ93Ye1xKudWNgKS507A0nMr1phh7mDMNNYYFhjUThdqNbi7Q==", "X-Received": "by 2002:a5d:5847:0:b0:43c:f8b4:e58 with SMTP id\n ffacd0b85a97d-43d292e2a9emr36065425f8f.41.1775714513163;\n Wed, 08 Apr 2026 23:01:53 -0700 (PDT)", "From": "mr-083 <matthieu@minio.io>", "X-Google-Original-From": "mr-083 <matthieu@min.io>", "To": "qemu-devel@nongnu.org,\n\tqemu-block@nongnu.org", "Cc": "its@irrelevant.dk, kbusch@kernel.org, stefanha@redhat.com,\n mr-083 <matthieu@min.io>", "Subject": "[PATCH 1/2] hw/nvme: add namespace hotplug support", "Date": "Thu, 9 Apr 2026 08:01:53 +0200", "Message-ID": "<20260409060155.94704-2-matthieu@min.io>", "X-Mailer": "git-send-email 2.53.0", "In-Reply-To": "<20260409060155.94704-1-matthieu@min.io>", "References": "<20260409060155.94704-1-matthieu@min.io>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=2a00:1450:4864:20::42b;\n envelope-from=matthieu@minio.io; helo=mail-wr1-x42b.google.com", "X-Spam_score_int": "-10", "X-Spam_score": "-1.1", "X-Spam_bar": "-", "X-Spam_report": "(-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n HK_NAME_MR_MRS=0.998,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=no autolearn_force=no", "X-Spam_action": "no action", "X-Mailman-Approved-At": "Thu, 09 Apr 2026 04:19:18 -0400", "X-BeenThere": "qemu-devel@nongnu.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "qemu development <qemu-devel.nongnu.org>", "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>", "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>", "List-Post": "<mailto:qemu-devel@nongnu.org>", "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>", "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>", "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org", "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org" }, "content": "Add hotplug support for nvme-ns devices on the NvmeBus. This enables\nnamespace-level hot-swap without removing the NVMe controller, which\nis how physical NVMe drives behave when hot-swapped in the same PCIe\nslot.\n\nMark nvme-ns devices as hotpluggable and register the NvmeBus as a\nhotplug handler with proper plug and unplug callbacks:\n\n- plug: attach namespace to all started controllers and send an\n Asynchronous Event Notification (AEN) with NS_ATTR_CHANGED so\n the guest kernel rescans namespaces\n- unplug: detach from all controllers, send AEN, remove from\n subsystem, then unrealize the device\n\nThe plug handler skips controllers that haven't started yet\n(qs_created == false) to avoid interfering with boot-time namespace\nattachment in nvme_start_ctrl().\n\nBoth the controller bus and subsystem bus are configured as hotplug\nhandlers via qbus_set_bus_hotplug_handler() since nvme-ns devices\nmay reparent to the subsystem bus during realize.\n\nSigned-off-by: Matthieu Receveur <matthieu@min.io>\n---\n hw/nvme/ctrl.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++\n hw/nvme/ns.c | 1 +\n hw/nvme/subsys.c | 2 ++\n 3 files changed, 88 insertions(+)", "diff": "diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c\nindex be6c7028cb..5502e4ea2b 100644\n--- a/hw/nvme/ctrl.c\n+++ b/hw/nvme/ctrl.c\n@@ -206,6 +206,7 @@\n #include \"system/hostmem.h\"\n #include \"hw/pci/msix.h\"\n #include \"hw/pci/pcie_sriov.h\"\n+#include \"hw/core/qdev.h\"\n #include \"system/spdm-socket.h\"\n #include \"migration/vmstate.h\"\n \n@@ -9293,6 +9294,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)\n }\n \n qbus_init(&n->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);\n+ qbus_set_bus_hotplug_handler(BUS(&n->bus));\n \n if (nvme_init_subsys(n, errp)) {\n return;\n@@ -9553,10 +9555,93 @@ static const TypeInfo nvme_info = {\n },\n };\n \n+static void nvme_ns_hot_plug(HotplugHandler *hotplug_dev, DeviceState *dev,\n+ Error **errp)\n+{\n+ NvmeNamespace *ns = NVME_NS(dev);\n+ NvmeSubsystem *subsys = ns->subsys;\n+ uint32_t nsid = ns->params.nsid;\n+ int i;\n+\n+ /*\n+ * Attach to all started controllers and notify via AEN.\n+ * Skip controllers that haven't started yet (boot-time realize) —\n+ * nvme_start_ctrl() will attach namespaces during controller init.\n+ */\n+ for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {\n+ NvmeCtrl *ctrl = nvme_subsys_ctrl(subsys, i);\n+ if (!ctrl || !ctrl->qs_created) {\n+ continue;\n+ }\n+\n+ if (nvme_csi_supported(ctrl, ns->csi) && !ns->params.detached) {\n+ nvme_attach_ns(ctrl, ns);\n+ nvme_update_dsm_limits(ctrl, ns);\n+\n+ if (!test_and_set_bit(nsid, ctrl->changed_nsids)) {\n+ nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE,\n+ NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED,\n+ NVME_LOG_CHANGED_NSLIST);\n+ }\n+ }\n+ }\n+}\n+\n+static void nvme_ns_hot_unplug(HotplugHandler *hotplug_dev, DeviceState *dev,\n+ Error **errp)\n+{\n+ NvmeNamespace *ns = NVME_NS(dev);\n+ NvmeSubsystem *subsys = ns->subsys;\n+ uint32_t nsid = ns->params.nsid;\n+ int i;\n+\n+ /*\n+ * Detach from all controllers and notify the guest via AEN.\n+ * Must happen before unrealize to avoid use-after-free when the\n+ * guest sends I/O to a freed namespace.\n+ */\n+ for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {\n+ NvmeCtrl *ctrl = nvme_subsys_ctrl(subsys, i);\n+ if (!ctrl || !nvme_ns(ctrl, nsid)) {\n+ continue;\n+ }\n+\n+ nvme_detach_ns(ctrl, ns);\n+ nvme_update_dsm_limits(ctrl, NULL);\n+\n+ if (!test_and_set_bit(nsid, ctrl->changed_nsids)) {\n+ nvme_enqueue_event(ctrl, NVME_AER_TYPE_NOTICE,\n+ NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED,\n+ NVME_LOG_CHANGED_NSLIST);\n+ }\n+ }\n+\n+ /* Remove from subsystem namespace list. */\n+ subsys->namespaces[nsid] = NULL;\n+\n+ /*\n+ * Unrealize: drain I/O, flush, cleanup structures, remove from QOM.\n+ * nvme_ns_unrealize() handles drain/shutdown/cleanup internally.\n+ */\n+ qdev_unrealize(dev);\n+}\n+\n+static void nvme_bus_class_init(ObjectClass *klass, const void *data)\n+{\n+ HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);\n+ hc->plug = nvme_ns_hot_plug;\n+ hc->unplug = nvme_ns_hot_unplug;\n+}\n+\n static const TypeInfo nvme_bus_info = {\n .name = TYPE_NVME_BUS,\n .parent = TYPE_BUS,\n .instance_size = sizeof(NvmeBus),\n+ .class_init = nvme_bus_class_init,\n+ .interfaces = (const InterfaceInfo[]) {\n+ { TYPE_HOTPLUG_HANDLER },\n+ { }\n+ },\n };\n \n static void nvme_register_types(void)\ndiff --git a/hw/nvme/ns.c b/hw/nvme/ns.c\nindex b0106eaa5c..eb628c0734 100644\n--- a/hw/nvme/ns.c\n+++ b/hw/nvme/ns.c\n@@ -937,6 +937,7 @@ static void nvme_ns_class_init(ObjectClass *oc, const void *data)\n dc->bus_type = TYPE_NVME_BUS;\n dc->realize = nvme_ns_realize;\n dc->unrealize = nvme_ns_unrealize;\n+ dc->hotpluggable = true;\n device_class_set_props(dc, nvme_ns_props);\n dc->desc = \"Virtual NVMe namespace\";\n }\ndiff --git a/hw/nvme/subsys.c b/hw/nvme/subsys.c\nindex 777e1c620f..fa35055d3c 100644\n--- a/hw/nvme/subsys.c\n+++ b/hw/nvme/subsys.c\n@@ -9,6 +9,7 @@\n #include \"qemu/osdep.h\"\n #include \"qemu/units.h\"\n #include \"qapi/error.h\"\n+#include \"hw/core/qdev.h\"\n \n #include \"nvme.h\"\n \n@@ -205,6 +206,7 @@ static void nvme_subsys_realize(DeviceState *dev, Error **errp)\n NvmeSubsystem *subsys = NVME_SUBSYS(dev);\n \n qbus_init(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev, dev->id);\n+ qbus_set_bus_hotplug_handler(BUS(&subsys->bus));\n \n nvme_subsys_setup(subsys, errp);\n }\n", "prefixes": [ "1/2" ] }