[RFC PATCH 1/5] vdso: Provide a sanitized subset of UAPI types
From: Fang Xieyan
Date: Tue Dec 01 2026 - 06:55:38 EST
The sanctioned include/vdso headers pull in <linux/types.h> and the UAPI
time headers. When building the kernel, those headers resolve to the
kernel-internal include/linux and include/asm-generic variants, so vDSO
code ends up depending on kernel-internal headers such as
include/asm-generic/bitsperlong.h, even though vDSO code is supposed to
use only the include/vdso/ headers.
Add include/vdso/types.h providing a self-contained sanitized subset of
the types that vDSO code shares: the basic integer types with their
plain u8..u64 aliases and bool (mirroring asm-generic/int-ll64.h and
linux/types.h), size_t/ssize_t (from the compiler, so they always match
the target C ABI), the legacy time types (mirroring
asm-generic/posix_types.h) and the clock IDs (mirroring
uapi/linux/time.h). The header includes nothing itself, so consumers get
the types without pulling in any kernel-internal header.
Architecture overridable types follow the UAPI convention instead of
being hardcoded: __kernel_long_t carries the UAPI macro sentinel, so an
architecture that defines it before including this header keeps
precedence, the way x86 does for x32 in the UAPI; no vDSO build needs
that today. __kernel_old_time_t follows __kernel_long_t, mirroring the
generic UAPI, which provides no separate override for it.
__kernel_suseconds_t is not mirrored at all: no vDSO code refers to the
type name (sparc64 overrides it with 'int' in its UAPI), it only
appears inside struct __kernel_old_timeval.
The time structs (struct __kernel_timespec, struct __kernel_old_timeval
and struct timezone) are intentionally not mirrored yet: the vDSO build
still reaches the UAPI time headers through other kernel headers (e.g.
asm/msr.h -> linux/percpu.h -> linux/time64.h), so defining them here
would conflict. They continue to come from the UAPI headers until those
remaining dependencies are isolated in follow-up work.
The new header has no users yet and there is no functional change.
Signed-off-by: Fang Xieyan <fangxy@xxxxxxxxxxxx>
---
The new header has no users yet, so this patch alone cannot affect any
build; the x86_64 and arm64 builds in this series verify the consumers.
A clang -fsyntax-only sparc64 probe that mirrors the include sequence of
arch/sparc/vdso/vclock_gettime.c (<linux/compiler.h>, <linux/types.h>,
<vdso/types.h>) compiles cleanly; hardcoding __kernel_suseconds_t as
long instead fails there with the expected 'long' vs 'int' typedef
conflict, which is why the type is not mirrored.
The __kernel_long_t guard is inert in the current tree: no vDSO build
installs an override (the x86 x32 vDSO objects are objcopy'd from the
-m64 ones, and no vDSO .cmd file in the x86 or i386 object trees uses
-mx32, while under __KERNEL__ the x86 uapi posix_types layer is not
visible), so it only preserves the UAPI convention for a future
override.
checkpatch --strict reports 0 errors (the new-typedef and _Bool
CamelCase warnings are inherent false positives for a types header).
include/vdso/types.h | 109 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
create mode 100644 include/vdso/types.h
diff --git a/include/vdso/types.h b/include/vdso/types.h
new file mode 100644
index 000000000000..9afaaf22688e
--- /dev/null
+++ b/include/vdso/types.h
@@ -0,0 +1,109 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _VDSO_TYPES_H
+#define _VDSO_TYPES_H
+
+#ifndef __ASSEMBLER__
+
+/*
+ * Sanitized subset of the UAPI types for vDSO code.
+ *
+ * The definitions below mirror the UAPI integer and time types
+ * (asm-generic/int-ll64.h, asm-generic/posix_types.h and the clock IDs
+ * from linux/time.h) plus the plain u8..u64 aliases and bool from the
+ * kernel-internal type headers, but they are provided here without
+ * including any of those headers: when building the kernel, those
+ * headers resolve to the kernel-internal include/linux and
+ * include/asm-generic variants, which vDSO code must not depend on.
+ *
+ * The time structs (struct __kernel_timespec, struct __kernel_old_timeval
+ * and struct timezone) are not mirrored here: the vDSO build still pulls
+ * in the UAPI time headers through other kernel headers, so defining them
+ * here would conflict. They continue to come from the UAPI headers until
+ * those remaining dependencies are isolated.
+ *
+ * Keep this header self-contained and in sync with the UAPI ABI.
+ */
+
+typedef __signed__ char __s8;
+typedef unsigned char __u8;
+
+typedef __signed__ short __s16;
+typedef unsigned short __u16;
+
+typedef __signed__ int __s32;
+typedef unsigned int __u32;
+
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+
+typedef __s8 s8;
+typedef __u8 u8;
+typedef __s16 s16;
+typedef __u16 u16;
+typedef __s32 s32;
+typedef __u32 u32;
+typedef __s64 s64;
+typedef __u64 u64;
+
+typedef _Bool bool;
+
+/*
+ * size_t and ssize_t come from the compiler rather than mirroring
+ * __kernel_size_t/__kernel_ssize_t, so they always match the target
+ * C ABI, including 32-bit vDSO variants built inside 64-bit kernels.
+ */
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ssize_t;
+
+typedef int __kernel_clockid_t;
+typedef __kernel_clockid_t clockid_t;
+
+typedef long long __kernel_time64_t;
+
+/*
+ * Mirror the generic UAPI definitions, which derive from
+ * __kernel_long_t. That type is architecture overridable in the UAPI,
+ * where a macro sentinel guards it so that an architecture can define
+ * the type ahead of the generic one, as x86 does for x32. The same
+ * guard is kept here, although no vDSO build overrides the type today.
+ * __kernel_old_time_t simply follows __kernel_long_t; the UAPI has no
+ * separate override for it. __kernel_suseconds_t is deliberately not
+ * mirrored: no vDSO code refers to the type name, it only appears
+ * inside struct __kernel_old_timeval, which still comes from the UAPI
+ * headers (sparc64 overrides it with 'int').
+ */
+#ifndef __kernel_long_t
+typedef long __kernel_long_t;
+#endif
+
+typedef __kernel_long_t __kernel_old_time_t;
+
+/*
+ * Clock IDs, mirroring include/uapi/linux/time.h.
+ */
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_THREAD_CPUTIME_ID 3
+#define CLOCK_MONOTONIC_RAW 4
+#define CLOCK_REALTIME_COARSE 5
+#define CLOCK_MONOTONIC_COARSE 6
+#define CLOCK_BOOTTIME 7
+#define CLOCK_REALTIME_ALARM 8
+#define CLOCK_BOOTTIME_ALARM 9
+/*
+ * The driver implementing this got removed. The clock ID is kept as a
+ * place holder. Do not reuse!
+ */
+#define CLOCK_SGI_CYCLE 10
+#define CLOCK_TAI 11
+
+#define MAX_CLOCKS 16
+
+#define CLOCK_AUX MAX_CLOCKS
+#define MAX_AUX_CLOCKS 8
+#define CLOCK_AUX_LAST (CLOCK_AUX + MAX_AUX_CLOCKS - 1)
+
+#endif /* __ASSEMBLER__ */
+
+#endif /* _VDSO_TYPES_H */
--
2.50.1