Skip to contentSkip to conversation

hw/block/nvme: misc fixes

PATCH In review Klaus Jensen 5 participants 20 messages Apr 5, 2021 – Apr 12, 2021

lore
Share & tools
lore
#2 lore raw

PATCH v2 2/8 hw/block/nvme: fix missing string representation for ns attachment

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Add the missing nvme_adm_opc_str entry for the Namespace Attachment command.

---
 hw/block/nvme.h | 1 +
 1 file changed, 1 insertion(+)
hw/block/nvme.h +1 -0
index 5b0031b11db2..9edc86d79e98 100644
@@ -86,6 +86,7 @@ static inline const char *nvme_adm_opc_str(uint8_t opc)
     case NVME_ADM_CMD_SET_FEATURES:     return "NVME_ADM_CMD_SET_FEATURES";
     case NVME_ADM_CMD_GET_FEATURES:     return "NVME_ADM_CMD_GET_FEATURES";
     case NVME_ADM_CMD_ASYNC_EV_REQ:     return "NVME_ADM_CMD_ASYNC_EV_REQ";
+    case NVME_ADM_CMD_NS_ATTACHMENT:    return "NVME_ADM_CMD_NS_ATTACHMENT";
     case NVME_ADM_CMD_FORMAT_NVM:       return "NVME_ADM_CMD_FORMAT_NVM";
     default:                            return "NVME_ADM_CMD_UNKNOWN";
     }
Signature · 1 line
2.31.1
#0 lore raw

v2 cover hw/block/nvme: misc fixes

From: Klaus Jensen <[email protected]>

Various fixes for 6.0.

v2:
- "hw/block/nvme: fix handling of private namespaces" update documentation (Gollu)
- add a patch for missing copyright headers

Klaus Jensen (8):
hw/block/nvme: fix pi constraint check
hw/block/nvme: fix missing string representation for ns attachment hw/block/nvme: fix the nsid 'invalid' value hw/block/nvme: fix controller namespaces array indexing hw/block/nvme: fix warning about legacy namespace configuration hw/block/nvme: update dmsrl limit on namespace detachment hw/block/nvme: fix handling of private namespaces hw/block/nvme: add missing copyright headers

 hw/block/nvme-dif.h    |  10 +++
 hw/block/nvme-ns.h     |  12 ++--
 hw/block/nvme-subsys.h |   7 +-
 hw/block/nvme.h        |  45 ++-----------
 include/block/nvme.h   |   1 +
 hw/block/nvme-dif.c    |  10 +++
 hw/block/nvme-ns.c     |  76 ++++++++++++++++++----
 hw/block/nvme-subsys.c |  28 --------
 hw/block/nvme.c        | 142 +++++++++++++++++------------------------
 hw/block/trace-events  |   1 -
 10 files changed, 156 insertions(+), 176 deletions(-)
Signature · 1 line
2.31.1
#3 lore raw

PATCH v2 3/8 hw/block/nvme: fix the nsid 'invalid' value

From: Klaus Jensen <[email protected]>

The nvme_nsid() function returns '-1' (FFFFFFFFh) when the given namespace is NULL. Since FFFFFFFFh is actually a valid namespace identifier (the "broadcast" value), change this to be '0' since that actually *is* the invalid value.

---
 hw/block/nvme-ns.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme-ns.h +1 -1
index 9ab7894fc83e..82340c4b2574 100644
@@ -96,7 +96,7 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns)
         return ns->params.nsid;
     }
 
-    return -1;
+    return 0;
 }
 
 static inline bool nvme_ns_shared(NvmeNamespace *ns)
Signature · 1 line
2.31.1
#11 lore raw

PATCH v2 6/8 hw/block/nvme: update dmsrl limit on namespace detachment

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

The Non-MDTS DMSRL limit must be recomputed when namespaces are detached.

Fixes 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command")
---
 hw/block/nvme.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/block/nvme.c +17 -0
index de0e726dfdd8..3dc51f407671 100644
@@ -4876,6 +4876,21 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
     return NVME_NO_COMPLETE;
 }
 
+static void __nvme_update_dmrsl(NvmeCtrl *n)
+{
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        n->dmrsl = MIN_NON_ZERO(n->dmrsl,
+                                BDRV_REQUEST_MAX_BYTES / nvme_l2b(ns, 1));
+    }
+}
+
 static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
 static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
 {
@@ -4925,6 +4940,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
             }
 
             nvme_ns_detach(ctrl, ns);
