mbox series

[v5,tip/perf/core,0/2] uprobes: speculative lockless VMA-to-uprobe lookup

Message ID 20241122035922.3321100-1-andrii@kernel.org (mailing list archive)
Headers show
Series uprobes: speculative lockless VMA-to-uprobe lookup | expand

Message

Andrii Nakryiko Nov. 22, 2024, 3:59 a.m. UTC
Implement speculative (lockless) resolution of VMA to inode to uprobe,
bypassing the need to take mmap_lock for reads, if possible. This series is
based on Suren's patch set [2], which adds mm_struct helpers that help detect
whether mm_struct was changed, which is used by uprobe logic to validate that
speculative results can be trusted after all the lookup logic results in
a valid uprobe instance.

Patch #1 is a simplification to uprobe VMA flag checking, suggested by Oleg.

Patch #2 is the speculative VMA-to-uprobe resolution logic itself, and is the
focal point of this patch set. It makes entry uprobes in common case scale
very well with number of CPUs, as we avoid any locking or cache line bouncing
between CPUs. See corresponding patch for details and benchmarking results.

Note, this patch set assumes that FMODE_BACKING files were switched to have
SLAB_TYPE_SAFE_BY_RCU semantics, which was recently done by Christian Brauner
in [0]. This change can be pulled into perf/core through stable
tags/vfs-6.13.for-bpf.file tag from [1].

  [0] https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git/commit/?h=vfs-6.13.for-bpf.file&id=8b1bc2590af61129b82a189e9dc7c2804c34400e
  [1] git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
  [2] https://lore.kernel.org/linux-mm/20241121162826.987947-1-surenb@google.com/

v4->v5:
- rebase on top of Suren's latest version of mm patches addressing Peter's
  comment and API renaming request;
v3->v4:
- rebased and dropped data_race(), given mm_struct uses real seqcount (Peter);
v2->v3:
- dropped kfree_rcu() patch (Christian);
- added data_race() annotations for fields of vma and vma->vm_file which could
  be modified during speculative lookup (Oleg);
- fixed int->long problem in stubs for mmap_lock_speculation_{start,end}(),
  caught by Kernel test robot;
v1->v2:
- adjusted vma_end_write_all() comment to point out it should never be called
  manually now, but I wasn't sure how ACQUIRE/RELEASE comments should be
  reworded (previously requested by Jann), so I'd appreciate some help there
  (Jann);
- int -> long change for mm_lock_seq, as agreed at LPC2024 (Jann, Suren, Liam);
- kfree_rcu_mightsleep() for FMODE_BACKING (Suren, Christian);
- vm_flags simplification in find_active_uprobe_rcu() and
  find_active_uprobe_speculative() (Oleg);
- guard(rcu)() simplified find_active_uprobe_speculative() implementation.

Andrii Nakryiko (2):
  uprobes: simplify find_active_uprobe_rcu() VMA checks
  uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution

 kernel/events/uprobes.c | 47 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

Comments

Peter Zijlstra Nov. 22, 2024, 11:07 a.m. UTC | #1
On Thu, Nov 21, 2024 at 07:59:20PM -0800, Andrii Nakryiko wrote:

> Andrii Nakryiko (2):
>   uprobes: simplify find_active_uprobe_rcu() VMA checks
>   uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution

Thanks, assuming Suren is okay with me carrying his patches through tip,
I'll make this land in tip/perf/core after -rc1.
Suren Baghdasaryan Nov. 22, 2024, 3:04 p.m. UTC | #2
On Fri, Nov 22, 2024 at 3:07 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Nov 21, 2024 at 07:59:20PM -0800, Andrii Nakryiko wrote:
>
> > Andrii Nakryiko (2):
> >   uprobes: simplify find_active_uprobe_rcu() VMA checks
> >   uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution
>
> Thanks, assuming Suren is okay with me carrying his patches through tip,
> I'll make this land in tip/perf/core after -rc1.

