public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ludwig Rydberg <ludwig.rydberg@gaisler.com>,
	Andreas Larsson <andreas@gaisler.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH 1/2] ring-buffer: Do not allow events in NMI with generic atomic64 cmpxchg()
Date: Tue, 21 Jan 2025 16:59:02 +0900	[thread overview]
Message-ID: <20250121165902.c671d578a19c0980c826eabb@kernel.org> (raw)
In-Reply-To: <20250120235721.407068250@goodmis.org>

On Mon, 20 Jan 2025 18:56:56 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: Steven Rostedt <rostedt@goodmis.org>
> 
> Some architectures can not safely do atomic64 operations in NMI context.
> Since the ring buffer relies on atomic64 operations to do its time
> keeping, if an event is requested in NMI context, reject it for these
> architectures.
> 

Looks good to me.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

> Cc: stable@vger.kernel.org
> Fixes: c84897c0ff592 ("ring-buffer: Remove 32bit timestamp logic")
> Closes: https://lore.kernel.org/all/86fb4f86-a0e4-45a2-a2df-3154acc4f086@gaisler.com/
> Reported-by: Ludwig Rydberg <ludwig.rydberg@gaisler.com>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ring_buffer.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
> index 6d61ff78926b..b8e0ae15ca5b 100644
> --- a/kernel/trace/ring_buffer.c
> +++ b/kernel/trace/ring_buffer.c
> @@ -4398,8 +4398,13 @@ rb_reserve_next_event(struct trace_buffer *buffer,
>  	int nr_loops = 0;
>  	int add_ts_default;
>  
> -	/* ring buffer does cmpxchg, make sure it is safe in NMI context */
> -	if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) &&
> +	/*
> +	 * ring buffer does cmpxchg as well as atomic64 operations
> +	 * (which some archs use locking for atomic64), make sure this
> +	 * is safe in NMI context
> +	 */
> +	if ((!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) ||
> +	     IS_ENABLED(CONFIG_GENERIC_ATOMIC64)) &&
>  	    (unlikely(in_nmi()))) {
>  		return NULL;
>  	}
> -- 
> 2.45.2
> 
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2025-01-21  7:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20 23:56 [PATCH 0/2] lib/atomic64: ring-buffer: Fix infinite recursion on some 32bit archs Steven Rostedt
2025-01-20 23:56 ` [PATCH 1/2] ring-buffer: Do not allow events in NMI with generic atomic64 cmpxchg() Steven Rostedt
2025-01-21  7:59   ` Masami Hiramatsu [this message]
2025-01-20 23:56 ` [PATCH 2/2] atomic64: Use arch_spin_locks instead of raw_spin_locks Steven Rostedt
2025-01-21  8:04   ` Masami Hiramatsu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250121165902.c671d578a19c0980c826eabb@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=andreas@gaisler.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=ludwig.rydberg@gaisler.com \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox