linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
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 1/2] mm: lock a vma before stack expansion
Date: Thu,  6 Jul 2023 21:32:10 -0700	[thread overview]
Message-ID: <20230707043211.3682710-1-surenb@google.com> (raw)

With recent changes necessitating mmap_lock to be held for write while
expanding a stack, per-VMA locks should follow the same rules and be
write-locked to prevent page faults into the VMA being expanded. Add
the necessary locking.

Signed-off-by: Suren Baghdasaryan <surenb@google.com>
---
 mm/mmap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index 204ddcd52625..c66e4622a557 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1977,6 +1977,8 @@ static int expand_upwards(struct vm_area_struct *vma, unsigned long address)
 		return -ENOMEM;
 	}
 
+	/* Lock the VMA before expanding to prevent concurrent page faults */
+	vma_start_write(vma);
 	/*
 	 * vma->vm_start/vm_end cannot change under us because the caller
 	 * is required to hold the mmap_lock in read mode.  We need the
@@ -2064,6 +2066,8 @@ int expand_downwards(struct vm_area_struct *vma, unsigned long address)
 		return -ENOMEM;
 	}
 
+	/* Lock the VMA before expanding to prevent concurrent page faults */
+	vma_start_write(vma);
 	/*
 	 * vma->vm_start/vm_end cannot change under us because the caller
 	 * is required to hold the mmap_lock in read mode.  We need the
-- 
2.41.0.255.g8b1d071c50-goog



             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 Suren Baghdasaryan [this message]
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
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-1-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