From 905215731833c88f31766e6fa80398bd18d29ca8 Mon Sep 17 00:00:00 2001 From: David Christensen Date: Mon, 16 Mar 2020 13:38:28 -0700 Subject: [PATCH] bus/pci: support IOVA as VA on PowerNV systems 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 mechanisms such as parsing files in the /sys hierarchy 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 --- 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 71b0a3053d..ca783b1575 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -554,7 +554,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 -- 2.20.1