40 Commits
Author SHA1 Message Date
Lucas ManningandgVisor bot 3a9ba17351 Fix device FD reference leaks and add support for VFIO_GROUP_UNSET_CONTAINER.
Fixes #11545

PiperOrigin-RevId: 739274186
2025-03-21 13:07:59 -07:00
Lucas ManningandgVisor bot 8482715727 Enable save/restore with TPUproxy.
This change also adds some small cleanup to TPU code.

PiperOrigin-RevId: 737673712
2025-03-17 10:55:06 -07:00
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 a5459a26cb Add memmap.MMapOpts.RequirePlatformEffect and use where appropriate.
Per the comment for vfs.GenericProxyDeviceConfigureMMap(), this ensures that if
invalid arguments are provided to application mmap() for a proxy device file,
then an error is returned immediately (from host mmap()) rather than when
demand paging causes host mmap() to be invoked.

PiperOrigin-RevId: 680733678
2024-09-30 15:13:16 -07: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
Lucas ManningandgVisor bot ab64b5eb54 Create a precise host file mapper that respects host file ranges.
This is required to get tpuproxy to work properly on the KVM platform.

PiperOrigin-RevId: 676120793
2024-09-18 14:02:15 -07:00
Jamie LiuandgVisor bot 8425e278c5 segment: add Set.Remove[Full]RangeWith()
These support the relatively common use case of removing all segments in a
given range (unconditionally) but doing something with them before they're
removed. This is always more compact, and may be slightly faster in some cases
(every replaced loop calls Isolate per iteration, while RemoveRangeWith avoids
redundant split checks between segments), at the cost of a direct function
call.

Also slightly optimize Set.LowerBoundSegmentSplitBefore() and
Set.UpperBoundSegmentSplitAfter() by inlining LowerBoundSegment and
UpperBoundSegment respectively; in the cases where Find() returns a
GapIterator, the segment that is returned doesn't need to be split since it
doesn't contain min/max respectively.

PiperOrigin-RevId: 675824581
2024-09-17 21:21:20 -07:00
Lucas ManningandgVisor bot 290789bab8 Refactor tpu chroot operations.
Ubuntu TPU images do not have the vfio-dev directories that COS images do,
so we need a more robust way of setting up the sandbox chroot to handle this
case. This change implements a way to get devices and minor numbers into the
sandbox with minimal support from the host filesystem and cleans up a few
methods to reflect their current usage.

Addresses #10795

PiperOrigin-RevId: 674363342
2024-09-13 11:15:28 -07:00
Lucas ManningandgVisor bot 932d9dc64b Add nested PCI device support and option to read directly from host dev files.
PiperOrigin-RevId: 670751194
2024-09-03 16:51:13 -07:00
Lucas ManningandgVisor bot 974e6dac72 Internal change.
PiperOrigin-RevId: 670667358
2024-09-03 12:48:06 -07:00
Lucas ManningandgVisor bot e29e270730 Reorganize tpuproxy code.
Now there is a main tpuproxy directory and two subdirs for each of the
different proxy implementations.

PiperOrigin-RevId: 667688748
2024-08-26 13:17:41 -07:00
Lucas ManningandgVisor bot bbbecc35cc Add support for v5pod and fix TPU v5 bugs.
V5 support was broken in a few different ways:
- tpu device files (/dev/vfio/X) were created with incorrect minor device nums.
- PCI paths on bus' other than 0000:00 were not supported.
- VFIO unmap was broken and not properly added to the seccomp allowlist.
- The VFIO main device file (/dev/vfio/vfio) did not account for overlapping
  device address ranges that correspond to different VFIO container groups.

Previously TPU support was tested on machines with single TPUs, which masked
most of these issues.

All these issues should be fixed by this change. Tested manually on GKE.

PiperOrigin-RevId: 656037853
2024-07-25 12:12:30 -07:00
Andrei Vagin af92292ac8 Fix typos 2024-05-02 11:09:16 -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
Jing ChenandgVisor bot 7ff0b64d6e Add pciDeviceFD mmap and initialize it with the corresponding host FD.
It removes kernfs.CachedMappable from pciDeviceFD.

PiperOrigin-RevId: 624296998
2024-04-12 14:45:22 -07:00
Jing ChenandgVisor bot 32afe881c5 Update tpuproxy package for a more consistent gVisor naming convention.
PiperOrigin-RevId: 620321751
2024-03-29 13:13:39 -07:00
Jing ChenandgVisor bot 88ee65f3a8 Implement pass through ioctl VFIO_IOMMU_UNMAP_DMA.
PiperOrigin-RevId: 620107765
2024-03-28 17:47:12 -07:00
Jing ChenandgVisor bot 79dd2520ff Implement ioctl command VFIO_IOMMU_MAP_DMA.
PiperOrigin-RevId: 619691808
2024-03-27 16:10:41 -07:00
Jing ChenandgVisor bot e902007771 Make vfio-pci devices mmappable backed by a host FD.
PiperOrigin-RevId: 619265846
2024-03-26 12:00:42 -07:00
Jing ChenandgVisor bot f94df6d1bf Implement VFIO-PCI TPU device's Pread and Pwrite to enable bus master at host.
PiperOrigin-RevId: 618998464
2024-03-25 16:50:53 -07:00
Jing ChenandgVisor bot 81e6512014 Implmenet ioctl command VFIO_DEVICE_RESET.
PiperOrigin-RevId: 618077589
2024-03-21 23:44:42 -07:00
Jing ChenandgVisor bot 628f1bad34 Implement the ioctl command VFIO_DEVICE_SET_IRQS.
PiperOrigin-RevId: 618047305
2024-03-21 20:43:12 -07:00
Jing ChenandgVisor bot 24251f576d Implement pass through ioctl command VFIO_DEVICE_GET_IRQ_INFO.
PiperOrigin-RevId: 618034948
2024-03-21 19:40:16 -07:00
Jing ChenandgVisor bot 8739b58b61 Implement pass through ioctl command VFIO_DEVICE_GET_REGION_INFO.
PiperOrigin-RevId: 617760440
2024-03-21 01:27:48 -07:00