lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250626160459.soHxOROG@linutronix.de>
Date: Thu, 26 Jun 2025 18:04:59 +0200
From: Nam Cao <namcao@...utronix.de>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Masami Hiramatsu <mhiramat@...nel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
	linux-trace-kernel@...r.kernel.org, linux-kernel@...r.kernel.org,
	Gabriele Monaco <gmonaco@...hat.com>, john.ogness@...utronix.de
Subject: Re: [PATCH] tracing: Remove pointless memory barriers

On Thu, Jun 26, 2025 at 11:35:20AM -0400, Steven Rostedt wrote:
> On Thu, 26 Jun 2025 17:19:40 +0200
> Nam Cao <namcao@...utronix.de> wrote:
> >  static void turn_monitoring_on_with_reset(void)
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index 95ae7c4e58357..0dff4298fc0e5 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> > @@ -936,7 +936,6 @@ int tracing_is_enabled(void)
> >  	 * return the mirror variable of the state of the ring buffer.
> >  	 * It's a little racy, but we don't really care.
> >  	 */
> > -	smp_rmb();
> >  	return !global_trace.buffer_disabled;
> >  }
> >  
> > @@ -1107,8 +1106,6 @@ void tracer_tracing_on(struct trace_array *tr)
> >  	 * important to be fast than accurate.
> >  	 */
> >  	tr->buffer_disabled = 0;
> > -	/* Make the flag seen by readers */
> > -	smp_wmb();
> >  }
> >  
> >  /**
> > @@ -1640,8 +1637,6 @@ void tracer_tracing_off(struct trace_array *tr)
> >  	 * important to be fast than accurate.
> >  	 */
> >  	tr->buffer_disabled = 1;
> > -	/* Make the flag seen by readers */
> > -	smp_wmb();
> >  }
> 
> The above three interact with each other. Without the barriers, the
> tr->buffer_disabled = 0, can be set on one CPU, and the other CPU can think
> the buffer is still enabled and do work that will end up doing nothing. Or
> it can be set to 1, and the other CPU still sees it disabled and will not
> do work when it can.

(I'm not that experienced with memory barrier, so I may be writing nonsense
here)

I think you have it inverted? I assume you meant:

"Without the barriers, the tr->buffer_disabled = 1 can be set on one CPU,
and the other CPU can think the buffer is still enabled and do work that
will end up doing nothing."

Your scenario can still happen despite the memory barrier:

CPU1                          CPU2
                              smp_rb()
                              read buffer_disabled, see 0 --> let's do work!
buffer_disabled=1
smp_wb()
                              do work -> end up doing nothing

>From my understanding, smp_wb()'s purpose is ensuring the ordering of one
write and another write, e.g.:
    write(a)
    smp_wb()
    write(b)

For our case, there is only a single write. Therefore I don't think
smp_wb() is useful.

Best regards,
Nam

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