From patchwork Tue Oct 22 08:21:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 61628 X-Patchwork-Delegate: david.marchand@redhat.com 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 60D244CE4; Tue, 22 Oct 2019 10:22:05 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by dpdk.org (Postfix) with ESMTP id 95A384C90 for ; Tue, 22 Oct 2019 10:22:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571732522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qL9GhC0UMM0SnICdLjt5qf+Rvie016JKARNmhOEm6vI=; b=ZJWrKqtRNPyKLPqmFz14luGPjPHGILbrT63fiA/HXCeCXxNopPvZkJmgpp6tfBXfUz98Ko 40Yikm6uhx+T7Gqo8v7TYkXdiAd8FxXSvMLXx9QGbXL384pLFsWRoPxCfqbOAMykgcO+T6 ncN5m3kMXmn7iuNdNlaGJT+HxzFbROA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-SQ45gMkBN-KneRrF1FRn8A-1; Tue, 22 Oct 2019 04:22:00 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 006781800D6A; Tue, 22 Oct 2019 08:22:00 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-129.brq.redhat.com [10.40.204.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EB2860C57; Tue, 22 Oct 2019 08:21:57 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, Ferruh Yigit Date: Tue, 22 Oct 2019 10:21:42 +0200 Message-Id: <1571732503-30424-2-git-send-email-david.marchand@redhat.com> In-Reply-To: <1571732503-30424-1-git-send-email-david.marchand@redhat.com> References: <1571313388-32142-1-git-send-email-david.marchand@redhat.com> <1571732503-30424-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: SQ45gMkBN-KneRrF1FRn8A-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH v3 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 Reviewed-by: Maxime Coquelin --- Changelog since v2: - do not switch to pci_ioport_map in igb_uio case, add a check on iopl there too, Changelog since v1: - change log message level from DEBUG to ERR, - add device name in log message, --- drivers/bus/pci/bsd/pci.c | 5 +++++ drivers/bus/pci/linux/pci.c | 6 ++++++ drivers/bus/pci/linux/pci_uio.c | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 7777179..ebbfeb1 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -539,6 +539,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(ERR, EAL, "%s(): insufficient ioport permissions for PCI device %s\n", + __func__, dev->name); + 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 318db19..740a2cd 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -657,6 +657,12 @@ pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused, int found = 0; size_t linesz; + if (rte_eal_iopl_init() != 0) { + RTE_LOG(ERR, EAL, "%s(): insufficient ioport permissions for PCI device %s\n", + __func__, dev->name); + return -1; + } + snprintf(pci_id, sizeof(pci_id), PCI_PRI_FMT, dev->addr.domain, dev->addr.bus, dev->addr.devid, dev->addr.function); diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index e031361..6dca05a 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -375,6 +375,12 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, int uio_num; unsigned long start; + if (rte_eal_iopl_init() != 0) { + RTE_LOG(ERR, EAL, "%s(): insufficient ioport permissions for PCI device %s\n", + __func__, dev->name); + return -1; + } + uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname), 0); if (uio_num < 0) return -1; From patchwork Tue Oct 22 08:21:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 61629 X-Patchwork-Delegate: david.marchand@redhat.com 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 0B42A1B94A; Tue, 22 Oct 2019 10:22:09 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 2192FF04 for ; Tue, 22 Oct 2019 10:22:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571732526; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rbrogettcKpP4nHURRilyn1GPxCxNz65MKTNw86On/g=; b=A2aPHdPYAwfrtPtmdyKLyRiMXe763EfLL83SWYuHW4H+19I7hY0TuYWlkdfazDRfbsiXt3 nLlPiulWvV3ftg1eJjwxUPxQqblib5QZIYGeYbx+avDldAqD83po+FXMSlLKS3xRDrZLDq toWMrZGw6TUH97J1eu5EX1P9UsZdXmU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-74-ajI7fAWKPuqbBtYGGzgDRA-1; Tue, 22 Oct 2019 04:22:02 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B0CE51005500; Tue, 22 Oct 2019 08:22:01 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-129.brq.redhat.com [10.40.204.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 70B6B60C57; Tue, 22 Oct 2019 08:22:00 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, Tiwei Bie , Zhihong Wang Date: Tue, 22 Oct 2019 10:21:43 +0200 Message-Id: <1571732503-30424-3-git-send-email-david.marchand@redhat.com> In-Reply-To: <1571732503-30424-1-git-send-email-david.marchand@redhat.com> References: <1571313388-32142-1-git-send-email-david.marchand@redhat.com> <1571732503-30424-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: ajI7fAWKPuqbBtYGGzgDRA-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH v3 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 available to root user (or users that have the CAP_SYS_RAWIO capability). But those permissions are only needed when the virtio devices accesses are done with inb/outb instructions, which is when the device is bound to a UIO kernel module. So far, the virtio driver was refusing to register based on the check on IO permissions. This check does not make sense when binding the device to vfio. Now that the check on IO permissions has been abstracted in the ioport API, we can remove it on virtio side. We still need to call rte_eal_iopl_init() in the virtio constructor so that the interrupt thread inherits this permission in the case it could be used with UIO later. Signed-off-by: David Marchand Reviewed-by: Maxime Coquelin Acked-by: Tiwei Bie --- Changelog since v1: - remove log message in constructor (thanks Tiwei), - reword commit log, --- drivers/net/virtio/virtio_ethdev.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 7261109..0a2ed2e 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -1995,11 +1995,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;