+
+            __nvme_update_dmrsl(ctrl);
         }
 
         /*
Signature · 1 line
2.31.1
#1 lore raw

PATCH v2 1/8 hw/block/nvme: fix pi constraint check

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Protection Information can only be enabled if there is at least 8 bytes of metadata.

---
 hw/block/nvme-ns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme-ns.c +1 -1
index 7f8d139a8663..ca04ee1bacfb 100644
@@ -394,7 +394,7 @@ static int nvme_ns_check_constraints(NvmeNamespace *ns, Error **errp)
         return -1;
     }
 
-    if (ns->params.pi && !ns->params.ms) {
+    if (ns->params.pi && ns->params.ms < 8) {
         error_setg(errp, "at least 8 bytes of metadata required to enable "
                    "protection information");
         return -1;
Signature · 1 line
2.31.1
#18 lore raw

PATCH v2 8/8 hw/block/nvme: add missing copyright headers

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Add missing license/copyright headers to the nvme-dif.{c,h} files.

---
 hw/block/nvme-dif.h | 10 ++++++++++
 hw/block/nvme-dif.c | 10 ++++++++++
 2 files changed, 20 insertions(+)
hw/block/nvme-dif.h +10 -0
index 5a8e37c8525b..524faffbd7a0 100644
@@ -1,3 +1,13 @@
+/*
+ * QEMU NVM Express End-to-End Data Protection support
+ *
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *   Klaus Jensen           <[email protected]>
+ *   Gollu Appalanaidu      <[email protected]>
+ */
+
 #ifndef HW_NVME_DIF_H
 #define HW_NVME_DIF_H
 
hw/block/nvme-dif.c +10 -0
index e6f04faafb5f..81b0a4cb1382 100644
@@ -1,3 +1,13 @@
+/*
+ * QEMU NVM Express End-to-End Data Protection support
+ *
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *   Klaus Jensen           <[email protected]>
+ *   Gollu Appalanaidu      <[email protected]>
+ */
+
 #include "qemu/osdep.h"
 #include "hw/block/block.h"
 #include "sysemu/dma.h"
Signature · 1 line
2.31.1
#6 lore raw

PATCH v2 4/8 hw/block/nvme: fix controller namespaces array indexing

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

The controller namespaces array being 0-indexed requires 'nsid - 1' everywhere. Something that is easy to miss. Align the controller namespaces array with the subsystem namespaces array such that both are 1-indexed.

---
 hw/block/nvme.h | 8 ++++----
 hw/block/nvme.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
hw/block/nvme.h +4 -4
index 9edc86d79e98..c610ab30dc5c 100644
@@ -217,7 +217,7 @@ typedef struct NvmeCtrl {
      * Attached namespaces to this controller.  If subsys is not given, all
      * namespaces in this list will always be attached.
      */
-    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES];
+    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES + 1];
     NvmeSQueue      **sq;
     NvmeCQueue      **cq;
     NvmeSQueue      admin_sq;
@@ -232,7 +232,7 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)
         return NULL;
     }
 
-    return n->namespaces[nsid - 1];
+    return n->namespaces[nsid];
 }
 
 static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns)
@@ -253,7 +253,7 @@ static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = ns;
+    n->namespaces[nsid] = ns;
 }
 
 static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
@@ -261,7 +261,7 @@ static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = NULL;
+    n->namespaces[nsid] = NULL;
 }
 
 static inline NvmeCQueue *nvme_cq(NvmeRequest *req)
