Skip to content

Commit 8c996e3

Browse files
birkelundphilmd
authored andcommitted
hw/nvme: fix attachment of private namespaces
Fix regression when attaching private namespaces that gets attached to the wrong controller. Keep track of the original controller "owner" of private namespaces, and only attach if this matches on controller enablement. Fixes: 6ccca4b ("hw/nvme: rework csi handling") Reported-by: Alan Adamson <[email protected]> Suggested-by: Alan Adamson <[email protected]> Signed-off-by: Klaus Jensen <[email protected]> Tested-by: Alan Adamson <[email protected]> Reviewed-by: Alan Adamson <[email protected]> Reviewed-by: Keith Busch <[email protected]> Message-ID: <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
1 parent f978f41 commit 8c996e3

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

hw/nvme/ctrl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7755,7 +7755,11 @@ static int nvme_start_ctrl(NvmeCtrl *n)
77557755
for (int i = 1; i <= NVME_MAX_NAMESPACES; i++) {
77567756
NvmeNamespace *ns = nvme_subsys_ns(n->subsys, i);
77577757

7758-
if (ns && nvme_csi_supported(n, ns->csi) && !ns->params.detached) {
7758+
if (!ns || (!ns->params.shared && ns->ctrl != n)) {
7759+
continue;
7760+
}
7761+
7762+
if (nvme_csi_supported(n, ns->csi) && !ns->params.detached) {
77597763
if (!ns->attached || ns->params.shared) {
77607764
nvme_attach_ns(n, ns);
77617765
}
@@ -8988,6 +8992,7 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
89888992
if (n->namespace.blkconf.blk) {
89898993
ns = &n->namespace;
89908994
ns->params.nsid = 1;
8995+
ns->ctrl = n;
89918996

89928997
if (nvme_ns_setup(ns, errp)) {
89938998
return;

hw/nvme/ns.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)
763763

764764
ns->id_ns.endgid = cpu_to_le16(0x1);
765765
ns->id_ns_ind.endgrpid = cpu_to_le16(0x1);
766+
767+
if (!ns->params.shared) {
768+
ns->ctrl = n;
769+
}
766770
}
767771

768772
static const Property nvme_ns_props[] = {

hw/nvme/nvme.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ typedef struct NvmeNamespace {
268268
NvmeSubsystem *subsys;
269269
NvmeEnduranceGroup *endgrp;
270270

271+
/* NULL for shared namespaces; set to specific controller if private */
272+
NvmeCtrl *ctrl;
273+
271274
struct {
272275
uint32_t err_rec;
273276
} features;

hw/nvme/subsys.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
5656
{
5757
NvmeSubsystem *subsys = n->subsys;
5858
NvmeSecCtrlEntry *sctrl = nvme_sctrl(n);
59-
int cntlid, nsid, num_rsvd, num_vfs = n->params.sriov_max_vfs;
59+
int cntlid, num_rsvd, num_vfs = n->params.sriov_max_vfs;
6060

6161
if (pci_is_vf(&n->parent_obj)) {
6262
cntlid = le16_to_cpu(sctrl->scid);
@@ -92,13 +92,6 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
9292

9393
subsys->ctrls[cntlid] = n;
9494

95-
for (nsid = 1; nsid < ARRAY_SIZE(subsys->namespaces); nsid++) {
96-
NvmeNamespace *ns = subsys->namespaces[nsid];
97-
if (ns && ns->params.shared && !ns->params.detached) {
98-
nvme_attach_ns(n, ns);
99-
}
100-
}
101-
10295
return cntlid;
10396
}
10497

0 commit comments

Comments
 (0)