From 1ae5fca498ebe10607ad0e4d5e83214e0e7507a4 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Wed, 17 Jan 2024 14:56:10 -0800 Subject: [PATCH] Add SupportedIoctls() to nvproxy. This allows callers to get all the ioctl/command/class numbers that nvproxy supports. PiperOrigin-RevId: 599298654 --- pkg/sentry/devices/nvproxy/version.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/sentry/devices/nvproxy/version.go b/pkg/sentry/devices/nvproxy/version.go index 3b3fd0ed4..90174f5a2 100644 --- a/pkg/sentry/devices/nvproxy/version.go +++ b/pkg/sentry/devices/nvproxy/version.go @@ -377,3 +377,30 @@ func ExpectedDriverChecksum(version DriverVersion) (string, bool) { } return abi.checksum, true } + +// SupportedIoctls returns the ioctl numbers that are supported by nvproxy at +// a given version. +func SupportedIoctls(version DriverVersion) (frontendIoctls map[uint32]struct{}, uvmIoctls map[uint32]struct{}, controlCmds map[uint32]struct{}, allocClasses map[uint32]struct{}, ok bool) { + abiCons, ok := abis[version] + if !ok { + return nil, nil, nil, nil, false + } + abi := abiCons.cons() + frontendIoctls = make(map[uint32]struct{}) + for ioc := range abi.frontendIoctl { + frontendIoctls[ioc] = struct{}{} + } + uvmIoctls = make(map[uint32]struct{}) + for ioc := range abi.uvmIoctl { + uvmIoctls[ioc] = struct{}{} + } + controlCmds = make(map[uint32]struct{}) + for cmd := range abi.controlCmd { + controlCmds[cmd] = struct{}{} + } + allocClasses = make(map[uint32]struct{}) + for class := range abi.allocationClass { + allocClasses[class] = struct{}{} + } + return +}