hw/block/nvme.c +1 -1
index c54ec3c9523c..6d31d5b17a0b 100644
@@ -5915,7 +5915,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
             return -1;
         }
     } else {
-        if (n->namespaces[nsid - 1]) {
+        if (n->namespaces[nsid]) {
             error_setg(errp, "namespace id '%d' is already in use", nsid);
             return -1;
         }
Signature · 1 line
2.31.1
#16 lore raw

PATCH v2 7/8 hw/block/nvme: fix handling of private namespaces

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Prior to this patch, if a private nvme-ns device (that is, a namespace that is not linked to a subsystem) is wired up to an nvme-subsys linked nvme controller device, the device fails to verify that the namespace id is unique within the subsystem. NVM Express v1.4b, Section 6.1.6 ("NSID and Namespace Usage") states that because the device supports Namespace Management, "NSIDs *shall* be unique within the NVM subsystem".

Additionally, prior to this patch, private namespaces are not known to the subsystem and the namespace is considered exclusive to the controller with which it is initially wired up to. However, this is not the definition of a private namespace; per Section 1.6.33 ("private namespace"), a private namespace is just a namespace that does not support multipath I/O or namespace sharing, which means "that it is only able to be attached to one controller at a time".

Fix this by always allocating namespaces in the subsystem (if one is linked to the controller), regardsless of the shared/private status of the namespace. Whether or not the namespace is shareable is controlled by a new shared nvme-ns parameter.

Finally, this fix allows the nvme-ns subsys parameter to be removed, since the shared parameter now serves the purpose of attaching the namespace to all controllers in the subsystem upon device realization. It is invalid to have an nvme-ns namespace device with a linked subsystem without the parent nvme controller device also being linked to one and since the nvme-ns devices will unconditionally be "attached" (in QEMU terms that is) to an nvme controller device through an NvmeBus, the nvme-ns namespace device can always get a reference to the subsystem of the controller it is explicitly (using 'bus=' parametr) or implicitly attaching to.

Fixes e570768566b3 ("hw/block/nvme: support for shared namespace in subsystem")
Cc Minwoo Im <[email protected]>
---
 hw/block/nvme-ns.h     |  10 +---
 hw/block/nvme-subsys.h |   7 +--
 hw/block/nvme.h        |  39 +------------
 include/block/nvme.h   |   1 +
 hw/block/nvme-ns.c     |  74 +++++++++++++++++++++----
 hw/block/nvme-subsys.c |  28 ----------
 hw/block/nvme.c        | 123 ++++++++++++++---------------------------
 hw/block/trace-events  |   1 -
 8 files changed, 113 insertions(+), 170 deletions(-)
hw/block/nvme-ns.h +3 -7
index 82340c4b2574..fb0a41f912e7 100644
@@ -29,6 +29,7 @@ typedef struct NvmeZone {
 
 typedef struct NvmeNamespaceParams {
     bool     detached;
+    bool     shared;
     uint32_t nsid;
     QemuUUID uuid;
 
@@ -60,8 +61,8 @@ typedef struct NvmeNamespace {
     const uint32_t *iocs;
     uint8_t      csi;
     uint16_t     status;
+    int          attached;
 
-    NvmeSubsystem   *subsys;
     QTAILQ_ENTRY(NvmeNamespace) entry;
 
     NvmeIdNsZoned   *id_ns_zoned;
@@ -99,11 +100,6 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns)
     return 0;
 }
 
-static inline bool nvme_ns_shared(NvmeNamespace *ns)
-{
-    return !!ns->subsys;
-}
-
 static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns)
 {
     NvmeIdNs *id_ns = &ns->id_ns;
@@ -225,7 +221,7 @@ static inline void nvme_aor_dec_active(NvmeNamespace *ns)
 }
 
 void nvme_ns_init_format(NvmeNamespace *ns);
-int nvme_ns_setup(NvmeNamespace *ns, Error **errp);
+int nvme_ns_setup(NvmeCtrl *n, NvmeNamespace *ns, Error **errp);
 void nvme_ns_drain(NvmeNamespace *ns);
 void nvme_ns_shutdown(NvmeNamespace *ns);
 void nvme_ns_cleanup(NvmeNamespace *ns);
hw/block/nvme-subsys.h +3 -4
index aafa04b84829..24132edd005c 100644
@@ -14,7 +14,7 @@
     OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)
 
 #define NVME_SUBSYS_MAX_CTRLS   32
-#define NVME_SUBSYS_MAX_NAMESPACES  256
+#define NVME_MAX_NAMESPACES     256
 
 typedef struct NvmeCtrl NvmeCtrl;
 typedef struct NvmeNamespace NvmeNamespace;
@@ -24,7 +24,7 @@ typedef struct NvmeSubsystem {
 
     NvmeCtrl    *ctrls[NVME_SUBSYS_MAX_CTRLS];
     /* Allocated namespaces for this subsystem */
-    NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES + 1];
+    NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1];
 
     struct {
         char *nqn;
@@ -32,7 +32,6 @@ typedef struct NvmeSubsystem {
 } NvmeSubsystem;
 
 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp);
-int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp);
 
 static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys,
         uint32_t cntlid)
@@ -54,7 +53,7 @@ static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys,
         return NULL;
     }
 
-    assert(nsid && nsid <= NVME_SUBSYS_MAX_NAMESPACES);
+    assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
     return subsys->namespaces[nsid];
 }
hw/block/nvme.h +1 -38
index 1570f65989a7..644143597a0f 100644
@@ -6,17 +6,9 @@
 #include "nvme-subsys.h"
 #include "nvme-ns.h"
 
-#define NVME_MAX_NAMESPACES 256
-
 #define NVME_DEFAULT_ZONE_SIZE   (128 * MiB)
 #define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB)
 
-/*
- * Subsystem namespace list for allocated namespaces should be larger than
- * attached namespace list in a controller.
- */
-QEMU_BUILD_BUG_ON(NVME_MAX_NAMESPACES > NVME_SUBSYS_MAX_NAMESPACES);
-
 typedef struct NvmeParams {
     char     *serial;
     uint32_t num_queues; /* deprecated since 5.1 */
@@ -234,35 +226,6 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)
     return n->namespaces[nsid];
 }
 
