linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Suren Baghdasaryan <surenb@google.com>,
	 akpm@linux-foundation.org, willy@infradead.org,
	david@redhat.com,  peterx@redhat.com, vbabka@suse.cz,
	michel@lespinasse.org, jglisse@google.com,  mhocko@suse.com,
	hannes@cmpxchg.org, dave@stgolabs.net, ldufour@linux.ibm.com,
	 hughd@google.com, punit.agrawal@bytedance.com,
	lstoakes@gmail.com,  rientjes@google.com,
	axelrasmussen@google.com, jannh@google.com,  shakeelb@google.com,
	tatashin@google.com, gthelen@google.com,  linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	 kernel-team@android.com
Subject: Re: [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible
Date: Fri, 7 Jul 2023 13:15:29 -0700	[thread overview]
Message-ID: <CAJuCfpEfhwU3hP+tWi=tpRGm2k6hyV7139oh1CH_E6v331wbeA@mail.gmail.com> (raw)
In-Reply-To: <20230707194829.u3p5zfjckmh6lktx@revolver>

On Fri, Jul 7, 2023 at 7:48 PM Liam R. Howlett <Liam.Howlett@oracle.com> wrote:
>
> * Suren Baghdasaryan <surenb@google.com> [230707 00:32]:
> > mmap_region adds a newly created VMA into VMA tree and might modify it
> > afterwards before dropping the mmap_lock. This poses a problem for page
> > faults handled under per-VMA locks because they don't take the mmap_lock
> > and can stumble on this VMA while it's still being modified. Currently
> > this does not pose a problem since post-addition modifications are done
> > only for file-backed VMAs, which are not handled under per-VMA lock.
> > However, once support for handling file-backed page faults with per-VMA
> > locks is added, this will become a race.
> > Fix this by write-locking the VMA before inserting it into the VMA tree.
> > Other places where a new VMA is added into VMA tree do not modify it
> > after the insertion, so do not need the same locking.
> >
> > Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> > ---
> >  mm/mmap.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/mm/mmap.c b/mm/mmap.c
> > index c66e4622a557..84c71431a527 100644
> > --- a/mm/mmap.c
> > +++ b/mm/mmap.c
> > @@ -2812,6 +2812,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> >       if (vma->vm_file)
> >               i_mmap_lock_write(vma->vm_file->f_mapping);
> >
> > +     /* Lock the VMA since it is modified after insertion into VMA tree */
>
> So it is modified, but that i_mmap_lock_write() directly above this
> comment is potentially moving below the insert and that is why this lock
> is needed.

Correct, we should not rely on i_mmap_lock_write() which can be moved
(and is suggested to be moved in
https://lore.kernel.org/all/20230606124939.93561-1-yu.ma@intel.com/).


>
> > +     vma_start_write(vma);
> >       vma_iter_store(&vmi, vma);
> >       mm->map_count++;
> >       if (vma->vm_file) {
> > --
> > 2.41.0.255.g8b1d071c50-goog
> >
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to kernel-team+unsubscribe@android.com.
>


  reply	other threads:[~2023-07-07 20:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07  4:32 [PATCH 1/2] mm: lock a vma before stack expansion Suren Baghdasaryan
2023-07-07  4:32 ` [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible Suren Baghdasaryan
2023-07-07 19:48   ` Liam R. Howlett
2023-07-07 20:15     ` Suren Baghdasaryan [this message]
2023-07-07 19:27 ` [PATCH 1/2] mm: lock a vma before stack expansion Andrew Morton
2023-07-07 20:03   ` Suren Baghdasaryan
2023-07-07 20:00 ` Markus Elfring
2023-07-07 20:03   ` Matthew Wilcox
2023-07-07 20:08     ` Suren Baghdasaryan
2023-07-08  5:55       ` [1/2] " Markus Elfring
2023-07-08  6:18         ` Suren Baghdasaryan
2023-07-08  6:33           ` Markus Elfring
2023-07-08  5:30     ` Markus Elfring

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='CAJuCfpEfhwU3hP+tWi=tpRGm2k6hyV7139oh1CH_E6v331wbeA@mail.gmail.com' \
    --to=surenb@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jannh@google.com \
    --cc=jglisse@google.com \
    --cc=kernel-team@android.com \
    --cc=ldufour@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mhocko@suse.com \
    --cc=michel@lespinasse.org \
    --cc=peterx@redhat.com \
    --cc=punit.agrawal@bytedance.com \
    --cc=rientjes@google.com \
    --cc=shakeelb@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tatashin@google.com \
    --cc=vbabka@suse.cz \
    --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