Skip to content

Commit 61057e6

Browse files
committed
Skip injection of GSP firmware by default
This change skips the injection of GSP firmware by default. An include-gsp-firmware feature flag is added to allow the firmware paths to be injected if required. Signed-off-by: Evan Lezar <[email protected]>
1 parent 30921c2 commit 61057e6

File tree

7 files changed

+22
-66
lines changed

7 files changed

+22
-66
lines changed

cmd/nvidia-container-runtime-hook/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ func doPrestart() {
9090

9191
args := []string{getCLIPath(cli)}
9292

93+
// Only include GSP firmware if explicitly renabled.
94+
if !hook.Features.IncludeGSPFirmware.IsEnabled() {
95+
args = append(args, "--no-gsp-firmware")
96+
}
9397
// Only include the nvidia-persistenced socket if it is explicitly enabled.
9498
if !hook.Features.IncludePersistencedSocket.IsEnabled() {
9599
args = append(args, "--no-persistenced")

cmd/nvidia-ctk/cdi/generate/generate.go

+7
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type options struct {
6161
ignorePatterns cli.StringSlice
6262
}
6363

64+
includeGSPFirmware bool
6465
includePersistencedSocket bool
6566
}
6667

@@ -171,6 +172,11 @@ func (m command) build() *cli.Command {
171172
Usage: "Specify a pattern the CSV mount specifications.",
172173
Destination: &opts.csv.ignorePatterns,
173174
},
175+
&cli.BoolFlag{
176+
Name: "include-gsp-firmware",
177+
Usage: "Include the GSP firmware in the generated CDI specification.",
178+
Destination: &opts.includeGSPFirmware,
179+
},
174180
&cli.BoolFlag{
175181
Name: "include-persistenced-socket",
176182
Usage: "Include the nvidia-persistenced socket in the generated CDI specification.",
@@ -280,6 +286,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
280286
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
281287
nvcdi.WithCSVFiles(opts.csv.files.Value()),
282288
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),
289+
nvcdi.WithOptInFeature("include-gsp-firmware", opts.includeGSPFirmware),
283290
nvcdi.WithOptInFeature("include-persistenced-socket", opts.includePersistencedSocket),
284291
)
285292
if err != nil {

internal/config/features.go

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
FeatureNVSWITCH = featureName("nvswitch")
2525
FeatureGDRCopy = featureName("gdrcopy")
2626
FeatureAllowLDConfigFromContainer = featureName("allow-ldconfig-from-container")
27+
FeatureIncludeGSPFirmware = featureName("include-gsp-firmware")
2728
FeatureIncludePersistencedSocket = featureName("include-persistenced-socket")
2829
)
2930

