mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit
@ 2026-10-22  6:36 Shubhang Kaushik (Ampere)
  2026-10-22 14:02 ` SJ Park
  2026-10-22 14:41 ` Aveline Noir
  0 siblings, 2 replies; 3+ messages in thread
From: Shubhang Kaushik (Ampere) @ 2026-10-22  6:36 UTC (permalink / raw)
  To: SJ Park, Andrew Morton, Fernand Sieber, Shakeel Butt,
	SeongJae Park, Leonard Foerster, Shubhang Kaushik,
	Christoph Lameter (Ampere)
  Cc: damon, linux-mm, linux-kernel, Shubhang Kaushik (Ampere)

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>
---
 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@gentwo.org>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit
  2026-10-22  6:36 [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit Shubhang Kaushik (Ampere)
@ 2026-10-22 14:02 ` SJ Park
  2026-10-22 14:41 ` Aveline Noir
  1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-10-22 14:02 UTC (permalink / raw)
  To: Shubhang Kaushik (Ampere)
  Cc: SJ Park, Andrew Morton, Fernand Sieber, Shakeel Butt,
	SeongJae Park, Leonard Foerster, Shubhang Kaushik,
	Christoph Lameter (Ampere),
	damon, linux-mm, linux-kernel

Hello Shubhang,

On Wed, 21 Oct 2026 23:36:19 -0700 "Shubhang Kaushik (Ampere)" <sh@gentwo.org> wrote:

> 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.

Thank you for finding and fixing this!

> 
> Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces")

I once thought if we need to Cc: stable@.  Because this is only for monitoring
accruacy improvement and DAMON is only beest-effort, I think we don't need to.

> Signed-off-by: Shubhang Kaushik (Ampere) <sh@gentwo.org>

Reviewed-by: SJ Park <sj@kernel.org>

I applied  this patch to damon/next [1] tree.  We are now in the middle of the
merge window.  It may better to focus on making mm.git changes pulled into the
mainline, rather than adding more changes that are not really urgent.  I
understand this series is not really urgent.  Hence, Andrew might not add this
patch until next -rc1 release.  In the case, I will request adding this to
mm.git after next -rc1 release.  So, no action from your side is needed for
now.  Let me know if you think this is really urgent.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees


Thanks,
SJ

[...]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit
  2026-10-22  6:36 [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit Shubhang Kaushik (Ampere)
  2026-10-22 14:02 ` SJ Park
@ 2026-10-22 14:41 ` Aveline Noir
  1 sibling, 0 replies; 3+ messages in thread
From: Aveline Noir @ 2026-10-22 14:41 UTC (permalink / raw)
  To: Shubhang Kaushik (Ampere),
	SJ Park, Andrew Morton, Fernand Sieber, Shakeel Butt,
	SeongJae Park, Leonard Foerster, Shubhang Kaushik,
	Christoph Lameter (Ampere)
  Cc: damon, linux-mm, linux-kernel

Hi Shubhang,

> Align the address before both the primary PTE operation and the
> MMU notifier call so that they cover the same page.

Looks good to me. Tested in an x86-64 KVM guest.

Reviewed-by: Aveline Noir <jm5905938@gmail.com>
Tested-by: Aveline Noir <jm5905938@gmail.com>

The PMD path has the same issue. I will send a patch for that.

Thanks,
Aveline Noir

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-22 14:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22  6:36 [PATCH] mm/damon: align MMU notifier range when clearing PTE young bit Shubhang Kaushik (Ampere)
2026-10-22 14:02 ` SJ Park
2026-10-22 14:41 ` Aveline Noir

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®