From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, "Nathan Gao" <zcgao@amazon.com>,
damon@lists.linux.dev
Subject: Re: [PATCH] mm/damon: use a page-aligned sampling address
Date: Thu, 27 Aug 2026 17:28:18 -0700 [thread overview]
Message-ID: <20260828002820.62184-1-sj@kernel.org> (raw)
In-Reply-To: <20260827195026.5B6DE1F000E9@smtp.kernel.org>
On Thu, 27 Aug 2026 19:50:25 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Unaligned address passed to `mmu_notifier_clear_young()` in THP and HugeTLB paths causes out-of-bounds young bit clearing.
> - [High] damos_va_migrate_pmd_entry() and damos_va_stat_pmd_entry() incorrectly advance the PTE loop by folio_nr_pages(), skipping unrelated PTEs.
> --
>
> commit aa3021f597712046c0814751d5b225db6dfc5b6c
> Author: Nathan Gao <zcgao@amazon.com>
> Subject: mm/damon: use a page-aligned sampling address
>
> This patch modifies the DAMON virtual address access check to page-align
> the randomly chosen sampling address. This prevents issues on architectures
> like arm64 where an unaligned address could lead to walking past block
> boundaries and causing page table corruption.
>
> > diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> > index 0648400b2d65b..8856a9131971d 100644
> > --- a/mm/damon/vaddr.c
> > +++ b/mm/damon/vaddr.c
> > @@ -361,7 +361,8 @@ static void __damon_va_prepare_access_check(struct mm_struct *mm,
> > struct damon_region *r,
> > struct damon_ctx *ctx)
> > {
> > - r->sampling_addr = damon_rand(ctx, r->ar.start, r->ar.end);
> > + r->sampling_addr = PAGE_ALIGN_DOWN(damon_rand(ctx, r->ar.start,
> > + r->ar.end));
>
> [Severity: High]
> This isn't a bug introduced by this patch, but while this patch page-aligns
> the sampling address, can this still cause out-of-bounds young bit clearing
> for huge pages?
>
> When DAMON samples a region, the address is passed down to THP and HugeTLB
> handlers. If the sampled address retains a sub-huge-page offset, the range
> passed to the MMU notifier spans two contiguous huge pages:
>
> mm/damon/ops-common.c:damon_pmdp_mkold() {
> ...
> young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + HPAGE_PMD_SIZE);
> ...
> }
>
> mm/damon/vaddr.c:damon_hugetlb_mkold() {
> ...
> if (mmu_notifier_clear_young(mm, addr, addr + huge_page_size(hstate_vma(vma))))
> ...
> }
>
> Secondary MMUs like KVM check for GFNs overlapping this range. Because the
> adjacent huge page overlaps with this range, KVM could incorrectly clear its
> young/accessed bit, altering the access history of an unrelated huge page.
Makes sense, I will work on this.
>
>
> [Severity: High]
> This is also a pre-existing issue not introduced by this patch, but do the
> PTE walk loops in damos_va_migrate_pmd_entry() and damos_va_stat_pmd_entry()
> skip unrelated PTEs?
>
> mm/damon/vaddr.c:damos_va_migrate_pmd_entry() {
> for (; addr < next; pte += nr, addr += nr * PAGE_SIZE) {
> nr = 1;
> ptent = ptep_get(pte);
> ...
> folio = vm_normal_folio(walk->vma, addr, ptent);
> ...
> nr = folio_nr_pages(folio);
> }
> }
>
> In the PTE walk loops, the step size nr is set to folio_nr_pages(folio).
> However, folio_nr_pages() simply returns the total size of the large folio.
> If the large folio is only partially mapped within the VMA, or if the
> iteration starts at an offset into the folio, blindly advancing pte += nr
> and addr += nr * PAGE_SIZE will overshoot the folio's boundaries. Could this
> skip valid PTEs that map entirely different folios, causing DAMON to silently
> ignore those pages?
I'm working [1] on this. The plan is to post it again without RFC tag after
the current merge window is closed.
[1] https://lore.kernel.org/20260802162631.90304-1-sj@kernel.org
>
> >
> > damon_va_mkold(mm, r->sampling_addr);
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260827193821.46115-1-zcgao@amazon.com?part=1
Thanks,
SJ
next prev parent reply other threads:[~2026-08-28 0:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 19:38 [PATCH] mm/damon: use a page-aligned sampling address Nathan Gao
2026-08-27 19:50 ` sashiko-bot
2026-08-28 0:28 ` SJ Park [this message]
2026-08-28 0:22 ` SJ Park
2026-08-29 1:04 ` Nathan Gao
2026-08-29 1:55 ` SJ Park
2026-08-31 22:50 ` Nathan Gao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260828002820.62184-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@kernel.org \
--cc=zcgao@amazon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.