linux/tools/testing/selftests/arm64/signal/sve_helpers.c
Andre Przywara 5225b6562b kselftest/arm64: signal: fix/refactor SVE vector length enumeration
Currently a number of SVE/SME related tests have almost identical
functions to enumerate all supported vector lengths. However over time
the copy&pasted code has diverged, allowing some bugs to creep in:
- fake_sigreturn_sme_change_vl reports a failure, not a SKIP if only
  one vector length is supported (but the SVE version is fine)
- fake_sigreturn_sme_change_vl tries to set the SVE vector length, not
  the SME one (but the other SME tests are fine)
- za_no_regs keeps iterating forever if only one vector length is
  supported (but za_regs is correct)

Since those bugs seem to be mostly copy&paste ones, let's consolidate
the enumeration loop into one shared function, and just call that from
each test. That should fix the above bugs, and prevent similar issues
from happening again.

Fixes: 4963aeb35a ("kselftest/arm64: signal: Add SME signal handling tests")
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20240821164401.3598545-1-andre.przywara@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
2024-08-23 11:34:55 +01:00

56 lines
1.3 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2024 ARM Limited
*
* Common helper functions for SVE and SME functionality.
*/
#include <stdbool.h>
#include <kselftest.h>
#include <asm/sigcontext.h>
#include <sys/prctl.h>
unsigned int vls[SVE_VQ_MAX];
unsigned int nvls;
int sve_fill_vls(bool use_sme, int min_vls)
{
int vq, vl;
int pr_set_vl = use_sme ? PR_SME_SET_VL : PR_SVE_SET_VL;
int len_mask = use_sme ? PR_SME_VL_LEN_MASK : PR_SVE_VL_LEN_MASK;
/*
* Enumerate up to SVE_VQ_MAX vector lengths
*/
for (vq = SVE_VQ_MAX; vq > 0; --vq) {
vl = prctl(pr_set_vl, vq * 16);
if (vl == -1)
return KSFT_FAIL;
vl &= len_mask;
/*
* Unlike SVE, SME does not require the minimum vector length
* to be implemented, or the VLs to be consecutive, so any call
* to the prctl might return the single implemented VL, which
* might be larger than 16. So to avoid this loop never
* terminating, bail out here when we find a higher VL than
* we asked for.
* See the ARM ARM, DDI 0487K.a, B1.4.2: I_QQRNR and I_NWYBP.
*/
if (vq < sve_vq_from_vl(vl))
break;
/* Skip missing VLs */
vq = sve_vq_from_vl(vl);
vls[nvls++] = vl;
}
if (nvls < min_vls) {
fprintf(stderr, "Only %d VL supported\n", nvls);
return KSFT_SKIP;
}
return KSFT_PASS;
}