irqbypass: Require producers to pass in Linux IRQ number during registration

Pass in the Linux IRQ associated with an IRQ bypass producer instead of
relying on the caller to set the field prior to registration, as there's
no benefit to relying on callers to do the right thing.

Take care to set producer->irq before __connect(), as KVM expects the IRQ
to be valid as soon as a connection is possible.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://lore.kernel.org/r/20250516230734.2564775-9-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
Sean Christopherson
2025-05-16 16:07:34 -07:00
parent 8394b32fae
commit 23b54381ce
4 changed files with 8 additions and 6 deletions

View File

@@ -85,12 +85,13 @@ static void __disconnect(struct irq_bypass_producer *prod,
* irq_bypass_register_producer - register IRQ bypass producer
* @producer: pointer to producer structure
* @eventfd: pointer to the eventfd context associated with the producer
* @irq: Linux IRQ number of the underlying producer device
*
* Add the provided IRQ producer to the set of producers and connect with the
* consumer with a matching eventfd, if one exists.
*/
int irq_bypass_register_producer(struct irq_bypass_producer *producer,
struct eventfd_ctx *eventfd)
struct eventfd_ctx *eventfd, int irq)
{
unsigned long index = (unsigned long)eventfd;
struct irq_bypass_consumer *consumer;
@@ -99,6 +100,8 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer,
if (WARN_ON_ONCE(producer->eventfd))
return -EINVAL;
producer->irq = irq;
guard(mutex)(&lock);
ret = xa_insert(&producers, index, producer, GFP_KERNEL);