Skip to content

Commit 13d750c

Browse files
compudjrostedt
authored andcommitted
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 <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Yonghong Song <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: [email protected] Cc: Joel Fernandes <[email protected]> Link: https://lore.kernel.org/[email protected] Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 0e6caab commit 13d750c

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

include/trace/trace_events.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ static struct trace_event_fields trace_event_fields_##call[] = { \
263263
tstruct \
264264
{} };
265265

266+
#undef DECLARE_EVENT_SYSCALL_CLASS
267+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
268+
266269
#undef DEFINE_EVENT_PRINT
267270
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
268271

@@ -396,11 +399,11 @@ static inline notrace int trace_event_get_offsets_##call( \
396399

397400
#include "stages/stage6_event_callback.h"
398401

399-
#undef DECLARE_EVENT_CLASS
400-
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
401-
\
402+
403+
#undef __DECLARE_EVENT_CLASS
404+
#define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
402405
static notrace void \
403-
trace_event_raw_event_##call(void *__data, proto) \
406+
do_trace_event_raw_event_##call(void *__data, proto) \
404407
{ \
405408
struct trace_event_file *trace_file = __data; \
406409
struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
@@ -425,15 +428,35 @@ trace_event_raw_event_##call(void *__data, proto) \
425428
\
426429
trace_event_buffer_commit(&fbuffer); \
427430
}
431+
432+
#undef DECLARE_EVENT_CLASS
433+
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
434+
__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
435+
PARAMS(assign), PARAMS(print)) \
436+
static notrace void \
437+
trace_event_raw_event_##call(void *__data, proto) \
438+
{ \
439+
do_trace_event_raw_event_##call(__data, args); \
440+
}
441+
442+
#undef DECLARE_EVENT_SYSCALL_CLASS
443+
#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, print) \
444+
__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \
445+
PARAMS(assign), PARAMS(print)) \
446+
static notrace void \
447+
trace_event_raw_event_##call(void *__data, proto) \
448+
{ \
449+
preempt_disable_notrace(); \
450+
do_trace_event_raw_event_##call(__data, args); \
451+
preempt_enable_notrace(); \
452+
}
453+
428454
/*
429455
* The ftrace_test_probe is compiled out, it is only here as a build time check
430456
* to make sure that if the tracepoint handling changes, the ftrace probe will
431457
* fail to compile unless it too is updated.
432458
*/
433459

434-
#undef DECLARE_EVENT_SYSCALL_CLASS
435-
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
436-
437460
#undef DEFINE_EVENT
438461
#define DEFINE_EVENT(template, call, proto, args) \
439462
static inline void ftrace_test_probe_##call(void) \
@@ -443,6 +466,8 @@ static inline void ftrace_test_probe_##call(void) \
443466

444467
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
445468

469+
#undef __DECLARE_EVENT_CLASS
470+
446471
#include "stages/stage7_class_define.h"
447472

448473
#undef DECLARE_EVENT_CLASS

kernel/trace/trace_syscalls.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id)
299299
int syscall_nr;
300300
int size;
301301

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+
302308
syscall_nr = trace_get_syscall_nr(current, regs);
303309
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
304310
return;
@@ -338,6 +344,12 @@ static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret)
338344
struct trace_event_buffer fbuffer;
339345
int syscall_nr;
340346

347+
/*
348+
* Syscall probe called with preemption enabled, but the ring
349+
* buffer and per-cpu data require preemption to be disabled.
350+
*/
351+
guard(preempt_notrace)();
352+
341353
syscall_nr = trace_get_syscall_nr(current, regs);
342354
if (syscall_nr < 0 || syscall_nr >= NR_syscalls)
343355
return;

0 commit comments

Comments
 (0)