-static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns)
-{
-    int nsid;
-
-    for (nsid = 1; nsid <= n->num_namespaces; nsid++) {
-        if (nvme_ns(n, nsid) == ns) {
-            return true;
-        }
-    }
-
-    return false;
-}
-
-static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns)
-{
-    uint32_t nsid = nvme_nsid(ns);
-    assert(nsid && nsid <= NVME_MAX_NAMESPACES);
-
-    n->namespaces[nsid] = ns;
-}
-
-static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
-{
-    uint32_t nsid = nvme_nsid(ns);
-    assert(nsid && nsid <= NVME_MAX_NAMESPACES);
-
-    n->namespaces[nsid] = NULL;
-}
-
 static inline NvmeCQueue *nvme_cq(NvmeRequest *req)
 {
     NvmeSQueue *sq = req->sq;
@@ -291,7 +254,7 @@ typedef enum NvmeTxDirection {
     NVME_TX_DIRECTION_FROM_DEVICE = 1,
 } NvmeTxDirection;
 
-int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp);
+void nvme_attach_ns(NvmeCtrl *n, NvmeNamespace *ns);
 uint16_t nvme_bounce_data(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
                           NvmeTxDirection dir, NvmeRequest *req);
 uint16_t nvme_bounce_mdata(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
include/block/nvme.h +1 -0
index b0a4e4291611..4ac926fbc687 100644
@@ -847,6 +847,7 @@ enum NvmeStatusCodes {
     NVME_FEAT_NOT_NS_SPEC       = 0x010f,
     NVME_FW_REQ_SUSYSTEM_RESET  = 0x0110,
     NVME_NS_ALREADY_ATTACHED    = 0x0118,
+    NVME_NS_PRIVATE             = 0x0119,
     NVME_NS_NOT_ATTACHED        = 0x011A,
     NVME_NS_CTRL_LIST_INVALID   = 0x011C,
     NVME_CONFLICTING_ATTRS      = 0x0180,
hw/block/nvme-ns.c +64 -10

117 lines not on this page · raw message

hw/block/nvme-subsys.c +0 -28
index 9fadef8cec99..283a97b79d57 100644
@@ -43,34 +43,6 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
     return cntlid;
 }
 
-int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp)
-{
-    NvmeSubsystem *subsys = ns->subsys;
-    NvmeCtrl *n;
-    uint32_t nsid = nvme_nsid(ns);
-    int i;
-
-    assert(nsid && nsid <= NVME_SUBSYS_MAX_NAMESPACES);
-
-    if (subsys->namespaces[nsid]) {
-        error_setg(errp, "namespace %d already registerd to subsy %s",
-                   nvme_nsid(ns), subsys->parent_obj.id);
-        return -1;
-    }
-
-    subsys->namespaces[nsid] = ns;
-
-    for (i = 0; i < ARRAY_SIZE(subsys->ctrls); i++) {
-        n = subsys->ctrls[i];
-
-        if (n && nvme_register_namespace(n, ns, errp)) {
-            return -1;
-        }
-    }
-
-    return 0;
-}
-
 static void nvme_subsys_setup(NvmeSubsystem *subsys)
 {
     const char *nqn = subsys->params.nqn ?
hw/block/nvme.c +41 -82

182 lines not on this page · raw message

hw/block/trace-events +0 -1
index 22da06986d72..fa12e3a67a75 100644
@@ -51,7 +51,6 @@ hd_geometry_guess(void *blk, uint32_t cyls, uint32_t heads, uint32_t secs, int t
 
 # nvme.c
 # nvme traces for successful events
-pci_nvme_register_namespace(uint32_t nsid) "nsid %"PRIu32""
 pci_nvme_irq_msix(uint32_t vector) "raising MSI-X IRQ vector %u"
 pci_nvme_irq_pin(void) "pulsing IRQ pin"
 pci_nvme_irq_masked(void) "IRQ is masked"
Signature · 1 line
2.31.1
#10 lore raw

PATCH v2 5/8 hw/block/nvme: fix warning about legacy namespace configuration

In reply to Klaus Jensen

From: Klaus Jensen <[email protected]>

Remove the unused BlockConf from the controller structure and fix the constraint checking to actually check the right BlockConf and issue the warning.

---
 hw/block/nvme.h | 1 -
 hw/block/nvme.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
hw/block/nvme.h +0 -1
index c610ab30dc5c..1570f65989a7 100644
@@ -166,7 +166,6 @@ typedef struct NvmeCtrl {
     NvmeBar      bar;
     NvmeParams   params;
     NvmeBus      bus;
-    BlockConf    conf;
 
     uint16_t    cntlid;
     bool        qs_created;
hw/block/nvme.c +1 -1
index 6d31d5b17a0b..de0e726dfdd8 100644
@@ -5813,7 +5813,7 @@ static void nvme_check_constraints(NvmeCtrl *n, Error **errp)
         params->max_ioqpairs = params->num_queues - 1;
     }
 
-    if (n->conf.blk) {
+    if (n->namespace.blkconf.blk) {
         warn_report("drive property is deprecated; "
                     "please use an nvme-ns device instead");
     }
Signature · 1 line
2.31.1
Reviewed-by on v2 7/8
#17 lore raw

Re: [PATCH for-6.0 v2 7/8] hw/block/nvme: fix handling of private namespaces

In reply to Klaus Jensen
Quoted 33 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

Prior to this patch, if a private nvme-ns device (that is, a namespace that is not linked to a subsystem) is wired up to an nvme-subsys linked nvme controller device, the device fails to verify that the namespace id is unique within the subsystem. NVM Express v1.4b, Section 6.1.6 ("NSID and Namespace Usage") states that because the device supports Namespace Management, "NSIDs *shall* be unique within the NVM subsystem".

Additionally, prior to this patch, private namespaces are not known to the subsystem and the namespace is considered exclusive to the controller with which it is initially wired up to. However, this is not the definition of a private namespace; per Section 1.6.33 ("private namespace"), a private namespace is just a namespace that does not support multipath I/O or namespace sharing, which means "that it is only able to be attached to one controller at a time".

Fix this by always allocating namespaces in the subsystem (if one is linked to the controller), regardsless of the shared/private status of the namespace. Whether or not the namespace is shareable is controlled by a new shared nvme-ns parameter.

Finally, this fix allows the nvme-ns subsys parameter to be removed, since the shared parameter now serves the purpose of attaching the namespace to all controllers in the subsystem upon device realization. It is invalid to have an nvme-ns namespace device with a linked subsystem without the parent nvme controller device also being linked to one and since the nvme-ns devices will unconditionally be "attached" (in QEMU terms that is) to an nvme controller device through an NvmeBus, the nvme-ns namespace device can always get a reference to the subsystem of the controller it is explicitly (using 'bus=' parametr) or implicitly attaching to.

Quoted 4 lines
Fixes e570768566b3 ("hw/block/nvme: support for shared namespace in subsystem")
Cc Minwoo Im <[email protected]>

Thanks for the fix.

#4 lore raw

Re: [PATCH for-6.0 v2 3/8] hw/block/nvme: fix the nsid 'invalid' value

In reply to Klaus Jensen

Hi Klaus,

Quoted 18 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The nvme_nsid() function returns '-1' (FFFFFFFFh) when the given namespace is NULL. Since FFFFFFFFh is actually a valid namespace identifier (the "broadcast" value), change this to be '0' since that actually *is* the invalid value.

---
 hw/block/nvme-ns.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme-ns.h +0 -0
index 9ab7894fc83e..82340c4b2574 100644

hw/block/nvme-ns.h static inline uint32_t nvme_nsid(NvmeNamespace *ns) · line 99

Quoted 5 lines
hw/block/nvme-ns.h +1 -1
@@ -96,7 +96,7 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns)
         return ns->params.nsid;
     }
 
-    return -1;
+    return 0;

For 6.1 can you add a NVME_NSID_INVALID definition along NVME_NSID_BROADCAST and use it here?

Quoted 4 lines
hw/block/nvme-ns.h +0 -0
 }
 
 static inline bool nvme_ns_shared(NvmeNamespace *ns)
