Skip to contentSkip to conversation

mm-mempolicy-fix-the-wrong-return-value-and-potential-pages-leak-of-mbind.patch removed from -mm tree

merged [email protected] 1 participant 1 message Nov 21, 2019 Stable branch

lore
Share & tools
lore

[email protected]

author tree notice Applied
#0 lore raw

The patch titled
Subject: mm: mempolicy: fix the wrong return value and potential pages leak of mbind
has been removed from the -mm tree. Its filename was
mm-mempolicy-fix-the-wrong-return-value-and-potential-pages-leak-of-mbind.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Yang Shi <[email protected]>
Subject: mm: mempolicy: fix the wrong return value and potential pages leak of mbind

Commit d883544515aa ("mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified") fixed the return value of mbind() for a couple of corner cases. But, it altered the errno for some other cases, for example, mbind() should return -EFAULT when part or all of the memory range specified by nodemask and maxnode points outside your accessible address space, or there was an unmapped hole in the specified memory range specified by addr and len.

Fix this by preserving the errno returned by queue_pages_range(). And, the pagelist may be not empty even though queue_pages_range() returns error, put the pages back to LRU since mbind_range() is not called to really apply the policy so those pages should not be migrated, this is also the old behavior before the problematic commit.

Fixes d883544515aa ("mm: mempolicy: make the behavior consistent when MPOL_MF_MOVE* and MPOL_MF_STRICT were specified")
Cc Vlastimil Babka <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mel Gorman <[email protected]>
Cc <[email protected]> [4.19 and 5.2+]

---

 mm/mempolicy.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
mm/mempolicy.c renamed from mm/mempolicy.c~mm-mempolicy-fix-the-wrong-return-value-and-potential-pages-leak-of-mbind +9 -5
@@ -672,7 +672,9 @@ static const struct mm_walk_ops queue_pa
  * 1 - there is unmovable page, but MPOL_MF_MOVE* & MPOL_MF_STRICT were
  *     specified.
  * 0 - queue pages successfully or no misplaced page.
- * -EIO - there is misplaced page and only MPOL_MF_STRICT was specified.
+ * errno - i.e. misplaced pages with MPOL_MF_STRICT specified (-EIO) or
+ *         memory range specified by nodemask and maxnode points outside
+ *         your accessible address space (-EFAULT)
  */
 static int
 queue_pages_range(struct mm_struct *mm, unsigned long start, unsigned long end,
@@ -1286,7 +1288,7 @@ static long do_mbind(unsigned long start
 			  flags | MPOL_MF_INVERT, &pagelist);
 
 	if (ret < 0) {
-		err = -EIO;
+		err = ret;
 		goto up_out;
 	}
 
@@ -1305,10 +1307,12 @@ static long do_mbind(unsigned long start
 
 		if ((ret > 0) || (nr_failed && (flags & MPOL_MF_STRICT)))
 			err = -EIO;
-	} else
-		putback_movable_pages(&pagelist);
-
+	} else {
 up_out:
+		if (!list_empty(&pagelist))
+			putback_movable_pages(&pagelist);
+	}
+
 	up_write(&mm->mmap_sem);
 mpol_out:
 	mpol_put(new);

_

Patches currently in -mm which might be from [email protected] are

mm-rmap-use-vm_bug_on_page-in-__page_check_anon_rmap.patch mm-vmscan-remove-unused-scan_control-parameter-from-pageout.patch mm-migrate-handle-freed-page-at-the-first-place.patch mm-shmem-use-proper-gfp-flags-for-shmem_writepage.patch