drivers/gpu/drm/xe/xe_pagefault.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_pagefault.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_pagefault.c- Extension
.c- Size
- 12958 bytes
- Lines
- 498
- 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.
- 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/circ_buf.hdrm/drm_exec.hdrm/drm_managed.hxe_bo.hxe_device.hxe_gt_printk.hxe_gt_types.hxe_gt_stats.hxe_hw_engine.hxe_pagefault.hxe_pagefault_types.hxe_svm.hxe_trace_bo.hxe_vm.h
Detected Declarations
function xe_pagefault_entry_sizefunction xe_pagefault_beginfunction xe_pagefault_handle_vmafunction xe_vma_userptr_check_repinfunction xe_pagefault_access_is_atomicfunction xe_pagefault_servicefunction xe_pagefault_queue_popfunction xe_pagefault_printfunction xe_pagefault_save_to_vmfunction xe_pagefault_queue_workfunction xe_pagefault_queue_initfunction for_each_gtfunction xe_pagefault_finifunction xe_pagefault_initfunction xe_pagefault_queue_resetfunction xe_pagefault_resetfunction xe_pagefault_queue_fullfunction xe_pagefault_handler
Annotated Snippet
xe_vma_userptr_check_repin(to_userptr_vma(vma))) {
struct xe_userptr_vma *uvma = to_userptr_vma(vma);
err = xe_vma_userptr_pin_pages(uvma);
if (err)
return err;
}
/* Lock VM and BOs dma-resv */
xe_validation_ctx_init(&ctx, &vm->xe->val, &exec, (struct xe_val_flags) {});
drm_exec_until_all_locked(&exec) {
err = xe_pagefault_begin(&exec, vma, tile->mem.vram,
needs_vram == 1);
drm_exec_retry_on_contention(&exec);
xe_validation_retry_on_oom(&ctx, &err);
if (err)
goto unlock_dma_resv;
/* Bind VMA only to the GT that has faulted */
trace_xe_vma_pf_bind(vma);
xe_vm_set_validation_exec(vm, &exec);
fence = xe_vma_rebind(vm, vma, BIT(tile->id));
xe_vm_set_validation_exec(vm, NULL);
if (IS_ERR(fence)) {
err = PTR_ERR(fence);
xe_validation_retry_on_oom(&ctx, &err);
goto unlock_dma_resv;
}
}
dma_fence_wait(fence, false);
dma_fence_put(fence);
unlock_dma_resv:
xe_validation_ctx_fini(&ctx);
if (err == -EAGAIN)
goto retry_userptr;
return err;
}
static bool
xe_pagefault_access_is_atomic(enum xe_pagefault_access_type access_type)
{
return (access_type & XE_PAGEFAULT_ACCESS_TYPE_MASK) == XE_PAGEFAULT_ACCESS_TYPE_ATOMIC;
}
static struct xe_vm *xe_pagefault_asid_to_vm(struct xe_device *xe, u32 asid)
{
struct xe_vm *vm;
down_read(&xe->usm.lock);
vm = xa_load(&xe->usm.asid_to_vm, asid);
if (vm && (xe_vm_in_fault_mode(vm) || xe_vm_has_scratch(vm)))
xe_vm_get(vm);
else
vm = ERR_PTR(-EINVAL);
up_read(&xe->usm.lock);
return vm;
}
static int xe_pagefault_service(struct xe_pagefault *pf)
{
struct xe_gt *gt = pf->gt;
struct xe_device *xe = gt_to_xe(gt);
struct xe_vm *vm;
struct xe_vma *vma = NULL;
int err;
bool atomic;
/* Producer flagged this fault to be nacked */
if (pf->consumer.fault_type_level == XE_PAGEFAULT_TYPE_LEVEL_NACK)
return -EFAULT;
vm = xe_pagefault_asid_to_vm(xe, pf->consumer.asid);
if (IS_ERR(vm))
return PTR_ERR(vm);
/*
* TODO: Change to read lock? Using write lock for simplicity.
*/
down_write(&vm->lock);
if (xe_vm_is_closed(vm)) {
err = -ENOENT;
goto unlock_vm;
}
vma = xe_vm_find_vma_by_addr(vm, pf->consumer.page_addr);
Annotation
- Immediate include surface: `linux/circ_buf.h`, `drm/drm_exec.h`, `drm/drm_managed.h`, `xe_bo.h`, `xe_device.h`, `xe_gt_printk.h`, `xe_gt_types.h`, `xe_gt_stats.h`.
- Detected declarations: `function xe_pagefault_entry_size`, `function xe_pagefault_begin`, `function xe_pagefault_handle_vma`, `function xe_vma_userptr_check_repin`, `function xe_pagefault_access_is_atomic`, `function xe_pagefault_service`, `function xe_pagefault_queue_pop`, `function xe_pagefault_print`, `function xe_pagefault_save_to_vm`, `function xe_pagefault_queue_work`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.