Skip to content

Commit f0854e8

Browse files
committed
Add disabled-device-node-modification hook to CDI spec
This hook is not added to management specs. Signed-off-by: Evan Lezar <[email protected]>
1 parent e9d706e commit f0854e8

File tree

6 files changed

+54
-1
lines changed

6 files changed

+54
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ containerEdits:
111111
- /lib/x86_64-linux-gnu
112112
env:
113113
- NVIDIA_CTK_DEBUG=false
114+
- hookName: createContainer
115+
path: /usr/bin/nvidia-cdi-hook
116+
args:
117+
- nvidia-cdi-hook
118+
- disable-device-node-modification
119+
env:
120+
- NVIDIA_CTK_DEBUG=false
114121
mounts:
115122
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
116123
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
@@ -180,6 +187,13 @@ containerEdits:
180187
- /lib/x86_64-linux-gnu
181188
env:
182189
- NVIDIA_CTK_DEBUG=false
190+
- hookName: createContainer
191+
path: /usr/bin/nvidia-cdi-hook
192+
args:
193+
- nvidia-cdi-hook
194+
- disable-device-node-modification
195+
env:
196+
- NVIDIA_CTK_DEBUG=false
183197
mounts:
184198
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
185199
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
@@ -240,6 +254,13 @@ containerEdits:
240254
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
241255
env:
242256
- NVIDIA_CTK_DEBUG=false
257+
- hookName: createContainer
258+
path: /usr/bin/nvidia-cdi-hook
259+
args:
260+
- nvidia-cdi-hook
261+
- disable-device-node-modification
262+
env:
263+
- NVIDIA_CTK_DEBUG=false
243264
mounts:
244265
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
245266
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77

internal/discover/hooks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ const (
3535
ChmodHook = HookName("chmod")
3636
// A CreateSymlinksHook is used to create symlinks in the container.
3737
CreateSymlinksHook = HookName("create-symlinks")
38+
// DisableDeviceNodeModificationHook refers to the hook used to ensure that
39+
// device nodes are not created by libnvidia-ml.so or nvidia-smi in a
40+
// container.
41+
// Added in v1.17.8
42+
DisableDeviceNodeModificationHook = HookName("disable-device-node-modification")
3843
// An EnableCudaCompatHook is used to enabled CUDA Forward Compatibility.
3944
// Added in v1.17.5
4045
EnableCudaCompatHook = HookName("enable-cuda-compat")

pkg/nvcdi/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ const (
4646

4747
// A CreateSymlinksHook is used to create symlinks in the container.
4848
CreateSymlinksHook = discover.CreateSymlinksHook
49+
// DisableDeviceNodeModificationHook refers to the hook used to ensure that
50+
// device nodes are not created by libnvidia-ml.so or nvidia-smi in a
51+
// container.
52+
// Added in v1.17.8
53+
DisableDeviceNodeModificationHook = discover.DisableDeviceNodeModificationHook
4954
// An EnableCudaCompatHook is used to enabled CUDA Forward Compatibility.
5055
// Added in v1.17.5
5156
EnableCudaCompatHook = discover.EnableCudaCompatHook

pkg/nvcdi/driver-nvml.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func (l *nvcdilib) NewDriverLibraryDiscoverer(version string) (discover.Discover
113113
updateLDCache, _ := discover.NewLDCacheUpdateHook(l.logger, libraries, l.hookCreator, l.ldconfigPath)
114114
discoverers = append(discoverers, updateLDCache)
115115

116+
disableDeviceNodeModification := l.hookCreator.Create(DisableDeviceNodeModificationHook)
117+
discoverers = append(discoverers, disableDeviceNodeModification)
118+
116119
d := discover.Merge(discoverers...)
117120

118121
return d, nil

pkg/nvcdi/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func New(opts ...Option) (Interface, error) {
130130
l.vendor = "management.nvidia.com"
131131
}
132132
// Management containers in general do not require CUDA Forward compatibility.
133-
l.disabledHooks = append(l.disabledHooks, HookEnableCudaCompat)
133+
l.disabledHooks = append(l.disabledHooks, HookEnableCudaCompat, DisableDeviceNodeModificationHook)
134134
lib = (*managementlib)(l)
135135
case ModeNvml:
136136
lib = (*nvmllib)(l)

tests/e2e/nvidia-container-toolkit_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,23 @@ var _ = Describe("docker", Ordered, ContinueOnFailure, func() {
216216
Expect(ldconfigOut).To(ContainSubstring("/usr/lib64"))
217217
})
218218
})
219+
220+
Describe("Disabling device node creation", Ordered, func() {
221+
BeforeAll(func(ctx context.Context) {
222+
_, _, err := r.Run("docker pull ubuntu")
223+
Expect(err).ToNot(HaveOccurred())
224+
})
225+
226+
It("should work with nvidia-container-runtime-hook", func(ctx context.Context) {
227+
output, _, err := r.Run("docker run --rm -i --runtime=runc --gpus=all ubuntu bash -c \"grep ModifyDeviceFiles: /proc/driver/nvidia/params\"")
228+
Expect(err).ToNot(HaveOccurred())
229+
Expect(output).To(Equal("ModifyDeviceFiles: 0\n"))
230+
})
231+
232+
It("should work with automatic CDI spec generation", func(ctx context.Context) {
233+
output, _, err := r.Run("docker run --rm -i --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=runtime.nvidia.com/gpu=all ubuntu bash -c \"grep ModifyDeviceFiles: /proc/driver/nvidia/params\"")
234+
Expect(err).ToNot(HaveOccurred())
235+
Expect(output).To(Equal("ModifyDeviceFiles: 0\n"))
236+
})
237+
})
219238
})

0 commit comments

Comments
 (0)