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 B57CB433D8 for ; Mon, 11 Dec 2023 11:15:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B020540ED2; Mon, 11 Dec 2023 11:15:39 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2064.outbound.protection.outlook.com [40.107.93.64]) by mails.dpdk.org (Postfix) with ESMTP id 40C9440E0F for ; Mon, 11 Dec 2023 11:15:38 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=brAksa/970flk6Gw1+FL3D7+oQpjSStfcc/FImiO/MNbeM2CWxpaYFHHgczs5lHLRDja2nCKiG5GbrChcuRnVFWT8YHVPx6ipgAXQ7AIA2gx/vGQftPk3sH4nDg+aQRWBy7XElxhq2osts9ejwhIGf+Uze5+cyiBzKVUSOjzOl+SqpBnbnp6rH0KpRIFbuufUHZZFyg3Flsk2K0ipufM2GTu75SzN7Uu7qbgHmfrIV76+jnzIn3wSylK+qvGI/dCzBfmlk5c32zt13FSaAfaj4c5P3rmaIQq9bIK2A1oo8vJQ1M3V1EIuY3zlaUns/5PlDgu3/yOeOMSw+raP8sFgw== 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=P5XKEX9R7zBMIhaR+yw/M+uq3Ui//uNH4soMHB5ewJk=; b=ZNHUyk7xfhoLHKpQoUhLV9fPTsLpCL3JUSSh6IiKetFx5JvFG2229bBDuZuqxiR7Bz1xRWmr15bA3vmDYeYL3I1YjZ82Sinz1OUEt5+vSJWmZ03cjeAYnmn/FAunvkeYHe0vF3iwJuKO/Og3c8gCwDrlQ0YHClKFCmt7azH6eEp1sEha9drlu1MPM7CXwvylUorrNYNGRII0gNJ11Ld63sbh7r5+dTzAA8NI2sIVJnfwSuDot9abu+DSxCC6ZA1JBx2XOsentLYSWW3pDjayNcLvzBo2bewxfolfo/yugLKfI/xjR2d3n1A1K08Zy6+r8AgYHHWf8vvA2iluxDBc0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=trustnetic.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=P5XKEX9R7zBMIhaR+yw/M+uq3Ui//uNH4soMHB5ewJk=; b=t6s5mSa8LL1qn0tYJAzDLNFIPdtqkgZ2DrMbtgdOsqwCJ5/F3H5vAYpab4+u2/H6Cd+hvfktEZZorjVviOI6J3O4vdHwLT/xrQr0PHRR6fwnaglC0nU8rIBqBf6SuDraASgJuNnfQtTUI/MfQuMd8viv9n6ToDFnZ7xBtxYosRE66Llzv7dw8vzC7BX8N/NiHIMEMR59hkXCIja427zO59ZglQfgKqD57TzoVlD3ZZHSjy1RvbENbsbqK8CftouTg89mDZLm6uMDtYmb+ajXtmt/XOWr7cHhHlEpRFzIK8cceOLkKQWYXUZX88JxXrMmq+rQAW0A9cD/lcpwJFf0iw== Received: from DS7PR03CA0238.namprd03.prod.outlook.com (2603:10b6:5:3ba::33) by MW6PR12MB8960.namprd12.prod.outlook.com (2603:10b6:303:23e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33; Mon, 11 Dec 2023 10:15:36 +0000 Received: from DS3PEPF000099DC.namprd04.prod.outlook.com (2603:10b6:5:3ba:cafe::1c) by DS7PR03CA0238.outlook.office365.com (2603:10b6:5:3ba::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.33 via Frontend Transport; Mon, 11 Dec 2023 10:15:35 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS3PEPF000099DC.mail.protection.outlook.com (10.167.17.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7091.18 via Frontend Transport; Mon, 11 Dec 2023 10:15:35 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Dec 2023 02:15:20 -0800 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Dec 2023 02:15:19 -0800 From: Xueming Li To: Jiawen Wu CC: dpdk stable Subject: patch 'net/txgbe: add proper memory barriers in Rx' has been queued to stable release 22.11.4 Date: Mon, 11 Dec 2023 18:10:56 +0800 Message-ID: <20231211101226.2122-32-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231211101226.2122-1-xuemingl@nvidia.com> References: <20231022142250.10324-1-xuemingl@nvidia.com> <20231211101226.2122-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DC:EE_|MW6PR12MB8960:EE_ X-MS-Office365-Filtering-Correlation-Id: ba15ea98-1289-4cea-2bee-08dbfa321dbb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S4fb/o470U3m+EbbXlXHd/Q+tkg36ZsaLwlvWjhYrWDmKq6XBvQtRn2bIZGfcALcW9uRVJQgZ3Basc2DF0FHp+cBdXcn/T5lVT4FDI/Z2VmIjYefwvjOCvCYvA+Ayto/SfmTN3tktwlUO52Ji+HeHrZUIKSu8ap01nO2qqf7HG9GeU97Cs0Qx65djBLH+NqcoKIbxj0ZZRRUSWowi1VnR281RJFCj38e5BcYcKTkpY8TbOJ8WKRF7rjDcgNfwsHO5vatyF/nqm5jqaPJOfV8r9zKNH546PWSiX2XFBTx7Dc2g7J5lG3O8xf/KUr7VEZzPEbYN0ci1SvybWpJNNx8b4I6zVSFvnkpkyxKw/KxvNKfswDVdxYhUFvl6n4MCqC0VZ9cAQ0bc7LPtwCIfasFjXh4aIMUSAlFXcddDlAPUz/pjdOTMtdju8++tmns7b8lgKwgTEE45ZyADpi+SsWidjfDacwQcfficXQZUgUVcCLKD8crWE5TT0T8wRKfX6EuDIbQJOxXcRwYXOQ9zkQnCpuPk2IVqd7Rd8P5k0EYeAGVQ3Kp1Hi7WgJIqETwd9SH2PO5i2v5ZxbAV3cpiNQ3ayF5HyYs7hynWoz2Hyx0p8nlk6SWuLStCf8fLiGBy+JMnDv+9U1p366WkWKQLtHrbXUpImqGXKCKc8zIwKKBWf82jbked5fkEi7OeBwrpHBYT0SW8rCJ/hvb9XG8MSoVDHdFuzC3Lz+aBMH/WicqgtVe4yF/wqf12r2K1y4I/k3uHt19PaUuNQCQjxHmD5k4Gg== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(376002)(396003)(346002)(39860400002)(136003)(230922051799003)(451199024)(1800799012)(186009)(82310400011)(64100799003)(36840700001)(46966006)(40470700004)(83380400001)(2906002)(478600001)(356005)(41300700001)(82740400003)(4001150100001)(7636003)(55016003)(70206006)(70586007)(6916009)(426003)(40480700001)(966005)(316002)(6666004)(86362001)(7696005)(4326008)(8936002)(8676002)(53546011)(40460700003)(36756003)(47076005)(6286002)(5660300002)(1076003)(36860700001)(26005)(336012)(16526019)(2616005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2023 10:15:35.5765 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba15ea98-1289-4cea-2bee-08dbfa321dbb X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099DC.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8960 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 Hi, FYI, your patch has been queued to stable release 22.11.4 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 12/13/23. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://git.dpdk.org/dpdk-stable/log/?h=22.11-staging This queued commit can be viewed at: https://git.dpdk.org/dpdk-stable/commit/?h=22.11-staging&id=33f8a0ce2cb240f08f1c160ad1712999c7a3a298 Thanks. Xueming Li --- >From 33f8a0ce2cb240f08f1c160ad1712999c7a3a298 Mon Sep 17 00:00:00 2001 From: Jiawen Wu Date: Wed, 1 Nov 2023 11:32:40 +0800 Subject: [PATCH] net/txgbe: add proper memory barriers in Rx Cc: Xueming Li [ upstream commit 5bf954b7d91ad20ee87befbad9fdb53f03dd488b ] Refer to commit 85e46c532bc7 ("net/ixgbe: add proper memory barriers in Rx"). Fix the same issue as ixgbe. Segmentation fault has been observed while running the txgbe_recv_pkts_lro() function to receive packets on the Loongson 3A5000 processor. It's caused by the out-of-order execution of CPU. So add a proper memory barrier to ensure the read ordering be correct. We also did the same thing in the txgbe_recv_pkts() function to make the rxd data be valid even though we did not find segmentation fault in this function. Fixes: 0e484278c85f ("net/txgbe: support Rx") Signed-off-by: Jiawen Wu --- drivers/net/txgbe/txgbe_rxtx.c | 47 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/net/txgbe/txgbe_rxtx.c b/drivers/net/txgbe/txgbe_rxtx.c index 834ada886a..24fc34d3c4 100644 --- a/drivers/net/txgbe/txgbe_rxtx.c +++ b/drivers/net/txgbe/txgbe_rxtx.c @@ -1476,11 +1476,22 @@ txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, * of accesses cannot be reordered by the compiler. If they were * not volatile, they could be reordered which could lead to * using invalid descriptor fields when read from rxd. + * + * Meanwhile, to prevent the CPU from executing out of order, we + * need to use a proper memory barrier to ensure the memory + * ordering below. */ rxdp = &rx_ring[rx_id]; staterr = rxdp->qw1.lo.status; if (!(staterr & rte_cpu_to_le_32(TXGBE_RXD_STAT_DD))) break; + + /* + * Use acquire fence to ensure that status_error which includes + * DD bit is loaded before loading of other descriptor words. + */ + rte_atomic_thread_fence(__ATOMIC_ACQUIRE); + rxd = *rxdp; /* @@ -1726,32 +1737,10 @@ txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts, next_desc: /* - * The code in this whole file uses the volatile pointer to - * ensure the read ordering of the status and the rest of the - * descriptor fields (on the compiler level only!!!). This is so - * UGLY - why not to just use the compiler barrier instead? DPDK - * even has the rte_compiler_barrier() for that. - * - * But most importantly this is just wrong because this doesn't - * ensure memory ordering in a general case at all. For - * instance, DPDK is supposed to work on Power CPUs where - * compiler barrier may just not be enough! - * - * I tried to write only this function properly to have a - * starting point (as a part of an LRO/RSC series) but the - * compiler cursed at me when I tried to cast away the - * "volatile" from rx_ring (yes, it's volatile too!!!). So, I'm - * keeping it the way it is for now. - * - * The code in this file is broken in so many other places and - * will just not work on a big endian CPU anyway therefore the - * lines below will have to be revisited together with the rest - * of the txgbe PMD. - * - * TODO: - * - Get rid of "volatile" and let the compiler do its job. - * - Use the proper memory barrier (rte_rmb()) to ensure the - * memory ordering below. + * "Volatile" only prevents caching of the variable marked + * volatile. Most important, "volatile" cannot prevent the CPU + * from executing out of order. So, it is necessary to use a + * proper memory barrier to ensure the memory ordering below. */ rxdp = &rx_ring[rx_id]; staterr = rte_le_to_cpu_32(rxdp->qw1.lo.status); @@ -1759,6 +1748,12 @@ next_desc: if (!(staterr & TXGBE_RXD_STAT_DD)) break; + /* + * Use acquire fence to ensure that status_error which includes + * DD bit is loaded before loading of other descriptor words. + */ + rte_atomic_thread_fence(__ATOMIC_ACQUIRE); + rxd = *rxdp; PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_id=%u " -- 2.25.1 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-12-11 17:56:24.187521000 +0800 +++ 0031-net-txgbe-add-proper-memory-barriers-in-Rx.patch 2023-12-11 17:56:22.937652300 +0800 @@ -1 +1 @@ -From 5bf954b7d91ad20ee87befbad9fdb53f03dd488b Mon Sep 17 00:00:00 2001 +From 33f8a0ce2cb240f08f1c160ad1712999c7a3a298 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 5bf954b7d91ad20ee87befbad9fdb53f03dd488b ] @@ -19 +21,0 @@ -Cc: stable@dpdk.org @@ -23,2 +25,2 @@ - drivers/net/txgbe/txgbe_rxtx.c | 49 +++++++++++++++------------------- - 1 file changed, 22 insertions(+), 27 deletions(-) + drivers/net/txgbe/txgbe_rxtx.c | 47 +++++++++++++++------------------- + 1 file changed, 21 insertions(+), 26 deletions(-) @@ -27 +29 @@ -index 834ada886a..1cd4b25965 100644 +index 834ada886a..24fc34d3c4 100644 @@ -30,9 +31,0 @@ -@@ -1226,7 +1226,7 @@ txgbe_rx_scan_hw_ring(struct txgbe_rx_queue *rxq) - for (j = 0; j < LOOK_AHEAD; j++) - s[j] = rte_le_to_cpu_32(rxdp[j].qw1.lo.status); - -- rte_atomic_thread_fence(__ATOMIC_ACQUIRE); -+ rte_atomic_thread_fence(rte_memory_order_acquire); - - /* Compute how many status bits were set */ - for (nb_dd = 0; nb_dd < LOOK_AHEAD && @@ -57 +50 @@ -+ rte_atomic_thread_fence(rte_memory_order_acquire); ++ rte_atomic_thread_fence(__ATOMIC_ACQUIRE); @@ -107 +100 @@ -+ rte_atomic_thread_fence(rte_memory_order_acquire); ++ rte_atomic_thread_fence(__ATOMIC_ACQUIRE);