We add two new fields in vfio_pci_irq_ctx struct: deoi and handler. If deoi is set, this means the physical IRQ attached to the virtual IRQ is directly deactivated by the guest and the VFIO driver does not need to disable the physical IRQ and mask it at VFIO level. The handler pointer is set accordingly and a wrapper handler is introduced that calls the chosen handler function. Signed-off-by: Eric Auger <eric.auger@xxxxxxxxxx> --- --- drivers/vfio/pci/vfio_pci_intrs.c | 32 ++++++++++++++++++++++++++------ drivers/vfio/pci/vfio_pci_private.h | 2 ++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index d4d377b..06aa713 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -121,11 +121,8 @@ void vfio_pci_intx_unmask(struct vfio_pci_device *vdev) static irqreturn_t vfio_intx_handler(int irq, void *dev_id) { struct vfio_pci_device *vdev = dev_id; - unsigned long flags; int ret = IRQ_NONE; - spin_lock_irqsave(&vdev->irqlock, flags); - if (!vdev->pci_2_3) { disable_irq_nosync(vdev->pdev->irq); vdev->ctx[0].automasked = true; @@ -137,14 +134,33 @@ static irqreturn_t vfio_intx_handler(int irq, void *dev_id) ret = IRQ_HANDLED; } - spin_unlock_irqrestore(&vdev->irqlock, flags); - if (ret == IRQ_HANDLED) vfio_send_intx_eventfd(vdev, NULL); return ret; } +static irqreturn_t vfio_intx_handler_deoi(int irq, void *dev_id) +{ + struct vfio_pci_device *vdev = dev_id; + + vfio_send_intx_eventfd(vdev, NULL); + return IRQ_HANDLED; +} + +static irqreturn_t vfio_intx_wrapper_handler(int irq, void *dev_id) +{ + struct vfio_pci_device *vdev = dev_id; + unsigned long flags; + irqreturn_t ret; + + spin_lock_irqsave(&vdev->irqlock, flags); + ret = vdev->ctx[0].handler(irq, dev_id); + spin_unlock_irqrestore(&vdev->irqlock, flags); + + return ret; +} + static int vfio_intx_enable(struct vfio_pci_device *vdev) { if (!is_irq_none(vdev)) @@ -208,7 +224,11 @@ static int vfio_intx_set_signal(struct vfio_pci_device *vdev, int fd) if (!vdev->pci_2_3) irqflags = 0; - ret = request_irq(pdev->irq, vfio_intx_handler, + if (vdev->ctx[0].deoi) + vdev->ctx[0].handler = vfio_intx_handler_deoi; + else + vdev->ctx[0].handler = vfio_intx_handler; + ret = request_irq(pdev->irq, vfio_intx_wrapper_handler, irqflags, vdev->ctx[0].name, vdev); if (ret) { vdev->ctx[0].trigger = NULL; diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index f7f1101..5cfe59a 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -36,6 +36,8 @@ struct vfio_pci_irq_ctx { char *name; bool masked; bool automasked; + bool deoi; + irqreturn_t (*handler)(int irq, void *dev_id); struct irq_bypass_producer producer; }; -- 2.5.5