From patchwork Fri Sep 6 09:58:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 58819 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 527281F2EE; Fri, 6 Sep 2019 11:59:06 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 732801F2EC for ; Fri, 6 Sep 2019 11:59:04 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DCDA2307D844 for ; Fri, 6 Sep 2019 09:59:03 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-127.brq.redhat.com [10.40.204.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id E686960BF1 for ; Fri, 6 Sep 2019 09:59:02 +0000 (UTC) From: David Marchand To: dev@dpdk.org Date: Fri, 6 Sep 2019 11:58:28 +0200 Message-Id: <1567763909-307-2-git-send-email-david.marchand@redhat.com> In-Reply-To: <1567763909-307-1-git-send-email-david.marchand@redhat.com> References: <1567763909-307-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 06 Sep 2019 09:59:03 +0000 (UTC) Subject: [dpdk-dev] [RFC PATCH 1/2] bus/pci: check IO permissions for UIO only X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "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 --- 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) From patchwork Fri Sep 6 09:58:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 58820 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 17FDD1F2F9; Fri, 6 Sep 2019 11:59:10 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 206F11F2ED for ; Fri, 6 Sep 2019 11:59:09 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44ADD190C107; Fri, 6 Sep 2019 09:59:08 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-127.brq.redhat.com [10.40.204.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59DAF60BF1; Fri, 6 Sep 2019 09:59:04 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Maxime Coquelin , Tiwei Bie , Zhihong Wang Date: Fri, 6 Sep 2019 11:58:29 +0200 Message-Id: <1567763909-307-3-git-send-email-david.marchand@redhat.com> In-Reply-To: <1567763909-307-1-git-send-email-david.marchand@redhat.com> References: <1567763909-307-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Fri, 06 Sep 2019 09:59:08 +0000 (UTC) Subject: [dpdk-dev] [RFC PATCH 2/2] net/virtio: do not require IO permissions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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); }