Compare
c902b6d709845def1d1d3ab818e0b9d9b962ab16..ffbfd3f98f4393e91dffce3a46ccb7cf5329cf2f
drm/xe: Don't transfer shrinker pages for pinned bos on purgeable state change
Pinned bos have their pages removed from the shrinker's shrinkable /
purgeable counts on pin, and added back on unpin according to the
bo's purgeable state at that time.
However, xe_bo_set_purgeable_shrinker() unconditionally transfers
pages between the shrinkable and purgeable counts. If the purgeable
state of a pinned bo changes, for example by userspace madvising
DONTNEED on a VMA of a bo that is also pinned as a scanout buffer,
this underflows one count and, after unpin, leaves the other one
permanently inflated.
Only update the purgeable flag for pinned bos, and leave the page
accounting to unpin.
Fixes: 536a2ead3a8f ("drm/xe/bo: Add purgeable shrinker state helpers")
Cc: Arvind Yadav <arvind.yadav@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: intel-xe@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v7.1+
Assisted-by: LLM
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Link: https://patch.msgid.link/20261009070053.7790-1-thomas.hellstrom@linux.intel.com
(cherry picked from commit afe6bc012034123fd838328668e609bf57e46bd3)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Thomas Hellström <thomas.hellstrom@linux.intel.com> · 2026-10-09 07:00 UTC · committed by Rodrigo Vivi
5 files changed,
+12
−10
- drivers/gpu/drm/xe/xe_bo.c
- kernel/trace/Makefile
- kernel/trace/ring_buffer.c
- kernel/trace/trace.c
- kernel/trace/trace_events_hist.c
modified drivers/gpu/drm/xe/xe_bo.c
| @@ -944,6 +944,8 @@ static int xe_bo_move_notify(struct xe_bo *bo, | |||
| 944 | 944 | * | |
| 945 | 945 | * Transfers pages between shrinkable and purgeable buckets when the BO | |
| 946 | 946 | * purgeable state changes. Called automatically from xe_bo_set_purgeable_state(). | |
| 947 | + | * For pinned BOs, whose pages are not accounted, only the purgeable flag is | |
| 948 | + | * updated, so that the correct bucket is used when the BO is unpinned. | |
| 947 | 949 | */ | |
| 948 | 950 | static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo, | |
| 949 | 951 | enum xe_madv_purgeable_state new_state) | |
| @@ -960,7 +962,8 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo, | |||
| 960 | 962 | return; | |
| 961 | 963 | ||
| 962 | 964 | xe_tt = container_of(tt, struct xe_ttm_tt, ttm); | |
| 963 | - | tt_pages = tt->num_pages; | |
| 965 | + | /* Pinned bos are not accounted. Only update the purgeable flag. */ | |
| 966 | + | tt_pages = xe_bo_is_pinned(bo) ? 0 : tt->num_pages; | |
| 964 | 967 | ||
| 965 | 968 | if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) { | |
| 966 | 969 | xe_tt->purgeable = true; | |
modified kernel/trace/Makefile
| @@ -146,11 +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 | - | $(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}') | |
| 150 | 150 | ||
| 151 | 151 | quiet_cmd_check_undefined = NM $< | |
| 152 | 152 | cmd_check_undefined = \ | |
| 153 | - | 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); \ | |
| 154 | 154 | if [ -n "$$undefsyms" ]; then \ | |
| 155 | 155 | echo "Unexpected symbols in $<:" >&2; \ | |
| 156 | 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 | ||
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 | ||