Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing/perf: Add might_fault check to syscall probes

Add a might_fault() check to validate that the perf sys_enter/sys_exit
probe callbacks are indeed called from a context where page faults can
be handled.

Cc: Michael Jeanson <mjeanson@efficios.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org
Cc: Joel Fernandes <joel@joelfernandes.org>
Link: https://lore.kernel.org/20241009010718.2050182-8-mathieu.desnoyers@efficios.com
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

authored by

Mathieu Desnoyers and committed by
Steven Rostedt (Google)
cdb537ac a3204c74

+3
+1
include/trace/perf.h
··· 84 84 u64 __count __attribute__((unused)); \ 85 85 struct task_struct *__task __attribute__((unused)); \ 86 86 \ 87 + might_fault(); \ 87 88 preempt_disable_notrace(); \ 88 89 do_perf_trace_##call(__data, args); \ 89 90 preempt_enable_notrace(); \
+2
kernel/trace/trace_syscalls.c
··· 602 602 * Syscall probe called with preemption enabled, but the ring 603 603 * buffer and per-cpu data require preemption to be disabled. 604 604 */ 605 + might_fault(); 605 606 guard(preempt_notrace)(); 606 607 607 608 syscall_nr = trace_get_syscall_nr(current, regs); ··· 711 710 * Syscall probe called with preemption enabled, but the ring 712 711 * buffer and per-cpu data require preemption to be disabled. 713 712 */ 713 + might_fault(); 714 714 guard(preempt_notrace)(); 715 715 716 716 syscall_nr = trace_get_syscall_nr(current, regs);