Commit Graph
86 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot c03b482fa2 fpu: avoid user stack corruptions
When we reserve space for an FPU state in a signal frame, we need to use
the size of the current fpu state. The kernel cpuid can report a smaller size.

On restore, we need to read the size of an fpu state from a signal frame.
After S/R, it can't be different from the current fpu size.

PiperOrigin-RevId: 546972243
2023-07-10 13:54:12 -07:00
Andrei VaginandgVisor bot a4e0e87f13 fpu: verify that a restored fpu state can be loaded by xrstor
PiperOrigin-RevId: 538886033
2023-06-08 14:14:53 -07:00
Andrei VaginandgVisor bot 37e797283c kvm: add the extended state information into fpu states
Otherwise, rt_sigreturn rejects it.

PiperOrigin-RevId: 537445737
2023-06-02 17:18:20 -07: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
Andrei Vagin 8d92b92dc3 arm64: validate registers that come from user-space
Reported-by: [email protected]
2023-01-17 12:43:56 -08:00
Andrei VaginandgVisor bot a63e4ed1a8 kernel: don't allocate extra buffer to copy fpu state from user-memory
We don't care about corrupting the current state, because sigreturn
syscalls never report errors and they queue SIGSEGV in case of any
problems.

Here are results fro the signal_benchmark on the kvm platform:
Before:
BM_FaultSignalFixup/real_time       6127 ns         6087 ns       111708
After:
BM_FaultSignalFixup/real_time       3661 ns         3654 ns       199755
PiperOrigin-RevId: 462021118
2022-07-19 18:12:52 -07:00
Etienne PerotandgVisor bot 15e3dd3c3d gVisor: Turn arch.Context interface references to struct pointers.
Since `arch.Context64` is the only concrete implementation of
`arch.Context`, this does not functionally change anything.
While `arch.Context64` *can* mean multiple things in the codebase, since
the `arch` module uses conditional compilation to create different builds
for AMD64 vs ARM64, the `Context64` type is still singular within each
possible version this can compile to.

This avoids the overhead involved in calling interface
functions in Go:
https://github.com/teh-cmc/go-internals/blob/master/chapter2_interfaces/README.md#dynamic-dispatch

This overhead is particularly painful for functions like `SyscallSaveOrig`
which is a no-op on AMD64.

On KVM, this reduces syscall latency by 4~5%:

```
name       old wall_ns/op  new wall_ns/op  delta
Getpid           602 ± 4%        579 ± 3%  -3.94%  (p=0.000 n=66+195)
GetpidOpt        604 ± 3%        573 ± 3%  -5.10%  (p=0.000 n=71+194)

name       old cpu_ns/op   new cpu_ns/op   delta
Getpid           604 ± 5%        581 ± 0%  -3.81%  (p=0.000 n=75+130)
GetpidOpt        604 ± 2%        574 ± 3%  -4.95%  (p=0.000 n=71+196)
```

PiperOrigin-RevId: 461742893
2022-07-18 16:32:28 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
gVisor bot b98e0ef99f Merge pull request #7087 from joehattori:feature/fix-capacity
PiperOrigin-RevId: 438670433
2022-03-31 15:06:15 -07:00
Jamie LiuandgVisor bot c0e0704781 Save/restore floating point state in amd64 signal frames.
PiperOrigin-RevId: 429178859
2022-02-16 17:23:40 -08:00
Joe Hattori 885ebe5e9d Allocate auxv with better capacity while loading stack 2022-01-23 13:05:38 -05: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
Jamie LiuandgVisor bot e886972f0c Don't use reflection in fpu.alignedBytes.
reflect.ValueOf takes an interface{}, so when passed a slice the compiler emits
a call to runtime.convTslice to heap-allocate a copy of the slice header.

