drivers/vhost/vhost.c
Source file repositories/reference/linux-study-clean/drivers/vhost/vhost.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/vhost.c- Extension
.c- Size
- 81309 bytes
- Lines
- 3331
- Domain
- Driver Families
- Bucket
- drivers/vhost
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/eventfd.hlinux/vhost.hlinux/uio.hlinux/mm.hlinux/miscdevice.hlinux/mutex.hlinux/poll.hlinux/file.hlinux/highmem.hlinux/slab.hlinux/vmalloc.hlinux/kthread.hlinux/cgroup.hlinux/module.hlinux/sort.hlinux/sched/mm.hlinux/sched/signal.hlinux/sched/vhost_task.hlinux/interval_tree_generic.hlinux/nospec.hlinux/kcov.hvhost.h
Detected Declarations
struct vhost_flush_structstruct vhost_attach_cgroups_structfunction vhost_disable_cross_endianfunction vhost_enable_cross_endian_bigfunction vhost_enable_cross_endian_littlefunction vhost_set_vring_endianfunction vhost_get_vring_endianfunction vhost_init_is_lefunction vhost_disable_cross_endianfunction vhost_get_vring_endianfunction vhost_init_is_lefunction vhost_reset_is_lefunction vhost_flush_workfunction vhost_poll_funcfunction vhost_poll_wakeupfunction vhost_work_initfunction vhost_poll_initfunction vhost_poll_startfunction vhost_poll_stopfunction vhost_worker_queuefunction vhost_vq_work_queuefunction __vhost_worker_flushfunction vhost_worker_flushfunction vhost_dev_flushfunction vhost_vq_has_workfunction vhost_poll_queuefunction __vhost_vq_meta_resetfunction vhost_vq_meta_resetfunction vhost_vring_call_resetfunction vhost_vq_is_setupfunction vhost_vq_resetfunction vhost_run_work_kthread_listfunction llist_for_each_entry_safefunction vhost_run_work_listfunction llist_for_each_entry_safefunction vhost_worker_killedfunction vhost_vq_free_iovecsfunction vhost_dev_alloc_iovecsfunction vhost_dev_free_iovecsfunction vhost_exceeds_weightfunction vhost_get_avail_sizefunction vhost_get_used_sizefunction vhost_get_desc_sizefunction vhost_dev_initfunction vhost_dev_check_ownerfunction vhost_attach_cgroups_workfunction vhost_attach_task_to_cgroupsfunction vhost_dev_has_owner
Annotated Snippet
struct vhost_flush_struct {
struct vhost_work work;
struct completion wait_event;
};
static void vhost_flush_work(struct vhost_work *work)
{
struct vhost_flush_struct *s;
s = container_of(work, struct vhost_flush_struct, work);
complete(&s->wait_event);
}
static void vhost_poll_func(struct file *file, wait_queue_head_t *wqh,
poll_table *pt)
{
struct vhost_poll *poll;
poll = container_of(pt, struct vhost_poll, table);
poll->wqh = wqh;
add_wait_queue(wqh, &poll->wait);
}
static int vhost_poll_wakeup(wait_queue_entry_t *wait, unsigned mode, int sync,
void *key)
{
struct vhost_poll *poll = container_of(wait, struct vhost_poll, wait);
struct vhost_work *work = &poll->work;
if (!(key_to_poll(key) & poll->mask))
return 0;
if (!poll->dev->use_worker)
work->fn(work);
else
vhost_poll_queue(poll);
return 0;
}
void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn)
{
clear_bit(VHOST_WORK_QUEUED, &work->flags);
work->fn = fn;
}
EXPORT_SYMBOL_GPL(vhost_work_init);
/* Init poll structure */
void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
__poll_t mask, struct vhost_dev *dev,
struct vhost_virtqueue *vq)
{
init_waitqueue_func_entry(&poll->wait, vhost_poll_wakeup);
init_poll_funcptr(&poll->table, vhost_poll_func);
poll->mask = mask;
poll->dev = dev;
poll->wqh = NULL;
poll->vq = vq;
vhost_work_init(&poll->work, fn);
}
EXPORT_SYMBOL_GPL(vhost_poll_init);
/* Start polling a file. We add ourselves to file's wait queue. The caller must
* keep a reference to a file until after vhost_poll_stop is called. */
int vhost_poll_start(struct vhost_poll *poll, struct file *file)
{
__poll_t mask;
if (poll->wqh)
return 0;
mask = vfs_poll(file, &poll->table);
if (mask)
vhost_poll_wakeup(&poll->wait, 0, 0, poll_to_key(mask));
if (mask & EPOLLERR) {
vhost_poll_stop(poll);
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL_GPL(vhost_poll_start);
/* Stop polling a file. After this function returns, it becomes safe to drop the
* file reference. You must also flush afterwards. */
void vhost_poll_stop(struct vhost_poll *poll)
{
if (poll->wqh) {
remove_wait_queue(poll->wqh, &poll->wait);
Annotation
- Immediate include surface: `linux/eventfd.h`, `linux/vhost.h`, `linux/uio.h`, `linux/mm.h`, `linux/miscdevice.h`, `linux/mutex.h`, `linux/poll.h`, `linux/file.h`.
- Detected declarations: `struct vhost_flush_struct`, `struct vhost_attach_cgroups_struct`, `function vhost_disable_cross_endian`, `function vhost_enable_cross_endian_big`, `function vhost_enable_cross_endian_little`, `function vhost_set_vring_endian`, `function vhost_get_vring_endian`, `function vhost_init_is_le`, `function vhost_disable_cross_endian`, `function vhost_get_vring_endian`.
- Atlas domain: Driver Families / drivers/vhost.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.