]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: Initialize irqfd waitqueue callback when adding to the queue
authorSean Christopherson <seanjc@google.com>
Thu, 22 May 2025 23:52:13 +0000 (16:52 -0700)
committerSean Christopherson <seanjc@google.com>
Mon, 23 Jun 2025 16:50:55 +0000 (09:50 -0700)
Initialize the irqfd waitqueue callback immediately prior to inserting the
irqfd into the eventfd's waitqueue.  Pre-initializing the state in a
completely different context is all kinds of confusing, and incorrectly
suggests that the waitqueue function needs to be initialize prior to
vfs_poll().

Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20250522235223.3178519-4-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
virt/kvm/eventfd.c

index 614f81cd37c11bb71e8d03f54c721790427b6581..7b7c5269cf18b584d9fb46d2343606c2f7bc0035 100644 (file)
@@ -256,6 +256,13 @@ static void kvm_irqfd_register(struct file *file, wait_queue_head_t *wqh,
        struct kvm_irqfd_pt *p = container_of(pt, struct kvm_irqfd_pt, pt);
        struct kvm_kernel_irqfd *irqfd = p->irqfd;
 
+       /*
+        * Add the irqfd as a priority waiter on the eventfd, with a custom
+        * wake-up handler, so that KVM *and only KVM* is notified whenever the
+        * underlying eventfd is signaled.
+        */
+       init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
+
        add_wait_queue_priority(wqh, &irqfd->wait);
 }
 
@@ -388,12 +395,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
                mutex_unlock(&kvm->irqfds.resampler_lock);
        }
 
-       /*
-        * Install our own custom wake-up handling so we are notified via
-        * a callback whenever someone signals the underlying eventfd
-        */
-       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