447 Commits

Author SHA1 Message Date
Lucas Manning 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
Ayush Ranjan 738e1d995f nvproxy: Add HasStatus.SetStatus and provide failWithStatus() util functions.
This creates a more centralized way for nvproxy to return errors to the the
user mode driver via the NvStatus field in ioctl structs. As opposed to failing
the ioctl with mysterious EINVALs.

Also updated the following structs to NOT implement HasStatus interface:
- IoctlRegisterFD
- RMAPIVersion
- IoctlSysParams

These don't have a Status field so it is misleading for them to implement
HasStatus. Created frontendIoctlSimpleNoStatus() and
frontendIoctlInvokeNoStatus() for such structs to use.

PiperOrigin-RevId: 738959856
2025-03-20 15:29:44 -07:00
Lucas Manning 129d4b63a7 Add support for more TPU devices.
PiperOrigin-RevId: 737696637
2025-03-17 11:53:29 -07:00
Nicolas Lacasse 6b0a0af862 Implement basic packet mode support for ptys.
From man TIOCPKT:
"""
In packet mode, each subsequent read(2) will return a packet that either
contains a single nonzero control byte, or has a single byte containing zero
('\0') followed by data written on the slave side of the pseudoterminal."
"""

This CL implements only the data portion of packet mode, not the control bytes,
but that seems to be enough to get xfce4-terminal to work.

PiperOrigin-RevId: 737175092
2025-03-15 09:26:56 -07:00
Jamie Liu 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
Ayush Ranjan 6b4f0082c2 nvproxy: Add support for AMPERE_A, ADA_A, HOPPER_A.
TURING_A was added in e6e1ecbdcc ("Add support for graphics in nvproxy.").
{GPU_ARCH}_A class is used for graphics workloads. Add the missing classes for
other GPU architectures we support.

PiperOrigin-RevId: 726620575
2025-02-13 13:45:12 -08:00
Lucas Manning faac8f36cd Add support for PACKET_STATISTICS.
PiperOrigin-RevId: 725271073
2025-02-10 10:46:54 -08:00
Lucas Manning 9c490f813d Implement GetSockOpt PACKET_HDRLEN and add a test for tcpdump.
PiperOrigin-RevId: 724445536
2025-02-07 13:06:14 -08:00
Lucas Manning 6194338723 Add support for setting PACKET_VERSION for PACKET_MMAP.
tcpdump requires TPACKET_V2 to work properly.

PiperOrigin-RevId: 723670574
2025-02-05 15:19:34 -08:00
Lucas Manning 83a4caf2a7 Implement MappablePacketEndpoint for PACKET_MMAP and add tests.
PiperOrigin-RevId: 723590936
2025-02-05 11:39:27 -08:00
Ayush Ranjan 1a9abee80b nvproxy: Add support for 570.86.15 driver.
Co-authored-by: Zach Koopmans <zkoopmans@google.com>
PiperOrigin-RevId: 721910920
2025-01-31 14:53:49 -08:00
Ayush Ranjan 0b5ee6d4df nvproxy: Add support for v565.57.01.
PiperOrigin-RevId: 720557549
2025-01-28 06:54:35 -08:00
clickyotomy 4a8209f26f netfilter: Support multiport matching (-m multiport)
This set of changes adds:

  - support for `xt_multiport_{,v1}` matchers for matching for
    a range of ports and their inverse, i.e.,:

      ```
      -m multiport [!] --[s|d]ports (PORT,...|PORT:PORT,...)
      ```

  - support for `IP{,6}T_SO_GET_REVISION_MATCH` socket options,
    which allows `iptables` to query for the highest supported
    revision for a given matcher
2025-01-18 09:46:30 -05:00
Lucas Manning 25b1d71341 Add constants and types related to the implementation of PACKET_MMAP.
This is the first in a series of changes that implements PACKET_MMAP.

PiperOrigin-RevId: 716014872
2025-01-15 17:45:19 -08:00
2022tgoel 7399a32b4c Add GPU video codecs support to nvproxy (so that tools like ffmpeg work)
adding cap

tests work

fix merge

unit test

small fixes

additional ioctls for L4 gpu
2025-01-09 01:09:47 +00:00
Ayush Ranjan b11efeaecd nvproxy: Clean up struct field tags.
Before this change, there were 2 places in which the driver struct names were
defined for nvproxy structs:
1. As struct field tags. The first field of structs had a tag `nvproxy:*`. This
   was kind of awkward. Such metadata is usually a struct comment.
