drivers/vdpa/vdpa_sim/vdpa_sim.c
Source file repositories/reference/linux-study-clean/drivers/vdpa/vdpa_sim/vdpa_sim.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vdpa/vdpa_sim/vdpa_sim.c- Extension
.c- Size
- 22164 bytes
- Lines
- 847
- Domain
- Driver Families
- Bucket
- drivers/vdpa
- 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.
- 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/init.hlinux/module.hlinux/device.hlinux/kernel.hlinux/kthread.hlinux/slab.hlinux/dma-map-ops.hlinux/vringh.hlinux/vdpa.hlinux/vhost_iotlb.huapi/linux/vdpa.huapi/linux/vhost_types.hvdpa_sim.h
Detected Declarations
struct vdpasim_mm_workfunction vdpasim_mm_work_fnfunction vdpasim_worker_change_mm_syncfunction vdpasim_vq_notifyfunction vdpasim_queue_readyfunction vdpasim_vq_resetfunction vdpasim_do_resetfunction vdpasim_work_fnfunction vdpasim_schedule_workfunction vdpasim_set_vq_addressfunction vdpasim_set_vq_numfunction vdpasim_get_vq_sizefunction vdpasim_kick_vqfunction vdpasim_set_vq_cbfunction vdpasim_set_vq_readyfunction vdpasim_get_vq_readyfunction vdpasim_set_vq_statefunction vdpasim_get_vq_statefunction vdpasim_get_vq_statsfunction vdpasim_get_vq_alignfunction vdpasim_get_vq_groupfunction vdpasim_get_device_featuresfunction vdpasim_get_backend_featuresfunction vdpasim_set_driver_featuresfunction vdpasim_get_driver_featuresfunction vdpasim_set_config_cbfunction vdpasim_get_device_idfunction vdpasim_get_vendor_idfunction vdpasim_get_statusfunction vdpasim_set_statusfunction vdpasim_compat_resetfunction vdpasim_resetfunction vdpasim_suspendfunction vdpasim_resumefunction vdpasim_get_config_sizefunction vdpasim_get_configfunction vdpasim_set_configfunction vdpasim_get_generationfunction vdpasim_get_iova_rangefunction vdpasim_set_group_asidfunction vdpasim_set_mapfunction vdpasim_reset_mapfunction vdpasim_bind_mmfunction vdpasim_unbind_mmfunction vdpasim_dma_mapfunction vdpasim_dma_unmapfunction vdpasim_freeexport vdpasim_create
Annotated Snippet
struct vdpasim_mm_work {
struct kthread_work work;
struct vdpasim *vdpasim;
struct mm_struct *mm_to_bind;
int ret;
};
static void vdpasim_mm_work_fn(struct kthread_work *work)
{
struct vdpasim_mm_work *mm_work =
container_of(work, struct vdpasim_mm_work, work);
struct vdpasim *vdpasim = mm_work->vdpasim;
mm_work->ret = 0;
//TODO: should we attach the cgroup of the mm owner?
vdpasim->mm_bound = mm_work->mm_to_bind;
}
static void vdpasim_worker_change_mm_sync(struct vdpasim *vdpasim,
struct vdpasim_mm_work *mm_work)
{
struct kthread_work *work = &mm_work->work;
kthread_init_work(work, vdpasim_mm_work_fn);
kthread_queue_work(vdpasim->worker, work);
kthread_flush_work(work);
}
static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa)
{
return container_of(vdpa, struct vdpasim, vdpa);
}
static void vdpasim_vq_notify(struct vringh *vring)
{
struct vdpasim_virtqueue *vq =
container_of(vring, struct vdpasim_virtqueue, vring);
if (!vq->cb)
return;
vq->cb(vq->private);
}
static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx)
{
struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
uint16_t last_avail_idx = vq->vring.last_avail_idx;
struct vring_desc *desc = (struct vring_desc *)
(uintptr_t)vq->desc_addr;
struct vring_avail *avail = (struct vring_avail *)
(uintptr_t)vq->driver_addr;
struct vring_used *used = (struct vring_used *)
(uintptr_t)vq->device_addr;
if (use_va && vdpasim->mm_bound) {
vringh_init_iotlb_va(&vq->vring, vdpasim->features, vq->num,
true, desc, avail, used);
} else {
vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num,
true, desc, avail, used);
}
vq->vring.last_avail_idx = last_avail_idx;
/*
* Since vdpa_sim does not support receive inflight descriptors as a
* destination of a migration, let's set both avail_idx and used_idx
* the same at vq start. This is how vhost-user works in a
* VHOST_SET_VRING_BASE call.
*
* Although the simple fix is to set last_used_idx at
* vdpasim_set_vq_state, it would be reset at vdpasim_queue_ready.
*/
vq->vring.last_used_idx = last_avail_idx;
vq->vring.notify = vdpasim_vq_notify;
}
static void vdpasim_vq_reset(struct vdpasim *vdpasim,
struct vdpasim_virtqueue *vq)
{
vq->ready = false;
vq->desc_addr = 0;
vq->driver_addr = 0;
vq->device_addr = 0;
vq->cb = NULL;
vq->private = NULL;
vringh_init_iotlb(&vq->vring, vdpasim->dev_attr.supported_features,
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/device.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/slab.h`, `linux/dma-map-ops.h`, `linux/vringh.h`.
- Detected declarations: `struct vdpasim_mm_work`, `function vdpasim_mm_work_fn`, `function vdpasim_worker_change_mm_sync`, `function vdpasim_vq_notify`, `function vdpasim_queue_ready`, `function vdpasim_vq_reset`, `function vdpasim_do_reset`, `function vdpasim_work_fn`, `function vdpasim_schedule_work`, `function vdpasim_set_vq_address`.
- Atlas domain: Driver Families / drivers/vdpa.
- Implementation status: integration implementation candidate.
- 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.