Commit
d2ce8fcd778ee6d92748c92d23a56d4416c29d86
drm/xe: Bump LRU for external objects on exec and rebind
The VM's private BOs get their LRU position refreshed in bulk via
ttm_lru_bulk_move_tail() on vm->lru_bulk_move, both after a successful
non-LR exec and after the LR preempt-fence rebind worker runs. External
objects (BOs potentially shared across VMs) are never added to that
per-VM bulk move list, so their LRU position is never refreshed by
either path. This makes external objects in active use look more
evictable than they are.
Add xe_vm_bump_lru(), which, under a single lru_lock critical section,
performs the bulk move of the VM's private BOs and bumps each external
object locked by the drm_exec transaction. Use it from both the non-LR
exec path and the LR rebind worker, replacing the open-coded bulk move.
Fixes: d490ecf57790 ("drm/xe: Rework xe_exec and the VM rebind worker to use the drm_exec helper")
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: <stable@vger.kernel.org> # v6.8+
Assisted-by: LLM
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patch.msgid.link/20261012132607.21387-1-thomas.hellstrom@linux.intel.com
(cherry picked from commit 324ba30cca180c2e1d02090743dd78ccb15b9e4a)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Thomas Hellström <thomas.hellstrom@linux.intel.com> · 2026-10-12 13:26 UTC · committed by Rodrigo Vivi
3 files changed,
+32
−8
modified drivers/gpu/drm/xe/xe_exec.c
| @@ -346,11 +346,8 @@ retry: | |||
| 346 | 346 | xe_sched_job_push(job); | |
| 347 | 347 | xe_vm_reactivate_rebind(vm); | |
| 348 | 348 | ||
| 349 | - | if (!err && !xe_vm_in_lr_mode(vm)) { | |
| 350 | - | spin_lock(&xe->ttm.lru_lock); | |
| 351 | - | ttm_lru_bulk_move_tail(&vm->lru_bulk_move); | |
| 352 | - | spin_unlock(&xe->ttm.lru_lock); | |
| 353 | - | } | |
| 349 | + | if (!err && !xe_vm_in_lr_mode(vm)) | |
| 350 | + | xe_vm_bump_lru(vm, exec); | |
| 354 | 351 | ||
| 355 | 352 | if (mode == EXEC_MODE_LR) | |
| 356 | 353 | xe_hw_engine_group_resume_faulting_lr_jobs(group); | |
modified drivers/gpu/drm/xe/xe_vm.c
| @@ -410,6 +410,33 @@ int xe_vm_validate_rebind(struct xe_vm *vm, struct drm_exec *exec, | |||
| 410 | 410 | return 0; | |
| 411 | 411 | } | |
| 412 | 412 | ||
| 413 | + | /** | |
| 414 | + | * xe_vm_bump_lru() - Bump the LRU position of BOs used by a submission | |
| 415 | + | * @vm: The vm for which we are bumping LRUs. | |
| 416 | + | * @exec: The struct drm_exec with the locked GEM objects. | |
| 417 | + | * | |
| 418 | + | * Move the VM's private BOs, and all external objects locked by @exec, | |
| 419 | + | * to the LRU tail. Private BOs are moved in bulk using @vm's | |
| 420 | + | * &xe_vm.lru_bulk_move. External objects, which may be shared with other | |
| 421 | + | * VMs, are not part of that bulk move and are bumped individually. | |
| 422 | + | */ | |
| 423 | + | void xe_vm_bump_lru(struct xe_vm *vm, struct drm_exec *exec) | |
| 424 | + | { | |
| 425 | + | spinlock_t *lru_lock = &vm->xe->ttm.lru_lock; | |
| 426 | + | struct drm_gem_object *obj; | |
| 427 | + | ||
| 428 | + | spin_lock(lru_lock); | |
| 429 | + | ttm_lru_bulk_move_tail(&vm->lru_bulk_move); | |
| 430 | + | drm_exec_for_each_locked_object(exec, obj) { | |
| 431 | + | if (!drm_gpuvm_is_extobj(&vm->gpuvm, obj)) | |
| 432 | + | continue; | |
| 433 | + | ||
| 434 | + | ttm_bo_move_to_lru_tail(&gem_to_xe_bo(obj)->ttm); | |
| 435 | + | cond_resched_lock(lru_lock); | |
| 436 | + | } | |
| 437 | + | spin_unlock(lru_lock); | |
| 438 | + | } | |
| 439 | + | ||
| 413 | 440 | static int xe_preempt_work_begin(struct drm_exec *exec, struct xe_vm *vm, | |
| 414 | 441 | bool *done) | |
| 415 | 442 | { | |
| @@ -560,9 +587,7 @@ retry: | |||
| 560 | 587 | ||
| 561 | 588 | #undef retry_required | |
| 562 | 589 | ||
| 563 | - | spin_lock(&vm->xe->ttm.lru_lock); | |
| 564 | - | ttm_lru_bulk_move_tail(&vm->lru_bulk_move); | |
| 565 | - | spin_unlock(&vm->xe->ttm.lru_lock); | |
| 590 | + | xe_vm_bump_lru(vm, &exec); | |
| 566 | 591 | ||
| 567 | 592 | /* Point of no return. */ | |
| 568 | 593 | arm_preempt_fences(vm, &preempt_fences); | |
modified drivers/gpu/drm/xe/xe_vm.h
| @@ -284,6 +284,8 @@ int xe_vm_lock_vma(struct drm_exec *exec, struct xe_vma *vma); | |||
| 284 | 284 | int xe_vm_validate_rebind(struct xe_vm *vm, struct drm_exec *exec, | |
| 285 | 285 | unsigned int num_fences); | |
| 286 | 286 | ||
| 287 | + | void xe_vm_bump_lru(struct xe_vm *vm, struct drm_exec *exec); | |
| 288 | + | ||
| 287 | 289 | struct dma_fence *xe_vm_bind_kernel_bo(struct xe_vm *vm, struct xe_bo *bo, | |
| 288 | 290 | struct xe_exec_queue *q, u64 addr, | |
| 289 | 291 | enum xe_cache_level cache_lvl); | |