Skip to content

Commit

Permalink
libnvidia-container: clean up patches
Browse files Browse the repository at this point in the history
This recreates the patches with `git format-patch` and adds descriptions to each of them. It also separates the binary and library lookup patches from each other.
  • Loading branch information
msanft committed Dec 22, 2024
1 parent e602d6f commit 24d9b8a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
From 8799541f99785d2bd881561386676fb0985e939e Mon Sep 17 00:00:00 2001
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <[email protected]>
Date: Thu, 10 Oct 2024 14:32:42 +0200
Subject: [PATCH] fix library resolving
Date: Fri, 20 Dec 2024 16:34:50 +0100
Subject: [PATCH] ldcache: don't use ldcache

Signed-off-by: Moritz Sanft <[email protected]>
This patch hinders libnvidia-container from using the loader cache, which doesn't get used on NixOS.
---
src/ldcache.c | 46 +++++++++++++++++-----------------------------
src/ldcache.h | 2 +-
src/nvc_info.c | 10 +++-------
src/nvc_info.c | 8 ++------
src/nvc_ldcache.c | 2 +-
4 files changed, 22 insertions(+), 38 deletions(-)
4 files changed, 21 insertions(+), 37 deletions(-)

diff --git a/src/ldcache.c b/src/ldcache.c
index 38bab055..8cd30a0f 100644
index 38bab0553208f66b2866ccea6cdb0faca4357f19..1c4acd52b622be4ca6accdc80da5a6fcf9ae67dd 100644
--- a/src/ldcache.c
+++ b/src/ldcache.c
@@ -108,40 +108,28 @@ ldcache_close(struct ldcache *ctx)

int
ldcache_resolve(struct ldcache *ctx, uint32_t arch, const char *root, const char * const libs[],
- char *paths[], size_t size, ldcache_select_fn select, void *select_ctx)
Expand All @@ -27,10 +27,10 @@ index 38bab055..8cd30a0f 100644
- int override;
+ char dir[PATH_MAX];
+ char lib[PATH_MAX];

- h = (struct header_libc6 *)ctx->ptr;
memset(paths, 0, size * sizeof(*paths));

- for (uint32_t i = 0; i < h->nlibs; ++i) {
- int32_t flags = h->libs[i].flags;
- char *key = (char *)ctx->ptr + h->libs[i].key;
Expand Down Expand Up @@ -74,7 +74,7 @@ index 38bab055..8cd30a0f 100644
return (0);
}
diff --git a/src/ldcache.h b/src/ldcache.h
index 33d78dd7..2b087dbc 100644
index 33d78dd7e21f65eb696535c115bbd2839a6c67ca..2b087dbca1a6a2946cd495e676a61e956212e3dc 100644
--- a/src/ldcache.h
+++ b/src/ldcache.h
@@ -50,6 +50,6 @@ void ldcache_init(struct ldcache *, struct error *, const char *);
Expand All @@ -83,10 +83,10 @@ index 33d78dd7..2b087dbc 100644
int ldcache_resolve(struct ldcache *, uint32_t, const char *, const char * const [],
- char *[], size_t, ldcache_select_fn, void *);
+ char *[], size_t, const char*);

#endif /* HEADER_LDCACHE_H */
diff --git a/src/nvc_info.c b/src/nvc_info.c
index b7b8adfa..d42f2beb 100644
index b7b8adfa7c79c326a1acb481a06a05d1463e810f..cf4b1905fd2127c28ee16649501be122d3be5261 100644
--- a/src/nvc_info.c
+++ b/src/nvc_info.c
@@ -217,15 +217,13 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
Expand All @@ -95,7 +95,7 @@ index b7b8adfa..d42f2beb 100644
ldcache_init(&ld, err, path);
- if (ldcache_open(&ld) < 0)
- return (-1);

info->nlibs = size;
info->libs = array_new(err, size);
if (info->libs == NULL)
Expand All @@ -104,7 +104,7 @@ index b7b8adfa..d42f2beb 100644
- info->libs, info->nlibs, select_libraries_fn, info) < 0)
+ info->libs, info->nlibs, info->nvrm_version) < 0)
goto fail;

info->nlibs32 = size;
@@ -233,13 +231,11 @@ find_library_paths(struct error *err, struct dxcore_context *dxcore, struct nvc_
if (info->libs32 == NULL)
Expand All @@ -114,34 +114,23 @@ index b7b8adfa..d42f2beb 100644
+ info->libs32, info->nlibs32, info->nvrm_version) < 0)
goto fail;
rv = 0;

fail:
- if (ldcache_close(&ld) < 0)
- return (-1);
return (rv);
}

@@ -253,7 +249,7 @@ find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_d
char path[PATH_MAX];
int rv = -1;

