* [dpdk-dev] [PATCH v3 01/16] vfio: fix include of eal_private.h to be local
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 02/16] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
` (16 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index f91b924..8b7d53f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -43,11 +43,11 @@
#include <rte_pci.h>
#include <rte_eal_memconfig.h>
#include <rte_malloc.h>
-#include <eal_private.h>
#include "eal_filesystem.h"
#include "eal_pci_init.h"
#include "eal_vfio.h"
+#include "eal_private.h"
/**
* @file
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 02/16] vfio: move VFIO-specific stuff to eal_vfio.h
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 03/16] vfio: move common vfio constants " Jan Viktorin
` (15 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The common VFIO definitions should be separated from the PCI-specific parts.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 28 ----------------------------
lib/librte_eal/linuxapp/eal/eal_vfio.h | 28 ++++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index f72a254..75b8ed3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -74,8 +74,6 @@ int pci_uio_ioport_unmap(struct rte_pci_ioport *p);
#ifdef VFIO_PRESENT
-#define VFIO_MAX_GROUPS 64
-
int pci_vfio_enable(void);
int pci_vfio_is_enabled(void);
int pci_vfio_mp_sync_setup(void);
@@ -99,15 +97,6 @@ int pci_vfio_map_resource(struct rte_pci_device *dev);
int pci_vfio_get_group_fd(int iommu_group_fd);
int pci_vfio_get_container_fd(void);
-/*
- * Function prototypes for VFIO multiprocess sync functions
- */
-int vfio_mp_sync_send_request(int socket, int req);
-int vfio_mp_sync_receive_request(int socket);
-int vfio_mp_sync_send_fd(int socket, int fd);
-int vfio_mp_sync_receive_fd(int socket);
-int vfio_mp_sync_connect_to_primary(void);
-
/* socket comm protocol definitions */
#define SOCKET_REQ_CONTAINER 0x100
#define SOCKET_REQ_GROUP 0x200
@@ -115,23 +104,6 @@ int vfio_mp_sync_connect_to_primary(void);
#define SOCKET_NO_FD 0x1
#define SOCKET_ERR 0xFF
-/*
- * we don't need to store device fd's anywhere since they can be obtained from
- * the group fd via an ioctl() call.
- */
-struct vfio_group {
- int group_no;
- int fd;
-};
-
-struct vfio_config {
- int vfio_enabled;
- int vfio_container_fd;
- int vfio_container_has_dma;
- int vfio_group_idx;
- struct vfio_group vfio_groups[VFIO_MAX_GROUPS];
-};
-
#endif
#endif /* EAL_PCI_INIT_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index f483bf4..cedbeb0 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -60,6 +60,34 @@
#define RTE_VFIO_NOIOMMU VFIO_NOIOMMU_IOMMU
#endif
+#define VFIO_MAX_GROUPS 64
+
+/*
+ * Function prototypes for VFIO multiprocess sync functions
+ */
+int vfio_mp_sync_send_request(int socket, int req);
+int vfio_mp_sync_receive_request(int socket);
+int vfio_mp_sync_send_fd(int socket, int fd);
+int vfio_mp_sync_receive_fd(int socket);
+int vfio_mp_sync_connect_to_primary(void);
+
+/*
+ * we don't need to store device fd's anywhere since they can be obtained from
+ * the group fd via an ioctl() call.
+ */
+struct vfio_group {
+ int group_no;
+ int fd;
+};
+
+struct vfio_config {
+ int vfio_enabled;
+ int vfio_container_fd;
+ int vfio_container_has_dma;
+ int vfio_group_idx;
+ struct vfio_group vfio_groups[VFIO_MAX_GROUPS];
+};
+
#define VFIO_PRESENT
#endif /* kernel version */
#endif /* RTE_EAL_VFIO */
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 03/16] vfio: move common vfio constants to eal_vfio.h
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 02/16] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
` (14 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 7 -------
lib/librte_eal/linuxapp/eal/eal_vfio.h | 7 +++++++
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 8b7d53f..c8f9ec1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -69,13 +69,6 @@ static struct rte_tailq_elem rte_vfio_tailq = {
};
EAL_REGISTER_TAILQ(rte_vfio_tailq)
-#define VFIO_DIR "/dev/vfio"
-#define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
-#define VFIO_GROUP_FMT "/dev/vfio/%u"
-#define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u"
-#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
-#define VFIO_GET_REGION_IDX(x) (x >> 40)
-
/* per-process VFIO config */
static struct vfio_config vfio_cfg;
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index cedbeb0..bcf6860 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -88,6 +88,13 @@ struct vfio_config {
struct vfio_group vfio_groups[VFIO_MAX_GROUPS];
};
+#define VFIO_DIR "/dev/vfio"
+#define VFIO_CONTAINER_PATH "/dev/vfio/vfio"
+#define VFIO_GROUP_FMT "/dev/vfio/%u"
+#define VFIO_NOIOMMU_GROUP_FMT "/dev/vfio/noiommu-%u"
+#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
+#define VFIO_GET_REGION_IDX(x) (x >> 40)
+
#define VFIO_PRESENT
#endif /* kernel version */
#endif /* RTE_EAL_VFIO */
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (2 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 03/16] vfio: move common vfio constants " Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 05/16] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
` (13 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
We make the iommu_types public temporarily here until the depending stuff is
refactored. The iommu_types and dma_map functions will be changed to be private
inside the eal_vfio module later.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/Makefile | 1 +
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 62 -----------------------
lib/librte_eal/linuxapp/eal/eal_vfio.c | 79 ++++++++++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 23 +++++++++
4 files changed, 103 insertions(+), 62 deletions(-)
create mode 100644 lib/librte_eal/linuxapp/eal/eal_vfio.c
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 30b30f3..517554f 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -66,6 +66,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_xen_memory.c
endif
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_thread.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_log.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vfio.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci_uio.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci_vfio.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index c8f9ec1..c52ea37 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -72,68 +72,6 @@ EAL_REGISTER_TAILQ(rte_vfio_tailq)
/* per-process VFIO config */
static struct vfio_config vfio_cfg;
-/* DMA mapping function prototype.
- * Takes VFIO container fd as a parameter.
- * Returns 0 on success, -1 on error.
- * */
-typedef int (*vfio_dma_func_t)(int);
-
-struct vfio_iommu_type {
- int type_id;
- const char *name;
- vfio_dma_func_t dma_map_func;
-};
-
-static int vfio_type1_dma_map(int);
-static int vfio_noiommu_dma_map(int);
-
-/* IOMMU types we support */
-static const struct vfio_iommu_type iommu_types[] = {
- /* x86 IOMMU, otherwise known as type 1 */
- { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map},
- /* IOMMU-less mode */
- { RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map},
-};
-
-int
-vfio_type1_dma_map(int vfio_container_fd)
-{
- const struct rte_memseg *ms = rte_eal_get_physmem_layout();
- int i, ret;
-
- /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
- for (i = 0; i < RTE_MAX_MEMSEG; i++) {
- struct vfio_iommu_type1_dma_map dma_map;
-
- if (ms[i].addr == NULL)
- break;
-
- memset(&dma_map, 0, sizeof(dma_map));
- dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
- dma_map.vaddr = ms[i].addr_64;
- dma_map.size = ms[i].len;
- dma_map.iova = ms[i].phys_addr;
- dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
-
- ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
-
- if (ret) {
- RTE_LOG(ERR, EAL, " cannot set up DMA remapping, "
- "error %i (%s)\n", errno, strerror(errno));
- return -1;
- }
- }
-
- return 0;
-}
-
-int
-vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
-{
- /* No-IOMMU mode does not need DMA mapping */
- return 0;
-}
-
int
pci_vfio_read_config(const struct rte_intr_handle *intr_handle,
void *buf, size_t len, off_t offs)
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
new file mode 100644
index 0000000..d3ffebe
--- /dev/null
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -0,0 +1,79 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <sys/ioctl.h>
+
+#include <rte_log.h>
+#include <rte_memory.h>
+
+#include "eal_vfio.h"
+
+int
+vfio_type1_dma_map(int vfio_container_fd)
+{
+ const struct rte_memseg *ms = rte_eal_get_physmem_layout();
+ int i, ret;
+
+ /* map all DPDK segments for DMA. use 1:1 PA to IOVA mapping */
+ for (i = 0; i < RTE_MAX_MEMSEG; i++) {
+ struct vfio_iommu_type1_dma_map dma_map;
+
+ if (ms[i].addr == NULL)
+ break;
+
+ memset(&dma_map, 0, sizeof(dma_map));
+ dma_map.argsz = sizeof(struct vfio_iommu_type1_dma_map);
+ dma_map.vaddr = ms[i].addr_64;
+ dma_map.size = ms[i].len;
+ dma_map.iova = ms[i].phys_addr;
+ dma_map.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE;
+
+ ret = ioctl(vfio_container_fd, VFIO_IOMMU_MAP_DMA, &dma_map);
+
+ if (ret) {
+ RTE_LOG(ERR, EAL, " cannot set up DMA remapping, "
+ "error %i (%s)\n", errno, strerror(errno));
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int
+vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
+{
+ /* No-IOMMU mode does not need DMA mapping */
+ return 0;
+}
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index bcf6860..c62f269 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -95,6 +95,29 @@ struct vfio_config {
#define VFIO_GET_REGION_ADDR(x) ((uint64_t) x << 40ULL)
#define VFIO_GET_REGION_IDX(x) (x >> 40)
+/* DMA mapping function prototype.
+ * Takes VFIO container fd as a parameter.
+ * Returns 0 on success, -1 on error.
+ * */
+typedef int (*vfio_dma_func_t)(int);
+
+struct vfio_iommu_type {
+ int type_id;
+ const char *name;
+ vfio_dma_func_t dma_map_func;
+};
+
+int vfio_type1_dma_map(int);
+int vfio_noiommu_dma_map(int);
+
+/* IOMMU types we support */
+static const struct vfio_iommu_type iommu_types[] = {
+ /* x86 IOMMU, otherwise known as type 1 */
+ { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map},
+ /* IOMMU-less mode */
+ { RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map},
+};
+
#define VFIO_PRESENT
#endif /* kernel version */
#endif /* RTE_EAL_VFIO */
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 05/16] vfio: generalize pci_vfio_set_iommu_type
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (3 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
` (12 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The pci_vfio_set_iommu_type is not PCI-specific and it is a private function
of the eal_pci_vfio.c. We just rename the function and make it available even
for non-PCI devices.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 25 +------------------------
lib/librte_eal/linuxapp/eal/eal_vfio.c | 22 ++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 4 ++++
3 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index c52ea37..5fdf23f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -203,29 +203,6 @@ pci_vfio_set_bus_master(int dev_fd)
return 0;
}
-/* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */
-static const struct vfio_iommu_type *
-pci_vfio_set_iommu_type(int vfio_container_fd) {
- unsigned idx;
- for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
- const struct vfio_iommu_type *t = &iommu_types[idx];
-
- int ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,
- t->type_id);
- if (!ret) {
- RTE_LOG(NOTICE, EAL, " using IOMMU type %d (%s)\n",
- t->type_id, t->name);
- return t;
- }
- /* not an error, there may be more supported IOMMU types */
- RTE_LOG(DEBUG, EAL, " set IOMMU type %d (%s) failed, "
- "error %i (%s)\n", t->type_id, t->name, errno,
- strerror(errno));
- }
- /* if we didn't find a suitable IOMMU type, fail */
- return NULL;
-}
-
/* check if we have any supported extensions */
static int
pci_vfio_has_supported_extensions(int vfio_container_fd) {
@@ -689,7 +666,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
vfio_cfg.vfio_container_has_dma == 0) {
/* select an IOMMU type which we will be using */
const struct vfio_iommu_type *t =
- pci_vfio_set_iommu_type(vfio_cfg.vfio_container_fd);
+ vfio_set_iommu_type(vfio_cfg.vfio_container_fd);
if (!t) {
RTE_LOG(ERR, EAL, " %s failed to select IOMMU type\n", pci_addr);
return -1;
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index d3ffebe..ff85283 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -39,6 +39,28 @@
#include "eal_vfio.h"
+const struct vfio_iommu_type *
+vfio_set_iommu_type(int vfio_container_fd) {
+ unsigned idx;
+ for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
+ const struct vfio_iommu_type *t = &iommu_types[idx];
+
+ int ret = ioctl(vfio_container_fd, VFIO_SET_IOMMU,
+ t->type_id);
+ if (!ret) {
+ RTE_LOG(NOTICE, EAL, " using IOMMU type %d (%s)\n",
+ t->type_id, t->name);
+ return t;
+ }
+ /* not an error, there may be more supported IOMMU types */
+ RTE_LOG(DEBUG, EAL, " set IOMMU type %d (%s) failed, "
+ "error %i (%s)\n", t->type_id, t->name, errno,
+ strerror(errno));
+ }
+ /* if we didn't find a suitable IOMMU type, fail */
+ return NULL;
+}
+
int
vfio_type1_dma_map(int vfio_container_fd)
{
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index c62f269..afbb98a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -107,6 +107,10 @@ struct vfio_iommu_type {
vfio_dma_func_t dma_map_func;
};
+/* pick IOMMU type. returns a pointer to vfio_iommu_type or NULL for error */
+const struct vfio_iommu_type *
+vfio_set_iommu_type(int vfio_container_fd);
+
int vfio_type1_dma_map(int);
int vfio_noiommu_dma_map(int);
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 06/16] vfio: generalize pci_vfio_has_supported_extensions
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (4 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 05/16] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-10 17:36 ` Thomas Monjalon
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 07/16] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
` (11 subsequent siblings)
17 siblings, 1 reply; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The pci_vfio_has_supported_extensions is not PCI-specific and it is a private
function of the eal_pci_vfio.c. We just rename the function and make it
available even for non-PCI devices.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 36 +-----------------------------
lib/librte_eal/linuxapp/eal/eal_vfio.c | 33 +++++++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 4 ++++
3 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 5fdf23f..f93db4a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -203,40 +203,6 @@ pci_vfio_set_bus_master(int dev_fd)
return 0;
}
-/* check if we have any supported extensions */
-static int
-pci_vfio_has_supported_extensions(int vfio_container_fd) {
- int ret;
- unsigned idx, n_extensions = 0;
- for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
- const struct vfio_iommu_type *t = &iommu_types[idx];
-
- ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
- t->type_id);
- if (ret < 0) {
- RTE_LOG(ERR, EAL, " could not get IOMMU type, "
- "error %i (%s)\n", errno,
- strerror(errno));
- close(vfio_container_fd);
- return -1;
- } else if (ret == 1) {
- /* we found a supported extension */
- n_extensions++;
- }
- RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n",
- t->type_id, t->name,
- ret ? "supported" : "not supported");
- }
-
- /* if we didn't find any supported IOMMU types, fail */
- if (!n_extensions) {
- close(vfio_container_fd);
- return -1;
- }
-
- return 0;
-}
-
/* set up interrupt support (but not enable interrupts) */
static int
pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
@@ -360,7 +326,7 @@ pci_vfio_get_container_fd(void)
return -1;
}
- ret = pci_vfio_has_supported_extensions(vfio_container_fd);
+ ret = vfio_has_supported_extensions(vfio_container_fd);
if (ret) {
RTE_LOG(ERR, EAL, " no supported IOMMU "
"extensions found!\n");
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index ff85283..6a95d2a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -62,6 +62,39 @@ vfio_set_iommu_type(int vfio_container_fd) {
}
int
+vfio_has_supported_extensions(int vfio_container_fd) {
+ int ret;
+ unsigned idx, n_extensions = 0;
+ for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
+ const struct vfio_iommu_type *t = &iommu_types[idx];
+
+ ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
+ t->type_id);
+ if (ret < 0) {
+ RTE_LOG(ERR, EAL, " could not get IOMMU type, "
+ "error %i (%s)\n", errno,
+ strerror(errno));
+ close(vfio_container_fd);
+ return -1;
+ } else if (ret == 1) {
+ /* we found a supported extension */
+ n_extensions++;
+ }
+ RTE_LOG(DEBUG, EAL, " IOMMU type %d (%s) is %s\n",
+ t->type_id, t->name,
+ ret ? "supported" : "not supported");
+ }
+
+ /* if we didn't find any supported IOMMU types, fail */
+ if (!n_extensions) {
+ close(vfio_container_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
vfio_type1_dma_map(int vfio_container_fd)
{
const struct rte_memseg *ms = rte_eal_get_physmem_layout();
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index afbb98a..8cb0d1d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -111,6 +111,10 @@ struct vfio_iommu_type {
const struct vfio_iommu_type *
vfio_set_iommu_type(int vfio_container_fd);
+/* check if we have any supported extensions */
+int
+vfio_has_supported_extensions(int vfio_container_fd);
+
int vfio_type1_dma_map(int);
int vfio_noiommu_dma_map(int);
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH v3 06/16] vfio: generalize pci_vfio_has_supported_extensions
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
@ 2016-07-10 17:36 ` Thomas Monjalon
0 siblings, 0 replies; 20+ messages in thread
From: Thomas Monjalon @ 2016-07-10 17:36 UTC (permalink / raw)
To: Jan Viktorin
Cc: dev, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
There is a small error in this patch:
2016-07-04 17:16, Jan Viktorin:
> The pci_vfio_has_supported_extensions is not PCI-specific and it is a private
> function of the eal_pci_vfio.c. We just rename the function and make it
> available even for non-PCI devices.
|...]
|> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -62,6 +62,39 @@ vfio_set_iommu_type(int vfio_container_fd) {
> }
>
> int
> +vfio_has_supported_extensions(int vfio_container_fd) {
> + int ret;
> + unsigned idx, n_extensions = 0;
> + for (idx = 0; idx < RTE_DIM(iommu_types); idx++) {
> + const struct vfio_iommu_type *t = &iommu_types[idx];
> +
> + ret = ioctl(vfio_container_fd, VFIO_CHECK_EXTENSION,
> + t->type_id);
> + if (ret < 0) {
> + RTE_LOG(ERR, EAL, " could not get IOMMU type, "
> + "error %i (%s)\n", errno,
> + strerror(errno));
> + close(vfio_container_fd);
lib/librte_eal/linuxapp/eal/eal_vfio.c:77:4: error:
implicit declaration of function ‘close’
It is fixed in patch 8 with "#include <unistd.h>".
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 07/16] vfio: move vfio-specific SOCKET_* constants
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (5 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 08/16] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
` (10 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The constants are not PCI-specific. Move them into the eal_vfio.h.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 7 -------
lib/librte_eal/linuxapp/eal/eal_vfio.h | 6 ++++++
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 75b8ed3..883787f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -97,13 +97,6 @@ int pci_vfio_map_resource(struct rte_pci_device *dev);
int pci_vfio_get_group_fd(int iommu_group_fd);
int pci_vfio_get_container_fd(void);
-/* socket comm protocol definitions */
-#define SOCKET_REQ_CONTAINER 0x100
-#define SOCKET_REQ_GROUP 0x200
-#define SOCKET_OK 0x0
-#define SOCKET_NO_FD 0x1
-#define SOCKET_ERR 0xFF
-
#endif
#endif /* EAL_PCI_INIT_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 8cb0d1d..121df0a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -115,6 +115,12 @@ vfio_set_iommu_type(int vfio_container_fd);
int
vfio_has_supported_extensions(int vfio_container_fd);
+#define SOCKET_REQ_CONTAINER 0x100
+#define SOCKET_REQ_GROUP 0x200
+#define SOCKET_OK 0x0
+#define SOCKET_NO_FD 0x1
+#define SOCKET_ERR 0xFF
+
int vfio_type1_dma_map(int);
int vfio_noiommu_dma_map(int);
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 08/16] vfio: generalize pci_vfio_get_container_fd
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (6 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 07/16] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 09/16] vfio: generalize pci_vfio_get_group_no Jan Viktorin
` (9 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The pci_vfio_get_container_fd is not PCI-specific. Move the implementation to
the eal_vfio.c as vfio_get_container_fd. No other code seems to call this
function.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 1 -
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 67 +-------------------
lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 2 +-
lib/librte_eal/linuxapp/eal/eal_vfio.c | 72 ++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 4 ++
5 files changed, 78 insertions(+), 68 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 883787f..d34212b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -95,7 +95,6 @@ int pci_vfio_ioport_unmap(struct rte_pci_ioport *p);
/* map VFIO resource prototype */
int pci_vfio_map_resource(struct rte_pci_device *dev);
int pci_vfio_get_group_fd(int iommu_group_fd);
-int pci_vfio_get_container_fd(void);
#endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index f93db4a..528479a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -299,71 +299,6 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
return -1;
}
-/* open container fd or get an existing one */
-int
-pci_vfio_get_container_fd(void)
-{
- int ret, vfio_container_fd;
-
- /* if we're in a primary process, try to open the container */
- if (internal_config.process_type == RTE_PROC_PRIMARY) {
- vfio_container_fd = open(VFIO_CONTAINER_PATH, O_RDWR);
- if (vfio_container_fd < 0) {
- RTE_LOG(ERR, EAL, " cannot open VFIO container, "
- "error %i (%s)\n", errno, strerror(errno));
- return -1;
- }
-
- /* check VFIO API version */
- ret = ioctl(vfio_container_fd, VFIO_GET_API_VERSION);
- if (ret != VFIO_API_VERSION) {
- if (ret < 0)
- RTE_LOG(ERR, EAL, " could not get VFIO API version, "
- "error %i (%s)\n", errno, strerror(errno));
- else
- RTE_LOG(ERR, EAL, " unsupported VFIO API version!\n");
- close(vfio_container_fd);
- return -1;
- }
-
- ret = vfio_has_supported_extensions(vfio_container_fd);
- if (ret) {
- RTE_LOG(ERR, EAL, " no supported IOMMU "
- "extensions found!\n");
- return -1;
- }
-
- return vfio_container_fd;
- } else {
- /*
- * if we're in a secondary process, request container fd from the
- * primary process via our socket
- */
- int socket_fd;
-
- socket_fd = vfio_mp_sync_connect_to_primary();
- if (socket_fd < 0) {
- RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
- return -1;
- }
- if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_CONTAINER) < 0) {
- RTE_LOG(ERR, EAL, " cannot request container fd!\n");
- close(socket_fd);
- return -1;
- }
- vfio_container_fd = vfio_mp_sync_receive_fd(socket_fd);
- if (vfio_container_fd < 0) {
- RTE_LOG(ERR, EAL, " cannot get container fd!\n");
- close(socket_fd);
- return -1;
- }
- close(socket_fd);
- return vfio_container_fd;
- }
-
- return -1;
-}
-
/* open group fd or get an existing one */
int
pci_vfio_get_group_fd(int iommu_group_no)
@@ -950,7 +885,7 @@ pci_vfio_enable(void)
return 0;
}
- vfio_cfg.vfio_container_fd = pci_vfio_get_container_fd();
+ vfio_cfg.vfio_container_fd = vfio_get_container_fd();
/* check if we have VFIO driver enabled */
if (vfio_cfg.vfio_container_fd != -1) {
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
index d54ded8..a759f02 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
@@ -296,7 +296,7 @@ pci_vfio_mp_sync_thread(void __rte_unused * arg)
switch (ret) {
case SOCKET_REQ_CONTAINER:
- fd = pci_vfio_get_container_fd();
+ fd = vfio_get_container_fd();
if (fd < 0)
vfio_mp_sync_send_request(conn_sock, SOCKET_ERR);
else
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index 6a95d2a..5660ddd 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -32,13 +32,19 @@
*/
#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <sys/ioctl.h>
#include <rte_log.h>
#include <rte_memory.h>
+#include <rte_eal_memconfig.h>
+#include "eal_filesystem.h"
#include "eal_vfio.h"
+#ifdef VFIO_PRESENT
+
const struct vfio_iommu_type *
vfio_set_iommu_type(int vfio_container_fd) {
unsigned idx;
@@ -95,6 +101,70 @@ vfio_has_supported_extensions(int vfio_container_fd) {
}
int
+vfio_get_container_fd(void)
+{
+ int ret, vfio_container_fd;
+
+ /* if we're in a primary process, try to open the container */
+ if (internal_config.process_type == RTE_PROC_PRIMARY) {
+ vfio_container_fd = open(VFIO_CONTAINER_PATH, O_RDWR);
+ if (vfio_container_fd < 0) {
+ RTE_LOG(ERR, EAL, " cannot open VFIO container, "
+ "error %i (%s)\n", errno, strerror(errno));
+ return -1;
+ }
+
+ /* check VFIO API version */
+ ret = ioctl(vfio_container_fd, VFIO_GET_API_VERSION);
+ if (ret != VFIO_API_VERSION) {
+ if (ret < 0)
+ RTE_LOG(ERR, EAL, " could not get VFIO API version, "
+ "error %i (%s)\n", errno, strerror(errno));
+ else
+ RTE_LOG(ERR, EAL, " unsupported VFIO API version!\n");
+ close(vfio_container_fd);
+ return -1;
+ }
+
+ ret = vfio_has_supported_extensions(vfio_container_fd);
+ if (ret) {
+ RTE_LOG(ERR, EAL, " no supported IOMMU "
+ "extensions found!\n");
+ return -1;
+ }
+
+ return vfio_container_fd;
+ } else {
+ /*
+ * if we're in a secondary process, request container fd from the
+ * primary process via our socket
+ */
+ int socket_fd;
+
+ socket_fd = vfio_mp_sync_connect_to_primary();
+ if (socket_fd < 0) {
+ RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
+ return -1;
+ }
+ if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_CONTAINER) < 0) {
+ RTE_LOG(ERR, EAL, " cannot request container fd!\n");
+ close(socket_fd);
+ return -1;
+ }
+ vfio_container_fd = vfio_mp_sync_receive_fd(socket_fd);
+ if (vfio_container_fd < 0) {
+ RTE_LOG(ERR, EAL, " cannot get container fd!\n");
+ close(socket_fd);
+ return -1;
+ }
+ close(socket_fd);
+ return vfio_container_fd;
+ }
+
+ return -1;
+}
+
+int
vfio_type1_dma_map(int vfio_container_fd)
{
const struct rte_memseg *ms = rte_eal_get_physmem_layout();
@@ -132,3 +202,5 @@ vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
/* No-IOMMU mode does not need DMA mapping */
return 0;
}
+
+#endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 121df0a..0fb05a4 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -115,6 +115,10 @@ vfio_set_iommu_type(int vfio_container_fd);
int
vfio_has_supported_extensions(int vfio_container_fd);
+/* open container fd or get an existing one */
+int
+vfio_get_container_fd(void);
+
#define SOCKET_REQ_CONTAINER 0x100
#define SOCKET_REQ_GROUP 0x200
#define SOCKET_OK 0x0
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 09/16] vfio: generalize pci_vfio_get_group_no
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (7 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 08/16] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 10/16] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
` (8 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
Generalize the pci_vfio_get_group_no to not be PCI-specific. Move the general
implementation to the eal_vfio.c as vfio_get_group_no and leave the original
pci_vfio_get_group_no being a wrapper around this to preserve compilation
issues. The pci_vfio_get_group_no function will be removed later.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 38 +-------------------------
lib/librte_eal/linuxapp/eal/eal_vfio.c | 43 ++++++++++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 7 +++++
3 files changed, 51 insertions(+), 37 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 528479a..c2ff465 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -401,43 +401,7 @@ pci_vfio_get_group_fd(int iommu_group_no)
static int
pci_vfio_get_group_no(const char *pci_addr, int *iommu_group_no)
{
- char linkname[PATH_MAX];
- char filename[PATH_MAX];
- char *tok[16], *group_tok, *end;
- int ret;
-
- memset(linkname, 0, sizeof(linkname));
- memset(filename, 0, sizeof(filename));
-
- /* try to find out IOMMU group for this device */
- snprintf(linkname, sizeof(linkname),
- "%s/%s/iommu_group", pci_get_sysfs_path(), pci_addr);
-
- ret = readlink(linkname, filename, sizeof(filename));
-
- /* if the link doesn't exist, no VFIO for us */
- if (ret < 0)
- return 0;
-
- ret = rte_strsplit(filename, sizeof(filename),
- tok, RTE_DIM(tok), '/');
-
- if (ret <= 0) {
- RTE_LOG(ERR, EAL, " %s cannot get IOMMU group\n", pci_addr);
- return -1;
- }
-
- /* IOMMU group is always the last token */
- errno = 0;
- group_tok = tok[ret - 1];
- end = group_tok;
- *iommu_group_no = strtol(group_tok, &end, 10);
- if ((end != group_tok && *end != '\0') || errno != 0) {
- RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", pci_addr);
- return -1;
- }
-
- return 1;
+ return vfio_get_group_no(pci_get_sysfs_path(), pci_addr, iommu_group_no);
}
static void
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index 5660ddd..2bf810e 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -165,6 +165,49 @@ vfio_get_container_fd(void)
}
int
+vfio_get_group_no(const char *sysfs_base,
+ const char *dev_addr, int *iommu_group_no)
+{
+ char linkname[PATH_MAX];
+ char filename[PATH_MAX];
+ char *tok[16], *group_tok, *end;
+ int ret;
+
+ memset(linkname, 0, sizeof(linkname));
+ memset(filename, 0, sizeof(filename));
+
+ /* try to find out IOMMU group for this device */
+ snprintf(linkname, sizeof(linkname),
+ "%s/%s/iommu_group", sysfs_base, dev_addr);
+
+ ret = readlink(linkname, filename, sizeof(filename));
+
+ /* if the link doesn't exist, no VFIO for us */
+ if (ret < 0)
+ return 0;
+
+ ret = rte_strsplit(filename, sizeof(filename),
+ tok, RTE_DIM(tok), '/');
+
+ if (ret <= 0) {
+ RTE_LOG(ERR, EAL, " %s cannot get IOMMU group\n", dev_addr);
+ return -1;
+ }
+
+ /* IOMMU group is always the last token */
+ errno = 0;
+ group_tok = tok[ret - 1];
+ end = group_tok;
+ *iommu_group_no = strtol(group_tok, &end, 10);
+ if ((end != group_tok && *end != '\0') || errno != 0) {
+ RTE_LOG(ERR, EAL, " %s error parsing IOMMU number!\n", dev_addr);
+ return -1;
+ }
+
+ return 1;
+}
+
+int
vfio_type1_dma_map(int vfio_container_fd)
{
const struct rte_memseg *ms = rte_eal_get_physmem_layout();
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 0fb05a4..619cd6b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -119,6 +119,13 @@ vfio_has_supported_extensions(int vfio_container_fd);
int
vfio_get_container_fd(void);
+/* parse IOMMU group number for a device
+ * returns 1 on success, -1 for errors, 0 for non-existent group
+ */
+int
+vfio_get_group_no(const char *sysfs_base,
+ const char *dev_addr, int *iommu_group_no);
+
#define SOCKET_REQ_CONTAINER 0x100
#define SOCKET_REQ_GROUP 0x200
#define SOCKET_OK 0x0
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 10/16] vfio: extract setup logic out of pci_vfio_map_resource
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (8 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 09/16] vfio: generalize pci_vfio_get_group_no Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 11/16] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
` (7 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The setup logic access the global vfio_cfg variable that will be moved in the
following commits. We need to separate all accesses to this variable to a
general code.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 85 +++++++++++++++++-------------
1 file changed, 49 insertions(+), 36 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index c2ff465..2792c23 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -411,37 +411,22 @@ clear_current_group(void)
vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = -1;
}
-
-/*
- * map the PCI resources of a PCI device in virtual memory (VFIO version).
- * primary and secondary processes follow almost exactly the same path
+/**
+ * Setup vfio_cfg for the device indentified by its address. It discovers
+ * the configured I/O MMU groups or sets a new one for the device. If a new
+ * groups is assigned, the DMA mapping is performed.
+ * Returns 0 on success, a negative value on failure and a positive value in
+ * case the given device cannot be managed this way.
*/
-int
-pci_vfio_map_resource(struct rte_pci_device *dev)
+static int pci_vfio_setup_device(const char *pci_addr, int *vfio_dev_fd,
+ struct vfio_device_info *device_info)
{
struct vfio_group_status group_status = {
.argsz = sizeof(group_status)
};
- struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
- int vfio_group_fd, vfio_dev_fd;
+ int vfio_group_fd;
int iommu_group_no;
- char pci_addr[PATH_MAX] = {0};
- struct rte_pci_addr *loc = &dev->addr;
- int i, ret, msix_bar;
- struct mapped_pci_resource *vfio_res = NULL;
- struct mapped_pci_res_list *vfio_res_list = RTE_TAILQ_CAST(rte_vfio_tailq.head, mapped_pci_res_list);
-
- struct pci_map *maps;
- uint32_t msix_table_offset = 0;
- uint32_t msix_table_size = 0;
- uint32_t ioport_bar;
-
- dev->intr_handle.fd = -1;
- dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
- /* store PCI address string */
- snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
- loc->domain, loc->bus, loc->devid, loc->function);
+ int ret;
/* get group number */
ret = pci_vfio_get_group_no(pci_addr, &iommu_group_no);
@@ -476,8 +461,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
}
/*
- * at this point, we know at least one port on this device is bound to VFIO,
- * so we can proceed to try and set this particular port up
+ * 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 the group is viable */
@@ -495,11 +480,6 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
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)) {
@@ -546,8 +526,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
}
/* get a file descriptor for the device */
- vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, pci_addr);
- if (vfio_dev_fd < 0) {
+ *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, pci_addr);
+ if (*vfio_dev_fd < 0) {
/* if we cannot get a device fd, this simply means that this
* particular port is not bound to VFIO
*/
@@ -557,14 +537,47 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
}
/* test and setup the device */
- ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_INFO, &device_info);
+ ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
if (ret) {
RTE_LOG(ERR, EAL, " %s cannot get device info, "
"error %i (%s)\n", pci_addr, errno, strerror(errno));
- close(vfio_dev_fd);
+ close(*vfio_dev_fd);
return -1;
}
+ return 0;
+}
+
+/*
+ * map the PCI resources of a PCI device in virtual memory (VFIO version).
+ * primary and secondary processes follow almost exactly the same path
+ */
+int
+pci_vfio_map_resource(struct rte_pci_device *dev)
+{
+ struct vfio_device_info device_info = { .argsz = sizeof(device_info) };
+ char pci_addr[PATH_MAX] = {0};
+ int vfio_dev_fd;
+ struct rte_pci_addr *loc = &dev->addr;
+ int i, ret, msix_bar;
+ struct mapped_pci_resource *vfio_res = NULL;
+ struct mapped_pci_res_list *vfio_res_list = RTE_TAILQ_CAST(rte_vfio_tailq.head, mapped_pci_res_list);
+
+ struct pci_map *maps;
+ uint32_t msix_table_offset = 0;
+ uint32_t msix_table_size = 0;
+ uint32_t ioport_bar;
+
+ dev->intr_handle.fd = -1;
+ dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+ /* store PCI address string */
+ snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
+ loc->domain, loc->bus, loc->devid, loc->function);
+
+ if ((ret = pci_vfio_setup_device(pci_addr, &vfio_dev_fd, &device_info)))
+ return ret;
+
/* get MSI-X BAR, if any (we have to know where it is because we can't
* easily mmap it when using VFIO) */
msix_bar = -1;
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 11/16] vfio: move global vfio_cfg to eal_vfio.c
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (9 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 10/16] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
` (6 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The vfio_cfg is a module-global variable and so together with this
variable, it is necessary to move functions:
* pci_vfio_get_group_fd
- renamed to vfio_get_group_fd
- pci_* version removed (no other call in EAL)
* pci_vfio_setup_device
- renamed as vfio_setup_device
* pci_vfio_enable
- renamed as vfio_enable
- generalized to check for a specific vfio driver presence
- pci_* specialization preserved as a wrapper
* pci_vfio_is_enabled
- renamed as vfio_is_enabled
- generalized to check for a specific vfio driver presence
to preserve the semantics of VFIO + PCI
- pci_* specialization preserved as a wrapper
* clear_current_group
- private function, just moved
To stop GCC complaining about "defined but not used", the private
function pci_vfio_get_group_no has been removed entirely.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 1 -
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 297 +--------------------
lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c | 2 +-
lib/librte_eal/linuxapp/eal/eal_vfio.c | 287 ++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_vfio.h | 17 ++
5 files changed, 309 insertions(+), 295 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d34212b..d00bf7d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -94,7 +94,6 @@ int pci_vfio_ioport_unmap(struct rte_pci_ioport *p);
/* map VFIO resource prototype */
int pci_vfio_map_resource(struct rte_pci_device *dev);
-int pci_vfio_get_group_fd(int iommu_group_fd);
#endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 2792c23..46cd683 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -69,9 +69,6 @@ static struct rte_tailq_elem rte_vfio_tailq = {
};
EAL_REGISTER_TAILQ(rte_vfio_tailq)
-/* per-process VFIO config */
-static struct vfio_config vfio_cfg;
-
int
pci_vfio_read_config(const struct rte_intr_handle *intr_handle,
void *buf, size_t len, off_t offs)
@@ -299,255 +296,6 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd)
return -1;
}
-/* open group fd or get an existing one */
-int
-pci_vfio_get_group_fd(int iommu_group_no)
-{
- int i;
- int vfio_group_fd;
- char filename[PATH_MAX];
-
- /* check if we already have the group descriptor open */
- for (i = 0; i < vfio_cfg.vfio_group_idx; i++)
- if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no)
- return vfio_cfg.vfio_groups[i].fd;
-
- /* if primary, try to open the group */
- if (internal_config.process_type == RTE_PROC_PRIMARY) {
- /* try regular group format */
- snprintf(filename, sizeof(filename),
- VFIO_GROUP_FMT, iommu_group_no);
- vfio_group_fd = open(filename, O_RDWR);
- if (vfio_group_fd < 0) {
- /* if file not found, it's not an error */
- if (errno != ENOENT) {
- RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
- strerror(errno));
- return -1;
- }
-
- /* special case: try no-IOMMU path as well */
- snprintf(filename, sizeof(filename),
- VFIO_NOIOMMU_GROUP_FMT, iommu_group_no);
- vfio_group_fd = open(filename, O_RDWR);
- if (vfio_group_fd < 0) {
- if (errno != ENOENT) {
- RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
- strerror(errno));
- return -1;
- }
- return 0;
- }
- /* noiommu group found */
- }
-
- /* if the fd is valid, create a new group for it */
- if (vfio_cfg.vfio_group_idx == VFIO_MAX_GROUPS) {
- RTE_LOG(ERR, EAL, "Maximum number of VFIO groups reached!\n");
- close(vfio_group_fd);
- return -1;
- }
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
- return vfio_group_fd;
- }
- /* if we're in a secondary process, request group fd from the primary
- * process via our socket
- */
- else {
- int socket_fd, ret;
-
- socket_fd = vfio_mp_sync_connect_to_primary();
-
- if (socket_fd < 0) {
- RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
- return -1;
- }
- if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_GROUP) < 0) {
- RTE_LOG(ERR, EAL, " cannot request container fd!\n");
- close(socket_fd);
- return -1;
- }
- if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) {
- RTE_LOG(ERR, EAL, " cannot send group number!\n");
- close(socket_fd);
- return -1;
- }
- ret = vfio_mp_sync_receive_request(socket_fd);
- switch (ret) {
- case SOCKET_NO_FD:
- close(socket_fd);
- return 0;
- case SOCKET_OK:
- vfio_group_fd = vfio_mp_sync_receive_fd(socket_fd);
- /* if we got the fd, return it */
- if (vfio_group_fd > 0) {
- close(socket_fd);
- return vfio_group_fd;
- }
- /* fall-through on error */
- default:
- RTE_LOG(ERR, EAL, " cannot get container fd!\n");
- close(socket_fd);
- return -1;
- }
- }
- return -1;
-}
-
-/* parse IOMMU group number for a PCI device
- * returns 1 on success, -1 for errors, 0 for non-existent group
- */
-static int
-pci_vfio_get_group_no(const char *pci_addr, int *iommu_group_no)
-{
- return vfio_get_group_no(pci_get_sysfs_path(), pci_addr, iommu_group_no);
-}
-
-static void
-clear_current_group(void)
-{
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = 0;
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = -1;
-}
-
-/**
- * Setup vfio_cfg for the device indentified by its address. It discovers
- * the configured I/O MMU groups or sets a new one for the device. If a new
- * groups is assigned, the DMA mapping is performed.
- * Returns 0 on success, a negative value on failure and a positive value in
- * case the given device cannot be managed this way.
- */
-static int pci_vfio_setup_device(const char *pci_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;
- int iommu_group_no;
- int ret;
-
- /* get group number */
- ret = pci_vfio_get_group_no(pci_addr, &iommu_group_no);
- if (ret == 0) {
- RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
- pci_addr);
- return 1;
- }
-
- /* if negative, something failed */
- if (ret < 0)
- return -1;
-
- /* get the actual group fd */
- vfio_group_fd = pci_vfio_get_group_fd(iommu_group_no);
- if (vfio_group_fd < 0)
- return -1;
-
- /* store group fd */
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
- vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
-
- /* 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",
- pci_addr);
- /* we store 0 as group fd to distinguish between existing but
- * unbound VFIO groups, and groups that don't exist at all.
- */
- vfio_cfg.vfio_group_idx++;
- 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 the group is viable */
- ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
- if (ret) {
- RTE_LOG(ERR, EAL, " %s cannot get group status, "
- "error %i (%s)\n", pci_addr, errno, strerror(errno));
- close(vfio_group_fd);
- clear_current_group();
- return -1;
- } else if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
- RTE_LOG(ERR, EAL, " %s VFIO group is not viable!\n", pci_addr);
- close(vfio_group_fd);
- clear_current_group();
- return -1;
- }
-
- /* 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_cfg.vfio_container_fd);
- if (ret) {
- RTE_LOG(ERR, EAL, " %s cannot add VFIO group to container, "
- "error %i (%s)\n", pci_addr, errno, strerror(errno));
- close(vfio_group_fd);
- clear_current_group();
- return -1;
- }
- /*
- * at this point we know that this group has been successfully
- * initialized, so we increment vfio_group_idx to indicate that we can
- * add new groups.
- */
- vfio_cfg.vfio_group_idx++;
- }
-
- /*
- * pick an IOMMU type and set up DMA mappings for container
- *
- * needs to be done only once, only when at least one group is assigned to
- * a container and only in primary process
- */
- if (internal_config.process_type == RTE_PROC_PRIMARY &&
- vfio_cfg.vfio_container_has_dma == 0) {
- /* select an IOMMU type which we will be using */
- const struct vfio_iommu_type *t =
- vfio_set_iommu_type(vfio_cfg.vfio_container_fd);
- if (!t) {
- RTE_LOG(ERR, EAL, " %s failed to select IOMMU type\n", pci_addr);
- return -1;
- }
- ret = t->dma_map_func(vfio_cfg.vfio_container_fd);
- if (ret) {
- RTE_LOG(ERR, EAL, " %s DMA remapping failed, "
- "error %i (%s)\n", pci_addr, errno, strerror(errno));
- return -1;
- }
- vfio_cfg.vfio_container_has_dma = 1;
- }
-
- /* get a file descriptor for the device */
- *vfio_dev_fd = ioctl(vfio_group_fd, VFIO_GROUP_GET_DEVICE_FD, pci_addr);
- if (*vfio_dev_fd < 0) {
- /* if we cannot get a device fd, this simply means that this
- * particular port is not bound to VFIO
- */
- RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
- pci_addr);
- return 1;
- }
-
- /* test and setup the device */
- ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
- if (ret) {
- RTE_LOG(ERR, EAL, " %s cannot get device info, "
- "error %i (%s)\n", pci_addr, errno, strerror(errno));
- close(*vfio_dev_fd);
- return -1;
- }
-
- return 0;
-}
-
/*
* map the PCI resources of a PCI device in virtual memory (VFIO version).
* primary and secondary processes follow almost exactly the same path
@@ -575,7 +323,8 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT,
loc->domain, loc->bus, loc->devid, loc->function);
- if ((ret = pci_vfio_setup_device(pci_addr, &vfio_dev_fd, &device_info)))
+ if ((ret = vfio_setup_device(pci_get_sysfs_path(), pci_addr,
+ &vfio_dev_fd, &device_info)))
return ret;
/* get MSI-X BAR, if any (we have to know where it is because we can't
@@ -834,50 +583,12 @@ pci_vfio_ioport_unmap(struct rte_pci_ioport *p)
int
pci_vfio_enable(void)
{
- /* initialize group list */
- int i;
- int vfio_available;
-
- for (i = 0; i < VFIO_MAX_GROUPS; i++) {
- vfio_cfg.vfio_groups[i].fd = -1;
- vfio_cfg.vfio_groups[i].group_no = -1;
- }
-
- /* inform the user that we are probing for VFIO */
- RTE_LOG(INFO, EAL, "Probing VFIO support...\n");
-
- /* check if vfio-pci module is loaded */
- vfio_available = rte_eal_check_module("vfio_pci");
-
- /* return error directly */
- if (vfio_available == -1) {
- RTE_LOG(INFO, EAL, "Could not get loaded module details!\n");
- return -1;
- }
-
- /* return 0 if VFIO modules not loaded */
- if (vfio_available == 0) {
- RTE_LOG(DEBUG, EAL, "VFIO modules not loaded, "
- "skipping VFIO support...\n");
- return 0;
- }
-
- vfio_cfg.vfio_container_fd = vfio_get_container_fd();
-
- /* check if we have VFIO driver enabled */
- if (vfio_cfg.vfio_container_fd != -1) {
- RTE_LOG(NOTICE, EAL, "VFIO support initialized\n");
- vfio_cfg.vfio_enabled = 1;
- } else {
- RTE_LOG(NOTICE, EAL, "VFIO support could not be initialized\n");
- }
-
- return 0;
+ return vfio_enable("vfio_pci");
}
int
pci_vfio_is_enabled(void)
{
- return vfio_cfg.vfio_enabled;
+ return vfio_is_enabled("vfio_pci");
}
#endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
index a759f02..b3f4c51 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
@@ -310,7 +310,7 @@ pci_vfio_mp_sync_thread(void __rte_unused * arg)
continue;
}
- fd = pci_vfio_get_group_fd(vfio_group_no);
+ fd = vfio_get_group_fd(vfio_group_no);
if (fd < 0)
vfio_mp_sync_send_request(conn_sock, SOCKET_ERR);
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index 2bf810e..d11f723 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -42,9 +42,296 @@
#include "eal_filesystem.h"
#include "eal_vfio.h"
+#include "eal_private.h"
#ifdef VFIO_PRESENT
+/* per-process VFIO config */
+static struct vfio_config vfio_cfg;
+
+int
+vfio_get_group_fd(int iommu_group_no)
+{
+ int i;
+ int vfio_group_fd;
+ char filename[PATH_MAX];
+
+ /* check if we already have the group descriptor open */
+ for (i = 0; i < vfio_cfg.vfio_group_idx; i++)
+ if (vfio_cfg.vfio_groups[i].group_no == iommu_group_no)
+ return vfio_cfg.vfio_groups[i].fd;
+
+ /* if primary, try to open the group */
+ if (internal_config.process_type == RTE_PROC_PRIMARY) {
+ /* try regular group format */
+ snprintf(filename, sizeof(filename),
+ VFIO_GROUP_FMT, iommu_group_no);
+ vfio_group_fd = open(filename, O_RDWR);
+ if (vfio_group_fd < 0) {
+ /* if file not found, it's not an error */
+ if (errno != ENOENT) {
+ RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
+ strerror(errno));
+ return -1;
+ }
+
+ /* special case: try no-IOMMU path as well */
+ snprintf(filename, sizeof(filename),
+ VFIO_NOIOMMU_GROUP_FMT, iommu_group_no);
+ vfio_group_fd = open(filename, O_RDWR);
+ if (vfio_group_fd < 0) {
+ if (errno != ENOENT) {
+ RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename,
+ strerror(errno));
+ return -1;
+ }
+ return 0;
+ }
+ /* noiommu group found */
+ }
+
+ /* if the fd is valid, create a new group for it */
+ if (vfio_cfg.vfio_group_idx == VFIO_MAX_GROUPS) {
+ RTE_LOG(ERR, EAL, "Maximum number of VFIO groups reached!\n");
+ close(vfio_group_fd);
+ return -1;
+ }
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
+ return vfio_group_fd;
+ }
+ /* if we're in a secondary process, request group fd from the primary
+ * process via our socket
+ */
+ else {
+ int socket_fd, ret;
+
+ socket_fd = vfio_mp_sync_connect_to_primary();
+
+ if (socket_fd < 0) {
+ RTE_LOG(ERR, EAL, " cannot connect to primary process!\n");
+ return -1;
+ }
+ if (vfio_mp_sync_send_request(socket_fd, SOCKET_REQ_GROUP) < 0) {
+ RTE_LOG(ERR, EAL, " cannot request container fd!\n");
+ close(socket_fd);
+ return -1;
+ }
+ if (vfio_mp_sync_send_request(socket_fd, iommu_group_no) < 0) {
+ RTE_LOG(ERR, EAL, " cannot send group number!\n");
+ close(socket_fd);
+ return -1;
+ }
+ ret = vfio_mp_sync_receive_request(socket_fd);
+ switch (ret) {
+ case SOCKET_NO_FD:
+ close(socket_fd);
+ return 0;
+ case SOCKET_OK:
+ vfio_group_fd = vfio_mp_sync_receive_fd(socket_fd);
+ /* if we got the fd, return it */
+ if (vfio_group_fd > 0) {
+ close(socket_fd);
+ return vfio_group_fd;
+ }
+ /* fall-through on error */
+ default:
+ RTE_LOG(ERR, EAL, " cannot get container fd!\n");
+ close(socket_fd);
+ return -1;
+ }
+ }
+ return -1;
+}
+
+static void
+clear_current_group(void)
+{
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = 0;
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = -1;
+}
+
+int 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;
+ int iommu_group_no;
+ int ret;
+
+ /* get group number */
+ ret = vfio_get_group_no(sysfs_base, dev_addr, &iommu_group_no);
+ if (ret == 0) {
+ RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
+ dev_addr);
+ return 1;
+ }
+
+ /* if negative, something failed */
+ if (ret < 0)
+ return -1;
+
+ /* get the actual group fd */
+ vfio_group_fd = vfio_get_group_fd(iommu_group_no);
+ if (vfio_group_fd < 0)
+ return -1;
+
+ /* store group fd */
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].group_no = iommu_group_no;
+ vfio_cfg.vfio_groups[vfio_cfg.vfio_group_idx].fd = vfio_group_fd;
+
+ /* 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);
+ /* we store 0 as group fd to distinguish between existing but
+ * unbound VFIO groups, and groups that don't exist at all.
+ */
+ vfio_cfg.vfio_group_idx++;
+ 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 the group is viable */
+ ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status);
+ if (ret) {
+ RTE_LOG(ERR, EAL, " %s cannot get group status, "
+ "error %i (%s)\n", dev_addr, errno, strerror(errno));
+ close(vfio_group_fd);
+ clear_current_group();
+ return -1;
+ } else if (!(group_status.flags & VFIO_GROUP_FLAGS_VIABLE)) {
+ RTE_LOG(ERR, EAL, " %s VFIO group is not viable!\n", dev_addr);
+ close(vfio_group_fd);
+ clear_current_group();
+ return -1;
+ }
+
+ /* 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_cfg.vfio_container_fd);
+ if (ret) {
+ RTE_LOG(ERR, EAL, " %s cannot add VFIO group to container, "
+ "error %i (%s)\n", dev_addr, errno, strerror(errno));
+ close(vfio_group_fd);
+ clear_current_group();
+ return -1;
+ }
+ /*
+ * at this point we know that this group has been successfully
+ * initialized, so we increment vfio_group_idx to indicate that we can
+ * add new groups.
+ */
+ vfio_cfg.vfio_group_idx++;
+ }
+
+ /*
+ * pick an IOMMU type and set up DMA mappings for container
+ *
+ * needs to be done only once, only when at least one group is assigned to
+ * a container and only in primary process
+ */
+ if (internal_config.process_type == RTE_PROC_PRIMARY &&
+ vfio_cfg.vfio_container_has_dma == 0) {
+ /* select an IOMMU type which we will be using */
+ const struct vfio_iommu_type *t =
+ vfio_set_iommu_type(vfio_cfg.vfio_container_fd);
+ if (!t) {
+ RTE_LOG(ERR, EAL, " %s failed to select IOMMU type\n", dev_addr);
+ return -1;
+ }
+ ret = t->dma_map_func(vfio_cfg.vfio_container_fd);
+ if (ret) {
+ RTE_LOG(ERR, EAL, " %s DMA remapping failed, "
+ "error %i (%s)\n", dev_addr, errno, strerror(errno));
+ return -1;
+ }
+ vfio_cfg.vfio_container_has_dma = 1;
+ }
+
+ /* 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 simply means that this
+ * particular port is not bound to VFIO
+ */
+ RTE_LOG(WARNING, EAL, " %s not managed by VFIO driver, skipping\n",
+ dev_addr);
+ return 1;
+ }
+
+ /* test and setup the device */
+ ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info);
+ if (ret) {
+ RTE_LOG(ERR, EAL, " %s cannot get device info, "
+ "error %i (%s)\n", dev_addr, errno, strerror(errno));
+ close(*vfio_dev_fd);
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+vfio_enable(const char *modname)
+{
+ /* initialize group list */
+ int i;
+ int vfio_available;
+
+ for (i = 0; i < VFIO_MAX_GROUPS; i++) {
+ vfio_cfg.vfio_groups[i].fd = -1;
+ vfio_cfg.vfio_groups[i].group_no = -1;
+ }
+
+ /* inform the user that we are probing for VFIO */
+ RTE_LOG(INFO, EAL, "Probing VFIO support...\n");
+
+ /* check if vfio-pci module is loaded */
+ vfio_available = rte_eal_check_module(modname);
+
+ /* return error directly */
+ if (vfio_available == -1) {
+ RTE_LOG(INFO, EAL, "Could not get loaded module details!\n");
+ return -1;
+ }
+
+ /* return 0 if VFIO modules not loaded */
+ if (vfio_available == 0) {
+ RTE_LOG(DEBUG, EAL, "VFIO modules not loaded, "
+ "skipping VFIO support...\n");
+ return 0;
+ }
+
+ vfio_cfg.vfio_container_fd = vfio_get_container_fd();
+
+ /* check if we have VFIO driver enabled */
+ if (vfio_cfg.vfio_container_fd != -1) {
+ RTE_LOG(NOTICE, EAL, "VFIO support initialized\n");
+ vfio_cfg.vfio_enabled = 1;
+ } else {
+ RTE_LOG(NOTICE, EAL, "VFIO support could not be initialized\n");
+ }
+
+ return 0;
+}
+
+int
+vfio_is_enabled(const char *modname)
+{
+ const int mod_available = rte_eal_check_module(modname);
+ return vfio_cfg.vfio_enabled && mod_available;
+}
+
const struct vfio_iommu_type *
vfio_set_iommu_type(int vfio_container_fd) {
unsigned idx;
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 619cd6b..d4532a5 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -126,6 +126,23 @@ int
vfio_get_group_no(const char *sysfs_base,
const char *dev_addr, int *iommu_group_no);
+/* open group fd or get an existing one */
+int
+vfio_get_group_fd(int iommu_group_no);
+
+/**
+ * Setup vfio_cfg for the device indentified by its address. It discovers
+ * the configured I/O MMU groups or sets a new one for the device. If a new
+ * groups is assigned, the DMA mapping is performed.
+ * Returns 0 on success, a negative value on failure and a positive value in
+ * case the given device cannot be managed this way.
+ */
+int vfio_setup_device(const char *sysfs_base, const char *dev_addr,
+ int *vfio_dev_fd, struct vfio_device_info *device_info);
+
+int vfio_enable(const char *modname);
+int vfio_is_enabled(const char *modname);
+
#define SOCKET_REQ_CONTAINER 0x100
#define SOCKET_REQ_GROUP 0x200
#define SOCKET_OK 0x0
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 12/16] vfio: fix typo in doc for vfio_setup_device
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (10 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 11/16] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 13/16] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
` (5 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
Suggested-by: Anatoly Burakov <anatoly.burakov@intel.com>
Acked-by: John McNamara <john.mcnamara@intel.com>
---
lib/librte_eal/linuxapp/eal/eal_vfio.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index d4532a5..4ca0fa3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -131,7 +131,7 @@ int
vfio_get_group_fd(int iommu_group_no);
/**
- * Setup vfio_cfg for the device indentified by its address. It discovers
+ * Setup vfio_cfg for the device identified by its address. It discovers
* the configured I/O MMU groups or sets a new one for the device. If a new
* groups is assigned, the DMA mapping is performed.
* Returns 0 on success, a negative value on failure and a positive value in
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 13/16] vfio: make vfio_*_dma_map and iommu_types private
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (11 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
` (4 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
There is no more reason to expose those definitions as nobody uses them.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal_vfio.c | 15 +++++++++++++--
lib/librte_eal/linuxapp/eal/eal_vfio.h | 11 -----------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.c b/lib/librte_eal/linuxapp/eal/eal_vfio.c
index d11f723..fcb0ab3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -49,6 +49,17 @@
/* per-process VFIO config */
static struct vfio_config vfio_cfg;
+static int vfio_type1_dma_map(int);
+static int vfio_noiommu_dma_map(int);
+
+/* IOMMU types we support */
+static const struct vfio_iommu_type iommu_types[] = {
+ /* x86 IOMMU, otherwise known as type 1 */
+ { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map},
+ /* IOMMU-less mode */
+ { RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map},
+};
+
int
vfio_get_group_fd(int iommu_group_no)
{
@@ -494,7 +505,7 @@ vfio_get_group_no(const char *sysfs_base,
return 1;
}
-int
+static int
vfio_type1_dma_map(int vfio_container_fd)
{
const struct rte_memseg *ms = rte_eal_get_physmem_layout();
@@ -526,7 +537,7 @@ vfio_type1_dma_map(int vfio_container_fd)
return 0;
}
-int
+static int
vfio_noiommu_dma_map(int __rte_unused vfio_container_fd)
{
/* No-IOMMU mode does not need DMA mapping */
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 4ca0fa3..f1a5427 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -149,17 +149,6 @@ int vfio_is_enabled(const char *modname);
#define SOCKET_NO_FD 0x1
#define SOCKET_ERR 0xFF
-int vfio_type1_dma_map(int);
-int vfio_noiommu_dma_map(int);
-
-/* IOMMU types we support */
-static const struct vfio_iommu_type iommu_types[] = {
- /* x86 IOMMU, otherwise known as type 1 */
- { RTE_VFIO_TYPE1, "Type 1", &vfio_type1_dma_map},
- /* IOMMU-less mode */
- { RTE_VFIO_NOIOMMU, "No-IOMMU", &vfio_noiommu_dma_map},
-};
-
#define VFIO_PRESENT
#endif /* kernel version */
#endif /* RTE_EAL_VFIO */
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (12 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 13/16] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 15/16] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
` (3 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The module eal_pci_vfio_mp_sync is quite generic so it shouldn't contain the
"pci" string in its name. The internal functions don't need the pci_* prefix.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/Makefile | 4 ++--
lib/librte_eal/linuxapp/eal/eal_pci.c | 2 +-
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 1 -
lib/librte_eal/linuxapp/eal/eal_vfio.h | 2 ++
.../linuxapp/eal/{eal_pci_vfio_mp_sync.c => eal_vfio_mp_sync.c} | 8 ++++----
5 files changed, 9 insertions(+), 8 deletions(-)
rename lib/librte_eal/linuxapp/eal/{eal_pci_vfio_mp_sync.c => eal_vfio_mp_sync.c} (98%)
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 517554f..1a97693 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -67,10 +67,10 @@ endif
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_thread.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_log.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vfio.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_vfio_mp_sync.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci_uio.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci_vfio.c
-SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_pci_vfio_mp_sync.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_debug.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_lcore.c
SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_timer.c
@@ -111,7 +111,7 @@ CFLAGS_eal_common_cpuflags.o := $(CPUFLAGS_LIST)
CFLAGS_eal.o := -D_GNU_SOURCE
CFLAGS_eal_interrupts.o := -D_GNU_SOURCE
-CFLAGS_eal_pci_vfio_mp_sync.o := -D_GNU_SOURCE
+CFLAGS_eal_vfio_mp_sync.o := -D_GNU_SOURCE
CFLAGS_eal_timer.o := -D_GNU_SOURCE
CFLAGS_eal_lcore.o := -D_GNU_SOURCE
CFLAGS_eal_thread.o := -D_GNU_SOURCE
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index f9c3efd..d0a6481 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -766,7 +766,7 @@ rte_eal_pci_init(void)
* VFIO container.
*/
if (internal_config.process_type == RTE_PROC_PRIMARY &&
- pci_vfio_mp_sync_setup() < 0)
+ vfio_mp_sync_setup() < 0)
return -1;
}
#endif
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d00bf7d..62c337f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -76,7 +76,6 @@ int pci_uio_ioport_unmap(struct rte_pci_ioport *p);
int pci_vfio_enable(void);
int pci_vfio_is_enabled(void);
-int pci_vfio_mp_sync_setup(void);
/* access config space */
int pci_vfio_read_config(const struct rte_intr_handle *intr_handle,
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index f1a5427..884884c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -149,6 +149,8 @@ int vfio_is_enabled(const char *modname);
#define SOCKET_NO_FD 0x1
#define SOCKET_ERR 0xFF
+int vfio_mp_sync_setup(void);
+
#define VFIO_PRESENT
#endif /* kernel version */
#endif /* RTE_EAL_VFIO */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c
similarity index 98%
rename from lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
rename to lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c
index b3f4c51..00cf919 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio_mp_sync.c
@@ -265,7 +265,7 @@ vfio_mp_sync_connect_to_primary(void)
* socket listening thread for primary process
*/
static __attribute__((noreturn)) void *
-pci_vfio_mp_sync_thread(void __rte_unused * arg)
+vfio_mp_sync_thread(void __rte_unused * arg)
{
int ret, fd, vfio_group_no;
@@ -376,7 +376,7 @@ vfio_mp_sync_socket_setup(void)
* set up a local socket and tell it to listen for incoming connections
*/
int
-pci_vfio_mp_sync_setup(void)
+vfio_mp_sync_setup(void)
{
int ret;
char thread_name[RTE_MAX_THREAD_NAME_LEN];
@@ -387,7 +387,7 @@ pci_vfio_mp_sync_setup(void)
}
ret = pthread_create(&socket_thread, NULL,
- pci_vfio_mp_sync_thread, NULL);
+ vfio_mp_sync_thread, NULL);
if (ret) {
RTE_LOG(ERR, EAL,
"Failed to create thread for communication with secondary processes!\n");
@@ -396,7 +396,7 @@ pci_vfio_mp_sync_setup(void)
}
/* Set thread_name for aid in debugging. */
- snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "pci-vfio-sync");
+ snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN, "vfio-sync");
ret = rte_thread_setname(socket_thread, thread_name);
if (ret)
RTE_LOG(DEBUG, EAL,
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 15/16] vfio: initialize vfio out of the PCI subsystem
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (13 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 16/16] vfio: change VFIO init to be extendable Jan Viktorin
` (2 subsequent siblings)
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
The VFIO does not depend on the PCI anymore so it can be initialized out of
the PCI subsystem.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal.c | 31 ++++++++++++++++++++++++++++++
lib/librte_eal/linuxapp/eal/eal_pci.c | 17 +---------------
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 3 ---
lib/librte_eal/linuxapp/eal/eal_vfio.h | 3 +++
4 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 543ef86..606b777 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -82,6 +82,7 @@
#include "eal_filesystem.h"
#include "eal_hugepages.h"
#include "eal_options.h"
+#include "eal_vfio.h"
#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
@@ -701,6 +702,31 @@ rte_eal_iopl_init(void)
return 0;
}
+#ifdef VFIO_PRESENT
+static int rte_eal_vfio_setup(void)
+{
+ if (internal_config.no_pci)
+ return 0;
+
+ pci_vfio_enable();
+
+ if (pci_vfio_is_enabled()) {
+
+ /* if we are primary process, create a thread to communicate with
+ * secondary processes. the thread will use a socket to wait for
+ * requests from secondary process to send open file descriptors,
+ * because VFIO does not allow multiple open descriptors on a group or
+ * VFIO container.
+ */
+ if (internal_config.process_type == RTE_PROC_PRIMARY &&
+ vfio_mp_sync_setup() < 0)
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
/* Launch threads, called at application init(). */
int
rte_eal_init(int argc, char **argv)
@@ -764,6 +790,11 @@ rte_eal_init(int argc, char **argv)
if (rte_eal_pci_init() < 0)
rte_panic("Cannot init PCI\n");
+#ifdef VFIO_PRESENT
+ if (rte_eal_vfio_setup() < 0)
+ rte_panic("Cannot init VFIO\n");
+#endif
+
#ifdef RTE_LIBRTE_IVSHMEM
if (rte_eal_ivshmem_init() < 0)
rte_panic("Cannot init IVSHMEM\n");
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index d0a6481..cd9de7c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -754,21 +754,6 @@ rte_eal_pci_init(void)
RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
return -1;
}
-#ifdef VFIO_PRESENT
- pci_vfio_enable();
-
- if (pci_vfio_is_enabled()) {
-
- /* if we are primary process, create a thread to communicate with
- * secondary processes. the thread will use a socket to wait for
- * requests from secondary process to send open file descriptors,
- * because VFIO does not allow multiple open descriptors on a group or
- * VFIO container.
- */
- if (internal_config.process_type == RTE_PROC_PRIMARY &&
- vfio_mp_sync_setup() < 0)
- return -1;
- }
-#endif
+
return 0;
}
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 62c337f..6a960d1 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -74,9 +74,6 @@ int pci_uio_ioport_unmap(struct rte_pci_ioport *p);
#ifdef VFIO_PRESENT
-int pci_vfio_enable(void);
-int pci_vfio_is_enabled(void);
-
/* access config space */
int pci_vfio_read_config(const struct rte_intr_handle *intr_handle,
void *buf, size_t len, off_t offs);
diff --git a/lib/librte_eal/linuxapp/eal/eal_vfio.h b/lib/librte_eal/linuxapp/eal/eal_vfio.h
index 884884c..43960eb 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.h
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.h
@@ -143,6 +143,9 @@ int vfio_setup_device(const char *sysfs_base, const char *dev_addr,
int vfio_enable(const char *modname);
int vfio_is_enabled(const char *modname);
+int pci_vfio_enable(void);
+int pci_vfio_is_enabled(void);
+
#define SOCKET_REQ_CONTAINER 0x100
#define SOCKET_REQ_GROUP 0x200
#define SOCKET_OK 0x0
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [dpdk-dev] [PATCH v3 16/16] vfio: change VFIO init to be extendable
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (14 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 15/16] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
@ 2016-07-04 15:16 ` Jan Viktorin
2016-07-04 15:26 ` [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Burakov, Anatoly
2016-07-10 18:17 ` Thomas Monjalon
17 siblings, 0 replies; 20+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:16 UTC (permalink / raw)
To: dev
Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
We can now just OR the vfio_enabled sequentially and so adding new VFIO
subsystems (vfio_platform) is possible.
Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
---
lib/librte_eal/linuxapp/eal/eal.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c
index 606b777..3fb2188 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -705,12 +705,14 @@ rte_eal_iopl_init(void)
#ifdef VFIO_PRESENT
static int rte_eal_vfio_setup(void)
{
- if (internal_config.no_pci)
- return 0;
+ int vfio_enabled = 0;
- pci_vfio_enable();
+ if (!internal_config.no_pci) {
+ pci_vfio_enable();
+ vfio_enabled |= pci_vfio_is_enabled();
+ }
- if (pci_vfio_is_enabled()) {
+ if (vfio_enabled) {
/* if we are primary process, create a thread to communicate with
* secondary processes. the thread will use a socket to wait for
--
2.8.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (15 preceding siblings ...)
2016-07-04 15:16 ` [dpdk-dev] [PATCH v3 16/16] vfio: change VFIO init to be extendable Jan Viktorin
@ 2016-07-04 15:26 ` Burakov, Anatoly
2016-07-10 18:17 ` Thomas Monjalon
17 siblings, 0 replies; 20+ messages in thread
From: Burakov, Anatoly @ 2016-07-04 15:26 UTC (permalink / raw)
To: Jan Viktorin, dev
Cc: David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger,
Shreyansh Jain
> From: Jan Viktorin [mailto:viktorin@rehivetech.com]
> Sent: Monday, July 4, 2016 4:17 PM
> To: dev@dpdk.org
> Cc: Jan Viktorin <viktorin@rehivetech.com>; Burakov, Anatoly
> <anatoly.burakov@intel.com>; David Marchand
> <david.marchand@6wind.com>; Wiles, Keith <keith.wiles@intel.com>;
> Santosh Shukla <sshukla@mvista.com>; Stephen Hemminger
> <stephen@networkplumber.org>; Shreyansh Jain
> <shreyansh.jain@nxp.com>
> Subject: [PATCH v3 00/16] Make VFIO support less dependent on PCI
>
> Hello,
>
> I've rebased the v2 of this patch set on top of the current master.
> It builds well for my setup (both VFIO enabled and disabled).
>
> Regards
> Jan
>
>
> v3:
> * 0012: Acked-by: John McNamara <john.mcnamara@intel.com>
>
> Jan Viktorin (16):
> vfio: fix include of eal_private.h to be local
> vfio: move VFIO-specific stuff to eal_vfio.h
> vfio: move common vfio constants to eal_vfio.h
> vfio: move vfio_iommu_type and dma_map functions to eal_vfio
> vfio: generalize pci_vfio_set_iommu_type
> vfio: generalize pci_vfio_has_supported_extensions
> vfio: move vfio-specific SOCKET_* constants
> vfio: generalize pci_vfio_get_container_fd
> vfio: generalize pci_vfio_get_group_no
> vfio: extract setup logic out of pci_vfio_map_resource
> vfio: move global vfio_cfg to eal_vfio.c
> vfio: fix typo in doc for vfio_setup_device
> vfio: make vfio_*_dma_map and iommu_types private
> vfio: rename and generalize eal_pci_vfio_mp_sync
> vfio: initialize vfio out of the PCI subsystem
> vfio: change VFIO init to be extendable
>
> lib/librte_eal/linuxapp/eal/Makefile | 5 +-
> lib/librte_eal/linuxapp/eal/eal.c | 33 ++
> lib/librte_eal/linuxapp/eal/eal_pci.c | 17 +-
> lib/librte_eal/linuxapp/eal/eal_pci_init.h | 41 --
> lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 517 +------------------
> lib/librte_eal/linuxapp/eal/eal_vfio.c | 547 +++++++++++++++++++++
> lib/librte_eal/linuxapp/eal/eal_vfio.h | 94 ++++
> .../{eal_pci_vfio_mp_sync.c => eal_vfio_mp_sync.c} | 12 +-
> 8 files changed, 691 insertions(+), 575 deletions(-) create mode 100644
> lib/librte_eal/linuxapp/eal/eal_vfio.c
> rename lib/librte_eal/linuxapp/eal/{eal_pci_vfio_mp_sync.c =>
> eal_vfio_mp_sync.c} (97%)
>
> --
> 2.8.0
For the whole patchset:
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI
2016-07-04 15:16 [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Jan Viktorin
` (16 preceding siblings ...)
2016-07-04 15:26 ` [dpdk-dev] [PATCH v3 00/16] Make VFIO support less dependent on PCI Burakov, Anatoly
@ 2016-07-10 18:17 ` Thomas Monjalon
17 siblings, 0 replies; 20+ messages in thread
From: Thomas Monjalon @ 2016-07-10 18:17 UTC (permalink / raw)
To: Jan Viktorin
Cc: dev, Anatoly Burakov, David Marchand, Keith Wiles,
Santosh Shukla, Stephen Hemminger, Shreyansh Jain
> Jan Viktorin (16):
> vfio: fix include of eal_private.h to be local
> vfio: move VFIO-specific stuff to eal_vfio.h
> vfio: move common vfio constants to eal_vfio.h
> vfio: move vfio_iommu_type and dma_map functions to eal_vfio
> vfio: generalize pci_vfio_set_iommu_type
> vfio: generalize pci_vfio_has_supported_extensions
> vfio: move vfio-specific SOCKET_* constants
> vfio: generalize pci_vfio_get_container_fd
> vfio: generalize pci_vfio_get_group_no
> vfio: extract setup logic out of pci_vfio_map_resource
> vfio: move global vfio_cfg to eal_vfio.c
> vfio: fix typo in doc for vfio_setup_device
> vfio: make vfio_*_dma_map and iommu_types private
> vfio: rename and generalize eal_pci_vfio_mp_sync
> vfio: initialize vfio out of the PCI subsystem
> vfio: change VFIO init to be extendable
Applied with include fixed in patch 6, thanks
^ permalink raw reply [flat|nested] 20+ messages in thread