virt/kvm/vfio.c
Source file repositories/reference/linux-study-clean/virt/kvm/vfio.c
File Facts
- System
- Linux kernel
- Corpus path
virt/kvm/vfio.c- Extension
.c- Size
- 7484 bytes
- Lines
- 360
- Domain
- Kernel Services
- Bucket
- virt
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/errno.hlinux/file.hlinux/kvm_host.hlinux/list.hlinux/module.hlinux/mutex.hlinux/slab.hlinux/uaccess.hlinux/vfio.hvfio.hasm/kvm_ppc.h
Detected Declarations
struct kvm_vfio_filestruct kvm_vfiofunction kvm_vfio_file_set_kvmfunction kvm_vfio_file_enforced_coherentfunction kvm_vfio_file_is_validfunction kvm_spapr_tce_release_vfio_groupfunction kvm_vfio_update_coherencyfunction list_for_each_entryfunction kvm_vfio_file_addfunction list_for_each_entryfunction kvm_vfio_file_freefunction kvm_vfio_file_delfunction list_for_each_entryfunction kvm_vfio_file_set_spapr_tcefunction list_for_each_entryfunction kvm_vfio_set_filefunction kvm_vfio_set_attrfunction kvm_vfio_has_attrfunction kvm_vfio_releasefunction kvm_vfio_createfunction kvm_vfio_ops_initfunction kvm_vfio_ops_exit
Annotated Snippet
struct kvm_vfio_file {
struct list_head node;
struct file *file;
#ifdef CONFIG_SPAPR_TCE_IOMMU
struct iommu_group *iommu_group;
#endif
};
struct kvm_vfio {
struct list_head file_list;
struct mutex lock;
bool noncoherent;
};
static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm)
{
void (*fn)(struct file *file, struct kvm *kvm);
fn = symbol_get(vfio_file_set_kvm);
if (!fn)
return;
fn(file, kvm);
symbol_put(vfio_file_set_kvm);
}
static bool kvm_vfio_file_enforced_coherent(struct file *file)
{
bool (*fn)(struct file *file);
bool ret;
fn = symbol_get(vfio_file_enforced_coherent);
if (!fn)
return false;
ret = fn(file);
symbol_put(vfio_file_enforced_coherent);
return ret;
}
static bool kvm_vfio_file_is_valid(struct file *file)
{
bool (*fn)(struct file *file);
bool ret;
fn = symbol_get(vfio_file_is_valid);
if (!fn)
return false;
ret = fn(file);
symbol_put(vfio_file_is_valid);
return ret;
}
#ifdef CONFIG_SPAPR_TCE_IOMMU
static struct iommu_group *kvm_vfio_file_iommu_group(struct file *file)
{
struct iommu_group *(*fn)(struct file *file);
struct iommu_group *ret;
fn = symbol_get(vfio_file_iommu_group);
if (!fn)
return NULL;
ret = fn(file);
symbol_put(vfio_file_iommu_group);
return ret;
}
static void kvm_spapr_tce_release_vfio_group(struct kvm *kvm,
struct kvm_vfio_file *kvf)
{
if (WARN_ON_ONCE(!kvf->iommu_group))
return;
kvm_spapr_tce_release_iommu_group(kvm, kvf->iommu_group);
iommu_group_put(kvf->iommu_group);
kvf->iommu_group = NULL;
}
#endif
/*
* Groups/devices can use the same or different IOMMU domains. If the same
Annotation
- Immediate include surface: `linux/errno.h`, `linux/file.h`, `linux/kvm_host.h`, `linux/list.h`, `linux/module.h`, `linux/mutex.h`, `linux/slab.h`, `linux/uaccess.h`.
- Detected declarations: `struct kvm_vfio_file`, `struct kvm_vfio`, `function kvm_vfio_file_set_kvm`, `function kvm_vfio_file_enforced_coherent`, `function kvm_vfio_file_is_valid`, `function kvm_spapr_tce_release_vfio_group`, `function kvm_vfio_update_coherency`, `function list_for_each_entry`, `function kvm_vfio_file_add`, `function list_for_each_entry`.
- Atlas domain: Kernel Services / virt.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.