drivers/vhost/vhost.h

Source file repositories/reference/linux-study-clean/drivers/vhost/vhost.h

File Facts

System
Linux kernel
Corpus path
drivers/vhost/vhost.h
Extension
.h
Size
12019 bytes
Lines
405
Domain
Driver Families
Bucket
drivers/vhost
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct vhost_work {
	struct llist_node	node;
	vhost_work_fn_t		fn;
	unsigned long		flags;
};

struct vhost_worker;
struct vhost_dev;

struct vhost_worker_ops {
	int (*create)(struct vhost_worker *worker, struct vhost_dev *dev,
		      const char *name);
	void (*stop)(struct vhost_worker *worker);
	void (*wakeup)(struct vhost_worker *worker);
};

struct vhost_worker {
	struct task_struct *kthread_task;
	struct vhost_task	*vtsk;
	struct vhost_dev	*dev;
	/* Used to serialize device wide flushing with worker swapping. */
	struct mutex		mutex;
	struct llist_head	work_list;
	struct kcov_common_handle_id kcov_handle;
	u32			id;
	int			attachment_cnt;
	bool			killed;
	const struct vhost_worker_ops *ops;
};

/* Poll a file (eventfd or socket) */
/* Note: there's nothing vhost specific about this structure. */
struct vhost_poll {
	poll_table		table;
	wait_queue_head_t	*wqh;
	wait_queue_entry_t	wait;
	struct vhost_work	work;
	__poll_t		mask;
	struct vhost_dev	*dev;
	struct vhost_virtqueue	*vq;
};

void vhost_poll_init(struct vhost_poll *poll, vhost_work_fn_t fn,
		     __poll_t mask, struct vhost_dev *dev,
		     struct vhost_virtqueue *vq);
int vhost_poll_start(struct vhost_poll *poll, struct file *file);
void vhost_poll_stop(struct vhost_poll *poll);
void vhost_poll_queue(struct vhost_poll *poll);

void vhost_work_init(struct vhost_work *work, vhost_work_fn_t fn);
void vhost_dev_flush(struct vhost_dev *dev);

struct vhost_log {
	u64 addr;
	u64 len;
};

enum vhost_uaddr_type {
	VHOST_ADDR_DESC = 0,
	VHOST_ADDR_AVAIL = 1,
	VHOST_ADDR_USED = 2,
	VHOST_NUM_ADDRS = 3,
};

struct vhost_vring_call {
	struct eventfd_ctx *ctx;
	struct irq_bypass_producer producer;
};

/* The virtqueue structure describes a queue attached to a device. */
struct vhost_virtqueue {
	struct vhost_dev *dev;
	struct vhost_worker __rcu *worker;

	/* The actual ring of buffers. */
	struct mutex mutex;
	unsigned int num;
	vring_desc_t __user *desc;
	vring_avail_t __user *avail;
	vring_used_t __user *used;
	const struct vhost_iotlb_map *meta_iotlb[VHOST_NUM_ADDRS];
	struct file *kick;
	struct vhost_vring_call call_ctx;
	struct eventfd_ctx *error_ctx;
	struct eventfd_ctx *log_ctx;

	struct vhost_poll poll;

	/* The routine to call when the Guest pings us, or timeout. */
	vhost_work_fn_t handle_kick;

Annotation

Implementation Notes