[PATCH v2 4/5] um: vdso: add the generic vDSO alongside the syscall-shim vDSO

Haikal Firmansyah haikalfirmansyh.kernel at gmail.com
Wed Nov 25 01:38:05 PST 2026


Add vclock_gettime.c, a thin wrapper around lib/vdso/gettimeofday.c
following the same pattern as
arch/x86/entry/vdso/common/vclock_gettime.c. Time is now computed
in userspace from the host TSC and the vvar on MMU builds. getcpu
and getrandom are deliberately not exported: libc falls back to the
syscall for both.

The old um_vdso.c shim ("This vDSO turns all calls into a syscall
so that UML can trap them") is KEPT, not deleted: it is the vDSO
for NOMMU builds, where the generic vDSO framework is not selected
(see the MMU-only selects in the Kconfig patch) and the shim needs
none of it. The Makefile picks vclock_gettime.o on MMU and
um_vdso.o on NOMMU.

Signed-off-by: Haikal Firmansyah <haikalfirmansyh.kernel at gmail.com>
---
 arch/x86/um/vdso/vclock_gettime.c | 60 +++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)
 create mode 100644 arch/x86/um/vdso/vclock_gettime.c

diff --git a/arch/x86/um/vdso/vclock_gettime.c
b/arch/x86/um/vdso/vclock_gettime.c
new file mode 100644
index 000000000..193a133d5
--- /dev/null
+++ b/arch/x86/um/vdso/vclock_gettime.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Fast user context implementation of clock_gettime, gettimeofday,
+ * time and clock_getres for UML.
+ *
+ * This provides the generic vDSO for MMU builds; the old um_vdso.c
+ * shim ("This vDSO turns all calls into a syscall so that UML can
+ * trap them") is kept for NOMMU builds. The time is now computed
+ * in userspace from the host TSC and the vvar published by
+ * update_vsyscall(), via the generic code in lib/vdso/gettimeofday.c
+ * (same pattern as arch/x86/entry/vdso/common/vclock_gettime.c).
+ *
+ * Deliberately NOT exported: getcpu (no guest CPU number exists in
+ * userspace; the x86 LSL/RDPID read would return the host CPU number)
+ * and getrandom (out of scope, needs the RNG vvar page). libc falls
+ * back to the syscall for both.
+ */
+
+/* Disable profiling for userspace code */
+#define DISABLE_BRANCH_PROFILING
+
+#include <linux/time.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <vdso/gettime.h>
+
+#include "lib/vdso/gettimeofday.c"
+
+int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
+{
+	return __cvdso_gettimeofday(tv, tz);
+}
+
+int gettimeofday(struct __kernel_old_timeval *, struct timezone *)
+	__weak __alias(__vdso_gettimeofday);
+
+__kernel_old_time_t __vdso_time(__kernel_old_time_t *t)
+{
+	return __cvdso_time(t);
+}
+
+__kernel_old_time_t time(__kernel_old_time_t *t)	__weak __alias(__vdso_time);
+
+/* 64-bit only (UML is x86_64 here) */
+int __vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
+{
+	return __cvdso_clock_gettime(clock, ts);
+}
+
+int clock_gettime(clockid_t, struct __kernel_timespec *)
+	__weak __alias(__vdso_clock_gettime);
+
+int __vdso_clock_getres(clockid_t clock,
+			struct __kernel_timespec *res)
+{
+	return __cvdso_clock_getres(clock, res);
+}
+
+int clock_getres(clockid_t, struct __kernel_timespec *)
+	__weak __alias(__vdso_clock_getres);
-- 
2.43.0



More information about the linux-um mailing list