332 Commits
Author SHA1 Message Date
Nayana BidariandgVisor bot e6b6f2aa11 Allow IPv6 addresses to be enabled/disabled in runsc based on the sysctl.
By default in runsc, we have both IPv4 and IPv6 addresses enabled on all the
interfaces. However, in runc this is based on the sysctl
net.ipv6.conf.all.disable_ipv6. This CL will make runsc behave similar to runc.
- If net.ipv6.conf.all.disable_ipv6 is > 0, then only IPv4 addresses will be
enabled on the interfaces including loopback when network mode is "sandbox".

PiperOrigin-RevId: 737656607
2025-03-17 10:10:46 -07:00
Ayush RanjanandgVisor bot 138e98fb7d nvproxy: Refactor DriverVersion out to nvconf package.
This allows for runsc to be able to use DriverVersion without having to depend
on the entirety of nvproxy.

PiperOrigin-RevId: 733912696
2025-03-05 16:43:03 -08:00
Nayana BidariandgVisor bot d05a277ca3 Add checkpoint restore metrics.
- SandboxCheckpointedMetric and SandboxRestoredMetric are added for sandbox
metadata metric which indicate whether sandbox is checkpointed or restored.
- NumCheckpointedSandboxesMetric and NumRestoredSandboxesMetric are added at
the process level which will get the count of number of sandboxes being
checkpointed and restored.

PiperOrigin-RevId: 726797010
2025-02-14 00:00:09 -08:00
Andrei Vagin f010ae01ac Fix a few typos 2025-01-29 21:16:51 -08:00
Fabricio VoznikaandgVisor bot fb730ff784 Remove checkpoint_count from runsc wait --checkpoint
This is done because external callers are not able to know
the snapshot generation number from the outside.

PiperOrigin-RevId: 707979556
2024-12-19 11:48:10 -08:00
Etienne PerotandgVisor bot 4362b11be9 Add --final-metrics-log flag to export metric data upon sandbox termination.
Fixes issue #11068

PiperOrigin-RevId: 688395401
2024-10-21 22:09:40 -07:00
Kevin KrakauerandgVisor bot 47dade3f98 runsc: don't error with --reproduce-nftables when there are no nftables rules
It's not an error for there to be no rules worth scraping. It just means we
don't have to do anything.

PiperOrigin-RevId: 683815384
2024-10-08 17:15:01 -07:00
Andrei VaginandgVisor bot 172bcc9bed runsc: grant CAP_SYS_PTRACE to the sandbox process when it is required
PiperOrigin-RevId: 683687479
2024-10-08 11:03:36 -07:00
Etienne PerotandgVisor bot 8e601582c2 Make runsc aware of host kernel settings and offer to tweak them.
This adds a `hostsettings` package which can be used to check and
optionally automatically adjust host kernel settings.

This currently covers six kernel settings:

  - `/proc/sys/kernel/yama/ptrace_scope`: must set to 0 or 1 when using
    `ptrace`.
  - `/proc/sys/user/max_user_namespaces`: must be >= 2, but also
    suggest increasing it further if low.
  - `/proc/sys/kernel/unprivileged_userns_clone`: Must be enabled in
    rootless mode.
  - `/proc/sys/kernel/unprivileged_userns_apparmor_policy`: Same.
  - `/proc/sys/vm/max_map_count`: suggest increasing max host VMAs.
  - `/sys/kernel/mm/transparent_hugepage/shmem_enabled`: suggest turning
    on transparent hugepages.

This is flag-gated; by default `runsc` only checks that these settings
are optimal, but only warns if they are not optimal (unless marked as
mandatory). Other flag settings can be used to either bypass this process
entirely (to avoid the small startup overhead this adds), or to make it
auto-adjust any suboptiomal kernel settings, either on a best-effort or
mandatory basis.

Updates issue #5964
Updates issue #9006

PiperOrigin-RevId: 683375555
2024-10-07 16:51:35 -07:00
gVisor bot 4962090d25 Merge pull request #10954 from google:test/avagin/network_plugins
PiperOrigin-RevId: 679730224
2024-09-27 14:34:57 -07:00
Jamie LiuandgVisor bot 41f01d8f9c pgalloc: integrate async page loading
When a pages file is provided to `runsc restore`, reads from that file are
asynchronous (via statefile.AsyncReader) in order to maximize throughput.
However, all such reads must complete before Kernel.LoadFrom() returns, so
applications cannot execute before MemoryFile loading is complete. The main
objective of this CL is to allow reads to continue after Kernel.LoadFrom()
returns, allowing applications to execute while MemoryFile loading is still in
progress. This behavior is user-visible: it affects whether deleting the pages
file frees disk space immediately on POSIX filesystems, may affect whether
deletion is possible on non-POSIX filesystems, and prevents unmounting
regardless. Thus it is flag-guarded as `runsc restore --background`.

