21 Commits
Author SHA1 Message Date
Jamie LiuandgVisor bot 86ceb5c26a Fix memmap.Translation.Perms returns.
memmap.Mappable.Translate() is passed a hostarch.AccessType indicating what
permissions are *immediately* required; it returns permissions in
memmap.Translation.Perms that are granted *to MM* until invalidation. MM
ensures that the permissions granted to the application are the intersection of
those granted by Translate, and those granted by VMA permissions; see
determination of pma.effectivePerms in
mm.MemoryManager.getPMAsInternalLocked(). This mechanism is used to avoid
marking pages dirty in the sentry's page cache for gofer-backed files until
PROT_WRITE pages are actually written to; see gofer.dentry.Translate(). In most
other cases, granting all supported permissions (to MM) up-front avoids a
redundant page fault for pages that are touched first for reading, and later
for writing.

Also:

- Prevent PROT_WRITE mappings of erofs files at mmap()/mprotect() time, rather
  than raising SIGBUS when writing to such mappings.

- Map nvproxy.frontendFD with PlatformEffectPopulate. This is the original goal
  of this CL; however, before this rest of this CL, MM.MMap() =>
  MM.populateVMAAndUnlock() => MM.getPMAsLocked(at=hostarch.NoAccess) =>
  MM.getPMAsInternalLocked(at=hostarch.NoAccess) =>
  nvproxy.frontendFD.Translate(at=hostarch.NoAccess) returns Translations with
  no permissions, causing MM.mapASLocked() to no-op.

PiperOrigin-RevId: 679360594
2024-09-26 17:59:37 -07:00
Ayush RanjanandgVisor bot ed9678b679 Delete pgalloc.MemoryFileProvider.
The work done in c087777e37 ("Plumb restore context to afterLoad()") makes
pgalloc.MemoryFileProvider redundant as structs can now easily restore
pgalloc.MemoryFile in stateify's afterLoad() method. This allows structs to
have a pgalloc.MemoryFile field and use that directly, instead of going through
the provided interface.

This cleans up a lot of code and also should be more performant (avoids an
interface method call on many hot paths).

PiperOrigin-RevId: 615258927
2024-03-12 20:06:58 -07:00
Fabricio VoznikaandgVisor bot 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
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
Nayana BidariandgVisor bot f8c4846f21 Pass memory cgroup id in pgalloc.Allocate()
For memory accounting per task, the memory cgroup id of the task is required.
This CL retrieves the cgroup id from the task context and stores it in the
AllocOpts struct which will later be used to account for memory usage.

