DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH 6.1.y] mm/damon/vaddr: drop last same folio access check optimization
Date: Wed, 09 Sep 2026 06:24:42 +0000	[thread overview]
Message-ID: <20260909062442.DB1AF1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909061152.278678-1-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The PMD is read directly via `*pmd` outside a lock, which can cause torn reads on architectures where PMD size is larger than the word size (e.g., 32-bit PAE).
--

commit 3ab3595f2bebbbf09add4e61c160f37ee6aa2807
Author: SJ Park <sj@kernel.org>

mm/damon/vaddr: drop last same folio access check optimization

This commit removes the same-folio access check optimization from DAMON's
virtual address monitoring. The optimization was found to race when multiple
kdamonds are running, and its impact was deemed doubtful.

Link: https://lore.kernel.org/20260715031002.108504-4-sj@kernel.org
Link: https://lore.kernel.org/20260621204050.10993-1-sj@kernel.org [1]

> diff --git a/mm/damon/vaddr.c b/mm/damon/vaddr.c
> index 708f281c1b6b4..4aa89347d754d 100644
> --- a/mm/damon/vaddr.c
> +++ b/mm/damon/vaddr.c
[ ... ]
> @@ -453,10 +452,8 @@ static int damon_young_pmd_entry(pmd_t *pmd, unsigned long addr,
>  			goto huge_out;
>  		if (pmd_young(*pmd) || !page_is_idle(page) ||
>  					mmu_notifier_test_young(walk->mm,
> -						addr)) {
> -			*priv->page_sz = HPAGE_PMD_SIZE;
> +						addr))
>  			priv->young = true;

[Severity: High]
This is a pre-existing issue, but does reading the PMD directly via *pmd
outside a lock risk torn reads on architectures where the PMD size is larger
than the word size (like 32-bit PAE)?

Earlier in damon_young_pmd_entry(), the code does:

if (pmd_trans_huge(*pmd)) {
        ptl = pmd_lock(walk->mm, pmd);

Since damon_young_pmd_entry() runs during DAMON's page table walk under
mmap_read_lock(), concurrent THP modifications aren't prevented. If a torn
read occurs on the lockless *pmd evaluation during a concurrent THP split or
collapse, it could bypass both the pmd_trans_huge() and pmd_bad() checks.

If it falls through to the regular page path, pte_offset_map_lock() might
map a bogus physical address from the torn value, allowing arbitrary memory
to be treated as PTEs.

A similar lockless check appears to exist in damon_mkold_pmd_entry() as
well. Could these paths use pmd_read_atomic() or pmdp_get_lockless() to
safely evaluate the PMD?

> -		}
>  		put_page(page);
>  huge_out:
>  		spin_unlock(ptl);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909061152.278678-1-sj@kernel.org?part=1

  reply	other threads:[~2026-09-09  6:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2026090858-legislate-monogamy-2299@gregkh>
2026-09-09  6:11 ` [PATCH 6.1.y] mm/damon/vaddr: drop last same folio access check optimization SJ Park
2026-09-09  6:24   ` sashiko-bot [this message]
2026-09-09 20:26   ` Sasha Levin

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=20260909062442.DB1AF1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox