* [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from
@ 2026-10-20 2:39 SJ Park
2026-10-20 8:03 ` sashiko-bot
2026-10-20 16:07 ` Aveline Noir
0 siblings, 2 replies; 3+ messages in thread
From: SJ Park @ 2026-10-20 2:39 UTC (permalink / raw)
To: Andrew Morton; +Cc: SJ Park, stable, damon, linux-kernel, linux-mm
damos_quota->charge_{target,addr}_from saves the target and region the
scheme's quota limit is reached. damos_skip_charged_region() skips the
target and regions before the point. The target that was assigned to
charge_target_from could be dynamically removed from the context by the
runtime parameters update (aka commit) feature. In this case,
damos_skip_charged_region() cannot find if the point is passed or not,
so the scheme is effectively disabled.
Similarly, the user could also remove all the regions of the target
using the runtime parameters update feature. It would be uncommon to do
that, but it is a supported feature. Because the skip pointer detection
logic (damos_skip_charged_region()) works for each region of targets,
this result in the logic is entirely skipped and the scheme is
effectively disabled again.
The user impact is that the DAMOS scheme could suddenly stop working
under certain uses of the runtime parameters update feature. It could
surprise users. No crash or leak happens though. Users could also
simply work around by re-installing the scheme.
Catch the corner cases in damos_adjust_quota() and reset the pointers.
Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update")
Cc: <stable@vger.kernel.org> # 5.19.x
Closes: https://sashiko.dev/#/bug/linux-cd0c55fc-0cc8-45d8-9637-3334811c49b8
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from RFC
- RFC: https://lore.kernel.org/20261019143713.98610-1-sj@kernel.org
- Drop RFC tag.
mm/damon/core.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 479169dc9ac75..eb1fcdabc0075 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -3383,6 +3383,26 @@ static void damos_trace_esz(struct damon_ctx *c, struct damos *s,
trace_damos_esz(cidx, sidx, quota->esz);
}
+static void damos_fix_stale_charge_pointers(struct damon_ctx *c,
+ struct damos *s)
+{
+ struct damos_quota *quota;
+ struct damon_target *t;
+
+ quota = &s->quota;
+ if (!quota->charge_target_from)
+ return;
+ damon_for_each_target(t, c) {
+ if (t == quota->charge_target_from) {
+ if (damon_nr_regions(t) > 0)
+ return;
+ break;
+ }
+ }
+ quota->charge_target_from = NULL;
+ quota->charge_addr_from = 0;
+}
+
static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
{
struct damos_quota *quota = &s->quota;
@@ -3418,6 +3438,8 @@ static void damos_adjust_quota(struct damon_ctx *c, struct damos *s)
damos_trace_esz(c, s, quota);
}
+ damos_fix_stale_charge_pointers(c, s);
+
if (damos_quota_is_full(quota, c->min_region_sz))
return;
if (!c->ops.get_scheme_score)
base-commit: e558ba2a16a47baf6b8e76bb11e92eb92a491e3a
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from
2026-10-20 2:39 [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park
@ 2026-10-20 8:03 ` sashiko-bot
2026-10-20 16:07 ` Aveline Noir
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-10-20 8:03 UTC (permalink / raw)
To: SJ Park; +Cc: damon
> damos_quota->charge_{target,addr}_from saves the target and region the
> scheme's quota limit is reached. damos_skip_charged_region() skips the
> target and regions before the point. The target that was assigned to
> charge_target_from could be dynamically removed from the context by the
> runtime parameters update (aka commit) feature. In this case,
> damos_skip_charged_region() cannot find if the point is passed or not,
> so the scheme is effectively disabled.
>
> Similarly, the user could also remove all the regions of the target
> using the runtime parameters update feature. It would be uncommon to do
> that, but it is a supported feature. Because the skip pointer detection
> logic (damos_skip_charged_region()) works for each region of targets,
> this result in the logic is entirely skipped and the scheme is
> effectively disabled again.
>
> The user impact is that the DAMOS scheme could suddenly stop working
> under certain uses of the runtime parameters update feature. It could
> surprise users. No crash or leak happens though. Users could also
> simply work around by re-installing the scheme.
>
> Catch the corner cases in damos_adjust_quota() and reset the pointers.
>
> Fixes: da87878010e5 ("mm/damon/sysfs: support online inputs update")
> Cc: <stable@vger.kernel.org> # 5.19.x
> Closes: https://sashiko.dev/#/bug/linux-cd0c55fc-0cc8-45d8-9637-3334811c49b8
> Signed-off-by: SJ Park <sj@kernel.org>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261020023958.108276-1-sj@kernel.org?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from
2026-10-20 2:39 [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park
2026-10-20 8:03 ` sashiko-bot
@ 2026-10-20 16:07 ` Aveline Noir
1 sibling, 0 replies; 3+ messages in thread
From: Aveline Noir @ 2026-10-20 16:07 UTC (permalink / raw)
To: SJ Park, Andrew Morton; +Cc: stable, damon, linux-kernel, linux-mm
Hi SJ,
> Catch the corner cases in damos_adjust_quota() and reset the pointers.
The patch looks good to me. I tested DAMON_RECLAIM stop/start after
filling the quota on x86-64 KVM and everything goes well :)
Reviewed-by: Aveline Noir <jm5905938@gmail.com>
Tested-by: Aveline Noir <jm5905938@gmail.com>
Thanks,
Aveline Noir
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-20 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-20 2:39 [PATCH] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park
2026-10-20 8:03 ` sashiko-bot
2026-10-20 16:07 ` Aveline Noir
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.