#7 lore raw

Re: [PATCH for-6.0 v2 4/8] hw/block/nvme: fix controller namespaces array indexing

In reply to Klaus Jensen
Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The controller namespaces array being 0-indexed requires 'nsid - 1' everywhere. Something that is easy to miss. Align the controller namespaces array with the subsystem namespaces array such that both are 1-indexed.

TBH I don't understand the justification. Assuming you hit a bug and try to protect yourself, maybe now you should also check for

  assert(n->namespaces[0] == NULL);

somewhere. In nvme_ns() maybe?

Quoted 62 lines
---
 hw/block/nvme.h | 8 ++++----
 hw/block/nvme.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
hw/block/nvme.h +4 -4
index 9edc86d79e98..c610ab30dc5c 100644
@@ -217,7 +217,7 @@ typedef struct NvmeCtrl {
      * Attached namespaces to this controller.  If subsys is not given, all
      * namespaces in this list will always be attached.
      */
-    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES];
+    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES + 1];
     NvmeSQueue      **sq;
     NvmeCQueue      **cq;
     NvmeSQueue      admin_sq;
@@ -232,7 +232,7 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)
         return NULL;
     }
 
-    return n->namespaces[nsid - 1];
+    return n->namespaces[nsid];
 }
 
 static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns)
@@ -253,7 +253,7 @@ static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = ns;
+    n->namespaces[nsid] = ns;
 }
 
 static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
@@ -261,7 +261,7 @@ static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = NULL;
+    n->namespaces[nsid] = NULL;
 }
 
 static inline NvmeCQueue *nvme_cq(NvmeRequest *req)
hw/block/nvme.c +1 -1
index c54ec3c9523c..6d31d5b17a0b 100644
@@ -5915,7 +5915,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
             return -1;
         }
     } else {
-        if (n->namespaces[nsid - 1]) {
+        if (n->namespaces[nsid]) {
             error_setg(errp, "namespace id '%d' is already in use", nsid);
             return -1;
         }
#12 lore raw

Re: [PATCH for-6.0 v2 6/8] hw/block/nvme: update dmsrl limit on namespace detachment

In reply to Klaus Jensen
Quoted 39 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The Non-MDTS DMSRL limit must be recomputed when namespaces are detached.

Fixes 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command")
---
 hw/block/nvme.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/block/nvme.c +15 -0
index de0e726dfdd8..3dc51f407671 100644
@@ -4876,6 +4876,21 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
     return NVME_NO_COMPLETE;
 }
 
+static void __nvme_update_dmrsl(NvmeCtrl *n)
+{
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        n->dmrsl = MIN_NON_ZERO(n->dmrsl,
+                                BDRV_REQUEST_MAX_BYTES / nvme_l2b(ns, 1));
+    }
+}
+
 static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
 static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
 {

hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 4945

Quoted 6 lines
hw/block/nvme.c +2 -0
@@ -4925,6 +4940,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
             }
 
             nvme_ns_detach(ctrl, ns);
+
+            __nvme_update_dmrsl(ctrl);
         }

Why the '__' prefix? It doesn't seem clearer (I'm not sure there is a convention, it makes me think of a internal macro expansion use for preprocessor).

There are very few uses of this prefix:

