From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Cc: david.marchand@redhat.com, jerinj@marvell.com, thomas@monjalon.net
Subject: [dpdk-dev] [PATCH v2] eal: pick IOVA as PA if IOMMU is not available
Date: Thu, 25 Jul 2019 10:52:24 +0100 [thread overview]
Message-ID: <b0259319e149f537b60d446cee2e58f65613e2f0.1564048328.git.anatoly.burakov@intel.com> (raw)
In-Reply-To: <5d8f83fb7dd574d83a044c6a01e2613798f256c3.1563986790.git.anatoly.burakov@intel.com>
When IOMMU is not available, /sys/kernel/iommu_groups will not be
populated. This is happening since at least 3.6 when VFIO support
was added. If the directory is empty, EAL should not pick IOVA as
VA as the default IOVA mode.
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
Notes:
v2:
- Decouple IOMMU from VFIO
- Add a check for physical addresses availability
lib/librte_eal/linux/eal/eal.c | 21 ++++++++++++++++++--
lib/librte_eal/linux/eal/eal_vfio.c | 30 +++++++++++++++++++++++++++++
lib/librte_eal/linux/eal/eal_vfio.h | 2 ++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c
index 34db78753..207ee0b1c 100644
--- a/lib/librte_eal/linux/eal/eal.c
+++ b/lib/librte_eal/linux/eal/eal.c
@@ -1061,8 +1061,25 @@ rte_eal_init(int argc, char **argv)
enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
if (iova_mode == RTE_IOVA_DC) {
- iova_mode = RTE_IOVA_VA;
- RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode, select IOVA as VA mode.\n");
+ RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
+
+ if (!phys_addrs) {
+ /* if we have no access to physical addreses,
+ * pick IOVA as VA mode.
+ */
+ iova_mode = RTE_IOVA_VA;
+ RTE_LOG(DEBUG, EAL, "Physical addresses are unavailable, selecting IOVA as VA mode.\n");
+ } else if (vfio_iommu_enabled()) {
+ /* we have an IOMMU, pick IOVA as VA mode */
+ iova_mode = RTE_IOVA_VA;
+ RTE_LOG(DEBUG, EAL, "IOMMU is available, selecting IOVA as VA mode.\n");
+ } else {
+ /* physical addresses available, and no IOMMU
+ * found, so pick IOVA as PA.
+ */
+ iova_mode = RTE_IOVA_PA;
+ RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
+ }
}
#ifdef RTE_LIBRTE_KNI
/* Workaround for KNI which requires physical address to work */
diff --git a/lib/librte_eal/linux/eal/eal_vfio.c b/lib/librte_eal/linux/eal/eal_vfio.c
index 501c74f23..92d290284 100644
--- a/lib/librte_eal/linux/eal/eal_vfio.c
+++ b/lib/librte_eal/linux/eal/eal_vfio.c
@@ -2,6 +2,7 @@
* Copyright(c) 2010-2018 Intel Corporation
*/
+#include <dirent.h>
#include <inttypes.h>
#include <string.h>
#include <fcntl.h>
@@ -19,6 +20,8 @@
#include "eal_vfio.h"
#include "eal_private.h"
+#define VFIO_KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups"
+
#ifdef VFIO_PRESENT
#define VFIO_MEM_EVENT_CLB_NAME "vfio_mem_event_clb"
@@ -2147,3 +2150,30 @@ rte_vfio_container_dma_unmap(__rte_unused int container_fd,
}
#endif /* VFIO_PRESENT */
+
+/*
+ * on Linux 3.6+, even if VFIO is not loaded, whenever IOMMU is enabled in the
+ * BIOS and in the kernel, /sys/kernel/iommu_groups path will contain kernel
+ * IOMMU groups. If IOMMU is not enabled, that path would be empty. Therefore,
+ * checking if the path is empty will tell us if IOMMU is enabled.
+ */
+int
+vfio_iommu_enabled(void)
+{
+ DIR *dir = opendir(VFIO_KERNEL_IOMMU_GROUPS_PATH);
+ struct dirent *d;
+ int n = 0;
+
+ /* if directory doesn't exist, assume IOMMU is not enabled */
+ if (dir == NULL)
+ return 0;
+
+ while ((d = readdir(dir)) != NULL) {
+ /* skip dot and dot-dot */
+ if (++n > 2)
+ break;
+ }
+ closedir(dir);
+
+ return n > 2;
+}
diff --git a/lib/librte_eal/linux/eal/eal_vfio.h b/lib/librte_eal/linux/eal/eal_vfio.h
index cb2d35fb1..58c7a7309 100644
--- a/lib/librte_eal/linux/eal/eal_vfio.h
+++ b/lib/librte_eal/linux/eal/eal_vfio.h
@@ -133,6 +133,8 @@ vfio_has_supported_extensions(int vfio_container_fd);
int vfio_mp_sync_setup(void);
+int vfio_iommu_enabled(void);
+
#define EAL_VFIO_MP "eal_vfio_mp_sync"
#define SOCKET_REQ_CONTAINER 0x100
--
2.17.1
next prev parent reply other threads:[~2019-07-25 9:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-24 16:46 [dpdk-dev] [PATCH] " Anatoly Burakov
2019-07-25 8:05 ` David Marchand
2019-07-25 9:31 ` Burakov, Anatoly
2019-07-25 9:35 ` David Marchand
2019-07-25 9:38 ` Burakov, Anatoly
2019-07-25 9:40 ` Burakov, Anatoly
2019-07-25 18:58 ` Thomas Monjalon
2019-07-25 9:52 ` Anatoly Burakov [this message]
2019-07-25 9:56 ` [dpdk-dev] [EXT] [PATCH v2] " Jerin Jacob Kollanukkaran
2019-07-25 11:05 ` [dpdk-dev] [PATCH v3] " Anatoly Burakov
2019-07-26 5:08 ` Stojaczyk, Dariusz
2019-07-26 15:37 ` [dpdk-dev] [PATCH v4] " Anatoly Burakov
2019-07-29 9:31 ` David Marchand
2019-07-29 11:18 ` Burakov, Anatoly
2019-07-29 13:52 ` [dpdk-dev] [PATCH v5] " Anatoly Burakov
2019-07-30 7:21 ` David Marchand
2019-07-30 8:10 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b0259319e149f537b60d446cee2e58f65613e2f0.1564048328.git.anatoly.burakov@intel.com \
--to=anatoly.burakov@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).