All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Xinhai <lixinhai.lxh@gmail.com>
To: linux-mm@kvack.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
	Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>,
	Hugh Dickins <hughd@google.com>,
	linux-man <linux-man@vger.kernel.org>
Subject: [PATCH v4 1/2] mm: Check range first in queue_pages_test_walk
Date: Fri,  8 Nov 2019 21:01:43 +0800	[thread overview]
Message-ID: <1573218104-11021-2-git-send-email-lixinhai.lxh@gmail.com> (raw)
In-Reply-To: <1573218104-11021-1-git-send-email-lixinhai.lxh@gmail.com>

Checking unmapped hole and updating the previous vma must be handled first,
otherwise the unmapped hole could be calculated from a wrong previous vma.

Several commits were relevant to this error:
commit 6f4576e3687b
("mempolicy: apply page table walker on queue_pages_range()"),
This commit was correct, the VM_PFNMAP check was after updateing previous
vma

commit 48684a65b4e3
(mm: pagewalk: fix misbehavior of walk_page_range for vma(VM_PFNMAP)),
This commit added VM_PFNMAP check before updateing previous vma. Then,
there were two VM_PFNMAP check did same thing twice.

commit acda0c334028
(mm/mempolicy.c: get rid of duplicated check for vma(VM_PFNMAP) in queue_page
s_range()),
This commit tried to fix the duplicated VM_PFNMAP check, but it wrongly
removed the one which was after updateing vma.

Fixes: acda0c334028 (mm/mempolicy.c: get rid of duplicated check for vma(VM_PFNMAP) in queue_page
s_range())
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Hugh Dickins <hughd@google.com>
Cc: linux-man <linux-man@vger.kernel.org>
Signed-off-by: Li Xinhai <lixinhai.lxh@gmail.com>
---
 mm/mempolicy.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 4ae967b..807f06f 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -618,6 +618,16 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
 	unsigned long endvma = vma->vm_end;
 	unsigned long flags = qp->flags;
 
+	/* range check first */
+	if (!(flags & MPOL_MF_DISCONTIG_OK)) {
+		if (!vma->vm_next && vma->vm_end < end)
+			return -EFAULT;
+		if (qp->prev && qp->prev->vm_end < vma->vm_start)
+			return -EFAULT;
+	}
+
+	qp->prev = vma;
+
 	/*
 	 * Need check MPOL_MF_STRICT to return -EIO if possible
 	 * regardless of vma_migratable
@@ -631,15 +641,6 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end,
 	if (vma->vm_start > start)
 		start = vma->vm_start;
 
-	if (!(flags & MPOL_MF_DISCONTIG_OK)) {
-		if (!vma->vm_next && vma->vm_end < end)
-			return -EFAULT;
-		if (qp->prev && qp->prev->vm_end < vma->vm_start)
-			return -EFAULT;
-	}
-
-	qp->prev = vma;
-
 	if (flags & MPOL_MF_LAZY) {
 		/* Similar to task_numa_work, skip inaccessible VMAs */
 		if (!is_vm_hugetlb_page(vma) &&
-- 
1.8.3.1


  reply	other threads:[~2019-11-08 13:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08 13:01 [PATCH v4 0/2] mm: Fix checking unmapped holes for mbind Li Xinhai
2019-11-08 13:01 ` Li Xinhai [this message]
2019-11-14  9:35   ` [PATCH v4 1/2] mm: Check range first in queue_pages_test_walk Naoya Horiguchi
2019-11-08 13:01 ` [PATCH v4 2/2] mm: Fix checking unmapped holes for mbind Li Xinhai
2019-11-14  9:30   ` Naoya Horiguchi
2019-11-15 15:33     ` lixinhai.lxh
2019-11-15 15:33       ` lixinhai.lxh

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=1573218104-11021-2-git-send-email-lixinhai.lxh@gmail.com \
    --to=lixinhai.lxh@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-man@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=vbabka@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.