2. In version.go while registering the struct with a name. Not all structs are
   defined in nvproxy (for example simple structs). In such cases, the driver
   struct name is directly assigned while registering struct info.

This change gets rid of (1). Most of the struct tags were `nvproxy:"same"`. Now
driverStructs() always infers the driver struct name using the nvproxy struct
name itself. The few cases where the nvproxy tag was needed, because driver
struct name was lower cased, were handled by defining driverStructWithName()
which allows specifying a different name. Now all driver struct names
definitions are in one place.

Along the way, also made the following fixes:
- For some reason, many structs defined in pkg/abi/nvgpu/frontend.go had
  camel-cased naming, while all other structs in pkg/abi/nvgpu/ctrl.go and
  pkg/abi/nvgpu/classes.go were named the same as their driver structs. The
  convention in the abi/* packages is to follow the kernel source naming.
  This is against Go sytle guide, but is more readable for gVisor purposes and
  has been a long accepted convention. This also makes the task of removing (1)
  easier. So renamed all such structs as per their driver names.
- A lot of code in pkg/sentry/devices/nvproxy/version.go was still referring to
  driver struct info as "struct names", even though it was representing more
  than just struct names. It also contains the reflect.Type of the struct which
  is used to compare the nvproxy struct layout to the driver struct layout.

PiperOrigin-RevId: 710648105
2024-12-30 01:32:41 -08:00
Ayush Ranjan e6e1ecbdcc Add support for graphics in nvproxy.
PiperOrigin-RevId: 708100465
2024-12-19 17:41:18 -08:00
Ayush Ranjan 1ca2bd4a69 nvproxy: Improve debuggability by logging failures coming from the host driver.
Most ioctl contain a `Status` field (which in driver code is of type NvStatus)
which indicates if the ioctl command succeeded or not. Non NV_OK=0 values
indicate some kind of failure. In case of failure, the ioctl(2) syscall still
succeeds. So the failure is currently not visible in gVisor strace/debug logs.

This helps flag instances where the host invocation of ioctl(2) resulted in a
failure in the driver.

This also helps avoid the usage of frontendIoctlSimple() in some cases.
frontendIoctlSimple() heap allocates a byte buffer. It is better to copy into
the ioctl params on the stack when possible.

PiperOrigin-RevId: 707312482
2024-12-17 17:26:22 -08:00
Ayush Ranjan ab9d8455d4 Re-use the same device file inode in tmpfs for overlay whiteout files.
When using overlayfs with tmpfs as the upper layer (common case), depending on
the application, a lot of whiteouts can be created. This leads to a lot of
memory allocation because new dentry and inode structs need to be allocated for
each whiteout. With this change, we at least avoid the inode allocations.

This is analogous with what Linux does. See fs/overlayfs/ovl_entry.h:ovl_fs's
field `whiteout` with comment "Shared whiteout cache".

PiperOrigin-RevId: 704897805
2024-12-10 17:11:22 -08:00
Jamie Liu 01e30ab09b nvproxy: don't depend on HVASpace for non-virtmem NVOS32_FUNCTION_ALLOC_SIZE
PiperOrigin-RevId: 704780681
2024-12-10 11:26:47 -08:00
Jamie Liu a55b3b2d90 nvproxy: track objects created by NV_ESC_RM_DUP_OBJECT
PiperOrigin-RevId: 704502046
2024-12-09 18:59:36 -08:00
Andrei Vagin 03a28d158e platform/systrap: return memory access type based on a page fault error code
Now we don't need to trigger a second fault to figure out whether it was write
or read access.

Fixes #11008

Co-developed-by: Jamie Liu <jamieliu@google.com>
PiperOrigin-RevId: 697677262
2024-11-18 10:33:59 -08:00
Jamie Liu cf5841ba66 mm: implement prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME)
PiperOrigin-RevId: 696727156
2024-11-14 19:06:07 -08:00
Jing Chen 17edc7260e Support TPU v6e w/ gVisor.
PiperOrigin-RevId: 687514246
2024-10-18 20:43:34 -07:00
Jing Chen a093ad0450 Simplify and format gVisor codebase.
The changes are just output of `gofmt -s -w .`.
2024-10-13 00:50:32 -07:00