mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [for-linus][PATCH 0/5] tracing: Fixes for v7.4
@ 2026-11-27 18:42 Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails Steven Rostedt
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Andrea Parri, Jeff Barnes, Vincent Donnefort, Yifan Feng


tracing fixes for v7.4:

- Fix user events on fork allocation failure

  User events are created by user tasks to be able to be traced within
  the kernel tracing facility. On fork, the duplication of user events
  can fail. If this happens the state of the event becomes stale,
  miss updates and produce undefined results.

  As user events are part of the set up of the program that uses them,
  fail a fork if the user event allocation fails for the new child.
  This only affects programs that set up user events for themselves.

- Fix a remote event alignemnt offset output

  The trace events for remote buffers does not take into account alignment
  constraints, and produces incorrect field offsets that cause failure in
  parsing the events from user space.

- Fix lost recursion records in recording ftrace functions that recurse

  There's a race in the logic that records ftrace functions that recurse
  where it checks if the last function that recursed is the same as the new
  one and if it is, it ignores the recursion. But the recording of that last
  function is done before the function is saved. If the saving fails due to
  a race, then if the same function is recursed again, it will be ignored as
  the code thinks it was recorded last time (but it wasn't).

- Reject '!!' at the beginning of input to set_ftrace_filter

  To remove a single function from the set_ftrace_filter file, the user
  echos "!func_name" into set_ftrace_filter and that function is removed
  from the list. The issue is that the parsing logic sees the '!', records
  it, removes it from the string and then continues the parsing with a "not"
  variable set. The later logic of the "not" code checks if the first
  character is a '!', and if it is, it triggers a WARN_ON() as it thinks the
  logic was broken.

  If the user echos in "!!func_name", the first '!' is removed and the not
  variable set, and the second '!' is processed making the code think there
  was a bug in the logic and triggers a WARN_ON().

  Simply have the code first check for "!!" at the start and return -EINVAL
  if that is found.

- Use atomic bitops and READ_ONCE() when processing flags variable

  KSCAN reported a data race on the trace_event flags variable.
  It is accessed in lockless mode during tracing and currently updated with
  simple "|" or "&" logic. This causes a read-modify-write race.
  Update the accesses to use bitops and READ_ONCE() to remove this race
  condition.


  git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes

Head SHA1: 86020484c0cf36a72ab998274d051f9a14ff4f40


Andrea Parri (1):
      ftrace: Fix lost recursion records in ftrace_record_recursion()

Jeff Barnes (1):
      tracing/user_events: Fail fork when event state duplication fails

Masami Hiramatsu (Google) (1):
      tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags

Vincent Donnefort (1):
      tracing/remotes: Align field offset in remote_event_format_show()

Yifan Feng (1):
      ftrace: Reject "!!" in front of a set_ftrace_filter command

----
 include/linux/trace_events.h          |  2 +-
 include/linux/user_events.h           | 16 +++++++---------
 kernel/fork.c                         |  8 ++++++--
 kernel/trace/ftrace.c                 |  7 +++++++
 kernel/trace/trace.c                  |  7 ++++---
 kernel/trace/trace.h                  | 18 ++++++++++--------
 kernel/trace/trace_events.c           |  2 +-
 kernel/trace/trace_events_filter.c    | 12 ++----------
 kernel/trace/trace_events_trigger.c   |  5 +++--
 kernel/trace/trace_events_user.c      |  8 +++++---
 kernel/trace/trace_recursion_record.c | 17 +++++++++--------
 kernel/trace/trace_remote.c           |  1 +
 12 files changed, 56 insertions(+), 47 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails
  2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
@ 2026-11-27 18:42 ` Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 2/5] tracing/remotes: Align field offset in remote_event_format_show() Steven Rostedt
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	stable, Jeff Barnes, Beau Belgrave

From: Jeff Barnes <jeffbarnes@linux.microsoft.com>

Registered user events are retained across fork, but duplicating their
state for a child with a separate mm can fail. Both user_event_mm_dup() and
user_events_fork() currently return void, so allocation failure silently
creates a child without the inherited registration state.

The child can consequently retain a stale copy-on-write enable word and
miss later event enable and disable updates.

Return an error from user_event_mm_dup() and user_events_fork(), and
perform the duplication in copy_process() while failure can still be
unwound. Return -ENOMEM when the child user_event_mm or any of its enablers
cannot be duplicated.

Add a cleanup path so successfully acquired user-events state is removed if
a later fork operation fails. Preserve the existing CLONE_VM behavior and
its task reference accounting.

A deterministic allocation-failure test on upstream master previously
allowed fork() to succeed while the child missed an enablement update. With
this change, the same fork fails with ENOMEM. The complete user_events ABI
suite passes.

Cc: stable@vger.kernel.org
Fixes: 7235759084a4 ("tracing/user_events: Use remote writes for event enablement")
Link: https://patch.msgid.link/20261002222639.1964370-1-jeffbarnes@linux.microsoft.com
Signed-off-by: Jeff Barnes <jeffbarnes@linux.microsoft.com>
Reviewed-by: Beau Belgrave <beaub@linux.microsoft.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/linux/user_events.h      | 16 +++++++---------
 kernel/fork.c                    |  8 ++++++--
 kernel/trace/trace_events_user.c |  8 +++++---
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/include/linux/user_events.h b/include/linux/user_events.h
index 57d1ff006090..75f184126727 100644
--- a/include/linux/user_events.h
+++ b/include/linux/user_events.h
@@ -27,28 +27,26 @@ struct user_event_mm {
 	struct rcu_work		put_rwork;
 };
 
-extern void user_event_mm_dup(struct task_struct *t,
-			      struct user_event_mm *old_mm);
+int user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm);
 
 extern void user_event_mm_remove(struct task_struct *t);
 
-static inline void user_events_fork(struct task_struct *t,
-				    u64 clone_flags)
+static inline int user_events_fork(struct task_struct *t, u64 clone_flags)
 {
 	struct user_event_mm *old_mm;
 
 	if (!t || !current->user_event_mm)
-		return;
+		return 0;
 
 	old_mm = current->user_event_mm;
 
 	if (clone_flags & CLONE_VM) {
 		t->user_event_mm = old_mm;
 		refcount_inc(&old_mm->tasks);
-		return;
+		return 0;
 	}
 
-	user_event_mm_dup(t, old_mm);
+	return user_event_mm_dup(t, old_mm);
 }
 
 static inline void user_events_execve(struct task_struct *t)
@@ -67,9 +65,9 @@ static inline void user_events_exit(struct task_struct *t)
 	user_event_mm_remove(t);
 }
 #else
-static inline void user_events_fork(struct task_struct *t,
-				    u64 clone_flags)
+static inline int user_events_fork(struct task_struct *t, u64 clone_flags)
 {
+	return 0;
 }
 
 static inline void user_events_execve(struct task_struct *t)
diff --git a/kernel/fork.c b/kernel/fork.c
index 5efceb8d58a7..cdba6ba6335d 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -2328,9 +2328,12 @@ __latent_entropy struct task_struct *copy_process(
 	retval = copy_mm(clone_flags, p);
 	if (retval)
 		goto bad_fork_cleanup_signal;
-	retval = copy_namespaces(clone_flags, p);
+	retval = user_events_fork(p, clone_flags);
 	if (retval)
 		goto bad_fork_cleanup_mm;
+	retval = copy_namespaces(clone_flags, p);
+	if (retval)
+		goto bad_fork_cleanup_user_events;
 	retval = copy_io(clone_flags, p);
 	if (retval)
 		goto bad_fork_cleanup_namespaces;
@@ -2598,7 +2601,6 @@ __latent_entropy struct task_struct *copy_process(
 
 	trace_task_newtask(p, clone_flags);
 	uprobe_copy_process(p, clone_flags);
-	user_events_fork(p, clone_flags);
 
 	copy_oom_score_adj(clone_flags, p);
 
@@ -2625,6 +2627,8 @@ __latent_entropy struct task_struct *copy_process(
 		exit_io_context(p);
 bad_fork_cleanup_namespaces:
 	exit_nsproxy_namespaces(p);
+bad_fork_cleanup_user_events:
+	user_events_exit(p);
 bad_fork_cleanup_mm:
 	sched_cache_fork_cleanup(p);
 	if (p->mm) {
diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index e29e1c772aa7..c561443f7947 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -868,7 +868,7 @@ void user_event_mm_remove(struct task_struct *t)
 	queue_rcu_work(system_percpu_wq, &mm->put_rwork);
 }
 
-void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
+int user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
 {
 	struct user_event_mm *mm = user_event_mm_alloc(t);
 	struct user_event_enabler *enabler;
@@ -877,7 +877,7 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
 	t->user_event_mm = NULL;
 
 	if (!mm)
-		return;
+		return -ENOMEM;
 
 	rcu_read_lock();
 
@@ -889,10 +889,12 @@ void user_event_mm_dup(struct task_struct *t, struct user_event_mm *old_mm)
 	rcu_read_unlock();
 
 	user_event_mm_attach(mm, t);
-	return;
+	return 0;
 error:
 	rcu_read_unlock();
 	user_event_mm_destroy(mm);
+
+	return -ENOMEM;
 }
 
 static bool current_user_event_enabler_exists(unsigned long uaddr,
-- 
2.53.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [for-linus][PATCH 2/5] tracing/remotes: Align field offset in remote_event_format_show()
  2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails Steven Rostedt
@ 2026-11-27 18:42 ` Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 3/5] ftrace: Fix lost recursion records in ftrace_record_recursion() Steven Rostedt
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	stable, Fuad Tabba, Vincent Donnefort

