Re: [BUG] tracing: Too many tries to read user space

From: Google

Date: Sun Jul 12 2026 - 22:56:09 EST


On Fri, 10 Jul 2026 07:46:05 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Fri, 10 Jul 2026 12:22:31 +0900
> Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
>
> > However, this seems a bit strange that we only checks the CPU-wide context
> > switching in the loop. Instead, can we introduce a per-cpu sequence counter
> > to per-cpu buffer, and check it?
>
> I originally tried this but found a situation that it fails:
>
> tbuf->sequence = 0;
>
> Task 1 Task 2
> ------ ------
>
> tbuf->sequence++;
> seq = tbuf->sequence; (seq = 1)
>
> preempt_enable();
>
> [schedule] ---------------------->
>
> tbuf->sequence++;
> seq = tbuf->sequence; (seq = 2);
>
> preempt_enable();
>
> copy_from_user(buffer);
>
> <--------------------[schedule]
>
> copy_from_user(buffer);
>
> *** BUFFER NOW CORRUPTED ***
>
> [schedule] ---------------------->
>
> preempt_disable();
>
> } while (tubf->sequence != seq); // tbuf->sequence == seq !!!!
>
>
> This is why we use a CPU wide counter.

Ah, indeed. As similar to seqlock, maybe we need to increment sequence
number after the process so that we can find the buffer is used some
other process. Or, just use a mutex to wait. But anyway, that will be
make it slower?

BTW, it is just an idea, but can we split fast path (per-cpu buffer)
and slow path (allocate an intermadiate buffer) for the page which
can cause page fault ?

Thanks,

>
> -- Steve
>
>


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>