83 Commits

Author SHA1 Message Date
Nicolas Lacasse d9fa8c2e8a Add AT_HWCAP and AT_HWCAP2 to auxv.
PiperOrigin-RevId: 704901883
2024-12-10 17:28:40 -08:00
Jamie Liu 453f16e729 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 0cf77c02f8 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2024-10-10 20:36:24 +09:00
gVisor bot b1d7ceafb1 Merge pull request #10721 from p12tic:expose-fake-cpuinfo-cache
PiperOrigin-RevId: 660077238
2024-08-06 13:33:39 -07:00
Povilas Kanapickas a6196f3670 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 Liu f84a013407 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 Liu e77a65a7ff Deflake cpuid_parse_test.
PiperOrigin-RevId: 632336195
2024-05-09 18:56:44 -07:00
Ayush Ranjan 7e395bbbd4 Plumb restore context to load*() methods.
This allows for external information to be passed to restore code.
Similar to c087777e37 ("Plumb restore context to afterLoad()").

Updates #1956.

PiperOrigin-RevId: 614125262
2024-03-08 20:28:02 -08:00
Fabricio Voznika c087777e37 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 Bogomolov 5300f3d305 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 Bogomolov bb84006816 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 Bogomolov e9bdc76c02 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 Bogomolov a81dd32be7 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 5f4abad306 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 <avagin@gmail.com>
2023-10-25 12:13:42 -07:00
Andrei Vagin 4cc749881e 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 1c1439e0c0 Internal change
PiperOrigin-RevId: 530997938
2023-05-10 14:07:03 -07:00
Etienne Perot 0620c3b638 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 Scannell 5ba34bd1a5 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 Scannell 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Adin Scannell be86ca7d22 Fix assembly declarations.
PiperOrigin-RevId: 511648708
2023-02-22 18:14:26 -08:00
Adin Scannell 6a4908b262 Process nogo targets across all architectures.
PiperOrigin-RevId: 511343590
2023-02-21 17:06:02 -08:00
Konstantin Bogomolov 45b3776646 x86: Add function to see if FSGSBASE is enabled.
PiperOrigin-RevId: 510512647
2023-02-17 13:48:11 -08:00
Konstantin Bogomolov 17d9b14478 x86: Add function to see if xsavec is available.
PiperOrigin-RevId: 510459831
2023-02-17 10:10:46 -08:00
Kevin Krakauer d8aa09e04c 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 801f45ab4b atomicbitops, cpuid: fix warnings, lack of atomics on macOS
Updates google/gvisor#7849
2022-07-31 19:26:54 -07:00