drivers/vfio/group.c
Source file repositories/reference/linux-study-clean/drivers/vfio/group.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/group.c- Extension
.c- Size
- 22421 bytes
- Lines
- 930
- Domain
- Driver Families
- Bucket
- drivers/vfio
- 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/vfio.hlinux/iommufd.hlinux/anon_inodes.hvfio.h
Detected Declarations
function vfio_group_has_iommufunction vfio_group_ioctl_unset_containerfunction vfio_group_ioctl_set_containerfunction vfio_device_group_get_kvm_safefunction vfio_df_group_openfunction vfio_df_group_closefunction vfio_group_ioctl_get_device_fdfunction vfio_group_ioctl_get_statusfunction vfio_group_fops_unl_ioctlfunction vfio_device_block_groupfunction vfio_device_unblock_groupfunction vfio_group_fops_openfunction vfio_device_remove_groupfunction vfio_group_fops_releasefunction vfio_group_find_from_iommufunction vfio_group_releasefunction vfio_group_has_devicefunction vfio_device_set_groupfunction vfio_device_remove_groupfunction vfio_device_group_registerfunction vfio_device_group_unregisterfunction vfio_device_group_use_iommufunction vfio_device_group_unuse_iommufunction vfio_device_has_containerfunction vfio_file_is_groupfunction vfio_group_enforced_coherentfunction vfio_group_set_kvmfunction vfio_file_has_devfunction vfio_group_initfunction vfio_group_cleanupexport vfio_file_iommu_groupexport vfio_file_is_groupexport vfio_file_has_dev
Annotated Snippet
static const struct file_operations vfio_group_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = vfio_group_fops_unl_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = vfio_group_fops_open,
.release = vfio_group_fops_release,
};
/*
* Group objects - create, release, get, put, search
*/
static struct vfio_group *
vfio_group_find_from_iommu(struct iommu_group *iommu_group)
{
struct vfio_group *group;
lockdep_assert_held(&vfio.group_lock);
/*
* group->iommu_group from the vfio.group_list cannot be NULL
* under the vfio.group_lock.
*/
list_for_each_entry(group, &vfio.group_list, vfio_next) {
if (group->iommu_group == iommu_group)
return group;
}
return NULL;
}
static void vfio_group_release(struct device *dev)
{
struct vfio_group *group = container_of(dev, struct vfio_group, dev);
mutex_destroy(&group->device_lock);
mutex_destroy(&group->group_lock);
WARN_ON(group->iommu_group);
WARN_ON(group->cdev_device_open_cnt);
ida_free(&vfio.group_ida, MINOR(group->dev.devt));
kfree(group);
}
static struct vfio_group *vfio_group_alloc(struct iommu_group *iommu_group,
enum vfio_group_type type)
{
struct vfio_group *group;
int minor;
group = kzalloc_obj(*group);
if (!group)
return ERR_PTR(-ENOMEM);
minor = ida_alloc_max(&vfio.group_ida, MINORMASK, GFP_KERNEL);
if (minor < 0) {
kfree(group);
return ERR_PTR(minor);
}
device_initialize(&group->dev);
group->dev.devt = MKDEV(MAJOR(vfio.group_devt), minor);
group->dev.class = &vfio_class;
group->dev.release = vfio_group_release;
cdev_init(&group->cdev, &vfio_group_fops);
group->cdev.owner = THIS_MODULE;
refcount_set(&group->drivers, 1);
mutex_init(&group->group_lock);
spin_lock_init(&group->kvm_ref_lock);
INIT_LIST_HEAD(&group->device_list);
mutex_init(&group->device_lock);
group->iommu_group = iommu_group;
/* put in vfio_group_release() */
iommu_group_ref_get(iommu_group);
group->type = type;
return group;
}
static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group,
enum vfio_group_type type)
{
struct vfio_group *group;
struct vfio_group *ret;
int err;
lockdep_assert_held(&vfio.group_lock);
group = vfio_group_alloc(iommu_group, type);
if (IS_ERR(group))
return group;
Annotation
- Immediate include surface: `linux/vfio.h`, `linux/iommufd.h`, `linux/anon_inodes.h`, `vfio.h`.
- Detected declarations: `function vfio_group_has_iommu`, `function vfio_group_ioctl_unset_container`, `function vfio_group_ioctl_set_container`, `function vfio_device_group_get_kvm_safe`, `function vfio_df_group_open`, `function vfio_df_group_close`, `function vfio_group_ioctl_get_device_fd`, `function vfio_group_ioctl_get_status`, `function vfio_group_fops_unl_ioctl`, `function vfio_device_block_group`.
- Atlas domain: Driver Families / drivers/vfio.
- 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.