* [PATCH] mm/damon/paddr: prevent address wrap in action walks
@ 2026-12-03 16:43 Kyuwon Cho
2026-12-03 17:38 ` Aveline Noir
2026-12-04 1:53 ` SJ Park
0 siblings, 2 replies; 5+ messages in thread
From: Kyuwon Cho @ 2026-12-03 16:43 UTC (permalink / raw)
To: SJ Park, Andrew Morton; +Cc: Quanmin Yan, damon, linux-mm
The physical-address DAMOS action loops advance their cursor by PAGE_SIZE
or folio_size(). A region whose converted end is near the maximum
physical address can make that addition wrap to zero. The loop condition
remains true and the DAMON worker scans almost the entire physical address
domain. Control operations such as damon_stop() then cannot complete:
INFO: task test:117 blocked for more than 10 seconds.
Call Trace:
__schedule (kernel/sched/core.c:7437)
schedule (kernel/sched/core.c:7529)
schedule_timeout (kernel/time/sleep_timeout.c:75)
wait_for_completion (kernel/sched/completion.c:153)
kthread_stop (kernel/kthread.c:760)
kthread_stop_put (kernel/kthread.c:781)
damon_stop (mm/damon/core.c:2207)
kernfs_fop_write_iter (fs/kernfs/file.c:345)
Calculate each converted end once and saturate every page or folio advance
at that end. Apply the same cursor handling to pageout, LRU deactivation,
migration, and stat actions because all four use the same open-ended
addition.
Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. The reproducer configures one paddr
region whose addr_unit conversion ends at PHYS_ADDR_MAX, starts a DAMOS
action, and requests that DAMON stop. With the patch the cursor reaches
the region end without wrapping and the stop request returns.
Found and tested on mainline fe6ff8d5d675 (v7.4-rc5); the patch is
against the DAMON next tree at 88b4c437ff4c.
mm/damon/paddr.c | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 2292f0d1aca9..cb67e0cd657d 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -36,6 +36,12 @@ static unsigned long damon_pa_core_addr(
return pa / addr_unit;
}
+static phys_addr_t damon_pa_next_addr(phys_addr_t addr, phys_addr_t end,
+ unsigned long size)
+{
+ return end - addr <= size ? end : addr + size;
+}
+
static void damon_pa_mkold(phys_addr_t paddr)
{
struct folio *folio = damon_get_monitor_folio(PHYS_PFN(paddr));
@@ -319,7 +325,7 @@ 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;
LIST_HEAD(folio_list);
bool install_young_filter = true;
struct damos_filter *filter;
@@ -341,12 +347,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);
+ 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;
+ addr = damon_pa_next_addr(addr, end, PAGE_SIZE);
continue;
}
@@ -364,7 +371,8 @@ 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 = damon_pa_next_addr(PFN_PHYS(folio_pfn(folio)), end,
+ folio_size(folio));
folio_put(folio);
}
if (install_young_filter)
@@ -380,14 +388,15 @@ 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;
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;
+ addr = damon_pa_next_addr(addr, end, PAGE_SIZE);
continue;
}
@@ -402,7 +411,8 @@ 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 = damon_pa_next_addr(PFN_PHYS(folio_pfn(folio)), end,
+ folio_size(folio));
folio_put(folio);
}
s->last_applied = folio;
@@ -427,15 +437,16 @@ 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;
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;
+ addr = damon_pa_next_addr(addr, end, PAGE_SIZE);
continue;
}
@@ -452,7 +463,8 @@ 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 = damon_pa_next_addr(PFN_PHYS(folio_pfn(folio)), end,
+ folio_size(folio));
folio_put(folio);
}
applied = damon_migrate_pages(&folio_list, s->target_nid);
@@ -465,23 +477,25 @@ 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;
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;
+ addr = damon_pa_next_addr(addr, end, PAGE_SIZE);
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 = damon_pa_next_addr(PFN_PHYS(folio_pfn(folio)), end,
+ folio_size(folio));
folio_put(folio);
}
s->last_applied = folio;
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] mm/damon/paddr: prevent address wrap in action walks
2026-12-03 16:43 [PATCH] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
@ 2026-12-03 17:38 ` Aveline Noir
2026-12-04 1:55 ` SJ Park
2026-12-04 1:53 ` SJ Park
1 sibling, 1 reply; 5+ messages in thread
From: Aveline Noir @ 2026-12-03 17:38 UTC (permalink / raw)
To: Kyuwon Cho
Cc: Andrew Morton, damon, linux-mm, sashiko-bot, sashiko-reviews,
SJ Park, Quanmin Yan
Hi Kyuwon,
On Fri, 04 Dec 2026 01:43:55 +0900 Kyuwon Cho wrote:
> A region whose converted end is near the maximum physical address can
> make that addition wrap to zero.
This looks hard to trigger, but the consequences could be pretty serious.
The code change itself looks good to me, and overall I think this fix is
worth having. SJ, what do you think?
Thanks,
Aveline Noir
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/paddr: prevent address wrap in action walks
2026-12-03 17:38 ` Aveline Noir
@ 2026-12-04 1:55 ` SJ Park
0 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-12-04 1:55 UTC (permalink / raw)
To: Aveline Noir
Cc: SJ Park, Kyuwon Cho, Andrew Morton, damon, linux-mm, sashiko-bot,
sashiko-reviews, Quanmin Yan
On Fri, 04 Dec 2026 04:38:23 +1100 Aveline Noir <jm5905938@gmail.com> wrote:
> Hi Kyuwon,
>
> On Fri, 04 Dec 2026 01:43:55 +0900 Kyuwon Cho wrote:
>
> > A region whose converted end is near the maximum physical address can
> > make that addition wrap to zero.
>
> This looks hard to trigger, but the consequences could be pretty serious.
> The code change itself looks good to me, and overall I think this fix is
> worth having. SJ, what do you think?
I agree the problem is better to be fixed, and deserve Cc: stable@. The patch
may have rooms to improve in my opinion, though. I added a few comments as a
reply.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/damon/paddr: prevent address wrap in action walks
2026-12-03 16:43 [PATCH] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-03 17:38 ` Aveline Noir
@ 2026-12-04 1:53 ` SJ Park
2026-12-04 2:26 ` SJ Park
1 sibling, 1 reply; 5+ messages in thread
From: SJ Park @ 2026-12-04 1:53 UTC (permalink / raw)
To: Kyuwon Cho; +Cc: SJ Park, Andrew Morton, Quanmin Yan, damon, linux-mm
Hello Kyuwon,
On Fri, 4 Dec 2026 01:43:55 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
> The physical-address DAMOS action loops advance their cursor by PAGE_SIZE
> or folio_size(). A region whose converted end is near the maximum
> physical address can make that addition wrap to zero. The loop condition
> remains true and the DAMON worker scans almost the entire physical address
> domain. Control operations such as damon_stop() then cannot complete:
>
> INFO: task test:117 blocked for more than 10 seconds.
> Call Trace:
> __schedule (kernel/sched/core.c:7437)
> schedule (kernel/sched/core.c:7529)
> schedule_timeout (kernel/time/sleep_timeout.c:75)
> wait_for_completion (kernel/sched/completion.c:153)
> kthread_stop (kernel/kthread.c:760)
> kthread_stop_put (kernel/kthread.c:781)
> damon_stop (mm/damon/core.c:2207)
> kernfs_fop_write_iter (fs/kernfs/file.c:345)
Thank you for finding and sharing this problem!
>
> Calculate each converted end once
I agree this is a good optimization. But not related to the abovely explained
problem. Hence shouldn't be a part of this patch, in my opinion. Please split
the change out to another patch, and post separately.
> and saturate every page or folio advance
> at that end.
Makes sense to me.
> Apply the same cursor handling to pageout, LRU deactivation,
> migration, and stat actions because all four use the same open-ended
> addition.
Doing these all in a single patch could make it difficult to backport on
certain stable kernels. Could you please find 'Fixes:' for each of the four
uses, and make patches for the each fix?
>
> Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
I think the fix patches would deserve Cc: stable@.
> Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
> ---
> The issue was found by an LLM-guided test generator that we are
> developing as a research prototype. The reproducer configures one paddr
> region whose addr_unit conversion ends at PHYS_ADDR_MAX, starts a DAMOS
> action, and requests that DAMON stop. With the patch the cursor reaches
> the region end without wrapping and the stop request returns.
>
> Found and tested on mainline fe6ff8d5d675 (v7.4-rc5); the patch is
> against the DAMON next tree at 88b4c437ff4c.
>
> mm/damon/paddr.c | 46 ++++++++++++++++++++++++++++++----------------
> 1 file changed, 30 insertions(+), 16 deletions(-)
>
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 2292f0d1aca9..cb67e0cd657d 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -36,6 +36,12 @@ static unsigned long damon_pa_core_addr(
> return pa / addr_unit;
> }
>
> +static phys_addr_t damon_pa_next_addr(phys_addr_t addr, phys_addr_t end,
> + unsigned long size)
> +{
> + return end - addr <= size ? end : addr + size;
I'd prefer having safe case first. E.g.,
return addr < end - size ? addr + size : end;
Could you please use that?
Also, as the code looks intuitive, I don't really feel like this helper
function is needed. What do you think?
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] mm/damon/paddr: prevent address wrap in action walks
2026-12-04 1:53 ` SJ Park
@ 2026-12-04 2:26 ` SJ Park
0 siblings, 0 replies; 5+ messages in thread
From: SJ Park @ 2026-12-04 2:26 UTC (permalink / raw)
To: SJ Park; +Cc: Kyuwon Cho, Andrew Morton, Quanmin Yan, damon, linux-mm
On Thu, 3 Dec 2026 17:53:23 -0800 SJ Park <sj@kernel.org> wrote:
> Hello Kyuwon,
>
> On Fri, 4 Dec 2026 01:43:55 +0900 Kyuwon Cho <kyuwon.cho@skku.edu> wrote:
>
> > The physical-address DAMOS action loops advance their cursor by PAGE_SIZE
> > or folio_size(). A region whose converted end is near the maximum
> > physical address can make that addition wrap to zero. The loop condition
> > remains true and the DAMON worker scans almost the entire physical address
> > domain. Control operations such as damon_stop() then cannot complete:
> >
> > INFO: task test:117 blocked for more than 10 seconds.
> > Call Trace:
> > __schedule (kernel/sched/core.c:7437)
> > schedule (kernel/sched/core.c:7529)
> > schedule_timeout (kernel/time/sleep_timeout.c:75)
> > wait_for_completion (kernel/sched/completion.c:153)
> > kthread_stop (kernel/kthread.c:760)
> > kthread_stop_put (kernel/kthread.c:781)
> > damon_stop (mm/damon/core.c:2207)
> > kernfs_fop_write_iter (fs/kernfs/file.c:345)
>
> Thank you for finding and sharing this problem!
>
> >
> > Calculate each converted end once
>
> I agree this is a good optimization. But not related to the abovely explained
> problem. Hence shouldn't be a part of this patch, in my opinion. Please split
> the change out to another patch, and post separately.
>
> > and saturate every page or folio advance
> > at that end.
>
> Makes sense to me.
>
> > Apply the same cursor handling to pageout, LRU deactivation,
> > migration, and stat actions because all four use the same open-ended
> > addition.
>
> Doing these all in a single patch could make it difficult to backport on
> certain stable kernels. Could you please find 'Fixes:' for each of the four
> uses, and make patches for the each fix?
>
> >
> > Fixes: 85246435b249 ("mm/damon/paddr: support addr_unit for DAMOS_PAGEOUT")
>
> I think the fix patches would deserve Cc: stable@.
>
> > Signed-off-by: Kyuwon Cho <kyuwon.cho@skku.edu>
> > ---
> > The issue was found by an LLM-guided test generator that we are
> > developing as a research prototype. The reproducer configures one paddr
> > region whose addr_unit conversion ends at PHYS_ADDR_MAX, starts a DAMOS
> > action, and requests that DAMON stop. With the patch the cursor reaches
> > the region end without wrapping and the stop request returns.
> >
> > Found and tested on mainline fe6ff8d5d675 (v7.4-rc5); the patch is
> > against the DAMON next tree at 88b4c437ff4c.
> >
> > mm/damon/paddr.c | 46 ++++++++++++++++++++++++++++++----------------
> > 1 file changed, 30 insertions(+), 16 deletions(-)
> >
> > diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> > index 2292f0d1aca9..cb67e0cd657d 100644
> > --- a/mm/damon/paddr.c
> > +++ b/mm/damon/paddr.c
> > @@ -36,6 +36,12 @@ static unsigned long damon_pa_core_addr(
> > return pa / addr_unit;
> > }
> >
> > +static phys_addr_t damon_pa_next_addr(phys_addr_t addr, phys_addr_t end,
> > + unsigned long size)
> > +{
> > + return end - addr <= size ? end : addr + size;
>
> I'd prefer having safe case first. E.g.,
>
> return addr < end - size ? addr + size : end;
Thinking again, end might be smaller than size. Maybe below?
size < end - addr ? addr + size : end;
Thanks,
SJ
>
> Could you please use that?
>
> Also, as the code looks intuitive, I don't really feel like this helper
> function is needed. What do you think?
>
>
> Thanks,
> SJ
>
> [...]
>
Thanks,
SJ
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-04 2:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:43 [PATCH] mm/damon/paddr: prevent address wrap in action walks Kyuwon Cho
2026-12-03 17:38 ` Aveline Noir
2026-12-04 1:55 ` SJ Park
2026-12-04 1:53 ` SJ Park
2026-12-04 2:26 ` SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox