From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A9C24A0C53 for ; Mon, 25 Oct 2021 14:21:19 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 19EE7410EB; Mon, 25 Oct 2021 14:21:19 +0200 (CEST) Received: from AZHDRRW-EX02.NVIDIA.COM (azhdrrw-ex02.nvidia.com [20.64.145.131]) by mails.dpdk.org (Postfix) with ESMTP id 80DAC4003E; Mon, 25 Oct 2021 14:21:14 +0200 (CEST) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.107) by mxs.oss.nvidia.com (10.13.234.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Mon, 25 Oct 2021 05:21:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EUluUP7AHmfxe7/9zriC6Pc3pgf00mJTZBhAofsiqio9TFBiCqRzzhos7LHp381sjZxRWdVZthZIzE8t6NHX11c18xI3lVkeOJbcWanf2eTbY9+ee+b06ES6TsxhvUFXDLZKAh/YBYnP+Gc9Iw2mq45+fO1tkJb/BBf0NjVDJTQrEQRDL3NGP9CZDT9SEXBrnbcVZ641MlKu+wyyEAviQjwpPFfdnauRUgKDJp9gGncv4OQWI8ntF8kMsrY1yyrMgnlPwJzBh0v1bOJLNPdwm9Txx4YkbVjGwZaZXHsaa1sLcciZRlejk1sKys91KvkJgv13mnoP/jdu5oDTjYmpVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YxiYI7noZ00mvN5wqzTnQM65brmClTAWKUmz2+MfvaU=; b=PsXztW4vh45dpCFRRUz6xQhy7ZVoreJDpVvhQJJSGGLqSlI6TTqx8d7cZ8UUaBWaslE0s0kuTrUHoijcytzN6pGTcPb8sB3DVEaucHojaq36YL8TlQlSFv4wJf8oQrMFwLtRb/6uhLX3HlYAEDTr8EpvJ9h9gTYCbUuPcwE5yTdcwZEY2WRQmMTkmRIfSHOQc083wc8Ja3RV1OXz5F9hUzf4excwU40PBXpxu4/waiiRX2wk3/G1U0cpyVzeF4uhY7Ww/iSYl75lNObJvjNombZVpOf2r1lGcz4cu2zhWSDtC589QJd7YAzZA6o82RqD/52xiihHn9O3mSU1TfWUDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=linux.microsoft.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YxiYI7noZ00mvN5wqzTnQM65brmClTAWKUmz2+MfvaU=; b=F67qu6xpOAYQR0NyadS4RHTXEEsvbsyjmGo1Vsww/wx/G2i3lBK8Rahmc0iUtZT4QfrxSUIOjnOj439t21KBvRdbAp69PEspw6Dg4PebIg5iVy952N/88McmFFXdePk4CPaNI/PbfHqQpe74VmR4EhLmnNEMpfwfe5/7Gp3oIxfvzhGCNzBT4sUPHIS2JajSeju9g3Fl+gVWvmAXSlGDE76vQiiK6oJ9abFW3XzqPGpBPHWlS67rVihvBd2HEK9ghzHgZQTCCE2kJqYjb/ljnVZFlTBl3IlwhhnQBtdk7qxNSYnZApktieddQqlpTyWV0zq9J5SduzHn0ywbNgAZnw== Received: from CO2PR04CA0166.namprd04.prod.outlook.com (2603:10b6:104:4::20) by BN6PR12MB1875.namprd12.prod.outlook.com (2603:10b6:404:103::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Mon, 25 Oct 2021 12:21:10 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:104:4:cafe::c2) by CO2PR04CA0166.outlook.office365.com (2603:10b6:104:4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Mon, 25 Oct 2021 12:21:09 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; linux.microsoft.com; dkim=none (message not signed) header.d=none;linux.microsoft.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Mon, 25 Oct 2021 12:21:09 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 25 Oct 2021 12:21:07 +0000 From: Dmitry Kozlyuk To: CC: , Tal Shnaiderman , Dmitry Kozlyuk , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Mon, 25 Oct 2021 15:20:52 +0300 Message-ID: <20211025122053.326790-1-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 44256a17-2e7f-4e6e-639f-08d997b1ed5b X-MS-TrafficTypeDiagnostic: BN6PR12MB1875: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ViGd8AmsWgqf5408DI2P2aJtS6yoi+62JbrLqx3P+yL8w0Ag+5IPvfBEUPvHxRwdV5q77Yr13XFgptA//IePmC8FsszsRZTt9+rs4fyaEWfWWR0DnEpxChzJWJ9kX6fpBYeGWXND+09Jjvx5vDkD+nVw/guNilFu6ItDgL8Jk74kmId+bBVtuvqWfCcx9CBNWvrPGVA1dnrZl8P4T5TY7Qc9Ysc/extg+Ipyde2Xeib6fXtoX9RmcseinBIlmup9VVfyGwlrInQkGzVY/wvjDIz2I8Ky8RKJ4z2LA7nheuMWlHKsIFd3KrJZyM4mxlydghhZukbrQApqvn4b7fqyG723lwSZk6bq22Gm/Yae3/kuo32cx2yQRPMCL4CPE1HF5Ie5BX9hvglYFTXU7q256qa5x1XgG0/C0vvS+KMRouncGCi6Inxx/cfOy4lZD4RIkEPEjjrjzdYwl5d9IvkyK5A1mGngmPEDjRU6Kw55bRtvh0jhKgnDUjnONwRoInlb0SN8Q1y5zNZ2h1i1o+zH1/RIx2HJxCPYjKWGcdYYn9T2o0s/+2jDRxsAulpiinxphcj5nw6WV4aB05BEdngbhykNe2OX4s2n1KIppRgeSXk03rC984i+PrHWKUkWO6ZTFTT3QebGe+tGn8J7sm1Nrufsqz4OgE/4AqUQSALpXA3sh5GX7zEIyxTsxLloAD/EK0d0au1ILk2cz+nOL3SYnQ== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(316002)(36906005)(2906002)(47076005)(5660300002)(86362001)(6286002)(450100002)(4326008)(7636003)(6916009)(70206006)(70586007)(54906003)(82310400003)(1076003)(107886003)(7696005)(8676002)(2616005)(16526019)(36756003)(356005)(83380400001)(6666004)(186003)(508600001)(426003)(336012)(8936002)(55016002)(36860700001)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2021 12:21:09.5661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44256a17-2e7f-4e6e-639f-08d997b1ed5b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1875 Subject: [dpdk-stable] [PATCH] eal/windows: fix IOVA mode detection and handling X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Windows EAL did not detect IOVA mode and worked incorrectly if physical addresses could not be obtained (if virt2phys driver was missing or inaccessible). In this case, rte_mem_virt2iova() reported RTE_BAD_IOVA for any address. Inability to obtain IOVA, be it PA or VA, should cause a failure for the DPDK allocator, but it was hidden by the implementation, so allocations did not fail when they should. The mode when DPDK cannot obtain PA but can work is IOVA-as-VA mode. However, rte_eal_iova_mode() always returned RTE_IOVA_DC (while it should only ever return RTE_IOVA_PA or RTE_IOVA_VA), because IOVA mode detection was not implemented. Implement IOVA mode detection: 1. Always allow to force --iova-mode=va. 2. Allow to force --iova-mode=pa only if virt2phys is available. 3. If no mode is forced and virt2phys is available, select the mode according to bus requests, default to PA. 4. If no mode is forced but virt2phys is unavailable, default to VA. Fix rte_mem_virt2iova() by returning VA when using IOVA-as-VA. Fix rte_eal_iova_mode() by returning the selected mode. Fixes: 2a5d547a4a9b ("eal/windows: implement basic memory management") Cc: stable@dpdk.org Reported-by: Tal Shnaiderman Signed-off-by: Dmitry Kozlyuk --- Fixes tag points to the commit that introduced the wrong behavior. Commit fec28ca0e3a9 ("net/mlx5: support mempool registration") exposed it, because since commit 11541c5c81dd ("mempool: add non-IO flag") RTE_MEMPOOL_F_NON_IO was mistakenly set for all mempools on Windows when virt2phys was not available. lib/eal/windows/eal.c | 63 ++++++++++++++++++++++++---------- lib/eal/windows/eal_memalloc.c | 15 +++----- lib/eal/windows/eal_memory.c | 6 ++-- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 3d8c520412..f7ce1b6671 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -276,6 +276,8 @@ rte_eal_init(int argc, char **argv) const struct rte_config *config = rte_eal_get_configuration(); struct internal_config *internal_conf = eal_get_internal_configuration(); + bool has_phys_addr; + enum rte_iova_mode iova_mode; int ret; eal_log_init(NULL, 0); @@ -322,18 +324,59 @@ rte_eal_init(int argc, char **argv) internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE; } + if (rte_eal_intr_init() < 0) { + rte_eal_init_alert("Cannot init interrupt-handling thread"); + return -1; + } + + if (rte_eal_timer_init() < 0) { + rte_eal_init_alert("Cannot init TSC timer"); + rte_errno = EFAULT; + return -1; + } + + bscan = rte_bus_scan(); + if (bscan < 0) { + rte_eal_init_alert("Cannot scan the buses"); + rte_errno = ENODEV; + return -1; + } + if (eal_mem_win32api_init() < 0) { rte_eal_init_alert("Cannot access Win32 memory management"); rte_errno = ENOTSUP; return -1; } + has_phys_addr = true; if (eal_mem_virt2iova_init() < 0) { /* Non-fatal error if physical addresses are not required. */ - RTE_LOG(WARNING, EAL, "Cannot access virt2phys driver, " + RTE_LOG(DEBUG, EAL, "Cannot access virt2phys driver, " "PA will not be available\n"); + has_phys_addr = false; } + iova_mode = internal_conf->iova_mode; + if (iova_mode == RTE_IOVA_PA && !has_phys_addr) { + rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available"); + rte_errno = EINVAL; + return -1; + } + if (iova_mode == RTE_IOVA_DC) { + RTE_LOG(DEBUG, EAL, "Specific IOVA mode is not requested, autodetecting\n"); + if (has_phys_addr) { + RTE_LOG(DEBUG, EAL, "Selecting IOVA mode according to bus requests\n"); + iova_mode = rte_bus_get_iommu_class(); + if (iova_mode == RTE_IOVA_DC) + iova_mode = RTE_IOVA_PA; + } else { + iova_mode = RTE_IOVA_VA; + } + } + RTE_LOG(DEBUG, EAL, "Selected IOVA mode '%s'\n", + iova_mode == RTE_IOVA_PA ? "PA" : "VA"); + rte_eal_get_configuration()->iova_mode = iova_mode; + if (rte_eal_memzone_init() < 0) { rte_eal_init_alert("Cannot init memzone"); rte_errno = ENODEV; @@ -358,27 +401,9 @@ rte_eal_init(int argc, char **argv) return -1; } - if (rte_eal_intr_init() < 0) { - rte_eal_init_alert("Cannot init interrupt-handling thread"); - return -1; - } - - if (rte_eal_timer_init() < 0) { - rte_eal_init_alert("Cannot init TSC timer"); - rte_errno = EFAULT; - return -1; - } - __rte_thread_init(config->main_lcore, &lcore_config[config->main_lcore].cpuset); - bscan = rte_bus_scan(); - if (bscan < 0) { - rte_eal_init_alert("Cannot init PCI"); - rte_errno = ENODEV; - return -1; - } - RTE_LCORE_FOREACH_WORKER(i) { /* diff --git a/lib/eal/windows/eal_memalloc.c b/lib/eal/windows/eal_memalloc.c index 4459d59b1a..55d6dcc71c 100644 --- a/lib/eal/windows/eal_memalloc.c +++ b/lib/eal/windows/eal_memalloc.c @@ -99,16 +99,11 @@ alloc_seg(struct rte_memseg *ms, void *requested_addr, int socket_id, */ *(volatile int *)addr = *(volatile int *)addr; - /* Only try to obtain IOVA if it's available, so that applications - * that do not need IOVA can use this allocator. - */ - if (rte_eal_using_phys_addrs()) { - iova = rte_mem_virt2iova(addr); - if (iova == RTE_BAD_IOVA) { - RTE_LOG(DEBUG, EAL, - "Cannot get IOVA of allocated segment\n"); - goto error; - } + iova = rte_mem_virt2iova(addr); + if (iova == RTE_BAD_IOVA) { + RTE_LOG(DEBUG, EAL, + "Cannot get IOVA of allocated segment\n"); + goto error; } /* Only "Ex" function can handle hugepages. */ diff --git a/lib/eal/windows/eal_memory.c b/lib/eal/windows/eal_memory.c index 71741fc07e..2fd37d9708 100644 --- a/lib/eal/windows/eal_memory.c +++ b/lib/eal/windows/eal_memory.c @@ -225,19 +225,17 @@ rte_mem_virt2phy(const void *virt) return phys.QuadPart; } -/* Windows currently only supports IOVA as PA. */ rte_iova_t rte_mem_virt2iova(const void *virt) { phys_addr_t phys; - if (virt2phys_device == INVALID_HANDLE_VALUE) - return RTE_BAD_IOVA; + if (rte_eal_iova_mode() == RTE_IOVA_VA) + return (rte_iova_t)virt; phys = rte_mem_virt2phy(virt); if (phys == RTE_BAD_PHYS_ADDR) return RTE_BAD_IOVA; - return (rte_iova_t)phys; } -- 2.25.1