Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/damon/paddr: drop last same folio access check reuse" failed to apply to 6.6-stable tree

PATCH Applied [email protected] 4 participants 4 messages Sep 8 – Sep 9

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x f23f0aa62b2f32c2b12f95959fc4603ef81678b2
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090853-disparity-bazooka-4747@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From f23f0aa62b2f32c2b12f95959fc4603ef81678b2 Mon Sep 17 00:00:00 2001
From: SJ Park <[email protected]>
Date: Tue, 14 Jul 2026 20:09:59 -0700
Subject: [PATCH] mm/damon/paddr: drop last same folio access check reuse
optimization

It can race when multiple kdamonds are being used. The problem from the race is doubtful, but the gain from the optimization is also doubtful. Simply drop the optimization in favor of code simplicity.

The user impact is doubtfully trivial. After all, this kind of interference can happen only by intentional user setup. Even if it happens, it will be rare, and the consequence is degradation of the best-effort monitoring results. No critical consequences like kernel panic or memory corruption happen.

The race was discovered [1] by Sashiko.

Fixes a28397beb55b ("mm/damon: implement primitives for physical address space monitoring")
Cc <[email protected]> # 5.16.x
mm/damon/paddr.c +4 -16
index b85f88a7a38f..e4f98d67461f 100644
@@ -65,7 +65,7 @@ static void damon_pa_prepare_access_checks(struct damon_ctx *ctx)
 	}
 }
 
-static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz)
+static bool damon_pa_young(phys_addr_t paddr)
 {
 	struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
 	bool accessed;
@@ -74,7 +74,6 @@ static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz)
 		return false;
 
 	accessed = damon_folio_young(folio);
-	*folio_sz = folio_size(folio);
 	folio_put(folio);
 	return accessed;
 }
@@ -82,23 +81,12 @@ static bool damon_pa_young(phys_addr_t paddr, unsigned long *folio_sz)
 static void __damon_pa_check_access(struct damon_region *r,
 		unsigned long addr_unit)
 {
-	static phys_addr_t last_addr;
-	static unsigned long last_folio_sz = PAGE_SIZE;
-	static bool last_accessed;
+	bool accessed;
 	phys_addr_t sampling_addr = damon_pa_phys_addr(
 			r->sampling_addr, addr_unit);
 
-	/* If the region is in the last checked page, reuse the result */
-	if (ALIGN_DOWN(last_addr, last_folio_sz) ==
-				ALIGN_DOWN(sampling_addr, last_folio_sz)) {
-		damon_update_region_access_rate(r, last_accessed);
-		return;
-	}
-
-	last_accessed = damon_pa_young(sampling_addr, &last_folio_sz);
-	damon_update_region_access_rate(r, last_accessed);
-
-	last_addr = sampling_addr;
+	accessed = damon_pa_young(sampling_addr);
+	damon_update_region_access_rate(r, accessed);
 }
 
 static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
maintainer
#1 lore raw

PATCH 1/1 mm/damon/paddr: drop last same folio access check reuse optimization

It can race when multiple kdamonds are being used. The problem from the race is doubtful, but the gain from the optimization is also doubtful. Simply drop the optimization in favor of code simplicity.

The user impact is doubtfully trivial. After all, this kind of interference can happen only by intentional user setup. Even if it happens, it will be rare, and the consequence is degradation of the best-effort monitoring results. No critical consequences like kernel panic or memory corruption happen.

The race was discovered [1] by Sashiko.

Fixes a28397beb55b ("mm/damon: implement primitives for physical address space monitoring")
Cc <[email protected]> # 5.16.x
(cherry picked from commit f23f0aa62b2f32c2b12f95959fc4603ef81678b2)
---
 mm/damon/paddr.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
mm/damon/paddr.c +4 -17
index 909db25efb35e..fe481ae64f37e 100644
@@ -111,7 +111,7 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma,
 	return *accessed == false;
 }
 
-static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
+static bool damon_pa_young(unsigned long paddr)
 {
 	struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
 	bool accessed = false;
@@ -143,30 +143,17 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
 		folio_unlock(folio);
 
 out:
-	*folio_sz = folio_size(folio);
 	folio_put(folio);
 	return accessed;
 }
 
 static void __damon_pa_check_access(struct damon_region *r)
 {
-	static unsigned long last_addr;
-	static unsigned long last_folio_sz = PAGE_SIZE;
-	static bool last_accessed;
-
-	/* If the region is in the last checked page, reuse the result */
-	if (ALIGN_DOWN(last_addr, last_folio_sz) ==
-				ALIGN_DOWN(r->sampling_addr, last_folio_sz)) {
-		if (last_accessed)
-			r->nr_accesses++;
-		return;
-	}
+	bool accessed;
 
-	last_accessed = damon_pa_young(r->sampling_addr, &last_folio_sz);
-	if (last_accessed)
+	accessed = damon_pa_young(r->sampling_addr);
+	if (accessed)
 		r->nr_accesses++;
-
-	last_addr = r->sampling_addr;
 }
 
 static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx)
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 6.6.y] mm/damon/paddr: drop last same folio access check reuse optimization

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

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

Pre-existing issues:
- [High] Physical address sampling and PFN iterations fail for large folios because damon_get_folio explicitly rejects tail pages. --

commit cb37cb361a4cb244731d8cba3a6b765eff4dcbaf
Author: SJ Park <[email protected]>

mm/damon/paddr: drop last same folio access check reuse optimization

This commit drops the optimization that reuses the previous physical address access check if the region falls within the last checked folio. The author removes it in favor of code simplicity, noting it can race when multiple kdamonds are used.

Quoted 4 lines
mm/damon/paddr.c +0 -0
index 909db25efb35e..fe481ae64f37e 100644

[ ... ]

mm/damon/paddr.c static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma, · line 117

Quoted 9 lines
mm/damon/paddr.c +1 -1
@@ -111,7 +111,7 @@ static bool __damon_pa_young(struct folio *folio, struct vm_area_struct *vma,
 	return *accessed == false;
 }
 
-static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
+static bool damon_pa_young(unsigned long paddr)
 {
 	struct folio *folio = damon_get_folio(PHYS_PFN(paddr));
 	bool accessed = false;

[Severity: High]
This isn't a bug introduced by this patch, but does physical address sampling fail for large folios because damon_get_folio() rejects tail pages?

In damon_pa_young(), the sampled physical address is passed to damon_get_folio() via PHYS_PFN(paddr). For large folios, this randomly sampled address is extremely likely to fall on a tail page. Since damon_get_folio() explicitly returns NULL for tail pages:

mm/damon/ops-common.c:damon_get_folio() {
    ...
    if (!page || PageTail(page))
        return NULL;
    ...
}

Does this mean DAMON silently ignores large folios for physical address monitoring? This same tail page rejection seems to cause the unconditional PAGE_SIZE stepping in damon_pa_pageout() and damon_pa_mark_accessed_or_deactivate() to skip entire large folios if the region boundaries start on a tail page.

While this wasn't introduced by this patch, dropping the last-folio-size cache here removes the only mechanism that might have partially masked this flaw for randomly sampled addresses that happened to hit a head page.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#3 lore raw

Re: [PATCH 6.6.y] mm/damon/paddr: drop last same folio access check reuse optimization

In reply to SJ Park
Quoted 3 lines

It can race when multiple kdamonds are being used. The problem from the race is doubtful, but the gain from the optimization is also doubtful. Simply drop the optimization in favor of code simplicity.

Queued for 6.6, thanks.

Signature · 2 lines
Thanks,
Sasha