hw/9pfs/cofs.c:21:static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
hw/block/nvme.c:1683:static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:1742:static void __nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:5213:static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns)
hw/i386/amd_iommu.c:1160:static int __amdvi_int_remap_msi(AMDVIState *iommu, hw/intc/s390_flic_kvm.c:255:static int __get_all_irqs(KVMS390FLICState *flic,
hw/net/rocker/rocker_desc.c:199:static bool __desc_ring_post_desc(DescRing *ring, int err) hw/net/sungem.c:766:static uint16_t __sungem_mii_read(SunGEMState *s, uint8_t phy_addr,
hw/ppc/ppc.c:867:static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp,
hw/s390x/pv.c:25:static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
pc-bios/s390-ccw/cio.c:315:static int __do_cio(SubChannelId schid, uint32_t ccw_addr, int fmt, Irb *irb) target/ppc/mmu-hash64.c:170:static void __helper_slbie(CPUPPCState *env, target_ulong addr,

Thomas, Eric, is it worth cleaning these and updating the 'CODESTYLE.rst'?

Phil.

#5 lore raw

Re: [PATCH for-6.0 v2 3/8] hw/block/nvme: fix the nsid 'invalid' value

In reply to Philippe Mathieu-Daudé
Quoted 24 lines · Philippe Mathieu-Daudé

Hi Klaus,

Quoted 21 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The nvme_nsid() function returns '-1' (FFFFFFFFh) when the given namespace is NULL. Since FFFFFFFFh is actually a valid namespace identifier (the "broadcast" value), change this to be '0' since that actually *is* the invalid value.

---
 hw/block/nvme-ns.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme-ns.h +0 -0
index 9ab7894fc83e..82340c4b2574 100644
@@ -96,7 +96,7 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns)
         return ns->params.nsid;
     }
 
Quoted 6 lines

hw/block/nvme-ns.h static inline uint32_t nvme_nsid(NvmeNamespace *ns) · line 99

Quoted 2 lines
hw/block/nvme-ns.h +1 -1
-    return -1;
+    return 0;

For 6.1 can you add a NVME_NSID_INVALID definition along NVME_NSID_BROADCAST and use it here?

Good idea Philippe, I'll write that up, thanks!

#13 lore raw

Re: [PATCH for-6.0 v2 6/8] hw/block/nvme: update dmsrl limit on namespace detachment

In reply to Philippe Mathieu-Daudé
Quoted 77 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The Non-MDTS DMSRL limit must be recomputed when namespaces are detached.

Fixes 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command")
---
 hw/block/nvme.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/block/nvme.c +15 -0
index de0e726dfdd8..3dc51f407671 100644
@@ -4876,6 +4876,21 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
     return NVME_NO_COMPLETE;
 }
 
+static void __nvme_update_dmrsl(NvmeCtrl *n)
+{
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        n->dmrsl = MIN_NON_ZERO(n->dmrsl,
+                                BDRV_REQUEST_MAX_BYTES / nvme_l2b(ns, 1));
+    }
+}
+
 static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
 static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
 {

hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 4945

Quoted 6 lines
hw/block/nvme.c +2 -0
@@ -4925,6 +4940,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
             }
 
             nvme_ns_detach(ctrl, ns);
+
+            __nvme_update_dmrsl(ctrl);
         }

Why the '__' prefix? It doesn't seem clearer (I'm not sure there is a convention, it makes me think of a internal macro expansion use for preprocessor).

There are very few uses of this prefix:

hw/9pfs/cofs.c:21:static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
hw/block/nvme.c:1683:static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:1742:static void __nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:5213:static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns)
hw/i386/amd_iommu.c:1160:static int __amdvi_int_remap_msi(AMDVIState *iommu, hw/intc/s390_flic_kvm.c:255:static int __get_all_irqs(KVMS390FLICState *flic,
hw/net/rocker/rocker_desc.c:199:static bool __desc_ring_post_desc(DescRing *ring, int err) hw/net/sungem.c:766:static uint16_t __sungem_mii_read(SunGEMState *s, uint8_t phy_addr,
hw/ppc/ppc.c:867:static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp,
hw/s390x/pv.c:25:static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
pc-bios/s390-ccw/cio.c:315:static int __do_cio(SubChannelId schid, uint32_t ccw_addr, int fmt, Irb *irb) target/ppc/mmu-hash64.c:170:static void __helper_slbie(CPUPPCState *env, target_ulong addr,

Quoted 3 lines

Thomas, Eric, is it worth cleaning these and updating the 'CODESTYLE.rst'?

Yeah ok, I think you are right that there is no clear convention on when to use this or not. I typically just use it for functions that are normally not supposed to be called directly.

But I don't even think its consistent in the nvme device. For my sake, we can clean it up, I'll drop it in this case since there is no good reason for it other than my own idea of "style".

#8 lore raw

Re: [PATCH for-6.0 v2 4/8] hw/block/nvme: fix controller namespaces array indexing

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The controller namespaces array being 0-indexed requires 'nsid - 1' everywhere. Something that is easy to miss. Align the controller namespaces array with the subsystem namespaces array such that both are 1-indexed.

TBH I don't understand the justification.

Justification is mostly to align with the subsystem device. I like the '1-indexed' approach better. And the -1 causes Coverity to complain before the assert was added.

Quoted 8 lines

Assuming you hit a
bug and try to protect yourself, maybe now you should also check for

  assert(n->namespaces[0] == NULL);

somewhere. In nvme_ns() maybe?

That is definitely a state that should always hold, I guess we can do that, but we do already guard all "insertions" into the namespace array by an assert on the nsid. Then again, asserting here makes sure that we don't introduce something else that inserts on this invalid position.

So, good point, I'll add it.

Quoted 64 lines
Quoted 62 lines
---
 hw/block/nvme.h | 8 ++++----
 hw/block/nvme.c | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
hw/block/nvme.h +4 -4
index 9edc86d79e98..c610ab30dc5c 100644
@@ -217,7 +217,7 @@ typedef struct NvmeCtrl {
      * Attached namespaces to this controller.  If subsys is not given, all
      * namespaces in this list will always be attached.
      */
-    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES];
+    NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES + 1];
     NvmeSQueue      **sq;
     NvmeCQueue      **cq;
     NvmeSQueue      admin_sq;
@@ -232,7 +232,7 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)
         return NULL;
     }
 
-    return n->namespaces[nsid - 1];
+    return n->namespaces[nsid];
 }
 
 static inline bool nvme_ns_is_attached(NvmeCtrl *n, NvmeNamespace *ns)
