damon_pa_migrate() advances its cursor by PAGE_SIZE or the current folio size. If the physical end of a region is near PHYS_ADDR_MAX, either addition can wrap the cursor to zero and make the migration action walk almost the entire physical address space. Saturate each advance at the converted region end. Calculate the end in the loop for now so this stable fix does not depend on the separate change that hoists the conversion out of the loop. Fixes: ec1d5bab0689 ("mm/damon/paddr: support addr_unit for MIGRATE_{HOT,COLD}") Cc: stable@vger.kernel.org Suggested-by: SJ Park Signed-off-by: Kyuwon Cho --- mm/damon/paddr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index ad6a6651ee77..9b57f5e9cf63 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -437,15 +437,18 @@ static unsigned long damon_pa_migrate(struct damon_region *r, unsigned long addr_unit, struct damos *s, unsigned long *sz_filter_passed) { - phys_addr_t addr, applied; + phys_addr_t addr, end, applied; + unsigned long size; LIST_HEAD(folio_list); struct folio *folio = NULL; addr = damon_pa_phys_addr(r->ar.start, addr_unit); while (addr < damon_pa_phys_addr(r->ar.end, addr_unit)) { + end = damon_pa_phys_addr(r->ar.end, addr_unit); folio = damon_get_folio(PHYS_PFN(addr)); if (damon_pa_invalid_damos_folio(folio, s)) { - addr += PAGE_SIZE; + size = PAGE_SIZE; + addr = size < end - addr ? addr + size : end; continue; } @@ -462,7 +465,9 @@ static unsigned long damon_pa_migrate(struct damon_region *r, folio_is_file_lru(folio)); list_add(&folio->lru, &folio_list); put_folio: - addr = PFN_PHYS(folio_pfn(folio)) + folio_size(folio); + addr = PFN_PHYS(folio_pfn(folio)); + size = folio_size(folio); + addr = size < end - addr ? addr + size : end; folio_put(folio); } applied = damon_migrate_pages(&folio_list, s->target_nid); -- 2.43.0