From patchwork Mon Mar 16 20:38:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Christensen X-Patchwork-Id: 66737 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6056CA0559; Mon, 16 Mar 2020 21:38:39 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 015191C029; Mon, 16 Mar 2020 21:38:39 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by dpdk.org (Postfix) with ESMTP id C52172BF9 for ; Mon, 16 Mar 2020 21:38:37 +0100 (CET) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02GKWW3U074187 for ; Mon, 16 Mar 2020 16:38:36 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yrue28hhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Mar 2020 16:38:36 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.27/8.16.0.27) with SMTP id 02GKUotm013492 for ; Mon, 16 Mar 2020 20:38:35 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma04wdc.us.ibm.com with ESMTP id 2yrpw6arqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 16 Mar 2020 20:38:35 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02GKcZmc35848664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Mar 2020 20:38:35 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 379D1AC05B; Mon, 16 Mar 2020 20:38:35 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21AB8AC059; Mon, 16 Mar 2020 20:38:35 +0000 (GMT) Received: from localhost.localdomain (unknown [9.114.224.51]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 16 Mar 2020 20:38:35 +0000 (GMT) From: David Christensen To: dev@dpdk.org Cc: David Christensen Date: Mon, 16 Mar 2020 13:38:28 -0700 Message-Id: <20200316203828.27279-1-drc@linux.vnet.ibm.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200226195033.33877-1-drc@linux.vnet.ibm.com> References: <20200226195033.33877-1-drc@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-16_09:2020-03-12, 2020-03-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 phishscore=0 adultscore=0 mlxlogscore=999 suspectscore=3 clxscore=1015 lowpriorityscore=0 priorityscore=1501 spamscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003160084 Subject: [dpdk-dev] [PATCH v2] bus/pci: support iova=va on PowerNV systems 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" All recent POWER systems, Power 8 and 9 specifically, support an IOMMU (it can't be disabled). The functionality of the IOMMU is different depending on whether it's running on a bare metal PowerNV system or in a virtual environment (PowerVM LPAR or KVM/QEMU). DPDK currently supports the IOMMU found on PowerNV platforms, sPAPRv2, so IOVA=VA mode can be enabled when the correct platform is detected. The POWER IOMMU type can't be detected through mechansims such as parsing files in the /sys heirarchy like x86_64 systems so the /proc/cpuinfo file is parsed to determine whether Linux is running on bare metal (i.e. PowerNV) or in a virtual environment (KVM/QEMU). Signed-off-by: David Christensen --- v2: * Fixed memory leak from use of getline * Fixed nits for NULL memory address and indent levels * Modified commit message description on logic for detecting IOMMU on a POWER system --- drivers/bus/pci/linux/pci.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index 740a2cdad..a1e30b721 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -549,7 +549,40 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev) bool pci_device_iommu_support_va(__rte_unused const struct rte_pci_device *dev) { - return false; + /* + * IOMMU is always present on a PowerNV host (IOMMUv2). + * IOMMU is also present in a KVM/QEMU VM (IOMMUv1) but is not + * currently supported by DPDK. Test for our current environment + * and report VA support as appropriate. + */ + + char *line = NULL; + size_t len = 0; + char filename[PATH_MAX] = "/proc/cpuinfo"; + FILE *fp = fopen(filename, "r"); + bool ret = false; + + if (fp == NULL) { + RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", + __func__, filename, strerror(errno)); + return ret; + } + + /* Check for a PowerNV platform */ + while (getline(&line, &len, fp) != -1) { + if (strstr(line, "platform") != NULL) + continue; + + if (strstr(line, "PowerNV") != NULL) { + RTE_LOG(DEBUG, EAL, "Running on a PowerNV system\n"); + ret = true; + break; + } + } + + free(line); + fclose(fp); + return ret; } #else bool