@@ -253,7 +253,7 @@ static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = ns;
+    n->namespaces[nsid] = ns;
 }
 
 static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
@@ -261,7 +261,7 @@ static inline void nvme_ns_detach(NvmeCtrl *n, NvmeNamespace *ns)
     uint32_t nsid = nvme_nsid(ns);
     assert(nsid && nsid <= NVME_MAX_NAMESPACES);
 
-    n->namespaces[nsid - 1] = NULL;
+    n->namespaces[nsid] = NULL;
 }
 
 static inline NvmeCQueue *nvme_cq(NvmeRequest *req)
hw/block/nvme.c +1 -1
index c54ec3c9523c..6d31d5b17a0b 100644
@@ -5915,7 +5915,7 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
             return -1;
         }
     } else {
-        if (n->namespaces[nsid - 1]) {
+        if (n->namespaces[nsid]) {
             error_setg(errp, "namespace id '%d' is already in use", nsid);
             return -1;
         }
Signature · 1 line
One of us - No more doubt, silence or taboo about mental illness.
#9 lore raw

Re: [PATCH for-6.0 v2 4/8] hw/block/nvme: fix controller namespaces array indexing

Quoted 24 lines · Klaus Jensen
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The controller namespaces array being 0-indexed requires 'nsid - 1' everywhere. Something that is easy to miss. Align the controller namespaces array with the subsystem namespaces array such that both are 1-indexed.

TBH I don't understand the justification.

Justification is mostly to align with the subsystem device. I like the '1-indexed' approach better. And the -1 causes Coverity to complain before the assert was added.

Quoted 8 lines

Assuming you hit a
bug and try to protect yourself, maybe now you should also check for

  assert(n->namespaces[0] == NULL);

somewhere. In nvme_ns() maybe?

Quoted 7 lines

That is definitely a state that should always hold, I guess we can do that, but we do already guard all "insertions" into the namespace array by an assert on the nsid. Then again, asserting here makes sure that we don't introduce something else that inserts on this invalid position.

So, good point, I'll add it.

Then again again.

I don't see the reason for the assert. Even if something ends up there by mistake we will never return it. If something ends up there due to new code, that nvme_ns() will always return NULL when nsid is zero and that should weed out the bug easily.

I'll update the commit message to make it clear that this is about making both the subsystem and controller namespaces arrays 1-indexed. Them being indexed differently is a recipe for disaster I'd say.

In anycase, I it actually a stretch to call this a bug fix, so I'll drop it and queue it up for v6.1.

#14 lore raw

Re: [PATCH for-6.0 v2 6/8] hw/block/nvme: update dmsrl limit on namespace detachment

In reply to Klaus Jensen
Quoted 82 lines · Klaus Jensen
Quoted 77 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The Non-MDTS DMSRL limit must be recomputed when namespaces are detached.

Fixes 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command")
---
  hw/block/nvme.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
hw/block/nvme.c +15 -0
index de0e726dfdd8..3dc51f407671 100644
@@ -4876,6 +4876,21 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
      return NVME_NO_COMPLETE;
  }
 
+static void __nvme_update_dmrsl(NvmeCtrl *n)
+{
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        n->dmrsl = MIN_NON_ZERO(n->dmrsl,
+                                BDRV_REQUEST_MAX_BYTES / nvme_l2b(ns, 1));
+    }
+}
+
  static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
  static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
  {

hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 4945

Quoted 6 lines
hw/block/nvme.c +2 -0
@@ -4925,6 +4940,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
              }
 
              nvme_ns_detach(ctrl, ns);
+
+            __nvme_update_dmrsl(ctrl);
          }

