Linux Trace Kernel
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Jeongho Choi <jh1012.choi@samsung.com>,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
	ji2yoon.jo@samsung.com, minki.jang@samsung.com,
	hajun.sung@samsung.com
Subject: Re: [BUG] tracing: Too many tries to read user space
Date: Mon, 13 Jul 2026 11:55:57 +0900	[thread overview]
Message-ID: <20260713115557.0a8f1c8feb24f435f9c3fece@kernel.org> (raw)
In-Reply-To: <20260710074605.33802554@gandalf.local.home>

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

> On Fri, 10 Jul 2026 12:22:31 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> 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@kernel.org>

  reply	other threads:[~2026-07-13  2:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260708123754epcas2p1f15cc305ddb09f97164491d750769ef7@epcas2p1.samsung.com>
2026-07-08 12:37 ` [BUG] tracing: Too many tries to read user space Jeongho Choi
2026-07-08 13:18   ` Steven Rostedt
2026-07-09  0:04     ` Masami Hiramatsu
2026-07-10  3:22   ` Masami Hiramatsu
2026-07-10 11:46     ` Steven Rostedt
2026-07-13  2:55       ` Masami Hiramatsu [this message]
2026-07-10 12:33     ` Steven Rostedt
2026-07-13  3:16       ` Masami Hiramatsu
2026-07-13 14:23         ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260713115557.0a8f1c8feb24f435f9c3fece@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=hajun.sung@samsung.com \
    --cc=jh1012.choi@samsung.com \
    --cc=ji2yoon.jo@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=minki.jang@samsung.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox