Yang Shi 24526268f4 mm: mempolicy: keep VMA walk if both MPOL_MF_STRICT and MPOL_MF_MOVE are specified
When calling mbind() with MPOL_MF_{MOVE|MOVEALL} | MPOL_MF_STRICT, kernel
should attempt to migrate all existing pages, and return -EIO if there is
misplaced or unmovable page.  Then commit 6f4576e3687b ("mempolicy: apply
page table walker on queue_pages_range()") messed up the return value and
didn't break VMA scan early ianymore when MPOL_MF_STRICT alone.  The
return value problem was fixed by commit a7f40cfe3b7a ("mm: mempolicy:
make mbind() return -EIO when MPOL_MF_STRICT is specified"), but it broke
the VMA walk early if unmovable page is met, it may cause some pages are
not migrated as expected.

The code should conceptually do:

 if (MPOL_MF_MOVE|MOVEALL)
     scan all vmas
     try to migrate the existing pages
     return success
 else if (MPOL_MF_MOVE* | MPOL_MF_STRICT)
     scan all vmas
     try to migrate the existing pages
     return -EIO if unmovable or migration failed
 else /* MPOL_MF_STRICT alone */
     break early if meets unmovable and don't call mbind_range() at all
 else /* none of those flags */
     check the ranges in test_walk, EFAULT without mbind_range() if discontig.

Fixed the behavior.

Link: https://lkml.kernel.org/r/20230920223242.3425775-1-yang@os.amperecomputing.com
Fixes: a7f40cfe3b7a ("mm: mempolicy: make mbind() return -EIO when MPOL_MF_STRICT is specified")
Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Rafael Aquini <aquini@redhat.com>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: David Rientjes <rientjes@google.com>
Cc: <stable@vger.kernel.org>	[4.9+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-09-29 17:20:48 -07:00
..
2023-09-08 12:16:52 -07:00
2023-08-29 20:32:10 -07:00
2023-06-09 16:25:17 -07:00
2023-07-24 18:04:30 -04:00
2023-08-31 12:20:12 -07:00
2023-06-19 16:19:25 -07:00
2023-08-31 12:20:12 -07:00
2023-08-31 12:20:12 -07:00
2023-04-12 17:36:23 -07:00
2023-08-31 12:20:12 -07:00
2023-08-31 12:20:12 -07:00
2022-10-03 14:02:43 -07:00
2023-08-31 12:20:12 -07:00
2022-09-26 19:46:09 -07:00
2023-08-31 12:20:12 -07:00
2023-08-31 12:20:12 -07:00
2023-08-29 20:32:10 -07:00
2023-07-18 10:07:47 +02:00
2023-07-18 10:07:47 +02:00
2023-07-14 09:57:21 +02:00
2023-06-23 16:59:30 -07:00
2023-04-12 17:36:23 -07:00
2023-08-31 12:20:12 -07:00
2023-09-05 10:13:45 -07:00