* [PATCH 2/5] mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of()
2026-07-14 13:52 [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races SJ Park
@ 2026-07-14 13:52 ` SJ Park
2026-07-14 14:32 ` [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-07-14 13:52 UTC (permalink / raw)
To: Andrew Morton
Cc: SJ Park, stable, Brendan Higgins, David Gow, SeongJae Park, damon,
kunit-dev, linux-kernel, linux-kselftest, linux-mm
KUNIT_EXPECT_EQ() does not abort the execution of test code when the
expectation is not met. But damon_test_merge_regions_of() code after
its initial KUNIT_EXPECT_EQ() call assumes the expectation is met. It
does a per-region test with a hard-coded number of regions that is
correct only if the expectation was met. As a result, __nth_region_of()
could return NULL, and the test code can dereference NULL pointers. Fix
the issue by catching the expectation failure and skip the per-region
tests.
The user impact on realistic setups should be negligible, as it is a
unit test.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260710144937.26981-1-sj@kernel.org
Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests")
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: SJ Park <sj@kernel.org>
---
mm/damon/tests/core-kunit.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
index 485472ddebd19..eba643762132f 100644
--- a/mm/damon/tests/core-kunit.h
+++ b/mm/damon/tests/core-kunit.h
@@ -260,11 +260,14 @@ static void damon_test_merge_regions_of(struct kunit *test)
damon_merge_regions_of(t, 9, 9999, ctx, true);
/* 0-112, 114-130, 130-156, 156-170, 170-230, 230-10170 */
KUNIT_EXPECT_EQ(test, damon_nr_regions(t), 6u);
+ if (damon_nr_regions(t) != 6)
+ goto out;
for (i = 0; i < 6; i++) {
r = __nth_region_of(t, i);
KUNIT_EXPECT_EQ(test, r->ar.start, saddrs[i]);
KUNIT_EXPECT_EQ(test, r->ar.end, eaddrs[i]);
}
+out:
damon_free_target(t);
damon_destroy_ctx(ctx);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races
2026-07-14 13:52 [PATCH 0/5] mm/damon: unurgent fixes for infinite loop, NULL de-ref and races SJ Park
2026-07-14 13:52 ` [PATCH 2/5] mm/damon/tests/core-kunit: catch test failure in test_merge_regions_of() SJ Park
@ 2026-07-14 14:32 ` SJ Park
1 sibling, 0 replies; 3+ messages in thread
From: SJ Park @ 2026-07-14 14:32 UTC (permalink / raw)
To: SJ Park
Cc: Andrew Morton, stable, Brendan Higgins, David Gow, Fernand Sieber,
Leonard Foerster, SeongJae Park, Shakeel Butt, damon, kunit-dev,
linux-kernel, linux-kselftest, linux-mm
On Tue, 14 Jul 2026 06:52:28 -0700 SJ Park <sj@kernel.org> wrote:
> Sashiko found a few issues in DAMON that could cause infinite loop, NULL
> dereference and monitoring results degradation. The first two sounds
> scary but the infinite loop happens only under unreasonable user setup.
> The NULL dereference is only in a unit test. Monitoring results
> degradation is trivial since it is only best-effort, and those happens
> from only unlikely races. Still those are bugs that better to fix if
> possible. Fix those.
Sashiko found one more bug that may better to be fixed together with this
series. Also patch 5 mistakenly lacks its Fixes: tag. I will post a new
version of this series with the fixes. Please don't pick this series into
mm-new for now.
Thanks,
SJ
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread