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

Configure Feed

Select the types of activity you want to include in your feed.

tracing/ftrace: disable preemption in syscall probe

In preparation for allowing system call enter/exit instrumentation to
handle page faults, make sure that ftrace can handle this change by
explicitly disabling preemption within the ftrace system call tracepoint
probes to respect the current expectations within ftrace ring buffer
code.

This change does not yet allow ftrace to take page faults per se within
its probe, but allows its existing probes to adapt to the upcoming
change.

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-3-mathieu.desnoyers@efficios.com
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
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)
13d750c2 0e6caab8

+44 -7
+32 -7
include/trace/trace_events.h
··· 263 263 tstruct \ 264 264 {} }; 265 265 266 + #undef DECLARE_EVENT_SYSCALL_CLASS 267 + #define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS 268 + 266 269 #undef DEFINE_EVENT_PRINT 267 270 #define DEFINE_EVENT_PRINT(template, name, proto, args, print) 268 271 ··· 399 396 400 397 #include "stages/stage6_event_callback.h" 401 398 402 - #undef DECLARE_EVENT_CLASS 403 - #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 404 - \ 399 + 400 + #undef __DECLARE_EVENT_CLASS 401 + #define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 405 402 static notrace void \ 406 - trace_event_raw_event_##call(void *__data, proto) \ 403 + do_trace_event_raw_event_##call(void *__data, proto) \ 407 404 { \ 408 405 struct trace_event_file *trace_file = __data; \ 409 406 struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ ··· 428 425 \ 429 426 trace_event_buffer_commit(&fbuffer); \ 430 427 } 428 + 429 + #undef DECLARE_EVENT_CLASS 430 + #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ 431 + __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ 432 + PARAMS(assign), PARAMS(print)) \ 433 + static notrace void \ 434 + trace_event_raw_event_##call(void *__data, proto) \ 435 + { \ 436 + do_trace_event_raw_event_##call(__data, args); \ 437 + } 438 + 439 + #undef DECLARE_EVENT_SYSCALL_CLASS 440 + #define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, print) \ 441 + __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ 442 + PARAMS(assign), PARAMS(print)) \ 443 + static notrace void \ 444 + trace_event_raw_event_##call(void *__data, proto) \ 445 + { \ 446 + preempt_disable_notrace(); \ 447 + do_trace_event_raw_event_##call(__data, args); \ 448 + preempt_enable_notrace(); \ 449 + } 450 + 431 451 /* 432 452 * The ftrace_test_probe is compiled out, it is only here as a build time check 433 453 * to make sure that if the tracepoint handling changes, the ftrace probe will 434 454 * fail to compile unless it too is updated. 435 455 */ 436 - 437 - #undef DECLARE_EVENT_SYSCALL_CLASS 438 - #define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS 439 456 440 457 #undef DEFINE_EVENT 441 458 #define DEFINE_EVENT(template, call, proto, args) \ ··· 465 442 } 466 443 467 444 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) 445 + 446 + #undef __DECLARE_EVENT_CLASS 468 447 469 448 #include "stages/stage7_class_define.h" 470 449
+12
kernel/trace/trace_syscalls.c
··· 299 299 int syscall_nr; 300 300 int size; 301 301 302 + /* 303 + * Syscall probe called with preemption enabled, but the ring 304 + * buffer and per-cpu data require preemption to be disabled. 305 + */ 306 + guard(preempt_notrace)(); 307 + 302 308 syscall_nr = trace_get_syscall_nr(current, regs); 303 309 if (syscall_nr < 0 || syscall_nr >= NR_syscalls) 304 310 return; ··· 343 337 struct syscall_metadata *sys_data; 344 338 struct trace_event_buffer fbuffer; 345 339 int syscall_nr; 340 + 341 + /* 342 + * Syscall probe called with preemption enabled, but the ring 343 + * buffer and per-cpu data require preemption to be disabled. 344 + */ 345 + guard(preempt_notrace)(); 346 346 347 347 syscall_nr = trace_get_syscall_nr(current, regs); 348 348 if (syscall_nr < 0 || syscall_nr >= NR_syscalls)