All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org, x86@kernel.org,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	Hao Luo <haoluo@google.com>, Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH perf/core 02/11] uprobes: Skip emulate/sstep on unique uprobe when ip is changed
Date: Wed, 3 Sep 2025 21:50:34 +0200	[thread overview]
Message-ID: <aLicCjuqchpm1h5I@krava> (raw)
In-Reply-To: <20250903112648.GC18799@redhat.com>

On Wed, Sep 03, 2025 at 01:26:48PM +0200, Oleg Nesterov wrote:
> On 09/02, Jiri Olsa wrote:
> >
> > If user decided to take execution elsewhere, it makes little sense
> > to execute the original instruction, so let's skip it.
> 
> Exactly.
> 
> So why do we need all these "is_unique" complications? Only a single
> is_unique/exclusive consumer can change regs->ip, so I guess handle_swbp()
> can just do
> 
> 	handler_chain(uprobe, regs);
> 	if (instruction_pointer(regs) != bp_vaddr)
> 		goto out;

hum, that's what I did in rfc [1] but I thought you did not like that [2]

[1] https://lore.kernel.org/bpf/20250801210238.2207429-2-jolsa@kernel.org/
[2] https://lore.kernel.org/bpf/20250802103426.GC31711@redhat.com/

I guess I misunderstood your reply [2], I'd be happy to drop the
unique/exclusive flag

jirka

> 
> 
> > Allowing this
> > behaviour only for uprobe with unique consumer attached.
> 
> But if a non-exclusive consumer changes regs->ip, we have a problem
> anyway, right?
> 
> We can probably add something like
> 
> 		rc = uc->handler(uc, regs, &cookie);
> 	+	WARN_ON(!uc->is_unique && instruction_pointer(regs) != bp_vaddr);
> 
> into handler_chain(), although I don't think this is needed.
> 
> Oleg.
> 
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  kernel/events/uprobes.c | 13 ++++++++++---
> >  1 file changed, 10 insertions(+), 3 deletions(-)
> > 
> > diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
> > index b9b088f7333a..da8291941c6b 100644
> > --- a/kernel/events/uprobes.c
> > +++ b/kernel/events/uprobes.c
> > @@ -2568,7 +2568,7 @@ static bool ignore_ret_handler(int rc)
> >  	return rc == UPROBE_HANDLER_REMOVE || rc == UPROBE_HANDLER_IGNORE;
> >  }
> >  
> > -static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
> > +static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs, bool *is_unique)
> >  {
> >  	struct uprobe_consumer *uc;
> >  	bool has_consumers = false, remove = true;
> > @@ -2582,6 +2582,9 @@ static void handler_chain(struct uprobe *uprobe, struct pt_regs *regs)
> >  		__u64 cookie = 0;
> >  		int rc = 0;
> >  
> > +		if (is_unique)
> > +			*is_unique |= uc->is_unique;
> > +
> >  		if (uc->handler) {
> >  			rc = uc->handler(uc, regs, &cookie);
> >  			WARN(rc < 0 || rc > 2,
> > @@ -2735,6 +2738,7 @@ static void handle_swbp(struct pt_regs *regs)
> >  {
> >  	struct uprobe *uprobe;
> >  	unsigned long bp_vaddr;
> > +	bool is_unique = false;
> >  	int is_swbp;
> >  
> >  	bp_vaddr = uprobe_get_swbp_addr(regs);
> > @@ -2789,7 +2793,10 @@ static void handle_swbp(struct pt_regs *regs)
> >  	if (arch_uprobe_ignore(&uprobe->arch, regs))
> >  		goto out;
> >  
> > -	handler_chain(uprobe, regs);
> > +	handler_chain(uprobe, regs, &is_unique);
> > +
> > +	if (is_unique && instruction_pointer(regs) != bp_vaddr)
> > +		goto out;
> >  
> >  	/* Try to optimize after first hit. */
> >  	arch_uprobe_optimize(&uprobe->arch, bp_vaddr);
> > @@ -2819,7 +2826,7 @@ void handle_syscall_uprobe(struct pt_regs *regs, unsigned long bp_vaddr)
> >  		return;
> >  	if (arch_uprobe_ignore(&uprobe->arch, regs))
> >  		return;
> > -	handler_chain(uprobe, regs);
> > +	handler_chain(uprobe, regs, NULL);
> >  }
> >  
> >  /*
> > -- 
> > 2.51.0
> > 
> 

  parent reply	other threads:[~2025-09-03 19:50 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 14:34 [PATCH perf/core 00/11] uprobes: Add unique uprobe Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 01/11] uprobes: Add unique flag to uprobe consumer Jiri Olsa
2025-09-02 15:11   ` Masami Hiramatsu
2025-09-03  6:35     ` Jiri Olsa
2025-09-03 10:49   ` Oleg Nesterov
2025-09-03 12:02     ` Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 02/11] uprobes: Skip emulate/sstep on unique uprobe when ip is changed Jiri Olsa
2025-09-03 11:26   ` Oleg Nesterov
2025-09-03 18:20     ` Andrii Nakryiko
2025-09-03 19:57       ` Jiri Olsa
2025-09-03 19:50     ` Jiri Olsa [this message]
2025-09-04  8:49       ` Oleg Nesterov
2025-09-04 10:46         ` Jiri Olsa
2025-09-04 11:23           ` Oleg Nesterov
2025-09-04 15:01             ` Alexei Starovoitov
2025-09-04 18:06               ` Andrii Nakryiko
2025-09-04 18:55                 ` Oleg Nesterov
2025-09-04 19:42                   ` Andrii Nakryiko
2025-09-05  8:51                     ` Oleg Nesterov
2025-09-02 14:34 ` [PATCH perf/core 03/11] perf: Add support to attach standard unique uprobe Jiri Olsa
2025-09-02 16:13   ` Alexei Starovoitov
2025-09-03  3:32   ` kernel test robot
2025-09-03 11:59   ` Oleg Nesterov
2025-09-03 13:03     ` Jiri Olsa
2025-09-03 13:22       ` Oleg Nesterov
2025-09-02 14:34 ` [PATCH perf/core 04/11] bpf: Add support to attach uprobe_multi " Jiri Olsa
2025-09-02 16:11   ` Alexei Starovoitov
2025-09-03  6:35     ` Jiri Olsa
2025-09-03 15:32       ` Alexei Starovoitov
2025-09-03 19:55         ` Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 05/11] bpf: Allow uprobe program to change context registers Jiri Olsa
2025-09-02 14:34 ` [PATCH perf/core 06/11] libbpf: Add support to attach unique uprobe_multi uprobe Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 07/11] libbpf: Add support to attach generic unique uprobe Jiri Olsa
2025-09-03 18:26   ` Andrii Nakryiko
2025-09-02 14:35 ` [PATCH perf/core 08/11] selftests/bpf: Add uprobe multi context registers changes test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 09/11] selftests/bpf: Add uprobe multi context ip register change test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 10/11] selftests/bpf: Add uprobe multi unique attach test Jiri Olsa
2025-09-02 14:35 ` [PATCH perf/core 11/11] selftests/bpf: Add uprobe " Jiri Olsa

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=aLicCjuqchpm1h5I@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=x86@kernel.org \
    --cc=yhs@fb.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.