From: Peter Xu Date: Mon, 6 Jan 2020 20:34:45 +0000 (-0700) Subject: vfio/pci: Don't remove irqchip notifier if not registered X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=0446f8121723b134ca1d1ed0b73e96d4a0a8689d;p=qemu.git 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 CC: David Gibson CC: Alex Williamson Cc: qemu-stable@nongnu.org # v4.2 Reported-by: yanghliu@redhat.com Debugged-by: Eduardo Habkost Fixes: c5478fea27ac ("vfio/pci: Respond to KVM irqchip change notifier") Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1782678 Signed-off-by: Peter Xu Reviewed-by: David Gibson Reviewed-by: Greg Kurz Signed-off-by: Alex Williamson --- diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 2d40b396f2..337a173ce7 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -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);