Skip to content

Commit 00a2230

Browse files
committed
Add opt-in feature for GSP firmware injection
This change stops the injection of GSP firmware by default. An opt-in config option or cdi generate argument is available to revert to the previous behaviour. Signed-off-by: Evan Lezar <[email protected]>
1 parent e2d0822 commit 00a2230

File tree

6 files changed

+21
-65
lines changed

6 files changed

+21
-65
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ func doPrestart() {
9595
if !hook.Features.AllowFabricmanager.IsEnabled() {
9696
args = append(args, "--no-fabricmanager")
9797
}
98+
if !hook.Features.AllowGSPFirmware.IsEnabled() {
99+
args = append(args, "--no-gsp-firmware")
100+
}
98101
if !hook.Features.AllowPersistenced.IsEnabled() {
99102
args = append(args, "--no-persistenced")
100103
}

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

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type options struct {
6262
}
6363

6464
withFabricmanager bool
65+
withGSPFirmware bool
6566
withPersistenced bool
6667
}
6768

@@ -177,6 +178,12 @@ func (m command) build() *cli.Command {
177178
Usage: "Include the nvidia-fabricmanager socket in the generated CDI specification.",
178179
Destination: &opts.withFabricmanager,
179180
},
181+
&cli.BoolFlag{
182+
Name: "with-gsp-firmware",
183+
Aliases: []string{"allow-gsp-firmware"},
184+
Usage: "Include the GSP firmware in the generated CDI specification.",
185+
Destination: &opts.withGSPFirmware,
186+
},
180187
&cli.BoolFlag{
181188
Name: "with-persistenced",
182189
Usage: "Include the nvidia-persistenced socket in the generated CDI specification.",
@@ -287,6 +294,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
287294
nvcdi.WithCSVFiles(opts.csv.files.Value()),
288295
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),
289296
nvcdi.WithOptInFeature("allow-fabricmanager", opts.withFabricmanager),
297+
nvcdi.WithOptInFeature("allow-gsp-firmware", opts.withGSPFirmware),
290298
nvcdi.WithOptInFeature("allow-persistenced", opts.withPersistenced),
291299
)
292300
if err != nil {

internal/config/features.go

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
FeatureAllowFabricmanager = featureName("allow-fabricmanager")
2727
FeatureAllowLdconfigOverride = featureName("allow-ldconfig-override")
2828
FeatureAllowPersistenced = featureName("allow-persistenced")
29+
FeatureAllowGSPFirmware = featureName("allow-gsp-firmware")
2930
)
3031

3132
// features specifies a set of named features.
@@ -37,6 +38,8 @@ type features struct {
3738
// AllowFabricmanager enables the injection of the nvidia-fabricmanager
3839
// socket into containers.
3940
AllowFabricmanager *feature `toml:"allow-fabricmanager,omitempty"`
41+
// AllowGSPFirmware enables the injection of GSP firmware into containers.
42+
AllowGSPFirmware *feature `toml:"allow-gsp-firmware,omitempty"`
4043
// AllowLDConfigOverride forces the nvidia-container-cli.ldconfig config
4144
// option to be used instead of the default of @/sbin/ldconfig.
4245
AllowLDConfigOverride *feature `toml:"allow-ldconfig-override,omitempty"`
@@ -64,6 +67,8 @@ func (fs features) IsEnabledInEnvironment(n featureName, in ...getenver) bool {
6467
// Features without envvar overrides
6568
case FeatureAllowFabricmanager:
6669
return fs.AllowFabricmanager.IsEnabled()
70+
case FeatureAllowGSPFirmware:
71+
return fs.AllowGSPFirmware.IsEnabled()
6772
case FeatureAllowLdconfigOverride:
6873
return fs.AllowLDConfigOverride.IsEnabled()
6974
case FeatureAllowPersistenced:

internal/modifier/cdi.go

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func generateAutomaticCDISpec(logger logger.Interface, cfg *config.Config, devic
190190
nvcdi.WithVendor("runtime.nvidia.com"),
191191
nvcdi.WithClass("gpu"),
192192
nvcdi.WithOptInFeature("allow-fabricmanager", cfg.Features.AllowFabricmanager.IsEnabled()),
193+
nvcdi.WithOptInFeature("allow-gsp-firmware", cfg.Features.AllowGSPFirmware.IsEnabled()),
193194
nvcdi.WithOptInFeature("allow-persistenced", cfg.Features.AllowPersistenced.IsEnabled()),
194195
)
195196
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/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)