Re: [GIT PULL v2] tracing: Updates for v6.9

From: Steven Rostedt
Date: Tue Mar 19 2024 - 13:04:39 EST


On Tue, 19 Mar 2024 09:23:10 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Mon, 18 Mar 2024 at 08:28, Steven Rostedt <rostedt@xxxxxxxxxxx> 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