Why the '__' prefix? It doesn't seem clearer (I'm not sure there is a convention, it makes me think of a internal macro expansion use for preprocessor).

There are very few uses of this prefix:

hw/9pfs/cofs.c:21:static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
hw/block/nvme.c:1683:static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:1742:static void __nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:5213:static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns)
hw/i386/amd_iommu.c:1160:static int __amdvi_int_remap_msi(AMDVIState *iommu, hw/intc/s390_flic_kvm.c:255:static int __get_all_irqs(KVMS390FLICState *flic,
hw/net/rocker/rocker_desc.c:199:static bool __desc_ring_post_desc(DescRing *ring, int err) hw/net/sungem.c:766:static uint16_t __sungem_mii_read(SunGEMState *s, uint8_t phy_addr,
hw/ppc/ppc.c:867:static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp,
hw/s390x/pv.c:25:static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
pc-bios/s390-ccw/cio.c:315:static int __do_cio(SubChannelId schid, uint32_t ccw_addr, int fmt, Irb *irb) target/ppc/mmu-hash64.c:170:static void __helper_slbie(CPUPPCState *env, target_ulong addr,

Quoted 3 lines

Thomas, Eric, is it worth cleaning these and updating the 'CODESTYLE.rst'?

Quoted 7 lines

Yeah ok, I think you are right that there is no clear convention on when to use this or not. I typically just use it for functions that are normally not supposed to be called directly.

But I don't even think its consistent in the nvme device. For my sake, we can clean it up, I'll drop it in this case since there is no good reason for it other than my own idea of "style".

IIRC all identifiers that start with two underscores are reserved by the C standard:

https://busybox.net/~landley/c99-draft.html#7.1.3

Thus you should not use two underscores at the beginning here at all.

HTH,
Thomas

#15 lore raw

Re: [PATCH for-6.0 v2 6/8] hw/block/nvme: update dmsrl limit on namespace detachment

Quoted 89 lines · Thomas Huth
Quoted 80 lines · Klaus Jensen
Quoted 75 lines · Philippe Mathieu-Daudé
Quoted 38 lines · Klaus Jensen

From: Klaus Jensen <[email protected]>

The Non-MDTS DMSRL limit must be recomputed when namespaces are detached.

Fixes 645ce1a70cb6 ("hw/block/nvme: support namespace attachment command")
---
 hw/block/nvme.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
hw/block/nvme.c +15 -0
index de0e726dfdd8..3dc51f407671 100644
@@ -4876,6 +4876,21 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
     return NVME_NO_COMPLETE;
 }
+static void __nvme_update_dmrsl(NvmeCtrl *n)
+{
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        n->dmrsl = MIN_NON_ZERO(n->dmrsl,
+                                BDRV_REQUEST_MAX_BYTES / nvme_l2b(ns, 1));
+    }
+}
+
 static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
 static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
 {

hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 4944

Quoted 5 lines
hw/block/nvme.c +2 -0
@@ -4925,6 +4940,8 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
             }
             nvme_ns_detach(ctrl, ns);
+
+            __nvme_update_dmrsl(ctrl);
         }

Why the '__' prefix? It doesn't seem clearer (I'm not sure there is a convention, it makes me think of a internal macro expansion use for preprocessor).

There are very few uses of this prefix:

hw/9pfs/cofs.c:21:static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
hw/block/nvme.c:1683:static uint16_t __nvme_zrm_open(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:1742:static void __nvme_advance_zone_wp(NvmeNamespace *ns, NvmeZone *zone,
hw/block/nvme.c:5213:static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns)
hw/i386/amd_iommu.c:1160:static int __amdvi_int_remap_msi(AMDVIState *iommu, hw/intc/s390_flic_kvm.c:255:static int __get_all_irqs(KVMS390FLICState *flic,
hw/net/rocker/rocker_desc.c:199:static bool __desc_ring_post_desc(DescRing *ring, int err) hw/net/sungem.c:766:static uint16_t __sungem_mii_read(SunGEMState *s, uint8_t phy_addr,
hw/ppc/ppc.c:867:static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp,
hw/s390x/pv.c:25:static int __s390_pv_cmd(uint32_t cmd, const char *cmdname, void *data)
pc-bios/s390-ccw/cio.c:315:static int __do_cio(SubChannelId schid, uint32_t ccw_addr, int fmt, Irb *irb) target/ppc/mmu-hash64.c:170:static void __helper_slbie(CPUPPCState *env, target_ulong addr,

Quoted 3 lines

Thomas, Eric, is it worth cleaning these and updating the 'CODESTYLE.rst'?

Quoted 7 lines

Yeah ok, I think you are right that there is no clear convention on when to use this or not. I typically just use it for functions that are normally not supposed to be called directly.

But I don't even think its consistent in the nvme device. For my sake, we can clean it up, I'll drop it in this case since there is no good reason for it other than my own idea of "style".

Quoted 6 lines

IIRC all identifiers that start with two underscores are reserved by the C standard:

https://busybox.net/~landley/c99-draft.html#7.1.3

Thus you should not use two underscores at the beginning here at all.

I'll clean up the remaining double underscores in the next cycle!