Re: [GIT PULL] tracing: user_event fix for 6.4

From: Steven Rostedt
Date: Fri Jun 23 2023 - 22:10:09 EST


On Fri, 23 Jun 2023 16:21:36 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Fri, 23 Jun 2023 at 12:29, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > Before user events become an ABI, fix the return value of the write
> > operation when tracing is disabled. It should not return an error, but
> > simply report it wrote zero bytes. Just like any other write operation
> > that doesn't write data but does not "fail".
>
> This makes no sense.
>
> A write() returning 0 means "Disk full". It's most definitely an
> error, and a failure.
>

OK, I shouldn't have said that it was like other disk write options. I
was thinking more of writing to something that uses a buffer like
snprintf() which returns the number of bytes written.

> But zero is not a particularly _good_ failure code. At least not
> unless your tracing disk is full. Is it?

It's not a failure. It means that the buffer is disabled. This is more
in line to what the kernel trace events do when tracing is disabled,
the writes just return zero. That is, you do not want to retry.

>
> If tracing is disabled, and you write something to it, I would expect
> to get a valid and reasonable error code back. Something like EINVAL
> or EIO or something to show "you did something wrong".
>
> I do not at all understand the sentence
>
> "When user_events are disabled, its write operation should return zero"
>
> as an "explanation" for this, and my immediate reaction is "Really?
> Why? That makes no sense".


So basically the way tracing is done is that something can enable the
event (that will then do the write) but if the trace buffer writes are
disabled, the writes should just be dropped. This is how it currently
works in the kernel, and we were trying to make it the same in user
space.

The code that does the write is basically something being monitored by
something else that will tell it to start writing. But that something
else could have the buffer disabled for writes. The use case for this
is to disable the buffer, enable all the trace events you care about,
and then enabled the buffer which is the same as enabling all events at
the same time to get a more coherent trace.

But we don't want the writes to return errors when the buffer is
disabled. The writes should just be dropped. An error code means
something isn't connected properly, but a zero return just means
everything is connected properly, but it is not ready to accept content
yet.

-- Steve