Skip to content

fix: clean the driver root so a trailing / does not leave relative paths - #2179

Open
protonnegativo wants to merge 1 commit into
NVIDIA:mainfrom
protonnegativo:fix/libcuda-dir-trailing-slash
Open

protonnegativo wants to merge 1 commit into
NVIDIA:mainfrom
protonnegativo:fix/libcuda-dir-trailing-slash

Conversation

@protonnegativo

Copy link
Copy Markdown

When the driver root ends in a separator (for example --driver-root=/run/nvidia/driver/), the generated CDI spec has a relative NVIDIA_CTK_LIBCUDA_DIR. Reproduced with the TestGenerateSpec setup (mock NVML, testdata/lookup/rootfs-1) and / appended to the driver root:

containerEdits:
    env:
        - NVIDIA_CTK_LIBCUDA_DIR=lib/x86_64-linux-gnu

Without the trailing / the value is /lib/x86_64-linux-gnu. Tools in the container that read this variable to find the injected libcuda.so (#1028) get a relative path.

root.Driver trims its root from located paths as a plain string prefix (RelativeToRoot, and getVersionLibs in pkg/nvcdi/driver-nvml.go), so /run/nvidia/driver/usr/lib64 became usr/lib64. The mounts in the spec were not affected because discover.NewMounts already cleans its root. This PR cleans the root once in root.New, so every user of Driver.Root sees the same normalized value.

Testing

  • Added a TestLocate case with a driver root ending in /. It fails on main (usr/lib64 instead of /usr/lib64) and passes with the fix.
  • Ran the TestGenerateSpec "default" setup (mock NVML, testdata/lookup/rootfs-1) with a trailing / on the driver root as a one-off check. Before the fix: NVIDIA_CTK_LIBCUDA_DIR=lib/x86_64-linux-gnu. After: /lib/x86_64-linux-gnu. Mounts and update-ldcache --folder values are unchanged.
  • go test ./internal/lookup/... ./internal/discover/... ./internal/modifier/... ./pkg/nvcdi/... ./cmd/nvidia-ctk/... ./cmd/nvidia-ctk-installer/... pass. gofmt -s -l is clean.

@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

The driver root is trimmed from located paths as a plain string prefix,
for example in RelativeToRoot. With a driver root such as
/run/nvidia/driver/ the result lost its leading separator, so the
generated CDI spec set NVIDIA_CTK_LIBCUDA_DIR=lib/x86_64-linux-gnu
instead of /lib/x86_64-linux-gnu.

Clean the root once when the Driver is constructed.

Signed-off-by: Dennys Kaluzny Pereira <protonnegativo@users.noreply.github.com>
@protonnegativo
protonnegativo force-pushed the fix/libcuda-dir-trailing-slash branch from 1c03a47 to 1ed2e1a Compare October 27, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant