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.

@protonnegativo
protonnegativo force-pushed the fix/libcuda-dir-trailing-slash branch 3 times, most recently from 920e5d4 to 1092a0f Compare October 28, 2026 02:38

@rajatchopra rajatchopra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@cdesiniotis

Copy link
Copy Markdown
Contributor

@protonnegativo in addition to the DCO sign-off, can you also cryptographically sign your commit? Thanks.

Comment on lines +60 to +61
// A root such as /run/nvidia/driver/ would otherwise leave relative paths
// when the root is trimmed from located paths.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These comments are unnecessary. Please remove them

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@protonnegativo please address this comment

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 1092a0f to 943ed2c Compare November 6, 2026 17:59
@protonnegativo

Copy link
Copy Markdown
Author

Thanks @cdesiniotis. I've re-signed the commit (SSH signing key, now showing as Verified) and force-pushed; the DCO sign-off is unchanged.

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.

4 participants