From: Jiri Olsa <olsajiri@gmail.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
oleg@redhat.com, andrii@kernel.org, mhiramat@kernel.org,
linux-kernel@vger.kernel.org, alx@kernel.org,
eyal.birger@gmail.com, kees@kernel.org, bpf@vger.kernel.org,
linux-trace-kernel@vger.kernel.org, x86@kernel.org,
songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com,
haoluo@google.com, rostedt@goodmis.org, alan.maguire@oracle.com,
David.Laight@aculab.com, thomas@t-8ch.de, mingo@kernel.org,
rick.p.edgecombe@intel.com
Subject: Re: [PATCH 2/6] uprobes/x86: Optimize is_optimize()
Date: Tue, 26 Aug 2025 10:25:29 +0200 [thread overview]
Message-ID: <aK1veaIWBv3dZUUP@krava> (raw)
In-Reply-To: <20250826065158.1b7ad5fc@pumpkin>
On Tue, Aug 26, 2025 at 06:51:58AM +0100, David Laight wrote:
> On Thu, 21 Aug 2025 14:28:24 +0200
> Peter Zijlstra <peterz@infradead.org> wrote:
>
> > Make is_optimized() return a tri-state and avoid return through
> > argument. This simplifies things a little.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > arch/x86/kernel/uprobes.c | 34 +++++++++++++---------------------
> > 1 file changed, 13 insertions(+), 21 deletions(-)
> >
> > --- a/arch/x86/kernel/uprobes.c
> > +++ b/arch/x86/kernel/uprobes.c
> > @@ -1047,7 +1047,7 @@ static bool __is_optimized(uprobe_opcode
> > return __in_uprobe_trampoline(vaddr + 5 + call->raddr);
> > }
> >
> > -static int is_optimized(struct mm_struct *mm, unsigned long vaddr, bool *optimized)
> > +static int is_optimized(struct mm_struct *mm, unsigned long vaddr)
> > {
> > uprobe_opcode_t insn[5];
> > int err;
> > @@ -1055,8 +1055,7 @@ static int is_optimized(struct mm_struct
> > err = copy_from_vaddr(mm, vaddr, &insn, 5);
> > if (err)
> > return err;
> > - *optimized = __is_optimized((uprobe_opcode_t *)&insn, vaddr);
> > - return 0;
> > + return __is_optimized((uprobe_opcode_t *)&insn, vaddr);
> > }
> >
> > static bool should_optimize(struct arch_uprobe *auprobe)
> > @@ -1069,17 +1068,14 @@ int set_swbp(struct arch_uprobe *auprobe
> > unsigned long vaddr)
> > {
> > if (should_optimize(auprobe)) {
> > - bool optimized = false;
> > - int err;
> > -
> > /*
> > * We could race with another thread that already optimized the probe,
> > * so let's not overwrite it with int3 again in this case.
> > */
> > - err = is_optimized(vma->vm_mm, vaddr, &optimized);
> > - if (err)
> > - return err;
> > - if (optimized)
> > + int ret = is_optimized(vma->vm_mm, vaddr);
> > + if (ret < 0)
> > + return ret;
> > + if (ret)
> > return 0;
>
> Looks like you should swap over 0 and 1.
> That would then be: if (ret <= 0) return ret;
hum, but if it's not optimized (ret == 0) we need to follow up with
installing breakpoint through following uprobe_write_opcode call
also I noticed we mix int/bool return, perhaps we could do fix below
jirka
---
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 0a8c0a4a5423..853abb2a5638 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -1064,7 +1064,7 @@ static int is_optimized(struct mm_struct *mm, unsigned long vaddr)
err = copy_from_vaddr(mm, vaddr, &insn, 5);
if (err)
return err;
- return __is_optimized((uprobe_opcode_t *)&insn, vaddr);
+ return __is_optimized((uprobe_opcode_t *)&insn, vaddr) ? 1 : 0;
}
static bool should_optimize(struct arch_uprobe *auprobe)
next prev parent reply other threads:[~2025-08-26 8:25 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 12:28 [PATCH 0/6] uprobes/x86: Cleanups and fixes Peter Zijlstra
2025-08-21 12:28 ` [PATCH 1/6] uprobes/x86: Add struct uretprobe_syscall_args Peter Zijlstra
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-08-21 12:28 ` [PATCH 2/6] uprobes/x86: Optimize is_optimize() Peter Zijlstra
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-08-26 5:51 ` [PATCH 2/6] " David Laight
2025-08-26 8:18 ` Peter Zijlstra
2025-08-27 19:32 ` David Laight
2025-08-26 8:25 ` Jiri Olsa [this message]
2025-08-26 8:33 ` Jiri Olsa
2025-08-21 12:28 ` [PATCH 3/6] uprobes/x86: Accept more NOP forms Peter Zijlstra
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-08-21 12:28 ` [PATCH 4/6] uprobes/x86: Fix uprobe syscall vs shadow stack Peter Zijlstra
2025-08-21 18:26 ` Edgecombe, Rick P
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-08-21 12:28 ` [PATCH 5/6] uprobes/x86: Make asm style consistent Peter Zijlstra
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-08-21 12:28 ` [PATCH 6/6] uprobes/x86: Add SLS mitigation to the trampolines Peter Zijlstra
2025-08-25 10:24 ` [tip: perf/core] " tip-bot2 for Peter Zijlstra
2025-09-10 1:05 ` [PATCH 6/6] " Masami Hiramatsu
2025-08-21 14:18 ` [PATCH 0/6] uprobes/x86: Cleanups and fixes Jiri Olsa
2025-08-21 18:27 ` Edgecombe, Rick P
2025-08-21 19:52 ` Jiri Olsa
2025-08-21 19:57 ` Edgecombe, Rick P
2025-08-22 8:42 ` Jiri Olsa
2025-08-22 18:05 ` Andrii Nakryiko
2025-09-09 12:48 ` Jiri Olsa
2025-09-09 15:20 ` Andrii Nakryiko
2025-09-09 16:39 ` Jiri Olsa
2025-09-09 16:44 ` Andrii Nakryiko
2025-08-22 15:51 ` Oleg Nesterov
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=aK1veaIWBv3dZUUP@krava \
--to=olsajiri@gmail.com \
--cc=David.Laight@aculab.com \
--cc=alan.maguire@oracle.com \
--cc=alx@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=eyal.birger@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kees@kernel.org \
--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=rick.p.edgecombe@intel.com \
--cc=rostedt@goodmis.org \
--cc=songliubraving@fb.com \
--cc=thomas@t-8ch.de \
--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.