DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI
@ 2016-04-29 13:44 Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 01/15] vfio: fix include of eal_private.h to be local Jan Viktorin
                   ` (32 more replies)
  0 siblings, 33 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

Hello,

here follows several patchs extracting the general VFIO code out of the
PCI + VFIO code base. Usually, it's just move and rename of functions.
The most complicated ones are:

* eal/linux: extract setup logic out of pci_vfio_map_resource

  - separation of some setup code out of the pci_vfio_map_resource
    (which is otherwise quite PCI-speicific)
  - it is required by the following one

* eal/linux: move global vfio_cfg to eal_vfio.c

  - moving the vfio_cfg global variable out of the eal_pci_vfio together with
    the functions working with this variable

Some patchs make just temporary changes to avoid breakages throughout the
patch set (dma mapping).

I am not sure, how exactly is the mp_sync code intended to work. Should there
be just a single socket connection (no matter how many bus-systems we support)?
I assume it works this way so I've generalized the eal_pci_vfio_mp_sync.

The vfio initialization is moved out of the rte_eal_pci_init into EAL.

The code is now prepared for adding of other infrastructures such as the SoC
that I've introduced in [1]. I've partially done this in my workspace.

The VFIO code is quite complex and written in a spaghetti style so a more
maintainance would be helpful. I've did my best to preserve the semantics
(I hope) to be 100 % the same as before.

Important: I didn't test whether it's working as I have no VFIO-enabled machine
at the moment and the SoC infra is not so ready yet.

[1] http://comments.gmane.org/gmane.comp.networking.dpdk.devel/30913

Regards
Jan

---

Jan Viktorin (15):
  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: 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             | 528 +++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_vfio.h             |  94 ++++
 .../{eal_pci_vfio_mp_sync.c => eal_vfio_mp_sync.c} |  12 +-
 8 files changed, 672 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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [dpdk-dev] [PATCH 01/15] vfio: fix include of eal_private.h to be local
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 02/15] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
                   ` (31 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 10266f8..257162b 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] 49+ messages in thread

* [dpdk-dev] [PATCH 02/15] vfio: move VFIO-specific stuff to eal_vfio.h
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 01/15] vfio: fix include of eal_private.h to be local Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 03/15] vfio: move common vfio constants " Jan Viktorin
                   ` (30 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 7011753..b4d7628 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -64,8 +64,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);
@@ -89,15 +87,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
@@ -105,23 +94,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] 49+ messages in thread

* [dpdk-dev] [PATCH 03/15] vfio: move common vfio constants to eal_vfio.h
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 01/15] vfio: fix include of eal_private.h to be local Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 02/15] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 04/15] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
                   ` (29 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 257162b..d29b7f1 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] 49+ messages in thread

* [dpdk-dev] [PATCH 04/15] vfio: move vfio_iommu_type and dma_map functions to eal_vfio
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (2 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 03/15] vfio: move common vfio constants " Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 05/15] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 e109361..128eb87 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -63,6 +63,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 d29b7f1..cfa26ee 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] 49+ messages in thread

* [dpdk-dev] [PATCH 05/15] vfio: generalize pci_vfio_set_iommu_type
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (3 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 04/15] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 06/15] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
                   ` (27 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 cfa26ee..f82368f 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] 49+ messages in thread

* [dpdk-dev] [PATCH 06/15] vfio: generalize pci_vfio_has_supported_extensions
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (4 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 05/15] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 07/15] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 f82368f..21aded7 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] 49+ messages in thread

* [dpdk-dev] [PATCH 07/15] vfio: move vfio-specific SOCKET_* constants
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (5 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 06/15] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 08/15] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
                   ` (25 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 b4d7628..fd81f4d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -87,13 +87,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] 49+ messages in thread

