* [PATCH v3 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-05 1:52 [PATCH v3 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
@ 2026-12-05 1:52 ` Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 2/4] mm/damon/paddr: prevent address wrap in LRU action walks Kyuwon Cho
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Kyuwon Cho @ 2026-12-05 1:52 UTC (permalink / raw)
To: SJ Park, Andrew Morton
Cc: Quanmin Yan, Aveline Noir, sashiko-bot, sashiko-reviews, damon,
linux-mm
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.
Depending on where the wrap makes the loop restart, and on the folio
states and sizes in the address range, the walk can repeat multiple times.
In the worst case, it can be infinite.
As a result, kdamond can page out unexpectedly much memory and consume
system resources. Users cannot stop it because the busy kdamond does not
respond to DAMON sysfs input. Regions ending near PHYS_ADDR_MAX are rare
in practice, but the consequence is severe.
Calculate the converted end once before the loop and saturate each advance
at that end.
Fixes: 57223ac29584 ("mm/damon/paddr: support the pageout scheme")
Cc: stable@vger.kernel.org
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
mm/damon/paddr.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index d7e01f3fdcdb..dc7618faec43 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;
@@ -341,12 +342,14 @@ 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);
+ while (addr < end) {
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 2/4] mm/damon/paddr: prevent address wrap in LRU action walks
2026-12-05 1:52 [PATCH v3 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
@ 2026-12-05 1:52 ` Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 3/4] mm/damon/paddr: prevent address wrap in migration walks Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 4/4] mm/damon/paddr: prevent address wrap in stat walks Kyuwon Cho
3 siblings, 0 replies; 5+ messages in thread
From: Kyuwon Cho @ 2026-12-05 1:52 UTC (permalink / raw)
To: SJ Park, Andrew Morton
Cc: Quanmin Yan, Aveline Noir, sashiko-bot, sashiko-reviews, damon,
linux-mm
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.
Depending on where the wrap makes the loop restart, and on the folio
states and sizes in the address range, the walk can repeat multiple times.
In the worst case, it can be infinite.
As a result, kdamond can activate or deactivate unexpectedly many folios
and consume system resources. Users cannot stop it because the busy
kdamond does not respond to DAMON sysfs input. Regions ending near
PHYS_ADDR_MAX are rare in practice, but the consequence is severe.
Calculate the converted end once before the loop and saturate each advance
at that end.
Fixes: 8cdcc532268d ("mm/damon/schemes: add 'LRU_PRIO' DAMOS action")
Cc: stable@vger.kernel.org
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
mm/damon/paddr.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index dc7618faec43..a90ac8ad9043 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);
+ while (addr < end) {
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 3/4] mm/damon/paddr: prevent address wrap in migration walks
2026-12-05 1:52 [PATCH v3 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 2/4] mm/damon/paddr: prevent address wrap in LRU action walks Kyuwon Cho
@ 2026-12-05 1:52 ` Kyuwon Cho
2026-12-05 1:52 ` [PATCH v3 4/4] mm/damon/paddr: prevent address wrap in stat walks Kyuwon Cho
3 siblings, 0 replies; 5+ messages in thread
From: Kyuwon Cho @ 2026-12-05 1:52 UTC (permalink / raw)
To: SJ Park, Andrew Morton
Cc: Quanmin Yan, Aveline Noir, sashiko-bot, sashiko-reviews, damon,
linux-mm
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.
Depending on where the wrap makes the loop restart, and on the folio
states and sizes in the address range, the walk can repeat multiple times.
In the worst case, it can be infinite.
As a result, kdamond can migrate unexpectedly much memory and consume
system resources. Users cannot stop it because the busy kdamond does not
respond to DAMON sysfs input. Regions ending near PHYS_ADDR_MAX are rare
in practice, but the consequence is severe.
Calculate the converted end once before the loop and saturate each advance
at that end.
Fixes: b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for demotion")
Cc: stable@vger.kernel.org
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
mm/damon/paddr.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index a90ac8ad9043..0962a246cc2d 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);
+ while (addr < end) {
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v3 4/4] mm/damon/paddr: prevent address wrap in stat walks
2026-12-05 1:52 [PATCH v3 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
` (2 preceding siblings ...)
2026-12-05 1:52 ` [PATCH v3 3/4] mm/damon/paddr: prevent address wrap in migration walks Kyuwon Cho
@ 2026-12-05 1:52 ` Kyuwon Cho
3 siblings, 0 replies; 5+ messages in thread
From: Kyuwon Cho @ 2026-12-05 1:52 UTC (permalink / raw)
To: SJ Park, Andrew Morton
Cc: Quanmin Yan, Aveline Noir, sashiko-bot, sashiko-reviews, damon,
linux-mm
damon_pa_stat() 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.
Depending on where the wrap makes the loop restart, and on the folio
states and sizes in the address range, the walk can repeat multiple times.
In the worst case, it can be infinite.
As a result, kdamond can consume CPU and system resources indefinitely
while accounting filter statistics. Users cannot stop it because the
busy kdamond does not respond to DAMON sysfs input. Regions ending near
PHYS_ADDR_MAX are rare in practice, but the consequence is severe.
Calculate the converted end once before the loop and saturate each advance
at that end.
Fixes: c0cb9d91bf29 ("mm/damon/paddr: report filter-passed bytes back for DAMOS_STAT action")
Cc: stable@vger.kernel.org
Suggested-by: SJ Park <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
mm/damon/paddr.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 0962a246cc2d..f18bbb808f3c 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -480,23 +480,28 @@ static unsigned long damon_pa_stat(struct damon_region *r,
unsigned long addr_unit, struct damos *s,
unsigned long *sz_filter_passed)
{
- phys_addr_t addr;
+ phys_addr_t addr, end;
+ unsigned long size;
struct folio *folio = NULL;
if (!damos_ops_has_filter(s))
return 0;
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);
+ while (addr < end) {
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;
}
if (!damos_pa_filter_out(s, folio))
*sz_filter_passed += folio_size(folio) / addr_unit;
- 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
^ permalink raw reply related [flat|nested] 5+ messages in thread