damon_pa_de_activate() 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 LRU 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: 51a1ebd3a295 ("mm/damon/paddr: support addr_unit for DAMOS_LRU_[DE]PRIO") 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 a0a310e7bd80..ad6a6651ee77 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -385,14 +385,17 @@ static inline unsigned long damon_pa_de_activate( struct damos *s, bool activate, unsigned long *sz_filter_passed) { - phys_addr_t addr, applied = 0; + phys_addr_t addr, end, applied = 0; + unsigned long size; 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; } @@ -407,7 +410,9 @@ static inline unsigned long damon_pa_de_activate( folio_deactivate(folio); applied += folio_nr_pages(folio); 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); } s->last_applied = folio; -- 2.43.0