Re: [PATCH 1/3] tracing: Return EOF instead of blocking on empty readonly instances
From: Masami Hiramatsu (Google)
Date: Wed Dec 02 2026 - 20:58:29 EST
On Wed, 2 Dec 2026 12:31:51 -0500, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> On Thu, 3 Dec 2026 00:05:25 +0900
> "Masami Hiramatsu (Google)" <mhiramat@xxxxxxxxxx> wrote:
>
> > ---
> > kernel/trace/trace.c | 18 +++++++++++++++---
> > 1 file changed, 15 insertions(+), 3 deletions(-)
> >
> > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> > index fa65ef8d7fbe..1a355f919fdb 100644
> > --- a/kernel/trace/trace.c
> > +++ b/kernel/trace/trace.c
> > @@ -5373,6 +5373,10 @@ static int tracing_wait_pipe(struct file *filp)
> > return -EAGAIN;
> > }
> >
> > + /* Readonly instances can never receive new events. */
> > + if (trace_array_is_readonly(iter->tr))
> > + return 0;
> > +
> > /*
> > * We block until we read something and tracing is disabled.
> > * We still block if tracing is disabled, but we have never
> > @@ -7162,6 +7166,9 @@ ssize_t tracing_buffers_read(struct file *filp, char __user *ubuf,
> > if ((filp->f_flags & O_NONBLOCK))
> > return -EAGAIN;
> >
>
> If the buffer is read only, even if the flag has NONBLOCK set, I think it
> should still return zero. As it will not get more data, right?
Ah, good catch! Indeed, this should NOT return -EAGAIN, because it is
read only.
>
>
> > + if (trace_array_is_readonly(iter->tr))
> > + return 0;
> > +
> > ret = wait_on_pipe(iter, 0);
> > if (ret)
> > return ret;
> > @@ -7375,8 +7382,12 @@ ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
> > if (woken)
> > goto out;
> >
> > - ret = -EAGAIN;
> > - if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
> > + if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) {
> > + ret = -EAGAIN;
> > + goto out;
> > + }
> > +
> > + if (trace_array_is_readonly(iter->tr))
> > goto out;
>
> It would make this change better, as the check could be before the ret = -EGAIN.
OK, let me update it not returning -EAGAIN on readonly instance.
Thanks!
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>