From 2df8b4d9ff01477f1fc5dc05ce49f73f6bcc9c83 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Fri, 7 Nov 2025 13:53:24 +0100
Subject: [PATCH 1/5] selftests: vdso: correctness: Add missing headers for
 kernel time types

Add the necessary kernel headers (asm/posix_types.h, linux/types.h,
linux/time_types.h) to vdso_test_correctness.c. These headers are
required to use kernel time types like __kernel_old_timespec,
__kernel_old_timeval, __kernel_old_time_t, and __kernel_timespec.

Remove the conflicting fallback definition of struct __kernel_timespec
from vdso_test_correctness.c as it's now properly defined in the
included headers.

Convert the function signatures and variable declarations to use the
kernel time types instead of libc types, ensuring the tests directly
exercise the kernel vDSO interface.

This fixes build failures on both 32-bit and 64-bit ARM architectures
when building the vDSO correctness tests.

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 .../selftests/vDSO/vdso_test_correctness.c    | 27 +++++++++----------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_correctness.c b/tools/testing/selftests/vDSO/vdso_test_correctness.c
index 055af95aa552..c9139a64cde8 100644
--- a/tools/testing/selftests/vDSO/vdso_test_correctness.c
+++ b/tools/testing/selftests/vDSO/vdso_test_correctness.c
@@ -22,6 +22,9 @@
 #include "vdso_config.h"
 #include "vdso_call.h"
 #include "kselftest.h"
+#include <asm/posix_types.h>
+#include <linux/types.h>
+#include <linux/time_types.h>
 
 static const char **name;
 
@@ -37,19 +40,12 @@ static const char **name;
 #define __NR_clock_gettime64	403
 #endif
 
-#ifndef __kernel_timespec
-struct __kernel_timespec {
-	long long	tv_sec;
-	long long	tv_nsec;
-};
-#endif
-
 /* max length of lines in /proc/self/maps - anything longer is skipped here */
 #define MAPS_LINE_LEN 128
 
 int nerrs = 0;
 
-typedef int (*vgettime_t)(clockid_t, struct timespec *);
+typedef int (*vgettime_t)(clockid_t, struct __kernel_old_timespec *);
 
 vgettime_t vdso_clock_gettime;
 
@@ -57,7 +53,7 @@ typedef int (*vgettime64_t)(clockid_t, struct __kernel_timespec *);
 
 vgettime64_t vdso_clock_gettime64;
 
-typedef long (*vgtod_t)(struct timeval *tv, struct timezone *tz);
+typedef long (*vgtod_t)(struct __kernel_old_timeval *tv, struct timezone *tz);
 
 vgtod_t vdso_gettimeofday;
 
@@ -154,7 +150,7 @@ static long sys_getcpu(unsigned * cpu, unsigned * node,
 	return syscall(__NR_getcpu, cpu, node, cache);
 }
 
-static inline int sys_clock_gettime(clockid_t id, struct timespec *ts)
+static inline int sys_clock_gettime(clockid_t id, struct __kernel_old_timespec *ts)
 {
 	return syscall(__NR_clock_gettime, id, ts);
 }
@@ -164,7 +160,7 @@ static inline int sys_clock_gettime64(clockid_t id, struct __kernel_timespec *ts
 	return syscall(__NR_clock_gettime64, id, ts);
 }
 
-static inline int sys_gettimeofday(struct timeval *tv, struct timezone *tz)
+static inline int sys_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
 {
 	return syscall(__NR_gettimeofday, tv, tz);
 }
@@ -221,7 +217,8 @@ static void test_getcpu(void)
 	}
 }
 
-static bool ts_leq(const struct timespec *a, const struct timespec *b)
+static bool ts_leq(const struct __kernel_old_timespec *a,
+		   const struct __kernel_old_timespec *b)
 {
 	if (a->tv_sec != b->tv_sec)
 		return a->tv_sec < b->tv_sec;
@@ -238,7 +235,7 @@ static bool ts64_leq(const struct __kernel_timespec *a,
 		return a->tv_nsec <= b->tv_nsec;
 }
 
-static bool tv_leq(const struct timeval *a, const struct timeval *b)
+static bool tv_leq(const struct __kernel_old_timeval *a, const struct __kernel_old_timeval *b)
 {
 	if (a->tv_sec != b->tv_sec)
 		return a->tv_sec < b->tv_sec;
@@ -263,7 +260,7 @@ static char const * const clocknames[] = {
 
 static void test_one_clock_gettime(int clock, const char *name)
 {
-	struct timespec start, vdso, end;
+	struct __kernel_old_timespec start, vdso, end;
 	int vdso_ret, end_ret;
 
 	printf("[RUN]\tTesting clock_gettime for clock %s (%d)...\n", name, clock);
@@ -387,7 +384,7 @@ static void test_clock_gettime64(void)
 
 static void test_gettimeofday(void)
 {
-	struct timeval start, vdso, end;
+	struct __kernel_old_timeval start, vdso, end;
 	struct timezone sys_tz, vdso_tz;
 	int vdso_ret, end_ret;
 
-- 
2.51.0

