From: Sachin Saxena <sachin.saxena@nxp.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, Hemant Agrawal <hemant.agrawal@nxp.com>
Subject: [dpdk-dev] [PATCH v2 27/30] bus/fslmc: support multi vfio group
Date: Thu, 29 Aug 2019 15:57:34 +0530 [thread overview]
Message-ID: <20190829102737.13267-28-sachin.saxena@nxp.com> (raw)
In-Reply-To: <20190829102737.13267-1-sachin.saxena@nxp.com>
From: Hemant Agrawal <hemant.agrawal@nxp.com>
DPAA2 support VFIO device passthrough in VM.
However in this case, each device is associated with different vfio group.
This code required different container id for each group.
On using the same container fd the second time,
ioctl calls are returning error.
Signed-off-by: Hemant Agrawal <hemant.agrawal@nxp.com>
---
drivers/bus/fslmc/fslmc_bus.c | 7 +-
drivers/bus/fslmc/fslmc_vfio.c | 160 ++++++++++++++++++++++++++-------
drivers/bus/fslmc/fslmc_vfio.h | 3 +
3 files changed, 133 insertions(+), 37 deletions(-)
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 9226d5b62..eff15f25d 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -1,6 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
- * Copyright 2016,2018 NXP
+ * Copyright 2016,2018-2019 NXP
*
*/
@@ -325,8 +325,7 @@ rte_fslmc_scan(void)
goto scan_fail;
/* Scan devices on the group */
- snprintf(fslmc_dirpath, sizeof(fslmc_dirpath), "%s/%d/devices",
- VFIO_IOMMU_GROUP_PATH, groupid);
+ sprintf(fslmc_dirpath, "%s/%s", SYSFS_FSL_MC_DEVICES, fslmc_container);
dir = opendir(fslmc_dirpath);
if (!dir) {
DPAA2_BUS_ERR("Unable to open VFIO group directory");
@@ -334,7 +333,7 @@ rte_fslmc_scan(void)
}
while ((entry = readdir(dir)) != NULL) {
- if (entry->d_name[0] == '.' || entry->d_type != DT_LNK)
+ if (entry->d_name[0] == '.' || entry->d_type != DT_DIR)
continue;
ret = scan_one_fslmc_device(entry->d_name);
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index 60c51d80e..970969d2b 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -40,16 +40,13 @@
#include "portal/dpaa2_hw_pvt.h"
#include "portal/dpaa2_hw_dpio.h"
-/** Pathname of FSL-MC devices directory. */
-#define SYSFS_FSL_MC_DEVICES "/sys/bus/fsl-mc/devices"
-
#define FSLMC_CONTAINER_MAX_LEN 8 /**< Of the format dprc.XX */
/* Number of VFIO containers & groups with in */
static struct fslmc_vfio_group vfio_group;
static struct fslmc_vfio_container vfio_container;
static int container_device_fd;
-static char *fslmc_container;
+char *fslmc_container;
static int fslmc_iommu_type;
static uint32_t *msi_intr_vaddr;
void *(*rte_mcp_ptr_list);
@@ -435,28 +432,136 @@ int rte_fslmc_vfio_dmamap(void)
return 0;
}
-static int64_t vfio_map_mcp_obj(struct fslmc_vfio_group *group, char *mcp_obj)
+static int
+fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
+ int *vfio_dev_fd, struct vfio_device_info *device_info)
+{
+ struct vfio_group_status group_status = {
+ .argsz = sizeof(group_status)
+ };
+ int vfio_group_fd, vfio_container_fd, iommu_group_no, ret;
+
+ /* get group number */
+ ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_no);
+ if (ret < 0)
+ return -1;
+
+ /* get the actual group fd */
+ vfio_group_fd = rte_vfio_get_group_fd(iommu_group_no);
+ if (vfio_group_fd < 0)
+ return -1;
+
+ /* if group_fd == 0, that means the device isn't managed by VFIO */
+ if (vfio_group_fd == 0) {
+ RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
+ dev_addr);
+ return 1;
+ }
+
+ /* Opens main vfio file descriptor which represents the "container" */
+ vfio_container_fd = rte_vfio_get_container_fd();
+ if (vfio_container_fd < 0) {
+ DPAA2_BUS_ERR("Failed to open VFIO container");
+ return -errno;
+ }
+
+ /* check if the group is viable */
+ ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
+ if (ret) {
+ DPAA2_BUS_ERR(" %s cannot get group status, "
+ "error %i (%s)\n", dev_addr,
+ errno, strerror(errno));
+ close(vfio_group_fd);
+ rte_vfio_clear_group(vfio_group_fd);
+ return -1;
+ } else if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
+ DPAA2_BUS_ERR(" %s VFIO group is not viable!\n", dev_addr);
+ close(vfio_group_fd);
+ rte_vfio_clear_group(vfio_group_fd);
+ return -1;
+ }
+ /* At this point, we know that this group is viable (meaning,
+ * all devices are either bound to VFIO or not bound to anything)
+ */
+
+ /* check if group does not have a container yet */
+ if (!(group_status.flags & VFIO_GROUP_FLAGS_CONTAINER_SET)) {
+
+ /* add group to a container */
+ ret = ioctl(vfio_group_fd, VFIO_GROUP_SET_CONTAINER,
+ &vfio_container_fd);
+ if (ret) {
+ DPAA2_BUS_ERR(" %s cannot add VFIO group to container, "
+ "error %i (%s)\n", dev_addr,
+ errno, strerror(errno));
+ close(vfio_group_fd);
+ close(vfio_container_fd);
+ rte_vfio_clear_group(vfio_group_fd);
+ return -1;
+ }
+
+ /*
+ * set an IOMMU type for container
+ *
+ */
+ if (ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
+ fslmc_iommu_type)) {
+ ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,
+ fslmc_iommu_type);
+ if (ret) {
+ DPAA2_BUS_ERR("Failed to setup VFIO iommu");
+ close(vfio_group_fd);
+ close(vfio_container_fd);
+ return -errno;
+ }
+ } else {
+ DPAA2_BUS_ERR("No supported IOMMU available");
+ close(vfio_group_fd);
+ close(vfio_container_fd);
+ return -EINVAL;
+ }
+ }
+
+ /* 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) {
+ /* if we cannot get a device fd, this implies a problem with
+ * the VFIO group or the container not having IOMMU configured.
+ */
+
+ DPAA2_BUS_WARN("Getting a vfio_dev_fd for %s failed", dev_addr);
+ close(vfio_group_fd);
+ close(vfio_container_fd);
+ rte_vfio_clear_group(vfio_group_fd);
+ return -1;
+ }
+
+ /* test and setup the device */
+ ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
+ if (ret) {
+ DPAA2_BUS_ERR(" %s cannot get device info, error %i (%s)",
+ dev_addr, errno, strerror(errno));
+ close(*vfio_dev_fd);
+ close(vfio_group_fd);
+ close(vfio_container_fd);
+ rte_vfio_clear_group(vfio_group_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+static intptr_t vfio_map_mcp_obj(const char *mcp_obj)
{
intptr_t v_addr = (intptr_t)MAP_FAILED;
int32_t ret, mc_fd;
+ struct vfio_group_status status = { .argsz = sizeof(status) };
struct vfio_device_info d_info = { .argsz = sizeof(d_info) };
struct vfio_region_info reg_info = { .argsz = sizeof(reg_info) };
- /* getting the mcp object's fd*/
- mc_fd = ioctl(group->fd, VFIO_GROUP_GET_DEVICE_FD, mcp_obj);
- if (mc_fd < 0) {
- DPAA2_BUS_ERR("Error in VFIO get dev %s fd from group %d",
- mcp_obj, group->fd);
- return v_addr;
- }
-
- /* getting device info*/
- ret = ioctl(mc_fd, VFIO_DEVICE_GET_INFO, &d_info);
- if (ret < 0) {
- DPAA2_BUS_ERR("Error in VFIO getting DEVICE_INFO");
- goto MC_FAILURE;
- }
+ fslmc_vfio_setup_device(SYSFS_FSL_MC_DEVICES, mcp_obj,
+ &mc_fd, &d_info);
/* getting device region info*/
ret = ioctl(mc_fd, VFIO_DEVICE_GET_REGION_INFO, ®_info);
@@ -589,19 +694,8 @@ fslmc_process_iodevices(struct rte_dpaa2_device *dev)
struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
struct rte_dpaa2_object *object = NULL;
- dev_fd = ioctl(vfio_group.fd, VFIO_GROUP_GET_DEVICE_FD,
- dev->device.name);
- if (dev_fd <= 0) {
- DPAA2_BUS_ERR("Unable to obtain device FD for device:%s",
- dev->device.name);
- return -1;
- }
-
- if (ioctl(dev_fd, VFIO_DEVICE_GET_INFO, &device_info)) {
- DPAA2_BUS_ERR("Unable to obtain information for device:%s",
- dev->device.name);
- return -1;
- }
+ fslmc_vfio_setup_device(SYSFS_FSL_MC_DEVICES, dev->device.name,
+ &dev_fd, &device_info);
switch (dev->dev_type) {
case DPAA2_ETH:
@@ -654,7 +748,7 @@ fslmc_process_mcp(struct rte_dpaa2_device *dev)
goto cleanup;
}
- v_addr = vfio_map_mcp_obj(&vfio_group, dev_name);
+ v_addr = vfio_map_mcp_obj(dev->device.name);
if (v_addr == (intptr_t)MAP_FAILED) {
DPAA2_BUS_ERR("Error mapping region (errno = %d)", errno);
ret = -1;
diff --git a/drivers/bus/fslmc/fslmc_vfio.h b/drivers/bus/fslmc/fslmc_vfio.h
index e877255ea..c98812129 100644
--- a/drivers/bus/fslmc/fslmc_vfio.h
+++ b/drivers/bus/fslmc/fslmc_vfio.h
@@ -10,6 +10,8 @@
#include <rte_vfio.h>
+/* Pathname of FSL-MC devices directory. */
+#define SYSFS_FSL_MC_DEVICES "/sys/bus/fsl-mc/devices"
#define DPAA2_MC_DPNI_DEVID 7
#define DPAA2_MC_DPSECI_DEVID 3
#define DPAA2_MC_DPCON_DEVID 5
@@ -38,6 +40,7 @@ typedef struct fslmc_vfio_container {
struct fslmc_vfio_group *group;
} fslmc_vfio_container;
+extern char *fslmc_container;
int rte_dpaa2_intr_enable(struct rte_intr_handle *intr_handle, int index);
int rte_dpaa2_intr_disable(struct rte_intr_handle *intr_handle, int index);
--
2.17.1
next prev parent reply other threads:[~2019-08-29 10:45 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-27 7:07 [dpdk-dev] [PATCH v1 00/30] Enhancements and fixes in NXP dpaax drivers and fsl-mc bus Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 01/30] bus/dpaa: fix DPAA SEC blacklist case Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 02/30] net/dpaa: improve the Rx offload debug message Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 03/30] bus/dpaa: remove un-necessary thread affinity Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 04/30] bus/dpaa: decouple fq portal alloc and init Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 05/30] net/dpaa: support Rx interrupt handler Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 06/30] net/dpaa: support for Rx interrupt enable and disable Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 07/30] net/dpaa: add SG support in Tx for non DPAA buffer Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 08/30] net/dpaa: reduce debug messages Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 09/30] net/dpaa2: improve the Rx offload debug message Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 10/30] common/dpaax: reduce debug mesages Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 11/30] mempool/dpaa: reduce debug messages Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 12/30] net/dpaa2: realign Rx offload support types Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 13/30] net/dpaa2: enable Rx offload for timestamp Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 14/30] net/dpaa2: support L2 payload based RSS distribution Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 15/30] net/dpaa2: add optional non-prefetch Rx mode Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 16/30] net/dpaa2: add taildrop support on frame count basis Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 17/30] net/dpaa2: add cgr counters in xtra stats Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 18/30] net/dpaa2: add support for config max Rx length in HW Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 19/30] net/dpaa2: use LFQIDs in Tx instead of qdid Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 20/30] net/dpaa2: support dpdmux classification on eth type Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 21/30] net/dpaa2: add Tx confirmation mode support Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 22/30] net/dpaa2: add timestamp support Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 23/30] net/dpaa2: add dprtc sub-module Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 24/30] net/dpaa2: add ptp driver Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 25/30] bus/fslmc: update PA-VA dpaax library only in PA mode Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 26/30] bus/fslmc: check for Dma map in primary process only Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 27/30] bus/fslmc: support multi vfio group Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 28/30] net/dpaa2: support separate MC portal per process Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 29/30] net/dpaa2: add support for soft parser in MC Sachin Saxena
2019-08-27 7:07 ` [dpdk-dev] [PATCH v1 30/30] net/dpaa2: add soft parser driver Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 00/30] Enhancements and fixes in NXP dpaax drivers and fsl-mc bus Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 01/30] bus/dpaa: fix DPAA SEC blacklist case Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 02/30] net/dpaa: improve the Rx offload debug message Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 03/30] bus/dpaa: remove un-necessary thread affinity Sachin Saxena
2019-09-30 11:51 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 04/30] bus/dpaa: decouple fq portal alloc and init Sachin Saxena
2019-09-30 11:52 ` Hemant Agrawal
2019-10-03 7:52 ` Ferruh Yigit
2019-10-03 9:42 ` Nipun Gupta
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 05/30] net/dpaa: support Rx interrupt handler Sachin Saxena
2019-09-30 11:51 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 06/30] net/dpaa: support for Rx interrupt enable and disable Sachin Saxena
2019-09-30 11:52 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 07/30] net/dpaa: add SG support in Tx for non DPAA buffer Sachin Saxena
2019-10-03 8:26 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 08/30] net/dpaa: reduce debug messages Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 09/30] net/dpaa2: improve the Rx offload debug message Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 10/30] common/dpaax: reduce debug mesages Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 11/30] mempool/dpaa: reduce debug messages Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 12/30] net/dpaa2: realign Rx offload support types Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 13/30] net/dpaa2: enable Rx offload for timestamp Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 14/30] net/dpaa2: support L2 payload based RSS distribution Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 15/30] net/dpaa2: add optional non-prefetch Rx mode Sachin Saxena
2019-10-03 8:26 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 16/30] net/dpaa2: add taildrop support on frame count basis Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 17/30] net/dpaa2: add cgr counters in xtra stats Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 18/30] net/dpaa2: add support for config max Rx length in HW Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 19/30] net/dpaa2: use LFQIDs in Tx instead of qdid Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 20/30] net/dpaa2: support dpdmux classification on eth type Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 21/30] net/dpaa2: add Tx confirmation mode support Sachin Saxena
2019-09-30 11:53 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 22/30] net/dpaa2: add timestamp support Sachin Saxena
2019-09-30 11:53 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 23/30] net/dpaa2: add dprtc sub-module Sachin Saxena
2019-10-03 8:26 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 24/30] net/dpaa2: add ptp driver Sachin Saxena
2019-10-03 8:26 ` Hemant Agrawal
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 25/30] bus/fslmc: update PA-VA dpaax library only in PA mode Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 26/30] bus/fslmc: check for Dma map in primary process only Sachin Saxena
2019-08-29 10:27 ` Sachin Saxena [this message]
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 28/30] net/dpaa2: support separate MC portal per process Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 29/30] net/dpaa2: add support for soft parser in MC Sachin Saxena
2019-08-29 10:27 ` [dpdk-dev] [PATCH v2 30/30] net/dpaa2: add soft parser driver Sachin Saxena
2019-10-03 8:26 ` Hemant Agrawal
2019-10-03 11:33 ` [dpdk-dev] [PATCH v2 00/30] Enhancements and fixes in NXP dpaax drivers and fsl-mc bus Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190829102737.13267-28-sachin.saxena@nxp.com \
--to=sachin.saxena@nxp.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).