linux-yocto/kernel/trace
Guenter Roeck 9aef476717 ftrace: Do not over-allocate ftrace memory
commit be55257fab181b93af38f8c4b1b3cb453a78d742 upstream.

The pg_remaining calculation in ftrace_process_locs() assumes that
ENTRIES_PER_PAGE multiplied by 2^order equals the actual capacity of the
allocated page group. However, ENTRIES_PER_PAGE is PAGE_SIZE / ENTRY_SIZE
(integer division). When PAGE_SIZE is not a multiple of ENTRY_SIZE (e.g.
4096 / 24 = 170 with remainder 16), high-order allocations (like 256 pages)
have significantly more capacity than 256 * 170. This leads to pg_remaining
being underestimated, which in turn makes skip (derived from skipped -
pg_remaining) larger than expected, causing the WARN(skip != remaining)
to trigger.

Extra allocated pages for ftrace: 2 with 654 skipped
WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:7295 ftrace_process_locs+0x5bf/0x5e0

A similar problem in ftrace_allocate_records() can result in allocating
too many pages. This can trigger the second warning in
ftrace_process_locs().

Extra allocated pages for ftrace
WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:7276 ftrace_process_locs+0x548/0x580

Use the actual capacity of a page group to determine the number of pages
to allocate. Have ftrace_allocate_pages() return the number of allocated
pages to avoid having to calculate it. Use the actual page group capacity
when validating the number of unused pages due to skipped entries.
Drop the definition of ENTRIES_PER_PAGE since it is no longer used.

Cc: stable@vger.kernel.org
Fixes: 4a3efc6baf ("ftrace: Update the mcount_loc check of skipped entries")
Link: https://patch.msgid.link/20260113152243.3557219-1-linux@roeck-us.net
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2026-01-23 11:21:25 +01:00
..
rv rv: Make rtapp/pagefault monitor depends on CONFIG_MMU 2025-10-20 12:47:40 +02:00
blktrace.c Significant patch series in this pull request: 2025-08-03 16:23:09 -07:00
bpf_trace.c bpf: Fix verifier assumptions of bpf_d_path's output buffer 2026-01-02 12:56:37 +01:00
bpf_trace.h
error_report-traces.c
fgraph.c fgraph: Check ftrace_pids_enabled on registration for early filtering 2026-01-08 10:16:57 +01:00
fprobe.c tracing: fprobe: Fix to remove recorded module addresses from filter 2025-09-24 23:18:26 +09:00
ftrace_internal.h
ftrace.c ftrace: Do not over-allocate ftrace memory 2026-01-23 11:21:25 +01:00
Kconfig tracing changes for 6.17 2025-08-01 10:29:36 -07:00
kprobe_event_gen_test.c
Makefile tracing: Have eprobes have their own config option 2025-07-30 10:38:43 -04:00
pid_list.c tracing: Cleanup upper_empty() in pid_list 2025-05-14 11:19:32 -04:00
pid_list.h
power-traces.c PM: cpufreq: powernv/tracing: Move powernv_throttle trace event 2025-07-21 16:40:56 -04:00
preemptirq_delay_test.c kernel: trace: preemptirq_delay_test: use offstack cpu mask 2025-07-08 18:17:38 -04:00
rethook.c
ring_buffer_benchmark.c
ring_buffer.c ring-buffer: Do not warn in ring_buffer_map_get_reader() when reader catches up 2025-11-06 19:38:54 -05:00
rpm-traces.c
synth_event_gen_test.c
trace_benchmark.c
trace_benchmark.h
trace_boot.c
trace_branch.c tracing: branch: Use trace_tracing_is_on_cpu() instead of "disabled" field 2025-05-09 15:19:10 -04:00
trace_btf.c
trace_btf.h
trace_clock.c
trace_dynevent.c tracing: dynevent: Add a missing lockdown check on dynevent 2025-09-25 00:22:46 +09:00
trace_dynevent.h tracing: probes: Fix a possible race in trace_probe_log APIs 2025-05-13 22:23:34 +09:00
trace_entries.h ftrace: Expose call graph depth as unsigned int 2025-05-08 09:36:08 -04:00
trace_eprobe.c tracing: Have eprobes handle arrays 2025-07-24 22:57:32 +09:00
trace_event_perf.c
trace_events_filter_test.h
trace_events_filter.c tracing changes for 6.17 2025-08-01 10:29:36 -07:00
trace_events_hist.c tracing: Fix memory leaks in create_field_var() 2025-11-06 19:51:33 -05:00
trace_events_inject.c
trace_events_synth.c tracing: Fix fixed array of synthetic event 2026-01-02 12:57:28 +01:00
trace_events_trigger.c tracing updates for v6.16: 2025-05-29 21:04:36 -07:00
trace_events_user.c tracing updates for v6.18: 2025-10-05 09:43:36 -07:00
trace_events.c tracing: Do not register unsupported perf events 2026-01-02 12:57:22 +01:00
trace_export.c
trace_fprobe.c tracing: tprobe-events: Fix to put tracepoint_user when disable the tprobe 2025-11-07 07:36:20 +09:00
trace_functions_graph.c fgraph: Copy args in intermediate storage with entry 2025-08-22 17:32:35 -04:00
trace_functions.c tracing updates for v6.16: 2025-05-29 21:04:36 -07:00
trace_hwlat.c tracing: Replace opencoded cpumask_next_wrap() in move_to_next_cpu() 2025-07-08 18:17:29 -04:00
trace_irqsoff.c tracing: Fix irqoff tracers on failure of acquiring calltime 2025-10-08 12:10:44 -04:00
trace_kdb.c ring-buffer: Remove ring_buffer_read_prepare_sync() 2025-07-22 20:01:41 -04:00
trace_kprobe_selftest.c
trace_kprobe_selftest.h
trace_kprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-02 08:05:01 +09:00
trace_mmiotrace.c tracing/mmiotrace: Remove reference to unused per CPU data pointer 2025-05-08 09:36:09 -04:00
trace_nop.c
trace_osnoise.c tracing clean up and fixes for v6.18: 2025-10-09 12:18:22 -07:00
trace_output.c tracing: Have unsigned int function args displayed as hexadecimal 2025-08-01 19:14:51 -04:00
trace_output.h
trace_preemptirq.c
trace_printk.c
trace_probe_kernel.h
trace_probe_tmpl.h
trace_probe.c Probes updates for v6.17: 2025-07-30 15:38:01 -07:00
trace_probe.h tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-02 08:05:01 +09:00
trace_recursion_record.c
trace_sched_switch.c tracing: Ensure optimized hashing works 2025-09-30 17:27:58 -04:00
trace_sched_wakeup.c tracing: Fix wakeup tracers on failure of acquiring calltime 2025-10-08 12:10:26 -04:00
trace_selftest_dynamic.c
trace_selftest.c
trace_seq.c
trace_stack.c tracing updates for v6.16: 2025-05-29 21:04:36 -07:00
trace_stat.c
trace_stat.h
trace_synth.h
trace_syscalls.c tracing: Have syscall trace events show "0x" for values greater than 10 2025-09-23 09:29:29 -04:00
trace_uprobe.c tracing: Fix race condition in kprobe initialization causing NULL pointer dereference 2025-10-02 08:05:01 +09:00
trace.c trace: ftrace_dump_on_oops[] is not exported, make it static 2026-01-17 16:35:29 +01:00
trace.h tracing: Replace syscall RCU pointer assignment with READ/WRITE_ONCE() 2025-09-23 09:29:29 -04:00
tracing_map.c tracing: Use vmalloc_array() to improve code 2025-09-23 09:31:58 -04:00
tracing_map.h