virt/kvm/eventfd.c
Source file repositories/reference/linux-study-clean/virt/kvm/eventfd.c
File Facts
- System
- Linux kernel
- Corpus path
virt/kvm/eventfd.c- Extension
.c- Size
- 26272 bytes
- Lines
- 1053
- Domain
- Kernel Services
- Bucket
- virt
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_host.hlinux/kvm.hlinux/kvm_irqfd.hlinux/workqueue.hlinux/syscalls.hlinux/wait.hlinux/poll.hlinux/file.hlinux/list.hlinux/eventfd.hlinux/kernel.hlinux/srcu.hlinux/slab.hlinux/seqlock.hlinux/irqbypass.htrace/events/kvm.hkvm/iodev.h
Detected Declarations
struct kvm_irqfd_ptstruct _ioeventfdfunction __attribute__function irqfd_injectfunction irqfd_resampler_notifyfunction irqfd_resampler_ackfunction irqfd_resampler_shutdownfunction irqfd_shutdownfunction irqfd_is_activefunction irqfd_deactivatefunction __attribute__function irqfd_wakeupfunction irqfd_updatefunction kvm_irqfd_registerfunction __attribute__function list_for_each_entryfunction kvm_irq_has_notifierfunction hlist_for_each_entry_srcufunction kvm_notify_acked_gsifunction kvm_notify_acked_irqfunction kvm_register_irq_ack_notifierfunction kvm_unregister_irq_ack_notifierfunction kvm_irqfd_deassignfunction list_for_each_entry_safefunction kvm_irqfdfunction kvm_irqfd_releasefunction synchronize_srcu_expeditedfunction list_for_each_entryfunction kvm_notify_irqfd_resamplerfunction list_for_each_entry_srcufunction kvm_irqfd_initfunction kvm_irqfd_exitfunction to_ioeventfdfunction ioeventfd_releasefunction ioeventfd_in_rangefunction ioeventfd_writefunction ioeventfd_destructorfunction ioeventfd_check_collisionfunction ioeventfd_bus_from_flagsfunction kvm_assign_ioeventfd_idxfunction kvm_deassign_ioeventfd_idxfunction list_for_each_entryfunction kvm_deassign_ioeventfdfunction kvm_assign_ioeventfdfunction kvm_ioeventfdfunction kvm_eventfd_init
Annotated Snippet
struct kvm_irqfd_pt {
struct kvm_kernel_irqfd *irqfd;
struct kvm *kvm;
poll_table pt;
int ret;
};
static void kvm_irqfd_register(struct file *file, wait_queue_head_t *wqh,
poll_table *pt)
{
struct kvm_irqfd_pt *p = container_of(pt, struct kvm_irqfd_pt, pt);
struct kvm_kernel_irqfd *irqfd = p->irqfd;
struct kvm *kvm = p->kvm;
/*
* Note, irqfds.lock protects the irqfd's irq_entry, i.e. its routing,
* and irqfds.items. It does NOT protect registering with the eventfd.
*/
spin_lock_irq(&kvm->irqfds.lock);
/*
* Initialize the routing information prior to adding the irqfd to the
* eventfd's waitqueue, as irqfd_wakeup() can be invoked as soon as the
* irqfd is registered.
*/
irqfd_update(kvm, 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);
/*
* Temporarily lie to lockdep about holding irqfds.lock to avoid a
* false positive regarding potential deadlock with irqfd_wakeup()
* (see irqfd_wakeup() for details).
*
* Adding to the wait queue will fail if there is already a priority
* waiter, i.e. if the eventfd is associated with another irqfd (in any
* VM). Note, kvm_irqfd_deassign() waits for all in-flight shutdown
* jobs to complete, i.e. ensures the irqfd has been removed from the
* eventfd's waitqueue before returning to userspace.
*/
spin_release(&kvm->irqfds.lock.dep_map, _RET_IP_);
p->ret = add_wait_queue_priority_exclusive(wqh, &irqfd->wait);
spin_acquire(&kvm->irqfds.lock.dep_map, 0, 0, _RET_IP_);
if (p->ret)
goto out;
list_add_tail(&irqfd->list, &kvm->irqfds.items);
out:
spin_unlock_irq(&kvm->irqfds.lock);
}
#if IS_ENABLED(CONFIG_HAVE_KVM_IRQ_BYPASS)
void __attribute__((weak)) kvm_arch_irq_bypass_stop(
struct irq_bypass_consumer *cons)
{
}
void __attribute__((weak)) kvm_arch_irq_bypass_start(
struct irq_bypass_consumer *cons)
{
}
void __weak kvm_arch_update_irqfd_routing(struct kvm_kernel_irqfd *irqfd,
struct kvm_kernel_irq_routing_entry *old,
struct kvm_kernel_irq_routing_entry *new)
{
}
#endif
static int
kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *args)
{
struct kvm_kernel_irqfd *irqfd;
struct eventfd_ctx *eventfd = NULL, *resamplefd = NULL;
struct kvm_irqfd_pt irqfd_pt;
int ret;
__poll_t events;
int idx;
if (!kvm_arch_intc_initialized(kvm))
return -EAGAIN;
if (!kvm_arch_irqfd_allowed(kvm, args))
Annotation
- Immediate include surface: `linux/kvm_host.h`, `linux/kvm.h`, `linux/kvm_irqfd.h`, `linux/workqueue.h`, `linux/syscalls.h`, `linux/wait.h`, `linux/poll.h`, `linux/file.h`.
- Detected declarations: `struct kvm_irqfd_pt`, `struct _ioeventfd`, `function __attribute__`, `function irqfd_inject`, `function irqfd_resampler_notify`, `function irqfd_resampler_ack`, `function irqfd_resampler_shutdown`, `function irqfd_shutdown`, `function irqfd_is_active`, `function irqfd_deactivate`.
- Atlas domain: Kernel Services / virt.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.