Re: [PATCH 2/2] uprobes: Skip remove_breakpoint() if UPROBE_COPY_INSN is not set
From: Masami Hiramatsu (Google)
Date: Thu Dec 03 2026 - 21:55:10 EST
On Thu, 3 Dec 2026 12:58:50 +0100, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> On 12/03, Masami Hiramatsu (Google) wrote:
> >
> > @@ -1194,6 +1197,19 @@ static int remove_breakpoint(struct uprobe *uprobe, struct vm_area_struct *vma,
> > {
> > struct mm_struct *mm = vma->vm_mm;
> >
> > + /* No breakpoint was ever installed if prepare_uprobe() never succeeded */
> > + if (!test_bit(UPROBE_COPY_INSN, &uprobe->flags))
> > + return 0;
> > +
> > + /*
> > + * Pairs with the smp_wmb() in prepare_uprobe().
> > + *
> > + * Guarantees that if we see the UPROBE_COPY_INSN bit set, then
> > + * we must also see the stores to &uprobe->arch before
> > + * set_orig_insn() reads them.
> > + */
> > + smp_rmb();
>
> Acked-by: Oleg Nesterov <oleg@xxxxxxxxxx>
>
Thanks!
> But again, it can use test_bit_acquire() unless I am confused.
Ah, indeed. I'll switch this to test_bit_acquire() in v2 too.
>
> And perhaps it would be better to change uprobe_unregister_nosync()
> to check UPROBE_COPY_INSN once?
Hm, I think keeping the check in remove_breakpoint() is safer for 3
reasons:
- It can race with uprobe_mmap() and then makes an orphaned
breakpoint. (uprobe_mmap() does not take register_rwsem.)
Since remove_breakpoint() is called under mmap_write_lock(mm),
it can avoid such race.
- uprobe_apply(uprobe, uc, false) also calls register_for_each_vma() ->
remove_breakpoint().
- As Sashiko pointed out on this patch, if MMF_HAS_UPROBES is still set on
an mm, remove_breakpoint() still needs to set MMF_RECALC_UPROBES before
skipping set_orig_insn().
>
> In any case UPROBE_COPY_INSN must die ;) see the TODO comment in
> prepare_uprobe().
Agreed. Since this may involve bigger refactoring across arch dependent
code, that should be done later.
Thank you,
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>