90 Commits
Author SHA1 Message Date
Tianyu Zhou fc1afc9de5 platform: add SlimVM platform
SlimVM is a lightweight VMX-based platform for gVisor that accelerates
sentry system calls by eliminating unnecessary user/kernel context
switches.

In a traditional gVisor + KVM setup, every guest syscall triggers a
full VM exit to userspace, then re-enters the kernel via a regular
syscall:

  gr0 -> hr0 (vm_exit) -> hr3 (ioctl return) -> hr0 (re-invoke syscall)

SlimVM eliminates this overhead. When the guest executes a VMCALL, the
VM exits into VMX root mode where SlimVM directly invokes the host
kernel's syscall handler, then immediately resumes the guest:

  gr0 -> hr0 (vmcall + direct function call)

SlimVM requires a companion kernel module that provides the /dev/slimvm
device interface. See https://github.com/antgroup/slimvm for the
kernel module and full documentation.

A sentry->host getpid microbenchmark (Xeon 6982P-C, host kernel 5.10.134)
shows the effect:

            │  ns/op  │ vs base │
  base          82.5       1.0x
  slimvm       420.9       5.1x
  kvm         3566.1      43.2x

slimvm is ~8.5x faster than the kvm platform on this path. See the issue
for details.

Updates: https://github.com/google/gvisor/issues/13330

Co-developed-by: Chenggang <[email protected]>
Co-developed-by: Robin Luk <[email protected]>
Co-developed-by: Tiwei Bie <[email protected]>
Co-developed-by: Jianfeng Tan <[email protected]>
Co-developed-by: liushi.ls <[email protected]>
Co-developed-by: Yong He <[email protected]>
Co-developed-by: Aaron Lu <[email protected]>
Co-developed-by: chris.zn <[email protected]>
Co-developed-by: Lai Jiangshan <[email protected]>
Co-developed-by: Lingfu <[email protected]>
Co-developed-by: Min Le <[email protected]>
Co-developed-by: Quan Xu <[email protected]>
Co-developed-by: Zhang Haoyu <[email protected]>
Co-developed-by: Dawei Shen <[email protected]>
Signed-off-by: Tianyu Zhou <[email protected]>
2026-06-25 10:27:28 +08:00
Konstantin BogomolovandgVisor bot f80a5163a3 Only exclude AMX TILEDATA from AMX extended state.
After Linux commit dc8aa31a7a, fx_sw->xstate_size is no longer used to
determine the location for FP_XSTATE_MAGIC2. This exposed the fact that
even in cases where AMX was disabled, AMX TILECFG was not considered to be
part of the AMX extended state.

Fixes #12741.

PiperOrigin-RevId: 904687888
2026-04-23 16:16:08 -07:00
Michael PrattandgVisor bot f89c6d5a2a Remove unsupported %w
log.Warningf doesn't wrap errors, so %w doesn't make sense.

PiperOrigin-RevId: 885771562
2026-03-18 13:56:06 -07:00
Tamir Duberstein 2882eec4b4 Fix QF1003 violations and drop suppression 2026-02-10 11:55:50 -08:00
gVisor bot ef16e283c6 Merge pull request #11498 from tianyuzhou95:albert/cpuid
PiperOrigin-RevId: 794363944
2025-08-12 20:04:01 -07:00
Tianyu Zhou 1948afa140 runsc: add support to control CPU features exposed to user apps
Currently, runsc compares the host feature set between the machine used
for checkpointing and the machine used for restoring. If the former
feature set is not a subset of the latter, the restore will fail, as
user apps might mistakenly use unsupported instructions.

Thanks to cpuid faulting support, it is possible to intercept the cpuid
instruction from user apps and generate results referring to the host
feature set recorded during sandbox boot.

This patch adds support to expose only specified CPU features by
removing features from the list when setting the feature set of kernel.
This makes it possible to checkpoint and restore on machines with
different CPU features. The list of enabled features is passed via
annotation.

It should be noted that currently this feature is not supported on
ARM64, as there is no ARM64 equivalent to cpuid.Static.Remove().

