linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: surenb@google.com, Liam Howlett <liam.howlett@oracle.com>,
	 Andrii Nakryiko <andrii@kernel.org>,
	brauner@kernel.org, linux-trace-kernel@vger.kernel.org,
	 peterz@infradead.org, oleg@redhat.com, rostedt@goodmis.org,
	 mhiramat@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org,  jolsa@kernel.org,
	paulmck@kernel.org, willy@infradead.org,
	 akpm@linux-foundation.org, linux-mm@kvack.org,
	mjguzik@gmail.com,  Miklos Szeredi <miklos@szeredi.hu>,
	Amir Goldstein <amir73il@gmail.com>,
	 linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 2/2] uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution
Date: Tue, 10 Sep 2024 17:39:19 +0200	[thread overview]
Message-ID: <CAG48ez1d9tU7-QeRSjRuxovG-jjNAwJ8B_G2jd43_etYMUPV6g@mail.gmail.com> (raw)
In-Reply-To: <CAEf4Bzb+ShZqcj9EKQB8U9tyaJ1LoOpRxd24v76FuPJP-=dkNg@mail.gmail.com>

On Mon, Sep 9, 2024 at 11:29 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
> On Mon, Sep 9, 2024 at 6:13 AM Jann Horn <jannh@google.com> wrote:
> > On Fri, Sep 6, 2024 at 7:12 AM Andrii Nakryiko <andrii@kernel.org> wrote:
> > > +static struct uprobe *find_active_uprobe_speculative(unsigned long bp_vaddr)
> > > +{
> > > +       const vm_flags_t flags = VM_HUGETLB | VM_MAYEXEC | VM_MAYSHARE;
> > > +       struct mm_struct *mm = current->mm;
> > > +       struct uprobe *uprobe;
> > > +       struct vm_area_struct *vma;
> > > +       struct file *vm_file;
> > > +       struct inode *vm_inode;
> > > +       unsigned long vm_pgoff, vm_start;
> > > +       int seq;
> > > +       loff_t offset;
> > > +
> > > +       if (!mmap_lock_speculation_start(mm, &seq))
> > > +               return NULL;
> > > +
> > > +       rcu_read_lock();
> > > +
> > > +       vma = vma_lookup(mm, bp_vaddr);
> > > +       if (!vma)
> > > +               goto bail;
> > > +
> > > +       vm_file = data_race(vma->vm_file);
> >
> > A plain "data_race()" says "I'm fine with this load tearing", but
> > you're relying on this load not tearing (since you access the vm_file
> > pointer below).
> > You're also relying on the "struct file" that vma->vm_file points to
> > being populated at this point, which means you need CONSUME semantics
> > here, which READ_ONCE() will give you, and something like RELEASE
> > semantics on any pairing store that populates vma->vm_file, which
> > means they'd all have to become something like smp_store_release()).
>
> vma->vm_file should be set in VMA before it is installed and is never
> modified afterwards, isn't that the case? So maybe no extra barrier
> are needed and READ_ONCE() would be enough.

Ah, right, I'm not sure what I was thinking there.

I... guess you only _really_ need the READ_ONCE() if something can
actually ever change the ->vm_file pointer, otherwise just a plain
load with no annotation whatsoever would be good enough? I'm fairly
sure nothing can ever change the ->vm_file pointer of a live VMA, and
I think _currently_ it looks like nothing will NULL out the ->vm_file
pointer on free either... though that last part is probably not
something you should rely on...


  reply	other threads:[~2024-09-10 15:40 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-06  5:12 [PATCH 0/2] uprobes,mm: speculative lockless VMA-to-uprobe lookup Andrii Nakryiko
2024-09-06  5:12 ` [PATCH 1/2] mm: introduce mmap_lock_speculation_{start|end} Andrii Nakryiko
2024-09-09 12:35   ` Jann Horn
2024-09-10  2:09     ` Suren Baghdasaryan
2024-09-10 15:31       ` Jann Horn
2024-09-11 21:34       ` Andrii Nakryiko
2024-09-11 21:48         ` Suren Baghdasaryan
2024-09-12 21:02           ` [PATCH v2 1/1] " Suren Baghdasaryan
2024-09-12 21:04             ` Suren Baghdasaryan
2024-09-12 22:19               ` Andrii Nakryiko
2024-09-12 22:24                 ` Suren Baghdasaryan
2024-09-12 22:52             ` Jann Horn
2024-09-24 17:15               ` Matthew Wilcox
2024-09-24 18:00                 ` Jann Horn
2024-09-06  5:12 ` [PATCH 2/2] uprobes: add speculative lockless VMA-to-inode-to-uprobe resolution Andrii Nakryiko
2024-09-08  1:22   ` Liam R. Howlett
2024-09-09  1:08     ` Andrii Nakryiko
2024-09-09 13:12   ` Jann Horn
2024-09-09 21:29     ` Andrii Nakryiko
2024-09-10 15:39       ` Jann Horn [this message]
2024-09-10 20:56         ` Andrii Nakryiko
2024-09-10 16:32       ` Suren Baghdasaryan
2024-09-10 20:58         ` Andrii Nakryiko
2024-09-12 11:17           ` Christian Brauner
2024-09-12 17:54             ` Andrii Nakryiko
2024-09-15 15:04   ` Oleg Nesterov
2024-09-17  8:19     ` Andrii Nakryiko
2024-09-10 16:06 ` [PATCH 0/2] uprobes,mm: speculative lockless VMA-to-uprobe lookup Jann Horn
2024-09-10 17:58   ` Andrii Nakryiko
2024-09-10 18:13     ` Jann Horn

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=CAG48ez1d9tU7-QeRSjRuxovG-jjNAwJ8B_G2jd43_etYMUPV6g@mail.gmail.com \
    --to=jannh@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=amir73il@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=liam.howlett@oracle.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mjguzik@gmail.com \
    --cc=oleg@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=willy@infradead.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