]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
irqbypass: Explicitly track producer and consumer bindings
authorSean Christopherson <seanjc@google.com>
Fri, 16 May 2025 23:07:30 +0000 (16:07 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:52:38 +0000 (13:52 -0700)
Explicitly track IRQ bypass producer:consumer bindings.  This will allow
making removal an O(1) operation; searching through the list to find
information that is trivially tracked (and useful for debug) is wasteful.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Link: https://lore.kernel.org/r/20250516230734.2564775-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
include/linux/irqbypass.h
virt/lib/irqbypass.c

index 1b57d15ac4cf21e7c009508cb55ca2bec7f9e0b8..b28197c87483c1d17d5c3f1f72c9e062ffe6bfa5 100644 (file)
@@ -29,10 +29,13 @@ struct irq_bypass_consumer;
  * pairings are not supported.
  */
 
+struct irq_bypass_consumer;
+
 /**
  * struct irq_bypass_producer - IRQ bypass producer definition
  * @node: IRQ bypass manager private list management
  * @eventfd: eventfd context used to match producers and consumers
+ * @consumer: The connected consumer (NULL if no connection)
  * @irq: Linux IRQ number for the producer device
  * @add_consumer: Connect the IRQ producer to an IRQ consumer (optional)
  * @del_consumer: Disconnect the IRQ producer from an IRQ consumer (optional)
@@ -46,6 +49,7 @@ struct irq_bypass_consumer;
 struct irq_bypass_producer {
        struct list_head node;
        struct eventfd_ctx *eventfd;
+       struct irq_bypass_consumer *consumer;
        int irq;
        int (*add_consumer)(struct irq_bypass_producer *,
                            struct irq_bypass_consumer *);
@@ -59,6 +63,7 @@ struct irq_bypass_producer {
  * struct irq_bypass_consumer - IRQ bypass consumer definition
  * @node: IRQ bypass manager private list management
  * @eventfd: eventfd context used to match producers and consumers
+ * @producer: The connected producer (NULL if no connection)
  * @add_producer: Connect the IRQ consumer to an IRQ producer
  * @del_producer: Disconnect the IRQ consumer from an IRQ producer
  * @stop: Perform any quiesce operations necessary prior to add/del (optional)
@@ -72,6 +77,8 @@ struct irq_bypass_producer {
 struct irq_bypass_consumer {
        struct list_head node;
        struct eventfd_ctx *eventfd;
+       struct irq_bypass_producer *producer;
+
        int (*add_producer)(struct irq_bypass_consumer *,
                            struct irq_bypass_producer *);
        void (*del_producer)(struct irq_bypass_consumer *,
index e8d7c420db52c89558f68753a4646b397a3fef2c..fdbf7ecc0c21909d13c300c361d1178436e224dd 100644 (file)
@@ -51,6 +51,10 @@ static int __connect(struct irq_bypass_producer *prod,
        if (prod->start)
                prod->start(prod);
 
+       if (!ret) {
+               prod->consumer = cons;
+               cons->producer = prod;
+       }
        return ret;
 }
 
@@ -72,6 +76,9 @@ static void __disconnect(struct irq_bypass_producer *prod,
                cons->start(cons);
        if (prod->start)
                prod->start(prod);
+
+       prod->consumer = NULL;
+       cons->producer = NULL;
 }
 
 /**
@@ -145,6 +152,7 @@ void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
 
                list_for_each_entry(consumer, &consumers, node) {
                        if (consumer->eventfd == producer->eventfd) {
+                               WARN_ON_ONCE(producer->consumer != consumer);
                                __disconnect(producer, consumer);
                                break;
                        }
@@ -234,6 +242,7 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
 
                list_for_each_entry(producer, &producers, node) {
                        if (producer->eventfd == consumer->eventfd) {
+                               WARN_ON_ONCE(consumer->producer != producer);
                                __disconnect(producer, consumer);
                                break;
                        }