drivers/gpu/drm/xe/xe_sync.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_sync.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_sync.c- Extension
.c- Size
- 10815 bytes
- Lines
- 447
- 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.
- 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
xe_sync.hlinux/dma-fence-array.hlinux/kthread.hlinux/sched/mm.hlinux/uaccess.hdrm/drm_print.hdrm/drm_syncobj.huapi/drm/xe_drm.hxe_device.hxe_exec_queue.hxe_macros.hxe_sched_job_types.h
Detected Declarations
struct xe_user_fencefunction user_fence_destroyfunction user_fence_getfunction user_fence_putfunction user_fence_workerfunction kick_ufencefunction user_fence_cbfunction xe_sync_entry_parsefunction xe_sync_entry_add_depsfunction xe_sync_entry_waitfunction xe_sync_needs_waitfunction xe_sync_entry_signalfunction xe_sync_entry_cleanupfunction xe_sync_in_fence_getfunction for_each_tilefunction list_for_each_entryfunction __xe_sync_ufence_getfunction xe_sync_ufence_getfunction xe_sync_ufence_putfunction xe_sync_ufence_get_status
Annotated Snippet
struct xe_user_fence {
struct xe_device *xe;
struct kref refcount;
struct dma_fence_cb cb;
struct work_struct worker;
struct mm_struct *mm;
u64 __user *addr;
u64 value;
int signalled;
};
static void user_fence_destroy(struct kref *kref)
{
struct xe_user_fence *ufence = container_of(kref, struct xe_user_fence,
refcount);
mmdrop(ufence->mm);
kfree(ufence);
}
static void user_fence_get(struct xe_user_fence *ufence)
{
kref_get(&ufence->refcount);
}
static void user_fence_put(struct xe_user_fence *ufence)
{
kref_put(&ufence->refcount, user_fence_destroy);
}
static struct xe_user_fence *user_fence_create(struct xe_device *xe, u64 addr,
u64 value)
{
struct xe_user_fence *ufence;
u64 __user *ptr = u64_to_user_ptr(addr);
u64 __maybe_unused prefetch_val;
if (get_user(prefetch_val, ptr))
return ERR_PTR(-EFAULT);
ufence = kzalloc_obj(*ufence);
if (!ufence)
return ERR_PTR(-ENOMEM);
ufence->xe = xe;
kref_init(&ufence->refcount);
ufence->addr = ptr;
ufence->value = value;
ufence->mm = current->mm;
mmgrab(ufence->mm);
return ufence;
}
static void user_fence_worker(struct work_struct *w)
{
struct xe_user_fence *ufence = container_of(w, struct xe_user_fence, worker);
WRITE_ONCE(ufence->signalled, 1);
if (mmget_not_zero(ufence->mm)) {
kthread_use_mm(ufence->mm);
if (copy_to_user(ufence->addr, &ufence->value, sizeof(ufence->value)))
XE_WARN_ON("Copy to user failed");
kthread_unuse_mm(ufence->mm);
mmput(ufence->mm);
} else {
drm_dbg(&ufence->xe->drm, "mmget_not_zero() failed, ufence wasn't signaled\n");
}
/*
* Wake up waiters only after updating the ufence state, allowing the UMD
* to safely reuse the same ufence without encountering -EBUSY errors.
*/
wake_up_all(&ufence->xe->ufence_wq);
user_fence_put(ufence);
}
static void kick_ufence(struct xe_user_fence *ufence, struct dma_fence *fence)
{
INIT_WORK(&ufence->worker, user_fence_worker);
queue_work(ufence->xe->ordered_wq, &ufence->worker);
dma_fence_put(fence);
}
static void user_fence_cb(struct dma_fence *fence, struct dma_fence_cb *cb)
{
struct xe_user_fence *ufence = container_of(cb, struct xe_user_fence, cb);
kick_ufence(ufence, fence);
}
Annotation
- Immediate include surface: `xe_sync.h`, `linux/dma-fence-array.h`, `linux/kthread.h`, `linux/sched/mm.h`, `linux/uaccess.h`, `drm/drm_print.h`, `drm/drm_syncobj.h`, `uapi/drm/xe_drm.h`.
- Detected declarations: `struct xe_user_fence`, `function user_fence_destroy`, `function user_fence_get`, `function user_fence_put`, `function user_fence_worker`, `function kick_ufence`, `function user_fence_cb`, `function xe_sync_entry_parse`, `function xe_sync_entry_add_deps`, `function xe_sync_entry_wait`.
- 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.
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.