Updates #11486

Signed-off-by: Tianyu Zhou <[email protected]>
Reviewed-by: Jamie Liu <[email protected]>
2025-08-07 10:35:00 +08:00
Jamie LiuandgVisor bot 9cd7edc7d5 cpuid: don't "normalize" to a smaller XSAVE area size
PiperOrigin-RevId: 750339843
2025-04-22 15:06:30 -07:00
Nicolas LacasseandgVisor bot 00dd298592 Add AT_HWCAP and AT_HWCAP2 to auxv.
PiperOrigin-RevId: 704901883
2024-12-10 17:28:40 -08:00
Jamie LiuandgVisor bot bd81c9bf32 cpuid: read /proc/cpuinfo incrementally
On machines with many CPUs, reading all of /proc/cpuinfo spends a surprising
amount of time generating information for each CPU; reduce this time by reading
incrementally until we find the CPU frequency. On such machines, this saves
3-4ms on sentry startup.

PiperOrigin-RevId: 688609950
2024-10-22 10:52:30 -07:00
Koichi Shiraishi 5677ce4285 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <[email protected]>
2024-10-10 20:36:24 +09:00
gVisor bot e445d30343 Merge pull request #10721 from p12tic:expose-fake-cpuinfo-cache
PiperOrigin-RevId: 660077238
2024-08-06 13:33:39 -07:00
Povilas Kanapickas 08be71c697 procfs: add cache size x86 cpuinfo field
Linux prints this field when cache information is available. This field
is conditional (see arch/x86/kernel/cpu/proc.c:x86_cache_size()). It a
different meaning and implementation on each vendor. For example, as of
Linux 6.1.0 it returns LLC size on Intel and L2 size on AMD CPUs.

Even though usefullness of this field in its current implementation
debatable, some relatively popular software such as PyPy (as of 7.3.11)
relies on it and prints a warning if it is not available.
2024-08-06 11:18:52 +03:00
Jamie LiuandgVisor bot cd57268c04 procfs: add topology-related x86 cpuinfo fields
Linux prints these fields when the kernel is built with support for multiple
processors/cores (CONFIG_SMP), in
arch/x86/kernel/cpu/proc.c:show_cpuinfo_core().

Fixes #10205

PiperOrigin-RevId: 632621375
2024-05-10 15:46:45 -07:00
Jamie LiuandgVisor bot 3e13d5eb84 Deflake cpuid_parse_test.
PiperOrigin-RevId: 632336195
2024-05-09 18:56:44 -07:00
Ayush RanjanandgVisor bot 533c7b5188 Plumb restore context to load*() methods.
This allows for external information to be passed to restore code.
Similar to a9af2d309b ("Plumb restore context to afterLoad()").

Updates #1956.

PiperOrigin-RevId: 614125262
2024-03-08 20:28:02 -08:00
Fabricio VoznikaandgVisor bot a9af2d309b Plumb restore context to afterLoad()
This allows for external information to be passed to restore code, like
host FDs to be remapped.

Updates #1956

PiperOrigin-RevId: 612540749
2024-03-04 12:21:50 -08:00
Konstantin BogomolovandgVisor bot fe778304f1 Don't use xgetbv on CPUs that don't support it.
Fixes #9996.

PiperOrigin-RevId: 606711566
2024-02-13 12:38:38 -08:00
Konstantin BogomolovandgVisor bot 4a4ca4cfa3 Fixup AMX workaround for ptrace.
SETREGSET/GETREGSET expect AMX portions of fpstate to always be used.
For this reason we need to allocate enough memory for this to happen,
even if we never populate the AMX portions within initX86FPState.

PiperOrigin-RevId: 599702181
2024-01-18 20:12:31 -08:00
Konstantin BogomolovandgVisor bot 7d6ecf548a Exclude AMX extended state from being xsave/xrstor'd.
For now we are going to completely disable using AMX, so we will
always subtract extended state size reserved from AMX from the rest
of the extended state size, and hardcode the AMX XCR0 bits to be
always off.

