Thread (8 messages) 8 messages, 3 authors, 11h ago

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

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date: 2026-07-13 02:56:01
Also in: lkml

On Fri, 10 Jul 2026 07:46:05 -0400
Steven Rostedt [off-list ref] wrote:
On Fri, 10 Jul 2026 12:22:31 +0900
Masami Hiramatsu (Google) [off-list ref] wrote:
quoted
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) [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help