Skip to content

Commit 210860e

Browse files
committed
selftests: vDSO: check cpu caps before running chacha test
Some archs -- arm64 and s390x -- implemented chacha using instructions that are available most places, but aren't always available. The kernel handles this just fine, but the selftest does not. Check the hwcaps before running, and skip the test if the cpu doesn't support it. As well, on s390x, always emit the fallback instructions of an alternative block, to ensure maximum compatibility. Co-developed-by: Heiko Carstens <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent b920aa7 commit 210860e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tools/include/asm/alternative.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22
#ifndef _TOOLS_ASM_ALTERNATIVE_ASM_H
33
#define _TOOLS_ASM_ALTERNATIVE_ASM_H
44

5+
#if defined(__s390x__)
6+
#ifdef __ASSEMBLY__
7+
.macro ALTERNATIVE oldinstr, newinstr, feature
8+
\oldinstr
9+
.endm
10+
#endif
11+
#else
12+
513
/* Just disable it so we can build arch/x86/lib/memcpy_64.S for perf bench: */
614

715
#define ALTERNATIVE #
816

917
#endif
18+
19+
#endif

tools/testing/selftests/vDSO/vdso_test_chacha.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55

66
#include <tools/le_byteshift.h>
77
#include <sys/random.h>
8+
#include <sys/auxv.h>
89
#include <string.h>
910
#include <stdint.h>
1011
#include <stdbool.h>
1112
#include "../kselftest.h"
1213

14+
#if defined(__aarch64__)
15+
static bool cpu_has_capabilities(void)
16+
{
17+
return getauxval(AT_HWCAP) & HWCAP_ASIMD;
18+
}
19+
#elif defined(__s390x__)
20+
static bool cpu_has_capabilities(void)
21+
{
22+
return getauxval(AT_HWCAP) & HWCAP_S390_VXRS;
23+
}
24+
#else
25+
static bool cpu_has_capabilities(void)
26+
{
27+
return true;
28+
}
29+
#endif
30+
1331
static uint32_t rol32(uint32_t word, unsigned int shift)
1432
{
1533
return (word << (shift & 31)) | (word >> ((-shift) & 31));
@@ -67,6 +85,8 @@ int main(int argc, char *argv[])
6785
uint8_t output1[BLOCK_SIZE * BLOCKS], output2[BLOCK_SIZE * BLOCKS];
6886

6987
ksft_print_header();
88+
if (!cpu_has_capabilities())
89+
ksft_exit_skip("Required CPU capabilities missing\n");
7090
ksft_set_plan(1);
7191

7292
for (unsigned int trial = 0; trial < TRIALS; ++trial) {

0 commit comments

Comments
 (0)