PiperOrigin-RevId: 546996195
2023-07-10 15:16:47 -07:00
Ayush RanjanandgVisor bot 04450bfbeb Don't return EINVAL if buf_index is set for IORING_OP_READV.
This is consistent with what Linux does after bb68d504f7c4 ("io_uring: ignore
->buf_index if REQ_F_BUFFER_SELECT isn't set").

This is causing the READVWithInvalidSqeFieldValue test to fail on newer kernel.

PiperOrigin-RevId: 527386953
2023-04-26 15:13:33 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Michael PrattandgVisor bot 8604e1c200 Avoid use of gohacks.SliceHeader to access pointer to data
Accessing a pointer to the data in a slice can be achieved with
`unsafe.Pointer(&slice[0])`.

f051ec6463 motivated using gohacks.SliceHeader in
this way with "we often use SliceHeader to extract pointers from slices in a
way that avoids bounds checking and/or handles nil slices correctly", but this
no longer seems to be the case. None of the remaining uses are obviously
performance sensitive or necessarily include bounds checks, nor get used with
nil slices.

This brings us one step closer to removing gohacks.SliceHeader, which is one
less internal detail to keep in sync with Go.

For #8422

PiperOrigin-RevId: 504408578
2023-01-24 16:42:27 -08:00
Rahat MahmoodandgVisor bot ef96e9328e Disable io_uring syscalls by default.
The current io_uring support is very limited and experimental. Disable
it by default, and add a flag to enable it for testing.

PiperOrigin-RevId: 500760451
2023-01-09 11:11:57 -08:00
Rahat MahmoodandgVisor bot a005752d88 iouringfs: Pet the watchdog during ProcessSubmissions.
This loop can take a long time. Since we're blocking on IO outside
Task.Block, we need to periodically check for interrupts and update
pet the watchdog.

Reported-by: syzbot+3fd282d7e4e5c83fc196@syzkaller.appspotmail.com
PiperOrigin-RevId: 494009269
2022-12-08 15:23:00 -08:00
Rahat MahmoodandgVisor bot 85d931396e iouringfs: Properly block tasks serializing on ProcessSubmissions.
Previously we were using a mutex to serialize concurrent callers to
ProcessSubmissions. The processing loop can run for a long time, so
blocking a task on a Lock() can lead to watchdog timeouts as well as
interruptibility issues.

Instead, put concurrent callers to sleep with Task.Block.

PiperOrigin-RevId: 492527965
2022-12-02 12:20:34 -08:00
Ayush RanjanandgVisor bot 1fa3c06f1e Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Rahat MahmoodandgVisor bot 3c0e0a3746 io_uring: Fix several issues with shared ring buffers.
- Don't use params stored in the shared buffers because they're
  modifiable by userspace. Instead, keep a private copy of these
  params for sentry use.

- The ring pointers were being copied and polled incorrectly. Instead
  of marshalling the various head/tail pointers, load them directly
  from the shared memory regions.

- Restructure mapping and marshalling code.

Reported-by: syzbot+ed041382441c65be76a3@syzkaller.appspotmail.com
Reported-by: syzbot+be78f32e26e862cca391@syzkaller.appspotmail.com
Reported-by: syzbot+97b5b9af7db8a967fa24@syzkaller.appspotmail.com
Reported-by: syzbot+6b831509e7b43bdb5788@syzkaller.appspotmail.com
PiperOrigin-RevId: 489281803
2022-11-17 12:45:32 -08:00
Rahat MahmoodandgVisor bot f3aaf43266 io_ring: Handle EOF on IORING_OP_READV
EOFs shouldn't be raised as an errno as error translation will
fail. Short reads aren't failures on a readv syscall.

Reported-by: syzbot+37fc0fc0df42740a5cea@syzkaller.appspotmail.com
PiperOrigin-RevId: 489242631
2022-11-17 10:17:39 -08:00
Sergey MadaminovandgVisor bot 60f83d99ea io_uring_enter: adding support for READV operation.
Handling NOP operations helped us to introduce facilities to process submission
requests. Now we can proceed to adding more meaningful operations. The logical
choice for the first one is the READV operation as it is a next operation after
NOP and it is also used for the cat-like application example based of IO_URING.

PiperOrigin-RevId: 487615618
2022-11-10 12:54:50 -08:00
Sergey MadaminovandgVisor bot a1476ce4f5 io_uring_setup: fixing cqentries setup bug.
We should compare against maximum number of allowed cq entries instead of
comparing against the flag that allows to set that number.

PiperOrigin-RevId: 487045476
2022-11-08 14:05:14 -08:00
Rahat MahmoodandgVisor bot d4b159ae93 iouring: Disallow zero, or less CQ entries than SQ entries
Reported-by: syzbot+ad039a9d567cc9ba5ea8@syzkaller.appspotmail.com
PiperOrigin-RevId: 485230763
2022-10-31 22:34:06 -07:00
Sergey MadaminovandgVisor bot 9ae2eea3ba io_uring_enter with NOP implementation for the IO_URING.
With io_uring_setup() and mmap() we can proceed with implementing a simplest
operation, namely, NOP. Once we make sure that we can send this command and
receive a response from the gVisor, we can move forward to read operation.

PiperOrigin-RevId: 485106019
2022-10-31 11:39:18 -07:00
Adin ScannellandgVisor bot 2928c19239 Move to code generation rather than reflection for io_uring offsets.
This avoids the cost at startup time and allows the resulting function to
be more effectively inlined to call sites. Although these are not widely
used at the moment, this change may also be used as an example for code
generation in similar cases.

PiperOrigin-RevId: 477597333
2022-09-28 17:53:21 -07:00
Sergey MadaminovandgVisor bot 05e7c2fceb mmap() implementation for the IO_URING.
Once the user receives a file descriptor from `io_uring_setup()`, it will be
used for the subsequent `mmap()` calls. Thus, we need to add support for it in
our iouringfs.

PiperOrigin-RevId: 477318038
2022-09-27 17:44:25 -07:00
Sergey MadaminovandgVisor bot 31d8668e51 Pseudo-filesystem iouringfs for IO_URING.
Similar to Linux, we should add pseudo-filesystem iouringfs in gVisor to back
IO_URING's file descriptors. We start with stubbing `io_uring_setup(2)` so it
provides a file descriptor backed by anonfs.

PiperOrigin-RevId: 473384042
2022-09-09 18:09:29 -07:00