From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4DE8CA0519; Fri, 3 Jul 2020 17:05:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BFBA31DC3D; Fri, 3 Jul 2020 17:05:51 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 491371DC1E for ; Fri, 3 Jul 2020 17:05:49 +0200 (CEST) IronPort-SDR: zGGV/SM3e/KElEy7qSbCCQEeX9ZdXXJ6j0dHr0CI02HkdGtuLvFSHNMb5SnnXwvpTRlsPS7Ufi aNLDSN6tH+Jw== X-IronPort-AV: E=McAfee;i="6000,8403,9671"; a="212177538" X-IronPort-AV: E=Sophos;i="5.75,308,1589266800"; d="scan'208";a="212177538" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jul 2020 08:05:44 -0700 IronPort-SDR: X4EOBwa9+f0S4zyDzFrJ36E6UlKPQ+ukqAUmMPi1lAv0daz/H5yhfO8XaMuvrDc9Ueo/aEUvBf 62q2q7UgyFmA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,308,1589266800"; d="scan'208";a="482399804" Received: from npg-dpdk-haiyue-3.sh.intel.com ([10.67.119.46]) by fmsmga005.fm.intel.com with ESMTP; 03 Jul 2020 08:05:42 -0700 From: Haiyue Wang To: dev@dpdk.org, anatoly.burakov@intel.com, thomas@monjalon.net, jerinj@marvell.com, david.marchand@redhat.com, arybchenko@solarflare.com Cc: Haiyue Wang , Harman Kalra Date: Fri, 3 Jul 2020 22:57:18 +0800 Message-Id: <20200703145718.81017-3-haiyue.wang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200703145718.81017-1-haiyue.wang@intel.com> References: <20200305043311.17065-1-vattunuru@marvell.com> <20200703145718.81017-1-haiyue.wang@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v17 2/2] eal: support for VFIO-PCI VF token X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The kernel module vfio-pci introduces the VF token to enable SR-IOV support since 5.7. The VF token can be set by a vfio-pci based PF driver and must be known by the vfio-pci based VF driver in order to gain access to the device. Since the vfio-pci module uses the VF token as internal data to provide the collaboration between SR-IOV PF and VFs, so DPDK can use the same VF token for all PF devices by specifying the related EAL option. Signed-off-by: Haiyue Wang Acked-by: Anatoly Burakov Acked-by: Andrew Rybchenko Tested-by: Harman Kalra --- doc/guides/linux_gsg/linux_drivers.rst | 35 ++++++++++++++++++- doc/guides/linux_gsg/linux_eal_parameters.rst | 4 +++ doc/guides/rel_notes/release_20_08.rst | 6 ++++ lib/librte_eal/common/eal_common_options.c | 3 ++ lib/librte_eal/common/eal_internal_cfg.h | 2 ++ lib/librte_eal/common/eal_options.h | 2 ++ lib/librte_eal/freebsd/eal.c | 5 +++ lib/librte_eal/include/rte_eal.h | 14 ++++++++ lib/librte_eal/linux/eal.c | 33 +++++++++++++++++ lib/librte_eal/linux/eal_vfio.c | 19 ++++++++++ lib/librte_eal/rte_eal_version.map | 3 ++ 11 files changed, 125 insertions(+), 1 deletion(-) diff --git a/doc/guides/linux_gsg/linux_drivers.rst b/doc/guides/linux_gsg/linux_drivers.rst index d40b495c1..4eda3d5bf 100644 --- a/doc/guides/linux_gsg/linux_drivers.rst +++ b/doc/guides/linux_gsg/linux_drivers.rst @@ -78,11 +78,44 @@ Note that in order to use VFIO, your kernel must support it. VFIO kernel modules have been included in the Linux kernel since version 3.6.0 and are usually present by default, however please consult your distributions documentation to make sure that is the case. +The ``vfio-pci`` module since Linux version 5.7 supports the creation of virtual +functions. After the PF is bound to vfio-pci module, the user can create the VFs +by sysfs interface, and these VFs are bound to vfio-pci module automatically. + +When the PF is bound to vfio-pci, it has initial VF token generated by random. For +security reason, this token is write only, the user can't read it from the kernel +directly. To access the VF, the user needs to start the PF with token parameter to +setup a VF token in UUID format, then the VF can be accessed with this new token. + +Since the ``vfio-pci`` module uses the VF token as internal data to provide the +collaboration between SR-IOV PF and VFs, so DPDK can use the same VF token for all +PF devices which bound to one application. This VF token can be specified by the EAL +parameter ``--vfio-vf-token``. + +.. code-block:: console + + 1. Generate the VF token by uuid command + 14d63f20-8445-11ea-8900-1f9ce7d5650d + + 2. sudo modprobe vfio-pci enable_sriov=1 + + 2. ./usertools/dpdk-devbind.py -b vfio-pci 0000:86:00.0 + + 3. echo 2 > /sys/bus/pci/devices/0000:86:00.0/sriov_numvfs + + 4. Start the PF: + ./x86_64-native-linux-gcc/app/testpmd -l 22-25 -n 4 -w 86:00.0 \ + --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=pf -- -i + + 5. Start the VF: + ./x86_64-native-linux-gcc/app/testpmd -l 26-29 -n 4 -w 86:02.0 \ + --vfio-vf-token=14d63f20-8445-11ea-8900-1f9ce7d5650d --file-prefix=vf0 -- -i + Also, to use VFIO, both kernel and BIOS must support and be configured to use IO virtualization (such as IntelĀ® VT-d). .. note:: - ``vfio-pci`` module doesn't support the creation of virtual functions. + ``vfio-pci`` module doesn't support the creation of virtual functions before Linux version 5.7. For proper operation of VFIO when running DPDK applications as a non-privileged user, correct permissions should also be set up. This can be done by using the DPDK setup script (called dpdk-setup.sh and located in the usertools directory). diff --git a/doc/guides/linux_gsg/linux_eal_parameters.rst b/doc/guides/linux_gsg/linux_eal_parameters.rst index b2cc60e44..bd3977cb3 100644 --- a/doc/guides/linux_gsg/linux_eal_parameters.rst +++ b/doc/guides/linux_gsg/linux_eal_parameters.rst @@ -40,6 +40,10 @@ Device-related options Use specified interrupt mode for devices bound to VFIO kernel driver. +* ``--vfio-vf-token `` + + Use specified VF token for devices bound to VFIO kernel driver. + Multiprocessing-related options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/guides/rel_notes/release_20_08.rst b/doc/guides/rel_notes/release_20_08.rst index 5cbc4ce14..333f315ca 100644 --- a/doc/guides/rel_notes/release_20_08.rst +++ b/doc/guides/rel_notes/release_20_08.rst @@ -107,6 +107,12 @@ New Features * Dump ``rte_flow`` memory consumption. * Measure packet per second forwarding. +* **Added the support for vfio-pci new VF token interface.** + + From Linux 5.7, vfio-pci supports to bind both SR-IOV PF and the created VFs, + it uses a shared VF token (UUID) to represent the collaboration between PF + and VFs. Update DPDK PCI driver to gain the access to the PF and VFs devices + by appending the VF token parameter. Removed Items ------------- diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 24b223ebf..15b47349d 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -94,6 +94,7 @@ eal_long_options[] = { {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, + {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM}, @@ -327,6 +328,8 @@ eal_reset_internal_config(struct internal_config *internal_cfg) /* if set to NONE, interrupt mode is determined automatically */ internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; + memset(internal_cfg->vfio_vf_token, 0, + sizeof(internal_cfg->vfio_vf_token)); #ifdef RTE_LIBEAL_USE_HPET internal_cfg->no_hpet = 0; diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h index 2aaa167d4..13f93388a 100644 --- a/lib/librte_eal/common/eal_internal_cfg.h +++ b/lib/librte_eal/common/eal_internal_cfg.h @@ -72,6 +72,8 @@ struct internal_config { volatile int syslog_facility; /**< facility passed to openlog() */ /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; + /** the shared VF token for VFIO-PCI bound PF and VFs devices */ + rte_uuid_t vfio_vf_token; char *hugefile_prefix; /**< the base filename of hugetlbfs files */ char *hugepage_dir; /**< specific hugetlbfs directory to use */ char *user_mbuf_pool_ops_name; diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h index 18e6da9ab..89769d48b 100644 --- a/lib/librte_eal/common/eal_options.h +++ b/lib/librte_eal/common/eal_options.h @@ -69,6 +69,8 @@ enum { OPT_VDEV_NUM, #define OPT_VFIO_INTR "vfio-intr" OPT_VFIO_INTR_NUM, +#define OPT_VFIO_VF_TOKEN "vfio-vf-token" + OPT_VFIO_VF_TOKEN_NUM, #define OPT_VMWARE_TSC_MAP "vmware-tsc-map" OPT_VMWARE_TSC_MAP_NUM, #define OPT_LEGACY_MEM "legacy-mem" diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c index 8c75cba79..040b1b7ee 100644 --- a/lib/librte_eal/freebsd/eal.c +++ b/lib/librte_eal/freebsd/eal.c @@ -966,6 +966,11 @@ rte_eal_vfio_intr_mode(void) return RTE_INTR_MODE_NONE; } +void +rte_eal_vfio_get_vf_token(__rte_unused rte_uuid_t vf_token) +{ +} + int rte_vfio_setup_device(__rte_unused const char *sysfs_base, __rte_unused const char *dev_addr, __rte_unused int *vfio_dev_fd, diff --git a/lib/librte_eal/include/rte_eal.h b/lib/librte_eal/include/rte_eal.h index 2f9ed298d..6c70632cc 100644 --- a/lib/librte_eal/include/rte_eal.h +++ b/lib/librte_eal/include/rte_eal.h @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -438,6 +439,19 @@ int rte_eal_create_uio_dev(void); */ enum rte_intr_mode rte_eal_vfio_intr_mode(void); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Copy the user-configured vfio VF token. + * + * @param vf_token + * vfio VF token configured with the command line is copied + * into this parameter, zero uuid by default. + */ +__rte_experimental +void rte_eal_vfio_get_vf_token(rte_uuid_t vf_token); + /** * A wrap API for syscall gettid. * diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c index 3b56d14da..d6b8d8be7 100644 --- a/lib/librte_eal/linux/eal.c +++ b/lib/librte_eal/linux/eal.c @@ -540,6 +540,7 @@ eal_usage(const char *prgname) " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n" " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n" " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n" + " --"OPT_VFIO_VF_TOKEN" VF token (UUID) shared between SR-IOV PF and VFs\n" " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n" " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n" " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n" @@ -620,6 +621,20 @@ eal_parse_vfio_intr(const char *mode) return -1; } +static int +eal_parse_vfio_vf_token(const char *vf_token) +{ + struct internal_config *cfg = eal_get_internal_configuration(); + rte_uuid_t uuid; + + if (!rte_uuid_parse(vf_token, uuid)) { + rte_uuid_copy(cfg->vfio_vf_token, uuid); + return 0; + } + + return -1; +} + /* Parse the arguments for --log-level only */ static void eal_log_level_parse(int argc, char **argv) @@ -762,6 +777,16 @@ eal_parse_args(int argc, char **argv) } break; + case OPT_VFIO_VF_TOKEN_NUM: + if (eal_parse_vfio_vf_token(optarg) < 0) { + RTE_LOG(ERR, EAL, "invalid parameters for --" + OPT_VFIO_VF_TOKEN "\n"); + eal_usage(prgname); + ret = -1; + goto out; + } + break; + case OPT_CREATE_UIO_DEV_NUM: internal_conf->create_uio_dev = 1; break; @@ -1342,6 +1367,14 @@ rte_eal_vfio_intr_mode(void) return internal_conf->vfio_intr_mode; } +void +rte_eal_vfio_get_vf_token(rte_uuid_t vf_token) +{ + struct internal_config *cfg = eal_get_internal_configuration(); + + rte_uuid_copy(vf_token, cfg->vfio_vf_token); +} + int rte_eal_check_module(const char *module_name) { diff --git a/lib/librte_eal/linux/eal_vfio.c b/lib/librte_eal/linux/eal_vfio.c index abb12a354..d4470a34d 100644 --- a/lib/librte_eal/linux/eal_vfio.c +++ b/lib/librte_eal/linux/eal_vfio.c @@ -714,6 +714,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int vfio_container_fd; int vfio_group_fd; int iommu_group_num; + rte_uuid_t vf_token; int i, ret; const struct internal_config *internal_conf = eal_get_internal_configuration(); @@ -899,6 +900,23 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, t->type_id, t->name); } + rte_eal_vfio_get_vf_token(vf_token); + + /* get a file descriptor for the device with VF token firstly */ + if (!rte_uuid_is_null(vf_token)) { + char vf_token_str[RTE_UUID_STRLEN]; + char dev[PATH_MAX]; + + rte_uuid_unparse(vf_token, vf_token_str, sizeof(vf_token_str)); + snprintf(dev, sizeof(dev), + "%s vf_token=%s", dev_addr, vf_token_str); + + *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, + dev); + if (*vfio_dev_fd >= 0) + goto dev_get_info; + } + /* get a file descriptor for the device */ *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, dev_addr); if (*vfio_dev_fd < 0) { @@ -914,6 +932,7 @@ rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, } /* test and setup the device */ +dev_get_info: ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info); if (ret) { RTE_LOG(ERR, EAL, " %s cannot get device info, " diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 196eef5af..7923c62f2 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -386,6 +386,9 @@ EXPERIMENTAL { rte_trace_point_lookup; rte_trace_regexp; rte_trace_save; + + # added in 20.08 + rte_eal_vfio_get_vf_token; }; INTERNAL { -- 2.27.0