From nobody Sat Sep 26 14:38:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DE66415F2E; Mon, 31 Aug 2026 15:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788188820; cv=none; b=c1XnZlQZ7W1sA4hUg745tzH3Vi1WdkujBIxZmfkgExlyUvQz4FZGTlkWzUJJ+lOq2aItr56UCEzd+WlrtUK4aCUjKDhHlXGlrtT+D/76mBtiKs9PbtL8d13vG3Jc/PS7Wm8BnutY8PbzUWWg4PEQggYto1011/6hgYF5jzvvd+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788188820; c=relaxed/simple; bh=5BPXTzgLt6Bl0eASrNOswsCfWT2dHB4EvDyCD00H+jI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kwphveO1chhAx7kWlSlOMnwPLAhV5wBzoHWNZcHYPuS8iE1SU113efBRKKOLBwgfozE618vrqzSdecOlOL8l2ggqVb9lGBmQVStvRNV+HovFJ/TK8OUokyFlFkQ67n4G0vh69czfQE0syNVQBUjbSdqO05+DbtpqSlj5YqKZayA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XDfT2val; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XDfT2val" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92CC01F00A3D; Mon, 31 Aug 2026 15:06:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788188818; bh=eijFprEn5vtvf/LMCpMXuJKzdfeHNzAGCtIabB6fjsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XDfT2valRq0ffCXEwmL39LKtmFGpqdNyt06q3bmYE66NkaTSfgTfwbjQeKlKNAhQt y4z1ah38eDZ48aX30QXLYfLnrbg8si31mjn1NSilOdX7YP/P/cSO5IsJiIPF7+M9Dv 9SmG82tY2XOAdAu/0TlhX1fO0NRcpMVo/r+Jxmp21iREl4rGlaPNSnK8BxrIjvPV2K l9R7ZvHuh48Y1gpZYgXfokb6+RDVmL2qLXmmaeHbOaZHBm2MR2pfoJkbugUxf2zZkg PZnuc6mAik0dHc1jbHuMP1LqirxB+Z3F1OGJGOLKxWVjBqem4NLlRZKI3oGBWdTpg1 37hcR4LuGULHQ== From: SJ Park To: Andrew Morton Cc: Jason Angelov , Brendan Higgins , David Gow , SJ Park , damon@lists.linux.dev, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 1/2] mm/damon/core-kunit: test probe_hits handling at region split and merge Date: Mon, 31 Aug 2026 08:06:48 -0700 Message-ID: <20260831150650.84829-2-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260831150650.84829-1-sj@kernel.org> References: <20260831150650.84829-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Angelov damon_split_region_at() copies probe_hits[] and last_probe_hits[] to the new split region. damon_merge_two_regions() sets probe_hits[] to the size-weighted average of the merged regions. Extend damon_test_split_at() and damon_test_merge_two() tests to cover those fields. Signed-off-by: Jason Angelov Reviewed-by: SJ Park Signed-off-by: SJ Park --- mm/damon/tests/core-kunit.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index ec7260a3bfea8..68591ca99a4f7 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -152,6 +152,8 @@ static void damon_test_split_at(struct kunit *test) } r->nr_accesses =3D 42; r->last_nr_accesses =3D 15; + r->probe_hits[0] =3D 7; + r->last_probe_hits[0] =3D 3; r->age =3D 10; damon_add_region(r, t); damon_split_region_at(t, r, 25); @@ -168,6 +170,8 @@ static void damon_test_split_at(struct kunit *test) =20 KUNIT_EXPECT_EQ(test, r->nr_accesses, r_new->nr_accesses); KUNIT_EXPECT_EQ(test, r->last_nr_accesses, r_new->last_nr_accesses); + KUNIT_EXPECT_EQ(test, r->probe_hits[0], r_new->probe_hits[0]); + KUNIT_EXPECT_EQ(test, r->last_probe_hits[0], r_new->last_probe_hits[0]); KUNIT_EXPECT_EQ(test, r->age, r_new->age); =20 out: @@ -189,6 +193,7 @@ static void damon_test_merge_two(struct kunit *test) kunit_skip(test, "region alloc fail"); } r->nr_accesses =3D 10; + r->probe_hits[0] =3D 6; r->age =3D 9; damon_add_region(r, t); r2 =3D damon_new_region(100, 300); @@ -197,6 +202,7 @@ static void damon_test_merge_two(struct kunit *test) kunit_skip(test, "second region alloc fail"); } r2->nr_accesses =3D 20; + r2->probe_hits[0] =3D 14; r2->age =3D 21; damon_add_region(r2, t); =20 @@ -204,6 +210,7 @@ static void damon_test_merge_two(struct kunit *test) KUNIT_EXPECT_EQ(test, r->ar.start, 0ul); KUNIT_EXPECT_EQ(test, r->ar.end, 300ul); KUNIT_EXPECT_EQ(test, r->nr_accesses, 16u); + KUNIT_EXPECT_EQ(test, r->probe_hits[0], 11); KUNIT_EXPECT_EQ(test, r->age, 17u); =20 i =3D 0; --=20 2.47.3 From nobody Sat Sep 26 14:38:01 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B7C951A72F; Mon, 31 Aug 2026 15:06:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788188820; cv=none; b=tVJxAqwS148v0ZDtB2gq4JT599bB4IhM83QTtE+CYbOgDXJUHGnVuQ8VIEHaeO09Sm+naaV3P5ElVoS/Q8TU2l8/dMqvUo70XfWomv5giow2cjt6Q5tdzMkRYw1hYZQODYHS67FwtJ13LbOWLRzLwENxPHkj0YRZqWJsQidJtqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788188820; c=relaxed/simple; bh=/m2MgfqcWMXWTS3rOf2JdJxa1KYmjpJgfVfa99jugPM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mnclsjet43V1Ju/og6U0XiC4guqlwvnVnzofpF7pCsjG/1vLvIp58McyIufRfWkGWdRr2GFnlLEod6XwXHotkMch5pzSHrL3RuHZ2RFNWZfL+z2WKV7zQu4nQ37UPGwHdmJQsRoXZsxONepZSf33B4beTZUKZCN6KSgdKiLvRIo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F5wScyc6; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F5wScyc6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 119F51F00A3F; Mon, 31 Aug 2026 15:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788188819; bh=o7lIq+lsQYzbYzf+cqUQ249deMwzfBwDjcIr5FOU1kQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F5wScyc6VUkcQzeNeObcmSoumA5UwCUlKoqWQIJjXLhYY/NhNn0CVz16iLB6Wof5X OVbAR8k2fpqNpOlw8oKOWNbtpgLrFd76oQ4H0cv34bKVOU8Twv0chFMJsgWvfk/PLP +Y8dF45RzxRUn3tlrqfTrFCLv9XnBsnjWxG6nf4WcmqBLEJtMgQS+5pE53CGvhVPSf fsnGoVnyVVwT/n1NZD9f6PU+O4e0k5p+6U16ExhiX+lWBunFoXtCTCV+/cBa4spfb+ s8TVCYgOvdvblvVqxU62Sin/thY7oQUGByap+TxLzaHqDjUEYwf5HkFZz+zFqqIWDz 0OFFIq2lQutSw== From: SJ Park To: Andrew Morton Cc: Jason Angelov , Brendan Higgins , David Gow , SJ Park , damon@lists.linux.dev, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 2/2] mm/damon/core-kunit: test damon_valid_probe_params() Date: Mon, 31 Aug 2026 08:06:49 -0700 Message-ID: <20260831150650.84829-3-sj@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260831150650.84829-1-sj@kernel.org> References: <20260831150650.84829-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jason Angelov damon_valid_probe_params() makes damon_commit_ctx() reject probe configurations that could overflow a probe_hits counter, a single (weight * probe_hits) product, or the sum of those products. Add a kunit test covering each rejection at its boundary: - samples per aggregation interval: U8_MAX is allowed, one more could overflow a probe_hits counter - single weight: the largest whose product fits in unsigned int is allowed, one larger is rejected - multiple probes: each product fits, but their sum overflows - no weight set: the validation is skipped Signed-off-by: Jason Angelov Reviewed-by: SJ Park Signed-off-by: SJ Park --- mm/damon/tests/core-kunit.h | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h index 68591ca99a4f7..af26b3d60957b 100644 --- a/mm/damon/tests/core-kunit.h +++ b/mm/damon/tests/core-kunit.h @@ -1341,6 +1341,62 @@ static void damon_test_commit_ctx(struct kunit *test) damon_destroy_ctx(dst); } =20 +static void damon_test_valid_probe_params(struct kunit *test) +{ + struct damon_ctx *ctx; + struct damon_probe *probe, *probe2; + + ctx =3D damon_new_ctx(); + if (!ctx) + kunit_skip(test, "ctx alloc fail"); + probe =3D damon_new_probe(); + if (!probe) { + damon_destroy_ctx(ctx); + kunit_skip(test, "probe alloc fail"); + } + damon_add_probe(ctx, probe); + + /* Parameters are validated only if any probe weight is set. */ + ctx->attrs.sample_interval =3D 1; + ctx->attrs.aggr_interval =3D 1000000; + KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx)); + + /* Up to U8_MAX samples per aggregation interval are allowed. */ + probe->weight =3D 100; + ctx->attrs.aggr_interval =3D 255; + KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx)); + + /* More samples could overflow the probe_hits counters. */ + ctx->attrs.aggr_interval =3D 256; + KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx)); + + /* The largest weight whose weighted hit count fits in unsigned int. */ + ctx->attrs.aggr_interval =3D 255; + probe->weight =3D UINT_MAX / 255; + KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx)); + + /* Any larger weight could overflow its weighted hit count. */ + probe->weight =3D UINT_MAX / 255 + 1; + KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx)); + + /* With one sample per aggregation, even the largest weight fits. */ + ctx->attrs.aggr_interval =3D 1; + probe->weight =3D UINT_MAX; + KUNIT_EXPECT_TRUE(test, damon_valid_probe_params(ctx)); + + /* The sum of all probes' weighted hit counts could also overflow. */ + probe2 =3D damon_new_probe(); + if (!probe2) { + damon_destroy_ctx(ctx); + kunit_skip(test, "probe2 alloc fail"); + } + probe2->weight =3D 1; + damon_add_probe(ctx, probe2); + KUNIT_EXPECT_FALSE(test, damon_valid_probe_params(ctx)); + + damon_destroy_ctx(ctx); +} + static void damos_test_filter_out(struct kunit *test) { struct damon_target *t; @@ -1667,6 +1723,7 @@ static struct kunit_case damon_test_cases[] =3D { KUNIT_CASE(damos_test_commit_migrate_hot), KUNIT_CASE(damon_test_commit_target_regions), KUNIT_CASE(damon_test_commit_ctx), + KUNIT_CASE(damon_test_valid_probe_params), KUNIT_CASE(damos_test_filter_out), KUNIT_CASE(damon_test_feed_loop_next_input), KUNIT_CASE(damon_test_set_filters_default_reject), --=20 2.47.3