DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [RFC PATCH 0/2] Using virtio ethdev ports as non-root
@ 2019-09-06  9:58 David Marchand
  2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 1/2] bus/pci: check IO permissions for UIO only David Marchand
  2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 2/2] net/virtio: do not require IO permissions David Marchand
  0 siblings, 2 replies; 3+ messages in thread
From: David Marchand @ 2019-09-06  9:58 UTC (permalink / raw)
  To: dev

I managed to run testpmd as non-root with virtio ports after quite some
tries.

Sending a first RFC with the (not so big) changes that are required on
the DPDK side.

I will come with a little howto for the non-RFC series for people
interested in this, since I had to align quite some stars to make it
work.

-- 
David Marchand

David Marchand (2):
  bus/pci: check IO permissions for UIO only
  net/virtio: do not require IO permissions

 drivers/bus/pci/bsd/pci.c          |  5 +++++
 drivers/bus/pci/linux/pci.c        | 10 ++++++++++
 drivers/net/virtio/virtio_ethdev.c |  8 ++------
 3 files changed, 17 insertions(+), 6 deletions(-)

-- 
1.8.3.1


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

* [dpdk-dev] [RFC PATCH 1/2] bus/pci: check IO permissions for UIO only
  2019-09-06  9:58 [dpdk-dev] [RFC PATCH 0/2] Using virtio ethdev ports as non-root David Marchand
@ 2019-09-06  9:58 ` David Marchand
  2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 2/2] net/virtio: do not require IO permissions David Marchand
  1 sibling, 0 replies; 3+ messages in thread
From: David Marchand @ 2019-09-06  9:58 UTC (permalink / raw)
  To: dev

On x86, calling inb/outb special instructions (used in uio ioport
read/write parts) is only possible if the right IO permissions has been
granted.

The only user of this API (the net/virtio pmd) checks this
unconditionnaly but this should be hidden by the rte_pci_ioport API
itself and only checked when the device is bound to a UIO driver.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/bus/pci/bsd/pci.c   |  5 +++++
 drivers/bus/pci/linux/pci.c | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index 8f07ed9..27d0488 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -540,6 +540,11 @@ rte_pci_ioport_map(struct rte_pci_device *dev, int bar,
 	switch (dev->kdrv) {
 #if defined(RTE_ARCH_X86)
 	case RTE_KDRV_NIC_UIO:
+		if (rte_eal_iopl_init() != 0) {
+			RTE_LOG(DEBUG, EAL, "%s(): cannot gain io permissions\n",
+				__func__);
+			return -1;
+		}
 		if ((uintptr_t) dev->mem_resource[bar].addr <= UINT16_MAX) {
 			p->base = (uintptr_t)dev->mem_resource[bar].addr;
 			ret = 0;
diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 43debaa..7f66500 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -661,6 +661,12 @@ pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
 		 dev->addr.domain, dev->addr.bus,
 		 dev->addr.devid, dev->addr.function);
 
+	if (rte_eal_iopl_init() != 0) {
+		RTE_LOG(DEBUG, EAL, "%s(): cannot gain io permissions\n",
+			__func__);
+		return -1;
+	}
+
 	fp = fopen("/proc/ioports", "r");
 	if (fp == NULL) {
 		RTE_LOG(ERR, EAL, "%s(): can't open ioports\n", __func__);
@@ -718,7 +724,11 @@ rte_pci_ioport_map(struct rte_pci_device *dev, int bar,
 		break;
 #endif
 	case RTE_KDRV_IGB_UIO:
+#if defined(RTE_ARCH_X86)
+		ret = pci_ioport_map(dev, bar, p);
+#else
 		ret = pci_uio_ioport_map(dev, bar, p);
+#endif
 		break;
 	case RTE_KDRV_UIO_GENERIC:
 #if defined(RTE_ARCH_X86)
-- 
1.8.3.1


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

* [dpdk-dev] [RFC PATCH 2/2] net/virtio: do not require IO permissions
  2019-09-06  9:58 [dpdk-dev] [RFC PATCH 0/2] Using virtio ethdev ports as non-root David Marchand
  2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 1/2] bus/pci: check IO permissions for UIO only David Marchand
@ 2019-09-06  9:58 ` David Marchand
  1 sibling, 0 replies; 3+ messages in thread
From: David Marchand @ 2019-09-06  9:58 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin, Tiwei Bie, Zhihong Wang

On x86, iopl permissions are only needed when the virtio devices are
bound to a uio kernel module.

When running a dpdk application as non root, the virtio driver was
refusing to register because of this check while it could work when
binding the device to vfio (requires to have a vIOMMU configured).

We still need to call rte_eal_iopl_init() in the constructor so that
the interrupt thread would inherit this permission in the case it could
be used with UIO later.
Log a warning message for the user to understand what is wrong.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index f96588b..ebbd561 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -1977,11 +1977,6 @@ exit:
 static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct rte_pci_device *pci_dev)
 {
-	if (rte_eal_iopl_init() != 0) {
-		PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-		return 1;
-	}
-
 	/* virtio pmd skips probe if device needs to work in vdpa mode */
 	if (vdpa_mode_selected(pci_dev->device.devargs))
 		return 1;
@@ -2013,7 +2008,8 @@ static struct rte_pci_driver rte_virtio_pmd = {
 
 RTE_INIT(rte_virtio_pmd_init)
 {
-	rte_eal_iopl_init();
+	if (rte_eal_iopl_init() != 0)
+		PMD_INIT_LOG(WARNING, "IOPL call failed - virtio devices won't be functional if bound to UIO drivers");
 	rte_pci_register(&rte_virtio_pmd);
 }
 
-- 
1.8.3.1


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

end of thread, other threads:[~2019-09-06  9:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-06  9:58 [dpdk-dev] [RFC PATCH 0/2] Using virtio ethdev ports as non-root David Marchand
2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 1/2] bus/pci: check IO permissions for UIO only David Marchand
2019-09-06  9:58 ` [dpdk-dev] [RFC PATCH 2/2] net/virtio: do not require IO permissions David Marchand

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