* [dpdk-dev] [PATCH 08/15] vfio: generalize pci_vfio_get_container_fd
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (6 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 07/15] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 09/15] vfio: generalize pci_vfio_get_group_no Jan Viktorin
                   ` (24 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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             | 68 ++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_vfio.h             |  4 ++
 5 files changed, 74 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 fd81f4d..6e7a603 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -85,7 +85,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 21aded7..33c11a1 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 26d966e..fbfa71d 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..3bcf55c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -32,11 +32,15 @@
  */
 
 #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"
 
 const struct vfio_iommu_type *
@@ -95,6 +99,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();
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] 49+ messages in thread

* [dpdk-dev] [PATCH 09/15] vfio: generalize pci_vfio_get_group_no
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (7 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 08/15] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 33c11a1..2b3dd2e 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),
-			 SYSFS_PCI_DEVICES "/%s/iommu_group", 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(SYSFS_PCI_DEVICES, 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 3bcf55c..33d2e11 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -163,6 +163,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] 49+ messages in thread

* [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (8 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 09/15] vfio: generalize pci_vfio_get_group_no Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-05-10 11:53   ` Burakov, Anatoly
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
                   ` (22 subsequent siblings)
  32 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 | 96 +++++++++++++++---------------
 1 file changed, 47 insertions(+), 49 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 2b3dd2e..cec6ce1 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,26 +461,6 @@ 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
-	 */
-
-	/* 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;
-	}
-
-	/*
 	 * at this point, we know that this group is viable (meaning, all devices
 	 * are either bound to VFIO or not bound to anything)
 	 */
@@ -546,8 +511,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 +522,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] 49+ messages in thread

* [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (9 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-05-10 11:56   ` Burakov, Anatoly
  2016-05-13 15:34   ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 12/15] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
                   ` (21 subsequent siblings)
  32 siblings, 2 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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         | 282 +--------------------
 lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |   2 +-
 lib/librte_eal/linuxapp/eal/eal_vfio.c             | 272 ++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_vfio.h             |  17 ++
 5 files changed, 294 insertions(+), 280 deletions(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 6e7a603..41d2dd6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -84,7 +84,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 cec6ce1..3d3f7dc 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,240 +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(SYSFS_PCI_DEVICES, 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 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
@@ -560,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(SYSFS_PCI_DEVICES, 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
@@ -819,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 fbfa71d..b2aa33f 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 33d2e11..7dce880 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -39,10 +39,282 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_eal_memconfig.h>
+#include <eal_private.h>
 
 #include "eal_filesystem.h"
 #include "eal_vfio.h"
 
+/* 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 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] 49+ messages in thread

* [dpdk-dev] [PATCH 12/15] vfio: make vfio_*_dma_map and iommu_types private
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (10 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 13/15] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
                   ` (20 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 7dce880..3f03f45 100644
--- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
@@ -47,6 +47,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)
 {
@@ -477,7 +488,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();
@@ -509,7 +520,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 d4532a5..f8728bd 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] 49+ messages in thread

