From nobody Wed Oct 1 22:30:48 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 DD5AF1E5B63 for ; Tue, 30 Sep 2025 17:01:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759251685; cv=none; b=AC3QMvkADPI5Q9JjQmFFtwydV3y37wG0B+nTrQMcGjtauzk6RXGbeAp1UTnea4lQv1axjtl6kTz16NX0xTNfBVgNSlJmjQOHLGwn01WFOmyCt9hQvb9QR6KW1h1UJAepCJJXoLFnQQl1B963nr0zqEMjUvtUHUEswKCA1GH3eNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759251685; c=relaxed/simple; bh=vY2v5I9kO5ehK/jc4YTT7DsX1ZGch709+915nX0G2s4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=SAQKenP0DZyVxjDoreeP++jgcN3gh16zWqSy7qwytul8GamDLgVJa8QoFzuhDgiicco5qded/9wVwnPP7Rpx68H8+zsOXiw87RXLqarv3Fa758xgOdfGMg2y7IzHYzOXlD9XRmClO44DavbxB9v5mRJut+WHf8IwxSoeUnHKRFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ey3RfBoM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Ey3RfBoM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74600C4CEF0; Tue, 30 Sep 2025 17:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759251685; bh=vY2v5I9kO5ehK/jc4YTT7DsX1ZGch709+915nX0G2s4=; h=Date:From:To:Cc:Subject:References:From; b=Ey3RfBoM06rSS+/fFro6uDf+g5ZTLhzEwsGWC8FvEY1SIJ40ut5GNMBddS0Gow8ru oA/iFbX3oQT0f99A/75Kb9cKF2lEjljAF96vQPyj4GHS65JhecHP+pNTyF5I2ygNSX E4vgvK+0XRTZXbzGouANvxVAfVPrBc3TwxaDJzQ4I+VleFFm9LJVjLOz0KMK2yhuAr JdCO+eM5tv64/ITOBQZBP9iY1f6v6vaqbPn9IHVt4LkrMwV6OQDXCVoZH87EJLQi1M c95M52ozc/kjkodpIw60itvppls6J8H1qX2tW/BQGhSGK54CaGrN+nymR5Ed8IpypP 6X0aV0iveVHZw== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1v3dkj-0000000DIFq-28hw; Tue, 30 Sep 2025 13:03:01 -0400 Message-ID: <20250930170301.362050230@kernel.org> User-Agent: quilt/0.68 Date: Tue, 30 Sep 2025 13:01:36 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Peter Zijlstra , Namhyung Kim , Takaya Saeki , Tom Zanussi , Thomas Gleixner , Ian Rogers , Douglas Raillard , "Paul E. McKenney" Subject: [for-next][PATCH 01/11] tracing: Replace syscall RCU pointer assignment with READ/WRITE_ONCE() References: <20250930170135.285740909@kernel.org> 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" From: Steven Rostedt The syscall events are pseudo events that hook to the raw syscalls. The ftrace_syscall_enter/exit() callback is called by the raw_syscall enter/exit tracepoints respectively whenever any of the syscall events are enabled. The trace_array has an array of syscall "files" that correspond to the system calls based on their __NR_SYSCALL number. The array is read and if there's a pointer to a trace_event_file then it is considered enabled and if it is NULL that syscall event is considered disabled. Currently it uses an rcu_dereference_sched() to get this pointer and a rcu_assign_ptr() or RCU_INIT_POINTER() to write to it. This is unnecessary as the file pointer will not go away outside the synchronization of the tracepoint logic itself. And this code adds no extra RCU synchronization that uses this. Replace these functions with a simple READ_ONCE() and WRITE_ONCE() which is all they need. This will also allow this code to not depend on preemption being disabled as system call tracepoints are now allowed to fault. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Peter Zijlstra Cc: Namhyung Kim Cc: Takaya Saeki Cc: Tom Zanussi Cc: Thomas Gleixner Cc: Ian Rogers Cc: Douglas Raillard Link: https://lore.kernel.org/20250923130713.594320290@kernel.org Reviewed-by: Paul E. McKenney Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 4 ++-- kernel/trace/trace_syscalls.c | 14 ++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 5f4bed5842f9..85eabb454bee 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -380,8 +380,8 @@ struct trace_array { #ifdef CONFIG_FTRACE_SYSCALLS int sys_refcount_enter; int sys_refcount_exit; - struct trace_event_file __rcu *enter_syscall_files[NR_syscalls]; - struct trace_event_file __rcu *exit_syscall_files[NR_syscalls]; + struct trace_event_file *enter_syscall_files[NR_syscalls]; + struct trace_event_file *exit_syscall_files[NR_syscalls]; #endif int stop_count; int clock_id; diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index 46aab0ab9350..3a0b65f89130 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c @@ -310,8 +310,7 @@ static void ftrace_syscall_enter(void *data, struct pt_= regs *regs, long id) if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; =20 - /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */ - trace_file =3D rcu_dereference_sched(tr->enter_syscall_files[syscall_nr]); + trace_file =3D READ_ONCE(tr->enter_syscall_files[syscall_nr]); if (!trace_file) return; =20 @@ -356,8 +355,7 @@ static void ftrace_syscall_exit(void *data, struct pt_r= egs *regs, long ret) if (syscall_nr < 0 || syscall_nr >=3D NR_syscalls) return; =20 - /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */ - trace_file =3D rcu_dereference_sched(tr->exit_syscall_files[syscall_nr]); + trace_file =3D READ_ONCE(tr->exit_syscall_files[syscall_nr]); if (!trace_file) return; =20 @@ -393,7 +391,7 @@ static int reg_event_syscall_enter(struct trace_event_f= ile *file, if (!tr->sys_refcount_enter) ret =3D register_trace_sys_enter(ftrace_syscall_enter, tr); if (!ret) { - rcu_assign_pointer(tr->enter_syscall_files[num], file); + WRITE_ONCE(tr->enter_syscall_files[num], file); tr->sys_refcount_enter++; } mutex_unlock(&syscall_trace_lock); @@ -411,7 +409,7 @@ static void unreg_event_syscall_enter(struct trace_even= t_file *file, return; mutex_lock(&syscall_trace_lock); tr->sys_refcount_enter--; - RCU_INIT_POINTER(tr->enter_syscall_files[num], NULL); + WRITE_ONCE(tr->enter_syscall_files[num], NULL); if (!tr->sys_refcount_enter) unregister_trace_sys_enter(ftrace_syscall_enter, tr); mutex_unlock(&syscall_trace_lock); @@ -431,7 +429,7 @@ static int reg_event_syscall_exit(struct trace_event_fi= le *file, if (!tr->sys_refcount_exit) ret =3D register_trace_sys_exit(ftrace_syscall_exit, tr); if (!ret) { - rcu_assign_pointer(tr->exit_syscall_files[num], file); + WRITE_ONCE(tr->exit_syscall_files[num], file); tr->sys_refcount_exit++; } mutex_unlock(&syscall_trace_lock); @@ -449,7 +447,7 @@ static void unreg_event_syscall_exit(struct trace_event= _file *file, return; mutex_lock(&syscall_trace_lock); tr->sys_refcount_exit--; - RCU_INIT_POINTER(tr->exit_syscall_files[num], NULL); + WRITE_ONCE(tr->exit_syscall_files[num], NULL); if (!tr->sys_refcount_exit) unregister_trace_sys_exit(ftrace_syscall_exit, tr); mutex_unlock(&syscall_trace_lock); --=20 2.50.1