From: Santosh Shukla <sshukla@mvista.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v5 08/11] eal: pci: introduce RTE_KDRV_VFIO_NOIOMMUi driver mode
Date: Tue, 19 Jan 2016 17:16:09 +0530 [thread overview]
Message-ID: <1453203972-24855-9-git-send-email-sshukla@mvista.com> (raw)
In-Reply-To: <1453203972-24855-1-git-send-email-sshukla@mvista.com>
Adding RTE_KDRV_VFIO_NOIOMMU mode in kernel driver. Also including
rte_vfio_is_noiommu() helper function. This function will parse
/sys/bus/pci/device/<bus_addr>/ and make sure that
- vfio noiommu mode set in kernel driver
- pci device attached to vfio-noiommu driver only
If both condition satisfies then set drv->kdrv = RTE_KDRV_VFIO_NOIOMMU
Also did similar changes in virtio_rd/wr, Changes applicable for virtio spec
0.95 only.
Signed-off-by: Santosh Shukla <sshukla@mvista.com>
---
v4--> v5:
- Removed virtio_xx_init_by_vfio and added new driver mode.
- Now no need to parse vfio interface in virtio. As pci_eal module will take of
vfio-noiommu driver parsing for virtio or any other future device willing to
use vfio-noiommu driver.
drivers/net/virtio/virtio_pci.c | 12 ++---
lib/librte_eal/common/include/rte_pci.h | 1 +
lib/librte_eal/linuxapp/eal/eal_pci.c | 13 ++++--
lib/librte_eal/linuxapp/eal/eal_pci_init.h | 1 +
lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 69 ++++++++++++++++++++++++++++
5 files changed, 87 insertions(+), 9 deletions(-)
diff --git a/drivers/net/virtio/virtio_pci.c b/drivers/net/virtio/virtio_pci.c
index 0c29f1d..537c552 100644
--- a/drivers/net/virtio/virtio_pci.c
+++ b/drivers/net/virtio/virtio_pci.c
@@ -60,7 +60,7 @@ virtio_read_reg_1(struct virtio_hw *hw, uint64_t reg_offset)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_inb(dev, reg_offset, &ret);
else
ret = inb(VIRTIO_PCI_REG_ADDR(hw, reg_offset));
@@ -75,7 +75,7 @@ virtio_read_reg_2(struct virtio_hw *hw, uint64_t reg_offset)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_inw(dev, reg_offset, &ret);
else
ret = inw(VIRTIO_PCI_REG_ADDR(hw, reg_offset));
@@ -90,7 +90,7 @@ virtio_read_reg_4(struct virtio_hw *hw, uint64_t reg_offset)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_inl(dev, reg_offset, &ret);
else
ret = inl(VIRTIO_PCI_REG_ADDR(hw, reg_offset));
@@ -104,7 +104,7 @@ virtio_write_reg_1(struct virtio_hw *hw, uint64_t reg_offset, uint8_t value)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_outb_p(dev, reg_offset, value);
else
outb_p((unsigned char)value,
@@ -117,7 +117,7 @@ virtio_write_reg_2(struct virtio_hw *hw, uint64_t reg_offset, uint16_t value)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_outw_p(dev, reg_offset, value);
else
outw_p((unsigned short)value,
@@ -130,7 +130,7 @@ virtio_write_reg_4(struct virtio_hw *hw, uint64_t reg_offset, uint32_t value)
struct rte_pci_device *dev;
dev = hw->dev;
- if (dev->kdrv == RTE_KDRV_VFIO)
+ if (dev->kdrv == RTE_KDRV_VFIO_NOIOMMU)
ioport_outl_p(dev, reg_offset, value);
else
outl_p((unsigned int)value,
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0c667ff..2dbc658 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -149,6 +149,7 @@ enum rte_kernel_driver {
RTE_KDRV_VFIO,
RTE_KDRV_UIO_GENERIC,
RTE_KDRV_NIC_UIO,
+ RTE_KDRV_VFIO_NOIOMMU,
RTE_KDRV_NONE,
};
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index eb503f0..2936497 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -131,6 +131,7 @@ rte_eal_pci_map_device(struct rte_pci_device *dev)
/* try mapping the NIC resources using VFIO if it exists */
switch (dev->kdrv) {
case RTE_KDRV_VFIO:
+ case RTE_KDRV_VFIO_NOIOMMU:
#ifdef VFIO_PRESENT
if (pci_vfio_is_enabled())
ret = pci_vfio_map_resource(dev);
@@ -158,6 +159,7 @@ rte_eal_pci_unmap_device(struct rte_pci_device *dev)
/* try unmapping the NIC resources using VFIO if it exists */
switch (dev->kdrv) {
case RTE_KDRV_VFIO:
+ case RTE_KDRV_VFIO_NOIOMMU:
RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
break;
case RTE_KDRV_IGB_UIO:
@@ -353,9 +355,12 @@ pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
}
if (!ret) {
- if (!strcmp(driver, "vfio-pci"))
- dev->kdrv = RTE_KDRV_VFIO;
- else if (!strcmp(driver, "igb_uio"))
+ if (!strcmp(driver, "vfio-pci")) {
+ if (pci_vfio_is_noiommu(dev) == 0)
+ dev->kdrv = RTE_KDRV_VFIO_NOIOMMU;
+ else
+ dev->kdrv = RTE_KDRV_VFIO;
+ } else if (!strcmp(driver, "igb_uio"))
dev->kdrv = RTE_KDRV_IGB_UIO;
else if (!strcmp(driver, "uio_pci_generic"))
dev->kdrv = RTE_KDRV_UIO_GENERIC;
@@ -630,6 +635,7 @@ int rte_eal_pci_read_bar(const struct rte_pci_device *device,
switch (device->kdrv) {
case RTE_KDRV_VFIO:
+ case RTE_KDRV_VFIO_NOIOMMU:
return pci_vfio_read_bar(intr_handle, buf, len,
offset, bar_idx);
default:
@@ -647,6 +653,7 @@ int rte_eal_pci_write_bar(const struct rte_pci_device *device,
switch (device->kdrv) {
case RTE_KDRV_VFIO:
+ case RTE_KDRV_VFIO_NOIOMMU:
return pci_vfio_write_bar(intr_handle, buf, len,
offset, bar_idx);
default:
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index 3bc592b..60b95d7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -60,6 +60,7 @@ int pci_uio_write_config(const struct rte_intr_handle *intr_handle,
int pci_vfio_enable(void);
int pci_vfio_is_enabled(void);
+int pci_vfio_is_noiommu(struct rte_pci_device *pci_dev);
int pci_vfio_mp_sync_setup(void);
/* access config space */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index df407ef..31d688b 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -973,4 +973,73 @@ pci_vfio_is_enabled(void)
{
return vfio_cfg.vfio_enabled;
}
+
+int
+pci_vfio_is_noiommu(struct rte_pci_device *pci_dev)
+{
+ FILE *fp;
+ struct rte_pci_addr *loc;
+ const char *path = "/sys/module/vfio/parameters/enable_unsafe_noiommu_mode";
+ char filename[PATH_MAX] = {0};
+ char buf[PATH_MAX] = {0};
+
+ /*
+ * 1. chk vfio-noiommu mode set in kernel driver
+ * 2. verify pci device attached to vfio-noiommu driver
+ * example:
+ * cd /sys/bus/pci/drivers/vfio-pci/<virtio_dev_addr>/iommu_group
+ * > cat name
+ * > vfio-noiommu --> means virtio_dev attached to vfio-noiommu driver
+ */
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ RTE_LOG(ERR, EAL, "can't open %s\n", path);
+ return -1;
+ }
+
+ if (fread(buf, sizeof(char), 1, fp) != 1) {
+ RTE_LOG(ERR, EAL, "can't read from file %s\n", path);
+ fclose(fp);
+ return -1;
+ }
+
+ if (strncmp(buf, "Y", 1) != 0) {
+ RTE_LOG(ERR, EAL, "[%s]: vfio: noiommu mode not set\n", path);
+ fclose(fp);
+ return -1;
+ }
+
+ fclose(fp);
+
+ /* 2. chk whether attached driver is vfio-noiommu or not */
+ loc = &pci_dev->addr;
+ snprintf(filename, sizeof(filename),
+ SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/iommu_group/name",
+ loc->domain, loc->bus, loc->devid, loc->function);
+
+ /* check for vfio-noiommu */
+ fp = fopen(filename, "r");
+ if (fp == NULL) {
+ RTE_LOG(ERR, EAL, "can't open %s\n", filename);
+ return -1;
+ }
+
+ if (fread(buf, sizeof(char), sizeof("vfio-noiommu"), fp) !=
+ sizeof("vfio-noiommu")) {
+ RTE_LOG(ERR, EAL, "can't read from file %s\n", filename);
+ fclose(fp);
+ return -1;
+ }
+
+ if (strncmp(buf, "vfio-noiommu", strlen("vfio-noiommu")) != 0) {
+ RTE_LOG(ERR, EAL, "not a vfio-noiommu driver\n");
+ fclose(fp);
+ return -1;
+ }
+
+ fclose(fp);
+
+ return 0;
+}
#endif
--
1.7.9.5
next prev parent reply other threads:[~2016-01-19 11:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 11:46 [dpdk-dev] [PATCH v5 00/11] Add virtio support for arm/arm64 Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 01/11] virtio: Introduce config RTE_VIRTIO_INC_VECTOR Santosh Shukla
2016-01-27 2:23 ` Santosh Shukla
2016-01-27 2:33 ` Yuanhan Liu
2016-01-29 4:32 ` Santosh Shukla
2016-01-29 4:42 ` Yuanhan Liu
2016-01-29 4:45 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 02/11] linuxapp: eal: arm: Always return 0 for rte_eal_iopl_init() Santosh Shukla
2016-01-21 9:41 ` David Marchand
2016-01-21 10:07 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 03/11] linuxapp/vfio: ignore mapping for ioport region Santosh Shukla
2016-01-27 2:24 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 04/11] virtio_pci.h: build fix for sys/io.h for non-x86 arch Santosh Shukla
2016-01-27 2:25 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 05/11] eal: pci: vfio: add rd/wr func for pci bar space Santosh Shukla
2016-01-21 9:42 ` David Marchand
2016-01-21 10:08 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 06/11] virtio: vfio: add api support to rd/wr ioport bar Santosh Shukla
2016-01-29 7:07 ` Yuanhan Liu
2016-01-29 7:16 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 07/11] virtio: pci: extend virtio pci rw api for vfio interface Santosh Shukla
2016-01-19 11:46 ` Santosh Shukla [this message]
2016-01-19 14:18 ` [dpdk-dev] [PATCH v5 08/11] eal: pci: introduce RTE_KDRV_VFIO_NOIOMMUi driver mode Burakov, Anatoly
2016-01-19 18:36 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 09/11] virtio_pci: do not parse if interface is vfio-noiommu Santosh Shukla
2016-01-29 7:17 ` Yuanhan Liu
2016-01-29 7:22 ` Santosh Shukla
2016-01-29 7:34 ` Yuanhan Liu
2016-01-29 9:02 ` Thomas Monjalon
2016-01-29 9:14 ` Yuanhan Liu
2016-01-29 9:16 ` Santosh Shukla
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 10/11] virtio: pci: add dummy func definition for in/outb for non-x86 arch Santosh Shukla
2016-01-27 10:37 ` Santosh Shukla
2016-01-29 7:01 ` Yuanhan Liu
2016-01-29 7:31 ` Santosh Shukla
2016-01-29 7:38 ` Yuanhan Liu
2016-01-19 11:46 ` [dpdk-dev] [PATCH v5 11/11] vfio: Support for no-IOMMU mode Santosh Shukla
2016-01-25 7:25 ` [dpdk-dev] [PATCH v5 00/11] Add virtio support for arm/arm64 Santosh Shukla
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=1453203972-24855-9-git-send-email-sshukla@mvista.com \
--to=sshukla@mvista.com \
--cc=dev@dpdk.org \
/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).