@@ -37,6 +38,8 @@ type features struct {
3738
// If this feature flag is not set to 'true' only host-rooted config paths
3839
// (i.e. paths starting with an '@' are considered valid)
3940
AllowLDConfigFromContainer *feature `toml:"allow-ldconfig-from-container,omitempty"`
41+
// IncludeGSPFirmware enables the injection of GSP firmware into containers.
42+
IncludeGSPFirmware *feature `toml:"include-gsp-firmware,omitempty"`
4043
// IncludePersistencedSocket enables the injection of the nvidia-persistenced
4144
// socket into containers.
4245
IncludePersistencedSocket *feature `toml:"include-persistenced-socket,omitempty"`
@@ -61,6 +64,8 @@ func (fs features) IsEnabledInEnvironment(n featureName, in ...getenver) bool {
6164
// Features without envvar overrides
6265
case FeatureAllowLDConfigFromContainer:
6366
return fs.AllowLDConfigFromContainer.IsEnabled()
67+
case FeatureIncludeGSPFirmware:
68+
return fs.IncludeGSPFirmware.IsEnabled()
6469
case FeatureIncludePersistencedSocket:
6570
return fs.IncludePersistencedSocket.IsEnabled()
6671
default:

internal/modifier/cdi.go

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func generateAutomaticCDISpec(logger logger.Interface, cfg *config.Config, devic
189189
nvcdi.WithDriverRoot(cfg.NVIDIAContainerCLIConfig.Root),
190190
nvcdi.WithVendor("runtime.nvidia.com"),
191191
nvcdi.WithClass("gpu"),
192+
nvcdi.WithOptInFeature("include-gsp-firmware", cfg.Features.IncludeGSPFirmware.IsEnabled()),
192193
nvcdi.WithOptInFeature("include-persistenced-socket", cfg.Features.IncludePersistencedSocket.IsEnabled()),
193194
)
194195
if err != nil {

pkg/nvcdi/driver-nvml.go

+1-64
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ package nvcdi
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"path/filepath"
2322
"strings"
2423

2524
"github.com/NVIDIA/go-nvml/pkg/nvml"
26-
"golang.org/x/sys/unix"
2725

2826
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
2927
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
@@ -63,7 +61,7 @@ func (l *nvcdilib) newDriverVersionDiscoverer(version string) (discover.Discover
6361
return nil, fmt.Errorf("failed to create discoverer for IPC sockets: %v", err)
6462
}
6563

66-
firmwares, err := NewDriverFirmwareDiscoverer(l.logger, l.driver.Root, version)
64+
firmwares, err := l.newDriverFirmwareDiscoverer(l.logger, l.driver.Root, version)
6765
if err != nil {
6866
return nil, fmt.Errorf("failed to create discoverer for GSP firmware: %v", err)
6967
}
@@ -107,67 +105,6 @@ func NewDriverLibraryDiscoverer(logger logger.Interface, driver *root.Driver, nv
107105
return d, nil
108106
}
109107

110-
func getUTSRelease() (string, error) {
111-
utsname := &unix.Utsname{}
112-
if err := unix.Uname(utsname); err != nil {
113-
return "", err
114-
}
115-
return unix.ByteSliceToString(utsname.Release[:]), nil
116-
}
117-
118-
func getFirmwareSearchPaths(logger logger.Interface) ([]string, error) {
119-
120-
var firmwarePaths []string
121-
if p := getCustomFirmwareClassPath(logger); p != "" {
122-
logger.Debugf("using custom firmware class path: %s", p)
123-
firmwarePaths = append(firmwarePaths, p)
124-
}
125-
126-
utsRelease, err := getUTSRelease()
127-
if err != nil {
128-
return nil, fmt.Errorf("failed to get UTS_RELEASE: %v", err)
129-
}
130-
131-
standardPaths := []string{
132-
filepath.Join("/lib/firmware/updates/", utsRelease),
133-
"/lib/firmware/updates/",
134-
filepath.Join("/lib/firmware/", utsRelease),
135-
"/lib/firmware/",
136-
}
137-
138-
return append(firmwarePaths, standardPaths...), nil
139-
}
140-
141-
// getCustomFirmwareClassPath returns the custom firmware class path if it exists.
142-
func getCustomFirmwareClassPath(logger logger.Interface) string {
143-
customFirmwareClassPath, err := os.ReadFile("/sys/module/firmware_class/parameters/path")
144-
if err != nil {
145-
logger.Warningf("failed to get custom firmware class path: %v", err)
146-
return ""
147-
}
148-
149-
return strings.TrimSpace(string(customFirmwareClassPath))
150-
}
151-
152-
// NewDriverFirmwareDiscoverer creates a discoverer for GSP firmware associated with the specified driver version.
153-
func NewDriverFirmwareDiscoverer(logger logger.Interface, driverRoot string, version string) (discover.Discover, error) {
154-
gspFirmwareSearchPaths, err := getFirmwareSearchPaths(logger)
155-
if err != nil {
156-
return nil, fmt.Errorf("failed to get firmware search paths: %v", err)
157-
}
158-
gspFirmwarePaths := filepath.Join("nvidia", version, "gsp*.bin")
159-
return discover.NewMounts(
160-
logger,
161-
lookup.NewFileLocator(
162-
lookup.WithLogger(logger),
163-
lookup.WithRoot(driverRoot),
164-
lookup.WithSearchPaths(gspFirmwareSearchPaths...),
165-
),
166-
driverRoot,
167-
[]string{gspFirmwarePaths},
168-
), nil
169-
}
170-
171108
// NewDriverBinariesDiscoverer creates a discoverer for GSP firmware associated with the GPU driver.
172109
func NewDriverBinariesDiscoverer(logger logger.Interface, driverRoot string) discover.Discover {
173110
return discover.NewMounts(

pkg/nvcdi/firmware.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// newDriverFirmwareDiscoverer creates a discoverer for GSP firmware associated with the specified driver version.
3333
func (l *nvcdilib) newDriverFirmwareDiscoverer(logger logger.Interface, driverRoot string, version string) (discover.Discover, error) {
34-
if !l.optInFeatures["allow-gsp-firmware"] {
34+
if !l.optInFeatures["include-gsp-firmware"] {
3535
return discover.None{}, nil
3636
}
3737

pkg/nvcdi/lib.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ type nvcdilib struct {
6969

7070
// New creates a new nvcdi library
7171
func New(opts ...Option) (Interface, error) {
72-
l := &nvcdilib{}
72+
l := &nvcdilib{
73+
optInFeatures: make(map[string]bool),
74+
}
7375
for _, opt := range opts {
7476
opt(l)
7577
}

0 commit comments

Comments
 (0)