Skip to content

Commit 071e731

Browse files
committed
vfio/pci: Pass eventfd context to IRQ handler
Create a link back to the vfio_pci_core_device on the eventfd context object to avoid lookups in the interrupt path. The context is known valid in the interrupt handler. Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent af6605f commit 071e731

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

drivers/vfio/pci/vfio_pci_intrs.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#include "vfio_pci_priv.h"
2424

2525
struct vfio_pci_irq_ctx {
26-
struct eventfd_ctx *trigger;
27-
struct virqfd *unmask;
28-
struct virqfd *mask;
29-
char *name;
30-
bool masked;
26+
struct vfio_pci_core_device *vdev;
27+
struct eventfd_ctx *trigger;
28+
struct virqfd *unmask;
29+
struct virqfd *mask;
30+
char *name;
31+
bool masked;
3132
struct irq_bypass_producer producer;
3233
};
3334

@@ -228,15 +229,11 @@ void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev)
228229

229230
static irqreturn_t vfio_intx_handler(int irq, void *dev_id)
230231
{
231-
struct vfio_pci_core_device *vdev = dev_id;
232-
struct vfio_pci_irq_ctx *ctx;
232+
struct vfio_pci_irq_ctx *ctx = dev_id;
233+
struct vfio_pci_core_device *vdev = ctx->vdev;
233234
unsigned long flags;
234235
int ret = IRQ_NONE;
235236

236-
ctx = vfio_irq_ctx_get(vdev, 0);
237-
if (WARN_ON_ONCE(!ctx))
238-
return ret;
239-
240237
spin_lock_irqsave(&vdev->irqlock, flags);
241238

242239
if (!vdev->pci_2_3) {
@@ -282,6 +279,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
282279

283280
ctx->name = name;
284281
ctx->trigger = trigger;
282+
ctx->vdev = vdev;
285283

286284
/*
287285
* Fill the initial masked state based on virq_disabled. After
@@ -312,7 +310,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
312310
vdev->irq_type = VFIO_PCI_INTX_IRQ_INDEX;
313311

314312
ret = request_irq(pdev->irq, vfio_intx_handler,
315-
irqflags, ctx->name, vdev);
313+
irqflags, ctx->name, ctx);
316314
if (ret) {
317315
vdev->irq_type = VFIO_PCI_NUM_IRQS;
318316
kfree(name);
@@ -358,7 +356,7 @@ static void vfio_intx_disable(struct vfio_pci_core_device *vdev)
358356
if (ctx) {
359357
vfio_virqfd_disable(&ctx->unmask);
360358
vfio_virqfd_disable(&ctx->mask);
361-
free_irq(pdev->irq, vdev);
359+
free_irq(pdev->irq, ctx);
362360
if (ctx->trigger)
363361
eventfd_ctx_put(ctx->trigger);
364362
kfree(ctx->name);

0 commit comments

Comments
 (0)