mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
nvproxy: Refactor DriverVersion out to nvconf package.
This allows for runsc to be able to use DriverVersion without having to depend on the entirety of nvproxy. PiperOrigin-RevId: 733912696
This commit is contained in:
@@ -115,6 +115,7 @@ go_test(
|
||||
deps = [
|
||||
":nvproxy",
|
||||
"//pkg/abi/nvgpu",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//pkg/test/testutil",
|
||||
"//tools/nvidia_driver_differ/parser",
|
||||
],
|
||||
|
||||
@@ -9,8 +9,10 @@ go_library(
|
||||
srcs = [
|
||||
"caps.go",
|
||||
"nvconf.go",
|
||||
"version.go",
|
||||
],
|
||||
visibility = [
|
||||
"//pkg/sentry:internal",
|
||||
"//tools:__subpackages__",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
// Copyright 2025 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package nvconf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DriverVersion represents a NVIDIA driver version patch release.
|
||||
//
|
||||
// +stateify savable
|
||||
type DriverVersion struct {
|
||||
major int
|
||||
minor int
|
||||
patch int
|
||||
}
|
||||
|
||||
// NewDriverVersion returns a new driver version.
|
||||
func NewDriverVersion(major, minor, patch int) DriverVersion {
|
||||
return DriverVersion{major, minor, patch}
|
||||
}
|
||||
|
||||
// DriverVersionFrom returns a DriverVersion from a string.
|
||||
func DriverVersionFrom(version string) (DriverVersion, error) {
|
||||
parts := strings.Split(version, ".")
|
||||
if len(parts) != 3 {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format of version string %q", version)
|
||||
}
|
||||
var (
|
||||
res DriverVersion
|
||||
err error
|
||||
)
|
||||
res.major, err = strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for major version %q: %v", version, err)
|
||||
}
|
||||
res.minor, err = strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for minor version %q: %v", version, err)
|
||||
}
|
||||
res.patch, err = strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for patch version %q: %v", version, err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (v DriverVersion) String() string {
|
||||
return fmt.Sprintf("%02d.%02d.%02d", v.major, v.minor, v.patch)
|
||||
}
|
||||
|
||||
// Equals returns true if the two driver versions are equal.
|
||||
func (v DriverVersion) Equals(other DriverVersion) bool {
|
||||
return v.major == other.major && v.minor == other.minor && v.patch == other.patch
|
||||
}
|
||||
|
||||
// IsGreaterThan returns true if v is greater than other.
|
||||
// isGreaterThan returns true if v is more recent than other, assuming v and other are on the same
|
||||
// dev branch.
|
||||
func (v DriverVersion) IsGreaterThan(other DriverVersion) bool {
|
||||
switch {
|
||||
case v.major > other.major:
|
||||
return true
|
||||
case other.major > v.major:
|
||||
return false
|
||||
case v.minor > other.minor:
|
||||
return true
|
||||
case other.minor > v.minor:
|
||||
return false
|
||||
case v.patch > other.patch:
|
||||
return true
|
||||
case other.patch > v.patch:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// Major returns the major version number.
|
||||
func (v DriverVersion) Major() int {
|
||||
return v.major
|
||||
}
|
||||
@@ -30,17 +30,13 @@ import (
|
||||
)
|
||||
|
||||
// Register registers all devices implemented by this package in vfsObj.
|
||||
func Register(vfsObj *vfs.VirtualFilesystem, versionStr string, driverCaps nvconf.DriverCaps, uvmDevMajor uint32) error {
|
||||
func Register(vfsObj *vfs.VirtualFilesystem, version nvconf.DriverVersion, driverCaps nvconf.DriverCaps, uvmDevMajor uint32) error {
|
||||
// The kernel driver's interface is unstable, so only allow versions of the
|
||||
// driver that are known to be supported.
|
||||
log.Infof("NVIDIA driver version: %s", versionStr)
|
||||
version, err := DriverVersionFrom(versionStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse Nvidia driver version %s: %w", versionStr, err)
|
||||
}
|
||||
log.Infof("NVIDIA driver version: %s", version)
|
||||
abiCons, ok := abis[version]
|
||||
if !ok {
|
||||
return fmt.Errorf("unsupported Nvidia driver version: %s", versionStr)
|
||||
return fmt.Errorf("unsupported Nvidia driver version: %s", version)
|
||||
}
|
||||
if driverCaps == 0 {
|
||||
log.Warningf("nvproxy: NVIDIA driver capability set is empty; all GPU operations will fail")
|
||||
@@ -76,7 +72,7 @@ func Register(vfsObj *vfs.VirtualFilesystem, versionStr string, driverCaps nvcon
|
||||
// +stateify savable
|
||||
type nvproxy struct {
|
||||
abi *driverABI `state:"nosave"`
|
||||
version DriverVersion
|
||||
version nvconf.DriverVersion
|
||||
capsEnabled nvconf.DriverCaps
|
||||
|
||||
fdsMu fdsMutex `state:"nosave"`
|
||||
|
||||
@@ -32,6 +32,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/test/testutil"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
"gvisor.dev/gvisor/tools/nvidia_driver_differ/parser"
|
||||
)
|
||||
|
||||
@@ -56,7 +57,7 @@ func createParserRunner(t *testing.T) (*os.File, *parser.Runner) {
|
||||
return parserFile, runner
|
||||
}
|
||||
|
||||
func getDriverDefs(t *testing.T, runner *parser.Runner, version nvproxy.DriverVersion) ([]nvproxy.DriverStructName, *parser.OutputJSON) {
|
||||
func getDriverDefs(t *testing.T, runner *parser.Runner, version nvconf.DriverVersion) ([]nvproxy.DriverStructName, *parser.OutputJSON) {
|
||||
t.Helper()
|
||||
|
||||
structNames, ok := nvproxy.SupportedStructNames(version)
|
||||
@@ -84,7 +85,7 @@ func TestSupportedStructNames(t *testing.T) {
|
||||
nvproxy.Init()
|
||||
|
||||
// Run the parser on all supported driver versions
|
||||
nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, checksum string) {
|
||||
nvproxy.ForEachSupportDriver(func(version nvconf.DriverVersion, checksum string) {
|
||||
t.Run(version.String(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
f, runner := createParserRunner(t)
|
||||
@@ -109,7 +110,7 @@ func TestSupportedStructNames(t *testing.T) {
|
||||
func TestStructDefinitionParity(t *testing.T) {
|
||||
nvproxy.Init()
|
||||
|
||||
nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, checksum string) {
|
||||
nvproxy.ForEachSupportDriver(func(version nvconf.DriverVersion, checksum string) {
|
||||
t.Run(version.String(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
f, runner := createParserRunner(t)
|
||||
|
||||
@@ -18,84 +18,12 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/abi/nvgpu"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
)
|
||||
|
||||
// DriverVersion represents a NVIDIA driver version patch release.
|
||||
//
|
||||
// +stateify savable
|
||||
type DriverVersion struct {
|
||||
major int
|
||||
minor int
|
||||
patch int
|
||||
}
|
||||
|
||||
// NewDriverVersion returns a new driver version.
|
||||
func NewDriverVersion(major, minor, patch int) DriverVersion {
|
||||
return DriverVersion{major, minor, patch}
|
||||
}
|
||||
|
||||
// DriverVersionFrom returns a DriverVersion from a string.
|
||||
func DriverVersionFrom(version string) (DriverVersion, error) {
|
||||
parts := strings.Split(version, ".")
|
||||
if len(parts) != 3 {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format of version string %q", version)
|
||||
}
|
||||
var (
|
||||
res DriverVersion
|
||||
err error
|
||||
)
|
||||
res.major, err = strconv.Atoi(parts[0])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for major version %q: %v", version, err)
|
||||
}
|
||||
res.minor, err = strconv.Atoi(parts[1])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for minor version %q: %v", version, err)
|
||||
}
|
||||
res.patch, err = strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
return DriverVersion{}, fmt.Errorf("invalid format for patch version %q: %v", version, err)
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (v DriverVersion) String() string {
|
||||
return fmt.Sprintf("%02d.%02d.%02d", v.major, v.minor, v.patch)
|
||||
}
|
||||
|
||||
// Equals returns true if the two driver versions are equal.
|
||||
func (v DriverVersion) Equals(other DriverVersion) bool {
|
||||
return v.major == other.major && v.minor == other.minor && v.patch == other.patch
|
||||
}
|
||||
|
||||
// isGreaterThan returns true if v is greater than other.
|
||||
// isGreaterThan returns true if v is more recent than other, assuming v and other are on the same
|
||||
// dev branch.
|
||||
func (v DriverVersion) isGreaterThan(other DriverVersion) bool {
|
||||
switch {
|
||||
case v.major > other.major:
|
||||
return true
|
||||
case other.major > v.major:
|
||||
return false
|
||||
case v.minor > other.minor:
|
||||
return true
|
||||
case other.minor > v.minor:
|
||||
return false
|
||||
case v.patch > other.patch:
|
||||
return true
|
||||
case other.patch > v.patch:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
// A driverABIFunc constructs and returns a driverABI.
|
||||
// This indirection exists to avoid memory usage from unused driver ABIs.
|
||||
type driverABIFunc func() *driverABI
|
||||
@@ -154,7 +82,7 @@ type DriverStruct struct {
|
||||
|
||||
// abis is a global map containing all supported Nvidia driver ABIs. This is
|
||||
// initialized on Init() and is immutable henceforth.
|
||||
var abis map[DriverVersion]abiConAndChecksum
|
||||
var abis map[nvconf.DriverVersion]abiConAndChecksum
|
||||
var abisOnce sync.Once
|
||||
|
||||
// Note: runfileChecksum is the checksum of the .run file of the driver installer for linux from
|
||||
@@ -163,9 +91,9 @@ var abisOnce sync.Once
|
||||
// Run `make sudo TARGETS=//tools/gpu:main ARGS="checksum --version={}"` to get checksum.
|
||||
func addDriverABI(major, minor, patch int, runfileChecksum string, cons driverABIFunc) driverABIFunc {
|
||||
if abis == nil {
|
||||
abis = make(map[DriverVersion]abiConAndChecksum)
|
||||
abis = make(map[nvconf.DriverVersion]abiConAndChecksum)
|
||||
}
|
||||
version := NewDriverVersion(major, minor, patch)
|
||||
version := nvconf.NewDriverVersion(major, minor, patch)
|
||||
abis[version] = abiConAndChecksum{cons: cons, checksum: runfileChecksum}
|
||||
return cons
|
||||
}
|
||||
@@ -908,7 +836,7 @@ func newDriverStruct(paramType reflect.Type, name string) DriverStruct {
|
||||
|
||||
// ForEachSupportDriver calls f on all supported drivers.
|
||||
// Precondition: Init() must have been called.
|
||||
func ForEachSupportDriver(f func(version DriverVersion, checksum string)) {
|
||||
func ForEachSupportDriver(f func(version nvconf.DriverVersion, checksum string)) {
|
||||
for version, abi := range abis {
|
||||
f(version, abi.checksum)
|
||||
}
|
||||
@@ -916,10 +844,10 @@ func ForEachSupportDriver(f func(version DriverVersion, checksum string)) {
|
||||
|
||||
// LatestDriver returns the latest supported driver.
|
||||
// Precondition: Init() must have been called.
|
||||
func LatestDriver() DriverVersion {
|
||||
var ret DriverVersion
|
||||
func LatestDriver() nvconf.DriverVersion {
|
||||
var ret nvconf.DriverVersion
|
||||
for version := range abis {
|
||||
if version.isGreaterThan(ret) {
|
||||
if version.IsGreaterThan(ret) {
|
||||
ret = version
|
||||
}
|
||||
}
|
||||
@@ -928,20 +856,20 @@ func LatestDriver() DriverVersion {
|
||||
|
||||
// SupportedDrivers returns a list of all supported drivers.
|
||||
// Precondition: Init() must have been called.
|
||||
func SupportedDrivers() []DriverVersion {
|
||||
var ret []DriverVersion
|
||||
func SupportedDrivers() []nvconf.DriverVersion {
|
||||
var ret []nvconf.DriverVersion
|
||||
for version := range abis {
|
||||
ret = append(ret, version)
|
||||
}
|
||||
sort.Slice(ret, func(i, j int) bool {
|
||||
return !ret[i].isGreaterThan(ret[j])
|
||||
return !ret[i].IsGreaterThan(ret[j])
|
||||
})
|
||||
return ret
|
||||
}
|
||||
|
||||
// ExpectedDriverChecksum returns the expected checksum for a given version.
|
||||
// Precondition: Init() must have been called.
|
||||
func ExpectedDriverChecksum(version DriverVersion) (string, bool) {
|
||||
func ExpectedDriverChecksum(version nvconf.DriverVersion) (string, bool) {
|
||||
abi, ok := abis[version]
|
||||
if !ok {
|
||||
return "", false
|
||||
@@ -951,7 +879,7 @@ func ExpectedDriverChecksum(version DriverVersion) (string, bool) {
|
||||
|
||||
// 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) {
|
||||
func SupportedIoctls(version nvconf.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
|
||||
@@ -978,7 +906,7 @@ func SupportedIoctls(version DriverVersion) (frontendIoctls map[uint32]struct{},
|
||||
|
||||
// SupportedStructNames returns the list of struct names supported by the given driver version.
|
||||
// It merges the frontend, uvm, control, and allocation names into one slice.
|
||||
func SupportedStructNames(version DriverVersion) ([]DriverStructName, bool) {
|
||||
func SupportedStructNames(version nvconf.DriverVersion) ([]DriverStructName, bool) {
|
||||
namesCons, ok := abis[version]
|
||||
if !ok {
|
||||
return nil, false
|
||||
@@ -1011,7 +939,7 @@ func SupportedStructNames(version DriverVersion) ([]DriverStructName, bool) {
|
||||
|
||||
// SupportedStructTypes returns the list of struct types supported by the given driver version.
|
||||
// It merges the frontend, uvm, control, and allocation names into one slice.
|
||||
func SupportedStructTypes(version DriverVersion) ([]DriverStruct, bool) {
|
||||
func SupportedStructTypes(version nvconf.DriverVersion) ([]DriverStruct, bool) {
|
||||
abiCons, ok := abis[version]
|
||||
if !ok {
|
||||
return nil, false
|
||||
|
||||
@@ -153,7 +153,7 @@ type containerInfo struct {
|
||||
|
||||
// nvidiaDriverVersion is the NVIDIA driver ABI version to use for
|
||||
// communicating with NVIDIA devices on the host.
|
||||
nvidiaDriverVersion string
|
||||
nvidiaDriverVersion nvconf.DriverVersion
|
||||
}
|
||||
|
||||
type loaderState int
|
||||
@@ -351,7 +351,7 @@ type Args struct {
|
||||
ProfileOpts profile.Opts
|
||||
// NvidiaDriverVersion is the NVIDIA driver ABI version to use for
|
||||
// communicating with NVIDIA devices on the host.
|
||||
NvidiaDriverVersion string
|
||||
NvidiaDriverVersion nvconf.DriverVersion
|
||||
// HostTHP contains host transparent hugepage settings.
|
||||
HostTHP HostTHP
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ go_library(
|
||||
"//pkg/prometheus",
|
||||
"//pkg/ring0",
|
||||
"//pkg/sentry/control",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//pkg/sentry/devices/tpuproxy",
|
||||
"//pkg/sentry/devices/tpuproxy/vfio",
|
||||
"//pkg/sentry/hostmm",
|
||||
|
||||
+10
-1
@@ -37,6 +37,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/metric"
|
||||
"gvisor.dev/gvisor/pkg/prometheus"
|
||||
"gvisor.dev/gvisor/pkg/ring0"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
"gvisor.dev/gvisor/pkg/sentry/hostmm"
|
||||
"gvisor.dev/gvisor/pkg/sentry/platform"
|
||||
"gvisor.dev/gvisor/runsc/boot"
|
||||
@@ -493,6 +494,14 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomma
|
||||
log.Infof("Core tag enabled (core tag=%d)", coreTags[0])
|
||||
}
|
||||
|
||||
var nvidiaDriverVersion nvconf.DriverVersion
|
||||
if b.nvidiaDriverVersion != "" {
|
||||
nvidiaDriverVersion, err = nvconf.DriverVersionFrom(b.nvidiaDriverVersion)
|
||||
if err != nil {
|
||||
util.Fatalf("Failed to parse nvidia driver version: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create the loader.
|
||||
bootArgs := boot.Args{
|
||||
ID: f.Arg(0),
|
||||
@@ -515,7 +524,7 @@ func (b *Boot) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcomma
|
||||
PodInitConfigFD: b.podInitConfigFD,
|
||||
SinkFDs: b.sinkFDs.GetArray(),
|
||||
ProfileOpts: b.profileFDs.ToOpts(),
|
||||
NvidiaDriverVersion: b.nvidiaDriverVersion,
|
||||
NvidiaDriverVersion: nvidiaDriverVersion,
|
||||
HostTHP: b.hostTHP,
|
||||
SaveFDs: b.saveFDs.GetFDs(),
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ go_library(
|
||||
"//pkg/prometheus",
|
||||
"//pkg/sentry/control",
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//pkg/sentry/fsimpl/erofs",
|
||||
"//pkg/sentry/pgalloc",
|
||||
"//pkg/sentry/platform",
|
||||
|
||||
@@ -47,6 +47,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/prometheus"
|
||||
"gvisor.dev/gvisor/pkg/sentry/control"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
"gvisor.dev/gvisor/pkg/sentry/fsimpl/erofs"
|
||||
"gvisor.dev/gvisor/pkg/sentry/pgalloc"
|
||||
"gvisor.dev/gvisor/pkg/sentry/platform"
|
||||
@@ -1747,7 +1748,7 @@ func getNvproxyDriverVersion(conf *config.Config) (string, error) {
|
||||
nvproxy.Init()
|
||||
return nvproxy.LatestDriver().String(), nil
|
||||
default:
|
||||
version, err := nvproxy.DriverVersionFrom(conf.NVProxyDriverVersion)
|
||||
version, err := nvconf.DriverVersionFrom(conf.NVProxyDriverVersion)
|
||||
return version.String(), err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ go_binary(
|
||||
deps = [
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//runsc/flag",
|
||||
"//tools/gpu/drivers",
|
||||
],
|
||||
|
||||
@@ -12,6 +12,7 @@ go_library(
|
||||
deps = [
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -19,5 +20,5 @@ go_test(
|
||||
name = "drivers_test",
|
||||
srcs = ["install_driver_test.go"],
|
||||
library = ":drivers",
|
||||
deps = ["//pkg/sentry/devices/nvproxy"],
|
||||
deps = ["//pkg/sentry/devices/nvproxy/nvconf"],
|
||||
)
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -42,10 +43,10 @@ func init() {
|
||||
|
||||
// Installer handles the logic to install drivers.
|
||||
type Installer struct {
|
||||
requestedVersion nvproxy.DriverVersion
|
||||
requestedVersion nvconf.DriverVersion
|
||||
// include functions so they can be mocked in tests.
|
||||
expectedChecksumFunc func(nvproxy.DriverVersion) (string, bool)
|
||||
getCurrentDriverFunc func() (nvproxy.DriverVersion, error)
|
||||
expectedChecksumFunc func(nvconf.DriverVersion) (string, bool)
|
||||
getCurrentDriverFunc func() (nvconf.DriverVersion, error)
|
||||
downloadFunc func(context.Context, string) (io.ReadCloser, error)
|
||||
installFunc func(string) error
|
||||
}
|
||||
@@ -62,7 +63,7 @@ func NewInstaller(requestedVersion string, latest bool) (*Installer, error) {
|
||||
case latest:
|
||||
ret.requestedVersion = nvproxy.LatestDriver()
|
||||
default:
|
||||
d, err := nvproxy.DriverVersionFrom(requestedVersion)
|
||||
d, err := nvconf.DriverVersionFrom(requestedVersion)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse requested driver version: %w", err)
|
||||
}
|
||||
@@ -89,7 +90,7 @@ func (i *Installer) MaybeInstall(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !existingDriver.Equals(nvproxy.DriverVersion{}) {
|
||||
if !existingDriver.Equals(nvconf.DriverVersion{}) {
|
||||
log.Infof("Uninstalling driver: %s", existingDriver)
|
||||
if err := i.uninstallDriver(ctx, existingDriver.String()); err != nil {
|
||||
return fmt.Errorf("failed to uninstall driver: %w", err)
|
||||
@@ -167,19 +168,19 @@ func (i *Installer) writeAndCheck(f *os.File, reader io.ReadCloser) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getCurrentDriver() (nvproxy.DriverVersion, error) {
|
||||
func getCurrentDriver() (nvconf.DriverVersion, error) {
|
||||
_, err := os.Stat(nvidiaSMIPath)
|
||||
// If the nvidia-smi executable does not exist, then we don't have a driver installed.
|
||||
if os.IsNotExist(err) {
|
||||
return nvproxy.DriverVersion{}, fmt.Errorf("nvidia-smi does not exist at path: %q", nvidiaSMIPath)
|
||||
return nvconf.DriverVersion{}, fmt.Errorf("nvidia-smi does not exist at path: %q", nvidiaSMIPath)
|
||||
}
|
||||
if err != nil {
|
||||
return nvproxy.DriverVersion{}, fmt.Errorf("failed to stat nvidia-smi: %w", err)
|
||||
return nvconf.DriverVersion{}, fmt.Errorf("failed to stat nvidia-smi: %w", err)
|
||||
}
|
||||
out, err := exec.Command(nvidiaSMIPath, []string{"--query-gpu", "driver_version", "--format=csv,noheader"}...).CombinedOutput()
|
||||
if err != nil {
|
||||
log.Warningf("failed to run nvidia-smi: %v", err)
|
||||
return nvproxy.DriverVersion{}, fmt.Errorf("failed to run nvidia-smi: %w", err)
|
||||
return nvconf.DriverVersion{}, fmt.Errorf("failed to run nvidia-smi: %w", err)
|
||||
}
|
||||
// If there are multiple GPUs, there will be one version per line.
|
||||
// Make sure they are all the same version.
|
||||
@@ -194,13 +195,13 @@ func getCurrentDriver() (nvproxy.DriverVersion, error) {
|
||||
continue
|
||||
}
|
||||
if line != sameVersion {
|
||||
return nvproxy.DriverVersion{}, fmt.Errorf("multiple driver versions found: %q and %q", sameVersion, line)
|
||||
return nvconf.DriverVersion{}, fmt.Errorf("multiple driver versions found: %q and %q", sameVersion, line)
|
||||
}
|
||||
}
|
||||
if sameVersion == "" {
|
||||
return nvproxy.DriverVersion{}, fmt.Errorf("no driver version found")
|
||||
return nvconf.DriverVersion{}, fmt.Errorf("no driver version found")
|
||||
}
|
||||
return nvproxy.DriverVersionFrom(sameVersion)
|
||||
return nvconf.DriverVersionFrom(sameVersion)
|
||||
}
|
||||
|
||||
// ListSupportedDrivers prints the driver to stderr in a format that can be
|
||||
@@ -217,7 +218,7 @@ func ListSupportedDrivers(outfile string) error {
|
||||
}
|
||||
|
||||
var list []string
|
||||
nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, checksum string) {
|
||||
nvproxy.ForEachSupportDriver(func(version nvconf.DriverVersion, checksum string) {
|
||||
list = append(list, version.String())
|
||||
})
|
||||
sort.Strings(list)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
)
|
||||
|
||||
// TestVersionInstalled tests when the version is already installed.
|
||||
@@ -30,12 +30,12 @@ func TestVersionInstalled(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
versionContent := []byte("some cool content")
|
||||
checksum := fmt.Sprintf("%x", sha256.Sum256(versionContent))
|
||||
version := nvproxy.NewDriverVersion(1, 2, 3)
|
||||
getFunction := func() (nvproxy.DriverVersion, error) { return version, nil }
|
||||
version := nvconf.NewDriverVersion(1, 2, 3)
|
||||
getFunction := func() (nvconf.DriverVersion, error) { return version, nil }
|
||||
downloadFunction := func(context.Context, string) (io.ReadCloser, error) { return nil, fmt.Errorf("should not get here") }
|
||||
installer := &Installer{
|
||||
requestedVersion: version,
|
||||
expectedChecksumFunc: func(v nvproxy.DriverVersion) (string, bool) {
|
||||
expectedChecksumFunc: func(v nvconf.DriverVersion) (string, bool) {
|
||||
if v == version {
|
||||
return checksum, true
|
||||
}
|
||||
@@ -52,10 +52,10 @@ func TestVersionInstalled(t *testing.T) {
|
||||
// TestVersionNotSupported tests when the version is not supported.
|
||||
func TestVersionNotSupported(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
unsupportedVersion := nvproxy.NewDriverVersion(1, 2, 3)
|
||||
unsupportedVersion := nvconf.NewDriverVersion(1, 2, 3)
|
||||
installer := &Installer{
|
||||
requestedVersion: unsupportedVersion,
|
||||
expectedChecksumFunc: func(v nvproxy.DriverVersion) (string, bool) {
|
||||
expectedChecksumFunc: func(v nvconf.DriverVersion) (string, bool) {
|
||||
return "", false
|
||||
},
|
||||
}
|
||||
@@ -71,13 +71,13 @@ func TestVersionNotSupported(t *testing.T) {
|
||||
// TestShaMismatch tests when a checksum of a driver doesn't match what's in the map.
|
||||
func TestShaMismatch(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
version := nvproxy.NewDriverVersion(1, 2, 3)
|
||||
version := nvconf.NewDriverVersion(1, 2, 3)
|
||||
installer := &Installer{
|
||||
requestedVersion: version,
|
||||
getCurrentDriverFunc: func() (nvproxy.DriverVersion, error) {
|
||||
return nvproxy.DriverVersion{}, nil
|
||||
getCurrentDriverFunc: func() (nvconf.DriverVersion, error) {
|
||||
return nvconf.DriverVersion{}, nil
|
||||
},
|
||||
expectedChecksumFunc: func(v nvproxy.DriverVersion) (string, bool) {
|
||||
expectedChecksumFunc: func(v nvconf.DriverVersion) (string, bool) {
|
||||
if v == version {
|
||||
return "mismatch", true
|
||||
}
|
||||
@@ -102,13 +102,13 @@ func TestDriverInstalls(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
content := []byte("some content")
|
||||
checksum := fmt.Sprintf("%x", sha256.Sum256(content))
|
||||
version := nvproxy.NewDriverVersion(1, 2, 3)
|
||||
version := nvconf.NewDriverVersion(1, 2, 3)
|
||||
installer := &Installer{
|
||||
requestedVersion: version,
|
||||
getCurrentDriverFunc: func() (nvproxy.DriverVersion, error) {
|
||||
return nvproxy.DriverVersion{}, nil
|
||||
getCurrentDriverFunc: func() (nvconf.DriverVersion, error) {
|
||||
return nvconf.DriverVersion{}, nil
|
||||
},
|
||||
expectedChecksumFunc: func(v nvproxy.DriverVersion) (string, bool) {
|
||||
expectedChecksumFunc: func(v nvconf.DriverVersion) (string, bool) {
|
||||
if v == version {
|
||||
return checksum, true
|
||||
}
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
"gvisor.dev/gvisor/runsc/flag"
|
||||
"gvisor.dev/gvisor/tools/gpu/drivers"
|
||||
)
|
||||
@@ -114,7 +115,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
nvproxy.ForEachSupportDriver(func(version nvproxy.DriverVersion, checksum string) {
|
||||
nvproxy.ForEachSupportDriver(func(version nvconf.DriverVersion, checksum string) {
|
||||
wantChecksum, err := drivers.ChecksumDriver(ctx, version.String())
|
||||
if err != nil {
|
||||
log.Warningf("error on version %q: %v", version.String(), err)
|
||||
|
||||
@@ -17,6 +17,7 @@ go_library(
|
||||
"//pkg/abi/nvgpu",
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//tools/ioctl_sniffer:ioctl_go_proto",
|
||||
"@org_golang_google_protobuf//proto:go_default_library",
|
||||
],
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/nvgpu"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy"
|
||||
"gvisor.dev/gvisor/pkg/sentry/devices/nvproxy/nvconf"
|
||||
pb "gvisor.dev/gvisor/tools/ioctl_sniffer/ioctl_go_proto"
|
||||
)
|
||||
|
||||
@@ -183,7 +184,7 @@ func Init() error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get host driver version: %w", err)
|
||||
}
|
||||
driverVer, err := nvproxy.DriverVersionFrom(driverVerStr)
|
||||
driverVer, err := nvconf.DriverVersionFrom(driverVerStr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse host driver version: %w", err)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ go_binary(
|
||||
deps = [
|
||||
"//pkg/log",
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"//tools/nvidia_driver_differ/parser",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ go_library(
|
||||
],
|
||||
deps = [
|
||||
"//pkg/sentry/devices/nvproxy",
|
||||
"//pkg/sentry/devices/nvproxy/nvconf",
|
||||
"@com_github_google_go_cmp//cmp:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user