From: Vincent Donnefort <vdonnefort@google.com>

remote_event_format_show() doesn't take into account each field's
alignment leading to an incorrect reporting of the actual field offset.
Use the existing field->align.

Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261009132848.709379-1-vdonnefort@google.com
Fixes: 072529158e60 ("tracing: Add events to trace remotes")
Reported-by: Fuad Tabba <fuad.tabba@linux.dev>
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev>
Tested-by: Fuad Tabba <fuad.tabba@linux.dev>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_remote.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/trace/trace_remote.c b/kernel/trace/trace_remote.c
index 2d5bc423efca..7e35f48ae467 100644
--- a/kernel/trace/trace_remote.c
+++ b/kernel/trace/trace_remote.c
@@ -1098,6 +1098,7 @@ static int remote_event_format_show(struct seq_file *s, void *unused)
 
 	field = &evt->fields[0];
 	while (field->name) {
+		offset = ALIGN(offset, field->align);
 		seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%u;\tsigned:%d;\n",
 			   field->type, field->name, offset, field->size,
 			   field->is_signed);
-- 
2.53.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [for-linus][PATCH 3/5] ftrace: Fix lost recursion records in ftrace_record_recursion()
  2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 2/5] tracing/remotes: Align field offset in remote_event_format_show() Steven Rostedt