No objections from me. Thanks!
Suren Baghdasaryan Nov. 22, 2024, 5:48 p.m. UTC | #3
On Fri, Nov 22, 2024 at 7:04 AM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Fri, Nov 22, 2024 at 3:07 AM Peter Zijlstra <peterz@infradead.org> wrote:
> >
> > On Thu, Nov 21, 2024 at 07:59:20PM -0800, Andrii Nakryiko wrote:
> >
> > > Andrii Nakryiko (2):
> > >   uprobes: simplify find_active_uprobe_rcu() VMA checks
> > >   uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution
> >
> > Thanks, assuming Suren is okay with me carrying his patches through tip,
> > I'll make this land in tip/perf/core after -rc1.
>
> No objections from me. Thanks!

I just fixed a build issue in one of my patches for an odd config, so
please use the latest version of the patchset from here:
https://lore.kernel.org/all/20241122174416.1367052-1-surenb@google.com/
Peter Zijlstra Nov. 23, 2024, 8:35 p.m. UTC | #4
On Fri, Nov 22, 2024 at 09:48:11AM -0800, Suren Baghdasaryan wrote:
> On Fri, Nov 22, 2024 at 7:04 AM Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > On Fri, Nov 22, 2024 at 3:07 AM Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Thu, Nov 21, 2024 at 07:59:20PM -0800, Andrii Nakryiko wrote:
> > >
> > > > Andrii Nakryiko (2):
> > > >   uprobes: simplify find_active_uprobe_rcu() VMA checks
> > > >   uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution
> > >
> > > Thanks, assuming Suren is okay with me carrying his patches through tip,
> > > I'll make this land in tip/perf/core after -rc1.
> >
> > No objections from me. Thanks!
> 
> I just fixed a build issue in one of my patches for an odd config, so
> please use the latest version of the patchset from here:
> https://lore.kernel.org/all/20241122174416.1367052-1-surenb@google.com/

updated, thanks!
Suren Baghdasaryan Nov. 24, 2024, 7:56 p.m. UTC | #5
On Sat, Nov 23, 2024 at 12:35 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Fri, Nov 22, 2024 at 09:48:11AM -0800, Suren Baghdasaryan wrote:
> > On Fri, Nov 22, 2024 at 7:04 AM Suren Baghdasaryan <surenb@google.com> wrote:
> > >
> > > On Fri, Nov 22, 2024 at 3:07 AM Peter Zijlstra <peterz@infradead.org> wrote:
> > > >
> > > > On Thu, Nov 21, 2024 at 07:59:20PM -0800, Andrii Nakryiko wrote:
> > > >
> > > > > Andrii Nakryiko (2):
> > > > >   uprobes: simplify find_active_uprobe_rcu() VMA checks
> > > > >   uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution
> > > >
> > > > Thanks, assuming Suren is okay with me carrying his patches through tip,
> > > > I'll make this land in tip/perf/core after -rc1.
> > >
> > > No objections from me. Thanks!
> >
> > I just fixed a build issue in one of my patches for an odd config, so
> > please use the latest version of the patchset from here:
> > https://lore.kernel.org/all/20241122174416.1367052-1-surenb@google.com/
>
> updated, thanks!

Hi Andrew,
I just noticed that patches from an old version of my patchset are
present in mm-unstable, more specifically these two:

fb23aacd2a14 "mm: convert mm_lock_seq to a proper seqcount"
549aeb99ccf1 "mm: introduce mmap_lock_speculation_{begin|end}"

Peter will be merging the latest version into tip/perf/core, so this
will cause a conflict at some point.
It should be easy to update them in mm-unstable to the latest version
[1]. I was able to revert the old ones and apply the new ones without
any merge conflict. If possible, please update them instead of
dropping them from mm-unstable. Some patches I'm preparing to post
have dependencies on this patchset.
Thanks,
Suren.

[1] https://lore.kernel.org/all/20241122174416.1367052-1-surenb@google.com/