From patchwork Sun Oct 20 12:29:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 61485 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 539B64C93; Sun, 20 Oct 2019 14:30:18 +0200 (CEST) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id DC5C64C90 for ; Sun, 20 Oct 2019 14:30:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571574616; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ceGlruxlZxhvHIIsuQfJcmHuS+Z0TqT1mpwD1Rb/g40=; b=IchBiBl6juWbM2LzkR8daVuAt7wUTx2n7RHygrA5Va8xmbxhHf4YbmDy+LyHXIsQXQmlQA tP/ofywYTtvBhIA7yQG82HlJaYzLD627d0LhOHAxGvm3hDgozP3DZeR9kfSqU5n2l0VtlY 4Lsi9ySjAUyVpHhAoiIHWcNQLiJseFc= 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-179-rnWFCcnNPaa5eA0iGLGreA-1; Sun, 20 Oct 2019 08:30:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D1541800DD6 for ; Sun, 20 Oct 2019 12:30:13 +0000 (UTC) Received: from dmarchan.remote.csb (ovpn-204-16.brq.redhat.com [10.40.204.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59A485D9C9 for ; Sun, 20 Oct 2019 12:30:12 +0000 (UTC) From: David Marchand To: dev@dpdk.org Date: Sun, 20 Oct 2019 14:29:58 +0200 Message-Id: <1571574599-25022-2-git-send-email-david.marchand@redhat.com> In-Reply-To: <1571574599-25022-1-git-send-email-david.marchand@redhat.com> References: <1571313388-32142-1-git-send-email-david.marchand@redhat.com> <1571574599-25022-1-git-send-email-david.marchand@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: rnWFCcnNPaa5eA0iGLGreA-1 X-Mimecast-Spam-Score: 0 Subject: [dpdk-dev] [PATCH v2 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 --- 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 | 10 ++++++++++ 2 files changed, 15 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..7b46fe1 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(ERR, EAL, "%s(): insufficient ioport permissions for PCI device %s\n", + __func__, dev->name); + 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)