MemoryFile ranges that have yet to be loaded, but that are being waited-for by
applications, should be prioritized over ranges for which no application is
waiting. This requires that application requests for data (calls to
MemoryFile.(memmap.File).DataFD/MapInternal()) are able to determine which
ranges have not yet been loaded, request reads for such ranges with elevated
priority, and wait for only those reads to be completed; none of these are
supported by the existing statefile.AsyncReader.

Thus:

- Add //pkg/sentry/pgalloc/aio, which provides an async I/O API that is
  designed to be easily implementable using a goroutine pool, Linux native AIO,
  or io_uring, though only includes a goroutine pool implementation. (io_uring
  is widely disabled due to security vulnerabilities. In my testing, Linux
  native AIO is slower than the goroutine pool, but this may change with lower
  GOMAXPROCS which needs further testing.)

- Move I/O scheduling into pgalloc: introduce an async page loader goroutine
  that is started by MemoryFile.LoadFrom() when async page loading is requested
  (implicitly, via the existence of a pages file), which is responsible for
  driving submission of read requests and handling their completions.

PiperOrigin-RevId: 679321884
2024-09-26 15:51:13 -07:00
Andrei Vagin ec18cb188f buildkite: run intergration tests with the network plugin 2024-09-25 21:35:17 -07:00
Kevin KrakauerandgVisor bot 90faaeb34f runsc: remove cilium as a dependency unless built with --define=gotags=xdp
XDP isn't currently being used or developed, so it's best to reduce external
dependencies.

