From: Reinette Chatre <reinette.chatre@intel.com>
To: Richard Cheng <icheng@nvidia.com>,
Tony Luck <tony.luck@intel.com>, <shuah@kernel.org>
Cc: <Dave.Martin@arm.com>, <james.morse@arm.com>,
<babu.moger@amd.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <fenghuay@nvidia.com>,
<newtonl@nvidia.com>, <kristinc@nvidia.com>,
<kaihengf@nvidia.com>, <kobak@nvidia.com>,
<sdonthineni@nvidia.com>
Subject: Re: [PATCH 2/3] selftests/resctrl: Add L3_CAT_VALIDATE to check invalid CBMs
Date: Wed, 5 Aug 2026 15:35:06 -0700 [thread overview]
Message-ID: <23a738a3-85dd-4fdf-851e-3b875f48e70d@intel.com> (raw)
In-Reply-To: <20260608110641.44457-3-icheng@nvidia.com>
Hi Richard,
Thank you very much. This is useful.
On 6/8/26 4:06 AM, Richard Cheng wrote:
> A CAT allocation is a CBM, and the kernel must refuse masks that can't
> describe a valid allocation. Nothing in the suite check this.
>
> Implement L3_CAT_VALIDATE, first confirm a valid full mask is accepted,
How about "L3_CBM_VALIDATE"?
> then write an empty mask and a mask with bits outside cbm_mask and
> confirm each is refused. A mask below min_cbm_bits is also checked where
The empty mask is not always a valid test (more below).
> the platform needs more than one bit.
(nit: please write changelog in imperative tone)
>
> Signed-off-by: Richard Cheng <icheng@nvidia.com>
> ---
> tools/testing/selftests/resctrl/cat_test.c | 79 +++++++++++++++++++
> tools/testing/selftests/resctrl/resctrl.h | 1 +
> .../testing/selftests/resctrl/resctrl_tests.c | 1 +
> 3 files changed, 81 insertions(+)
>
> diff --git a/tools/testing/selftests/resctrl/cat_test.c b/tools/testing/selftests/resctrl/cat_test.c
> index 16a947f1ed16..d236988916d9 100644
> --- a/tools/testing/selftests/resctrl/cat_test.c
> +++ b/tools/testing/selftests/resctrl/cat_test.c
> @@ -603,3 +603,82 @@ struct resctrl_test l3_cat_occup_test = {
> .run_test = cat_occup_run_test,
> .cleanup = cat_occup_test_cleanup,
> };
> +
> +/*
> + * L3_CAT_VALIDATE - Verify the kernel rejects invalid L3 CBM writes.
> + *
> + * CAT allocation accepts a Capacity Bit Mask (CBM). The kernel must reject
> + * masks that cannot represent a valid allocation: an empty mask, a mask with
> + * bits outside cbm_mask, or (where the platform requires it) a mask with
> + * fewer than min_cbm_bits bits. A rejected schemata write makes
> + * write_schemata() return non-zero, which is the signal this test checks.
> + */
> +static int cat_validate_run_test(const struct resctrl_test *test,
All tests in this file are "cat" tests so this function name could be more
specific. How about "cbm_validate_run_test()"?
> + const struct user_params *uparams)
> +{
> + unsigned long full_mask, bad_mask;
> + unsigned int min_cbm_bits, start;
> + char schemata[64];
> + int count_of_bits, ret;
(reverse fir please)
> +
> + ret = get_full_cbm(test->resource, &full_mask);
> + if (ret)
> + return ret;
> +
> + ret = resource_info_unsigned_get(test->resource, "min_cbm_bits",
> + &min_cbm_bits);
> + if (ret)
> + return ret;
> +
> + count_of_bits = count_bits(full_mask);
> +
> + /* A valid full CBM must be accepted */
> + snprintf(schemata, sizeof(schemata), "%lx", full_mask);
> + if (write_schemata("", schemata, uparams->cpu, test->resource)) {
> + ksft_print_msg("Valid CBM 0x%lx was rejected\n", full_mask);
> + return 1;
KSFT_FAIL?
> + }
> +
> + /* An empty mask must be rejected. */
Some systems do support an empty mask (AMD) so this needs to depend on min_cbm_bits
being larger than zero.
> + if (!write_schemata("", "0", uparams->cpu, test->resource)) {
> + ksft_print_msg("Empty CBM was accepted, must be rejected\n");
> + return 1;
> + }
> +
> + /* A mask with a bit outside cbm_mask must be rejected. */
> + bad_mask = full_mask | (1UL << count_of_bits);
> + snprintf(schemata, sizeof(schemata), "%lx", bad_mask);
> + if (!write_schemata("", schemata, uparams->cpu, test->resource)) {
> + ksft_print_msg("Out-of-range CBM 0x%lx was accepted, must be rejected\n",
> + bad_mask);
> + return 1;
KSFT_FAIL?
> + }
> +
> + /*
> + * A mask with fewer than min_cbm_bits bits must be rejected. When
> + * min_cbm_bits is 1 the only sub-minimum mask is the empty mask
> + * This case only applies when the platform requires more contiguous bits.
> + */
> + if (min_cbm_bits > 1) {
> + count_contiguous_bits(full_mask, &start);
The return value should be checked here to ensure that the create_bit_mask() below
is valid.
> + bad_mask = create_bit_mask(start, min_cbm_bits - 1);
> + snprintf(schemata, sizeof(schemata), "%lx", bad_mask);
> + if (!write_schemata("", schemata, uparams->cpu, test->resource)) {
> + ksft_print_msg("CBM 0x%lx with too few bits was accepted\n",
> + bad_mask);
> + return 1;
KSFT_FAIL?
> + }
> + }
> +
> + ksft_print_msg("Pass: CAT rejects invalid CBM writes\n");
> +
> + return 0;
> +}
> +
> +struct resctrl_test l3_cat_validate_test = {
> + .name = "L3_CAT_VALIDATE",
> + .group = "CAT",
> + .resource = "L3",
> + .feature_check = test_resource_feature_check,
> + .run_test = cat_validate_run_test,
> +};
> diff --git a/tools/testing/selftests/resctrl/resctrl.h b/tools/testing/selftests/resctrl/resctrl.h
> index ce3abf0bdac2..e2e3cf7833bc 100644
> --- a/tools/testing/selftests/resctrl/resctrl.h
> +++ b/tools/testing/selftests/resctrl/resctrl.h
> @@ -248,6 +248,7 @@ extern struct resctrl_test mba_test;
> extern struct resctrl_test cmt_test;
> extern struct resctrl_test l3_cat_test;
> extern struct resctrl_test l3_cat_occup_test;
> +extern struct resctrl_test l3_cat_validate_test;
> extern struct resctrl_test l3_noncont_cat_test;
> extern struct resctrl_test l2_noncont_cat_test;
>
> diff --git a/tools/testing/selftests/resctrl/resctrl_tests.c b/tools/testing/selftests/resctrl/resctrl_tests.c
> index 324a60818aa1..66739e96f33c 100644
> --- a/tools/testing/selftests/resctrl/resctrl_tests.c
> +++ b/tools/testing/selftests/resctrl/resctrl_tests.c
> @@ -20,6 +20,7 @@ static struct resctrl_test *resctrl_tests[] = {
> &cmt_test,
> &l3_cat_test,
> &l3_cat_occup_test,
> + &l3_cat_validate_test,
> &l3_noncont_cat_test,
> &l2_noncont_cat_test,
> };
Thank you.
Reinette
next prev parent reply other threads:[~2026-08-05 22:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-08 11:06 [PATCH 0/3] selftests/resctrl: increase L3 cache test coverage Richard Cheng
2026-06-08 11:06 ` [PATCH 1/3] selftests/resctrl: Add L3_CAT_OCCUP test to verify CAT bounds occupancy Richard Cheng
2026-08-05 22:18 ` Reinette Chatre
2026-08-10 4:22 ` Richard Cheng
2026-06-08 11:06 ` [PATCH 2/3] selftests/resctrl: Add L3_CAT_VALIDATE to check invalid CBMs Richard Cheng
2026-08-05 22:35 ` Reinette Chatre [this message]
2026-06-08 11:06 ` [PATCH 3/3] selftests/resctrl: Add L3_BIT_USAGE to check bit_usage tracks allocation Richard Cheng
2026-08-05 22:37 ` Reinette Chatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23a738a3-85dd-4fdf-851e-3b875f48e70d@intel.com \
--to=reinette.chatre@intel.com \
--cc=Dave.Martin@arm.com \
--cc=babu.moger@amd.com \
--cc=fenghuay@nvidia.com \
--cc=icheng@nvidia.com \
--cc=james.morse@arm.com \
--cc=kaihengf@nvidia.com \
--cc=kobak@nvidia.com \
--cc=kristinc@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=newtonl@nvidia.com \
--cc=sdonthineni@nvidia.com \
--cc=shuah@kernel.org \
--cc=tony.luck@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®