damon_pa_pageout() 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 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: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT") 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 d7e01f3fdcdb..a0a310e7bd80 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -319,7 +319,8 @@ static unsigned long damon_pa_pageout(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); bool install_young_filter = true; struct damos_filter *filter; @@ -342,11 +343,13 @@ static unsigned long damon_pa_pageout(struct damon_region *r, 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_monitor_folio(PHYS_PFN(addr)); if (folio && !folio_test_lru(folio)) goto put_folio; if (damon_pa_invalid_damos_folio(folio, s)) { - addr += PAGE_SIZE; + size = PAGE_SIZE; + addr = size < end - addr ? addr + size : end; continue; } @@ -364,7 +367,9 @@ static unsigned long damon_pa_pageout(struct damon_region *r, else 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); } if (install_young_filter) -- 2.43.0