drivers/virt/acrn/irqfd.c
Source file repositories/reference/linux-study-clean/drivers/virt/acrn/irqfd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virt/acrn/irqfd.c- Extension
.c- Size
- 5291 bytes
- Lines
- 228
- Domain
- Driver Families
- Bucket
- drivers/virt
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/eventfd.hlinux/file.hlinux/poll.hlinux/slab.hacrn_drv.h
Detected Declarations
struct hsm_irqfdfunction acrn_irqfd_injectfunction hsm_irqfd_shutdownfunction hsm_irqfd_shutdown_workfunction hsm_irqfd_wakeupfunction hsm_irqfd_poll_funcfunction acrn_irqfd_assignfunction acrn_irqfd_deassignfunction acrn_irqfd_configfunction acrn_irqfd_initfunction acrn_irqfd_deinit
Annotated Snippet
struct hsm_irqfd {
struct acrn_vm *vm;
wait_queue_entry_t wait;
struct work_struct shutdown;
struct eventfd_ctx *eventfd;
struct list_head list;
poll_table pt;
struct acrn_msi_entry msi;
};
static void acrn_irqfd_inject(struct hsm_irqfd *irqfd)
{
struct acrn_vm *vm = irqfd->vm;
acrn_msi_inject(vm, irqfd->msi.msi_addr,
irqfd->msi.msi_data);
}
static void hsm_irqfd_shutdown(struct hsm_irqfd *irqfd)
{
u64 cnt;
lockdep_assert_held(&irqfd->vm->irqfds_lock);
/* remove from wait queue */
list_del_init(&irqfd->list);
eventfd_ctx_remove_wait_queue(irqfd->eventfd, &irqfd->wait, &cnt);
eventfd_ctx_put(irqfd->eventfd);
kfree(irqfd);
}
static void hsm_irqfd_shutdown_work(struct work_struct *work)
{
struct hsm_irqfd *irqfd;
struct acrn_vm *vm;
irqfd = container_of(work, struct hsm_irqfd, shutdown);
vm = irqfd->vm;
mutex_lock(&vm->irqfds_lock);
if (!list_empty(&irqfd->list))
hsm_irqfd_shutdown(irqfd);
mutex_unlock(&vm->irqfds_lock);
}
/* Called with wqh->lock held and interrupts disabled */
static int hsm_irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode,
int sync, void *key)
{
unsigned long poll_bits = (unsigned long)key;
struct hsm_irqfd *irqfd;
struct acrn_vm *vm;
irqfd = container_of(wait, struct hsm_irqfd, wait);
vm = irqfd->vm;
if (poll_bits & POLLIN)
/* An event has been signaled, inject an interrupt */
acrn_irqfd_inject(irqfd);
if (poll_bits & POLLHUP)
/* Do shutdown work in thread to hold wqh->lock */
queue_work(vm->irqfd_wq, &irqfd->shutdown);
return 0;
}
static void hsm_irqfd_poll_func(struct file *file, wait_queue_head_t *wqh,
poll_table *pt)
{
struct hsm_irqfd *irqfd;
irqfd = container_of(pt, struct hsm_irqfd, pt);
add_wait_queue(wqh, &irqfd->wait);
}
/*
* Assign an eventfd to a VM and create a HSM irqfd associated with the
* eventfd. The properties of the HSM irqfd are built from a &struct
* acrn_irqfd.
*/
static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)
{
struct eventfd_ctx *eventfd = NULL;
struct hsm_irqfd *irqfd, *tmp;
__poll_t events;
int ret = 0;
irqfd = kzalloc_obj(*irqfd);
if (!irqfd)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/eventfd.h`, `linux/file.h`, `linux/poll.h`, `linux/slab.h`, `acrn_drv.h`.
- Detected declarations: `struct hsm_irqfd`, `function acrn_irqfd_inject`, `function hsm_irqfd_shutdown`, `function hsm_irqfd_shutdown_work`, `function hsm_irqfd_wakeup`, `function hsm_irqfd_poll_func`, `function acrn_irqfd_assign`, `function acrn_irqfd_deassign`, `function acrn_irqfd_config`, `function acrn_irqfd_init`.
- Atlas domain: Driver Families / drivers/virt.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.