linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: akpm@linux-foundation.org, Suren Baghdasaryan <surenb@google.com>
Cc: torvalds@linux-foundation.org, willy@infradead.org,
	 liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com,
	 ldufour@linux.ibm.com, vbabka@suse.cz, michel@lespinasse.org,
	 jglisse@google.com, mhocko@suse.com, hannes@cmpxchg.org,
	dave@stgolabs.net,  hughd@google.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	 kernel-team@android.com
Subject: Re: [PATCH v4 5/6] mm: always lock new vma before inserting into vma tree
Date: Mon, 14 Aug 2023 16:54:01 +0200	[thread overview]
Message-ID: <CAG48ez0XCXoXbSR6dyX7GUQYJKRFKQsHuye5q-PLU3-gR5of5A@mail.gmail.com> (raw)
In-Reply-To: <20230804152724.3090321-6-surenb@google.com>

@akpm can you fix this up?

On Fri, Aug 4, 2023 at 5:27 PM Suren Baghdasaryan <surenb@google.com> wrote:
> While it's not strictly necessary to lock a newly created vma before
> adding it into the vma tree (as long as no further changes are performed
> to it), it seems like a good policy to lock it and prevent accidental
> changes after it becomes visible to the page faults. Lock the vma before
> adding it into the vma tree.
>
> Suggested-by: Jann Horn <jannh@google.com>
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> ---
>  mm/mmap.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 3937479d0e07..850a39dee075 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -412,6 +412,8 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma)
>         if (vma_iter_prealloc(&vmi))
>                 return -ENOMEM;
>
> +       vma_start_write(vma);
> +
>         if (vma->vm_file) {
>                 mapping = vma->vm_file->f_mapping;
>                 i_mmap_lock_write(mapping);

Something went wrong when this part of the patch was applied, because
of a conflict with "mm/mmap: move vma operations to mm_struct out of
the critical section of file mapping lock"; see how this patch ended
up in the mm tree:
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?id=26cb4dafc13871ab68a4fb480ca1e19381cff392

> @@ -403,6 +403,8 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma)
>
>   vma_iter_store(&vmi, vma);
>
> + vma_start_write(vma);
> +
>   if (vma->vm_file) {
>  mapping = vma->vm_file->f_mapping;
>  i_mmap_lock_write(mapping);

The "vma_start_write()" has to be ordered before the
"vma_iter_store(&vmi, vma)".


  reply	other threads:[~2023-08-14 14:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04 15:27 [PATCH v4 0/6] make vma locking more obvious Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 1/6] mm: enable page walking API to lock vmas during the walk Suren Baghdasaryan
2023-08-04 19:14   ` Andrew Morton
2023-08-04 19:41     ` Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 2/6] mm: for !CONFIG_PER_VMA_LOCK equate write lock assertion for vma and mmap Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 3/6] mm: replace mmap with vma write lock assertions when operating on a vma Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 4/6] mm: lock vma explicitly before doing vm_flags_reset and vm_flags_reset_once Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 5/6] mm: always lock new vma before inserting into vma tree Suren Baghdasaryan
2023-08-14 14:54   ` Jann Horn [this message]
2023-08-14 19:15     ` Andrew Morton
2023-08-14 19:19       ` Liam R. Howlett
2023-08-14 20:02       ` Jann Horn
2023-08-14 20:06         ` Suren Baghdasaryan
2023-08-04 15:27 ` [PATCH v4 6/6] mm: move vma locking out of vma_prepare and dup_anon_vma Suren Baghdasaryan

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=CAG48ez0XCXoXbSR6dyX7GUQYJKRFKQsHuye5q-PLU3-gR5of5A@mail.gmail.com \
    --to=jannh@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=dave@stgolabs.net \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hughd@google.com \
    --cc=jglisse@google.com \
    --cc=kernel-team@android.com \
    --cc=ldufour@linux.ibm.com \
    --cc=liam.howlett@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=michel@lespinasse.org \
    --cc=peterx@redhat.com \
    --cc=surenb@google.com \
    --cc=torvalds@linux-foundation.org \
    --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