17 Commits
Author SHA1 Message Date
Jamie LiuandgVisor bot b01944883b Add memmap.File.MemoryType()
This has no effect (outside of debug logging) until cl/723723715.

Updates #11436

PiperOrigin-RevId: 736686635
2025-03-13 17:08:52 -07:00
Jamie LiuandgVisor bot 0659b6035a vfs: establish lock ordering for FilesystemImpl.PrependPath
- Add type parameter Filesystem to vfs/genericfstree, which is required to
  provide `ancestryMu sync.RWMutex`, and add such a RWMutex to all FSImpls that
  use genericfstree.

- Modify genericfstree.PrependPath() and genericfstree.IsDescendant() to use
  ancestryMu to ensure atomicity. For callers of genericfstree.PrependPath(),
  this means that (broader) FSImpl locks no longer need to be held during the
  call. For callers of genericfstree.IsDescendant(), this means that we can
  remove documentation warnings about its non-atomicity.

- Minor cleanup: Remove useless variable `start`, which is always 0, from
  MM.ReadMaps/SmapsDataInto().

PiperOrigin-RevId: 696713993
2024-11-14 18:14:27 -08:00
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
Jamie LiuandgVisor bot a50fb5ded0 Add memmap.File.DataFD().
This is used in cl/674746696 to ensure that users of MemoryFile data wait until
that data has been loaded.

PiperOrigin-RevId: 679255898
2024-09-26 12:51:20 -07:00
Jamie LiuandgVisor bot 31979a7187 mm: add fallback to buffered I/O when memmap.File.MapInternal() is unavailable
MapInternal() returns a coherent memory mapping of the host file descriptor
represented by a memmap.File, in the sentry's address space. This is
principally used when the sentry needs to access the contents of application
memory (for e.g. syscall arguments passed by pointer, or the source/destination
of a write()/read() syscall); it usually looks up the memmap.Files backing
application addresses and obtains mappings via MapInternal().

/dev/nvidia-uvm cannot generally be mapped into the sentry's address space, for
reasons described by
https://github.com/google/gvisor/blob/master/g3doc/proposals/nvidia_driver_proxy.md#unified-virtual-memory-uvm
(in short, nvidia-uvm requires that a given page at file offset X can only be
mapped at address X). To allow the sentry to access the contents of such
mappings, make it possible for memmap.File.MapInternal() to indicate that a
fallback to buffered I/O is required, add interface methods
memmap.File.Buffer{Read,Write}At() to perform this buffered I/O, and implement
this fallback in the MM I/O path.

This CL does not use the new buffered I/O fallback anywhere; a following CL
adds it to nvproxy's nvidia-uvm.

Updates #10331

PiperOrigin-RevId: 629830825
2024-05-01 14:05:55 -07:00
Fabricio VoznikaandgVisor bot 26dd42a0ea Allow host FD to be restored with a different FD
FD numbers can vary between depending on the options used with
runsc command. For example, there are extra FDs passed to
`runsc boot` if `debug-log` is enabled. So instead of requiring
all FDs to have the exact same numbering during restore, provide
a mechanism to remap the FD. Each host FD has a unique identifier
with a map to their corresponding FD. Then during restore, FD
numbers are remapped to the correct ones.

Updates #1956

PiperOrigin-RevId: 615215783
2024-03-12 16:57:07 -07:00
Ayush RanjanandgVisor bot 50db853e59 Update fsimpl/erofs to not depend on FilesystemImplSaveRestoreExtension.
Now with restore context available in afterLoad(), we don't need to depend
on this extension.

PiperOrigin-RevId: 614913227
2024-03-11 22:36:46 -07:00
Ayush RanjanandgVisor bot 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 VoznikaandgVisor bot 35dab382a6 Add container name to unique path keys
This is to allow multi-containers to be saved/restored
without conflicting "unique" IDs.

Updates #1956

PiperOrigin-RevId: 601231193
2024-01-24 14:16:44 -08:00
Ayush RanjanandgVisor bot 2d90b66af1 Add checkpoint/restore support for tmpfs with file backend.
Tmpfs with file-backed are widely used:
1. Via --overlay2 flag. The default is root:self so the root mount uses this.
2. EmptyDir mounts with default medium are created as tmpfs with file backend.

This change unblocks (1) use case from being used with checkpoint/restore.
For (2), checkpoint/restore is not yet supported in multicontainers.

Most notably, this allows checkpoint/restore to work with default runsc flags.

PiperOrigin-RevId: 586291915
2023-11-29 04:16:21 -08:00
Tiwei Bie 0da79ed4bf erofs: support block based dirent lookup
This patch adds the block based dirent lookup support to pkg/erofs,
which will do the dirent lookup by doing binary search on disk data
directly. This is helpful for searching files in large directories
and also reduces the memory overhead.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-11-28 12:59:35 +08:00
Tiwei Bie 3bcfd77929 erofs: cleanups and hardening
- Add more sanity checks on dirent name offset and length.
- Both of "super block" and "superblock" are used in comments and
  strings now, let's convert all "super block" to "superblock".
- Add some comments that can add clarity.
- Refactor the code in tests to make it easier to add more tests.

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-11-28 10:32:58 +08:00
Tiwei Bie bff11508c7 runsc: add the EROFS rootfs support
This patch adds the EROFS rootfs support. No gofer process will be
created for the container, when there is no need to pass through host
files into a container via the gofer process. Annotations for rootfs
are also introduced to provide extra information, including the mount
source, mount type and overlay config. Additionally, busybox-static
is added to the default image and will be used to build the EROFS
rootfs images during the test.

Updates #8956

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-11-07 08:02:16 +08:00
gVisor bot f4b7b8f5e3 Merge pull request #9577 from btw616:erofs-checkpoint-restore-support
PiperOrigin-RevId: 576593626
2023-10-25 11:41:16 -07:00
Tiwei Bie 78a667cb8a erofs: add checkpoint/restore support
Updates #8956

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-10-23 22:02:41 +08:00
Tiwei Bie 15e4366487 erofs: fix wrong assumption on the order of on-disk directory entries
For each directory, _all_ the on-disk directory entries are _strictly_
recorded in alphabetical order. There is no special treatment of "." and
"..". Thanks to @hsiangkao for pointing out this bug.

Fixes: eca83ac68c ("Add initial support for EROFS")
Reported-by: Gao Xiang <xiang@kernel.org>
Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-10-07 21:15:16 +08:00
Tiwei Bie eca83ac68c Add initial support for EROFS
This patch adds initial support for EROFS [1]. Below is a brief
summary of the supported features.

Both inode formats are supported:

- compact format (32 bytes);
- extended format (64 bytes);

Below data layouts are supported:

- flat file data without data inline (no extent);
- flat file data with tail packing data inline (no extent);

Below file types are supported:

- directory;
- regular file;
- symlink;

Special files (e.g. fifo) can be listed, but cannot be accessed.

With this patch, sentry will be able to mount the EROFS image
created with below command and access the files on it.

 mkfs.erofs -E noinline_data <IMAGE FILE> <SOURCE DIRECTORY>

[1] https://docs.kernel.org/filesystems/erofs.html

Updates #8956

Signed-off-by: Tiwei Bie <tiwei.btw@antgroup.com>
2023-10-04 18:15:30 +08:00