drivers/vhost/net.c
Source file repositories/reference/linux-study-clean/drivers/vhost/net.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/net.c- Extension
.c- Size
- 48288 bytes
- Lines
- 1911
- Domain
- Driver Families
- Bucket
- drivers/vhost
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/compat.hlinux/eventfd.hlinux/vhost.hlinux/virtio_net.hlinux/miscdevice.hlinux/module.hlinux/moduleparam.hlinux/mutex.hlinux/workqueue.hlinux/file.hlinux/slab.hlinux/sched/clock.hlinux/sched/signal.hlinux/vmalloc.hlinux/net.hlinux/if_packet.hlinux/if_arp.hlinux/if_tun.hlinux/if_macvlan.hlinux/if_tap.hlinux/if_vlan.hlinux/skb_array.hlinux/skbuff.hnet/sock.hnet/xdp.hvhost.h
Detected Declarations
struct vhost_net_ubuf_refstruct vhost_net_bufstruct vhost_net_virtqueuestruct vhost_netfunction vhost_net_buf_get_sizefunction vhost_net_buf_is_emptyfunction vhost_net_buf_producefunction vhost_net_buf_unproducefunction vhost_net_buf_peek_lenfunction vhost_net_buf_peekfunction vhost_net_buf_initfunction vhost_net_enable_zcopyfunction vhost_net_ubuf_allocfunction vhost_net_ubuf_putfunction vhost_net_ubuf_put_and_waitfunction vhost_net_ubuf_put_wait_and_freefunction vhost_net_clear_ubuf_infofunction vhost_net_set_ubuf_infofunction vhost_net_vq_resetfunction vhost_net_tx_packetfunction vhost_net_tx_errfunction vhost_net_tx_select_zcopyfunction vhost_sock_zcopyfunction vhost_sock_xdpfunction vhost_zerocopy_signal_usedfunction vhost_zerocopy_completefunction busy_clockfunction vhost_can_busy_pollfunction vhost_net_disable_vqfunction vhost_net_enable_vqfunction vhost_net_signal_usedfunction vhost_tx_batchfunction sock_has_rx_datafunction vhost_net_busy_poll_try_queuefunction vhost_net_busy_pollfunction vhost_net_tx_get_vq_descfunction vhost_exceeds_maxpendfunction init_iov_iterfunction get_tx_bufsfunction tx_can_batchfunction vhost_net_build_xdpfunction handle_tx_copyfunction handle_tx_zerocopyfunction handle_txfunction peek_head_lenfunction vhost_net_rx_peek_head_lenfunction get_rx_bufsfunction handle_rx
Annotated Snippet
static const struct file_operations vhost_net_fops = {
.owner = THIS_MODULE,
.release = vhost_net_release,
.read_iter = vhost_net_chr_read_iter,
.write_iter = vhost_net_chr_write_iter,
.poll = vhost_net_chr_poll,
.unlocked_ioctl = vhost_net_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = vhost_net_open,
.llseek = noop_llseek,
};
static struct miscdevice vhost_net_misc = {
.minor = VHOST_NET_MINOR,
.name = "vhost-net",
.fops = &vhost_net_fops,
};
static int __init vhost_net_init(void)
{
if (experimental_zcopytx)
vhost_net_enable_zcopy(VHOST_NET_VQ_TX);
return misc_register(&vhost_net_misc);
}
module_init(vhost_net_init);
static void __exit vhost_net_exit(void)
{
misc_deregister(&vhost_net_misc);
}
module_exit(vhost_net_exit);
MODULE_VERSION("0.0.1");
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Michael S. Tsirkin");
MODULE_DESCRIPTION("Host kernel accelerator for virtio net");
MODULE_ALIAS_MISCDEV(VHOST_NET_MINOR);
MODULE_ALIAS("devname:vhost-net");
Annotation
- Immediate include surface: `linux/compat.h`, `linux/eventfd.h`, `linux/vhost.h`, `linux/virtio_net.h`, `linux/miscdevice.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/mutex.h`.
- Detected declarations: `struct vhost_net_ubuf_ref`, `struct vhost_net_buf`, `struct vhost_net_virtqueue`, `struct vhost_net`, `function vhost_net_buf_get_size`, `function vhost_net_buf_is_empty`, `function vhost_net_buf_produce`, `function vhost_net_buf_unproduce`, `function vhost_net_buf_peek_len`, `function vhost_net_buf_peek`.
- Atlas domain: Driver Families / drivers/vhost.
- Implementation status: pattern 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.