Compare
89bab1dba8a0167ef0d819e0f55b6bafa038e87f..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
10 files changed,
+63
−24
- drivers/gpu/drm/xe/xe_bo.c
- drivers/gpu/drm/xe/xe_exec.c
- drivers/gpu/drm/xe/xe_oa.c
- drivers/gpu/drm/xe/xe_vm.c
- drivers/gpu/drm/xe/xe_vm.h
- kernel/trace/Makefile
- kernel/trace/ring_buffer.c
- kernel/trace/trace.c
- kernel/trace/trace_events_hist.c
- kernel/trace/undefsyms_base.c
modified drivers/gpu/drm/xe/xe_bo.c
| @@ -330,6 +330,12 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo, | |||
| 330 | 330 | return; | |
| 331 | 331 | } | |
| 332 | 332 | ||
| 333 | + | /* No resource: nothing is placed/mapped, so there is nothing to evict. */ | |
| 334 | + | if (!tbo->resource) { | |
| 335 | + | placement->num_placement = 0; | |
| 336 | + | return; | |
| 337 | + | } | |
| 338 | + | ||
| 333 | 339 | bo = ttm_to_xe_bo(tbo); | |
| 334 | 340 | if (bo->flags & XE_BO_FLAG_CPU_ADDR_MIRROR) { | |
| 335 | 341 | *placement = sys_placement; | |
| @@ -944,6 +950,8 @@ static int xe_bo_move_notify(struct xe_bo *bo, | |||
| 944 | 950 | * | |
| 945 | 951 | * Transfers pages between shrinkable and purgeable buckets when the BO | |
| 946 | 952 | * purgeable state changes. Called automatically from xe_bo_set_purgeable_state(). | |
| 953 | + | * For pinned BOs, whose pages are not accounted, only the purgeable flag is | |
| 954 | + | * updated, so that the correct bucket is used when the BO is unpinned. | |
| 947 | 955 | */ | |
| 948 | 956 | static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo, | |
| 949 | 957 | enum xe_madv_purgeable_state new_state) | |
| @@ -960,7 +968,8 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo, | |||
| 960 | 968 | return; | |
| 961 | 969 | ||
| 962 | 970 | xe_tt = container_of(tt, struct xe_ttm_tt, ttm); | |
| 963 | - | tt_pages = tt->num_pages; | |
| 971 | + | /* Pinned bos are not accounted. Only update the purgeable flag. */ | |
| 972 | + | tt_pages = xe_bo_is_pinned(bo) ? 0 : tt->num_pages; | |
| 964 | 973 | ||
| 965 | 974 | if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) { | |
| 966 | 975 | xe_tt->purgeable = true; | |
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_oa.c
| @@ -914,6 +914,13 @@ static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream, size_t size) | |||
| 914 | 914 | if (IS_ERR(bo)) | |
| 915 | 915 | return PTR_ERR(bo); | |
| 916 | 916 | ||
| 917 | + | /* | |
| 918 | + | * ttm_bo_type_kernel BOs are not zeroed on allocation, so the buffer can | |
| 919 | + | * hold stale data from previously freed pages. Since the OA buffer is | |
| 920 | + | * mmap'able by userspace, clear it here to avoid leaking kernel memory. | |
| 921 | + | */ | |
| 922 | + | xe_map_memset(stream->oa->xe, &bo->vmap, 0, 0, xe_bo_size(bo)); | |
| 923 | + | ||
| 917 | 924 | stream->oa_buffer.bo = bo; | |
| 918 | 925 | ||
| 919 | 926 | stream->oa_buffer.bounce = kmalloc(stream->oa_buffer.format->size, GFP_KERNEL); | |
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); | |
modified kernel/trace/Makefile
| @@ -146,12 +146,11 @@ KASAN_SANITIZE_undefsyms_base.o := y | |||
| 146 | 146 | ||
| 147 | 147 | UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __msan \ | |
| 148 | 148 | __aeabi_unwind_cpp __s390_indirect_jump __x86_indirect_thunk simple_ring_buffer \ | |
| 149 | - | current_thread_info_reg \ | |
| 150 | - | $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}') | |
| 149 | + | $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}') | |
| 151 | 150 | ||
| 152 | 151 | quiet_cmd_check_undefined = NM $< | |
| 153 | 152 | cmd_check_undefined = \ | |
| 154 | - | undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \ | |
| 153 | + | undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \ | |
| 155 | 154 | if [ -n "$$undefsyms" ]; then \ | |
| 156 | 155 | echo "Unexpected symbols in $<:" >&2; \ | |
| 157 | 156 | echo "$$undefsyms" >&2; \ | |
modified kernel/trace/ring_buffer.c
| @@ -2380,9 +2380,6 @@ int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, in | |||
| 2380 | 2380 | struct seq_file *m; | |
| 2381 | 2381 | int ret; | |
| 2382 | 2382 | ||
| 2383 | - | if (!cpumask_test_cpu(cpu, buffer->cpumask)) | |
| 2384 | - | return -ENODEV; | |
| 2385 | - | ||
| 2386 | 2383 | ret = seq_open(file, &rb_meta_seq_ops); | |
| 2387 | 2384 | if (ret) | |
| 2388 | 2385 | return ret; | |
| @@ -3630,8 +3627,10 @@ static void rb_inc_iter(struct ring_buffer_iter *iter) | |||
| 3630 | 3627 | /* Return the index into the sub-buffers for a given sub-buffer */ | |
| 3631 | 3628 | static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf) | |
| 3632 | 3629 | { | |
| 3633 | - | void *subbuf_array = rb_subbufs_from_meta(meta); | |
| 3630 | + | void *subbuf_array; | |
| 3634 | 3631 | ||
| 3632 | + | subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs; | |
| 3633 | + | subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size); | |
| 3635 | 3634 | return (subbuf - subbuf_array) / meta->subbuf_size; | |
| 3636 | 3635 | } | |
| 3637 | 3636 | ||
| @@ -7998,8 +7997,12 @@ consume: | |||
| 7998 | 7997 | goto out; | |
| 7999 | 7998 | } | |
| 8000 | 7999 | ||
| 8000 | + | /* Did the reader catch up with the writer? */ | |
| 8001 | + | if (cpu_buffer->reader_page == cpu_buffer->commit_page) | |
| 8002 | + | goto out; | |
| 8003 | + | ||
| 8001 | 8004 | reader = rb_get_reader_page(cpu_buffer); | |
| 8002 | - | if (!reader) | |
| 8005 | + | if (WARN_ON(!reader)) | |
| 8003 | 8006 | goto out; | |
| 8004 | 8007 | ||
| 8005 | 8008 | /* Check if any events were dropped */ | |
modified kernel/trace/trace.c
| @@ -5881,7 +5881,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp) | |||
| 5881 | 5881 | ||
| 5882 | 5882 | ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu); | |
| 5883 | 5883 | if (ret < 0) | |
| 5884 | - | trace_array_put(tr); | |
| 5884 | + | __trace_array_put(tr); | |
| 5885 | 5885 | return ret; | |
| 5886 | 5886 | } | |
| 5887 | 5887 | ||
modified kernel/trace/trace_events_hist.c
| @@ -289,7 +289,7 @@ static u64 hist_field_log2(struct hist_field *hist_field, | |||
| 289 | 289 | ||
| 290 | 290 | u64 val = hist_fn_call(operand, elt, buffer, rbe, event); | |
| 291 | 291 | ||
| 292 | - | return order_base_2(val); | |
| 292 | + | return (u64) ilog2(roundup_pow_of_two(val)); | |
| 293 | 293 | } | |
| 294 | 294 | ||
| 295 | 295 | static u64 hist_field_bucket(struct hist_field *hist_field, | |
| @@ -3090,7 +3090,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data, | |||
| 3090 | 3090 | key_field = hist_data->fields[i]; | |
| 3091 | 3091 | if (!first) | |
| 3092 | 3092 | seq_buf_putc(&s, ','); | |
| 3093 | - | expr_field_str(key_field, &s); | |
| 3093 | + | seq_buf_puts(&s, key_field->field->name); | |
| 3094 | 3094 | first = false; | |
| 3095 | 3095 | } | |
| 3096 | 3096 | ||
modified kernel/trace/undefsyms_base.c
| @@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | 10 | #include <linux/atomic.h> | |
| 11 | 11 | #include <linux/string.h> | |
| 12 | - | #include <asm/local.h> | |
| 13 | 12 | #include <asm/page.h> | |
| 14 | 13 | ||
| 15 | 14 | void undefsyms_base(void *p, int n); | |
| @@ -19,13 +18,11 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE); | |||
| 19 | 18 | void undefsyms_base(void *p, int n) | |
| 20 | 19 | { | |
| 21 | 20 | char buffer[256] = { 0 }; | |
| 22 | - | u32 u = 0; | |
| 23 | 21 | ||
| 22 | + | u32 u = 0; | |
| 24 | 23 | memset((char * volatile)page, 8, PAGE_SIZE); | |
| 25 | 24 | memset((char * volatile)buffer, 8, sizeof(buffer)); | |
| 26 | 25 | memcpy((void * volatile)p, buffer, sizeof(buffer)); | |
| 27 | 26 | cmpxchg((u32 * volatile)&u, 0, 8); | |
| 28 | - | cmpxchg((unsigned long *)p, 0, 8); | |
| 29 | - | local_set((local_t *)p, 8); | |
| 30 | 27 | WARN_ON(n == 0xdeadbeef); | |
| 31 | 28 | } | |