selftests: vDSO: look for arch-specific function name in getrandom test
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Thu, 22 Aug 2024 07:13:22 +0000 (09:13 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Fri, 30 Aug 2024 13:44:38 +0000 (15:44 +0200)
Don't hard-code x86 specific names. Rather, use vdso_config definitions
to find the correct function matching the architecture.

Add random VDSO function names in names[][]. Remove the #ifdef
CONFIG_VDSO32, as having the name there all the time is harmless and
guaranties a steady index for following strings.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
[Jason: add [6] to variable declaration rather than each usage site.]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tools/testing/selftests/vDSO/vdso_config.h
tools/testing/selftests/vDSO/vdso_test_getrandom.c

index 7b543e7..b5ba5de 100644 (file)
@@ -68,16 +68,15 @@ static const char *versions[7] = {
        "LINUX_5.10"
 };
 
-static const char *names[2][6] = {
+static const char *names[2][7] = {
        {
                "__kernel_gettimeofday",
                "__kernel_clock_gettime",
                "__kernel_time",
                "__kernel_clock_getres",
                "__kernel_getcpu",
-#if defined(VDSO_32BIT)
                "__kernel_clock_gettime64",
-#endif
+               "__kernel_getrandom",
        },
        {
                "__vdso_gettimeofday",
@@ -85,9 +84,8 @@ static const char *names[2][6] = {
                "__vdso_time",
                "__vdso_clock_getres",
                "__vdso_getcpu",
-#if defined(VDSO_32BIT)
                "__vdso_clock_gettime64",
-#endif
+               "__vdso_getrandom",
        },
 };
 
index 89c9611..20bbef9 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "../kselftest.h"
 #include "parse_vdso.h"
+#include "vdso_config.h"
 
 #ifndef timespecsub
 #define        timespecsub(tsp, usp, vsp)                                      \
@@ -100,15 +101,18 @@ static void vgetrandom_put_state(void *state)
 
 static void vgetrandom_init(void)
 {
+       const char *version = versions[VDSO_VERSION];
+       const char *name = names[VDSO_NAMES][6];
        unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
+
        if (!sysinfo_ehdr) {
                printf("AT_SYSINFO_EHDR is not present!\n");
                exit(KSFT_SKIP);
        }
        vdso_init_from_sysinfo_ehdr(sysinfo_ehdr);
-       vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym("LINUX_2.6", "__vdso_getrandom");
+       vgrnd.fn = (__typeof__(vgrnd.fn))vdso_sym(version, name);
        if (!vgrnd.fn) {
-               printf("__vdso_getrandom is missing!\n");
+               printf("%s is missing!\n", name);
                exit(KSFT_FAIL);
        }
        if (vgrnd.fn(NULL, 0, 0, &vgrnd.params, ~0UL) != 0) {