From: Nadav Amit <nadav.amit@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Peter Xu <peterx@redhat.com>, Nadav Amit <namit@vmware.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Minchan Kim <minchan@kernel.org>, Colin Cross <ccross@google.com>,
Suren Baghdasarya <surenb@google.com>,
Mike Rapoport <rppt@linux.vnet.ibm.com>
Subject: [RFC PATCH 1/8] mm/madvise: propagate vma->vm_end changes
Date: Sun, 26 Sep 2021 09:12:52 -0700 [thread overview]
Message-ID: <20210926161259.238054-2-namit@vmware.com> (raw)
In-Reply-To: <20210926161259.238054-1-namit@vmware.com>
From: Nadav Amit <namit@vmware.com>
The comment in madvise_dontneed_free() says that vma splits that occur
while the mmap-lock is dropped, during userfaultfd_remove(), should be
handled correctly, but nothing in the code indicates that it is so: prev
is invalidated, and do_madvise() will therefore continue to update VMAs
from the "obsolete" end (i.e., the one before the split).
Propagate the changes to end from madvise_dontneed_free() back to
do_madvise() and continue the updates from the new end accordingly.
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Colin Cross <ccross@google.com>
Cc: Suren Baghdasarya <surenb@google.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Fixes: 70ccb92fdd90 ("userfaultfd: non-cooperative: userfaultfd_remove revalidate vma in MADV_DONTNEED")
Signed-off-by: Nadav Amit <namit@vmware.com>
---
mm/madvise.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/mm/madvise.c b/mm/madvise.c
index 0734db8d53a7..a2b05352ebfe 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -768,10 +768,11 @@ static long madvise_dontneed_single_vma(struct vm_area_struct *vma,
static long madvise_dontneed_free(struct vm_area_struct *vma,
struct vm_area_struct **prev,
- unsigned long start, unsigned long end,
+ unsigned long start, unsigned long *pend,
int behavior)
{
struct mm_struct *mm = vma->vm_mm;
+ unsigned long end = *pend;
*prev = vma;
if (!can_madv_lru_vma(vma))
@@ -811,6 +812,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma,
* end-vma->vm_end range, but the manager can
* handle a repetition fine.
*/
+ *pend = end;
end = vma->vm_end;
}
VM_WARN_ON(start >= end);
@@ -980,8 +982,10 @@ static int madvise_inject_error(int behavior,
static long
madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
- unsigned long start, unsigned long end, int behavior)
+ unsigned long start, unsigned long *pend, int behavior)
{
+ unsigned long end = *pend;
+
switch (behavior) {
case MADV_REMOVE:
return madvise_remove(vma, prev, start, end);
@@ -993,7 +997,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
return madvise_pageout(vma, prev, start, end);
case MADV_FREE:
case MADV_DONTNEED:
- return madvise_dontneed_free(vma, prev, start, end, behavior);
+ return madvise_dontneed_free(vma, prev, start, pend, behavior);
case MADV_POPULATE_READ:
case MADV_POPULATE_WRITE:
return madvise_populate(vma, prev, start, end, behavior);
@@ -1199,7 +1203,7 @@ int do_madvise(struct mm_struct *mm, unsigned long start, size_t len_in, int beh
tmp = end;
/* Here vma->vm_start <= start < tmp <= (end|vma->vm_end). */
- error = madvise_vma(vma, &prev, start, tmp, behavior);
+ error = madvise_vma(vma, &prev, start, &tmp, behavior);
if (error)
goto out;
start = tmp;
--
2.25.1
next prev parent reply other threads:[~2021-09-26 23:44 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-26 16:12 [RFC PATCH 0/8] mm/madvise: support process_madvise(MADV_DONTNEED) Nadav Amit
2021-09-26 16:12 ` Nadav Amit [this message]
2021-09-27 9:08 ` [RFC PATCH 1/8] mm/madvise: propagate vma->vm_end changes Kirill A. Shutemov
2021-09-27 10:11 ` Nadav Amit
2021-09-27 11:55 ` Kirill A. Shutemov
2021-09-27 12:33 ` Nadav Amit
2021-09-27 12:45 ` Kirill A. Shutemov
2021-09-27 12:59 ` Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 2/8] mm/madvise: remove unnecessary check on madvise_dontneed_free() Nadav Amit
2021-09-27 9:11 ` Kirill A. Shutemov
2021-09-27 11:05 ` Nadav Amit
2021-09-27 12:19 ` Kirill A. Shutemov
2021-09-27 12:52 ` Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 3/8] mm/madvise: remove unnecessary checks on madvise_free_single_vma() Nadav Amit
2021-09-27 9:17 ` Kirill A. Shutemov
2021-09-27 9:24 ` Kirill A. Shutemov
2021-09-26 16:12 ` [RFC PATCH 4/8] mm/madvise: define madvise behavior in a struct Nadav Amit
2021-09-27 9:31 ` Kirill A. Shutemov
2021-09-27 10:31 ` Nadav Amit
2021-09-27 12:14 ` Kirill A. Shutemov
2021-09-27 20:36 ` Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 5/8] mm/madvise: perform certain operations once on process_madvise() Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 6/8] mm/madvise: more aggressive TLB batching Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 7/8] mm/madvise: deduplicate code in madvise_dontneed_free() Nadav Amit
2021-09-26 16:12 ` [RFC PATCH 8/8] mm/madvise: process_madvise(MADV_DONTNEED) Nadav Amit
2021-09-27 9:24 ` [RFC PATCH 0/8] mm/madvise: support process_madvise(MADV_DONTNEED) David Hildenbrand
2021-09-27 10:41 ` Nadav Amit
2021-09-27 10:58 ` David Hildenbrand
2021-09-27 12:00 ` Nadav Amit
2021-09-27 12:16 ` Michal Hocko
2021-09-27 19:12 ` Nadav Amit
2021-09-29 7:52 ` Michal Hocko
2021-09-29 18:31 ` Nadav Amit
2021-10-12 23:14 ` Peter Xu
2021-10-13 15:47 ` Nadav Amit
2021-10-13 23:09 ` Peter Xu
2021-09-27 17:05 ` David Hildenbrand
2021-09-27 19:59 ` Nadav Amit
2021-09-28 8:53 ` David Hildenbrand
2021-09-28 22:56 ` Nadav Amit
2021-10-04 17:58 ` David Hildenbrand
2021-10-07 16:19 ` Nadav Amit
2021-10-07 16:46 ` David Hildenbrand
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=20210926161259.238054-2-namit@vmware.com \
--to=nadav.amit@gmail.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ccross@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=namit@vmware.com \
--cc=peterx@redhat.com \
--cc=rppt@linux.vnet.ibm.com \
--cc=surenb@google.com \
/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;
as well as URLs for NNTP newsgroup(s).