PiperOrigin-RevId: 394310052
2021-09-01 14:07:57 -07:00
Jamie LiuandgVisor bot f53b8a38e5 Add go:build directives as required by Go 1.17's gofmt.
PiperOrigin-RevId: 385894869
2021-07-20 16:28:45 -07:00
Zach KoopmansandgVisor bot 5e6d494c2f [syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent:
EEXIST
EFAULT
ENOTDIR
ENOTTY
EOPNOTSUPP
ERANGE
ESRCH

PiperOrigin-RevId: 384329869
2021-07-12 15:26:20 -07:00
Zach KoopmansandgVisor bot cd84634cc0 [syserror] Change syserror to linuxerr for E2BIG, EADDRINUSE, and EINVAL
Remove three syserror entries duplicated in linuxerr. Because of the
linuxerr.Equals method, this is a mere change of return values from
syserror to linuxerr definitions.

Done with only these three errnos as CLs removing all grow to a significantly
large size.

PiperOrigin-RevId: 382173835
2021-06-29 15:08:46 -07:00
Ayush RanjanandgVisor bot f7e133f133 [op] Move SignalInfo to abi/linux package.
Fixes #214

PiperOrigin-RevId: 378680466
2021-06-10 10:26:36 -07:00
Ayush RanjanandgVisor bot 13128df6e1 [op] Move SignalStack to abi/linux package.
Updates #214

PiperOrigin-RevId: 378594929
2021-06-10 01:00:24 -07:00
Ayush RanjanandgVisor bot 2149f75c99 [op] Move SignalAct to abi/linux package.
There were also other duplicate definitions of the same struct that I have now
removed.

Updates #214

PiperOrigin-RevId: 378579954
2021-06-09 22:53:41 -07:00
Andrei Vagin 89be1b308d platform/kvm/x86: restore mxcsr when switching from guest to sentry
Goruntime sets mxcsr once and never changes it.

Reported-by: [email protected]
Fixes: #5754
2021-04-01 13:28:15 -07:00
Zach KoopmansandgVisor bot d8f34027b3 [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Howard Zhang 09a53be509 Fix nogo test error
Signed-off-by: Howard Zhang <[email protected]>
2021-03-25 17:39:28 +08:00
Andrei VaginandgVisor bot e5368292ab Move the code that manages floating-point state to a separate package
This change is inspired by Adin's cl/355256448.

PiperOrigin-RevId: 364695931
2021-03-23 18:46:37 -07:00
Ayush RanjanandgVisor bot c3ff9f93bc [op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.

Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
  are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
  returns it and not unix.Stat_t.

Updates #214

PiperOrigin-RevId: 360701387
2021-03-03 10:25:58 -08:00
Jamie LiuandgVisor bot 347e062d3b Add gohacks.Slice/StringHeader.
See https://github.com/golang/go/issues/19367 for rationale. Note that the
upstream decision arrived at in that thread, while useful for some of our use
cases, doesn't account for all of our SliceHeader use cases (we often use
SliceHeader to extract pointers from slices in a way that avoids bounds
checking and/or handles nil slices correctly) and also doesn't exist yet.

PiperOrigin-RevId: 358071574
2021-02-17 17:41:10 -08:00
Robin Luk 5a5995f15f arm64: clean code
In order to improve the performance and stability, I reorg 2 modules slightly.
  arch: no red zone on Arm64.
  ring0: use stp instead of movd, and set RSV_REG_APP=R19.
Signed-off-by: Robin Luk <[email protected]>
2021-02-03 11:50:35 +00:00
Andrei VaginandgVisor bot 751466b0f9 Internal change.
PiperOrigin-RevId: 347720083
2020-12-15 16:51:35 -08:00
Adin ScannellandgVisor bot 69f0412910 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Etienne PerotandgVisor bot c4cee5ea31 Implement fcntl options F_GETSIG and F_SETSIG.
These options allow overriding the signal that gets sent to the process when
I/O operations are available on the file descriptor, rather than the default
`SIGIO` signal. Doing so also populates `siginfo` to contain extra information
about which file descriptor caused the event (`si_fd`) and what events happened
on it (`si_band`). The logic around which FD is populated within `si_fd`
matches Linux's, which means it has some weird edge cases where that value may
not actually refer to a file descriptor that is still valid.

This CL also ports extra S/R logic regarding async handler in VFS2.
Without this, async I/O handlers aren't properly re-registered after S/R.

PiperOrigin-RevId: 345436598
2020-12-03 06:20:29 -08:00
gVisor bot 16d3de2376 Merge pull request #4035 from lubinszARM:pr_misc_01
PiperOrigin-RevId: 335051794
2020-10-02 10:27:03 -07:00
Rahat MahmoodandgVisor bot 468f31e66f Replace remaining uses of reflection-based marshalling.
- Rewrite arch.Stack.{Push,Pop}. For the most part, stack now
  implements marshal.CopyContext and can be used as the target of
  marshal operations. Stack.Push had some extra logic for
  automatically null-terminating slices. This was only used for two
  specific types of slices, and is now handled explicitly.

- Delete usermem.CopyObject{In,Out}.

- Replace most remaining uses of the encoding/binary package with
  go-marshal. Most of these were using the binary package to compute
  the size of a struct, which go-marshal can directly replace. ~3 uses
  of the binary package remain. These aren't reasonably replaceable by
  go-marshal: for example one use is to construct the syscall
  trampoline for systrap.

- Fill out remaining convenience wrappers in the primitive package.

PiperOrigin-RevId: 334502375
2020-09-29 18:08:07 -07:00
Bin Lu 55e2bc67d1 arm64: some minor changes
This patch adds minor changes for Arm64 platform:
  1, add SetRobustList/GetRobustList support for arm64 syscall module.
  2, add newfstatat support for arm64 vfs2 syscall module.
  3, add tls value in ProtoBuf.

Signed-off-by: Bin Lu <[email protected]>
2020-09-25 03:32:57 -04:00
Rahat MahmoodandgVisor bot c25d44649f Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Rahat MahmoodandgVisor bot 172800eed9 Move the 'marshal' and 'primitive' packages to the 'pkg' directory.
PiperOrigin-RevId: 331256608
2020-09-11 17:42:49 -07:00
Bin Lu 64cb7e355e Running hello-world on Thunderx2 with kvm
Signed-off-by: Bin Lu <[email protected]>
2020-08-12 05:37:27 -04:00
lubinszARMandgVisor bot f3c9494e8f kvm-tls-2:add the preservation of user-TLS in the Arm64 kvm platform
This patch load/save TLS for the container application.

Related issue: full context-switch supporting for Arm64 #1238

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/2761 from lubinszARM:pr_tls_2 cb5dbca1c9c3f378002406da7a58887f9b5032b3
PiperOrigin-RevId: 322887044
2020-07-23 16:08:16 -07:00
Bin Lu 53536188e9 initialize an empty fp state area for sentry on Arm64
We need to initialize an empty fp state area for the sentry.

Signed-off-by: Bin Lu <[email protected]>
2020-06-09 05:01:03 -04:00
Adin ScannellandgVisor bot 42f37ead1d Minor formatting updates for gvisor.dev.
* Aggregate architecture Overview in "What is gVisor?" as it makes more sense
  in one place.

* Drop "user-space kernel" and use "application kernel". The term "user-space
  kernel" is confusing when some platform implementation do not run in
  user-space (instead running in guest ring zero).

* Clear up the relationship between the Platform page in the user guide and the
  Platform page in the architecture guide, and ensure they are cross-linked.

* Restore the call-to-action quick start link in the main page, and drop the
  GitHub link (which also appears in the top-right).

* Improve image formatting by centering all doc and blog images, and move the
  image captions to the alt text.

PiperOrigin-RevId: 311845158
2020-05-15 20:05:18 -07:00
Bin Lu e7626a532a Add fpsimd support in sigreturn on Arm64
Signed-off-by: Bin Lu <[email protected]>
2020-05-11 21:53:29 -04:00
Bin Lu 48f954c7b9 code clean in arch module
Signed-off-by: Bin Lu <[email protected]>
2020-04-28 01:15:43 -04:00
Rahat MahmoodandgVisor bot 77606ee3d6 Enable automated marshalling for signals and the arch package.
PiperOrigin-RevId: 308472331
2020-04-25 23:56:04 -07:00
gVisor bot d2306a5df3 Merge pull request #1819 from lubinszARM:pr_signal_2
PiperOrigin-RevId: 308100771
2020-04-23 12:01:38 -07:00
gVisor bot c98d0f7e95 Merge pull request #2168 from xiaobo55x:ptrace_test
PiperOrigin-RevId: 306306809
2020-04-13 14:17:53 -07:00
Jon BuddandgVisor bot 9043a0bb9e Remove obsolete TODOs for b/38173783
The comments in the ticket indicate that this behavior
is fine and that the ticket should be closed, so we shouldn't
need pointers to the ticket.

PiperOrigin-RevId: 306266071
2020-04-13 11:02:14 -07:00
Haibo Xu 6ea313b81a Enable syscall ptrace test on arm64.
Signed-off-by: Haibo Xu <[email protected]>
Change-Id: I5bb8fa7d580d173b1438d6465e1adb442216c8fa
2020-04-10 10:00:26 +08:00
Michael PrattandgVisor bot c87bf956ac Fix 386 build tags
The build tag for 32-bit x86 is 386, not i386.

Updates #2298

PiperOrigin-RevId: 304206373
2020-04-01 10:00:03 -07:00
Bin Lu b376a289bb Arm64 signal#2: signal support in arch module
SA_RESTORER is always used on Intel platform.
But this flag is optional on other platforms.

The vdso is enabled, so we can use the sigreturn trampolines
the vdso provides instead on Arm platform.

Signed-off-by: Bin Lu <[email protected]>
2020-03-31 22:53:15 -04:00
gVisor bot 7851644f57 Merge pull request #2061 from lubinszARM:pr_restart_syscall
PiperOrigin-RevId: 301700868
2020-03-18 17:11:43 -07:00
Bin Lu 22c5d7ed3c passed the syscall test case 'alarm' on Arm64 platform
This issue was caused by 'restart_syscall'.
The value of Register R0 should be stored after finishing sysemu.
So that we can restore the value and restart syscall.

Signed-off-by: Bin Lu <[email protected]>
2020-03-12 05:57:47 -04:00