mm/damon: porting fixes that cherry-pick failed on 2026-11-07
Subsystems (3)
SJ Park
maintainercover mm/damon: porting fixes that cherry-pick failed on 2026-11-07
Manually port five DAMON fixes that cherry-pick failed [1-5] and turned out to really need to be picked. Note that seven patches [6-12] that also failed in the same day were having wrong Cc:stable@ tags, so ignored.
Patches that this series is porting.
[1] https://lore.kernel.org/[email protected]
[2] https://lore.kernel.org/[email protected]
[3] https://lore.kernel.org/[email protected]
[4] https://lore.kernel.org/[email protected]
[5] https://lore.kernel.org/[email protected]
Patches that also cherry-pick failed but deliverately ignored.
[6] https://lore.kernel.org/[email protected]
[7] https://lore.kernel.org/[email protected]
[8] https://lore.kernel.org/[email protected]
[9] https://lore.kernel.org/[email protected]
[10] https://lore.kernel.org/[email protected]
[11] https://lore.kernel.org/[email protected]
[12] https://lore.kernel.org/[email protected]
Changes from RFC
- RFC: https://lore.kernel.org/[email protected]
- None.
SJ Park (5):
mm/damon/core: skip applying scheme if region split for quota fails mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once mm/damon/core: remove unreachable damos charge_{target,addr}_from mm/damon/core: filter out damos address filter-split failed region
mm/damon/core.c | 63 +++++++++++++++++++++++++++++++------ mm/damon/sysfs-schemes.c | 5 ++- mm/damon/tests/core-kunit.h | 16 +++++++--- 3 files changed, 66 insertions(+), 18 deletions(-)
base-commit: bd28b146e1b6b6048a00f4d240d0f6b2e1db6b3c
Signature · 1 line
2.47.3
SJ Park
maintainerPATCH 1/5 mm/damon/core: skip applying scheme if region split for quota fails
Patch series "mm/damon: fix DAMOS bugs in core, paddr and vaddr".
Fix misc bugs of DAMOS. Patch 1 makes DAMOS less stress memory allocator under extreme situation. Patches 2 and 3 fix wrong folios walking in DAMON_PADDR. Patches 4 and 5 fix wrong folios walking in DAMON_VADDR. Patches 6-8 handle extreme and unlikely memory situations that can cause divide by zero and underflow.
All bugs are discovered by Sashiko.
This patch (of 8):
damos_apply_scheme() splits a region and apply the action to the subregion if it is needed for not violating the quota. The split operation (damon_split_region_at()) could fail for allocation failure. In the case, the quota could be violated. From the user's perspective, DAMOS becomes more aggressive than expected under the extreme situation. Handle the failure.
The user impact is not critical. The failure of damon_split_region_at() is unlikely since it is arguably too small to fail. Also DAMOS being aggressive is limited to the single region. Users can set min_nr_regions to set the maximum size of each region. If it is reasonably set, the transient overhead shouldn't be critical.
The issue was discovered [1] by Sashiko.
6.18.y porting notes. Modify damon_split_region_at() to return failures. It is a part of commit c60874860762 ("mm/damon/core: handle region split failure in apply_min_nr_regions()"). Without it, build fails.
--- mm/damon/core.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
mm/damon/core.c +8 -4
@@ -1700,7 +1700,7 @@ static void kdamond_tune_intervals(struct damon_ctx *c)damon_set_attrs (c, &new_attrs); } -static void damon_split_region_at (struct damon_target *t, +static int damon_split_region_at (struct damon_target *t,struct damon_region *r,unsigned long sz_r);static bool __damos_valid_target (struct damon_region *r,struct damos *s)
@@ -2000,7 +2000,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, c->min_sz_region);if (!sz) goto update_stat; -damon_split_region_at (t, r, sz); +if (damon_split_region_at (t, r, sz)) + goto update_stat; }if (damos_filter_out (c, t, r, s))return ;
@@ -2454,15 +2455,17 @@ static void kdamond_merge_regions(struct damon_ctx *c, unsigned int threshold,* * r the region to be split * sz_r size of the first sub-region that will be made +* +* Return: 0 on success, negative error code otherwise. */ -static void damon_split_region_at (struct damon_target *t, +static int damon_split_region_at (struct damon_target *t,struct damon_region *r,unsigned long sz_r) {struct damon_region *new; new =damon_new_region (r->ar.start + sz_r, r->ar.end);if (!new) -return ; +return -ENOMEM ; r->ar.end = new->ar.start;
@@ -2472,6 +2475,7 @@ static void damon_split_region_at(struct damon_target *t, new->nr_accesses = r->nr_accesses;damon_insert_region (new, r,damon_next_region (r), t); +return 0 ; }/* Split every region in the given target into 'nr_subs' regions */
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6.18.y 1/5] mm/damon/core: skip applying scheme if region split for quota fails
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] mm/damon: damos_apply_scheme() inflates stats on region split failure It also noticed 1 related…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/damon: damos_apply_scheme() inflates stats on region split failure
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] mm/damon/core: total_charged_ns overflow in damos_apply_scheme() [1]
--
commit 9174bd7b58d2e2acd57046175fb6abb05138bbb9
Author: SJ Park <[email protected]>
mm/damon/core: skip applying scheme if region split for quota fails
This commit updates damon_split_region_at() to return an error code on allocation failure and skips applying a scheme in damos_apply_scheme() when splitting a region for quota enforcement fails.
Quoted 4 lines
mm/damon/core.c +0
-0
[ ... ]
mm/damon/core.c static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, · line 2007
Quoted 10 lines
mm/damon/core.c +2
-1@@ -2000,7 +2000,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, c->min_sz_region);if (!sz) goto update_stat; -damon_split_region_at (t, r, sz); +if (damon_split_region_at (t, r, sz)) + goto update_stat; }if (damos_filter_out (c, t, r, s))return ;
[Severity: Low]
Does jumping to update_stat when damon_split_region_at() fails inflate s->stat.nr_tried and s->stat.sz_tried?
At this point sz is the non-zero aligned remaining quota size. Jumping to update_stat calls damos_update_stat(s, sz, 0, 0), which increments s->stat.nr_tried and adds sz to s->stat.sz_tried even though damos_filter_out() and c->ops.apply_scheme() were skipped. Because quota->charged_sz is not updated on failure, subsequent oversized regions in the walk that also fail to split will repeatedly add sz to s->stat.sz_tried.
[Severity: High]
This problem wasn't introduced by this patch, but can quota->total_charged_ns overflow on 32-bit architectures [1] in damos_apply_scheme()?
struct damos_quota defines total_charged_ns as unsigned long, which wraps around zero after roughly 4.29 seconds of accumulated scheme execution on 32-bit platforms:
include/linux/damon.h:struct damos_quota {
...
unsigned long total_charged_ns;
...
};mm/damon/core.c:damos_apply_scheme() {
...
quota->total_charged_ns += timespec64_to_ns(&end) -
timespec64_to_ns(&begin);
...
}mm/damon/core.c:damos_set_effective_quota() {
...
if (quota->total_charged_ns)
throughput = mult_frac(quota->total_charged_sz, 1000000,
quota->total_charged_ns);
...
}When total_charged_ns wraps to a small value, damos_set_effective_quota() computes an inflated throughput and effective size quota (quota->esz), causing DAMOS to process far more memory than allowed by the time quota.
[1] https://sashiko.dev/#/bug/linux-c8969436-aa48-48c6-9f46-a12a64361494
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
SJ Park
maintainerRe: [PATCH 6.18.y 1/5] mm/damon/core: skip applying scheme if region split for quota fails
Quoted 45 lines · On Sun, 08 Nov 2026 19:35:07 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mm/damon:damos_apply_scheme()inflates stats on region split failure
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High]mm/damon/core:total_charged_nsoverflow indamos_apply_scheme()[1]
--commit
9174bd7b58d2e2acd57046175fb6abb05138bbb9
Author: SJ Park <[email protected]>
mm/damon/core: skip applying scheme if region split for quota failsThis commit updates
damon_split_region_at()to return an error code on allocation failure and skips applying a scheme indamos_apply_scheme()when splitting a region for quota enforcement fails.Quoted 4 lines
mm/damon/core.c +0
-0[ ... ]
mm/damon/core.c static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, · line 2007
Quoted 10 lines
mm/damon/core.c +2
-1@@ -2000,7 +2000,8 @@ static void damos_apply_scheme(struct damon_ctx *c, struct damon_target *t, c->min_sz_region);if (!sz) goto update_stat; -damon_split_region_at (t, r, sz); +if (damon_split_region_at (t, r, sz)) + goto update_stat; }if (damos_filter_out (c, t, r, s))return ;[Severity: Low]
Does jumping toupdate_statwhendamon_split_region_at()fails inflates->stat.nr_triedands->stat.sz_tried?
Quoted 7 lines
At this point sz is the non-zero aligned remaining quota size. Jumping to
update_statcallsdamos_update_stat(s, sz, 0, 0), which incrementss->stat.nr_triedand adds sz tos->stat.sz_triedeven thoughdamos_filter_out()andc->ops.apply_scheme()were skipped. Becausequota->charged_szis not updated on failure, subsequent oversized regions in the walk that also fail to split will repeatedly add sz tos->stat.sz_tried.
User impact is trivial and the same behavior exists in the mainline. No blocker.
Quoted 5 lines
[Severity: High]
This problem wasn't introduced by this patch, but canquota->total_charged_nsoverflow on 32-bit architectures [1] indamos_apply_scheme()?
Known low priority issue. No blocker for this patch.
Quoted 26 lines
struct
damos_quotadefinestotal_charged_nsas unsigned long, which wraps around zero after roughly 4.29 seconds of accumulated scheme execution on 32-bit platforms:include/linux/damon.h:struct damos_quota { ... unsigned long total_charged_ns; ... };mm/damon/core.c:damos_apply_scheme() { ... quota->total_charged_ns += timespec64_to_ns(&end) - timespec64_to_ns(&begin); ... }mm/damon/core.c:damos_set_effective_quota() { ... if (quota->total_charged_ns) throughput = mult_frac(quota->total_charged_sz, 1000000, quota->total_charged_ns); ... }
Quoted 9 lines
When
total_charged_nswraps to a small value,damos_set_effective_quota()computes an inflated throughput and effective size quota (quota->esz), causing DAMOS to process far more memory than allowed by the time quota.[1] https://sashiko.dev/#/bug/linux-c8969436-aa48-48c6-9f46-a12a64361494
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Thanks,
SJ
SJ Park
maintainerPATCH 2/5 mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
In reply to SJ ParkWhen DAMOS_QUOTA_SOME_MEM_PSI_US metric damos quota goal is set, the PSI delta for the feedback loop is calculated using damos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.
The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Check last_psi_total initialization and skip the tuning round when it is not initialized. For this, initialize last_psi_total with U64_MAX in the goal creation and the goal commit time. U64_MAX means the field is not initialized. The tuning round shows the value and adjusts it to guarantee the current quota is maintained for the round, and last_psi_total is correctly initialized on the next round.
Before this change, committing a new PSI goal on an existing PSI goal with goal-only DAMON sysfs command (commit_schemes_quota_goals) just worked. After this change, the tuning round right after the commit will be unnecessarily skipped, because last_psi_total is unconditionally marked as not initialized in the damos_commit_quota_goal_union(). This is an intended tradeoff for simplicity. Skipping just one round of tuning is no problem. Meanwhile it makes both the code and the behavior simple to understand.
Also update the quota goal commit unit test for changed last_psi_total setup behavior.
The issue was discovered [1] by Sashiko.
--- mm/damon/core.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
mm/damon/core.c +11 -2
@@ -348,6 +348,8 @@ struct damos_quota_goal *damos_new_quota_goal(return NULL ; goal->metric = metric; goal->target_value = target_value; +if (metric ==DAMOS_QUOTA_SOME_MEM_PSI_US ) + goal->last_psi_total =U64_MAX ;INIT_LIST_HEAD (&goal->list);return goal; }
@@ -798,6 +800,9 @@ static void damos_commit_quota_goal_union( struct damos_quota_goal *dst, struct damos_quota_goal *src) {switch (dst->metric) { +case DAMOS_QUOTA_SOME_MEM_PSI_US : + dst->last_psi_total =U64_MAX ; +break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :case DAMOS_QUOTA_NODE_MEM_FREE_BP : dst->nid = src->nid;
@@ -816,7 +821,6 @@ static int damos_commit_quota_goal( dst->target_value = src->target_value;if (dst->metric ==DAMOS_QUOTA_USER_INPUT ) dst->current_value = src->current_value; -/* keep last_psi_total as is, since it will be updated in next cycle */ damos_commit_quota_goal_union (dst, src);return 0 ; }
@@ -2171,7 +2175,12 @@ static void damos_set_quota_goal_current_value(struct damos_quota_goal *goal)break ;case DAMOS_QUOTA_SOME_MEM_PSI_US : now_psi_total =damos_get_some_mem_psi_total (); - goal->current_value = now_psi_total - goal->last_psi_total; +/* uninitialized last_psi_total; make no effect this round */ +if (goal->last_psi_total ==U64_MAX ) + goal->current_value = goal->target_value; +else + goal->current_value = now_psi_total - + goal->last_psi_total; goal->last_psi_total = now_psi_total;break ;case DAMOS_QUOTA_NODE_MEM_USED_BP :
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6.18.y 2/5] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
When
DAMOS_QUOTA_SOME_MEM_PSI_USmetric damos quota goal is set, the PSI delta for the feedback loop is calculated usingdamos_quota_goal->last_psi_total. However, it is initialized only after the first feedback loop. The first iteration of the loop uses the uninitialized value. As a result, the feedback loop can change the effective quota in an unexpected way at the first iteration.The user impact of the issue is not big, because the issue impacts only the first iteration of the feedback loop. The feedback loop also has an internal cap of the quota adjustment. The wrong adjustment will soon be corrected over a few iterations. For this reason, doing no initialization at commit time was intentional. It is also explicitly commented. That said, nobody likes behaviors that are unexpected or difficult to be expected.
Quoted 6 lines
[ ... ]Cc David Gow <[email protected]>Cc Quanmin Yan <[email protected]>Cc <[email protected]> # 6.9.x(cherry picked from commit 29c6084658af41b5b1fefd873d26d441830ced34)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
SJ Park
maintainerPATCH 3/5 mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
In reply to SJ ParkDAMON sysfs interface reads the user-provided size range arguments for hugepage_size type DAMOS filter twice. Once for validation, and once again for assignments to the variable that will be passed to the core layer. If the user updates the arguments in parallel, an invalid size range could be passed to the core layer. Avoid it by doing the assignments first, and then validating the assigned variables before passing those to the core layer.
User impact of the bug should be trivial. From the core layer's perspective, the invalid size range is not really invalid. It just works as having a weird size range. No critical issues such as a crash or a leak could happen. And sane users ain't do such parallel arguments update anyway. If they do, such racy behavior is arguably somewhat expected and deserved. That said, there is no reason to keep such races.
--- mm/damon/sysfs-schemes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
mm/damon/sysfs-schemes.c +2 -3
@@ -2493,12 +2493,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { -if (sysfs_filter->sz_range.min > - sysfs_filter->sz_range.max) { + filter->sz_range = sysfs_filter->sz_range; +if (filter->sz_range.min > filter->sz_range.max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6.18.y 3/5] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] mm/damon/sysfs: TOCTOU race in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] mm/damon/sysfs: TOCTOU race in damos_sysfs_add_quota_score()
[1]
--
commit 244e62bfada7cc56b0025da40ea03dad6d9c6420
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
This commit copies sysfs_filter->sz_range into filter->sz_range before validating it in damon_sysfs_add_scheme_filters() so that a concurrent sysfs update cannot pass an unvalidated size range to the core layer.
Quoted 9 lines
mm/damon/sysfs-schemes.c +0
-1@@ -2493,12 +2493,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { - if (sysfs_filter->sz_range.min >
mm/damon/sysfs-schemes.c static int damon_sysfs_add_scheme_filters(struct damos *scheme, · line 2503
Quoted 10 lines
mm/damon/sysfs-schemes.c +2
-2- sysfs_filter->sz_range.max) { + filter->sz_range = sysfs_filter->sz_range; +if (filter->sz_range.min > filter->sz_range.max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);
[Severity: High]
This problem wasn't introduced by this patch, but can damos_sysfs_add_quota_score() just below hit a similar double-read race on sysfs_goal->target_value [1]?
mm/damon/sysfs-schemes.c:damos_sysfs_add_quota_score() {
...
if (!sysfs_goal->target_value)
continue;
goal = damos_new_quota_goal(sysfs_goal->metric,
sysfs_goal->target_value);
...
}target_value_store() updates sysfs_goal->target_value without holding damon_sysfs_lock:
CPU0 CPU1damos_sysfs_add_quota_score()
if (!sysfs_goal->target_value)
target_value_store()
kstrtoul(..., &goal->target_value)
damos_new_quota_goal(...,
sysfs_goal->target_value)
...
damos_quota_score()
mult_frac(...,
goal->target_value) <-- divide-by-zeroIf a concurrent write sets sysfs_goal->target_value to 0 between the check and the second read, damos_new_quota_goal() creates a goal with a zero target_value, which later causes a divide-by-zero in damos_quota_score(). sysfs_goal->metric is also read twice in damos_sysfs_add_quota_score(), so a concurrent metric_store() between damos_new_quota_goal() and the switch can leave goal->nid or goal->current_value uninitialized.
[1] https://sashiko.dev/#/bug/linux-7f814c9a-986f-4103-a55a-ef9537dcf62b
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
SJ Park
maintainerRe: [PATCH 6.18.y 3/5] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
Quoted 68 lines · On Sun, 08 Nov 2026 19:30:36 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High]mm/damon/sysfs: TOCTOU race indamos_sysfs_add_quota_score()
[1]
--commit
244e62bfada7cc56b0025da40ea03dad6d9c6420
Author: SJ Park <[email protected]>
mm/damon/sysfs-schemes: readsysfs_filter->sz_rangeonly onceThis commit copies
sysfs_filter->sz_rangeintofilter->sz_rangebefore validating it indamon_sysfs_add_scheme_filters()so that a concurrent sysfs update cannot pass an unvalidated size range to the core layer.Quoted 9 lines
mm/damon/sysfs-schemes.c +0
-1@@ -2493,12 +2493,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme, }else if (filter->type ==DAMOS_FILTER_TYPE_TARGET ) { filter->target_idx = sysfs_filter->target_idx; }else if (filter->type ==DAMOS_FILTER_TYPE_HUGEPAGE_SIZE ) { - if (sysfs_filter->sz_range.min >mm/damon/sysfs-schemes.c static int damon_sysfs_add_scheme_filters(struct damos *scheme, · line 2503
Quoted 10 lines
mm/damon/sysfs-schemes.c +2
-2- sysfs_filter->sz_range.max) { + filter->sz_range = sysfs_filter->sz_range; +if (filter->sz_range.min > filter->sz_range.max) {damos_destroy_filter (filter);return -EINVAL ; } - filter->sz_range = sysfs_filter->sz_range; }damos_add_filter (scheme, filter);[Severity: High]
This problem wasn't introduced by this patch, but candamos_sysfs_add_quota_score()just below hit a similar double-read race onsysfs_goal->target_value[1]?mm/damon/sysfs-schemes.c:damos_sysfs_add_quota_score() { ... if (!sysfs_goal->target_value) continue; goal = damos_new_quota_goal(sysfs_goal->metric, sysfs_goal->target_value); ... }
target_value_store()updatessysfs_goal->target_valuewithout holdingdamon_sysfs_lock:CPU0 CPU1
damos_sysfs_add_quota_score()
if (!sysfs_goal->target_value)target_value_store() kstrtoul(..., &goal->target_value) damos_new_quota_goal(..., sysfs_goal->target_value) ... damos_quota_score() mult_frac(..., goal->target_value) <-- divide-by-zero
Quoted 6 lines
If a concurrent write sets
sysfs_goal->target_valueto 0 between the check and the second read,damos_new_quota_goal()creates a goal with a zerotarget_value, which later causes a divide-by-zero indamos_quota_score().sysfs_goal->metricis also read twice indamos_sysfs_add_quota_score(), so a concurrentmetric_store()betweendamos_new_quota_goal()and the switch can leavegoal->nidorgoal->current_valueuninitialized.
No. damon_sysfs_valid_start_ctx() [1] avoids the divide-by-zero.
[1] https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
[1] https://sashiko.dev/#/bug/linux-7f814c9a-986f-4103-a55a-ef9537dcf62b
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Thanks,
SJ
Re: [PATCH 6.18.y 3/5] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
In reply to SJ ParkQuoted 1 line
mm/damon/sysfs-schemes: readsysfs_filter->sz_rangeonly once
Queued for 6.18, thanks.
Signature · 2 lines
Thanks, Sasha
SJ Park
maintainerPATCH 4/5 mm/damon/core: remove unreachable damos charge_{target,addr}_from
In reply to SJ Parkdamos_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.
--- mm/damon/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
mm/damon/core.c +22 -0
@@ -2261,6 +2261,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;
@@ -2297,6 +2317,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 (!c->ops.get_scheme_score)return ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6.18.y 4/5] mm/damon/core: remove unreachable damos charge_{target,addr}_from
Sashiko has reviewed this patch and found no issues.
Quoted 22 lines
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 tocharge_target_fromcould 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.
Quoted 8 lines
Fixes da87878010e5 ("mm/damon/sysfs: support online inputs update")Signed-off-by SJ Park <[email protected]>Signed-off-by Andrew Morton <[email protected]>Cc <[email protected]> # 5.19.x(cherry picked from commit 5695abc4e742b947f586bfb6a080a80ad9957e5d)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
SJ Park
maintainerPATCH 5/5 mm/damon/core: filter out damos address filter-split failed region
In reply to SJ ParkWhen an address type DAMOS filter is configured, DAMOS tries to split the region for the filter range, and apply DAMOS action to the filter-in region. The split operation (damon_split_region_at()) could fail from allocation failure under extreme memory pressure. In the case, DAMOS action could be applied more or less than expected, ignoring the address filter.
The issue only rarely happens under extreme memory pressure. No crash or leak happens. Occasionally not applying the action to a few regions shouldn't be a real problem. But applying the action to a region that the user has excluded via address filter could be a surprise depending on the use case. It is only theoretical. No such real case is found yet.
Filter out the entire region if the split is failed. Update damos_filter_match() signature to receive the error from split. Also update kunit tests for the updated signature.
The issue was discovered [1] by sashiko.
--- mm/damon/core.c | 16 ++++++++++++---- mm/damon/tests/core-kunit.h | 16 +++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-)
mm/damon/core.c +12 -4
@@ -1812,13 +1812,14 @@ static void damos_update_stat(struct damos *s,static bool damos_filter_match (struct damon_ctx *ctx,struct damon_target *t,struct damon_region *r,struct damos_filter *filter, -unsigned long min_sz_region) +unsigned long min_sz_region,int *err) {bool matched = false;struct damon_target *ti;int target_idx =0 ;unsigned long start, end; + *err =0 ;switch (filter->type) {case DAMOS_FILTER_TYPE_TARGET :damon_for_each_target (ti, ctx) {
@@ -1844,12 +1845,13 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t, }/* start before the range and overlap */ if (r->ar.start < start) { -damon_split_region_at (t, r, start - r->ar.start); + *err =damon_split_region_at (t, r, + start - r->ar.start); matched = false;break ; }/* start inside the range */ -damon_split_region_at (t, r, end - r->ar.start); + *err =damon_split_region_at (t, r, end - r->ar.start); matched = true;break ;default :
@@ -1863,10 +1865,16 @@ static bool damos_filter_out(struct damon_ctx *ctx, struct damon_target *t, struct damon_region *r, struct damos *s) { struct damos_filter *filter; +bool matching; +int err; s->core_filters_allowed = false;damos_for_each_filter (filter, s) { -if (damos_filter_match (ctx, t, r, filter, ctx->min_sz_region)) { + matching =damos_filter_match (ctx, t, r, filter, + ctx->min_sz_region, &err); +if (err) +return true; +if (matching) {if (filter->allow) s->core_filters_allowed = true;return !filter->allow;
mm/damon/tests/core-kunit.h +11 -5
@@ -548,6 +548,7 @@ static void damos_test_filter_out(struct kunit *test)struct damon_target *t;struct damon_region *r, *r2;struct damos_filter *f; +int err; f =damos_new_filter (DAMOS_FILTER_TYPE_ADDR , true, false);if (!f)
@@ -570,28 +571,32 @@ static void damos_test_filter_out(struct kunit *test)/* region in the range */ KUNIT_EXPECT_TRUE (test, -damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION )); +damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION , + &err));KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 );/* region before the range */ r->ar.start =DAMON_MIN_REGION *1 ; r->ar.end =DAMON_MIN_REGION *2 ;KUNIT_EXPECT_FALSE (test, -damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION )); +damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION , + &err));KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 );/* region after the range */ r->ar.start =DAMON_MIN_REGION *6 ; r->ar.end =DAMON_MIN_REGION *8 ;KUNIT_EXPECT_FALSE (test, -damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION )); +damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION , + &err));KUNIT_EXPECT_EQ (test,damon_nr_regions (t),1 );/* region started before the range */ r->ar.start =DAMON_MIN_REGION *1 ; r->ar.end =DAMON_MIN_REGION *4 ;KUNIT_EXPECT_FALSE (test, -damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION )); +damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION , + &err));/* filter should have split the region */ KUNIT_EXPECT_EQ (test, r->ar.start,DAMON_MIN_REGION *1 );KUNIT_EXPECT_EQ (test, r->ar.end,DAMON_MIN_REGION *2 );
@@ -607,7 +612,8 @@ static void damos_test_filter_out(struct kunit *test) r->ar.start =DAMON_MIN_REGION *2 ; r->ar.end =DAMON_MIN_REGION *8 ;KUNIT_EXPECT_TRUE (test, -damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION )); +damos_filter_match (NULL , t, r, f,DAMON_MIN_REGION , + &err));/* filter should have split the region */ KUNIT_EXPECT_EQ (test, r->ar.start,DAMON_MIN_REGION *2 );KUNIT_EXPECT_EQ (test, r->ar.end,DAMON_MIN_REGION *6 );
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 6.18.y 5/5] mm/damon/core: filter out damos address filter-split failed region
Sashiko has reviewed this patch and found no issues.
Quoted 19 lines
When an address type DAMOS filter is configured, DAMOS tries to split the region for the filter range, and apply DAMOS action to the filter-in region. The split operation (
damon_split_region_at()) could fail from allocation failure under extreme memory pressure. In the case, DAMOS action could be applied more or less than expected, ignoring the address filter.The issue only rarely happens under extreme memory pressure. No crash or leak happens. Occasionally not applying the action to a few regions shouldn't be a real problem. But applying the action to a region that the user has excluded via address filter could be a surprise depending on the use case. It is only theoretical. No such real case is found yet.
Filter out the entire region if the split is failed. Update
damos_filter_match()signature to receive the error from split. Also update kunit tests for the updated signature.The issue was discovered [1] by sashiko.
Quoted 8 lines
Fixes ab9bda001b68 ("mm/damon/core: introduce address range type damos filter")Signed-off-by SJ Park <[email protected]>Signed-off-by Andrew Morton <[email protected]>Cc <[email protected]> # 6.6.x(cherry picked from commit bbeec2d8324d7aac438bb12dd2d22b184e0a8d43)Signed-off-by SJ Park <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5