From: SJ Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Shubhang Kaushik (Ampere)" <sh@gentwo.org>,
Fernand Sieber <sieberf@amazon.com>,
Leonard Foerster <foersleo@amazon.de>, SJ Park <sj@kernel.org>,
SeongJae Park <sjpark@amazon.de>,
Shakeel Butt <shakeel.butt@linux.dev>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Aveline Noir <jm5905938@gmail.com>
Subject: [PATCH 2/9] mm/damon/ops-common: align MMU notifier range when clearing PTE young bit
Date: Mon, 2 Nov 2026 07:07:49 -0800 [thread overview]
Message-ID: <20261102150757.93058-3-sj@kernel.org> (raw)
In-Reply-To: <20261102150757.93058-1-sj@kernel.org>
From: "Shubhang Kaushik (Ampere)" <sh@gentwo.org>
DAMON selects a byte-granular sampling address. damon_ptep_mkold()
clears the young bit of the PTE covering that address, but passes the
unaligned range [addr, addr + PAGE_SIZE) to MMU notifiers.
For an unaligned address, that range extends into the following page.
KVM ages every guest page intersecting the notifier range, so it can age
a secondary mapping for the following page although DAMON cleared only
the sampled page's primary PTE.
Align the address before both the primary PTE operation and the
MMU notifier call so that they cover the same page.
Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")
Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>
Reviewed-by: Aveline Noir <jm5905938@gmail.com>
Tested-by: Aveline Noir <jm5905938@gmail.com>
Reviewed-by: SJ Park <sj@kernel.org>
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20261021-damon-align-pte-young-notifier-v1-1-d0365ac45b66@gentwo.org
- Collect R-b: from SJ.
- Collect R-b: and T-b: from Aveline.
- Update subject prefix.
- Rebase to latest mm-new.
mm/damon/ops-common.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
index 2f3bf86a221be..f88c6fd189fca 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -64,6 +64,8 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr
bool young = false;
unsigned long pfn;
+ addr = PAGE_ALIGN_DOWN(addr);
+
if (likely(pte_present(pteval)))
pfn = pte_pfn(pteval);
else
@@ -83,8 +85,7 @@ void damon_ptep_mkold(pte_t *pte, struct vm_area_struct *vma, unsigned long addr
* Arch implementation of ptep_test_and_clear_young() may
* require aligned @addr
*/
- young |= ptep_test_and_clear_young(vma, PAGE_ALIGN_DOWN(addr),
- pte);
+ young |= ptep_test_and_clear_young(vma, addr, pte);
young |= mmu_notifier_clear_young(vma->vm_mm, addr, addr + PAGE_SIZE);
if (young)
folio_set_young(folio);
--
2.47.3
next prev parent reply other threads:[~2026-11-02 15:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 15:07 [PATCH 0/9] mm/damon: various fixes and cleanup of code, test, and docs SJ Park
2026-11-02 15:07 ` [PATCH 1/9] mm/damon/core: remove unnecessary zero-initialization in damon_new_ctx() SJ Park
2026-11-02 15:07 ` SJ Park [this message]
2026-11-02 15:07 ` [PATCH 3/9] mm/damon/ops-common: align MMU notifier range when clearing PMD young bit SJ Park
2026-11-02 15:07 ` [PATCH 4/9] mm/damon/stat: avoid 32-bit overflow in idle percentiles SJ Park
2026-11-02 15:07 ` [PATCH 5/9] mm/damon/{p,v}addr: skip folios already on the migration target node SJ Park
2026-11-02 15:07 ` [PATCH 6/9] selftests/damon/sysfs.py: stop obsolete_target shells hanging the test SJ Park
2026-11-02 15:07 ` [PATCH 7/9] mm/damon/reclaim: fix typo and grammar SJ Park
2026-11-02 15:07 ` [PATCH 8/9] Docs/admin-guide/mm/damon/lru_sort: fix grammar and stlye SJ Park
2026-11-02 15:07 ` [PATCH 9/9] Docs/admin-guide/mm/damon/reclaim: document how to disable watermarks SJ Park
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=20261102150757.93058-3-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=foersleo@amazon.de \
--cc=jm5905938@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sh@gentwo.org \
--cc=shakeel.butt@linux.dev \
--cc=sieberf@amazon.com \
--cc=sjpark@amazon.de \
/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