From: Suren Baghdasaryan <surenb@google.com>
To: akpm@linux-foundation.org
Cc: willy@infradead.org, liam.howlett@oracle.com, 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,
surenb@google.com
Subject: [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible
Date: Thu, 6 Jul 2023 21:32:11 -0700 [thread overview]
Message-ID: <20230707043211.3682710-2-surenb@google.com> (raw)
In-Reply-To: <20230707043211.3682710-1-surenb@google.com>
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 */
+ vma_start_write(vma);
vma_iter_store(&vmi, vma);
mm->map_count++;
if (vma->vm_file) {
--
2.41.0.255.g8b1d071c50-goog
next prev parent reply other threads:[~2023-07-07 4:32 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 ` Suren Baghdasaryan [this message]
2023-07-07 19:48 ` [PATCH 2/2] mm: lock newly mapped VMA which can be modified after it becomes visible Liam R. Howlett
2023-07-07 20:15 ` Suren Baghdasaryan
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=20230707043211.3682710-2-surenb@google.com \
--to=surenb@google.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=liam.howlett@oracle.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