PiperOrigin-RevId: 678786045
2024-09-25 11:43:46 -07:00
gVisor bot 079c1a937b Merge pull request #9551 from amysaq2023:support-external-stack
PiperOrigin-RevId: 677933413
2024-09-23 14:12:32 -07:00
Jamie LiuandgVisor bot 14560f6815 Handle concurrent FD closure in sandbox.setCloExeOnAllFDs().
PiperOrigin-RevId: 673551838
2024-09-11 15:12:21 -07:00
gVisor bot 3c4b246cf2 Fix printf violations inside of the gvisor code
Recently printf.Analyzer has become stricter
(https://github.com/golang/go/issues/60529)
which led to new findings.
gvisor nogo tests run this analyzer and fail if it produces findings.

PiperOrigin-RevId: 671657227
2024-09-06 00:45:23 -07:00
Andrei VaginandgVisor bot cc1f5503f1 runsc: always run the sandbox process in a new pid namespace
The sandbox process was executed in the current pid namespace if a target
platform used ptrace. It was the workaround for the kernel issue that was
fixed by 8fb335e07837 ("kernel/exit.c: release ptraced tasks before
zap_pid_ns_processes"). This fix was back-ported to stable branches.

PiperOrigin-RevId: 668121544
2024-08-27 13:45:32 -07:00
Ayush RanjanandgVisor bot 01a3927adf Fix Sandbox.ControlSocketPath if the rootDir path has changed.
The rootDir path can change if the runsc caller is invoking runsc from a
different mount namespace (for example from within a privileged container).

Sandbox.sandboxConnect() tries to use this path to connect to the sandbox.

PiperOrigin-RevId: 661340742
2024-08-09 11:32:19 -07:00
Ayush RanjanandgVisor bot 19f6b0c07f Use /proc/sys/net/core/dev_weight to determine if we are in the root netns.
After 19249c0724f2 ("net: make net.core.{r,w}mem_{default,max} namespaced")
/proc/sys/net/core/rmem_default is present in non-initial netns as well.

/proc/sys/net/core/dev_weight has existed from the beginning of Linux git repo
in 1da177e4c3f4 ("Linux-2.6.12-rc2"). So it should be safe to use this file.

Demo:
```
$ sudo ip netns add foo
$ sudo ip netns exec foo stat /proc/sys/net/core/dev_weight
stat: cannot statx '/proc/sys/net/core/dev_weight': No such file or directory
$ sudo ip netns delete foo
```

Fixes #10704

PiperOrigin-RevId: 658087447
2024-07-31 11:50:13 -07:00
Andrei VaginandgVisor bot cd56935ddf runsc: pass the GLIBC_TUNABLES env to the sandbox process
It is required to disable rseq for runsc-race.

PiperOrigin-RevId: 653752784
2024-07-18 14:19:36 -07:00
Ayush RanjanandgVisor bot bd9b5a819f Add a runsc wait --checkpoint n command to wait for a checkpoint to complete.
This command waits for (n-1)th checkpoint to complete successfully. Then waits
for the next checkpoint attempt (which would increment checkpoint count to n)
and returns its status.

If sandbox checkpoint count has already reached n, it returns immediately.

PiperOrigin-RevId: 651884599
2024-07-12 14:19:46 -07:00
Anqi Shen 56f2530dad Support plugin network stack
This commit supports a third-party network stack as a plugin stack for
gVisor.

The overall plugin package structure is the following:

- pkg/sentry/socket/plugin:
  Interfaces for initializing plugin network stack. It will be used
  in network setting up during sandbox creating.

- pkg/sentry/socket/plugin/stack:
  Glue layer for plugin stack's socket and stack ops with sentry. It
  will also register plugin stack operations if imported.

- pkg/sentry/socket/plugin/cgo:
  Interfaces defined in C for plugin network stack to support.

To build target runsc-plugin-stack, which imports
pkg/sentry/socket/plugin/stack package and enables CGO:

bazel build --config=plugin-tldk runsc:runsc-plugin-stack

(i.e. --config=plugin-tldk indicates that using TLDK as plugin stack)

By using runsc-plugin-stack binary and setting "--network=plugin" in
runtimeArgs, user can use third-party network stack instead of
netstack embedded in gVisor to get better network performance.

Redis benchmark with following setups:
1. KVM platform
2. 4 physical cores for target pod
3. target pod as redis server

Runc:
$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 115207.38 requests per second, p50=0.215 msec
GET: 92336.11 requests per second, p50=0.279 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 113895.21 requests per second, p50=0.247 msec
GET: 96899.23 requests per second, p50=0.271 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 126582.27 requests per second, p50=0.199 msec
GET: 95969.28 requests per second, p50=0.271 msec

Runsc with plugin stack:
$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 123915.74 requests per second, p50=0.343 msec
GET: 115473.45 requests per second, p50=0.335 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 120918.98 requests per second, p50=0.351 msec
GET: 117647.05 requests per second, p50=0.351 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 119904.08 requests per second, p50=0.367 msec
GET: 112739.57 requests per second, p50=0.375 msec

Runsc with netstack:
$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 59952.04 requests per second, p50=0.759 msec
GET: 61162.08 requests per second, p50=0.631 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 52219.32 requests per second, p50=0.719 msec
GET: 58719.91 requests per second, p50=0.663 msec

$redis-benchmark -h [target ip] -n 100000 -t get,set -q
SET: 59952.04 requests per second, p50=0.751 msec
GET: 60827.25 requests per second, p50=0.751 msec

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

Co-developed-by: Tianyu Zhou <wentong.zty@antgroup.com>
Signed-off-by: Anqi Shen <amy.saq@antgroup.com>
2024-07-12 09:10:13 +00:00
Etienne PerotandgVisor bot b4ca91450f Standardize timestamps in runsc log filenames.
Prior to this change, the log files each have their own timestamp computed
independently. For example, this means that the coverage log file, the panic
log file, the debug log file, the first Gofer's log file, and the profile
files for the same Sentry may all have different timestamps in their
filenames. Now they are the same.

This change introduces a central `runsc/starttime` package for which the sole
purpose is to hold the start time of the `runsc` process, for easy plumbing
in all places that need it.

PiperOrigin-RevId: 646667986
2024-06-25 17:48:13 -07:00
Fabricio VoznikaandgVisor bot d4e733ac17 Add a few extension points
PiperOrigin-RevId: 644476039
2024-06-18 12:31:58 -07:00
Ayush RanjanandgVisor bot e14770381f Add save/restore/resume hooks in runsc/boot/restore.go.
Move save/resume methods to containerManager.

PiperOrigin-RevId: 642011529
2024-06-10 13:54:20 -07:00