- if ((env = secure_getenv("PATH")) == NULL) {
+ if ((env = "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin") == NULL) {
error_setx(err, "environment variable PATH not found");
return (-1);
}

diff --git a/src/nvc_ldcache.c b/src/nvc_ldcache.c
index db3b2f69..ae5def43 100644
index db3b2f69692270e9058b2e26f18eb31677909d05..ae5def43b4cb3973af3aad55361265173ca938a7 100644
--- a/src/nvc_ldcache.c
+++ b/src/nvc_ldcache.c
@@ -367,7 +367,7 @@ nvc_ldcache_update(struct nvc_context *ctx, const struct nvc_container *cnt)
if (validate_args(ctx, cnt != NULL) < 0)
return (-1);

- argv = (char * []){cnt->cfg.ldconfig, "-f", "/etc/ld.so.conf", "-C", "/etc/ld.so.cache", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
+ argv = (char * []){cnt->cfg.ldconfig, "-f", "/tmp/ld.so.conf.nvidia-host", "-C", "/tmp/ld.so.cache.nvidia-host", cnt->cfg.libs_dir, cnt->cfg.libs32_dir, NULL};
if (*argv[0] == '@') {
/*
* We treat this path specially to be relative to the host filesystem.
--
2.46.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <[email protected]>
Date: Fri, 20 Dec 2024 16:37:07 +0100
Subject: [PATCH] nvc: nvidia-docker-compatible binary lookups

This patch maintains compatibility with NixOS' `virtualisation.docker.enableNvidia` option (which is to be removed soon), while also enabling supplying a custom PATH, to work with the modern CDI-based approach.
---
src/nvc_info.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/nvc_info.c b/src/nvc_info.c
index cf4b1905fd2127c28ee16649501be122d3be5261..2ab552860ef98879b76398a6f9be95f07b2c8a4a 100644
--- a/src/nvc_info.c
+++ b/src/nvc_info.c
@@ -243,16 +243,28 @@ static int
find_binary_paths(struct error *err, struct dxcore_context* dxcore, struct nvc_driver_info* info,
const char *root, const char * const bins[], size_t size)
{
- char *env, *ptr;
+ char *env, *ptr, *os_path;
const char *dir;
char tmp[PATH_MAX];
char path[PATH_MAX];
int rv = -1;

- if ((env = secure_getenv("PATH")) == NULL) {
+ if ((os_path = secure_getenv("PATH")) == NULL) {
error_setx(err, "environment variable PATH not found");
return (-1);
}
+
+ // TODO: Remove this patch once `virtualisation.docker.enableNvidia` is removed from NixOS.
+ // It only exists to maintain compatibility with the old nvidia-docker package.
+ int p_rv = snprintf(env, PATH_MAX, "/run/nvidia-docker/bin:/run/nvidia-docker/extras/bin:%s", os_path);
+ if (p_rv >= PATH_MAX) {
+ error_setx(err, "PATH environment variable too long");
+ return (-1);
+ } else if (p_rv < 0) {
+ error_setx(err, "error setting PATH environment variable");
+ return (-1);
+ }
+
if ((env = ptr = xstrdup(err, env)) == NULL)
return (-1);

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Moritz Sanft <[email protected]>
Date: Fri, 20 Dec 2024 16:38:55 +0100
Subject: [PATCH] nvc: fix struct declaration

---
src/nvcgo.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/nvcgo.c b/src/nvcgo.c
index 2e090c9bef83e165dfb722ab27e3287407466173..643504cd485fbe4a89d5959a1adfb69ff6748576 100644
--- a/src/nvcgo.c
+++ b/src/nvcgo.c
@@ -33,7 +33,8 @@
void nvcgo_program_1(struct svc_req *, register SVCXPRT *);

static struct nvcgo_ext {
- struct nvcgo;
+ struct rpc rpc;
+ struct libnvcgo api;
bool initialized;
void *dl_handle;
} global_nvcgo_context;
14 changes: 0 additions & 14 deletions pkgs/by-name/li/libnvidia-container/inline-c-struct.patch

This file was deleted.

14 changes: 8 additions & 6 deletions pkgs/by-name/li/libnvidia-container/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ stdenv.mkDerivation rec {
patches = [
# Locations of nvidia driver libraries are not resolved via ldconfig which
# doesn't get used on NixOS.
# TODO: The latter doesn't really apply anymore.
# Additional support binaries like nvidia-smi
# are not resolved via the environment PATH but via the derivation output
# path.
(replaceVars ./fix-library-resolving.patch {
(replaceVars ./0001-ldcache-don-t-use-ldcache.patch {
inherit (addDriverRunpath) driverLink;
})

# Use both PATH and the legacy nvidia-docker paths (NixOS artifacts)
# for binary lookups.
# TODO: Remove the legacy compatibility once nvidia-docker is removed
# from NixOS.
./0002-nvc-nvidia-docker-compatible-binary-lookups.patch

# fix bogus struct declaration
./inline-c-struct.patch
./0003-nvc-fix-struct-declaration.patch
];

postPatch = ''
Expand Down

0 comments on commit 24d9b8a

Please sign in to comment.