[PATCH] fix syzbot reports

From: Lorenzo Stoakes
Date: Tue Jun 17 2025 - 15:56:25 EST


Use folio_trylock() to resolve
https://lore.kernel.org/all/aFEAPOozHsR1/PLI@ly-workstation/ and balance
lock/unlock in move_pgt_entry() to fix
https://lore.kernel.org/all/68512333.a70a0220.395abc.0205.GAE@xxxxxxxxxx/

Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
---
mm/mremap.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/mm/mremap.c b/mm/mremap.c
index 2da064f8c898..a4ec69959fc7 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -601,12 +601,12 @@ static bool move_pgt_entry(struct pagetable_move_control *pmc,

if (!pmc->need_rmap_locks && should_take_rmap_locks(entry)) {
override_locks = true;
-
pmc->need_rmap_locks = true;
- /* See comment in move_ptes() */
- maybe_take_rmap_locks(pmc);
}

+ /* See comment in move_ptes() */
+ maybe_take_rmap_locks(pmc);
+
switch (entry) {
case NORMAL_PMD:
moved = move_normal_pmd(pmc, old_entry, new_entry);
@@ -824,7 +824,8 @@ static unsigned long relocate_anon_pte(struct pagetable_move_control *pmc,
if (!folio)
return ret;

- folio_lock(folio);
+ if (!folio_trylock(folio))
+ return 0;

/* No-op. */
if (!folio_test_anon(folio) || folio_test_ksm(folio))
--
2.49.0