Skip to contentSkip to conversation

FAILED: patch "[PATCH] mm/damon/core: make charge_addr_from aware of end-address" failed to apply to 6.1-stable tree

PATCH New [email protected] 3 participants 3 messages Jul 20 – Jul 21

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 6.1-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.1.y
git checkout FETCH_HEAD
git cherry-pick -x 5a2d162e22bf33eb89d53e802d0fc1ec422e19b6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026072059-refocus-lizard-6528@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

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

From 5a2d162e22bf33eb89d53e802d0fc1ec422e19b6 Mon Sep 17 00:00:00 2001
From: SeongJae Park <[email protected]>
Date: Mon, 27 Apr 2026 21:29:40 -0700
Subject: [PATCH] mm/damon/core: make charge_addr_from aware of end-address
exclusivity

DAMON region end address is exclusive one, but charge_addr_from is assigned assuming the end address is inclusive. As a result, DAMOS action to next up to min_region_sz memory can be skipped. This is quite negligible user impact. But, the bug is a bug that can be very simply fixed. Fix the wrong assignment to respect the exclusiveness of the address.

The issue was discovered [1] by Sashiko.

Fixes 50585192bc2e ("mm/damon/schemes: skip already charged targets and regions")
Cc <[email protected]> # 5.16.x
mm/damon/core.c +1 -1
index 3dbbbfdeff71..901ffdaefb7f 100644
@@ -2106,7 +2106,7 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t,
 		if (damos_quota_is_set(quota) &&
 				quota->charged_sz >= quota->esz) {
 			quota->charge_target_from = t;
-			quota->charge_addr_from = r->ar.end + 1;
+			quota->charge_addr_from = r->ar.end;
 		}
 	}
 	if (s->action != DAMOS_STAT)
maintainer
#1 lore raw

PATCH 1/1 mm/damon/core: make charge_addr_from aware of end-address exclusivity

From: SeongJae Park <[email protected]>

DAMON region end address is exclusive one, but charge_addr_from is assigned assuming the end address is inclusive. As a result, DAMOS action to next up to min_region_sz memory can be skipped. This is quite negligible user impact. But, the bug is a bug that can be very simply fixed. Fix the wrong assignment to respect the exclusiveness of the address.

The issue was discovered [1] by Sashiko.

Fixes 50585192bc2e ("mm/damon/schemes: skip already charged targets and regions")
Cc <[email protected]> # 5.16.x
(cherry picked from commit 5a2d162e22bf33eb89d53e802d0fc1ec422e19b6)
---
 mm/damon/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c +1 -1
index d293200d824e9..4b434ebd37c53 100644
@@ -803,7 +803,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
 			quota->charged_sz += sz;
 			if (quota->esz && quota->charged_sz >= quota->esz) {
 				quota->charge_target_from = t;
-				quota->charge_addr_from = r->ar.end + 1;
+				quota->charge_addr_from = r->ar.end;
 			}
 		}
 		if (s->action != DAMOS_STAT)
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 6.1.y] mm/damon/core: make charge_addr_from aware of end-address exclusivity

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

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

Pre-existing issues:
- [High] Modifying the local region pointer r inside the damon_for_each_scheme loop causes subsequent schemes to miss the first half of a split region.
- [High] Regions created by damon_split_region_at() are silently skipped by the caller's safe list iterator.
- [High] Failure to set charge_target_from when the remaining quota is less than DAMON_MIN_REGION breaks the round-robin mechanism and wastes CPU.
- [Medium] The scheme's resume logic unconditionally skips the uncharged remainder of a target's last region when resetting the charge state. --

--- Patch [1]: [PATCH 6.1.y] mm/damon/core: make charge_addr_from aware of end-address exclusivity --- commit 5e517614c6d1a61febddeb99e7bb671793abbca6
Author: SeongJae Park <[email protected]>
Subject: mm/damon/core: make charge_addr_from aware of end-address exclusivity

This commit fixes a bug where charge_addr_from was assigned assuming the end address is inclusive. It changes the assignment to respect the exclusiveness of the DAMON region end address.

Quoted 4 lines
mm/damon/core.c +0 -0
index d293200d824e9..4b434ebd37c53 100644

[ ... ]

mm/damon/core.c static void damon_do_apply_schemes(struct damon_ctx *c, · line 809

Quoted 9 lines
mm/damon/core.c +1 -1
@@ -803,7 +803,7 @@ static void damon_do_apply_schemes(struct damon_ctx *c,
 			quota->charged_sz += sz;
 			if (quota->esz && quota->charged_sz >= quota->esz) {
 				quota->charge_target_from = t;
-				quota->charge_addr_from = r->ar.end + 1;
+				quota->charge_addr_from = r->ar.end;
 			}
 		}
 		if (s->action != DAMOS_STAT)

[Severity: High]
This is a pre-existing issue, but does the safe iterator in kdamond_apply_schemes() skip newly inserted regions?

mm/damon/core.c:kdamond_apply_schemes() {
    ...
    damon_for_each_region_safe(r, next_r, t) {
        ...
        damon_do_apply_schemes(c, t, r);
    }
}

If damon_do_apply_schemes() calls damon_split_region_at(), it inserts a new region immediately after r. Because next_r is cached before the loop body, the newly inserted right-hand region falls into a blind spot and appears to be skipped for the current aggregation interval.

[Severity: High]
This is a pre-existing issue, but is it possible that reassigning the local region pointer causes subsequent schemes to miss the first half of a split region?

mm/damon/core.c:damon_do_apply_schemes() {
    ...
    damon_for_each_scheme(s, c) {
        ...
        if (quota->charge_addr_from && r->ar.start < quota->charge_addr_from) {
            ...
            damon_split_region_at(t, r, sz);
            r = damon_next_region(r);
            sz = damon_sz_region(r);
        }
        ...
    }
}

Modifying the loop parameter r leaks to subsequent schemes in the iteration, causing them to evaluate only the second half of the split region and completely miss the first half.

[Severity: Medium]
This is a pre-existing issue, but could this logic unconditionally skip the uncharged remainder of a target's last region?

mm/damon/core.c:damon_do_apply_schemes() {
    ...
    if (r == damon_last_region(t)) {
        quota->charge_target_from = NULL;
        quota->charge_addr_from = 0;
        continue;
    }
    ...
}

When resuming from a previous charge window that exhausted its quota in the middle of the last region of a target, it looks like this clears the charge tracking and immediately executes continue, skipping the evaluation of the rest of the region.

[Severity: High]
This is a pre-existing issue, but can this jump break the round-robin mechanism and waste CPU when the remaining quota is less than DAMON_MIN_REGION?

mm/damon/core.c:damon_do_apply_schemes() {
    ...
    if (quota->esz && quota->charged_sz + sz > quota->esz) {
        sz = ALIGN_DOWN(quota->esz - quota->charged_sz, DAMON_MIN_REGION);
        if (!sz)
            goto update_stat;
        damon_split_region_at(t, r, sz);
    }
    ...
}

When the remaining quota is less than DAMON_MIN_REGION, ALIGN_DOWN results in sz == 0. The code then jumps to update_stat, bypassing the charged_sz update. This prevents charged_sz from reaching esz, creating a pseudo-infinite evaluation loop for the rest of the regions without saving the resume state.

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