* [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
@ 2026-12-04 6:36 ` Kyuwon Cho
2026-12-04 14:47 ` SJ Park
2026-12-04 6:36 ` [PATCH v2 2/4] mm/damon/paddr: prevent address wrap in LRU action walks Kyuwon Cho
` (3 subsequent siblings)
4 siblings, 1 reply; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 6:36 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 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 <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
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
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 6:36 ` [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
@ 2026-12-04 14:47 ` SJ Park
2026-12-04 14:53 ` SJ Park
2026-12-04 16:19 ` Kyuwon Cho
0 siblings, 2 replies; 13+ messages in thread
From: SJ Park @ 2026-12-04 14:47 UTC (permalink / raw)
To: Kyuwon Cho
Cc: SJ Park, Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
On Fri, 4 Dec 2026 15:36:56 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
> 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.
The v1 of this was describing the resulting user impact quite well. But
somehow it is dropped in v2. Please add a user impact description. Also,
walking the almost the entire physical address space is already bad. But I
think the worst scenario is that this could be even an infinite loop. Am I
correct? If so, maybe something like below could be added.
"""
Depending on to where the wrap makes the loop start from again, and the folio
status and sizes in the address range, the walk can be repeated multiple times.
In the worst case, it could be infinite.
As a result, kdamond pages out unexpectedly many memory and consume system
resource. Users cannot stop that since kdamond is busy and therefore don't
respond to DAMON sysfs user inputs.
The near-PHYS_ADDR_MAX end address region would be rare in real. But the
consequence is quite bad.
"""
>
> 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.
Now I think the 'end' calculation should be done out of the loop, if we will
use 'end' anyway. Read below for more details. So the last sentence could be
dropped.
>
> Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
> 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 | 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;
In the v1 of this, I objected calculating 'end' before the loop because it
looked unrelated optimization.
Now I understand 'end' is used here, to make the above line shorter and easy to
read. I agree it is a good decision. In this case, calculatiing 'end' before
the loop and reusing makes more sense. Let's do that as a part of this patch.
> 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
>
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 14:47 ` SJ Park
@ 2026-12-04 14:53 ` SJ Park
2026-12-04 15:36 ` Aveline Noir
2026-12-04 16:19 ` Kyuwon Cho
1 sibling, 1 reply; 13+ messages in thread
From: SJ Park @ 2026-12-04 14:53 UTC (permalink / raw)
To: SJ Park
Cc: Kyuwon Cho, Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
On Fri, 04 Dec 2026 06:47:57 -0800 SJ Park <sj@kernel.org> wrote:
> On Fri, 4 Dec 2026 15:36:56 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
>
> > 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.
>
> The v1 of this was describing the resulting user impact quite well. But
> somehow it is dropped in v2. Please add a user impact description. Also,
> walking the almost the entire physical address space is already bad. But I
> think the worst scenario is that this could be even an infinite loop. Am I
> correct? If so, maybe something like below could be added.
>
> """
> Depending on to where the wrap makes the loop start from again, and the folio
> status and sizes in the address range, the walk can be repeated multiple times.
> In the worst case, it could be infinite.
>
> As a result, kdamond pages out unexpectedly many memory and consume system
> resource. Users cannot stop that since kdamond is busy and therefore don't
> respond to DAMON sysfs user inputs.
>
> The near-PHYS_ADDR_MAX end address region would be rare in real. But the
> consequence is quite bad.
> """
>
> >
> > 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.
>
> Now I think the 'end' calculation should be done out of the loop, if we will
> use 'end' anyway. Read below for more details. So the last sentence could be
> dropped.
>
> >
> > Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
Also, seems this Fixes: is wrong. The issue has started before the commit,
isn't it?
Thanks,
SJ
> > 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 | 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;
>
> In the v1 of this, I objected calculating 'end' before the loop because it
> looked unrelated optimization.
>
> Now I understand 'end' is used here, to make the above line shorter and easy to
> read. I agree it is a good decision. In this case, calculatiing 'end' before
> the loop and reusing makes more sense. Let's do that as a part of this patch.
>
> > 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
> >
> >
>
>
> Thanks,
> SJ
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 14:53 ` SJ Park
@ 2026-12-04 15:36 ` Aveline Noir
2026-12-04 16:20 ` Kyuwon Cho
0 siblings, 1 reply; 13+ messages in thread
From: Aveline Noir @ 2026-12-04 15:36 UTC (permalink / raw)
To: SJ Park
Cc: Andrew Morton, damon, Kyuwon Cho, linux-mm, sashiko-bot,
sashiko-reviews, Quanmin Yan
Hi SJ and Kyuwon,
On Fri, 04 Dec 2026 06:53:04 -0800 SJ Park wrote:
> Also, seems this Fixes: is wrong. The issue has started before the
> commit, isn't it?
I thought maybe this is the right tag.
Fixes: 57223ac29584 ("mm/damon/paddr: support the pageout scheme")
The original pageout loop already advanced an unsigned long cursor by
PAGE_SIZE. v5.16's debugfs init_regions kept the supplied end address as
is, so the cursor could wrap even before addr_unit support. What do you
think?
Thanks,
Aveline Noir
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 15:36 ` Aveline Noir
@ 2026-12-04 16:20 ` Kyuwon Cho
0 siblings, 0 replies; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 16:20 UTC (permalink / raw)
To: Aveline Noir
Cc: SJ Park, Andrew Morton, damon, linux-mm, sashiko-bot,
sashiko-reviews, Quanmin Yan
Hi Aveline,
> Fixes: 57223ac29584 ("mm/damon/paddr: support the pageout scheme")
>
> The original pageout loop already advanced an unsigned long cursor by
> PAGE_SIZE. v5.16's debugfs init_regions kept the supplied end address
> as is, so the cursor could wrap even before addr_unit support.
Agreed. Thank you for checking this. SJ is right that the previous tag
was too new, and 57223ac29584 matches what we found for patch 1/4.
For the other patches, the origins are:
- 8cdcc532268d ("mm/damon/schemes: add 'LRU_PRIO' DAMOS action")
introduced the earliest affected LRU loop in the shared walk's
lineage.
- b51820ebea65 ("mm/damon/paddr: introduce DAMOS_MIGRATE_COLD action for
demotion") introduced the migration loop with a PAGE_SIZE advance.
- c0cb9d91bf29 ("mm/damon/paddr: report filter-passed bytes back for
DAMOS_STAT action") introduced the stat loop with a PAGE_SIZE advance.
I will use those four origins in v3.
Thanks,
Kyuwon
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks
2026-12-04 14:47 ` SJ Park
2026-12-04 14:53 ` SJ Park
@ 2026-12-04 16:19 ` Kyuwon Cho
1 sibling, 0 replies; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 16:19 UTC (permalink / raw)
To: SJ Park
Cc: Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
Hi SJ,
> Please add a user impact description. Also, walking the almost the
> entire physical address space is already bad. But I think the worst
> scenario is that this could be even an infinite loop. Am I correct?
Yes. With addr_unit=65535, for example, the region units convert as
follows:
281479271743488 * 65535 = 0xffffffffffff0000
281479271743489 * 65535 = 0xffffffffffffffff
The cursor starts page-aligned and remains page-aligned because both
PAGE_SIZE and folio-size advances are page multiples. It can never
reach the end in the final partial page. The final-page advance wraps
to zero, so the same walk repeats indefinitely. Other wrapping ends
cause one additional near-full walk and then stop.
This keeps kdamond busy, and a state=off write blocks in damon_stop().
I will restore your impact wording with the indefinite case included.
Here is a minimal root-only test. It needs a kernel with DAMON sysfs,
paddr, pageout, and addr_unit support.
cd /sys/kernel/mm/damon/admin/kdamonds
echo 1 > nr_kdamonds
echo 1 > 0/contexts/nr_contexts
cd 0/contexts/0
echo paddr > operations
echo 65535 > addr_unit
echo 1 > targets/nr_targets
echo 1 > targets/0/regions/nr_regions
# one unit: [0xffffffffffff0000, 0xffffffffffffffff) in bytes
echo 281479271743488 > targets/0/regions/0/start
echo 281479271743489 > targets/0/regions/0/end
echo 1 > schemes/nr_schemes
echo pageout > schemes/0/action
echo 18446744073709551615 > schemes/0/access_pattern/sz/max
echo 4294967295 > schemes/0/access_pattern/nr_accesses/max
echo 4294967295 > schemes/0/access_pattern/age/max
echo on > ../../state
sleep 2
echo off > ../../state # never returns
Without the fix, the last write never returns. With the change I
describe below applied, it returns right away.
> In this case, calculatiing 'end' before the loop and reusing makes
> more sense. Let's do that as a part of this patch.
Agreed. I will calculate end once before each loop and reuse it for the
loop condition and the saturated advances.
Thanks,
Kyuwon
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 2/4] mm/damon/paddr: prevent address wrap in LRU action walks
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
@ 2026-12-04 6:36 ` Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 3/4] mm/damon/paddr: prevent address wrap in migration walks Kyuwon Cho
` (2 subsequent siblings)
4 siblings, 0 replies; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 6:36 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 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 <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
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
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v2 3/4] mm/damon/paddr: prevent address wrap in migration walks
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 1/4] mm/damon/paddr: prevent address wrap in pageout walks Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 2/4] mm/damon/paddr: prevent address wrap in LRU action walks Kyuwon Cho
@ 2026-12-04 6:36 ` Kyuwon Cho
2026-12-04 6:36 ` [PATCH v2 4/4] mm/damon/paddr: prevent address wrap in stat walks Kyuwon Cho
2026-12-04 15:17 ` [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks SJ Park
4 siblings, 0 replies; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 6:36 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 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 <sj@kernel.org>
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
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
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v2 4/4] mm/damon/paddr: prevent address wrap in stat walks
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
` (2 preceding siblings ...)
2026-12-04 6:36 ` [PATCH v2 3/4] mm/damon/paddr: prevent address wrap in migration walks Kyuwon Cho
@ 2026-12-04 6:36 ` Kyuwon Cho
2026-12-04 15:17 ` [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks SJ Park
4 siblings, 0 replies; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 6:36 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 and make the stat 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: 01e7ee33a0ca ("mm/damon/paddr: support addr_unit for DAMOS_STAT")
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 | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 9b57f5e9cf63..23a8315532b7 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -480,7 +480,8 @@ 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))
@@ -488,15 +489,19 @@ static unsigned long damon_pa_stat(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_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] 13+ messages in thread* Re: [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks
2026-12-04 6:36 [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
` (3 preceding siblings ...)
2026-12-04 6:36 ` [PATCH v2 4/4] mm/damon/paddr: prevent address wrap in stat walks Kyuwon Cho
@ 2026-12-04 15:17 ` SJ Park
2026-12-04 16:22 ` Kyuwon Cho
4 siblings, 1 reply; 13+ messages in thread
From: SJ Park @ 2026-12-04 15:17 UTC (permalink / raw)
To: Kyuwon Cho
Cc: SJ Park, Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
Hello Kyuwon,
Thank you for revisioning. But, from the next time, please don't post a new
version of a patch without ensuring the discussions on the previous version is
completed. Please reply to all comments unless it is clearly there is nothing
to reply, and share your next version posting plan. Then wait a sufficient
time to ensure no person object to the plan.
On Fri, 4 Dec 2026 15:36:55 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
> The four physical-address DAMOS action walks can wrap their cursor near
> PHYS_ADDR_MAX and then scan almost the entire physical address space.
Please mention this is not just one more time iteration, but could be
indefinite times repeat.
> Split the fixes by introducing commit so each can be backported
> independently. Each patch open-codes the saturating advance requested by
> SJ Park and carries its own Fixes and stable tags.
>
> The conversion-hoisting optimization from v1 is posted separately and is
> not marked for stable.
I now think the optimization is better to be made together with this series. I
left details about that and more comments to patch 1. Most of the comments
also be applied to other patches of this series. Please read and reply.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 13+ messages in thread* Re: [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks
2026-12-04 15:17 ` [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks SJ Park
@ 2026-12-04 16:22 ` Kyuwon Cho
2026-12-04 17:13 ` SJ Park
0 siblings, 1 reply; 13+ messages in thread
From: Kyuwon Cho @ 2026-12-04 16:22 UTC (permalink / raw)
To: SJ Park
Cc: Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
Hi SJ,
> Please mention this is not just one more time iteration, but could be
> indefinite times repeat.
>
> I now think the optimization is better to be made together with this
> series.
For v3, I plan to:
- hoist each converted end before its loop in all four patches;
- saturate both PAGE_SIZE and folio-size advances at that end;
- restore the impact text, including the indefinite repeat, in the cover
letter and each patch;
- correct each patch's Fixes tag and keep its stable Cc; and
- fold the endpoint optimization into the fixes.
I will post v3 after you and the other recipients have had time to
object to this plan.
Thanks,
Kyuwon
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/4] mm/damon/paddr: prevent address wrap in action walks
2026-12-04 16:22 ` Kyuwon Cho
@ 2026-12-04 17:13 ` SJ Park
0 siblings, 0 replies; 13+ messages in thread
From: SJ Park @ 2026-12-04 17:13 UTC (permalink / raw)
To: Kyuwon Cho
Cc: SJ Park, Andrew Morton, Quanmin Yan, Aveline Noir, sashiko-bot,
sashiko-reviews, damon, linux-mm
On Sat, 05 Dec 2026 01:22:20 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
> Hi SJ,
>
> > Please mention this is not just one more time iteration, but could be
> > indefinite times repeat.
> >
> > I now think the optimization is better to be made together with this
> > series.
>
> For v3, I plan to:
>
> - hoist each converted end before its loop in all four patches;
> - saturate both PAGE_SIZE and folio-size advances at that end;
> - restore the impact text, including the indefinite repeat, in the cover
> letter and each patch;
> - correct each patch's Fixes tag and keep its stable Cc; and
> - fold the endpoint optimization into the fixes.
>
> I will post v3 after you and the other recipients have had time to
> object to this plan.
Looks good to me.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 13+ messages in thread