mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Fang Xieyan <fangxy@xiaopeng.com>
To: Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	x86@kernel.org
Cc: "Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Dave Hansen" <dave.hansen@linux.intel.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"Thomas Weißschuh" <linux@weissschuh.net>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"WANG Xuerui" <kernel@xen0n.name>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	linux-arch@vger.kernel.org, linux-riscv@lists.infradead.org,
	loongarch@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 1/5] vdso: Provide a sanitized subset of UAPI types
Date: Tue,  1 Dec 2026 19:55:19 +0800	[thread overview]
Message-ID: <20261201115523.75606-2-fangxy@xiaopeng.com> (raw)
In-Reply-To: <20261201115523.75606-1-fangxy@xiaopeng.com>

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@xiaopeng.com>
---
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


  reply	other threads:[~2026-12-01 11:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 11:55 [RFC PATCH 0/5] vdso: Provide a sanitized subset of UAPI types for vDSO code Fang Xieyan
2026-12-01 11:55 ` Fang Xieyan [this message]
2026-12-01 11:55 ` [RFC PATCH 2/5] x86/vdso: Drop redundant kernel header includes Fang Xieyan
2026-12-01 11:55 ` [RFC PATCH 3/5] vdso: Switch the sanctioned headers to vdso/types.h Fang Xieyan
2026-12-01 11:55 ` [RFC PATCH 4/5] riscv: Drop redundant internal header includes from the vDSO sources Fang Xieyan
2026-12-01 11:55 ` [RFC PATCH 5/5] loongarch: " Fang Xieyan
  -- strict thread matches above, loose matches on Subject: below --
2026-12-01 10:24 [RFC PATCH 0/5] vdso: Provide a sanitized subset of UAPI types for vDSO code Fang Xieyan
2026-12-01 10:24 ` [RFC PATCH 1/5] vdso: Provide a sanitized subset of UAPI types Fang Xieyan
2026-12-01 11:28   ` Thomas Weißschuh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201115523.75606-2-fangxy@xiaopeng.com \
    --to=fangxy@xiaopeng.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=chenhuacai@kernel.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=kernel@xen0n.name \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux@weissschuh.net \
    --cc=loongarch@lists.linux.dev \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®