drivers/virtio/virtio_ring.c
Source file repositories/reference/linux-study-clean/drivers/virtio/virtio_ring.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/virtio/virtio_ring.c- Extension
.c- Size
- 105572 bytes
- Lines
- 3984
- Domain
- Driver Families
- Bucket
- drivers/virtio
- 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.
- 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/virtio.hlinux/virtio_ring.hlinux/virtio_config.hlinux/device.hlinux/slab.hlinux/module.hlinux/hrtimer.hlinux/dma-mapping.hlinux/kmsan.hlinux/spinlock.hxen/xen.h
Detected Declarations
struct vring_desc_state_splitstruct vring_desc_state_packedstruct vring_desc_extrastruct vring_virtqueue_splitstruct vring_virtqueue_packedstruct vring_virtqueuestruct virtqueue_opsstruct vring_virtqueuestruct used_entryenum vq_layoutfunction READ_ONCEfunction vring_read_split_used_idfunction vring_read_split_used_lenfunction vring_read_split_avail_eventfunction vring_read_packed_desc_flagsfunction vring_read_packed_desc_idfunction vring_read_packed_desc_lenfunction virtqueue_is_packedfunction virtqueue_is_in_orderfunction virtqueue_use_indirectfunction vring_use_map_apifunction vring_need_unmap_bufferfunction virtio_max_dma_sizefunction vring_free_queuefunction vring_mapping_errorfunction vring_map_one_sgfunction vring_map_singlefunction virtqueue_initfunction vring_unmap_one_splitfunction virtqueue_add_desc_splitfunction virtqueue_add_splitfunction virtqueue_kick_prepare_splitfunction detach_indirect_splitfunction detach_buf_split_in_orderfunction detach_buf_splitfunction virtqueue_poll_splitfunction more_used_splitfunction more_used_split_in_orderfunction virtqueue_disable_cb_splitfunction virtqueue_enable_cb_prepare_splitfunction virtqueue_enable_cb_delayed_splitfunction virtqueue_vring_init_splitfunction virtqueue_reset_splitfunction virtqueue_vring_attach_splitfunction vring_alloc_state_extra_splitfunction vring_free_splitfunction vring_alloc_queue_splitfunction bool
Annotated Snippet
struct vring_desc_state_split {
void *data; /* Data for callback. */
/* Indirect desc table and extra table, if any. These two will be
* allocated together. So we won't stress more to the memory allocator.
*/
struct vring_desc *indir_desc;
u32 total_in_len;
};
struct vring_desc_state_packed {
void *data; /* Data for callback. */
/* Indirect desc table and extra table, if any. These two will be
* allocated together. So we won't stress more to the memory allocator.
*/
struct vring_packed_desc *indir_desc;
u16 num; /* Descriptor list length. */
u16 last; /* The last desc state in a list. */
u32 total_in_len; /* In length for the skipped buffer. */
};
struct vring_desc_extra {
dma_addr_t addr; /* Descriptor DMA addr. */
u32 len; /* Descriptor length. */
u16 flags; /* Descriptor flags. */
u16 next; /* The next desc state in a list. */
};
struct vring_virtqueue_split {
/* Actual memory layout for this queue. */
struct vring vring;
/* Last written value to avail->flags */
u16 avail_flags_shadow;
/*
* Last written value to avail->idx in
* guest byte order.
*/
u16 avail_idx_shadow;
/* Per-descriptor state. */
struct vring_desc_state_split *desc_state;
struct vring_desc_extra *desc_extra;
/* DMA address and size information */
dma_addr_t queue_dma_addr;
size_t queue_size_in_bytes;
/*
* The parameters for creating vrings are reserved for creating new
* vring.
*/
u32 vring_align;
bool may_reduce_num;
};
struct vring_virtqueue_packed {
/* Actual memory layout for this queue. */
struct {
unsigned int num;
struct vring_packed_desc *desc;
struct vring_packed_desc_event *driver;
struct vring_packed_desc_event *device;
} vring;
/* Driver ring wrap counter. */
bool avail_wrap_counter;
/* Avail used flags. */
u16 avail_used_flags;
/* Index of the next avail descriptor. */
u16 next_avail_idx;
/*
* Last written value to driver->flags in
* guest byte order.
*/
u16 event_flags_shadow;
/* Per-descriptor state. */
struct vring_desc_state_packed *desc_state;
struct vring_desc_extra *desc_extra;
/* DMA address and size information */
dma_addr_t ring_dma_addr;
dma_addr_t driver_event_dma_addr;
dma_addr_t device_event_dma_addr;
Annotation
- Immediate include surface: `linux/virtio.h`, `linux/virtio_ring.h`, `linux/virtio_config.h`, `linux/device.h`, `linux/slab.h`, `linux/module.h`, `linux/hrtimer.h`, `linux/dma-mapping.h`.
- Detected declarations: `struct vring_desc_state_split`, `struct vring_desc_state_packed`, `struct vring_desc_extra`, `struct vring_virtqueue_split`, `struct vring_virtqueue_packed`, `struct vring_virtqueue`, `struct virtqueue_ops`, `struct vring_virtqueue`, `struct used_entry`, `enum vq_layout`.
- Atlas domain: Driver Families / drivers/virtio.
- Implementation status: integration 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.