Fixes #9750.

PiperOrigin-RevId: 599302059
2024-01-17 15:11:03 -08:00
Konstantin BogomolovandgVisor bot d4afe779c0 Add cpuid features block (EAX=07H,ECX=0):EDX.
This block holds information about whether AMX is enabled or not,
which is important for CPUs that support it due to the fact that
the fpstate buffer becomes dynamically sized, and the cpuid value
reported for extended state size assumes that AMX is enabled for
any given process.

PiperOrigin-RevId: 598941137
2024-01-16 13:40:49 -08:00
Andrei Vagin 43bd258fcf Fix a few typos
It is an idea of running codespell as part of our presubmit checks.
Before enabling it for new changes, let's fix what it has found.

Signed-off-by: Andrei Vagin <[email protected]>
2023-10-25 12:13:42 -07:00
Andrei VaginandgVisor bot fdf4c669d1 cpuid: ExtendedStateSize returns the state size just for the enabled features
It is impossible to enable any features from user-space, so
it is no reason to return the maximum size with all features enabled.

The kvm and systrap platforms uses ExtendedStateSize to generate fpu states
that are restored via rt_sigreturn, but the kernel rejects frames with
incorrect sizes.

PiperOrigin-RevId: 537333319
2023-06-02 09:39:06 -07:00
gVisor bot e12fd32695 Internal change
PiperOrigin-RevId: 530997938
2023-05-10 14:07:03 -07:00
Etienne PerotandgVisor bot d53fe574e0 cpuid: Initialize hostFeatureSet only when it's needed.
This moves the initialization of `cpuid.hostFeatureSet` out of package-level
`init` and instead moves it to an explicit `cpuid.Initialize()` function.

On AMD64, this saves about 512KiB of heap memory that would otherwise always
be live.

PiperOrigin-RevId: 514896323
2023-03-07 18:27:49 -08:00
Adin ScannellandgVisor bot daafc82dd5 Add explicit NOFRAME annotation in assembly functions.
For all trivial and zero frame-sized functions, we now require an explicit
NOFRAME annotation as the heuristic has changed. See go.dev/cl/466316.

Most of these functions do not  *require* NOFRAME, but this change encodes
the existing behavior in order to avoid accidental bugs or regressions.

PiperOrigin-RevId: 513946210
2023-03-04 00:53:20 -08:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Adin ScannellandgVisor bot f230d5d6f2 Fix assembly declarations.
PiperOrigin-RevId: 511648708
2023-02-22 18:14:26 -08:00
Adin ScannellandgVisor bot 5dd4a95711 Process nogo targets across all architectures.
PiperOrigin-RevId: 511343590
2023-02-21 17:06:02 -08:00
Konstantin BogomolovandgVisor bot 9674f2ccc2 x86: Add function to see if FSGSBASE is enabled.
PiperOrigin-RevId: 510512647
2023-02-17 13:48:11 -08:00
Konstantin BogomolovandgVisor bot e60f26a063 x86: Add function to see if xsavec is available.
PiperOrigin-RevId: 510459831
2023-02-17 10:10:46 -08:00
Kevin KrakauerandgVisor bot 3a76efe831 convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Brad Fitzpatrick c78e4eea1a atomicbitops, cpuid: fix warnings, lack of atomics on macOS
Updates google/gvisor#7849
2022-07-31 19:26:54 -07:00
Andrei VaginandgVisor bot 96d16036a0 cpuid: cache host cpuid features
HostFeatureSet() returns a fixed set that is initialized at startup.

Here results fro the signal_benchmark on the kvm platform:
Before:
BM_FaultSignalFixup/real_time       8353 ns         8383 ns        94234

