* [PATCH] selftests: riscv: Handle a missing IMA_EXT_1 in which-cpus
@ 2026-12-04 12:41 Christian Sagstetter
2026-12-04 19:44 ` Clement Leger
0 siblings, 1 reply; 2+ messages in thread
From: Christian Sagstetter @ 2026-12-04 12:41 UTC (permalink / raw)
To: Shuah Khan, Paul Walmsley
Cc: Palmer Dabbelt, Albert Ou, Alexandre Ghiti, linux-kselftest,
linux-riscv, Andrew Jones
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")
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--;
+ } 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
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] selftests: riscv: Handle a missing IMA_EXT_1 in which-cpus
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
0 siblings, 0 replies; 2+ messages in thread
From: Clement Leger @ 2026-12-04 19:44 UTC (permalink / raw)
To: Christian Sagstetter, Shuah Khan, Paul Walmsley
Cc: Palmer Dabbelt, Albert Ou, Alexandre Ghiti, linux-kselftest,
linux-riscv, Andrew Jones
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 19:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox