drivers/iommu/iommu-sva.c
Source file repositories/reference/linux-study-clean/drivers/iommu/iommu-sva.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iommu/iommu-sva.c- Extension
.c- Size
- 8678 bytes
- Lines
- 343
- Domain
- Driver Families
- Bucket
- drivers/iommu
- 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/mmu_context.hlinux/mmu_notifier.hlinux/mutex.hlinux/sched/mm.hlinux/iommu.hiommu-priv.h
Detected Declarations
function iommu_sva_bind_devicefunction iommu_sva_unbind_devicefunction iommu_sva_get_pasidfunction mm_pasid_dropfunction iommu_sva_handle_mmfunction iommu_sva_handle_iopffunction iommu_sva_iopf_handlerfunction iommu_sva_invalidate_kva_rangeexport iommu_sva_bind_deviceexport iommu_sva_unbind_deviceexport iommu_sva_get_pasid
Annotated Snippet
ret = handle_mm_fault(vma, prm->addr, fault_flags, NULL);
status = ret & VM_FAULT_ERROR ? IOMMU_PAGE_RESP_INVALID :
IOMMU_PAGE_RESP_SUCCESS;
out_put_mm:
mmap_read_unlock(mm);
mmput(mm);
return status;
}
static void iommu_sva_handle_iopf(struct work_struct *work)
{
struct iopf_fault *iopf;
struct iopf_group *group;
enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
group = container_of(work, struct iopf_group, work);
list_for_each_entry(iopf, &group->faults, list) {
/*
* For the moment, errors are sticky: don't handle subsequent
* faults in the group if there is an error.
*/
if (status != IOMMU_PAGE_RESP_SUCCESS)
break;
status = iommu_sva_handle_mm(&iopf->fault,
group->attach_handle->domain->mm);
}
iopf_group_response(group, status);
iopf_free_group(group);
}
static int iommu_sva_iopf_handler(struct iopf_group *group)
{
struct iommu_fault_param *fault_param = group->fault_param;
INIT_WORK(&group->work, iommu_sva_handle_iopf);
if (!queue_work(fault_param->queue->wq, &group->work))
return -EBUSY;
return 0;
}
static struct iommu_domain *iommu_sva_domain_alloc(struct device *dev,
struct mm_struct *mm)
{
const struct iommu_ops *ops = dev_iommu_ops(dev);
struct iommu_domain *domain;
if (!ops->domain_alloc_sva)
return ERR_PTR(-EOPNOTSUPP);
domain = ops->domain_alloc_sva(dev, mm);
if (IS_ERR(domain))
return domain;
domain->type = IOMMU_DOMAIN_SVA;
domain->cookie_type = IOMMU_COOKIE_SVA;
mmgrab(mm);
domain->mm = mm;
domain->owner = ops;
domain->iopf_handler = iommu_sva_iopf_handler;
return domain;
}
void iommu_sva_invalidate_kva_range(unsigned long start, unsigned long end)
{
struct iommu_mm_data *iommu_mm;
guard(mutex)(&iommu_sva_lock);
if (!iommu_sva_present)
return;
list_for_each_entry(iommu_mm, &iommu_sva_mms, mm_list_elm)
mmu_notifier_arch_invalidate_secondary_tlbs(iommu_mm->mm, start, end);
}
Annotation
- Immediate include surface: `linux/mmu_context.h`, `linux/mmu_notifier.h`, `linux/mutex.h`, `linux/sched/mm.h`, `linux/iommu.h`, `iommu-priv.h`.
- Detected declarations: `function iommu_sva_bind_device`, `function iommu_sva_unbind_device`, `function iommu_sva_get_pasid`, `function mm_pasid_drop`, `function iommu_sva_handle_mm`, `function iommu_sva_handle_iopf`, `function iommu_sva_iopf_handler`, `function iommu_sva_invalidate_kva_range`, `export iommu_sva_bind_device`, `export iommu_sva_unbind_device`.
- Atlas domain: Driver Families / drivers/iommu.
- 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.