Skip to content

Commit

Permalink
Add no-create-imex-channels command line option
Browse files Browse the repository at this point in the history
This change adds a no-create-imex-channels command line option to opt-out
of the creation of imex channel device nodes.

Note that the creation of device nodes is only triggered if --load-kmods
is specified.

Signed-off-by: Evan Lezar <[email protected]>
  • Loading branch information
elezar committed Oct 14, 2024
1 parent 4ef6252 commit 1f2ad79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/cli/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static struct argp usage = {
{"user", 'u', "UID[:GID]", OPTION_ARG_OPTIONAL, "User and group to use for privilege separation", -1},
{"root", 'r', "PATH", 0, "Path to the driver root directory", -1},
{"ldcache", 'l', "FILE", 0, "Path to the system's DSO cache", -1},
{"no-create-imex-channels", 0x80, NULL, 0, "Don't automatically create IMEX channel device nodes", -1},
{NULL, 0, NULL, 0, "Commands:", 0},
{"info", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "Report information about the driver and devices", 0},
{"list", 0, NULL, OPTION_DOC|OPTION_NO_USAGE, "List driver components", 0},
Expand Down Expand Up @@ -112,6 +113,10 @@ parser(int key, char *arg, struct argp_state *state)
case 'l':
ctx->ldcache = arg;
break;
case 0x80:
if (str_join(&err, &ctx->init_flags, "no-create-imex-channels", " ") < 0)
goto fatal;
break;
case ARGP_KEY_ARGS:
state->argv += state->next;
state->argc -= state->next;
Expand Down
17 changes: 10 additions & 7 deletions src/nvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "xfuncs.h"

static int init_within_userns(struct error *);
static int load_kernel_modules(struct error *, const char *, const struct nvc_imex_info *);
static int load_kernel_modules(struct error *, const char *, const struct nvc_imex_info *, int32_t);
static int copy_config(struct error *, struct nvc_context *, const struct nvc_config *);

const char interpreter[] __attribute__((section(".interp"))) = LIB_DIR "/" LD_SO;
Expand Down Expand Up @@ -229,7 +229,7 @@ mig_nvcaps_mknodes(struct error *err, int num_gpus) {
}

static int
load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_info *imex)
load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_info *imex, int32_t flags)
{
int userns;
pid_t pid;
Expand Down Expand Up @@ -290,10 +290,13 @@ load_kernel_modules(struct error *err, const char *root, const struct nvc_imex_i
log_info("running mknod for all nvcaps in " NV_CAPS_DEVICE_DIR);
if (mig_nvcaps_mknodes(err, devs.num_matches) < 0)
log_errf("could not create kernel module device nodes: %s", err->msg);
for (int i = 0; i < (int)imex->nchans; ++i) {
log_infof("running mknod for " NV_CAPS_IMEX_DEVICE_PATH, imex->chans[i].id);
if (nvidia_cap_imex_channel_mknod(imex->chans[i].id) == 0)
log_errf("could not mknod for IMEX channel %d", imex->chans[i].id);

if (!(flags & OPT_NO_CREATE_IMEX_CHANNELS)) {
for (int i = 0; i < (int)imex->nchans; ++i) {
log_infof("running mknod for " NV_CAPS_IMEX_DEVICE_PATH, imex->chans[i].id);
if (nvidia_cap_imex_channel_mknod(imex->chans[i].id) == 0)
log_errf("could not mknod for IMEX channel %d", imex->chans[i].id);
}
}
error_reset(err);
}
Expand Down Expand Up @@ -420,7 +423,7 @@ nvc_init(struct nvc_context *ctx, const struct nvc_config *cfg, const char *opts
if (flags & OPT_LOAD_KMODS) {
if (ctx->dxcore.initialized)
log_warn("skipping kernel modules load on WSL");
else if (load_kernel_modules(&ctx->err, ctx->cfg.root, &ctx->cfg.imex) < 0)
else if (load_kernel_modules(&ctx->err, ctx->cfg.root, &ctx->cfg.imex, flags) < 0)
goto fail;
}

Expand Down
4 changes: 3 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ struct option {

/* Library options */
enum {
OPT_LOAD_KMODS = 1 << 0,
OPT_LOAD_KMODS = 1 << 0,
OPT_NO_CREATE_IMEX_CHANNELS = 1 << 1,
};

static const struct option library_opts[] = {
{"load-kmods", OPT_LOAD_KMODS},
{"no-create-imex-channels", OPT_NO_CREATE_IMEX_CHANNELS}
};

static const char * const default_library_opts = "";
Expand Down

0 comments on commit 1f2ad79

Please sign in to comment.