@ 2026-11-27 18:42 ` Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 4/5] ftrace: Reject "!!" in front of a set_ftrace_filter command Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 5/5] tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags Steven Rostedt
  4 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	Andrea Parri

From: Andrea Parri <parri.andrea@gmail.com>

cached_function is set to the current ip before the cmpxchg() that
claims a slot in recursed_functions[]. When that cmpxchg() loses a
race for the same slot, the code bumps index and retries via "goto
again", but the retry immediately matches its own cached_function
write and returns without ever reaching the bumped-index cmpxchg().

Concretely, for two writers racing on the same index:

  CPU 0 (ip = A)                    CPU 1 (ip = B)
  --------------                    --------------
                                     cmpxchg(&recursed_functions[index].ip,
                                             0, B);      // succeeds
  cached_function = A;
  cmpxchg(&recursed_functions[index].ip,
          0, A);
    // fails, old == B
  index++;
  goto again;
  if (A == cached_function)         // true: matches A's own store
          return;                   // A is dropped, not retried

Once dropped this way, cached_function stays set to A, so every later
recursion of A also hits the fast path and returns before reaching the
retry, until some unrelated ip overwrites the cache.

Set cached_function only after the cmpxchg() has claimed the slot. The
retry path then leaves the cache untouched and no longer matches its
own store. When the cmpxchg() finds ip already present, the writer
that installed it sets the cache.

The bug was found with the help of an LLM.

Link: https://patch.msgid.link/20261026182553.221141-1-parri.andrea@gmail.com
Fixes: 773c16705058e ("ftrace: Add recording of functions that caused recursion")
Signed-off-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_recursion_record.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/kernel/trace/trace_recursion_record.c b/kernel/trace/trace_recursion_record.c
index bac4bc844ccd..4f63bec052fc 100644
--- a/kernel/trace/trace_recursion_record.c
+++ b/kernel/trace/trace_recursion_record.c
@@ -17,8 +17,8 @@ static struct recursed_functions recursed_functions[CONFIG_FTRACE_RECORD_RECURSI
 static atomic_t nr_records;
 
 /*
- * Cache the last found function. Yes, updates to this is racey, but
- * so is memory cache ;-)
+ * Cache the last function found in or added to recursed_functions[].
+ * Updates to this are racy, but this is only a best-effort cache.
  */
 static unsigned long cached_function;
 
@@ -67,24 +67,25 @@ void ftrace_record_recursion(unsigned long ip, unsigned long parent_ip)
 		}
 	}
 
-	cached_function = ip;
-
 	/*
 	 * We only want to add a function if it hasn't been added before.
-	 * Add to the current location before incrementing the count.
-	 * If it fails to add, then increment the index (save in i)
-	 * and try again.
+	 * Claim the current slot before incrementing the count. If the slot
+	 * is occupied by another function, advance to the next slot and retry.
+	 *
+	 * Do not update cached_function until ip is known to be present;
+	 * otherwise the retry would match its own cache update.
 	 */
 	old = cmpxchg(&recursed_functions[index].ip, 0, ip);
 	if (old != 0) {
 		/* Did something else already added this for us? */
 		if (old == ip)
 			return;
-		/* Try the next location (use i for the next index) */
+		/* Try the next location */
 		index++;
 		goto again;
 	}
 
+	cached_function = ip;
 	recursed_functions[index].parent_ip = parent_ip;
 
 	/*
-- 
2.53.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [for-linus][PATCH 4/5] ftrace: Reject "!!" in front of a set_ftrace_filter command
  2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
                   ` (2 preceding siblings ...)
  2026-11-27 18:42 ` [for-linus][PATCH 3/5] ftrace: Fix lost recursion records in ftrace_record_recursion() Steven Rostedt
@ 2026-11-27 18:42 ` Steven Rostedt
  2026-11-27 18:42 ` [for-linus][PATCH 5/5] tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags Steven Rostedt
  4 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	stable, Yifan Feng

From: Yifan Feng <evanfengff@gmail.com>

A command written to set_ftrace_filter with two '!' in front of the
function glob triggers the WARN_ON() in
unregister_ftrace_function_probe_func():

  # echo '!!vfs_read:traceoff' >> set_ftrace_filter
  WARNING: kernel/trace/ftrace.c:5675 at unregister_ftrace_function_probe_func+0x662/0x870

The command callbacks strip the first '!' and pass the rest as the glob
of the probe to remove. filter_parse_regex() then reports the second
'!' as a negated glob, which function probes do not support.

Return -EINVAL for such input in ftrace_process_regex(), before a
command callback is called.

Cc: stable@vger.kernel.org
Link: https://patch.msgid.link/20261119191205.32892-1-evanfengff@gmail.com
Fixes: 23b4ff3aa479 ("ftrace: add traceon traceoff commands to enable/disable the buffers")
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Yifan Feng <evanfengff@gmail.com>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 6654da9d1bbf..5b161959e701 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5847,6 +5847,13 @@ static int ftrace_process_regex(struct ftrace_iterator *iter,
 
 	/* command found */
 
+	/*
+	 * A double "!!" confuses the parser. This isn't a boolean operation,
+	 * simply reject it.
+	 */
+	if (func[0] == '!' && func[1] == '!')
+		return -EINVAL;
+
 	command = strsep(&next, ":");
 
 	guard(mutex)(&ftrace_cmd_mutex);
-- 
2.53.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [for-linus][PATCH 5/5] tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags
  2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
                   ` (3 preceding siblings ...)
  2026-11-27 18:42 ` [for-linus][PATCH 4/5] ftrace: Reject "!!" in front of a set_ftrace_filter command Steven Rostedt
@ 2026-11-27 18:42 ` Steven Rostedt
  4 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2026-11-27 18:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Masami Hiramatsu, Mark Rutland, Mathieu Desnoyers, Andrew Morton,
	stable, syzbot+1faa12be48036b80e416

