linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/core: disallow non-power of two min_region_sz
@ 2026-02-14 21:41 SeongJae Park
  0 siblings, 0 replies; only message in thread
From: SeongJae Park @ 2026-02-14 21:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: SeongJae Park, # 6 . 18 . x, Quanmin Yan, damon, linux-kernel, linux-mm

DAMON core uses min_region_sz parameter value as the DAMON region
alignment.  The alignment is made using ALIGN() and ALIGN_DOWN(), which
support only the power of two alignments.  But DAMON core API callers
can set min_region_sz to an arbitrary number.  Users can also set it
indirectly, using addr_unit.

When the alignment is not properly set, DAMON behavior becomes difficult
to expect and understand, makes it effectively broken.  It doesn't cause
a kernel crash-like significant issue, though.

Fix the issue by disallowing min_region_sz input that is not a power of
two.  Add the check to damon_commit_ctx(), as all DAMON API callers who
set min_region_sz uses the function.

This can be a sort of behavioral change, but it does not break users,
for the following reasons.  As the symptom is making DAMON effectively
broken, it is not reasonable to believe there are real use cases of
non-power of two min_region_sz.  There is no known use case or issue
reports from the setup, either.

In future, if we find real use cases of non-power of two alignments and
we can support it with low enough overhead, we can consider moving the
restriction.  But, for now, simply disallowing the corner case should be
good enough as a hot fix.

Fixes: d8f867fa0825 ("mm/damon: add damon_ctx->min_sz_region")
Cc: <stable@vger.kernel.org> # 6.18.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
 mm/damon/core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index 925908415a041..55cbf86476006 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -1252,6 +1252,9 @@ int damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src)
 {
 	int err;
 
+	if (!is_power_of_2(src->min_region_sz))
+		return -EINVAL;
+
 	err = damon_commit_schemes(dst, src);
 	if (err)
 		return err;

base-commit: 918647226184ca20e5f86ee7d4df3e34c7433799
-- 
2.47.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-02-14 21:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-14 21:41 [PATCH] mm/damon/core: disallow non-power of two min_region_sz SeongJae Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox