@@ -42,9 +42,10 @@ type Interface interface {
4242}
4343
4444type nvpassthrough struct {
45- logger basicLogger
46- hostRoot string
47- nvpciLib nvpci.Interface
45+ logger basicLogger
46+ hostRoot string
47+ nvpciLib nvpci.Interface
48+ loadKernelModules bool
4849}
4950
5051var _ Interface = (* nvpassthrough )(nil )
@@ -84,6 +85,8 @@ func WithLogger(logger basicLogger) Option {
8485}
8586
8687// WithHostRoot provides an Option to set the path to the host root filesystem.
88+ // The path is only used when the WithLoadKernelModules option is also enabled.
89+ // The path is assumed to be a chroot-able filesystem.
8790func WithHostRoot (hostRoot string ) Option {
8891 return func (w * nvpassthrough ) {
8992 w .hostRoot = hostRoot
@@ -97,6 +100,15 @@ func WithNvpciLib(lib nvpci.Interface) Option {
97100 }
98101}
99102
103+ // WithLoadKernelModules provides an Option for opting-in to loading
104+ // kernel modules before binding NVIDIA PCI devices to them. By default,
105+ // this behavior is disabled.
106+ func WithLoadKernelModules (loadKernelModules bool ) Option {
107+ return func (w * nvpassthrough ) {
108+ w .loadKernelModules = loadKernelModules
109+ }
110+ }
111+
100112// FindBestVFIOVariant finds the "best" match of all vfio_pci aliases for
101113// device in the host modules.alias file. This uses the algorithm of
102114// finding every modules.alias line that begins with "alias vfio_pci:",
@@ -166,9 +178,11 @@ func (n *nvpassthrough) BindToVFIODriver(address string) error {
166178 return fmt .Errorf ("failed to find best vfio variant driver: %w" , err )
167179 }
168180
169- km := newKernelModules (n .hostRoot )
170- if err := km .load (vfioDriverName ); err != nil {
171- return fmt .Errorf ("failed to load %q driver: %w" , vfioDriverName , err )
181+ if n .loadKernelModules {
182+ km := newKernelModules (n .hostRoot )
183+ if err := km .load (vfioDriverName ); err != nil {
184+ return fmt .Errorf ("failed to load %q driver: %w" , vfioDriverName , err )
185+ }
172186 }
173187
174188 // (cdesiniotis) Module names in the modules.alias file will only ever contain
0 commit comments