Skip to content

Commit 48f044a

Browse files
seehearfeelakpm00
authored andcommitted
selftests/vDSO: fix runtime errors on LoongArch
It could not find __vdso_getcpu and __vdso_gettimeofday when test getcpu and gettimeofday on LoongArch. # make headers && cd tools/testing/selftests/vDSO && make # ./vdso_test_getcpu Could not find __vdso_getcpu # ./vdso_test_gettimeofday Could not find __vdso_gettimeofday One simple way is to add LoongArch case to define version and name, just like commit d942f23 ("selftests/vDSO: Add riscv getcpu & gettimeofday test"), but it is not the best way. Since each architecture has already defined names and versions in vdso_config.h, it is proper to include vdso_config.h to get version and name for all archs. Link: https://lkml.kernel.org/r/20240428030530.24399-3-yangtiezhu@loongson.cn Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Kees Cook <keescook@chromium.org> Cc: Mark Brown <broonie@kernel.org> Cc: Shuah Khan <skhan@linuxfoundation.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent dc8dc57 commit 48f044a

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

tools/testing/selftests/vDSO/vdso_test_getcpu.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@
1313

1414
#include "../kselftest.h"
1515
#include "parse_vdso.h"
16-
17-
#if defined(__riscv)
18-
const char *version = "LINUX_4.15";
19-
#else
20-
const char *version = "LINUX_2.6";
21-
#endif
22-
const char *name = "__vdso_getcpu";
16+
#include "vdso_config.h"
2317

2418
struct getcpu_cache;
2519
typedef long (*getcpu_t)(unsigned int *, unsigned int *,
2620
struct getcpu_cache *);
2721

2822
int main(int argc, char **argv)
2923
{
24+
const char *version = versions[VDSO_VERSION];
25+
const char **name = (const char **)&names[VDSO_NAMES];
3026
unsigned long sysinfo_ehdr;
3127
unsigned int cpu, node;
3228
getcpu_t get_cpu;
@@ -40,17 +36,17 @@ int main(int argc, char **argv)
4036

4137
vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
4238

43-
get_cpu = (getcpu_t)vdso_sym(version, name);
39+
get_cpu = (getcpu_t)vdso_sym(version, name[4]);
4440
if (!get_cpu) {
45-
printf("Could not find %s\n", name);
41+
printf("Could not find %s\n", name[4]);
4642
return KSFT_SKIP;
4743
}
4844

4945
ret = get_cpu(&cpu, &node, 0);
5046
if (ret == 0) {
5147
printf("Running on CPU %u node %u\n", cpu, node);
5248
} else {
53-
printf("%s failed\n", name);
49+
printf("%s failed\n", name[4]);
5450
return KSFT_FAIL;
5551
}
5652

tools/testing/selftests/vDSO/vdso_test_gettimeofday.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,13 @@
1818

1919
#include "../kselftest.h"
2020
#include "parse_vdso.h"
21-
22-
/*
23-
* ARM64's vDSO exports its gettimeofday() implementation with a different
24-
* name and version from other architectures, so we need to handle it as
25-
* a special case.
26-
*/
27-
#if defined(__aarch64__)
28-
const char *version = "LINUX_2.6.39";
29-
const char *name = "__kernel_gettimeofday";
30-
#elif defined(__riscv)
31-
const char *version = "LINUX_4.15";
32-
const char *name = "__vdso_gettimeofday";
33-
#else
34-
const char *version = "LINUX_2.6";
35-
const char *name = "__vdso_gettimeofday";
36-
#endif
21+
#include "vdso_config.h"
3722

3823
int main(int argc, char **argv)
3924
{
25+
const char *version = versions[VDSO_VERSION];
26+
const char **name = (const char **)&names[VDSO_NAMES];
27+
4028
unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
4129
if (!sysinfo_ehdr) {
4230
printf("AT_SYSINFO_EHDR is not present!\n");
@@ -47,10 +35,10 @@ int main(int argc, char **argv)
4735

4836
/* Find gettimeofday. */
4937
typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
50-
gtod_t gtod = (gtod_t)vdso_sym(version, name);
38+
gtod_t gtod = (gtod_t)vdso_sym(version, name[0]);
5139

5240
if (!gtod) {
53-
printf("Could not find %s\n", name);
41+
printf("Could not find %s\n", name[0]);
5442
return KSFT_SKIP;
5543
}
5644

@@ -61,7 +49,7 @@ int main(int argc, char **argv)
6149
printf("The time is %lld.%06lld\n",
6250
(long long)tv.tv_sec, (long long)tv.tv_usec);
6351
} else {
64-
printf("%s failed\n", name);
52+
printf("%s failed\n", name[0]);
6553
return KSFT_FAIL;
6654
}
6755

0 commit comments

Comments
 (0)