drivers/vdpa/vdpa_user/vduse_dev.c
Source file repositories/reference/linux-study-clean/drivers/vdpa/vdpa_user/vduse_dev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vdpa/vdpa_user/vduse_dev.c- Extension
.c- Size
- 59636 bytes
- Lines
- 2624
- Domain
- Driver Families
- Bucket
- drivers/vdpa
- 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/virtio_net.hlinux/cleanup.hlinux/init.hlinux/module.hlinux/cdev.hlinux/device.hlinux/eventfd.hlinux/slab.hlinux/wait.hlinux/dma-map-ops.hlinux/poll.hlinux/file.hlinux/uio.hlinux/vdpa.hlinux/nospec.hlinux/virtio.hlinux/vmalloc.hlinux/sched/mm.huapi/linux/vduse.huapi/linux/vdpa.huapi/linux/virtio_config.huapi/linux/virtio_ids.huapi/linux/virtio_blk.huapi/linux/virtio_ring.hlinux/mod_devicetable.hiova_domain.h
Detected Declarations
struct vduse_virtqueuestruct vduse_devstruct vduse_vdpastruct vduse_umemstruct vduse_asstruct vduse_vq_groupstruct vduse_devstruct vduse_dev_msgstruct vduse_controlstruct compat_vduse_iotlb_entrystruct compat_vduse_vq_infostruct vq_sysfs_entrystruct vduse_mgmt_devfunction list_for_each_entryfunction vduse_enqueue_msgfunction vduse_enqueue_msg_headfunction vduse_dev_brokenfunction vduse_dev_msg_syncfunction vduse_dev_get_vq_state_packedfunction vduse_dev_get_vq_state_splitfunction vduse_dev_set_statusfunction vduse_dev_update_iotlbfunction vduse_dev_read_iterfunction is_mem_zerofunction vduse_dev_write_iterfunction vduse_dev_pollfunction vduse_dev_resetfunction vduse_vdpa_set_vq_addressfunction vduse_vq_kickfunction vduse_vq_kick_workfunction vduse_vdpa_kick_vqfunction vduse_vdpa_set_vq_cbfunction vduse_vdpa_set_vq_numfunction vduse_vdpa_get_vq_sizefunction vduse_vdpa_set_vq_readyfunction vduse_vdpa_get_vq_readyfunction vduse_vdpa_set_vq_statefunction vduse_get_vq_groupfunction vduse_get_vq_mapfunction read_lockfunction vduse_vdpa_get_vq_statefunction vduse_vdpa_get_vq_alignfunction vduse_vdpa_get_device_featuresfunction vduse_vdpa_set_driver_featuresfunction vduse_vdpa_get_driver_featuresfunction vduse_vdpa_set_config_cbfunction vduse_vdpa_get_vq_num_maxfunction vduse_vdpa_get_device_id
Annotated Snippet
static const struct file_operations vduse_dev_fops = {
.owner = THIS_MODULE,
.open = vduse_dev_open,
.release = vduse_dev_release,
.read_iter = vduse_dev_read_iter,
.write_iter = vduse_dev_write_iter,
.poll = vduse_dev_poll,
.unlocked_ioctl = vduse_dev_ioctl,
.compat_ioctl = vduse_dev_compat_ioctl,
.llseek = noop_llseek,
};
static ssize_t irq_cb_affinity_show(struct vduse_virtqueue *vq, char *buf)
{
return sprintf(buf, "%*pb\n", cpumask_pr_args(&vq->irq_affinity));
}
static ssize_t irq_cb_affinity_store(struct vduse_virtqueue *vq,
const char *buf, size_t count)
{
cpumask_var_t new_value;
int ret;
if (!zalloc_cpumask_var(&new_value, GFP_KERNEL))
return -ENOMEM;
ret = cpumask_parse(buf, new_value);
if (ret)
goto free_mask;
ret = -EINVAL;
if (!cpumask_intersects(new_value, cpu_online_mask))
goto free_mask;
cpumask_copy(&vq->irq_affinity, new_value);
ret = count;
free_mask:
free_cpumask_var(new_value);
return ret;
}
struct vq_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct vduse_virtqueue *vq, char *buf);
ssize_t (*store)(struct vduse_virtqueue *vq, const char *buf,
size_t count);
};
static struct vq_sysfs_entry irq_cb_affinity_attr = __ATTR_RW(irq_cb_affinity);
static struct attribute *vq_attrs[] = {
&irq_cb_affinity_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(vq);
static ssize_t vq_attr_show(struct kobject *kobj, struct attribute *attr,
char *buf)
{
struct vduse_virtqueue *vq = container_of(kobj,
struct vduse_virtqueue, kobj);
struct vq_sysfs_entry *entry = container_of(attr,
struct vq_sysfs_entry, attr);
if (!entry->show)
return -EIO;
return entry->show(vq, buf);
}
static ssize_t vq_attr_store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count)
{
struct vduse_virtqueue *vq = container_of(kobj,
struct vduse_virtqueue, kobj);
struct vq_sysfs_entry *entry = container_of(attr,
struct vq_sysfs_entry, attr);
if (!entry->store)
return -EIO;
return entry->store(vq, buf, count);
}
static const struct sysfs_ops vq_sysfs_ops = {
.show = vq_attr_show,
.store = vq_attr_store,
};
static void vq_release(struct kobject *kobj)
Annotation
- Immediate include surface: `linux/virtio_net.h`, `linux/cleanup.h`, `linux/init.h`, `linux/module.h`, `linux/cdev.h`, `linux/device.h`, `linux/eventfd.h`, `linux/slab.h`.
- Detected declarations: `struct vduse_virtqueue`, `struct vduse_dev`, `struct vduse_vdpa`, `struct vduse_umem`, `struct vduse_as`, `struct vduse_vq_group`, `struct vduse_dev`, `struct vduse_dev_msg`, `struct vduse_control`, `struct compat_vduse_iotlb_entry`.
- Atlas domain: Driver Families / drivers/vdpa.
- 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.