From: Clement Leger <clement.leger@linux.dev>
To: Christian Sagstetter <christian.sagstetter@gmail.com>,
Shuah Khan <shuah@kernel.org>, Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org,
Andrew Jones <andrew.jones@oss.qualcomm.com>
Subject: Re: [PATCH] selftests: riscv: Handle a missing IMA_EXT_1 in which-cpus
Date: Fri, 4 Dec 2026 20:44:51 +0100 [thread overview]
Message-ID: <d504117f-c34e-4963-9e5f-6a191ab73dbd@linux.dev> (raw)
In-Reply-To: <20261204124130.1830295-1-christian.sagstetter@gmail.com>
On 12/4/26 13:41, Christian Sagstetter wrote:
> Kernels that support RISCV_HWPROBE_WHICH_CPUS can predate IMA_EXT_1.
> They return -1 in the key field when asked for the extension bitmap.
> The which-cpus selftest asserts that the key is recognized and aborts
> before running any of its seven checks.
>
> Omit the last key from the three CPU filter queries when the probe
> reports it as unknown. Keep using IMA_EXT_1 when recognized, including
> when its bitmap is zero.
>
> On a two-CPU riscv64 QEMU guest running Linux 6.12.117, the original
> test aborts and the updated test passes all seven checks. On Linux
> 7.0.13 both versions pass all seven checks with IMA_EXT_1 available.
>
> Codex identified the compatibility issue, drafted the change and commit
> message, and ran the before-and-after tests.
>
> Fixes: 462a94fb8ae8 ("riscv: hwprobe: add support for RISCV_HWPROBE_KEY_IMA_EXT_1")
Hi Christian,
While this indeed fixes the test, I'm not sure it fully qualifies as
"Fixes" the commit functionality itself. ie only the kselftest is fixed,
the existing hwprobe behavior is still correct.
> Signed-off-by: Christian Sagstetter <christian.sagstetter@gmail.com>
> ---
> .../selftests/riscv/hwprobe/which-cpus.c | 18 ++++++++++++++----
> 1 file changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/riscv/hwprobe/which-cpus.c b/tools/testing/selftests/riscv/hwprobe/which-cpus.c
> index 587feb198..4a8222a33 100644
> --- a/tools/testing/selftests/riscv/hwprobe/which-cpus.c
> +++ b/tools/testing/selftests/riscv/hwprobe/which-cpus.c
> @@ -84,6 +84,7 @@ static void do_which_cpus(int argc, char **argv, cpu_set_t *cpus)
> int main(int argc, char **argv)
> {
> struct riscv_hwprobe pairs[3];
> + size_t nr_filter_pairs = ARRAY_SIZE(pairs);
> cpu_set_t cpus_aff, cpus;
> __u64 ext0_all, ext1_all;
> long rc;
> @@ -114,7 +115,13 @@ int main(int argc, char **argv)
>
> pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, };
> rc = riscv_hwprobe(pairs, 1, 0, NULL, 0);
> - assert(rc == 0 && pairs[0].key == RISCV_HWPROBE_KEY_IMA_EXT_1);
> + assert(rc == 0);
> + if (pairs[0].key == -1) {
> + ksft_print_msg("IMA_EXT_1 unavailable, omitting it from CPU filters\n");
> + nr_filter_pairs--;
nit: That remains tied to the lines below (ie pairs[2] contains the
RISCV_HWPROBE_KEY_IMA_EXT_1 key). Maybe something more robust would be
nice like zeroing/invalidting the key or whatever. If someone adds
another key after that in future extensions, it will break again. But if
that's the only way to do it, that's fine.
> + } else {
> + assert(pairs[0].key == RISCV_HWPROBE_KEY_IMA_EXT_1);
> + }
> ext1_all = pairs[0].value;
>
> pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
> @@ -141,21 +148,24 @@ int main(int argc, char **argv)
> pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ext0_all, };
> pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ext1_all, };
> CPU_ZERO(&cpus);
> - rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
> + rc = riscv_hwprobe(pairs, nr_filter_pairs, sizeof(cpus), (unsigned long *)&cpus,
> + RISCV_HWPROBE_WHICH_CPUS);
> ksft_test_result(rc == 0 && CPU_COUNT(&cpus) == sysconf(_SC_NPROCESSORS_ONLN), "set all cpus\n");
>
> pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
> pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ext0_all, };
> pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ext1_all, };
> memcpy(&cpus, &cpus_aff, sizeof(cpu_set_t));
> - rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
> + rc = riscv_hwprobe(pairs, nr_filter_pairs, sizeof(cpus), (unsigned long *)&cpus,
> + RISCV_HWPROBE_WHICH_CPUS);
> ksft_test_result(rc == 0 && CPU_EQUAL(&cpus, &cpus_aff), "set all affinity cpus\n");
>
> pairs[0] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_BASE_BEHAVIOR, .value = RISCV_HWPROBE_BASE_BEHAVIOR_IMA, };
> pairs[1] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_0, .value = ~ext0_all, };
> pairs[2] = (struct riscv_hwprobe){ .key = RISCV_HWPROBE_KEY_IMA_EXT_1, .value = ~ext1_all, };
> memcpy(&cpus, &cpus_aff, sizeof(cpu_set_t));
> - rc = riscv_hwprobe(pairs, 3, sizeof(cpu_set_t), (unsigned long *)&cpus, RISCV_HWPROBE_WHICH_CPUS);
> + rc = riscv_hwprobe(pairs, nr_filter_pairs, sizeof(cpus), (unsigned long *)&cpus,
> + RISCV_HWPROBE_WHICH_CPUS);
> ksft_test_result(rc == 0 && CPU_COUNT(&cpus) == 0, "clear all cpus\n");
>
> ksft_finished();
>
> base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
Reviewed-by: Clément Léger <clement.leger@linux.dev>
Thanks,
Clément
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
prev parent reply other threads:[~2026-12-04 19:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 12:41 [PATCH] selftests: riscv: Handle a missing IMA_EXT_1 in which-cpus Christian Sagstetter
2026-12-04 19:44 ` Clement Leger [this message]
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=d504117f-c34e-4963-9e5f-6a191ab73dbd@linux.dev \
--to=clement.leger@linux.dev \
--cc=alex@ghiti.fr \
--cc=andrew.jones@oss.qualcomm.com \
--cc=aou@eecs.berkeley.edu \
--cc=christian.sagstetter@gmail.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=shuah@kernel.org \
/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