From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07DCE199930; Mon, 30 Sep 2024 19:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; cv=none; b=bwfmEc3SSVNCcZayxpZ+m4j+RuCNCu9dTYJdoGczCr78MhfYGx4EcY0ycsdB0Lw6lWqYX4aSfmoRBUmrytgOjFgLQXaxm0YqJjDdxwPiNRIgsPjsj3yIUrJ5FJjVxDuX14v4zYyzRfpoZvkC7beLKTsCgMMDhPTFRhLZlMuPguU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; c=relaxed/simple; bh=BtUdvfoGNYu9/1n2UYHiEotu2NVSo7k7uUSWVyyG0zs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tpNv/kgB/7dOPJ6iSv53CAHzPOuQ6nXkdNLd3T9Z5XuWYKSd40xIPTRNytSX6BY/QFOtyDZ2wVi5CukRCu5EN68oAXXVYUD/YGEbnAW/UIoSz6DgsZTbfLiMRoxbk5Zg38y9iQs96rxjGIt2v5gF5ywRol59qanqe/xi+4H6IA0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=P2DE+IFL; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="P2DE+IFL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724390; bh=BtUdvfoGNYu9/1n2UYHiEotu2NVSo7k7uUSWVyyG0zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P2DE+IFLzFWRnAIZVJVNyBfXmIBcCimaW9Ebda9UPtL7PFmN1YHo0vOymCor7VpN9 Nr5ZWgnMCH5ZHlsrC63KT0kDxFjRA7BCYV1GhXtT9CzdYWb5sxW39pawBzY8eyEQkR aesVCcdlQg83CbEpVmUyCIq4VcLvVCCDgm7aSkq71Ed8XCykehzmjRF5DBb/HY5YK8 32SAhh3DWRliDifM6Gafg3khjIMDscGB/q+wNZHNsCbBUtDdMYVnLwmK6Ibc5f/D4l xKjK8pk6yT6hKM/Ra6w//DhwA1Yn99xQJ2YrU/94p8Yalcvk703jI9q4gPfPzuVC+g rqC1cI7NzOV4Q== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK255lSzQk1; Mon, 30 Sep 2024 15:26:30 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 1/8] tracing: Declare system call tracepoints with TRACE_EVENT_SYSCALL Date: Mon, 30 Sep 2024 15:23:50 -0400 Message-Id: <20240930192357.1154417-2-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for allowing system call tracepoints to handle page faults, introduce TRACE_EVENT_SYSCALL to declare the sys_enter/sys_exit tracepoints. Emit the static inlines register_trace_syscall_##name for events declared with TRACE_EVENT_SYSCALL, allowing source-level validation that only probes meant to handle system call entry/exit events are registered to them. Move the common code between __DECLARE_TRACE and __DECLARE_TRACE_SYSCALL into __DECLARE_TRACE_COMMON. This change is not meant to alter the generated code, and only prepares the following modifications. Signed-off-by: Mathieu Desnoyers Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/linux/tracepoint.h | 66 +++++++++++++++++++++++++-------- include/trace/bpf_probe.h | 3 ++ include/trace/define_trace.h | 5 +++ include/trace/events/syscalls.h | 4 +- include/trace/perf.h | 3 ++ include/trace/trace_events.h | 28 ++++++++++++++ kernel/entry/common.c | 4 +- kernel/trace/trace_syscalls.c | 8 ++-- 8 files changed, 98 insertions(+), 23 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 6be396bb4297..2e4b4952bba2 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -248,10 +248,28 @@ static inline struct tracepoint *tracepoint_ptr_deref= (tracepoint_ptr_t *p) * site if it is not watching, as it will need to be active when the * tracepoint is enabled. */ -#define __DECLARE_TRACE(name, proto, args, cond, data_proto) \ +#define __DECLARE_TRACE_COMMON(name, proto, args, cond, data_proto) \ extern int __traceiter_##name(data_proto); \ DECLARE_STATIC_CALL(tp_func_##name, __traceiter_##name); \ extern struct tracepoint __tracepoint_##name; \ + static inline int \ + unregister_trace_##name(void (*probe)(data_proto), void *data) \ + { \ + return tracepoint_probe_unregister(&__tracepoint_##name,\ + (void *)probe, data); \ + } \ + static inline void \ + check_trace_callback_type_##name(void (*cb)(data_proto)) \ + { \ + } \ + static inline bool \ + trace_##name##_enabled(void) \ + { \ + return static_key_false(&__tracepoint_##name.key); \ + } + +#define __DECLARE_TRACE(name, proto, args, cond, data_proto) \ + __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), cond, PARAMS(da= ta_proto)) \ static inline void trace_##name(proto) \ { \ if (static_key_false(&__tracepoint_##name.key)) \ @@ -263,8 +281,13 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) "RCU not watching for tracepoint"); \ } \ } \ - __DECLARE_TRACE_RCU(name, PARAMS(proto), PARAMS(args), \ - PARAMS(cond)) \ + static inline void trace_##name##_rcuidle(proto) \ + { \ + if (static_key_false(&__tracepoint_##name.key)) \ + __DO_TRACE(name, \ + TP_ARGS(args), \ + TP_CONDITION(cond), 1); \ + } \ static inline int \ register_trace_##name(void (*probe)(data_proto), void *data) \ { \ @@ -277,21 +300,26 @@ static inline struct tracepoint *tracepoint_ptr_deref= (tracepoint_ptr_t *p) { \ return tracepoint_probe_register_prio(&__tracepoint_##name, \ (void *)probe, data, prio); \ - } \ - static inline int \ - unregister_trace_##name(void (*probe)(data_proto), void *data) \ - { \ - return tracepoint_probe_unregister(&__tracepoint_##name,\ - (void *)probe, data); \ - } \ - static inline void \ - check_trace_callback_type_##name(void (*cb)(data_proto)) \ + } + +#define __DECLARE_TRACE_SYSCALL(name, proto, args, cond, data_proto) \ + __DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), cond, PARAMS(da= ta_proto)) \ + static inline void trace_syscall_##name(proto) \ { \ + if (static_key_false(&__tracepoint_##name.key)) \ + __DO_TRACE(name, \ + TP_ARGS(args), \ + TP_CONDITION(cond), 0); \ + if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \ + WARN_ONCE(!rcu_is_watching(), \ + "RCU not watching for tracepoint"); \ + } \ } \ - static inline bool \ - trace_##name##_enabled(void) \ + static inline int \ + register_trace_syscall_##name(void (*probe)(data_proto), void *data) \ { \ - return static_key_false(&__tracepoint_##name.key); \ + return tracepoint_probe_register(&__tracepoint_##name, \ + (void *)probe, data); \ } =20 /* @@ -439,6 +467,11 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \ PARAMS(void *__data, proto)) =20 +#define DECLARE_TRACE_SYSCALL(name, proto, args) \ + __DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \ + cpu_online(raw_smp_processor_id()), \ + PARAMS(void *__data, proto)) + #define TRACE_EVENT_FLAGS(event, flag) =20 #define TRACE_EVENT_PERF_PERM(event, expr...) @@ -576,6 +609,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) struct, assign, print) \ DECLARE_TRACE_CONDITION(name, PARAMS(proto), \ PARAMS(args), PARAMS(cond)) +#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, \ + print, reg, unreg) \ + DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args)) =20 #define TRACE_EVENT_FLAGS(event, flag) =20 diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h index a2ea11cc912e..c85bbce5aaa5 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -53,6 +53,9 @@ __bpf_trace_##call(void *__data, proto) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + /* * This part is compiled out, it is only here as a build time check * to make sure that if the tracepoint handling changes, the diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h index 00723935dcc7..ff5fa17a6259 100644 --- a/include/trace/define_trace.h +++ b/include/trace/define_trace.h @@ -46,6 +46,10 @@ assign, print, reg, unreg) \ DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args)) =20 +#undef TRACE_EVENT_SYSCALL +#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, print, reg,= unreg) \ + DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args)) + #undef TRACE_EVENT_NOP #define TRACE_EVENT_NOP(name, proto, args, struct, assign, print) =20 @@ -107,6 +111,7 @@ #undef TRACE_EVENT #undef TRACE_EVENT_FN #undef TRACE_EVENT_FN_COND +#undef TRACE_EVENT_SYSCALL #undef TRACE_EVENT_CONDITION #undef TRACE_EVENT_NOP #undef DEFINE_EVENT_NOP diff --git a/include/trace/events/syscalls.h b/include/trace/events/syscall= s.h index b6e0cbc2c71f..f31ff446b468 100644 --- a/include/trace/events/syscalls.h +++ b/include/trace/events/syscalls.h @@ -15,7 +15,7 @@ =20 #ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS =20 -TRACE_EVENT_FN(sys_enter, +TRACE_EVENT_SYSCALL(sys_enter, =20 TP_PROTO(struct pt_regs *regs, long id), =20 @@ -41,7 +41,7 @@ TRACE_EVENT_FN(sys_enter, =20 TRACE_EVENT_FLAGS(sys_enter, TRACE_EVENT_FL_CAP_ANY) =20 -TRACE_EVENT_FN(sys_exit, +TRACE_EVENT_SYSCALL(sys_exit, =20 TP_PROTO(struct pt_regs *regs, long ret), =20 diff --git a/include/trace/perf.h b/include/trace/perf.h index 2c11181c82e0..ded997af481e 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -55,6 +55,9 @@ perf_trace_##call(void *__data, proto) \ head, __task); \ } =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + /* * This part is compiled out, it is only here as a build time check * to make sure that if the tracepoint handling changes, the diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index c2f9cabf154d..8bcbb9ee44de 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -45,6 +45,16 @@ PARAMS(print)); \ DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); =20 +#undef TRACE_EVENT_SYSCALL +#define TRACE_EVENT_SYSCALL(name, proto, args, tstruct, assign, print, reg= , unreg) \ + DECLARE_EVENT_SYSCALL_CLASS(name, \ + PARAMS(proto), \ + PARAMS(args), \ + PARAMS(tstruct), \ + PARAMS(assign), \ + PARAMS(print)); \ + DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args)); + #include "stages/stage1_struct_define.h" =20 #undef DECLARE_EVENT_CLASS @@ -57,6 +67,9 @@ \ static struct trace_event_class event_class_##name; =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT #define DEFINE_EVENT(template, name, proto, args) \ static struct trace_event_call __used \ @@ -117,6 +130,9 @@ tstruct; \ }; =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT #define DEFINE_EVENT(template, name, proto, args) =20 @@ -208,6 +224,9 @@ static struct trace_event_functions trace_event_type_fu= ncs_##call =3D { \ .trace =3D trace_raw_output_##call, \ }; =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT_PRINT #define DEFINE_EVENT_PRINT(template, call, proto, args, print) \ static notrace enum print_line_t \ @@ -265,6 +284,9 @@ static inline notrace int trace_event_get_offsets_##cal= l( \ return __data_size; \ } =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) =20 /* @@ -409,6 +431,9 @@ trace_event_raw_event_##call(void *__data, proto) \ * fail to compile unless it too is updated. */ =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT #define DEFINE_EVENT(template, call, proto, args) \ static inline void ftrace_test_probe_##call(void) \ @@ -434,6 +459,9 @@ static struct trace_event_class __used __refdata event_= class_##call =3D { \ _TRACE_PERF_INIT(call) \ }; =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT #define DEFINE_EVENT(template, call, proto, args) \ \ diff --git a/kernel/entry/common.c b/kernel/entry/common.c index 90843cc38588..d08472421d0e 100644 --- a/kernel/entry/common.c +++ b/kernel/entry/common.c @@ -58,7 +58,7 @@ long syscall_trace_enter(struct pt_regs *regs, long sysca= ll, syscall =3D syscall_get_nr(current, regs); =20 if (unlikely(work & SYSCALL_WORK_SYSCALL_TRACEPOINT)) { - trace_sys_enter(regs, syscall); + trace_syscall_sys_enter(regs, syscall); /* * Probes or BPF hooks in the tracepoint may have changed the * system call number as well. @@ -166,7 +166,7 @@ static void syscall_exit_work(struct pt_regs *regs, uns= igned long work) audit_syscall_exit(regs); =20 if (work & SYSCALL_WORK_SYSCALL_TRACEPOINT) - trace_sys_exit(regs, syscall_get_return_value(current, regs)); + trace_syscall_sys_exit(regs, syscall_get_return_value(current, regs)); =20 step =3D report_single_step(work); if (step || work & SYSCALL_WORK_SYSCALL_TRACE) diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 9c581d6da843..067f8e2b930f 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -377,7 +377,7 @@ static int reg_event_syscall_enter(struct trace_event_f= ile *file, return -ENOSYS; mutex_lock(&syscall_trace_lock); if (!tr->sys_refcount_enter) - ret =3D register_trace_sys_enter(ftrace_syscall_enter, tr); + ret =3D register_trace_syscall_sys_enter(ftrace_syscall_enter, tr); if (!ret) { rcu_assign_pointer(tr->enter_syscall_files[num], file); tr->sys_refcount_enter++; @@ -415,7 +415,7 @@ static int reg_event_syscall_exit(struct trace_event_fi= le *file, return -ENOSYS; mutex_lock(&syscall_trace_lock); if (!tr->sys_refcount_exit) - ret =3D register_trace_sys_exit(ftrace_syscall_exit, tr); + ret =3D register_trace_syscall_sys_exit(ftrace_syscall_exit, tr); if (!ret) { rcu_assign_pointer(tr->exit_syscall_files[num], file); tr->sys_refcount_exit++; @@ -631,7 +631,7 @@ static int perf_sysenter_enable(struct trace_event_call= *call) =20 mutex_lock(&syscall_trace_lock); if (!sys_perf_refcount_enter) - ret =3D register_trace_sys_enter(perf_syscall_enter, NULL); + ret =3D register_trace_syscall_sys_enter(perf_syscall_enter, NULL); if (ret) { pr_info("event trace: Could not activate syscall entry trace point"); } else { @@ -728,7 +728,7 @@ static int perf_sysexit_enable(struct trace_event_call = *call) =20 mutex_lock(&syscall_trace_lock); if (!sys_perf_refcount_exit) - ret =3D register_trace_sys_exit(perf_syscall_exit, NULL); + ret =3D register_trace_syscall_sys_exit(perf_syscall_exit, NULL); if (ret) { pr_info("event trace: Could not activate syscall exit trace point"); } else { --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72691199E82; Mon, 30 Sep 2024 19:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; cv=none; b=giofidvLKvMALowA3zNNQ/xN5POJbezXFHJCfETIk3t/fRQpWmYlukq5UonYCbr8gtUzlb1bOAyksd9o0okQ+2Av2aeh1bdmJhLV8v6QR+aKcdpm9OKn9N3yLorXXhlqBX9hlpYIEQUIQTcaqZ4HJcu94OwJa8wHSYyWjbVheeQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; c=relaxed/simple; bh=l2ujnQzLE5sJ+zSp4VjmrpS8WBs1Z995gnqtqR4i1nA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p9uA2F8Ajd7idn6lJHk1SLaCJ5fxZPmhy5wM3o0WZsq81ysa/9QCyy69qGK8st4YW9x/FaJtoqBqDBC1faBDOpXZzmNGLU26cn+DHH/QE6HA6wfxIwnwzJbRocxIZtrLX13VBtRU3MuaznmZmI3xehmKyRgq2CpbA08fdljjuZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=rSXz/Ok9; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="rSXz/Ok9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724391; bh=l2ujnQzLE5sJ+zSp4VjmrpS8WBs1Z995gnqtqR4i1nA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rSXz/Ok9aQTzjCKRw5X2p1Lz39a9+bj6VrFO8dc5qAJh6GzeUYYhxBF8H81HdLBQU W9nxy+AOdlKz2LPa9yuOjWtTO+BMGmmTiyvxwp9ELNHix9k54L8E9v2icLqPLUOz0v N4IYYbXmohpzyF+SuKLnwbH+/SkZgVeJBMhlCqhoOWIamKZm2/iH8DN/d7bcyhSFqD susYhk56LuTE7fUI1IWntwWmWxuY8jzlE1RTK1TkDDH0dnhu7bRR4hRRYfo+W5W5LQ d1UTwEwTpJwdKxZUdKa4QhQIrHeJ5Lq0KsTbJeZ+GRLXEfzqrxgyW3WfMouDWhN/l/ xjWQFgSUEEmJw== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK30h9WzQXn; Mon, 30 Sep 2024 15:26:31 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 2/8] tracing/ftrace: guard syscall probe with preempt_notrace Date: Mon, 30 Sep 2024 15:23:51 -0400 Message-Id: <20240930192357.1154417-3-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Mathieu Desnoyers Acked-by: Masami Hiramatsu (Google) Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/trace_events.h | 38 ++++++++++++++++++++++++++++------- kernel/trace/trace_syscalls.c | 12 +++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 8bcbb9ee44de..0228d9ed94a3 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -263,6 +263,9 @@ static struct trace_event_fields trace_event_fields_##c= all[] =3D { \ tstruct \ {} }; =20 +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS + #undef DEFINE_EVENT_PRINT #define DEFINE_EVENT_PRINT(template, name, proto, args, print) =20 @@ -396,11 +399,11 @@ static inline notrace int trace_event_get_offsets_##c= all( \ =20 #include "stages/stage6_event_callback.h" =20 -#undef DECLARE_EVENT_CLASS -#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ - \ + +#undef __DECLARE_EVENT_CLASS +#define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ static notrace void \ -trace_event_raw_event_##call(void *__data, proto) \ +do_trace_event_raw_event_##call(void *__data, proto) \ { \ struct trace_event_file *trace_file =3D __data; \ struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ @@ -425,15 +428,34 @@ trace_event_raw_event_##call(void *__data, proto) \ \ trace_event_buffer_commit(&fbuffer); \ } + +#undef DECLARE_EVENT_CLASS +#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ +__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ + PARAMS(assign), PARAMS(print)) \ +static notrace void \ +trace_event_raw_event_##call(void *__data, proto) \ +{ \ + do_trace_event_raw_event_##call(__data, args); \ +} + +#undef DECLARE_EVENT_SYSCALL_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, pr= int) \ +__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ + PARAMS(assign), PARAMS(print)) \ +static notrace void \ +trace_event_raw_event_##call(void *__data, proto) \ +{ \ + guard(preempt_notrace)(); \ + do_trace_event_raw_event_##call(__data, args); \ +} + /* * The ftrace_test_probe is compiled out, it is only here as a build time = check * to make sure that if the tracepoint handling changes, the ftrace probe = will * fail to compile unless it too is updated. */ =20 -#undef DECLARE_EVENT_SYSCALL_CLASS -#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS - #undef DEFINE_EVENT #define DEFINE_EVENT(template, call, proto, args) \ static inline void ftrace_test_probe_##call(void) \ @@ -443,6 +465,8 @@ static inline void ftrace_test_probe_##call(void) \ =20 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) =20 +#undef __DECLARE_EVENT_CLASS + #include "stages/stage7_class_define.h" =20 #undef DECLARE_EVENT_CLASS diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 067f8e2b930f..abf0e0b7cd0b 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -299,6 +299,12 @@ static void ftrace_syscall_enter(void *data, struct pt= _regs *regs, long id) int syscall_nr; int size; =20 + /* + * Syscall probe called with preemption enabled, but the ring + * buffer and per-cpu data require preemption to be disabled. + */ + guard(preempt_notrace)(); + syscall_nr =3D trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; @@ -338,6 +344,12 @@ static void ftrace_syscall_exit(void *data, struct pt_= regs *regs, long ret) struct trace_event_buffer fbuffer; int syscall_nr; =20 + /* + * Syscall probe called with preemption enabled, but the ring + * buffer and per-cpu data require preemption to be disabled. + */ + guard(preempt_notrace)(); + syscall_nr =3D trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD5D1199E88; Mon, 30 Sep 2024 19:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; cv=none; b=R8cT1QQ3C7xVtUZc9BV1FErz904HlLyHE90S8kzt7yMc3jxKmxew7GEX6c8gcb0t2V/lyM+lBrST+cbQrsU+2rk1v4cHRlFJz9rZ4S+qRY6eea0TXvjtMCIJw7KfT1lBFWqmOyH3fRji0PEl2NjzVPgDX5em6NtOMTMqblNgW1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; c=relaxed/simple; bh=MWuMSBa0wltjyl8Q6xHGNS8TrHMMgd8rkPqmN7QbQzs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=l11P0tiINYUvPzo/skaT7pWw2ah7zhND/SpwY6b9no17SDXVmr5Nmfwj9lEwWArAkJCoPx6ZXbdSfElVil3H2ekrlCgtL40dnzgQQyztoUOfpOc7ea6PThMCiTFGQIjluYmsuzCSv6zjH0y/rH9lBnuWq2TDIx2ojX089lSvwls= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=HF25+y90; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="HF25+y90" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724391; bh=MWuMSBa0wltjyl8Q6xHGNS8TrHMMgd8rkPqmN7QbQzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HF25+y90fKuI2ulXl05/Jmj2CBHObD/AE7uoluW6d83w5lbuFqVPiRFuysLF/VVt6 V0MmaO3xc9z8sv8tObgBg5rT8S2s8mc861CM/p9eIL2P/opoMHlcLIK6bh9v96z9ER GIJ88QULzXbSUm+qfNFAF8AXub+bSELrdiDNcxOJIjBe2StStt2g62Y3wjuF80EMLk CTlIGscuA8MBBV0US/8dU7CvqQyPqsZrgnLEvH+Kv/ku7hYoSR0U76s/s0+oYCFP/9 4X9a2up5Puhb+tVsVFQ/hdI+jxFmNidlMIOZT2kq2jcO3j8kBShg0nsySoxMJ5Ruz3 sg0oyEM+nznvA== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK33LvMzQXp; Mon, 30 Sep 2024 15:26:31 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 3/8] tracing/perf: guard syscall probe with preempt_notrace Date: Mon, 30 Sep 2024 15:23:52 -0400 Message-Id: <20240930192357.1154417-4-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for allowing system call enter/exit instrumentation to handle page faults, make sure that perf can handle this change by explicitly disabling preemption within the perf system call tracepoint probes to respect the current expectations within perf ring buffer code. This change does not yet allow perf to take page faults per se within its probe, but allows its existing probes to adapt to the upcoming change. Signed-off-by: Mathieu Desnoyers Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/perf.h | 41 +++++++++++++++++++++++++++++++---- kernel/trace/trace_syscalls.c | 12 ++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/trace/perf.h b/include/trace/perf.h index ded997af481e..5650c1bad088 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -12,10 +12,10 @@ #undef __perf_task #define __perf_task(t) (__task =3D (t)) =20 -#undef DECLARE_EVENT_CLASS -#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ +#undef __DECLARE_EVENT_CLASS +#define __DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ static notrace void \ -perf_trace_##call(void *__data, proto) \ +do_perf_trace_##call(void *__data, proto) \ { \ struct trace_event_call *event_call =3D __data; \ struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\ @@ -55,8 +55,38 @@ perf_trace_##call(void *__data, proto) \ head, __task); \ } =20 +/* + * Define unused __count and __task variables to use @args to pass + * arguments to do_perf_trace_##call. This is needed because the + * macros __perf_count and __perf_task introduce the side-effect to + * store copies into those local variables. + */ +#undef DECLARE_EVENT_CLASS +#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ +__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ + PARAMS(assign), PARAMS(print)) \ +static notrace void \ +perf_trace_##call(void *__data, proto) \ +{ \ + u64 __count __attribute__((unused)); \ + struct task_struct *__task __attribute__((unused)); \ + \ + do_perf_trace_##call(__data, args); \ +} + #undef DECLARE_EVENT_SYSCALL_CLASS -#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, pr= int) \ +__DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args), PARAMS(tstruct), \ + PARAMS(assign), PARAMS(print)) \ +static notrace void \ +perf_trace_##call(void *__data, proto) \ +{ \ + u64 __count __attribute__((unused)); \ + struct task_struct *__task __attribute__((unused)); \ + \ + guard(preempt_notrace)(); \ + do_perf_trace_##call(__data, args); \ +} =20 /* * This part is compiled out, it is only here as a build time check @@ -76,4 +106,7 @@ static inline void perf_test_probe_##call(void) \ DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args)) =20 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE) + +#undef __DECLARE_EVENT_CLASS + #endif /* CONFIG_PERF_EVENTS */ diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index abf0e0b7cd0b..a3d8ac00793e 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -594,6 +594,12 @@ static void perf_syscall_enter(void *ignore, struct pt= _regs *regs, long id) int rctx; int size; =20 + /* + * Syscall probe called with preemption enabled, but the ring + * buffer and per-cpu data require preemption to be disabled. + */ + guard(preempt_notrace)(); + syscall_nr =3D trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; @@ -694,6 +700,12 @@ static void perf_syscall_exit(void *ignore, struct pt_= regs *regs, long ret) int rctx; int size; =20 + /* + * Syscall probe called with preemption enabled, but the ring + * buffer and per-cpu data require preemption to be disabled. + */ + guard(preempt_notrace)(); + syscall_nr =3D trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D1E4199E8B; Mon, 30 Sep 2024 19:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; cv=none; b=LbgQ/BOYvQaZbrqB1D/VxQ6tPzwJikG755ExkTldDIs0FE5ASwx+sRhJMYiTUC1wbiGKg8ox27nDaNXnMetw13wfRO39dreuDtgaIe4mrc6qVxjCYkiwovkpVflWkzqzNLbx8BEYIjf4OqeO2s6MPIv5Z1Q8PowUORyek5YB4ZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724394; c=relaxed/simple; bh=uQvGGRjFBg81/CMoacZvVtIn7AY3sce+G3Hk/Qjw2wU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YMDfbFrTdn9Z1MAIarMbAGLf+hiDFxKc3ocr1iBwbMCH9rEbpey83588mUW3lhJ7erTMzZQrcTTlMEkzG4iQOTSb99cvdIZfMnfnUQ0tUU6waTQvLg9gTh2GRBWBHOoY8qRWcmlZq6m9jCEFqsdwTGeSCOIuGNG0SeFdF6SEp1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=FqR0hWKG; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="FqR0hWKG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724392; bh=uQvGGRjFBg81/CMoacZvVtIn7AY3sce+G3Hk/Qjw2wU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FqR0hWKG0kr5XJzMo2Jfeb7KmZjhMfJFpUg5zW8DW474CA9bJGBICnOoGwK8ePETB PcNmwPWAWSUNZlOl0QaJ6JagTTRhNp5MYjn7DNVVGqTTd+xMkhThx15GLYcxS5nQXv 9iigsrup3zLAaNXazmDxRPIuLDsFVkZQZXZEZAcdFWHiMmZDq1FjSZu9iA9UDzdyOr nHconsWJe0gZCC4ej5KSIvtf70w9iUHVcpWSFszC4MK4oDUpxBufowWnYpUqWN9ZgC 01T/r0CnXN+/NjqKxyzFXhkBDqdvwlc+V0/GeAlkJrsHKod00S6s7MgeSyJ8lcTN4U 7HmlcJFjhZ+BQ== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK364vfzQXq; Mon, 30 Sep 2024 15:26:31 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Andrii Nakryiko , Michael Jeanson Subject: [PATCH resend 4/8] tracing/bpf: guard syscall probe with preempt_notrace Date: Mon, 30 Sep 2024 15:23:53 -0400 Message-Id: <20240930192357.1154417-5-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for allowing system call enter/exit instrumentation to handle page faults, make sure that bpf can handle this change by explicitly disabling preemption within the bpf system call tracepoint probes to respect the current expectations within bpf tracing code. This change does not yet allow bpf to take page faults per se within its probe, but allows its existing probes to adapt to the upcoming change. Signed-off-by: Mathieu Desnoyers Acked-by: Andrii Nakryiko Tested-by: Andrii Nakryiko # BPF parts Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/bpf_probe.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h index c85bbce5aaa5..211b98d45fc6 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -53,8 +53,17 @@ __bpf_trace_##call(void *__data, proto) \ #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \ __BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) =20 +#define __BPF_DECLARE_TRACE_SYSCALL(call, proto, args) \ +static notrace void \ +__bpf_trace_##call(void *__data, proto) \ +{ \ + guard(preempt_notrace)(); \ + CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(__data, CAST_TO_U64(args)); \ +} + #undef DECLARE_EVENT_SYSCALL_CLASS -#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS +#define DECLARE_EVENT_SYSCALL_CLASS(call, proto, args, tstruct, assign, pr= int) \ + __BPF_DECLARE_TRACE_SYSCALL(call, PARAMS(proto), PARAMS(args)) =20 /* * This part is compiled out, it is only here as a build time check --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD01919A288; Mon, 30 Sep 2024 19:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; cv=none; b=g3SzjAtV9I7lEYVwtEVxSvyGHpz6T/J7wEv1Q3KCZqb/v4ywIrlf3oNQub0gHrdL6EX9AIDqPRyUUqOBLjawgPyL+/cxKQJZJ/xi92gdx2SYL8FxOUfxDcDka9fMJG9APXrWKCWG2OGkTH1H1JwL3867GItXz7o/aE+g0ROQVlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; c=relaxed/simple; bh=YAvfsUVzkdfENSEXcdox6M3fVrWGL98jFGGUdZ3uQlo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hh+9y4ywSXXaDWaf65QD38WJAyPyys94+SB6OqB0dqBuT/k8Aq9QsY/M5I4HvwHvNvYpZIuTMDyke/Nn/1Hn96eFwHIBmDnhgxsBCja/5Q1wrUojcUL7cbf09f2GyAcStSidu1DonxGrkJXSBlNF6ffafAkKei08/iEuxf/3Bw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=u6Ekf46q; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="u6Ekf46q" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724392; bh=YAvfsUVzkdfENSEXcdox6M3fVrWGL98jFGGUdZ3uQlo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u6Ekf46qlP8Twrz9HI8S9JwYn0vP6FGn3guxZNAp5YoGh1deUucH86mPWQriTIfPC 3TxQkudaY4TwWja926DGvuaPSOLk6pXCis3uX1dNCxNtKwRFAIal9ZjSP/jfbwkKtc L6UiCnn5qLXSPhTZrdcZee+WfRBbxgucGiYkroACYKMzqAUYlN+Nr80mKofaXknFwt EWy02iiuXbUv2EVxNpOJqxbPG0HXGs7yvymIVBsakk32ugKxixOo77KXyjqK3sfIBu lO2ocXBxRlQix8MD/W8zRjSw7FZpXzCkSYzreqobA5/lQaLdM05qSx1mSCVp0QSkau 0PwR+5IpE0+pA== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK41kL0zQPl; Mon, 30 Sep 2024 15:26:32 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 5/8] tracing: Allow system call tracepoints to handle page faults Date: Mon, 30 Sep 2024 15:23:54 -0400 Message-Id: <20240930192357.1154417-6-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use Tasks Trace RCU to protect iteration of system call enter/exit tracepoint probes to allow those probes to handle page faults. In preparation for this change, all tracers registering to system call enter/exit tracepoints should expect those to be called with preemption enabled. This allows tracers to fault-in userspace system call arguments such as path strings within their probe callbacks. Signed-off-by: Mathieu Desnoyers Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/linux/tracepoint.h | 25 +++++++++++++++++-------- init/Kconfig | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h index 2e4b4952bba2..106e951896c2 100644 --- a/include/linux/tracepoint.h +++ b/include/linux/tracepoint.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include =20 @@ -89,6 +90,7 @@ int unregister_tracepoint_module_notifier(struct notifier= _block *nb) #ifdef CONFIG_TRACEPOINTS static inline void tracepoint_synchronize_unregister(void) { + synchronize_rcu_tasks_trace(); synchronize_srcu(&tracepoint_srcu); synchronize_rcu(); } @@ -191,7 +193,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) * it_func[0] is never NULL because there is at least one element in the a= rray * when the array itself is non NULL. */ -#define __DO_TRACE(name, args, cond, rcuidle) \ +#define __DO_TRACE(name, args, cond, rcuidle, syscall) \ do { \ int __maybe_unused __idx =3D 0; \ \ @@ -202,8 +204,12 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) "Bad RCU usage for tracepoint")) \ return; \ \ - /* keep srcu and sched-rcu usage consistent */ \ - preempt_disable_notrace(); \ + if (syscall) { \ + rcu_read_lock_trace(); \ + } else { \ + /* keep srcu and sched-rcu usage consistent */ \ + preempt_disable_notrace(); \ + } \ \ /* \ * For rcuidle callers, use srcu since sched-rcu \ @@ -221,7 +227,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(= tracepoint_ptr_t *p) srcu_read_unlock_notrace(&tracepoint_srcu, __idx);\ } \ \ - preempt_enable_notrace(); \ + if (syscall) \ + rcu_read_unlock_trace(); \ + else \ + preempt_enable_notrace(); \ } while (0) =20 #ifndef MODULE @@ -231,7 +240,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) if (static_key_false(&__tracepoint_##name.key)) \ __DO_TRACE(name, \ TP_ARGS(args), \ - TP_CONDITION(cond), 1); \ + TP_CONDITION(cond), 1, 0); \ } #else #define __DECLARE_TRACE_RCU(name, proto, args, cond) @@ -275,7 +284,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) if (static_key_false(&__tracepoint_##name.key)) \ __DO_TRACE(name, \ TP_ARGS(args), \ - TP_CONDITION(cond), 0); \ + TP_CONDITION(cond), 0, 0); \ if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \ WARN_ONCE(!rcu_is_watching(), \ "RCU not watching for tracepoint"); \ @@ -286,7 +295,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) if (static_key_false(&__tracepoint_##name.key)) \ __DO_TRACE(name, \ TP_ARGS(args), \ - TP_CONDITION(cond), 1); \ + TP_CONDITION(cond), 1, 0); \ } \ static inline int \ register_trace_##name(void (*probe)(data_proto), void *data) \ @@ -309,7 +318,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(t= racepoint_ptr_t *p) if (static_key_false(&__tracepoint_##name.key)) \ __DO_TRACE(name, \ TP_ARGS(args), \ - TP_CONDITION(cond), 0); \ + TP_CONDITION(cond), 0, 1); \ if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \ WARN_ONCE(!rcu_is_watching(), \ "RCU not watching for tracepoint"); \ diff --git a/init/Kconfig b/init/Kconfig index 5783a0b87517..72e13ee73c43 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1936,6 +1936,7 @@ config BINDGEN_VERSION_TEXT # config TRACEPOINTS bool + select TASKS_TRACE_RCU =20 source "kernel/Kconfig.kexec" =20 --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACFC919A281; Mon, 30 Sep 2024 19:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; cv=none; b=EiSds36MVR3/yuwBHzKXPqzRxypRjvuKWY7jkalurM0eeSB96+WBW9PqQHQHvSY88vviZCYe79hagJvzwvg1ylRIEO+2QfyUwFZb4LPYc6JI8D4+UbfPYGv6OhbeQWh3ILfPwCbvoS/j5JAfhjiB6jzsmC2Eb4Mn6eiZHhRwIWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; c=relaxed/simple; bh=jzrIYZ+NCfJJx2hpaA2hpfIcWE+lBCRlUE3pqnCzPys=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oLK6nvZfhK1hWMF2Ykh06dxCu9BJaU5UsoPwSkHqWQxPmObJa67iBtb/LTqpMpXMDylnIEOMJ5wXwi5fH2NW+2efAVWV+khXXo8cl3oykFBNILIdVz1Kdk9zIyq1pDBehOVaHvwn8aEn67SPXtQNLtLtCW5TEszqql5SfrmZmJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=LWz5TE/u; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="LWz5TE/u" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724392; bh=jzrIYZ+NCfJJx2hpaA2hpfIcWE+lBCRlUE3pqnCzPys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LWz5TE/uu1joLZFDkBoIS/ae2dUCXUzkKUPIX8yb4SwVsNnHJ2auB+5CLun7Ys3sl XV8MzJhRMar1LDpt8HCrnmZOnxCbzuayb8cE0JStneltc4I+3SQxb25g3dKEvi6nED uELjXD5DjrzLNYBi7BKkgQLa4bjMw/EdmTRW65IVvwHUTTMH2XapDIiUiemP9iVTiC EYPO1+8ERzz3ES1pcUoryYO1h7WlnDOryJM7iOIeJK4O+TSqgMtuxetxlSgZE5m8MZ MbTsPGTHvTs3ERDhC3dYsytqtkE6KQJ8waTQYoA4YnF5WrxleHJIR0wjoNSNTzh5Mb oJiAXgdN+4cIA== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK44Wv4zQgH; Mon, 30 Sep 2024 15:26:32 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 6/8] tracing/ftrace: Add might_fault check to syscall probes Date: Mon, 30 Sep 2024 15:23:55 -0400 Message-Id: <20240930192357.1154417-7-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a might_fault() check to validate that the ftrace sys_enter/sys_exit probe callbacks are indeed called from a context where page faults can be handled. Signed-off-by: Mathieu Desnoyers Acked-by: Masami Hiramatsu (Google) Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/trace_events.h | 1 + kernel/trace/trace_syscalls.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h index 0228d9ed94a3..e0d4850b0d77 100644 --- a/include/trace/trace_events.h +++ b/include/trace/trace_events.h @@ -446,6 +446,7 @@ __DECLARE_EVENT_CLASS(call, PARAMS(proto), PARAMS(args)= , PARAMS(tstruct), \ static notrace void \ trace_event_raw_event_##call(void *__data, proto) \ { \ + might_fault(); \ guard(preempt_notrace)(); \ do_trace_event_raw_event_##call(__data, args); \ } diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index a3d8ac00793e..0430890cbb42 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -303,6 +303,7 @@ static void ftrace_syscall_enter(void *data, struct pt_= regs *regs, long id) * Syscall probe called with preemption enabled, but the ring * buffer and per-cpu data require preemption to be disabled. */ + might_fault(); guard(preempt_notrace)(); =20 syscall_nr =3D trace_get_syscall_nr(current, regs); @@ -348,6 +349,7 @@ static void ftrace_syscall_exit(void *data, struct pt_r= egs *regs, long ret) * Syscall probe called with preemption enabled, but the ring * buffer and per-cpu data require preemption to be disabled. */ + might_fault(); guard(preempt_notrace)(); =20 syscall_nr =3D trace_get_syscall_nr(current, regs); --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16C3619ABBF; Mon, 30 Sep 2024 19:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; cv=none; b=PHCq563g4HfitRoK49q1xrKuMkUWLO6jjh/lhxx6gQmsmEZJvnpTwOW6Fi0QbVNcaP0WVKBIqGcv8wx0ANVbY3RejIx0wA7Ddlejk19aDhzYFU1Dn5SdwtpfJgc8aULsdsMrNrIwSflK6RmVL5Vz3V7JunUdUEYvLqDs4emyN8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; c=relaxed/simple; bh=uJq5iVZHWqF4O/NYGe5n5RCWahHYrd6IuFGzrAbE8HA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sBijP6yIbUesc5uNBwkvbgdMVkRPkibtqQNUfgvgMTswimhSNrdZhGMhzuKH/XzVc1eBKlirk7W8PSGXIrprw9EOO2g+1GD7XL+/19Gckre5ZpdULoyR5as/c7oXKSyWOIOOG2pAZuT9yPXnUBeLv0BdndwAMusYPcvUK/OBuP0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=DzJswE9l; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="DzJswE9l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724393; bh=uJq5iVZHWqF4O/NYGe5n5RCWahHYrd6IuFGzrAbE8HA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DzJswE9lhCMGSOmCKReyUyVVhmOBXeU8K7m5f+lyNu0uePwzjqSoUt4H3LhZn16nR MYQCedfyWFqOsjs63WEcrb4y+sPH4rMAL69I4C6JiguQSrHEBxYP8bTzxzgeHPKzdG +5IX8WKYVa365SqASWSDXDwQjnXyTpAgkw+8WG7C12mnUYQ087ayDTQTgVwqd7eTOA KMoEFQUpJaC2TWMKG4Fu9KPaBJcdPaVdejqFvMTARMp8zqAu8w7qNShZ5s5k7nDl3q puQu1HsYtyRdNYL8xVvYPbrDFwGYIQsv7zIPv7DouQzaVnDlXCg7S32khXhQvWdzc/ glhDjNq1zDNpw== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK509WCzQPm; Mon, 30 Sep 2024 15:26:33 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Michael Jeanson Subject: [PATCH resend 7/8] tracing/perf: Add might_fault check to syscall probes Date: Mon, 30 Sep 2024 15:23:56 -0400 Message-Id: <20240930192357.1154417-8-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Mathieu Desnoyers Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/perf.h | 1 + kernel/trace/trace_syscalls.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/include/trace/perf.h b/include/trace/perf.h index 5650c1bad088..321bfd7919f6 100644 --- a/include/trace/perf.h +++ b/include/trace/perf.h @@ -84,6 +84,7 @@ perf_trace_##call(void *__data, proto) \ u64 __count __attribute__((unused)); \ struct task_struct *__task __attribute__((unused)); \ \ + might_fault(); \ guard(preempt_notrace)(); \ do_perf_trace_##call(__data, args); \ } diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 0430890cbb42..53faa791c735 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -600,6 +600,7 @@ static void perf_syscall_enter(void *ignore, struct pt_= regs *regs, long id) * Syscall probe called with preemption enabled, but the ring * buffer and per-cpu data require preemption to be disabled. */ + might_fault(); guard(preempt_notrace)(); =20 syscall_nr =3D trace_get_syscall_nr(current, regs); @@ -706,6 +707,7 @@ static void perf_syscall_exit(void *ignore, struct pt_r= egs *regs, long ret) * Syscall probe called with preemption enabled, but the ring * buffer and per-cpu data require preemption to be disabled. */ + might_fault(); guard(preempt_notrace)(); =20 syscall_nr =3D trace_get_syscall_nr(current, regs); --=20 2.39.2 From nobody Thu Nov 28 16:41:03 2024 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16CC619ABC3; Mon, 30 Sep 2024 19:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=167.114.26.122 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; cv=none; b=VWhVdT+a1uTDtA//WDmjDXvvkccaKD0lIV4rbCBy8oByAl2I6wbZ79ppOKuPvW7vxmgZ1fd8oczK96tvtrveSpjTEqBGIjA1GnHKyPmATkqBtwIxkbW8T8TuZBKRKCE503NnsXG8k8ozgbigAMAwOaiFbfiq48s8l3t/a/0nmDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727724396; c=relaxed/simple; bh=iV8BNOEUAlVnHaxKIKuldZvcuyZQrIw4r05iL6v8clg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Yco9UsUSmEu5qLJL7cyKjbQOVbId1QWX+exMYEndyghxMUsYtFCBnCEoJxC5vnWem0DhaEn8m0nUSnRhNsjFGt+deDnWZfiRwms19R12X/03E61ph3vZZy/+YPMA4Rv1NG3IHxawbzKOLbczXcAN0fw9vFZ6C3PQf1WcYO8l8Vg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=WVM635kA; arc=none smtp.client-ip=167.114.26.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="WVM635kA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1727724393; bh=iV8BNOEUAlVnHaxKIKuldZvcuyZQrIw4r05iL6v8clg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WVM635kA5GrnUEYPnE4b4+Us/P2YAOSfJs6BF99O+udp2iUMhyhxH8lDaujuFxjwZ MdYoMDnDhSjHKgmMTnFIk54h0LoGPuyfVhBbg3wSWBqc2Pn2hKfHO7QQwGgRvAcai3 vUOe80mFpG4PZLH3pORXkvQ00Gqe5RkuOToRLmgEo/mbY+D2xTklpXOBHym/yvsiaa dCM1WCWQLJSlBj9aLPK6DT1do1+zVI9qJbWfIay5kWNOQKiVpyy9wBebBZJtJ/Pj5D 76OWvxNyynMQfPOGhgL5s+IBL374uTAiSXD5DzibxwlC4xJJLbrG+TOMRvjQWN/fIF Zugd00u+k6NZg== Received: from thinkos.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XHWK52jRwzQgJ; Mon, 30 Sep 2024 15:26:33 -0400 (EDT) From: Mathieu Desnoyers To: Steven Rostedt , Masami Hiramatsu Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Peter Zijlstra , Alexei Starovoitov , Yonghong Song , "Paul E . McKenney" , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Namhyung Kim , Andrii Nakryiko , bpf@vger.kernel.org, Joel Fernandes , linux-trace-kernel@vger.kernel.org, Andrii Nakryiko , Michael Jeanson Subject: [PATCH resend 8/8] tracing/bpf: Add might_fault check to syscall probes Date: Mon, 30 Sep 2024 15:23:57 -0400 Message-Id: <20240930192357.1154417-9-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> References: <20240930192357.1154417-1-mathieu.desnoyers@efficios.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a might_fault() check to validate that the bpf sys_enter/sys_exit probe callbacks are indeed called from a context where page faults can be handled. Signed-off-by: Mathieu Desnoyers Acked-by: Andrii Nakryiko Tested-by: Andrii Nakryiko # BPF parts Cc: Michael Jeanson Cc: Steven Rostedt Cc: Masami Hiramatsu Cc: Peter Zijlstra Cc: Alexei Starovoitov Cc: Yonghong Song Cc: Paul E. McKenney Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Namhyung Kim Cc: Andrii Nakryiko Cc: bpf@vger.kernel.org Cc: Joel Fernandes Acked-by and Tested-by tags to relevant commits. --- include/trace/bpf_probe.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/trace/bpf_probe.h b/include/trace/bpf_probe.h index 211b98d45fc6..099df5c3e38a 100644 --- a/include/trace/bpf_probe.h +++ b/include/trace/bpf_probe.h @@ -57,6 +57,7 @@ __bpf_trace_##call(void *__data, proto) \ static notrace void \ __bpf_trace_##call(void *__data, proto) \ { \ + might_fault(); \ guard(preempt_notrace)(); \ CONCATENATE(bpf_trace_run, COUNT_ARGS(args))(__data, CAST_TO_U64(args)); \ } --=20 2.39.2