diff mbox series

[v4,1/2] mm: Check range first in queue_pages_test_walk

Message ID 1573218104-11021-2-git-send-email-lixinhai.lxh@gmail.com (mailing list archive)
State New, archived
Headers show
Series mm: Fix checking unmapped holes for mbind | expand

Commit Message

Li Xinhai Nov. 8, 2019, 1:01 p.m. UTC
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(-)

Comments

Naoya Horiguchi Nov. 14, 2019, 9:35 a.m. UTC | #1
On Fri, Nov 08, 2019 at 09:01:43PM +0800, Li Xinhai wrote:
> 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>

Reviewed-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
diff mbox series

Patch

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) &&