hw/block/nvme: fix msix uninit
v2 cover hw/block/nvme: fix msix uninit
From: Klaus Jensen <[email protected]>
First patch fixes a regression where msix is not correctly uninit'ed when an nvme device is hotplugged with device_del. When viewed in conjunction with the commit that introduced the bug (commit 1901b4967c3f), I think the fix looks relatively obvious.
Second patch disables hotplugging for nvme controllers that are connected to subsystems since the way namespaces are connected to the nvme controller bus is messed up by removing the device. This bug causes a segfault but is *not* a regression and is related to an experimental feature.
v2:
- remove memory subregion as well
- add (possible) patch to disable hotplugging on subsystem connected controllers
Klaus Jensen (2):
hw/block/nvme: fix invalid msix exclusive uninit hw/block/nvme: disable hotplugging for subsystem-linked controllers
hw/block/nvme.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Signature · 1 line
2.31.1
PATCH v2 1/2 hw/block/nvme: fix invalid msix exclusive uninit
From: Klaus Jensen <[email protected]>
Commit 1901b4967c3f changed the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.
Unfortunately, the msix_uninit_exclusive_bar() call remains in nvme_exit() which causes havoc when the device is removed with, say, device_del. Fix this.
Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
--- hw/block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/block/nvme.c +2 -1
@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev)if (n->pmr.dev) {host_memory_backend_set_mapped (n->pmr.dev, false); } -msix_uninit_exclusive_bar (pci_dev); +msix_uninit (pci_dev, &n->bar0, &n->bar0); +memory_region_del_subregion (&n->bar0, &n->iomem); }static Property nvme_props[] = {
Signature · 1 line
2.31.1
Re: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
Quoted 24 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +0
-0
hw/block/nvme.c static void nvme_exit(PCIDevice *pci_dev) · line 6242
Quoted 9 lines
hw/block/nvme.c +2
-1@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev)if (n->pmr.dev) {host_memory_backend_set_mapped (n->pmr.dev, false); } -msix_uninit_exclusive_bar (pci_dev); +msix_uninit (pci_dev, &n->bar0, &n->bar0); +memory_region_del_subregion (&n->bar0, &n->iomem); }static Property nvme_props[] = {
Looks plausible, but if you want this in rc5 could somebody review it, please ?
thanks
-- PMM
Re: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
In reply to Klaus JensenQuoted 35 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>---
hw/block/nvme.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +2
-1@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev)if (n->pmr.dev) {host_memory_backend_set_mapped (n->pmr.dev, false); } -msix_uninit_exclusive_bar (pci_dev); +msix_uninit (pci_dev, &n->bar0, &n->bar0); +memory_region_del_subregion (&n->bar0, &n->iomem); }static Property nvme_props[] = {Signature · 1 line
2.31.1
Ping for a review on this please :)
Re: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
Quoted 32 lines · Klaus Jensen
Quoted 31 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>---
hw/block/nvme.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +2
-1@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev) if (n->pmr.dev) { host_memory_backend_set_mapped(n->pmr.dev, false); } - msix_uninit_exclusive_bar(pci_dev); + msix_uninit(pci_dev, &n->bar0, &n->bar0); + memory_region_del_subregion(&n->bar0, &n->iomem); }
Quoted 6 lines
Quoted 4 lines
hw/block/nvme.c +0
-0static Property nvme_props[] = {--
2.31.1Ping for a review on this please :)
You forgot to Cc the maintainers :/ (doing it now).
$ ./scripts/get_maintainer.pl -f include/hw/pci/msix.h "Michael S. Tsirkin" <[email protected]> (supporter:PCI) Marcel Apfelbaum <[email protected]> (supporter:PCI)
Re: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
Quoted 40 lines · Philippe Mathieu-Daudé
Quoted 32 lines · Klaus Jensen
Quoted 31 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>---
hw/block/nvme.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +2
-1@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev) if (n->pmr.dev) { host_memory_backend_set_mapped(n->pmr.dev, false); } - msix_uninit_exclusive_bar(pci_dev); + msix_uninit(pci_dev, &n->bar0, &n->bar0); + memory_region_del_subregion(&n->bar0, &n->iomem); }Quoted 6 lines
Quoted 4 lines
hw/block/nvme.c +0
-0static Property nvme_props[] = {--
2.31.1Ping for a review on this please :)
Quoted 6 lines
You forgot to Cc the maintainers :/ (doing it now).
$ ./scripts/get_maintainer.pl -f include/hw/pci/msix.h "Michael S. Tsirkin" <[email protected]> (supporter:PCI) Marcel Apfelbaum <[email protected]> (supporter:PCI)
I didnt consider CC'ing the PCI maintainers directly, but makes total sense here, thanks!
Michael S. Tsirkin
Reviewed-byRe: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Klaus Jensen
Quoted 9 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>
Quoted 29 lines
Quoted 17 lines
Quoted 17 lines
---
hw/block/nvme.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +2
-1@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev) if (n->pmr.dev) { host_memory_backend_set_mapped(n->pmr.dev, false); } - msix_uninit_exclusive_bar(pci_dev); + msix_uninit(pci_dev, &n->bar0, &n->bar0); + memory_region_del_subregion(&n->bar0, &n->iomem); }Quoted 6 lines
Quoted 4 lines
hw/block/nvme.c +0
-0static Property nvme_props[] = {--
2.31.1Ping for a review on this please :)
You forgot to Cc the maintainers :/ (doing it now).
$ ./scripts/get_maintainer.pl -f include/hw/pci/msix.h "Michael S. Tsirkin" <[email protected]> (supporter:PCI) Marcel Apfelbaum <[email protected]> (supporter:PCI)
Peter Maydell
AppliedRe: [PATCH for-6.0 v2 1/2] hw/block/nvme: fix invalid msix exclusive uninit
In reply to Klaus JensenQuoted 24 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
Commit
1901b4967c3fchanged the nvme device from using a bar exclusive for MSI-x to sharing it on bar0.Unfortunately, the
msix_uninit_exclusive_bar()call remains innvme_exit()which causes havoc when the device is removed with, say,device_del. Fix this.Additionally, a subregion is added but it is not removed on exit which causes a reference to linger and the drive to never be unlocked.
Fixes 1901b4967c3f ("hw/block/nvme: move msix table and pba to BAR 0")Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/block/nvme.c +0
-0
hw/block/nvme.c static void nvme_exit(PCIDevice *pci_dev)
Quoted 10 lines
hw/block/nvme.c +2
-2@@ -6235,7 +6235,8 @@ static void nvme_exit(PCIDevice *pci_dev)if (n->pmr.dev) {host_memory_backend_set_mapped (n->pmr.dev, false); } -msix_uninit_exclusive_bar (pci_dev); +msix_uninit (pci_dev, &n->bar0, &n->bar0); +memory_region_del_subregion (&n->bar0, &n->iomem); }static Property nvme_props[] = { --
Applied this patch (but not patch 2) to master for 6.0; thanks.
-- PMM
PATCH v2 2/2 hw/block/nvme: disable hotplugging for subsystem-linked controllers
In reply to Klaus JensenFrom: Klaus Jensen <[email protected]>
If a controller is linked to a subsystem, do not allow it to be hotplugged since this will mess up the (possibly shared) namespaces.
--- hw/block/nvme.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/block/nvme.c +4 -0
@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)static int nvme_init_subsys (NvmeCtrl *n,Error **errp) { +DeviceClass *dc;int cntlid;if (!n->subsys) {return 0 ; } + dc =DEVICE_GET_CLASS (n); + dc->hotpluggable = false; + cntlid =nvme_subsys_register_ctrl (n, errp);if (cntlid <0 ) {return -1 ;
Signature · 1 line
2.31.1
Re: [PATCH for-6.0 v2 2/2] hw/block/nvme: disable hotplugging for subsystem-linked controllers
Quoted 22 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
If a controller is linked to a subsystem, do not allow it to be hotplugged since this will mess up the (possibly shared) namespaces.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 4 ++++ 1 file changed, 4 insertions(+)hw/block/nvme.c +1
-0@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)static int nvme_init_subsys (NvmeCtrl *n,Error **errp) { +DeviceClass *dc;int cntlid;
hw/block/nvme.c static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) · line 6155
Quoted 10 lines
hw/block/nvme.c +3
-0if (!n->subsys) {return 0 ; } + dc =DEVICE_GET_CLASS (n); + dc->hotpluggable = false; + cntlid =nvme_subsys_register_ctrl (n, errp);if (cntlid <0 ) {return -1 ;
I'm not sure this is right -- the DeviceClass is the class struct, which there's only one of for every instance of the device in the system. So this is saying "if this instance is linked to a subsystem, don't let any *future* instances ever be hotpluggable". I'm not even sure if it will do the right thing for the current device, because this function is called from the device's realize method, and the device_set_realized() function does the "forbid if dc->hotpluggable is false" check before calling the realize method.
Possibly what you want to do here is to call the device_get_hotplugged() function and just make the realize method fail with a suitable error if the device is both (a) being hotplugged and (b) has a subsystem link; but I'm not an expert on hotplug, so I might be wrong.
thanks
-- PMM
Re: [PATCH for-6.0 v2 2/2] hw/block/nvme: disable hotplugging for subsystem-linked controllers
Quoted 44 lines · Peter Maydell
Quoted 22 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
If a controller is linked to a subsystem, do not allow it to be hotplugged since this will mess up the (possibly shared) namespaces.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 4 ++++ 1 file changed, 4 insertions(+)hw/block/nvme.c +1
-0@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)static int nvme_init_subsys (NvmeCtrl *n,Error **errp) { +DeviceClass *dc;int cntlid;hw/block/nvme.c static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) · line 6155
Quoted 10 lines
hw/block/nvme.c +3
-0if (!n->subsys) {return 0 ; } + dc =DEVICE_GET_CLASS (n); + dc->hotpluggable = false; + cntlid =nvme_subsys_register_ctrl (n, errp);if (cntlid <0 ) {return -1 ;I'm not sure this is right -- the DeviceClass is the class struct, which there's only one of for every instance of the device in the system. So this is saying "if this instance is linked to a subsystem, don't let any *future* instances ever be hotpluggable". I'm not even sure if it will do the right thing for the current device, because this function is called from the device's realize method, and the
device_set_realized()function does the "forbid ifdc->hotpluggableis false" check before calling the realize method.
Quoted 6 lines
Possibly what you want to do here is to call the
device_get_hotplugged()function and just make the realize method fail with a suitable error if the device is both (a) being hotplugged and (b) has a subsystem link; but I'm not an expert on hotplug, so I might be wrong.
Thanks Peter, this sounds exactly like what I want. I'll respin!
I have a "full" fix that actually makes the device hotpluggable in the context of subsystems, but it is definitely not an -rc thing.
Re: [PATCH for-6.0 v2 2/2] hw/block/nvme: disable hotplugging for subsystem-linked controllers
Quoted 53 lines · Klaus Jensen
Quoted 44 lines · Peter Maydell
Quoted 22 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
If a controller is linked to a subsystem, do not allow it to be hotplugged since this will mess up the (possibly shared) namespaces.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 4 ++++ 1 file changed, 4 insertions(+)hw/block/nvme.c +1
-0@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)static int nvme_init_subsys (NvmeCtrl *n,Error **errp) { +DeviceClass *dc;int cntlid;hw/block/nvme.c static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) · line 6155
Quoted 10 lines
hw/block/nvme.c +3
-0if (!n->subsys) {return 0 ; } + dc =DEVICE_GET_CLASS (n); + dc->hotpluggable = false; + cntlid =nvme_subsys_register_ctrl (n, errp);if (cntlid <0 ) {return -1 ;I'm not sure this is right -- the DeviceClass is the class struct, which there's only one of for every instance of the device in the system. So this is saying "if this instance is linked to a subsystem, don't let any *future* instances ever be hotpluggable". I'm not even sure if it will do the right thing for the current device, because this function is called from the device's realize method, and the
device_set_realized()function does the "forbid ifdc->hotpluggableis false" check before calling the realize method.Quoted 6 lines
Possibly what you want to do here is to call the
device_get_hotplugged()function and just make the realize method fail with a suitable error if the device is both (a) being hotplugged and (b) has a subsystem link; but I'm not an expert on hotplug, so I might be wrong.
Quoted 4 lines
Thanks Peter, this sounds exactly like what I want. I'll respin!
I have a "full" fix that actually makes the device hotpluggable in the context of subsystems, but it is definitely not an -rc thing.
For 6.0 I don't think we should put this in anyway -- it's not a regression and in any case it sounds like it needs more work...
-- PMM
Re: [PATCH for-6.0 v2 2/2] hw/block/nvme: disable hotplugging for subsystem-linked controllers
Quoted 54 lines · Peter Maydell
Quoted 53 lines · Klaus Jensen
Quoted 50 lines · Peter Maydell
Quoted 22 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
If a controller is linked to a subsystem, do not allow it to be hotplugged since this will mess up the (possibly shared) namespaces.
Signed-off-by Klaus Jensen <[email protected]>--- hw/block/nvme.c | 4 ++++ 1 file changed, 4 insertions(+)hw/block/nvme.c +1
-0@@ -6140,12 +6140,16 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev)static int nvme_init_subsys (NvmeCtrl *n,Error **errp) { +DeviceClass *dc;int cntlid;hw/block/nvme.c static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) · line 6155
Quoted 10 lines
hw/block/nvme.c +3
-0if (!n->subsys) {return 0 ; } + dc =DEVICE_GET_CLASS (n); + dc->hotpluggable = false; + cntlid =nvme_subsys_register_ctrl (n, errp);if (cntlid <0 ) {return -1 ;I'm not sure this is right -- the DeviceClass is the class struct, which there's only one of for every instance of the device in the system. So this is saying "if this instance is linked to a subsystem, don't let any *future* instances ever be hotpluggable". I'm not even sure if it will do the right thing for the current device, because this function is called from the device's realize method, and the
device_set_realized()function does the "forbid ifdc->hotpluggableis false" check before calling the realize method.Possibly what you want to do here is to call the
device_get_hotplugged()function and just make the realize method fail with a suitable error if the device is both (a) being hotplugged and (b) has a subsystem link; but I'm not an expert on hotplug, so I might be wrong.
Quoted 8 lines
Quoted 4 lines
Thanks Peter, this sounds exactly like what I want. I'll respin!
I have a "full" fix that actually makes the device hotpluggable in the context of subsystems, but it is definitely not an -rc thing.
For 6.0 I don't think we should put this in anyway -- it's not a regression and in any case it sounds like it needs more work...
Agree, patch 1 is what I would like to see in if an -rc5 is spun.
Quoted 18 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
First patch fixes a regression where msix is not correctly uninit'ed when an nvme device is hotplugged with
device_del. When viewed in conjunction with the commit that introduced the bug (commit1901b4967c3f), I think the fix looks relatively obvious.Second patch disables hotplugging for nvme controllers that are connected to subsystems since the way namespaces are connected to the nvme controller bus is messed up by removing the device. This bug causes a segfault but is *not* a regression and is related to an experimental feature.
v2:
- remove memory subregion as well
- add (possible) patch to disable hotplugging on subsystem connected controllers
Quoted 11 lines
Klaus Jensen (2):
hw/block/nvme: fix invalid msix exclusive uninit hw/block/nvme: disable hotplugging for subsystem-linked controllers
hw/block/nvme.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)Signature · 1 line
2.31.1
Peter,
I know you have a lot of crap on your plate right now, so for the record, yes, this is a regression, but not release critical, right?
I am not aware of anyone depending on this unplugging functionality (which according to Bug 1925496 is and have always been flaky) in production. Basically, as far as I know, all known uses of this device are for development and/or testing.
Quoted 15 lines · Klaus Jensen
Quoted 7 lines · Klaus Jensen
From: Klaus Jensen <[email protected]>
First patch fixes a regression where msix is not correctly uninit'ed when an nvme device is hotplugged with
device_del. When viewed in conjunction with the commit that introduced the bug (commit1901b4967c3f), I think the fix looks relatively obvious.Quoted 5 lines
Second patch disables hotplugging for nvme controllers that are connected to subsystems since the way namespaces are connected to the nvme controller bus is messed up by removing the device. This bug causes a segfault but is *not* a regression and is related to an experimental feature.
Quoted 7 lines
I know you have a lot of crap on your plate right now, so for the record, yes, this is a regression, but not release critical, right?
I am not aware of anyone depending on this unplugging functionality (which according to Bug 1925496 is and have always been flaky) in production. Basically, as far as I know, all known uses of this device are for development and/or testing.
Thanks for the update. We probably are going to have to roll an rc5 for the network-interface hotplug crash, but it sounds from your description (especially if hotunplug has always been broken) as if we could safely leave theses fixes until 6.1.
thanks
-- PMM