* [PATCH v1.1] mm/damon/core: handle region split failure in apply_min_nr_regions()
@ 2026-07-19 15:54 SJ Park
0 siblings, 0 replies; only message in thread
From: SJ Park @ 2026-07-19 15:54 UTC (permalink / raw)
To: Andrew Morton; +Cc: SJ Park, stable, damon, linux-kernel, linux-mm
damon_apply_min_nr_regions() repeatedly split each region until its size
becomes small enough to meet the user-defined low limit of the number of
regions. The loop assumes the split operation (damon_split_region_at())
will always succeed and create the new region. But the operation could
silently fail for memory allocation failures, for example.
If such failure happens and the region was the last region, the linked
list-based next region fetching returns invalid pointer. As a result,
invalid memory dereference and corruption could happen. Even if the
corner case is handled, it imposes stress to the allocator by trying
split regions for other targets. Fix the issue by breaking all the
loops for any region split failure.
This means there could be a min_nr_regions violation. It will only
rarely happen since the allocation is arguably too small to fail. Even
if it happens, it is only temporal. damon_apply_min_nr_regions() will
be called again after the aggregation interval.
The user impact of the issue should be minor, since the allocation is
arguably too small to fail. But, it could still theoretically happen,
and the consequence is very bad.
This issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260717011834.120715-1-sj@kernel.org
Fixes: b1029f29eb1d ("mm/damon/core: split regions for min_nr_regions")
Cc: <stable@vger.kernel.org> # 7.1.x
Signed-off-by: SJ Park <sj@kernel.org>
---
Changes from v1
- v1: https://lore.kernel.org/20260718001442.87129-1-sj@kernel.org
- Break all loops for any allocation failure to reduce allocator stress.
- Rebase to latest mm-new.
Changes from RFC v1
- RFC v1: https://lore.kernel.org/20260718004301.88883-1-sj@kernel.org
- Drop RFC tag.
- Rebase to the latest mm-new.
mm/damon/core.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 20d267c615faf..e0122376f43d4 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1886,7 +1886,7 @@ static unsigned long damon_region_sz_limit(struct damon_ctx *ctx)
return sz;
}
-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);
/*
@@ -1912,11 +1912,13 @@ static unsigned long damon_apply_min_nr_regions(struct damon_ctx *ctx)
damon_for_each_target(t, ctx) {
damon_for_each_region_safe(r, next, t) {
while (damon_sz_region(r) > max_region_sz) {
- damon_split_region_at(t, r, max_region_sz);
+ if (damon_split_region_at(t, r, max_region_sz))
+ goto out;
r = damon_next_region(r);
}
}
}
+out:
return max_region_sz;
}
@@ -3411,8 +3413,10 @@ static void damon_verify_split_region_at(struct damon_region *r,
*
* 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;
@@ -3420,7 +3424,7 @@ static void damon_split_region_at(struct damon_target *t,
damon_verify_split_region_at(r, sz_r);
new = damon_new_region(r->ar.start + sz_r, r->ar.end);
if (!new)
- return;
+ return -ENOMEM;
r->ar.end = new->ar.start;
@@ -3433,6 +3437,7 @@ static void damon_split_region_at(struct damon_target *t,
sizeof(r->last_probe_hits));
damon_insert_region(new, r, damon_next_region(r), t);
+ return 0;
}
/* Split every region in the given target into 'nr_subs' regions */
base-commit: 1111bc7bc679131632fe9f436f4c990e8b86bee5
--
2.47.3
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-19 15:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-19 15:54 [PATCH v1.1] mm/damon/core: handle region split failure in apply_min_nr_regions() SJ Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox