get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.1/patches/2223604/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2223604,
    "url": "http://patchwork.ozlabs.org/api/1.1/patches/2223604/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415173852.71135-1-matthieu@min.io/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/1.1/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": "<20260415173852.71135-1-matthieu@min.io>",
    "date": "2026-04-15T17:38:52",
    "name": "[v4] hw/nvme: add namespace hotplug support",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "2ef8e0bd9b105cd56663a7eeed5f577895a79cb7",
    "submitter": {
        "id": 93098,
        "url": "http://patchwork.ozlabs.org/api/1.1/people/93098/?format=api",
        "name": "Matthieu Rolla",
        "email": "matthieu@minio.io"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260415173852.71135-1-matthieu@min.io/mbox/",
    "series": [
        {
            "id": 500022,
            "url": "http://patchwork.ozlabs.org/api/1.1/series/500022/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500022",
            "date": "2026-04-15T17:38:52",
            "name": "[v4] hw/nvme: add namespace hotplug support",
            "version": 4,
            "mbox": "http://patchwork.ozlabs.org/series/500022/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2223604/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2223604/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=pvcTJWYi;\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=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists1p.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 4fwpLQ1Bv1z1yHd\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 03:39:40 +1000 (AEST)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wD4CR-000096-QQ; Wed, 15 Apr 2026 13:38:51 -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 1wD4CN-00008p-PY\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 13:38:47 -0400",
            "from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c])\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 1wD4CL-0002ic-LP\n for qemu-devel@nongnu.org; Wed, 15 Apr 2026 13:38:47 -0400",
            "by mail-wm1-x32c.google.com with SMTP id\n 5b1f17b1804b1-488a14c31eeso57112605e9.0\n for <qemu-devel@nongnu.org>; Wed, 15 Apr 2026 10:38:45 -0700 (PDT)",
            "from localhost\n (2a01cb001411480010f92e9cd3b40a22.ipv6.abo.wanadoo.fr.\n [2a01:cb00:1411:4800:10f9:2e9c:d3b4:a22])\n by smtp.gmail.com with UTF8SMTPSA id\n 5b1f17b1804b1-488f0ea65b9sm39069835e9.5.2026.04.15.10.38.42\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Wed, 15 Apr 2026 10:38:43 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=minio.io; s=minio; t=1776274724; x=1776879524; 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=Fm1uSt8v3N52EDQqCSTygQcIRULkfTeQnbM96/UzDVE=;\n b=pvcTJWYig9Y7xnLHJRjDa26f7/zCGCFBvCfoXrE0Bp/oCi4Lm02pKuicKkEyykv8Xo\n ggvlhtwsW6TsH3PJ/1PBBlrvapjI1SLF40mx/50XjDNpEsPkztrgitQYQLbrUcmrxLc8\n bmlPizUwZQZnNSJ0zDqa4l3MQnIc4oivZK8Gqoe7EL+eW12QV9FgWzNjJwVzgdbQZECT\n fWbotsaSetlDStYjD3quLgTngMUZqLFmkIHa4HGw1YFmscLGTpxtJ96z+uFzwwNxvCyO\n z4+5ViyOJ7ZxV8fOSe6KU9whxV3b0NoiWlXRGA/6Z1gg7U4uCgS68jfWCyuvZxGMhhek\n CQ0g==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776274724; x=1776879524;\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=Fm1uSt8v3N52EDQqCSTygQcIRULkfTeQnbM96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Wn46Bl4RCBxu/YDqNDlrWqoAxPbl3qv/\n nxiVBCmTtghqhZYxMNCInEJ0K4ezvXBsmRzOwV7Jx/Ie66rlJNSsEWv3oJFoLbYR+9O3o0RGNgB\n 5MYoQhRJ5JxtpO5mvMX6dDKRHfkBWOmSx85xhi9vsebrpWc1C1BhcK67N2tN6oakwfoFsw=",
        "X-Received": "by 2002:a05:600c:c10d:b0:488:ae4e:51a5 with SMTP id\n 5b1f17b1804b1-488d683d633mr217192825e9.15.1776274723436;\n Wed, 15 Apr 2026 10:38:43 -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 v4] hw/nvme: add namespace hotplug support",
        "Date": "Wed, 15 Apr 2026 19:38:52 +0200",
        "Message-ID": "<20260415173852.71135-1-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::32c;\n envelope-from=matthieu@minio.io; helo=mail-wm1-x32c.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-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\nNVMe namespace-level hot-add and hot-remove via device_add and\ndevice_del with proper Asynchronous Event Notification (AEN), so the\nguest kernel can react to namespace topology changes.\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 and adds the block device\n- unplug: drain in-flight I/O, detach from all controllers, send\n  AEN, then unrealize the device. The guest kernel rescans and\n  removes the block 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\nThe unplug handler drains in-flight I/O via nvme_ns_drain() before\ndetaching the namespace from controllers, so pending requests can\ncomplete normally without touching freed state.\n\nFor symmetry with nvme_ns_realize() which sets subsys->namespaces[nsid],\nnvme_ns_unrealize() now clears that slot too making the namespace\nlifecycle complete.\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\nExample hot-swap sequence using the NVMe subsystem model:\n\n  # Boot with: -device nvme-subsys,id=subsys0\n  #            -device nvme,id=ctrl0,subsys=subsys0\n  #            -device nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1\n\n  device_del ns0             # guest receives AEN, removes /dev/nvme0n1\n  drive_del drv0\n  drive_add 0 file=disk.qcow2,format=qcow2,id=drv0,if=none\n  device_add nvme-ns,id=ns0,drive=drv0,bus=ctrl0,nsid=1\n                              # guest receives AEN, adds /dev/nvme0n1\n\nTested with Linux 6.1 guest (NVMe driver processes AEN and rescans\nnamespace list automatically).\n\nSigned-off-by: Matthieu <matthieu@min.io>\n---\n hw/nvme/ctrl.c   | 88 ++++++++++++++++++++++++++++++++++++++++++++++++\n hw/nvme/ns.c     |  8 +++++\n hw/nvme/subsys.c |  2 ++\n 3 files changed, 98 insertions(+)",
    "diff": "diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c\nindex be6c7028cb..2024b0ff75 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,96 @@ 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+     * Drain in-flight I/O before tearing down the namespace.\n+     * This must happen while the namespace is still attached to the\n+     * controllers so any pending requests can complete normally.\n+     */\n+    nvme_ns_drain(ns);\n+\n+    /*\n+     * Detach from all controllers and notify the guest via AEN.\n+     * The guest kernel will rescan namespaces and remove the block device.\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+    /*\n+     * Unrealize: removes from subsystem (in nvme_ns_unrealize), flushes,\n+     * cleans up structures, and removes from QOM.\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..f4f755c6fc 100644\n--- a/hw/nvme/ns.c\n+++ b/hw/nvme/ns.c\n@@ -719,10 +719,17 @@ void nvme_ns_cleanup(NvmeNamespace *ns)\n static void nvme_ns_unrealize(DeviceState *dev)\n {\n     NvmeNamespace *ns = NVME_NS(dev);\n+    NvmeSubsystem *subsys = ns->subsys;\n+    uint32_t nsid = ns->params.nsid;\n \n     nvme_ns_drain(ns);\n     nvme_ns_shutdown(ns);\n     nvme_ns_cleanup(ns);\n+\n+    /* Symmetric with nvme_ns_realize() which sets subsys->namespaces[nsid]. */\n+    if (subsys && nsid && subsys->namespaces[nsid] == ns) {\n+        subsys->namespaces[nsid] = NULL;\n+    }\n }\n \n void nvme_ns_atomic_configure_boundary(bool dn, uint16_t nabsn,\n@@ -937,6 +944,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": [
        "v4"
    ]
}