* [dpdk-dev] [PATCH 13/15] vfio: rename and generalize eal_pci_vfio_mp_sync
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (11 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 12/15] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 14/15] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
                   ` (19 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 128eb87..c6f6b53 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -64,10 +64,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
@@ -108,7 +108,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 bdc08a0..732e21c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -742,7 +742,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 41d2dd6..cdfdada 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -66,7 +66,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 f8728bd..471627f 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 b2aa33f..bff6e81 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(ERR, EAL,
-- 
2.8.0

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [dpdk-dev] [PATCH 14/15] vfio: initialize vfio out of the PCI subsystem
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (12 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 13/15] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable Jan Viktorin
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 8aafd51..92225cf 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)
 
@@ -723,6 +724,31 @@ rte_eal_iopl_init(void)
 #endif
 }
 
+#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)
@@ -788,6 +814,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 732e21c..1ca4c1f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -730,21 +730,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 cdfdada..9eb9cb7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -64,9 +64,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 471627f..c2c8f80 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] 49+ messages in thread

* [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (13 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 14/15] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
@ 2016-04-29 13:44 ` Jan Viktorin
  2016-05-10 11:50   ` Burakov, Anatoly
  2016-05-10 12:18 ` [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Santosh Shukla
                   ` (17 subsequent siblings)
  32 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-04-29 13:44 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger

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 92225cf..1549fe5 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -727,12 +727,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] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable Jan Viktorin
@ 2016-05-10 11:50   ` Burakov, Anatoly
  2016-05-10 12:54     ` Jan Viktorin
  0 siblings, 1 reply; 49+ messages in thread
From: Burakov, Anatoly @ 2016-05-10 11:50 UTC (permalink / raw)
  To: Jan Viktorin, dev
  Cc: David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

Hi Jan,

> 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 92225cf..1549fe5 100644
> --- a/lib/librte_eal/linuxapp/eal/eal.c
> +++ b/lib/librte_eal/linuxapp/eal/eal.c
> @@ -727,12 +727,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();
> +	}

Could there be a situation where we need to know if a particular VFIO subsystem is enabled? Do you think it's worth adding (e.g. vfio_enabled |= VFIO_PCI_ENABLED or something)? (I don't imply it is necessary, just asking)

Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
@ 2016-05-10 11:53   ` Burakov, Anatoly
  2016-05-10 12:58     ` Jan Viktorin
  0 siblings, 1 reply; 49+ messages in thread
From: Burakov, Anatoly @ 2016-05-10 11:53 UTC (permalink / raw)
  To: Jan Viktorin, dev
  Cc: David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

Hi Jan,


>  	/*
> -	 * 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
> -	 */
> -
> -	/* 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;
> -	}
> -

I think you've lost this bit when moving things around. I can't find any viability checks in eal_vfio.c

Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
@ 2016-05-10 11:56   ` Burakov, Anatoly
  2016-05-10 12:55     ` Jan Viktorin
  2016-05-13 15:34   ` Jan Viktorin
  1 sibling, 1 reply; 49+ messages in thread
From: Burakov, Anatoly @ 2016-05-10 11:56 UTC (permalink / raw)
  To: Jan Viktorin, dev
  Cc: David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

Hi Jan,

> --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> @@ -39,10 +39,282 @@
>  #include <rte_log.h>
>  #include <rte_memory.h>
>  #include <rte_eal_memconfig.h>
> +#include <eal_private.h>
> 
>  #include "eal_filesystem.h"
>  #include "eal_vfio.h"

I believe the eal_private.h should be local include (in quotes), like in other places.

> +/**
> + * 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.
> + */

I think it would've been good to fix the typo in the comment ("indentified") :)

Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (14 preceding siblings ...)
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable Jan Viktorin
@ 2016-05-10 12:18 ` Santosh Shukla
  2016-05-10 12:45   ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 00/16] Make VFIO support less dependent " Jan Viktorin
                   ` (16 subsequent siblings)
  32 siblings, 1 reply; 49+ messages in thread
From: Santosh Shukla @ 2016-05-10 12:18 UTC (permalink / raw)
  To: Jan Viktorin
  Cc: dpdk, Anatoly Burakov, David Marchand, Keith Wiles,
	Stephen Hemminger, Shukla, Santosh

On Fri, Apr 29, 2016 at 7:14 PM, Jan Viktorin <viktorin@rehivetech.com> wrote:
>
> Hello,
>
> here follows several patchs extracting the general VFIO code out of the
> PCI + VFIO code base. Usually, it's just move and rename of functions.
> The most complicated ones are:
>
> * eal/linux: extract setup logic out of pci_vfio_map_resource
>
>   - separation of some setup code out of the pci_vfio_map_resource
>     (which is otherwise quite PCI-speicific)
>   - it is required by the following one
>
> * eal/linux: move global vfio_cfg to eal_vfio.c
>
>   - moving the vfio_cfg global variable out of the eal_pci_vfio together with
>     the functions working with this variable
>
> Some patchs make just temporary changes to avoid breakages throughout the
> patch set (dma mapping).
>
> I am not sure, how exactly is the mp_sync code intended to work. Should there
> be just a single socket connection (no matter how many bus-systems we support)?
> I assume it works this way so I've generalized the eal_pci_vfio_mp_sync.
>
> The vfio initialization is moved out of the rte_eal_pci_init into EAL.
>
> The code is now prepared for adding of other infrastructures such as the SoC
> that I've introduced in [1]. I've partially done this in my workspace.
>

I haven't started reading patch set, we'll do so. But by referring to
your initiative [1] which is non-pci SoC infra, How about binding
those non-pci soc via vfio-platform-way? As because vfio-for-platform
device use-case is such non-pci accelerators in SoC. is your current
refactoring effort aligned towards vfio-platform direction?

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI
  2016-05-10 12:18 ` [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Santosh Shukla
@ 2016-05-10 12:45   ` Jan Viktorin
  0 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-05-10 12:45 UTC (permalink / raw)
  To: Santosh Shukla
  Cc: dpdk, Anatoly Burakov, David Marchand, Keith Wiles,
	Stephen Hemminger, Shukla, Santosh

Hello Santosh,

On Tue, 10 May 2016 17:48:23 +0530
Santosh Shukla <sshukla@mvista.com> wrote:

> On Fri, Apr 29, 2016 at 7:14 PM, Jan Viktorin <viktorin@rehivetech.com> wrote:
> >
> > Hello,
> >
> > here follows several patchs extracting the general VFIO code out of the
> > PCI + VFIO code base. Usually, it's just move and rename of functions.
> > The most complicated ones are:
> >
> > * eal/linux: extract setup logic out of pci_vfio_map_resource
> >
> >   - separation of some setup code out of the pci_vfio_map_resource
> >     (which is otherwise quite PCI-speicific)
> >   - it is required by the following one
> >
> > * eal/linux: move global vfio_cfg to eal_vfio.c
> >
> >   - moving the vfio_cfg global variable out of the eal_pci_vfio together with
> >     the functions working with this variable
> >
> > Some patchs make just temporary changes to avoid breakages throughout the
> > patch set (dma mapping).
> >
> > I am not sure, how exactly is the mp_sync code intended to work. Should there
> > be just a single socket connection (no matter how many bus-systems we support)?
> > I assume it works this way so I've generalized the eal_pci_vfio_mp_sync.
> >
> > The vfio initialization is moved out of the rte_eal_pci_init into EAL.
> >
> > The code is now prepared for adding of other infrastructures such as the SoC
> > that I've introduced in [1]. I've partially done this in my workspace.

Probably, I should have written here "later, vfio-platform will be
connected to this"...

> >  
> 
> I haven't started reading patch set, we'll do so. But by referring to
> your initiative [1] which is non-pci SoC infra, How about binding
> those non-pci soc via vfio-platform-way? As because vfio-for-platform
> device use-case is such non-pci accelerators in SoC. is your current
> refactoring effort aligned towards vfio-platform direction?

Sure, vfio-platform is the way to go. However, this patch set is just a
refactoring. The goal is to be able to connect with the vfio-platform.
Without this patch set, it leads to lots of duplicated code.

Jan

-- 
  Jan Viktorin                E-mail: Viktorin@RehiveTech.com
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable
  2016-05-10 11:50   ` Burakov, Anatoly
@ 2016-05-10 12:54     ` Jan Viktorin
  2016-05-10 13:15       ` Burakov, Anatoly
  0 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-05-10 12:54 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

Hello Anatoly,

On Tue, 10 May 2016 11:50:23 +0000
"Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:

> Hi Jan,
> 
> > 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 92225cf..1549fe5 100644
> > --- a/lib/librte_eal/linuxapp/eal/eal.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal.c
> > @@ -727,12 +727,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();
> > +	}  
> 
> Could there be a situation where we need to know if a particular VFIO subsystem is enabled? Do you think it's worth adding (e.g. vfio_enabled |= VFIO_PCI_ENABLED or something)? (I don't imply it is necessary, just asking)

Well... the semantics are quite tricky here.

There are: vfio-pci, vfio-platform and vfio-amba in the Linux Kernel. I
ignore vfio-amba because I don't know any considerable device supported
by this.

With respect to the VFIO, if you have both PCI and SoC infra enabled,
you have to check for both vfio-pci and vfio-platform.

If only PCI is there you have to check only for vfio-pci.
But, if you check for vfio-platform as well and it is not there then
the EAL init would fail without a reason (because you don't need
vfio-platform). Vice-versa for SoC.

This patch improves the check to cover those situations. Later on,
I'll just append something like:

if (!internal_config.no_soc) {
	soc_vfio_enable();
	vfio_enabled |= soc_vfio_is_enabled();
}

and the EAL init would be happy... I hope ;).

The thing is that we don't know which devices will bind to VFIO and we
don't know which of those devices would use vfio-pci and vfio-platform.
So, if both PCI and SoC are enabled and only vfio-platform is there we
cannot say here "failed because vfio-pci is missing".

Jan

> 
> Thanks,
> Anatoly



-- 
  Jan Viktorin                E-mail: Viktorin@RehiveTech.com
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c
  2016-05-10 11:56   ` Burakov, Anatoly
@ 2016-05-10 12:55     ` Jan Viktorin
  0 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-05-10 12:55 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

On Tue, 10 May 2016 11:56:36 +0000
"Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:

> Hi Jan,
> 
> > --- a/lib/librte_eal/linuxapp/eal/eal_vfio.c
> > +++ b/lib/librte_eal/linuxapp/eal/eal_vfio.c
> > @@ -39,10 +39,282 @@
> >  #include <rte_log.h>
> >  #include <rte_memory.h>
> >  #include <rte_eal_memconfig.h>
> > +#include <eal_private.h>
> > 
> >  #include "eal_filesystem.h"
> >  #include "eal_vfio.h"  
> 
> I believe the eal_private.h should be local include (in quotes), like in other places.

+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.
> > + */  
> 
> I think it would've been good to fix the typo in the comment ("indentified") :)

Ok.

Regards
Jan

> 
> Thanks,
> Anatoly



-- 
  Jan Viktorin                E-mail: Viktorin@RehiveTech.com
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource
  2016-05-10 11:53   ` Burakov, Anatoly
@ 2016-05-10 12:58     ` Jan Viktorin
  2016-05-10 13:17       ` Jan Viktorin
  0 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-05-10 12:58 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

On Tue, 10 May 2016 11:53:21 +0000
"Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:

> Hi Jan,
> 
> 
> >  	/*
> > -	 * 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
> > -	 */
> > -
> > -	/* 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;
> > -	}
> > -  
> 
> I think you've lost this bit when moving things around. I can't find any viability checks in eal_vfio.c

Thanks for this catch, I'll check. I've rebased the patch set once
because there were some changes to the original VFIO code. Hope for no
more such rebasing.

Regards
Jan

> 
> Thanks,
> Anatoly



-- 
  Jan Viktorin                E-mail: Viktorin@RehiveTech.com
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable
  2016-05-10 12:54     ` Jan Viktorin
@ 2016-05-10 13:15       ` Burakov, Anatoly
  0 siblings, 0 replies; 49+ messages in thread
From: Burakov, Anatoly @ 2016-05-10 13:15 UTC (permalink / raw)
  To: Jan Viktorin
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

> > Could there be a situation where we need to know if a particular VFIO
> > subsystem is enabled? Do you think it's worth adding (e.g.
> > vfio_enabled |= VFIO_PCI_ENABLED or something)? (I don't imply it is
> > necessary, just asking)
> 
> Well... the semantics are quite tricky here.
> 
> There are: vfio-pci, vfio-platform and vfio-amba in the Linux Kernel. I ignore
> vfio-amba because I don't know any considerable device supported by this.
> 
> With respect to the VFIO, if you have both PCI and SoC infra enabled, you
> have to check for both vfio-pci and vfio-platform.
> 
> If only PCI is there you have to check only for vfio-pci.
> But, if you check for vfio-platform as well and it is not there then the EAL init
> would fail without a reason (because you don't need vfio-platform). Vice-
> versa for SoC.
> 
> This patch improves the check to cover those situations. Later on, I'll just
> append something like:
> 
> if (!internal_config.no_soc) {
> 	soc_vfio_enable();
> 	vfio_enabled |= soc_vfio_is_enabled();
> }
> 
> and the EAL init would be happy... I hope ;).
> 
> The thing is that we don't know which devices will bind to VFIO and we don't
> know which of those devices would use vfio-pci and vfio-platform.
> So, if both PCI and SoC are enabled and only vfio-platform is there we cannot
> say here "failed because vfio-pci is missing".

OK fair enough :)

I haven't yet tested the patchset itself, I'll report back if I get any issues.

Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource
  2016-05-10 12:58     ` Jan Viktorin
@ 2016-05-10 13:17       ` Jan Viktorin
  0 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-05-10 13:17 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger

On Tue, 10 May 2016 14:58:26 +0200
Jan Viktorin <viktorin@rehivetech.com> wrote:

> On Tue, 10 May 2016 11:53:21 +0000
> "Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:
> 
> > Hi Jan,
> > 
> >   
> > >  	/*
> > > -	 * 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
> > > -	 */
> > > -
> > > -	/* 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;
> > > -	}
> > > -    
> > 
> > I think you've lost this bit when moving things around. I can't find any viability checks in eal_vfio.c  
> 
> Thanks for this catch, I'll check. I've rebased the patch set once
> because there were some changes to the original VFIO code. Hope for no
> more such rebasing.

OK. Confirmed. Fixed for v2.

Jan

> 
> Regards
> Jan
> 
> > 
> > Thanks,
> > Anatoly  
> 
> 
> 



-- 
  Jan Viktorin                E-mail: Viktorin@RehiveTech.com
  System Architect            Web:    www.RehiveTech.com
  RehiveTech
  Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c
  2016-04-29 13:44 ` [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
  2016-05-10 11:56   ` Burakov, Anatoly
@ 2016-05-13 15:34   ` Jan Viktorin
  1 sibling, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-05-13 15:34 UTC (permalink / raw)
  To: dev
  Cc: Anatoly Burakov, David Marchand, Keith Wiles, Santosh Shukla,
	Stephen Hemminger

Self review:

* missing #ifdef VFIO_PRESENT ... #endif in eal_vfio.c leads to fail
  when VFIO build is disabled

Jan

On Fri, 29 Apr 2016 15:44:12 +0200
Jan Viktorin <viktorin@rehivetech.com> wrote:

> 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         | 282 +--------------------
>  lib/librte_eal/linuxapp/eal/eal_pci_vfio_mp_sync.c |   2 +-
>  lib/librte_eal/linuxapp/eal/eal_vfio.c             | 272 ++++++++++++++++++++
>  lib/librte_eal/linuxapp/eal/eal_vfio.h             |  17 ++
>  5 files changed, 294 insertions(+), 280 deletions(-)

[...]

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [dpdk-dev] [PATCH v2 00/16] Make VFIO support less dependent on PCI
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (15 preceding siblings ...)
  2016-05-10 12:18 ` [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Santosh Shukla
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 UTC (permalink / raw)
  To: dev
  Cc: Jan Viktorin, Anatoly Burakov, David Marchand, Keith Wiles,
	Santosh Shukla, Stephen Hemminger, Shreyansh Jain

Hello,

here follows several patchs extracting the general VFIO code out of the
PCI + VFIO code base. Usually, it's just move and rename of functions.
The goal is to be able to extend for other Linux VFIO drivers then
vfio-pci. That is especially vfio-platform. However, just the
vfio-platform support may be insufficient because several platform
devices require to call clk_prepare_enable which is not possible to be
done from userspace and which is not being solved in the VFIO code base
at the moment.

Some patchs make just temporary changes to avoid breakages throughout the
patch set (dma mapping).

The most complicated patchs are:

* eal/linux: extract setup logic out of pci_vfio_map_resource

  - separation of some setup code out of the pci_vfio_map_resource
    (which is otherwise quite PCI-specific)
  - it is required by the following one

* eal/linux: move global vfio_cfg to eal_vfio.c

  - moving the vfio_cfg global variable out of the eal_pci_vfio together with
    the functions working with this variable

I am not sure, how exactly is the mp_sync code intended to work. Should there
be just a single socket connection (no matter how many bus-systems we support)?
I assume it works this way so I've generalized the eal_pci_vfio_mp_sync.

The vfio initialization is moved out of the rte_eal_pci_init into EAL.

The code is now prepared for adding of other infrastructures such as the SoC
that I've introduced in [1]. I've partially done this in my workspace.

The VFIO code is quite complex and written in a spaghetti style so a more
maintainance would be helpful. I've did my best to preserve the semantics
(I hope) to be 100 % the same as before.

Important: I didn't test whether it's working as I have no VFIO-enabled machine
at the moment and the SoC infra is not so ready yet.

[1] http://comments.gmane.org/gmane.comp.networking.dpdk.devel/30913

Regards
Jan

---
v2:
* fixed missing ifdef VFIO_PRESENT - broke builds with VFIO disabled
* fixed include of eal_private.h (A. Burakov)
* fixed lost viable code (A. Burakov)
* fixed typo "indentified" (A. Burakov)
---

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (16 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 00/16] Make VFIO support less dependent " Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-07-04 10:22   ` Burakov, Anatoly
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 02/16] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
                   ` (14 subsequent siblings)
  32 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 10266f8..257162b 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 02/16] vfio: move VFIO-specific stuff to eal_vfio.h
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (17 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 03/16] vfio: move common vfio constants " Jan Viktorin
                   ` (13 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 7011753..b4d7628 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -64,8 +64,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);
@@ -89,15 +87,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
@@ -105,23 +94,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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 03/16] vfio: move common vfio constants to eal_vfio.h
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (18 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 02/16] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 257162b..d29b7f1 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (19 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 03/16] vfio: move common vfio constants " Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 05/16] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
                   ` (11 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 d29b7f1..cfa26ee 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 05/16] vfio: generalize pci_vfio_set_iommu_type
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (20 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 cfa26ee..f82368f 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 06/16] vfio: generalize pci_vfio_has_supported_extensions
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (21 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 05/16] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 07/16] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 f82368f..21aded7 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 07/16] vfio: move vfio-specific SOCKET_* constants
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (22 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 08/16] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 b4d7628..fd81f4d 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -87,13 +87,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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 08/16] vfio: generalize pci_vfio_get_container_fd
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (23 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 07/16] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 09/16] vfio: generalize pci_vfio_get_group_no Jan Viktorin
                   ` (7 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 fd81f4d..6e7a603 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -85,7 +85,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 21aded7..33c11a1 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 26d966e..fbfa71d 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 09/16] vfio: generalize pci_vfio_get_group_no
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (24 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 08/16] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
@ 2016-06-13 13:01 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 10/16] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:01 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 33c11a1..2b3dd2e 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),
-			 SYSFS_PCI_DEVICES "/%s/iommu_group", 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(SYSFS_PCI_DEVICES, 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 10/16] vfio: extract setup logic out of pci_vfio_map_resource
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (25 preceding siblings ...)
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 09/16] vfio: generalize pci_vfio_get_group_no Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 11/16] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
                   ` (5 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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>
---
v2
* fixed lost viable code (A. Burakov)
---
 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 2b3dd2e..27ce6a8 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 11/16] vfio: move global vfio_cfg to eal_vfio.c
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (26 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 10/16] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
                   ` (4 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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>
---
v2
* viable code was not lost in 10/16, thus, it is moved here (A. Burakov)
---
 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 6e7a603..41d2dd6 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -84,7 +84,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 27ce6a8..3d3f7dc 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(SYSFS_PCI_DEVICES, 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(SYSFS_PCI_DEVICES, 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 fbfa71d..b2aa33f 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (27 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 11/16] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-24 15:55   ` Mcnamara, John
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 13/16] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
                   ` (3 subsequent siblings)
  32 siblings, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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>
---
 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 13/16] vfio: make vfio_*_dma_map and iommu_types private
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (28 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (29 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 13/16] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 15/16] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 16/16] vfio: change VFIO init to be extendable Jan Viktorin
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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 bdc08a0..732e21c 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -742,7 +742,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 41d2dd6..cdfdada 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -66,7 +66,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 b2aa33f..bff6e81 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(ERR, EAL,
-- 
2.8.0

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [dpdk-dev] [PATCH v2 15/16] vfio: initialize vfio out of the PCI subsystem
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (30 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 16/16] vfio: change VFIO init to be extendable Jan Viktorin
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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 8aafd51..92225cf 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)
 
@@ -723,6 +724,31 @@ rte_eal_iopl_init(void)
 #endif
 }
 
+#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)
@@ -788,6 +814,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 732e21c..1ca4c1f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -730,21 +730,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 cdfdada..9eb9cb7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -64,9 +64,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] 49+ messages in thread

* [dpdk-dev] [PATCH v2 16/16] vfio: change VFIO init to be extendable
  2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
                   ` (31 preceding siblings ...)
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 15/16] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
@ 2016-06-13 13:02 ` Jan Viktorin
  32 siblings, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-06-13 13:02 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 92225cf..1549fe5 100644
--- a/lib/librte_eal/linuxapp/eal/eal.c
+++ b/lib/librte_eal/linuxapp/eal/eal.c
@@ -727,12 +727,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] 49+ messages in thread

* Re: [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device
  2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
@ 2016-06-24 15:55   ` Mcnamara, John
  0 siblings, 0 replies; 49+ messages in thread
From: Mcnamara, John @ 2016-06-24 15:55 UTC (permalink / raw)
  To: Jan Viktorin, dev
  Cc: Burakov, Anatoly, David Marchand, Wiles, Keith, Santosh Shukla,
	Stephen Hemminger, Shreyansh Jain

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jan Viktorin
> Sent: Monday, June 13, 2016 2:02 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: [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for
> vfio_setup_device
> 
> Signed-off-by: Jan Viktorin <viktorin@rehivetech.com>
> Suggested-by: Anatoly Burakov <anatoly.burakov@intel.com>

Acked-by: John McNamara <john.mcnamara@intel.com>

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
  2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
@ 2016-07-04 10:22   ` Burakov, Anatoly
  2016-07-04 10:55     ` Jan Viktorin
  2016-07-04 15:00     ` Jan Viktorin
  0 siblings, 2 replies; 49+ messages in thread
From: Burakov, Anatoly @ 2016-07-04 10:22 UTC (permalink / raw)
  To: Jan Viktorin, dev
  Cc: David Marchand, Wiles, Keith, Santosh Shukla, Stephen Hemminger,
	Shreyansh Jain

> -----Original Message-----
> From: Jan Viktorin [mailto:viktorin@rehivetech.com]
> Sent: Monday, June 13, 2016 2:02 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 v2 01/16] vfio: fix include of eal_private.h to be local
> 
> 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 10266f8..257162b 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

There's no patch cover letter so I'll reply to the first patch. I've done some cursory testing with a NIC, nothing seems to be broken and the code looks OK to me. So, once this patchset is rebased on latest master (patches 9, 14 and 15 no longer apply cleanly), ack from me.

Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
  2016-07-04 10:22   ` Burakov, Anatoly
@ 2016-07-04 10:55     ` Jan Viktorin
  2016-07-04 15:00     ` Jan Viktorin
  1 sibling, 0 replies; 49+ messages in thread
From: Jan Viktorin @ 2016-07-04 10:55 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla,
	Stephen Hemminger, Shreyansh Jain

On Mon, 4 Jul 2016 10:22:08 +0000
"Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:

> > -----Original Message-----
> > From: Jan Viktorin [mailto:viktorin@rehivetech.com]
> > Sent: Monday, June 13, 2016 2:02 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 v2 01/16] vfio: fix include of eal_private.h to be local
> > 
> > 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 10266f8..257162b 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  
> 

Hello Anatoly,

> There's no patch cover letter so I'll reply to the first patch.

yes, there is (and you are in CC), may be lost in the traffic...

http://dpdk.org/ml/archives/dev/2016-June/041085.html

ID: 1465822926-23742-1-git-send-email-viktorin@rehivetech.com

> I've done some cursory testing with a NIC, nothing seems to be broken and the code looks OK to me. So, once this patchset is rebased on latest master (patches 9, 14 and 15 no longer apply cleanly), ack from me.

Thank you very much! I am going to do the rebase.

Jan

> 
> Thanks,
> Anatoly



-- 
   Jan Viktorin                  E-mail: Viktorin@RehiveTech.com
   System Architect              Web:    www.RehiveTech.com
   RehiveTech
   Brno, Czech Republic

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
  2016-07-04 10:22   ` Burakov, Anatoly
  2016-07-04 10:55     ` Jan Viktorin
@ 2016-07-04 15:00     ` Jan Viktorin
  2016-07-04 15:09       ` Burakov, Anatoly
  1 sibling, 1 reply; 49+ messages in thread
From: Jan Viktorin @ 2016-07-04 15:00 UTC (permalink / raw)
  To: Burakov, Anatoly
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla,
	Stephen Hemminger, Shreyansh Jain

On Mon, 4 Jul 2016 10:22:08 +0000
"Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:

[...] 

> There's no patch cover letter so I'll reply to the first patch. I've done some cursory testing with a NIC, nothing seems to be broken and the code looks OK to me. So, once this patchset is rebased on latest master (patches 9, 14 and 15 no longer apply cleanly), ack from me.

I am going to post v3. Should I include the ACKs on all patches or will you post them yourself?

Jan

> 
> Thanks,
> Anatoly

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
  2016-07-04 15:00     ` Jan Viktorin
@ 2016-07-04 15:09       ` Burakov, Anatoly
  0 siblings, 0 replies; 49+ messages in thread
From: Burakov, Anatoly @ 2016-07-04 15:09 UTC (permalink / raw)
  To: Jan Viktorin
  Cc: dev, David Marchand, Wiles, Keith, Santosh Shukla,
	Stephen Hemminger, Shreyansh Jain

> -----Original Message-----
> From: Jan Viktorin [mailto:viktorin@rehivetech.com]
> Sent: Monday, July 4, 2016 4:01 PM
> To: Burakov, Anatoly <anatoly.burakov@intel.com>
> Cc: dev@dpdk.org; 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: Re: [PATCH v2 01/16] vfio: fix include of eal_private.h to be local
> 
> On Mon, 4 Jul 2016 10:22:08 +0000
> "Burakov, Anatoly" <anatoly.burakov@intel.com> wrote:
> 
> [...]
> 
> > There's no patch cover letter so I'll reply to the first patch. I've done some
> cursory testing with a NIC, nothing seems to be broken and the code looks
> OK to me. So, once this patchset is rebased on latest master (patches 9, 14
> and 15 no longer apply cleanly), ack from me.
> 
> I am going to post v3. Should I include the ACKs on all patches or will you post
> them yourself?
> 

I'll test the patchset again and ack the patchset. Thanks!

^ permalink raw reply	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2016-07-04 15:11 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-29 13:44 [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 01/15] vfio: fix include of eal_private.h to be local Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 02/15] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 03/15] vfio: move common vfio constants " Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 04/15] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 05/15] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 06/15] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 07/15] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 08/15] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 09/15] vfio: generalize pci_vfio_get_group_no Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 10/15] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
2016-05-10 11:53   ` Burakov, Anatoly
2016-05-10 12:58     ` Jan Viktorin
2016-05-10 13:17       ` Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 11/15] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
2016-05-10 11:56   ` Burakov, Anatoly
2016-05-10 12:55     ` Jan Viktorin
2016-05-13 15:34   ` Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 12/15] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 13/15] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 14/15] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
2016-04-29 13:44 ` [dpdk-dev] [PATCH 15/15] vfio: change VFIO init to be extendable Jan Viktorin
2016-05-10 11:50   ` Burakov, Anatoly
2016-05-10 12:54     ` Jan Viktorin
2016-05-10 13:15       ` Burakov, Anatoly
2016-05-10 12:18 ` [dpdk-dev] [PATCH 00/15] Make VFIO support independent on PCI Santosh Shukla
2016-05-10 12:45   ` Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 00/16] Make VFIO support less dependent " Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 01/16] vfio: fix include of eal_private.h to be local Jan Viktorin
2016-07-04 10:22   ` Burakov, Anatoly
2016-07-04 10:55     ` Jan Viktorin
2016-07-04 15:00     ` Jan Viktorin
2016-07-04 15:09       ` Burakov, Anatoly
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 02/16] vfio: move VFIO-specific stuff to eal_vfio.h Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 03/16] vfio: move common vfio constants " Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 04/16] vfio: move vfio_iommu_type and dma_map functions to eal_vfio Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 05/16] vfio: generalize pci_vfio_set_iommu_type Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 06/16] vfio: generalize pci_vfio_has_supported_extensions Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 07/16] vfio: move vfio-specific SOCKET_* constants Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 08/16] vfio: generalize pci_vfio_get_container_fd Jan Viktorin
2016-06-13 13:01 ` [dpdk-dev] [PATCH v2 09/16] vfio: generalize pci_vfio_get_group_no Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 10/16] vfio: extract setup logic out of pci_vfio_map_resource Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 11/16] vfio: move global vfio_cfg to eal_vfio.c Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 12/16] vfio: fix typo in doc for vfio_setup_device Jan Viktorin
2016-06-24 15:55   ` Mcnamara, John
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 13/16] vfio: make vfio_*_dma_map and iommu_types private Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 14/16] vfio: rename and generalize eal_pci_vfio_mp_sync Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 15/16] vfio: initialize vfio out of the PCI subsystem Jan Viktorin
2016-06-13 13:02 ` [dpdk-dev] [PATCH v2 16/16] vfio: change VFIO init to be extendable Jan Viktorin

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).