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 184CBA0C43; Fri, 22 Oct 2021 23:09:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D57994069D; Fri, 22 Oct 2021 23:09:41 +0200 (CEST) Received: from AZHDRRW-EX01.nvidia.com (azhdrrw-ex01.nvidia.com [20.51.104.162]) by mails.dpdk.org (Postfix) with ESMTP id 07B0E40150 for ; Fri, 22 Oct 2021 23:09:41 +0200 (CEST) Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.108) by mxs.oss.nvidia.com (10.13.234.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.858.15; Fri, 22 Oct 2021 14:09:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aYHWTVuLrq7NLogVLsvJWZ5klOV9Aw1XeTRKHwhgQFysfagCua0NQmApemP47Lma/PtYYf0jyp3+sTp7KMb6cbHMQ6fzp4e/o9xb/xjwUM6+XjHAs/FEFQ0kFcsun/594dUR3tIy+bN4k1czGG+rvm4JstV6sU0hlsXYMDZaE2lSvpUQvaUWtNtRqEvJgS8Z0u1nFZJ4xZkRaNYFSp3XnHNGNTDJnT9zJbc29/pMVWGnLXtd8ZsTl6ED7Xl4Qx68R7H+/nSb8rNoRLgNllBrupFXyglMaArl9Yahs/sL/pnBh9Mq2dV0/ogRGVPj15iemR0V9NlQ5ZYAMl0ttxLy9A== 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=mwGefMYmADAHIIyaezGY2qmbFNG2vS1OEdkU6tGU7Xo=; b=KzwowLFtV6CtrCqzAwVe667iONKklcYekBD1syqJqleFK2tuSF0BQ0A73Vz0EpvgDjSJWqHvZ4T0wghO339jpaPUyzQbdYrKzDjbk6ISbnNSY/S9PK6d4L+YlO2yqSQSZuy2oH3wHNSvx0P1yzKTHNNgIj9/F2ACSN/b4iaLrKZEGMcUYbwd9cRK959DrXjsA7GmNTxQFtfq+WXcae03vw2z0updonEWrWAs26b6ItIIw891NK0LXFabEiSbbd+qtfKsjaBsWyqG0Qr60Uzs3aryqqI5Wv6RVq5rZ7dcmmZcvcv5uMUkopD40Iwnil9Fpy8ERO3LbdD8c8SmHtdVfA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=oktetlabs.ru 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=mwGefMYmADAHIIyaezGY2qmbFNG2vS1OEdkU6tGU7Xo=; b=ADW7QK4X2inZIf7q6KEjuYbuJDwqDplz6flW1181TMelx3srOB5IPIcGSmPZ5YAFhSJ1ELADESrluB7MdPuykOvbuF+/DES5oE2ZJgPf5xRc4iQifAs5XzRp/UOoqbdoafH46th200ntEPh+gz/t0a9YhK0RZu8mYFQgsYWcPOYCQVOFSIyutkfobiDCtWFb7Wlfk4K61xGNl86W86sSIXNnJNKKavpqQcdH0Y2TSr0SNbWCbMZAfTr3vjNaPXhJ3JkwiJqnXW+0JKwyCAMtK1i6HNYIU58FhOSpznTiu23GoCGXCahVJVK5+V9OptDYOHCFF5cn/xT1amL9ZnhHNQ== Received: from DM5PR2201CA0017.namprd22.prod.outlook.com (2603:10b6:4:14::27) by CH2PR12MB5002.namprd12.prod.outlook.com (2603:10b6:610:6d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Fri, 22 Oct 2021 21:09:38 +0000 Received: from DM6NAM11FT032.eop-nam11.prod.protection.outlook.com (2603:10b6:4:14:cafe::c9) by DM5PR2201CA0017.outlook.office365.com (2603:10b6:4:14::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 via Frontend Transport; Fri, 22 Oct 2021 21:09:38 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; oktetlabs.ru; dkim=none (message not signed) header.d=none;oktetlabs.ru; 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 DM6NAM11FT032.mail.protection.outlook.com (10.13.173.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4628.16 via Frontend Transport; Fri, 22 Oct 2021 21:09:36 +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; Fri, 22 Oct 2021 21:09:32 +0000 From: Dmitry Kozlyuk To: CC: Olivier Matz , Andrew Rybchenko Date: Sat, 23 Oct 2021 00:09:19 +0300 Message-ID: <20211022210920.207732-1-dkozlyuk@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211022075937.52983-1-dkozlyuk@nvidia.com> References: <20211022075937.52983-1-dkozlyuk@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e5343a3-9489-454e-daa1-08d995a04119 X-MS-TrafficTypeDiagnostic: CH2PR12MB5002: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iF46GpQm9IHj5a/DySoWKuKLUfwPaWeTD4c8lw9KvDphAlNU2754P9zxmHhie9eoSuhICjFo/1m0ep+/PjqvGn90yWGecUM82OF14DM1w7TPEMhgmJbftz2E8MppLHMlZbrnLVwEciiDXNnUi9ZXgEOOxeAa03hQ/kpYSplXMjWnJ7XlsF5HQaZO9M4R3/dx7i/7Zn00Yw9YPnTFw2Fo8U2d4T/OisY7IS6Qx1yzVKtLFKihnADZPbsZzsZkh/oYw4Njl05hm8hAudzn5dFjG4jA4X9Hh4cn3rviVT37Anxg44/JxBskf/wO2UNlclifiq5XTKPdRWQQPWKwxHXHhRHHRSR6q4Usp4enTe+X/w69mlz20xP9vkomThBbbicQobSxOQyKLkA5PIeBjTC2/JPzUXwjSzj+0vbmqM3yxF+TrdJ2PRLq6S/q0G+s3sDlwS006abK8nVpFhtZ8HuOxW/XcMUnf7U/qj2ASwjLD45AZke6Fb821AejCA1ndRRvrejotpnNqNG78urDMjkHVGUg73CEKzN3RpO8LPQLT4dxpNfji3jC/WZ2+UKdq5BZvqlJukL4Bh4uK1aqC2sw3YRsqI5MDP4nrIeeNmNatjMlGXjCEyhxqgGBWcbuxZi5xcbAnDjCNEYEkAXORCjaZGGYdZwupaef4n20sv7wIsLLpuceQtTxJXhW7Iu8AlEmYxYoodWAdssSWIYYWlMM/w== 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)(6916009)(8936002)(356005)(83380400001)(70586007)(36906005)(508600001)(2906002)(316002)(6666004)(70206006)(82310400003)(16526019)(8676002)(26005)(7696005)(2616005)(5660300002)(54906003)(47076005)(1076003)(7636003)(6286002)(107886003)(86362001)(55016002)(336012)(36756003)(4326008)(426003)(186003)(36860700001); DIR:OUT; SFP:1101; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2021 21:09:36.8055 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6e5343a3-9489-454e-daa1-08d995a04119 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: DM6NAM11FT032.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB5002 Subject: [dpdk-dev] [PATCH v2] mempool: fix non-IO flag inference X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" When mempool had been created with RTE_MEMPOOL_F_NO_IOVA_CONTIG flag but later populated with valid IOVA, RTE_MEMPOOL_F_NON_IO was unset, while it should be kept. The unit test did not catch this because rte_mempool_populate_default() it used was populating with RTE_BAD_IOVA. Keep setting RTE_MEMPOOL_NON_IO at an empty mempool creation and add an assert for it in the unit test (remove the separate case). Do not reset the flag if RTE_MEMPOOL_F_ON_IOVA_CONTIG is set. Fixes: 11541c5c81dd ("mempool: add non-IO flag") Signed-off-by: Dmitry Kozlyuk --- v2: IOVA mode has nothing to do with populating the mempool, so logic related to it is removed and the unit test simplified. app/test/test_mempool.c | 45 +++++++++++++++++---------------------- lib/mempool/rte_mempool.c | 4 ++-- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/app/test/test_mempool.c b/app/test/test_mempool.c index 4f399b461d..4b0f6b0e7f 100644 --- a/app/test/test_mempool.c +++ b/app/test/test_mempool.c @@ -740,16 +740,31 @@ test_mempool_events_safety(void) static int test_mempool_flag_non_io_set_when_no_iova_contig_set(void) { + void *virt = NULL; + rte_iova_t iova; + size_t size = MEMPOOL_ELT_SIZE * 16; struct rte_mempool *mp = NULL; int ret; + virt = rte_malloc("test_mempool", size, rte_mem_page_size()); + RTE_TEST_ASSERT_NOT_NULL(virt, "Cannot allocate memory"); + iova = rte_mem_virt2iova(virt); + RTE_TEST_ASSERT_NOT_EQUAL(iova, RTE_BAD_IOVA, "Cannot get IOVA"); mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, MEMPOOL_ELT_SIZE, 0, 0, SOCKET_ID_ANY, RTE_MEMPOOL_F_NO_IOVA_CONTIG); RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", rte_strerror(rte_errno)); rte_mempool_set_ops_byname(mp, rte_mbuf_best_mempool_ops(), NULL); - ret = rte_mempool_populate_default(mp); + + RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO, + "NON_IO flag is not set on an empty mempool"); + + /* + * Always use valid IOVA so that populate() has no other reason + * to infer that the mempool cannot be used for IO. + */ + ret = rte_mempool_populate_iova(mp, virt, iova, size, NULL, NULL); RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", rte_strerror(-ret)); RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO, @@ -757,6 +772,7 @@ test_mempool_flag_non_io_set_when_no_iova_contig_set(void) ret = TEST_SUCCESS; exit: rte_mempool_free(mp); + rte_free(virt); return ret; } @@ -785,6 +801,9 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", rte_strerror(rte_errno)); + RTE_TEST_ASSERT(mp->flags & RTE_MEMPOOL_F_NON_IO, + "NON_IO flag is not set on an empty mempool"); + ret = rte_mempool_populate_iova(mp, RTE_PTR_ADD(virt, 1 * block_size), RTE_BAD_IOVA, block_size, NULL, NULL); RTE_TEST_ASSERT(ret > 0, "Failed to populate mempool: %s", @@ -812,28 +831,6 @@ test_mempool_flag_non_io_unset_when_populated_with_valid_iova(void) return ret; } -static int -test_mempool_flag_non_io_unset_by_default(void) -{ - struct rte_mempool *mp; - int ret; - - mp = rte_mempool_create_empty("empty", MEMPOOL_SIZE, - MEMPOOL_ELT_SIZE, 0, 0, - SOCKET_ID_ANY, 0); - RTE_TEST_ASSERT_NOT_NULL(mp, "Cannot create mempool: %s", - rte_strerror(rte_errno)); - ret = rte_mempool_populate_default(mp); - RTE_TEST_ASSERT_EQUAL(ret, (int)mp->size, "Failed to populate mempool: %s", - rte_strerror(-ret)); - RTE_TEST_ASSERT(!(mp->flags & RTE_MEMPOOL_F_NON_IO), - "NON_IO flag is set by default"); - ret = TEST_SUCCESS; -exit: - rte_mempool_free(mp); - return ret; -} - #pragma pop_macro("RTE_TEST_TRACE_FAILURE") static int @@ -1022,8 +1019,6 @@ test_mempool(void) GOTO_ERR(ret, err); /* test NON_IO flag inference */ - if (test_mempool_flag_non_io_unset_by_default() < 0) - GOTO_ERR(ret, err); if (test_mempool_flag_non_io_set_when_no_iova_contig_set() < 0) GOTO_ERR(ret, err); if (test_mempool_flag_non_io_unset_when_populated_with_valid_iova() < 0) diff --git a/lib/mempool/rte_mempool.c b/lib/mempool/rte_mempool.c index b75d26c82a..f66a561d05 100644 --- a/lib/mempool/rte_mempool.c +++ b/lib/mempool/rte_mempool.c @@ -372,8 +372,8 @@ rte_mempool_populate_iova(struct rte_mempool *mp, char *vaddr, STAILQ_INSERT_TAIL(&mp->mem_list, memhdr, next); mp->nb_mem_chunks++; - /* At least some objects in the pool can now be used for IO. */ - if (iova != RTE_BAD_IOVA) + /* Check if at least some objects in the pool are now usable for IO. */ + if (!(mp->flags & RTE_MEMPOOL_F_NO_IOVA_CONTIG) && iova != RTE_BAD_IOVA) mp->flags &= ~RTE_MEMPOOL_F_NON_IO; /* Report the mempool as ready only when fully populated. */ -- 2.25.1