From 86431df1685cbfe20a54a48327e5000edc3e98e9 Mon Sep 17 00:00:00 2001 From: Jun Zeng Date: Thu, 8 Sep 2022 17:29:15 +0800 Subject: [PATCH] lib/env_dpdk: Add support for vfio-vf-token parameter The kernel vfio_pci driver module introduced vf_token checking mechanism since kernel version 5.7, and has been supported by DPDK. So add support for it to deal with the scenario of VF. Signed-off-by: Jun Zeng Change-Id: Ie9700fa395327da4e847c6213167284c148a64e3 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14424 Tested-by: SPDK CI Jenkins Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris --- include/spdk/env.h | 1 + include/spdk/event.h | 8 +++++++- lib/env_dpdk/Makefile | 2 +- lib/env_dpdk/init.c | 9 +++++++++ lib/event/app.c | 12 ++++++++++-- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index bd4578e93..c54c8c8ed 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -62,6 +62,7 @@ struct spdk_env_opts { /** Opaque context for use of the env implementation. */ void *env_context; + const char *vf_token; }; /** diff --git a/include/spdk/event.h b/include/spdk/event.h index be4c8b833..be8c3ee62 100644 --- a/include/spdk/event.h +++ b/include/spdk/event.h @@ -157,8 +157,14 @@ struct spdk_app_opts { * If non-NULL, a string array of allowed RPC methods. */ const char **rpc_allowlist; + + /** + * Used to pass vf_token to vfio_pci driver through DPDK. + * The vf_token is an UUID that shared between SR-IOV PF and VF. + */ + const char *vf_token; } __attribute__((packed)); -SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 208, "Incorrect size"); +SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 216, "Incorrect size"); /** * Initialize the default value of opts diff --git a/lib/env_dpdk/Makefile b/lib/env_dpdk/Makefile index 6b4c3b2e4..32d5f0a7e 100644 --- a/lib/env_dpdk/Makefile +++ b/lib/env_dpdk/Makefile @@ -6,7 +6,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -SO_VER := 10 +SO_VER := 11 SO_MINOR := 0 CFLAGS += $(ENV_CFLAGS) diff --git a/lib/env_dpdk/init.c b/lib/env_dpdk/init.c index c9ea41601..aacd2c4dc 100644 --- a/lib/env_dpdk/init.c +++ b/lib/env_dpdk/init.c @@ -459,6 +459,15 @@ build_eal_cmdline(const struct spdk_env_opts *opts) return -1; } } + + /* --vfio-vf-token used for VF initialized by vfio_pci driver. */ + if (opts->vf_token) { + args = push_arg(args, &argcount, _sprintf_alloc("--vfio-vf-token=%s", + opts->vf_token)); + if (args == NULL) { + return -1; + } + } #endif g_eal_cmdline = args; diff --git a/lib/event/app.c b/lib/event/app.c index b04a5f7cb..0f0841b75 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -125,7 +125,9 @@ static const struct option g_cmdline_options[] = { #define DISABLE_CPUMASK_LOCKS_OPT_IDX 267 {"disable-cpumask-locks", no_argument, NULL, DISABLE_CPUMASK_LOCKS_OPT_IDX}, #define RPCS_ALLOWED_OPT_IDX 268 - {"rpcs-allowed", required_argument, NULL, RPCS_ALLOWED_OPT_IDX} + {"rpcs-allowed", required_argument, NULL, RPCS_ALLOWED_OPT_IDX}, +#define ENV_VF_TOKEN_OPT_IDX 269 + {"vfio-vf-token", required_argument, NULL, ENV_VF_TOKEN_OPT_IDX}, }; static void @@ -337,6 +339,7 @@ app_setup_env(struct spdk_app_opts *opts) env_opts.base_virtaddr = opts->base_virtaddr; env_opts.env_context = opts->env_context; env_opts.iova_mode = opts->iova_mode; + env_opts.vf_token = opts->vf_token; rc = spdk_env_init(&env_opts); free(env_opts.pci_blocked); @@ -516,10 +519,11 @@ app_copy_opts(struct spdk_app_opts *opts, struct spdk_app_opts *opts_user, size_ SET_FIELD(disable_signal_handlers); SET_FIELD(msg_mempool_size); SET_FIELD(rpc_allowlist); + SET_FIELD(vf_token); /* You should not remove this statement, but need to update the assert statement * if you add a new field, and also add a corresponding SET_FIELD statement */ - SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 208, "Incorrect size"); + SPDK_STATIC_ASSERT(sizeof(struct spdk_app_opts) == 216, "Incorrect size"); #undef SET_FIELD } @@ -872,6 +876,7 @@ usage(void (*app_usage)(void)) SPDK_APP_DEFAULT_NUM_TRACE_ENTRIES); printf(" --rpcs-allowed comma-separated list of permitted RPCS\n"); printf(" --env-context Opaque context for use of the env implementation\n"); + printf(" --vfio-vf-token VF token (UUID) shared between SR-IOV PF and VFs for vfio_pci driver\n"); spdk_log_usage(stdout, "-L"); spdk_trace_mask_usage(stdout, "-e"); if (app_usage) { @@ -1129,6 +1134,9 @@ spdk_app_parse_args(int argc, char **argv, struct spdk_app_opts *opts, goto out; } break; + case ENV_VF_TOKEN_OPT_IDX: + opts->vf_token = optarg; + break; case VERSION_OPT_IDX: printf(SPDK_VERSION_STRING"\n"); retval = SPDK_APP_PARSE_ARGS_HELP;