From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>

syzbot reported a KCSAN data race on struct trace_event_file::flags
between filter_disable() and __trace_trigger_soft_disabled():

  BUG: KCSAN: data-race in __trace_trigger_soft_disabled /
  apply_subsystem_event_filter

  write to 0xffff888100172888 of 8 bytes by task 5433 on cpu 0:
   filter_disable [inline]
   process_system_preds [inline]
   create_system_filter [inline]
   apply_subsystem_event_filter+0x28f/0xcd0
   subsystem_filter_write+0x79/0xd0

  read to 0xffff888100172888 of 8 bytes by task 5440 on cpu 1:
   __trace_trigger_soft_disabled+0x20/0x1a0
   trace_trigger_soft_disabled [inline]

filter_disable() and event_set_filtered_flag() update
EVENT_FILE_FL_FILTERED using non-atomic read-modify-write operations on
file->flags and compare old_flags != file->flags to decide whether to
call trace_buffered_event_disable() / trace_buffered_event_enable().

Because other bits in file->flags (such as
EVENT_FILE_FL_SOFT_DISABLED_BIT from event enable/disable triggers) can
be modified concurrently without event_mutex using atomic bitops, the
non-atomic RMW can lose concurrent bit updates or misdetect a flag
transition and unbalance the buffered event refcount.

