mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Beau Belgrave <beaub@linux.microsoft.com>,
	Huang Yiwei <quic_hyiwei@quicinc.com>,
	John Garry <john.g.garry@oracle.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Thorsten Blum <thorsten.blum@toblux.com>,
	Vincent Donnefort <vdonnefort@google.com>,
	linke li <lilinke99@qq.com>
Subject: Re: [GIT PULL v2] tracing: Updates for v6.9
Date: Tue, 19 Mar 2024 13:06:53 -0400	[thread overview]
Message-ID: <20240319130653.0cfdaf6e@gandalf.local.home> (raw)
In-Reply-To: <CAHk-=wjxX16kWd=uxG5wzqt=aXoYDf1BgWOKk+qVmAO0zh7sjA@mail.gmail.com>

On Tue, 19 Mar 2024 09:23:10 -0700
Linus Torvalds <torvalds@linux-foundation.org> wrote:

> On Mon, 18 Mar 2024 at 08:28, Steven Rostedt <rostedt@goodmis.org> wrote:
> >
> > - Added checks to make sure that the source of __string() is also the
> >   source of __assign_str() so that it can be safely removed in the next
> >   merge window.  
> 
> Aargh.
> 
> I didn't notice this initially, because it doesn't happen with gcc (or
> maybe not with allmodconfig), but with clang I get
> 
>     CC [M]  net/sunrpc/sched.o
>   In file included from net/sunrpc/sched.c:31:
>   In file included from ./include/trace/events/sunrpc.h:2524:
>   In file included from ./include/trace/define_trace.h:102:
>   In file included from ./include/trace/trace_events.h:419:
>   include/trace/events/sunrpc.h:707:4: error: result of comparison
> against a string literal is unspecified (use an explicit string
> comparison function instead) [-Werror,-Wstring-compare]
> 
> and then about 250 lines ot messy "explanations" for how it was
> expanded because it happens on line 709 too in the same macro, and it
> ends up being three macros deep or something.
> 
> So no, this all needs to be re-done. That
> 
>                 WARN_ON_ONCE(__builtin_constant_p(src) ?                \
>                              strcmp((src), __data_offsets.dst##_ptr_) : \
>                              (src) != __data_offsets.dst##_ptr_);       \
> 
> does *NOT* work.

In most all cases, src is not a constant and should always equal to what was
passed to __string(), but if it is a constant like "some string" then clang
warns that comparing pointers to strings is UB.

That is,

	__string(src, mystring)

[..]

	__assign_str(src, mystring);

works, but if it has:

	__string(src, "this string");

then

	__assign_str(src, "this string");

is UB due to the compiler having two different pointers to "this string".

I originally just had the "src != str" check but then it was reported that
clang complained about it. It still complained with the
__builtin_constant_p() but the code that it produced did the right thing.

This is in the fast path (where the trace event happens), but I can make it
always do strcmp(), even though it will slow down what is being recorded,
as I plan on removing the parameter in the next merge window anyway.

-- Steve


  parent reply	other threads:[~2024-03-19 17:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 15:30 Steven Rostedt
2024-03-18 22:47 ` pr-tracker-bot
2024-03-19 16:23 ` Linus Torvalds
2024-03-19 16:58   ` Steven Rostedt
2024-03-19 17:06   ` Steven Rostedt [this message]
2024-03-19 17:13     ` Steven Rostedt
2024-03-19 21:03       ` Nathan Chancellor
2024-03-19 21:22         ` Linus Torvalds
2024-03-19 21:27           ` Nathan Chancellor
2024-03-19 21:27         ` Steven Rostedt

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=20240319130653.0cfdaf6e@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=alison.schofield@intel.com \
    --cc=beaub@linux.microsoft.com \
    --cc=john.g.garry@oracle.com \
    --cc=lilinke99@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=quic_hyiwei@quicinc.com \
    --cc=rdunlap@infradead.org \
    --cc=thorsten.blum@toblux.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vdonnefort@google.com \
    /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

all inboxes | Powered by JetHome®