*/
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
+ /*
+ * Set the irqfd routing and add it to KVM's list before registering
+ * the irqfd with the eventfd, so that the routing information is valid
+ * and stays valid, e.g. if there are GSI routing changes, prior to
+ * making the irqfd visible, i.e. before it might be signaled.
+ *
+ * Note, holding SRCU ensures a stable read of routing information, and
+ * also prevents irqfd_shutdown() from freeing the irqfd before it's
+ * fully initialized.
+ */
+ idx = srcu_read_lock(&kvm->irq_srcu);
+
spin_lock_irq(&kvm->irqfds.lock);
ret = 0;
continue;
/* This fd is used for another irq already. */
ret = -EBUSY;
- spin_unlock_irq(&kvm->irqfds.lock);
- goto fail;
+ goto fail_duplicate;
}
- idx = srcu_read_lock(&kvm->irq_srcu);
irqfd_update(kvm, irqfd);
list_add_tail(&irqfd->list, &kvm->irqfds.items);
srcu_read_unlock(&kvm->irq_srcu, idx);
return 0;
+fail_duplicate:
+ spin_unlock_irq(&kvm->irqfds.lock);
+ srcu_read_unlock(&kvm->irq_srcu, idx);
fail:
if (irqfd->resampler)
irqfd_resampler_shutdown(irqfd);