[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 4/8] vfio/pci: Respond to KVM irqchip change notifier
From: |
David Gibson |
Subject: |
[PULL 4/8] vfio/pci: Respond to KVM irqchip change notifier |
Date: |
Tue, 26 Nov 2019 17:01:47 +1100 |
VFIO PCI devices already respond to the pci intx routing notifier, in order
to update kernel irqchip mappings when routing is updated. However this
won't handle the case where the irqchip itself is replaced by a different
model while retaining the same routing. This case can happen on
the pseries machine type due to PAPR feature negotiation.
To handle that case, add a handler for the irqchip change notifier, which
does much the same thing as the routing notifier, but is unconditional,
rather than being a no-op when the routing hasn't changed.
Cc: Alex Williamson <address@hidden>
Cc: Alexey Kardashevskiy <address@hidden>
Signed-off-by: David Gibson <address@hidden>
Tested-by: Alex Williamson <address@hidden>
Reviewed-by: Alex Williamson <address@hidden>
Reviewed-by: Greg Kurz <address@hidden>
Acked-by: Alex Williamson <address@hidden>
---
hw/vfio/pci.c | 25 +++++++++++++++++++------
hw/vfio/pci.h | 1 +
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 521289aa7d..2d40b396f2 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -256,6 +256,14 @@ static void vfio_intx_routing_notifier(PCIDevice *pdev)
}
}
+static void vfio_irqchip_change(Notifier *notify, void *data)
+{
+ VFIOPCIDevice *vdev = container_of(notify, VFIOPCIDevice,
+ irqchip_change_notifier);
+
+ vfio_intx_update(vdev, &vdev->intx.route);
+}
+
static int vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp)
{
uint8_t pin = vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1);
@@ -2973,30 +2981,32 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_intx_mmap_enable, vdev);
pci_device_set_intx_routing_notifier(&vdev->pdev,
vfio_intx_routing_notifier);
+ vdev->irqchip_change_notifier.notify = vfio_irqchip_change;
+ kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier);
ret = vfio_intx_enable(vdev, errp);
if (ret) {
- goto out_teardown;
+ goto out_deregister;
}
}
if (vdev->display != ON_OFF_AUTO_OFF) {
ret = vfio_display_probe(vdev, errp);
if (ret) {
- goto out_teardown;
+ goto out_deregister;
}
}
if (vdev->enable_ramfb && vdev->dpy == NULL) {
error_setg(errp, "ramfb=on requires display=on");
- goto out_teardown;
+ goto out_deregister;
}
if (vdev->display_xres || vdev->display_yres) {
if (vdev->dpy == NULL) {
error_setg(errp, "xres and yres properties require display=on");
- goto out_teardown;
+ goto out_deregister;
}
if (vdev->dpy->edid_regs == NULL) {
error_setg(errp, "xres and yres properties need edid support");
- goto out_teardown;
+ goto out_deregister;
}
}
@@ -3020,8 +3030,10 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
return;
-out_teardown:
+out_deregister:
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
+ kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier);
+out_teardown:
vfio_teardown_msi(vdev);
vfio_bars_exit(vdev);
error:
@@ -3064,6 +3076,7 @@ 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);
vfio_disable_interrupts(vdev);
if (vdev->intx.mmap_timer) {
timer_free(vdev->intx.mmap_timer);
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index b329d50338..35626cd63e 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -169,6 +169,7 @@ typedef struct VFIOPCIDevice {
bool enable_ramfb;
VFIODisplay *dpy;
Error *migration_blocker;
+ Notifier irqchip_change_notifier;
} VFIOPCIDevice;
uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len);
--
2.23.0
- [PULL 0/8] ppc-for-4.2 queue 20191126, David Gibson, 2019/11/26
- [PULL 8/8] ppc/spapr_events: fix potential NULL pointer dereference in rtas_event_log_dequeue, David Gibson, 2019/11/26
- [PULL 7/8] mos6522: update counters when timer interrupts are off, David Gibson, 2019/11/26
- [PULL 1/8] pseries: fix migration-test and pxe-test, David Gibson, 2019/11/26
- [PULL 4/8] vfio/pci: Respond to KVM irqchip change notifier,
David Gibson <=
- [PULL 5/8] spapr: Handle irq backend changes with VFIO PCI devices, David Gibson, 2019/11/26
- [PULL 6/8] spapr: Work around spurious warnings from vfio INTx initialization, David Gibson, 2019/11/26
- [PULL 3/8] vfio/pci: Split vfio_intx_update(), David Gibson, 2019/11/26
- [PULL 2/8] kvm: Introduce KVM irqchip change notifier, David Gibson, 2019/11/26
- Re: [PULL 0/8] ppc-for-4.2 queue 20191126, Peter Maydell, 2019/11/26