[PATCH] mm/damon: align MMU notifier range when clearing PTE young bit

From: Shubhang Kaushik (Ampere)

Date: Thu Oct 22 2026 - 02:36:42 EST


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@xxxxxxxxxx>
---
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 8fc61d06d358597c4b8eec9523865f43496298d1..848c327f231e722499b9aac2c041b3aa84061d56 100644
--- a/mm/damon/ops-common.c
+++ b/mm/damon/ops-common.c
@@ -46,6 +46,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
@@ -65,8 +67,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);

---
base-commit: 4403278e4ea2f654f8130a5c03eb8b4516a0f201
change-id: 20261021-damon-align-pte-young-notifier-e8f19e0e84c5

Best regards,
--
Shubhang Kaushik (Ampere) <sh@xxxxxxxxxx>