From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 7B96BA045E for ; Thu, 30 May 2019 23:31:58 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A61281B9B1; Thu, 30 May 2019 23:31:04 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 7A7981B944 for ; Thu, 30 May 2019 23:30:28 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 May 2019 14:30:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,532,1549958400"; d="scan'208";a="180089099" Received: from bwalker-desk.ch.intel.com ([143.182.136.145]) by fmsmga002.fm.intel.com with ESMTP; 30 May 2019 14:30:25 -0700 From: Ben Walker To: dev@dpdk.org Cc: Ben Walker Date: Thu, 30 May 2019 14:29:59 -0700 Message-Id: <20190530212959.1205097-12-benjamin.walker@intel.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190530212959.1205097-1-benjamin.walker@intel.com> References: <20190530174819.1160221-2-benjamin.walker@intel.com> <20190530212959.1205097-1-benjamin.walker@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 12/12] eal: If bus can't decide PA or VA, try to access PA 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" If the bus can't determine a preference for IOVA_PA vs. IOVA_VA by looking at the devices and drivers, as a last resort test if physical addresses are even accessible in /proc/self/pagemap. If they are, use IOVA_PA. If they are not, use IOVA_VA. Signed-off-by: Ben Walker --- lib/librte_eal/common/eal_common_bus.c | 4 ---- lib/librte_eal/linux/eal/eal.c | 30 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c index c8f1901f0..77f1be1b4 100644 --- a/lib/librte_eal/common/eal_common_bus.c +++ b/lib/librte_eal/common/eal_common_bus.c @@ -237,10 +237,6 @@ rte_bus_get_iommu_class(void) mode |= bus->get_iommu_class(); } - if (mode != RTE_IOVA_VA) { - /* Use default IOVA mode */ - mode = RTE_IOVA_PA; - } return mode; } diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c index 161399619..af9c003a7 100644 --- a/lib/librte_eal/linux/eal/eal.c +++ b/lib/librte_eal/linux/eal/eal.c @@ -948,6 +948,7 @@ rte_eal_init(int argc, char **argv) static char logid[PATH_MAX]; char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_MAX_THREAD_NAME_LEN]; + enum rte_iova_mode iova_mode; /* checks if the machine is adequate */ if (!rte_cpu_is_supported()) { @@ -1037,18 +1038,33 @@ rte_eal_init(int argc, char **argv) /* if no EAL option "--iova-mode=", use bus IOVA scheme */ if (internal_config.iova_mode == RTE_IOVA_DC) { - /* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */ - rte_eal_get_configuration()->iova_mode = - rte_bus_get_iommu_class(); + /* autodetect the IOVA mapping mode */ + iova_mode = rte_bus_get_iommu_class(); /* Workaround for KNI which requires physical address to work */ - if (rte_eal_get_configuration()->iova_mode == RTE_IOVA_VA && + if (iova_mode == RTE_IOVA_VA && rte_eal_check_module("rte_kni") == 1) { - rte_eal_get_configuration()->iova_mode = RTE_IOVA_PA; + iova_mode = RTE_IOVA_PA; RTE_LOG(WARNING, EAL, - "Some devices want IOVA as VA but PA will be used because.. " - "KNI module inserted\n"); + "Some devices want IOVA as VA but PA will be" + " used because KNI module inserted\n"); + } + + if (iova_mode == RTE_IOVA_DC) { + /* If the bus doesn't care, check if physical addresses are + * accessible. + */ + if (rte_eal_using_phys_addrs()) { + /* Physical addresses are available, so the safest + * choice is to use those. + */ + iova_mode = RTE_IOVA_PA; + } else { + iova_mode = RTE_IOVA_VA; + } } + + rte_eal_get_configuration()->iova_mode = iova_mode; } else { rte_eal_get_configuration()->iova_mode = internal_config.iova_mode; -- 2.20.1