[PATCH v2 0/5] um: Use the generic vDSO for UML/x86

Haikal Firmansyah haikalfirmansyh.kernel at gmail.com
Wed Nov 25 01:37:06 PST 2026


This series replaces UML's hand-written x86_64 vDSO with the generic
vDSO framework (lib/vdso).

Changes in v2: patch 3 now skips TSC calibration explicitly when
time-travel is active (the guest clock is independent of the host
clock there, so the host TSC cannot be used), and the clocksource
registration in um_timer_init() is restructured so the original
call is kept verbatim instead of being removed, keeping the patch
free of long removed lines.  Patch 1 wraps one long function
signature in the shadow headers.  No other patch changes.

Since 2011 UML/x86_64 has shipped a vDSO that turns every __vdso_*
call into a syscall so that UML can trap it (Richard Weinberger,
"um: implement a x86_64 vDSO").  That was the right call when UML had
no way to give userspace a trustworthy clock, but it means every
clock_gettime() still pays a full syscall round trip: about 36 us
in our guest measurements.

The guest can read the host TSC with RDTSC without a trap,
so there is no need to bounce to the kernel for time at all.  This
series calibrates the host TSC at boot, switches the timekeeper
clocksource to it, and lets the generic vDSO interpolate the time
in userspace from the TSC and the vvar, following the same pattern
as arch/x86/entry/vdso.  Measured in the guest:

  clock_gettime(CLOCK_REALTIME): median 70 ns, against
  36,535 ns via the raw syscall. In the boot where the
  syscall baseline was measured the vDSO median was 80 ns,
  so the same-boot speedup is 457x; at the typical 70 ns
  median it is about 520x. Monotonicity, drift and reboot
  gates pass, 6 boots on 7.4-rc3, 0 segfaults.

The patches:

  1. um: vdso: add shadow headers for the vDSO build
  2. um: Kconfig: select generic vDSO options for UML (MMU only)
  3. um: time: use the host TSC as clocksource for the vDSO
  4. um: vdso: add the generic vDSO alongside the syscall-shim vDSO
  5. um: vdso: wire up the vvar mapping, layout and build (MMU only)

Three things I want to be upfront about.  First, patch 1 adds shadow
copies of four asm/vdso headers because the x86 ones cannot be
reused verbatim in the UML vDSO build (rdtsc_ordered() needs plain
"lfence; rdtsc" as the ALTERNATIVE patching machinery is not
available there; cpu_relax is already defined by UML with its own
time-travel handling).  These are workarounds for UML build
limitations, and I am open to a cleaner fix if reviewers prefer
one.  Second, the generic vDSO is MMU-only: patch 2 selects the
generic-vDSO Kconfig options only "if MMU" (following the
arch/riscv precedent), because the pulled-in generic code calls
MMU-only functions and would break the NOMMU build.  NOMMU UML
keeps the existing syscall-shim vDSO, and the NOMMU build and
link are verified.  Third, getcpu and getrandom are deliberately
not exported: there is no guest CPU number in userspace (an x86
RDPID read would return the host CPU), and the RNG vvar page is
out of scope; libc falls back to the syscall for both.

This series is based on vanilla Linux 7.4-rc3.  It was developed and
tested in a UML guest (4 vCPUs, 256 MB, seccomp mode).  The 32-bit
(i386) build passes, but UML builds a vDSO only for x86_64 upstream
(arch/x86/um/Makefile includes vdso/ only in the 64-bit branch), so
the vDSO speedup here is x86_64-only and i386 is unaffected.  It has
not yet been tested outside that setup, and I would appreciate review
and test reports.

The commit messages and this cover letter were drafted with the
help of an AI assistant; the code itself is my own work, tested
and measured in the UML guest.

Signed-off-by: Haikal Firmansyah <haikalfirmansyh.kernel at gmail.com>



More information about the linux-um mailing list