]> www.infradead.org Git - users/jedix/linux-maple.git/commit
mm: gup: fix infinite loop within __get_longterm_locked
authorZhaoyang Huang <zhaoyang.huang@unisoc.com>
Tue, 21 Jan 2025 02:01:59 +0000 (10:01 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 26 Jan 2025 23:05:01 +0000 (15:05 -0800)
commit6c58bace5a58c3d7a469eb4c2f9966f4f5304e47
treeb98595324abacc2a511fdd08f27b4d086a805898
parent906dad76cc54495822d78cca6277ab83c4b7308f
mm: gup: fix infinite loop within __get_longterm_locked

We can run into an infinite loop in __get_longterm_locked() when
collect_longterm_unpinnable_folios() finds only folios that are isolated
from the LRU or were never added to the LRU.  This can happen when all
folios to be pinned are never added to the LRU, for example when
vm_ops->fault allocated pages using cma_alloc() and never added them to
the LRU.

We incorrectly update the "collected" variable even if nothing was
collected.  Fix it by incrementing "collected" only when we isolated a
folio and added it to the list of folios to migrate.

Link: https://lkml.kernel.org/r/20250121020159.3636477-1-zhaoyang.huang@unisoc.com
Fixes: 67e139b02d99 ("mm/gup.c: refactor check_and_migrate_movable_pages()")
Signed-off-by: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
Reviewed-by: John Hubbard <jhubbard@nvidia.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Suggested-by: David Hildenbrand <david@redhat.com>
Cc: Aijun Sun <aijun.sun@unisoc.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/gup.c