Skip to contentSkip to conversation

Using virtio ethdev ports as non-root

RFC PATCH New David Marchand 1 participant 3 messages Sep 6, 2019 Network drivers

lore
Share & tools
lore
#0 lore raw

cover Using virtio ethdev ports as non-root

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.

Signature · 13 lines
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
#1 lore raw

RFC PATCH 1/2 bus/pci: check IO permissions for UIO only

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.

---
 drivers/bus/pci/bsd/pci.c   |  5 +++++
 drivers/bus/pci/linux/pci.c | 10 ++++++++++
 2 files changed, 15 insertions(+)
drivers/bus/pci/bsd/pci.c +5 -0
index 8f07ed9..27d0488 100644
@@ -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;
drivers/bus/pci/linux/pci.c +10 -0
index 43debaa..7f66500 100644
@@ -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)
Signature · 1 line
1.8.3.1
#2 lore raw

RFC PATCH 2/2 net/virtio: do not require IO permissions

In reply to David Marchand

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.

---
 drivers/net/virtio/virtio_ethdev.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -6
index f96588b..ebbd561 100644
@@ -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);
 }
 
Signature · 1 line
1.8.3.1