drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c- Extension
.c- Size
- 92022 bytes
- Lines
- 3270
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-buf.hlinux/list.hlinux/pagemap.hlinux/sched/mm.hlinux/sched/task.hdrm/ttm/ttm_tt.hdrm/drm_exec.hamdgpu_object.hamdgpu_gem.hamdgpu_vm.hamdgpu_hmm.hamdgpu_amdkfd.hamdgpu_dma_buf.huapi/linux/kfd_ioctl.hamdgpu_xgmi.hkfd_priv.hkfd_smi_events.h
Detected Declarations
struct bo_vm_reservation_contextenum bo_vm_matchfunction kfd_mem_is_attachedfunction reuse_dmamapfunction Systemfunction amdgpu_amdkfd_reserve_system_memfunction memoryfunction amdgpu_amdkfd_unreserve_mem_limitfunction amdgpu_amdkfd_release_notifyfunction create_dmamap_sg_bofunction amdgpu_amdkfd_remove_eviction_fencefunction amdgpu_amdkfd_remove_all_eviction_fencesfunction amdgpu_amdkfd_bo_validatefunction amdgpu_amdkfd_bo_validate_and_fencefunction amdgpu_amdkfd_validate_vm_bofunction vm_validate_pt_pd_bosfunction vm_update_pdsfunction get_pte_flagsfunction create_sg_tablefunction kfd_mem_dmamap_userptrfunction kfd_mem_dmamap_dmabuffunction kfd_mem_dmamap_sg_bofunction kfd_mem_dmamap_attachmentfunction kfd_mem_dmaunmap_userptrfunction kfd_mem_dmaunmap_dmabuffunction kfd_mem_dmaunmap_attachmentfunction kfd_mem_export_dmabuffunction kfd_mem_attach_dmabuffunction kfd_mem_attachfunction drm_exec_until_all_lockedfunction kfd_mem_detachfunction add_kgd_mem_to_kfd_bo_listfunction remove_kgd_mem_from_kfd_bo_listfunction init_user_pagesfunction reserve_bo_and_vmfunction reserve_bo_and_cond_vmsfunction list_for_each_entryfunction reserve_bo_and_function unmap_bo_from_gpuvmfunction update_gpuvm_ptefunction map_bo_to_gpuvmfunction process_validate_vmsfunction list_for_each_entryfunction process_sync_pds_resvfunction list_for_each_entryfunction process_update_pdsfunction list_for_each_entryfunction init_kfd_vm
Annotated Snippet
struct bo_vm_reservation_context {
/* DRM execution context for the reservation */
struct drm_exec exec;
/* Number of VMs reserved */
unsigned int n_vms;
/* Pointer to sync object */
struct amdgpu_sync *sync;
};
enum bo_vm_match {
BO_VM_NOT_MAPPED = 0, /* Match VMs where a BO is not mapped */
BO_VM_MAPPED, /* Match VMs where a BO is mapped */
BO_VM_ALL, /* Match all VMs a BO was added to */
};
/**
* reserve_bo_and_vm - reserve a BO and a VM unconditionally.
* @mem: KFD BO structure.
* @vm: the VM to reserve.
* @ctx: the struct that will be used in unreserve_bo_and_vms().
*/
static int reserve_bo_and_vm(struct kgd_mem *mem,
struct amdgpu_vm *vm,
struct bo_vm_reservation_context *ctx)
{
struct amdgpu_bo *bo = mem->bo;
int ret;
WARN_ON(!vm);
ctx->n_vms = 1;
ctx->sync = &mem->sync;
drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
drm_exec_until_all_locked(&ctx->exec) {
ret = amdgpu_vm_lock_pd(vm, &ctx->exec, 2);
drm_exec_retry_on_contention(&ctx->exec);
if (unlikely(ret))
goto error;
ret = drm_exec_prepare_obj(&ctx->exec, &bo->tbo.base, 1);
drm_exec_retry_on_contention(&ctx->exec);
if (unlikely(ret))
goto error;
}
return 0;
error:
pr_err("Failed to reserve buffers in ttm.\n");
drm_exec_fini(&ctx->exec);
return ret;
}
/**
* reserve_bo_and_cond_vms - reserve a BO and some VMs conditionally
* @mem: KFD BO structure.
* @vm: the VM to reserve. If NULL, then all VMs associated with the BO
* is used. Otherwise, a single VM associated with the BO.
* @map_type: the mapping status that will be used to filter the VMs.
* @ctx: the struct that will be used in unreserve_bo_and_vms().
*
* Returns 0 for success, negative for failure.
*/
static int reserve_bo_and_cond_vms(struct kgd_mem *mem,
struct amdgpu_vm *vm, enum bo_vm_match map_type,
struct bo_vm_reservation_context *ctx)
{
struct kfd_mem_attachment *entry;
struct amdgpu_bo *bo = mem->bo;
int ret;
ctx->sync = &mem->sync;
drm_exec_init(&ctx->exec, DRM_EXEC_INTERRUPTIBLE_WAIT |
DRM_EXEC_IGNORE_DUPLICATES, 0);
drm_exec_until_all_locked(&ctx->exec) {
ctx->n_vms = 0;
list_for_each_entry(entry, &mem->attachments, list) {
if ((vm && vm != entry->bo_va->base.vm) ||
(entry->is_mapped != map_type
&& map_type != BO_VM_ALL))
continue;
ret = amdgpu_vm_lock_pd(entry->bo_va->base.vm,
&ctx->exec, 2);
drm_exec_retry_on_contention(&ctx->exec);
if (unlikely(ret))
goto error;
++ctx->n_vms;
}
ret = drm_exec_prepare_obj(&ctx->exec, &bo->tbo.base, 1);
Annotation
- Immediate include surface: `linux/dma-buf.h`, `linux/list.h`, `linux/pagemap.h`, `linux/sched/mm.h`, `linux/sched/task.h`, `drm/ttm/ttm_tt.h`, `drm/drm_exec.h`, `amdgpu_object.h`.
- Detected declarations: `struct bo_vm_reservation_context`, `enum bo_vm_match`, `function kfd_mem_is_attached`, `function reuse_dmamap`, `function System`, `function amdgpu_amdkfd_reserve_system_mem`, `function memory`, `function amdgpu_amdkfd_unreserve_mem_limit`, `function amdgpu_amdkfd_release_notify`, `function create_dmamap_sg_bo`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.