Skip to content

Commit b5c5435

Browse files
committed
KVM: Initialize irqfd waitqueue callback when adding to the queue
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>
1 parent 140768a commit b5c5435

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

virt/kvm/eventfd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ static void kvm_irqfd_register(struct file *file, wait_queue_head_t *wqh,
256256
struct kvm_irqfd_pt *p = container_of(pt, struct kvm_irqfd_pt, pt);
257257
struct kvm_kernel_irqfd *irqfd = p->irqfd;
258258

259+
/*
260+
* Add the irqfd as a priority waiter on the eventfd, with a custom
261+
* wake-up handler, so that KVM *and only KVM* is notified whenever the
262+
* underlying eventfd is signaled.
263+
*/
264+
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
265+
259266
add_wait_queue_priority(wqh, &irqfd->wait);
260267
}
261268

@@ -388,12 +395,6 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
388395
mutex_unlock(&kvm->irqfds.resampler_lock);
389396
}
390397

391-
/*
392-
* Install our own custom wake-up handling so we are notified via
393-
* a callback whenever someone signals the underlying eventfd
394-
*/
395-
init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
396-
397398
/*
398399
* Set the irqfd routing and add it to KVM's list before registering
399400
* the irqfd with the eventfd, so that the routing information is valid

0 commit comments

Comments
 (0)