Use test_and_clear_bit() / test_and_set_bit() on
EVENT_FILE_FL_FILTERED_BIT in filter_disable() and
event_set_filtered_flag(), and use READ_ONCE() / test_bit() for lockless
readers of file->flags in the trace event fast paths.

CC: stable@vger.kernel.org
Link: https://patch.msgid.link/179533184612.139632.4029978219979965754.stgit@devnote2
Reported-by: syzbot+1faa12be48036b80e416@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/6b0234dc.44b41460.34b83f.0019.GAE@google.com
Fixes: 0fc1b09ff1ff ("tracing: Use temp buffer when filtering events")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/linux/trace_events.h        |  2 +-
 kernel/trace/trace.c                |  7 ++++---
 kernel/trace/trace.h                | 18 ++++++++++--------
 kernel/trace/trace_events.c         |  2 +-
 kernel/trace/trace_events_filter.c  | 12 ++----------
 kernel/trace/trace_events_trigger.c |  5 +++--
 6 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 321f2f3a6c8e..7a0aa23825de 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -764,7 +764,7 @@ bool __trace_trigger_soft_disabled(struct trace_event_file *file);
 static __always_inline bool
 trace_trigger_soft_disabled(struct trace_event_file *file)
 {
-	unsigned long eflags = file->flags;
+	unsigned long eflags = READ_ONCE(file->flags);
 
 	if (likely(!(eflags & (EVENT_FILE_FL_TRIGGER_MODE |
 			       EVENT_FILE_FL_SOFT_DISABLED |
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 65b9d67647e5..fa65ef8d7fbe 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1886,7 +1886,8 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
 	*current_rb = tr->array_buffer.buffer;
 
 	if (!tr->no_filter_buffering_ref &&
-	    (trace_file->flags & (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED))) {
+	    (READ_ONCE(trace_file->flags) &
+	     (EVENT_FILE_FL_SOFT_DISABLED | EVENT_FILE_FL_FILTERED))) {
 		preempt_disable_notrace();
 		/*
 		 * Filtering is on, so try to use the per cpu buffer first.
@@ -1947,7 +1948,7 @@ trace_event_buffer_lock_reserve(struct trace_buffer **current_rb,
 	 * to store the trace event for the trigger to use. It's recursive
 	 * safe and will not be recorded anywhere.
 	 */
-	if (!entry && trace_file->flags & EVENT_FILE_FL_TRIGGER_COND) {
+	if (!entry && (READ_ONCE(trace_file->flags) & EVENT_FILE_FL_TRIGGER_COND)) {
 		*current_rb = temp_buffer;
 		entry = __trace_buffer_lock_reserve(*current_rb, type, len,
 						    trace_ctx);
@@ -1978,7 +1979,7 @@ static void output_printk(struct trace_event_buffer *fbuffer)
 
 	file = fbuffer->trace_file;
 	if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &file->flags) ||
-	    (unlikely(file->flags & EVENT_FILE_FL_FILTERED) &&
+	    (unlikely(test_bit(EVENT_FILE_FL_FILTERED_BIT, &file->flags)) &&
 	     !filter_match_preds(file->filter, fbuffer->entry)))
 		return;
 
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 1fec567e789e..32997b58a8a0 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -1729,24 +1729,26 @@ __event_trigger_test_discard(struct trace_event_file *file,
 			     void *entry,
 			     enum event_trigger_type *tt)
 {
-	unsigned long eflags = file->flags;
+	unsigned long eflags = READ_ONCE(file->flags);
 
-	if (eflags & EVENT_FILE_FL_TRIGGER_COND)
+	if (eflags & EVENT_FILE_FL_TRIGGER_COND) {
 		*tt = event_triggers_call(file, buffer, entry, event);
+		eflags = READ_ONCE(file->flags);
+	}
 
-	if (likely(!(file->flags & (EVENT_FILE_FL_SOFT_DISABLED |
-				    EVENT_FILE_FL_FILTERED |
-				    EVENT_FILE_FL_PID_FILTER))))
+	if (likely(!(eflags & (EVENT_FILE_FL_SOFT_DISABLED |
+			       EVENT_FILE_FL_FILTERED |
+			       EVENT_FILE_FL_PID_FILTER))))
 		return false;
 
-	if (file->flags & EVENT_FILE_FL_SOFT_DISABLED)
+	if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
 		goto discard;
 
-	if (file->flags & EVENT_FILE_FL_FILTERED &&
+	if (eflags & EVENT_FILE_FL_FILTERED &&
 	    !filter_match_preds(file->filter, entry))
 		goto discard;
 
-	if ((file->flags & EVENT_FILE_FL_PID_FILTER) &&
+	if ((eflags & EVENT_FILE_FL_PID_FILTER) &&
 	    trace_event_ignore_this_pid(file))
 		goto discard;
 
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 7f89160aeff3..394d7cde1a70 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -707,7 +707,7 @@ void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
 {
 	struct trace_event_call *event_call = trace_file->event_call;
 
-	if ((trace_file->flags & EVENT_FILE_FL_PID_FILTER) &&
+	if (test_bit(EVENT_FILE_FL_PID_FILTER_BIT, &trace_file->flags) &&
 	    trace_event_ignore_this_pid(trace_file))
 		return NULL;
 
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index a9d77df3e19a..b3ac2519a62d 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -1349,11 +1349,7 @@ static void free_prog(struct event_filter *filter)
 
 static void filter_disable(struct trace_event_file *file)
 {
-	unsigned long old_flags = file->flags;
-
-	file->flags &= ~EVENT_FILE_FL_FILTERED;
-
-	if (old_flags != file->flags)
+	if (test_and_clear_bit(EVENT_FILE_FL_FILTERED_BIT, &file->flags))
 		trace_buffered_event_disable();
 }
 
@@ -2331,11 +2327,7 @@ static int process_preds(struct trace_event_call *call,
 
 static inline void event_set_filtered_flag(struct trace_event_file *file)
 {
-	unsigned long old_flags = file->flags;
-
-	file->flags |= EVENT_FILE_FL_FILTERED;
-
-	if (old_flags != file->flags)
+	if (!test_and_set_bit(EVENT_FILE_FL_FILTERED_BIT, &file->flags))
 		trace_buffered_event_enable();
 }
 
diff --git a/kernel/trace/trace_events_trigger.c b/kernel/trace/trace_events_trigger.c
index a2487ad7fef8..96203ba72ab9 100644
--- a/kernel/trace/trace_events_trigger.c
+++ b/kernel/trace/trace_events_trigger.c
@@ -214,7 +214,7 @@ EXPORT_SYMBOL_GPL(event_triggers_call);
 
 bool __trace_trigger_soft_disabled(struct trace_event_file *file)
 {
-	unsigned long eflags = file->flags;
+	unsigned long eflags = READ_ONCE(file->flags);
 
 	if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
 		event_triggers_call(file, NULL, NULL, NULL);
@@ -1692,7 +1692,8 @@ event_enable_count_func(struct event_trigger_data *data,
 		return false;
 
 	/* Skip if the event is in a state we want to switch to */
-	if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
+	if (enable_data->enable == !test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
+					     &enable_data->file->flags))
 		return false;
 
 	if (data->count != -1)
-- 
2.53.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-27 18:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-27 18:42 [for-linus][PATCH 0/5] tracing: Fixes for v7.4 Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 1/5] tracing/user_events: Fail fork when event state duplication fails Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 2/5] tracing/remotes: Align field offset in remote_event_format_show() Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 3/5] ftrace: Fix lost recursion records in ftrace_record_recursion() Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 4/5] ftrace: Reject "!!" in front of a set_ftrace_filter command Steven Rostedt
2026-11-27 18:42 ` [for-linus][PATCH 5/5] tracing/filters: Use atomic bitops and READ_ONCE() for trace_event_file::flags Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®