Skip to contentSkip to conversation

vfio/pci: Don't remove irqchip notifier if not registered

PATCH In review Peter Xu 4 participants 5 messages Dec 31, 2019 – Jan 7, 2020

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 vfio/pci: Don't remove irqchip notifier if not registered

The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed. If the assigned device does not support INTx, this will cause QEMU to crash when unplugging the device from the system. Change it to conditionally remove the notifier only if the notify hook is setup.

CC Eduardo Habkost <[email protected]>
CC David Gibson <[email protected]>
CC Alex Williamson <[email protected]>
Reported-by [email protected]
Fixes c5478fea27 ("vfio/pci: Respond to KVM irqchip change notifier", 2019-11-26)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678

---
 hw/vfio/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
index 2d40b396f2..337a173ce7 100644
@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
     pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
-    kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    if (vdev->irqchip_change_notifier.notify) {
+        kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    }
     vfio_disable_interrupts(vdev);
     if (vdev->intx.mmap_timer) {
         timer_free(vdev->intx.mmap_timer);
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Peter Xu

The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed. If the assigned device does not support INTx, this will cause QEMU to crash when unplugging the device from the system. Change it to conditionally remove the notifier only if the notify hook is setup.

Quoted 7 lines
CC Eduardo Habkost <[email protected]>
CC David Gibson <[email protected]>
CC Alex Williamson <[email protected]>
Reported-by [email protected]
Fixes c5478fea27 ("vfio/pci: Respond to KVM irqchip change notifier", 2019-11-26)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678

Mea culpa.

Quoted 19 lines
---
 hw/vfio/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
index 2d40b396f2..337a173ce7 100644
@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
     pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
-    kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    if (vdev->irqchip_change_notifier.notify) {
+        kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    }
     vfio_disable_interrupts(vdev);
     if (vdev->intx.mmap_timer) {
         timer_free(vdev->intx.mmap_timer);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Reviewed-by on v1 1/1
#2 lore raw
In reply to Peter Xu
Quoted 6 lines · On Tue, 31 Dec 2019 08:39:15 -0500 Peter Xu <[email protected]> wrote:

The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed. If the assigned device does not support INTx, this will cause QEMU to crash when unplugging the device from the system. Change it to conditionally remove the notifier only if the notify hook is setup.

Quoted 8 lines
CC Eduardo Habkost <[email protected]>
CC David Gibson <[email protected]>
CC Alex Williamson <[email protected]>
Reported-by [email protected]
Fixes c5478fea27 ("vfio/pci: Respond to KVM irqchip change notifier", 2019-11-26)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678

---

Good catch... sorry for missing this during review :-\

Cc'ing stable since we certainly want this fix in 4.2.1 as well.

Quoted 18 lines
 hw/vfio/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
index 2d40b396f2..337a173ce7 100644
@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
     pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
-    kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    if (vdev->irqchip_change_notifier.notify) {
+        kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    }
     vfio_disable_interrupts(vdev);
     if (vdev->intx.mmap_timer) {
         timer_free(vdev->intx.mmap_timer);
#3 lore raw
In reply to Peter Xu
Quoted 22 lines · On Tue, 31 Dec 2019 08:39:15 -0500 Peter Xu <[email protected]> wrote:

The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed. If the assigned device does not support INTx, this will cause QEMU to crash when unplugging the device from the system. Change it to conditionally remove the notifier only if the notify hook is setup.

CC Eduardo Habkost <[email protected]>
CC David Gibson <[email protected]>
CC Alex Williamson <[email protected]>
Reported-by [email protected]
Fixes c5478fea27 ("vfio/pci: Respond to KVM irqchip change notifier", 2019-11-26)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678

---
 hw/vfio/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +0 -0
index 2d40b396f2..337a173ce7 100644

hw/vfio/pci.c static void vfio_exitfn(PCIDevice *pdev) · line 3084

Quoted 10 lines
hw/vfio/pci.c +3 -1
@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
     pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
-    kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    if (vdev->irqchip_change_notifier.notify) {
+        kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    }
     vfio_disable_interrupts(vdev);
     if (vdev->intx.mmap_timer) {
         timer_free(vdev->intx.mmap_timer);

Thanks, Peter! Sent a pull request with David and Greg's R-b, stable tag, and debug credit to Eduardo as I think he spotted the issue first. Thanks,

Alex

author
#4 lore raw
Quoted 32 lines · Alex Williamson
Quoted 29 lines · On Tue, 31 Dec 2019 08:39:15 -0500 Peter Xu <[email protected]> wrote:

The kvm irqchip notifier is only registered if the device supports INTx, however it's unconditionally removed. If the assigned device does not support INTx, this will cause QEMU to crash when unplugging the device from the system. Change it to conditionally remove the notifier only if the notify hook is setup.

CC Eduardo Habkost <[email protected]>
CC David Gibson <[email protected]>
CC Alex Williamson <[email protected]>
Reported-by [email protected]
Fixes c5478fea27 ("vfio/pci: Respond to KVM irqchip change notifier", 2019-11-26)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678

---
 hw/vfio/pci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
index 2d40b396f2..337a173ce7 100644
@@ -3076,7 +3076,9 @@ static void vfio_exitfn(PCIDevice *pdev)
     vfio_unregister_req_notifier(vdev);
     vfio_unregister_err_notifier(vdev);
     pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
-    kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    if (vdev->irqchip_change_notifier.notify) {
+        kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+    }
Quoted 8 lines

hw/vfio/pci.c static void vfio_exitfn(PCIDevice *pdev) · line 3084

Quoted 3 lines
hw/vfio/pci.c +0 -0
     vfio_disable_interrupts(vdev);
     if (vdev->intx.mmap_timer) {
         timer_free(vdev->intx.mmap_timer);

Thanks, Peter! Sent a pull request with David and Greg's R-b, stable tag, and debug credit to Eduardo as I think he spotted the issue first. Thanks,

Yes thanks! I wished Eduardo had even updated the bz when he debugged so I won't be needinfo-ed and did it twice without notice :)

Signature · 1 line
Peter Xu