drivers/vhost/vdpa.c
Source file repositories/reference/linux-study-clean/drivers/vhost/vdpa.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vhost/vdpa.c- Extension
.c- Size
- 40185 bytes
- Lines
- 1699
- 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.
- 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/kernel.hlinux/module.hlinux/cdev.hlinux/device.hlinux/mm.hlinux/slab.hlinux/iommu.hlinux/uuid.hlinux/vdpa.hlinux/nospec.hlinux/vhost.hvhost.h
Detected Declarations
struct vhost_vdpa_asstruct vhost_vdpafunction iotlb_to_asidfunction vhost_vdpa_reset_mapfunction vhost_vdpa_remove_asfunction handle_vq_kickfunction vhost_vdpa_virtqueue_cbfunction vhost_vdpa_config_cbfunction vhost_vdpa_setup_vq_irqfunction vhost_vdpa_unsetup_vq_irqfunction _compat_vdpa_resetfunction vhost_vdpa_resetfunction vhost_vdpa_bind_mmfunction vhost_vdpa_unbind_mmfunction vhost_vdpa_get_device_idfunction vhost_vdpa_get_statusfunction vhost_vdpa_set_statusfunction vhost_vdpa_config_validatefunction vhost_vdpa_get_configfunction vhost_vdpa_set_configfunction vhost_vdpa_can_suspendfunction vhost_vdpa_can_resumefunction vhost_vdpa_has_desc_groupfunction vhost_vdpa_get_featuresfunction vhost_vdpa_get_backend_featuresfunction vhost_vdpa_has_persistent_mapfunction vhost_vdpa_set_featuresfunction vhost_vdpa_get_vring_numfunction vhost_vdpa_config_putfunction vhost_vdpa_set_config_callfunction vhost_vdpa_get_iova_rangefunction vhost_vdpa_get_config_sizefunction vhost_vdpa_get_vqs_countfunction vhost_vdpa_suspendfunction vhost_vdpa_resumefunction vhost_vdpa_vring_ioctlfunction vhost_vdpa_unlocked_ioctlfunction vhost_vdpa_general_unmapfunction vhost_vdpa_pa_unmapfunction vhost_vdpa_va_unmapfunction vhost_vdpa_iotlb_unmapfunction perm_to_iommu_flagsfunction vhost_vdpa_mapfunction vhost_vdpa_unmapfunction vhost_vdpa_va_mapfunction vhost_vdpa_pa_mapfunction vhost_vdpa_process_iotlb_updatefunction vhost_vdpa_process_iotlb_msg
Annotated Snippet
static const struct file_operations vhost_vdpa_fops = {
.owner = THIS_MODULE,
.open = vhost_vdpa_open,
.release = vhost_vdpa_release,
.write_iter = vhost_vdpa_chr_write_iter,
.unlocked_ioctl = vhost_vdpa_unlocked_ioctl,
#ifdef CONFIG_MMU
.mmap = vhost_vdpa_mmap,
#endif /* CONFIG_MMU */
.compat_ioctl = compat_ptr_ioctl,
};
static void vhost_vdpa_release_dev(struct device *device)
{
struct vhost_vdpa *v =
container_of(device, struct vhost_vdpa, dev);
ida_free(&vhost_vdpa_ida, v->minor);
kfree(v->vqs);
kfree(v);
}
static int vhost_vdpa_probe(struct vdpa_device *vdpa)
{
const struct vdpa_config_ops *ops = vdpa->config;
struct vhost_vdpa *v;
int minor;
int i, r;
/* We can't support platform IOMMU device with more than 1
* group or as
*/
if (!ops->set_map && !ops->dma_map &&
(vdpa->ngroups > 1 || vdpa->nas > 1))
return -EOPNOTSUPP;
v = kzalloc_obj(*v, GFP_KERNEL | __GFP_RETRY_MAYFAIL);
if (!v)
return -ENOMEM;
minor = ida_alloc_max(&vhost_vdpa_ida, VHOST_VDPA_DEV_MAX - 1,
GFP_KERNEL);
if (minor < 0) {
kfree(v);
return minor;
}
atomic_set(&v->opened, 0);
v->minor = minor;
v->vdpa = vdpa;
v->nvqs = vdpa->nvqs;
v->virtio_id = ops->get_device_id(vdpa);
device_initialize(&v->dev);
v->dev.release = vhost_vdpa_release_dev;
v->dev.parent = &vdpa->dev;
v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
v->vqs = kmalloc_objs(struct vhost_virtqueue, v->nvqs);
if (!v->vqs) {
r = -ENOMEM;
goto err;
}
r = dev_set_name(&v->dev, "vhost-vdpa-%u", minor);
if (r)
goto err;
cdev_init(&v->cdev, &vhost_vdpa_fops);
v->cdev.owner = THIS_MODULE;
r = cdev_device_add(&v->cdev, &v->dev);
if (r)
goto err;
init_completion(&v->completion);
vdpa_set_drvdata(vdpa, v);
for (i = 0; i < VHOST_VDPA_IOTLB_BUCKETS; i++)
INIT_HLIST_HEAD(&v->as[i]);
return 0;
err:
put_device(&v->dev);
return r;
}
static void vhost_vdpa_remove(struct vdpa_device *vdpa)
{
struct vhost_vdpa *v = vdpa_get_drvdata(vdpa);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/cdev.h`, `linux/device.h`, `linux/mm.h`, `linux/slab.h`, `linux/iommu.h`, `linux/uuid.h`.
- Detected declarations: `struct vhost_vdpa_as`, `struct vhost_vdpa`, `function iotlb_to_asid`, `function vhost_vdpa_reset_map`, `function vhost_vdpa_remove_as`, `function handle_vq_kick`, `function vhost_vdpa_virtqueue_cb`, `function vhost_vdpa_config_cb`, `function vhost_vdpa_setup_vq_irq`, `function vhost_vdpa_unsetup_vq_irq`.
- 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.
- 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.