Skip to content

Commit 3b5992e

Browse files
zx2c4shuahkh
authored andcommitted
selftests: vDSO: unconditionally build chacha test
Rather than using symlinks to find the vgetrandom-chacha.S file for each arch, store this in a file that uses the compiler to determine architecture, and then make use of weak symbols to skip the test on architectures that don't provide the code. Signed-off-by: Jason A. Donenfeld <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent c66be90 commit 3b5992e

File tree

8 files changed

+26
-12
lines changed

8 files changed

+26
-12
lines changed

tools/arch/arm64/vdso

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/arch/loongarch/vdso

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/arch/powerpc/vdso

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/arch/s390/vdso

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/arch/x86/vdso

Lines changed: 0 additions & 1 deletion
This file was deleted.

tools/testing/selftests/vDSO/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ endif
1111
TEST_GEN_PROGS += vdso_test_correctness
1212
ifeq ($(ARCH)$(CONFIG_X86_32),$(filter $(ARCH)$(CONFIG_X86_32),x86 x86_64 loongarch arm64 powerpc s390))
1313
TEST_GEN_PROGS += vdso_test_getrandom
14-
TEST_GEN_PROGS += vdso_test_chacha
1514
endif
15+
TEST_GEN_PROGS += vdso_test_chacha
1616

1717
CFLAGS := -std=gnu99 -O2
1818

@@ -37,9 +37,9 @@ $(OUTPUT)/vdso_test_getrandom: CFLAGS += -isystem $(top_srcdir)/tools/include \
3737
$(KHDR_INCLUDES) \
3838
-isystem $(top_srcdir)/include/uapi
3939

40-
$(OUTPUT)/vdso_test_chacha: $(top_srcdir)/tools/arch/$(SRCARCH)/vdso/vgetrandom-chacha.S
40+
$(OUTPUT)/vdso_test_chacha: vgetrandom-chacha.S
4141
$(OUTPUT)/vdso_test_chacha: CFLAGS += -idirafter $(top_srcdir)/tools/include \
4242
-idirafter $(top_srcdir)/tools/include/generated \
4343
-idirafter $(top_srcdir)/arch/$(SRCARCH)/include \
4444
-idirafter $(top_srcdir)/include \
45-
-D__ASSEMBLY__ -Wa,--noexecstack
45+
-Wa,--noexecstack

tools/testing/selftests/vDSO/vdso_test_chacha.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (C) 2022-2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
44
*/
55

6+
#include <linux/compiler.h>
67
#include <tools/le_byteshift.h>
78
#include <sys/random.h>
89
#include <sys/auxv.h>
@@ -73,10 +74,10 @@ static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, u
7374
counter[1] = s[13];
7475
}
7576

76-
typedef uint8_t u8;
77-
typedef uint32_t u32;
78-
typedef uint64_t u64;
79-
#include <vdso/getrandom.h>
77+
void __weak __arch_chacha20_blocks_nostack(uint8_t *dst_bytes, const uint32_t *key, uint32_t *counter, size_t nblocks)
78+
{
79+
ksft_exit_skip("Not implemented on architecture\n");
80+
}
8081

8182
int main(int argc, char *argv[])
8283
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2024 Jason A. Donenfeld <[email protected]>. All Rights Reserved.
4+
*/
5+
6+
#define __ASSEMBLY__
7+
8+
#if defined(__aarch64__)
9+
#include "../../../../arch/arm64/kernel/vdso/vgetrandom-chacha.S"
10+
#elif defined(__loongarch__)
11+
#include "../../../../arch/loongarch/vdso/vgetrandom-chacha.S"
12+
#elif defined(__powerpc__) || defined(__powerpc64__)
13+
#include "../../../../arch/powerpc/kernel/vdso/vgetrandom-chacha.S"
14+
#elif defined(__s390x__)
15+
#include "../../../../arch/s390/kernel/vdso64/vgetrandom-chacha.S"
16+
#elif defined(__x86_64__)
17+
#include "../../../../arch/x86/entry/vdso/vgetrandom-chacha.S"
18+
#endif

0 commit comments

Comments
 (0)