After:
BM_FaultSignalFixup/real_time       6127 ns         6087 ns       111708
PiperOrigin-RevId: 462012597
2022-07-19 17:20:14 -07:00
Ayush RanjanandgVisor bot 4350f4a0a3 Import hostos in ARM cpuid test.
Fixes ba9f54755d ("Use hostos.KernelVersion everywhere, and
have it return semver strings")

PiperOrigin-RevId: 461712007
2022-07-18 14:16:57 -07:00
Kevin KrakauerandgVisor bot ba9f54755d Use hostos.KernelVersion everywhere, and have it return semver strings
PiperOrigin-RevId: 460872657
2022-07-13 21:29:08 -07:00
Ayush RanjanandgVisor bot 2987d9cb0a Simplify codebase.
Ran gofmt -w -s ./

PiperOrigin-RevId: 449415155
2022-05-18 00:56:31 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
gVisor bot d7ef1e68fd Merge pull request #7391 from zhlhahaha:2477
PiperOrigin-RevId: 446793644
2022-05-05 13:07:01 -07:00
Andrei Vagin ea236d39dc cpuid: handle CPUID(0x80000006): L2 cache information
Fixes: #7341

Signed-off-by: Andrei Vagin <[email protected]>
2022-04-11 12:38:01 -07:00
gVisor bot 8df2cd1ebf Merge pull request #7167 from zhlhahaha:2438
PiperOrigin-RevId: 433048695
2022-03-07 15:03:09 -08:00
William ChangandgVisor bot 1189312433 Implement core tagging
Links to some possibly useful reference material on core tagging:
* LWN article: https://lwn.net/Articles/861251/
* Kernel docs: https://www.kernel.org/doc/Documentation/admin-guide/hw-vuln/core-scheduling.rst

PiperOrigin-RevId: 431093418
2022-02-25 21:51:02 -08:00
Howard Zhang 6805ef919f add stateify savable tag for FeatureSet of Arm64
Signed-off-by: Howard Zhang <[email protected]>
2022-02-10 20:21:34 +08:00
Andrei VaginandgVisor bot b687f9e532 Disable VMX and SVM in guest PCID.
The origin version converts KVM cpuid entries into cpuid.Static
to be able to modify it. But such conversion has side-effects
that we need to avoid and so it looks reasonable to modify KVM
cpuid entries directly.

PiperOrigin-RevId: 424221630
2022-01-25 17:41:53 -08:00
Andrei VaginandgVisor bot 0adad239b6 cpuid: deflake cpuid_test
xsavec, xgetbv1 are in Sub-leaf (EAX = 0DH, ECX = 1).

PiperOrigin-RevId: 423948954
2022-01-24 17:18:35 -08:00
Adin ScannellandgVisor bot 33a9bf8e30 Refactor CPUID to allow for use in KVM and ring0.
Updates #5039

PiperOrigin-RevId: 421696994
2022-01-13 17:24:28 -08:00
Ayush RanjanandgVisor bot fcc36ebcbd Update CPUID features.
PiperOrigin-RevId: 409548753
2021-11-12 17:44:20 -08:00
Andrei VaginandgVisor bot a80f3d0d8e platform/kvm: map vdso and vvar into a guest address space
Right now, each vdso call triggers vmexit. VDSO and VVAR pages are
mapped with VM_IO and get_user_pages fails for such vma-s. KVM was not
able to handle this case up to the v4.8 kernel. This problem was fixed by
add6a0cd1c5ba ("KVM: MMU: try to fix up page faults before giving up").

For some unknown reasons, it still doesn't work in case of nested
virtualization.

Before:
BenchmarkKernelVDSO-6                   	  252519	      4598 ns/op
After:
BenchmarkKernelVDSO-6                   	34431957	        34.91 ns/op
PiperOrigin-RevId: 405715941
2021-10-26 13:04:40 -07:00
Jing Chen 7433981075 initialize hostFeatureSet from init function 2021-10-23 15:39:57 -07:00
Jing Chen 9420f4d4b1 fix the failed test target //pkg/cpuid:cpuid_test on arm64. 2021-10-23 15:39:57 -07:00
Jamie LiuandgVisor bot 52f81b9d53 Cache cpuid.HostFeatureSet().
PiperOrigin-RevId: 394261815
2021-09-01 10:29:51 -07:00