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 9D5194301E for ; Thu, 10 Aug 2023 01:53:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 975C243257; Thu, 10 Aug 2023 01:53:41 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by mails.dpdk.org (Postfix) with ESMTP id 04CC1406B6 for ; Thu, 10 Aug 2023 01:53:40 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gXQGjC7xuDaNac/mOrKdsgVdzMr9gNFuNWY32r1yUw+eBHIGB3pNXnijVCmWEN+pr2pAYInWQB9cFktDYLhF99y+OYHS/u7EwVHY6l3ol2IAVca2hqrdR8LamGEyr1Cy7XvKZJu8+LhrNvmOTNXshbEIjCUINwbwzx9/77qeTdqPjxnV4naspIIxxqg29GvLuE9iJynXKhaWLPE8xVe7C9pXiyxfZgkATcn8b3JqgRqUSnyzMnz93N+978YCXKNvE0EHdoVabl3935PYTRV+VVKPM5fhWpjOZvQrDVKEuu0Qh71K1XKjkqtKE34Cjk7RfOjxTkenOtMq+mHPkVyc1Q== 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=ZzY8KCbCWf+U58cAC/onE2DV8dc5khkisoNlIpVoDsk=; b=mXbZ0TrpMK6+U1wvtQVi9AWd5RHgYcD/FU8axmxpmyzNtQ2CIHjtRSPoM8YmLmbcSkO6QSZWLf74kNYpvLSv4jo7/GtEj0HJjhdHSLkUW22LtZ03yCMBwPaoU1uwZojq62MEP93ir/k8L1EtLE2lOeDNVizQIlu1MRcycpM4IwmgrHKzyoDgNKoVhuIy/URKiGLSPxW/i5N4qRN/TaMMZ+2VA1JyNJgOMN8WIoDc4xYbVBq5AJdYMULd1yKTyO2svh+XITKlItEt7e+dyf2UB767fvjcYLpiz58ETGHUApKKuh1xjKzXo3wlvdFevBKgsmMrQrdrNZJO4tH/gfvHqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=loongson.cn 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 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=ZzY8KCbCWf+U58cAC/onE2DV8dc5khkisoNlIpVoDsk=; b=VsLsaXmqpf0CJuq8v4OOi3WaiDCquNblIpfGqcmT3yJARZreBB7+9Qg7lJxdz+gsNHI5FS9rdwPjiJCSpl5sjSBXyuYJfx/hrsq2o/vDHdbJJTs2H03AqMjObyA/kX2tQlK7Dmu4yWqqCn5ineuvyxkP7RsmYJcb3wsPt4XkHlKargMQnWSI0vTm8jAYtox1a/t5qoIXfdpQ096ONsymJG3X4EQc/oBIUfoqhrcJ6XruRDkzhrrAIVMCX3nXnS6GWrYG3REtemTQi0M+t80BDVE48orbxTG51Hor5Lfo4Fhl1NSUeuad4yMdcv0RhirwzUFY+XNJETzxWtMOUNu7lw== Received: from SN7PR04CA0003.namprd04.prod.outlook.com (2603:10b6:806:f2::8) by BL1PR12MB5361.namprd12.prod.outlook.com (2603:10b6:208:31f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Wed, 9 Aug 2023 23:53:38 +0000 Received: from SA2PEPF000015C6.namprd03.prod.outlook.com (2603:10b6:806:f2:cafe::dc) by SN7PR04CA0003.outlook.office365.com (2603:10b6:806:f2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.28 via Frontend Transport; Wed, 9 Aug 2023 23:53:38 +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 SA2PEPF000015C6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.19 via Frontend Transport; Wed, 9 Aug 2023 23:53:37 +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.5; Wed, 9 Aug 2023 16:53:21 -0700 Received: from nvidia.com (10.126.230.37) 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.37; Wed, 9 Aug 2023 16:53:19 -0700 From: Xueming Li To: Min Zhou CC: Ruifeng Wang , dpdk stable Subject: patch 'net/ixgbe: add proper memory barriers in Rx' has been queued to stable release 22.11.3 Date: Thu, 10 Aug 2023 07:47:59 +0800 Message-ID: <20230809234930.32424-38-xuemingl@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230809234930.32424-1-xuemingl@nvidia.com> References: <20230625063544.11183-1-xuemingl@nvidia.com> <20230809234930.32424-1-xuemingl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.37] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF000015C6:EE_|BL1PR12MB5361:EE_ X-MS-Office365-Filtering-Correlation-Id: 280e2c97-ec21-43f7-df92-08db9933d96e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /zdeoorbEDONRUAjrsDs/u59gXpkssJEJS3+/g4Zy+8hYbepcNKJxkIWmFbKvJazuUx3qSJPehMpbb9ryth7RVC93UoNsFhv6o1EkfKOxlqSN1WFZQ1MHX3IVvcjIbHFqJ3r718ZC2zobVZPRDDrqWJfHxHM7Qa35H0Wb5k9EJzm9kzwu4reG8pyoWWjVYAhPRK9TXH5VeEIVO/jmRp+4qHQz++M6cDrdFwqDQBE7OPXhNxIF6CJRY2qfEPEgZEF4VLLAur8BNuXbGPiRmVPumvDR0A4YTQFanpVWL+M/nfcDlxLx08pzws/CUHPCV7t1to8epA9SSGwT5YPMY+UPwO2Pci6LUIniuWu4Zk+KAXQHP+CtV2jEhwQmJv1biqcVPBesa6TmNoc+GV7touem7LWLmoHv+Ht2ItdEMZjGUfkVGUQlahG/0A1gy96kDAmPTTy9CoMoNdcIt2B66XvwxONKI5YcRDeahDH444jaLDVaH/TbTZgJ5TuHACvOBEot/JyR2wmcaE4zzlXfUuNQ6cxtN0YYvGUVfZBhraV+h5K3JYiP5o88hxKGReOiqcG21Y2jxsi3K3+QMmKBPYpQwMXjxUT11Xjziit5tzsry/e6+jv4u4WR74J6I2a4QdVvepugUaAWFEpoABOVHv9iTKHOeNWSsj/226ByXb/KtST18uFGxZMhDobl1rkRnzeGiDLYpMhT3qairgoNHGJRUkM7/zoeWtg8xaohYvnp6qKS2jb9OgLn5A0HCCqvJo6Nvt+/iC4mPONNC5GElWEKg== 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:(13230028)(4636009)(346002)(136003)(376002)(39860400002)(396003)(1800799006)(186006)(451199021)(82310400008)(40470700004)(46966006)(36840700001)(40460700003)(55016003)(40480700001)(6916009)(54906003)(70586007)(53546011)(6286002)(336012)(70206006)(16526019)(1076003)(26005)(6666004)(478600001)(36756003)(40140700001)(83380400001)(47076005)(426003)(2616005)(36860700001)(41300700001)(316002)(7696005)(966005)(4326008)(2906002)(86362001)(82740400003)(8936002)(8676002)(5660300002)(7636003)(356005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2023 23:53:37.1954 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 280e2c97-ec21-43f7-df92-08db9933d96e 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: SA2PEPF000015C6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5361 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.3 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 08/11/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=00f8c02c414b3fc3db882c328c2b2deb369050d2 the Thanks. Xueming Li --- >From 00f8c02c414b3fc3db882c328c2b2deb369050d2 Mon Sep 17 00:00:00 2001 From: Min Zhou Date: Tue, 13 Jun 2023 17:44:25 +0800 Subject: [PATCH] net/ixgbe: add proper memory barriers in Rx Cc: Xueming Li [ upstream commit 85e46c532bc76ebe07f6a397aa76211250aca59c ] Segmentation fault has been observed while running the ixgbe_recv_pkts_lro() function to receive packets on the Loongson 3C5000 processor which has 64 cores and 4 NUMA nodes. >From the ixgbe_recv_pkts_lro() function, we found that as long as the first packet has the EOP bit set, and the length of this packet is less than or equal to rxq->crc_len, the segmentation fault will definitely happen even though on the other platforms. For example, if we made the first packet which had the EOP bit set had a zero length by force, the segmentation fault would happen on X86. Because when processd the first packet the first_seg->next will be NULL, if at the same time this packet has the EOP bit set and its length is less than or equal to rxq->crc_len, the following loop will be executed: for (lp = first_seg; lp->next != rxm; lp = lp->next) ; We know that the first_seg->next will be NULL under this condition. So the expression of lp->next->next will cause the segmentation fault. Normally, the length of the first packet with EOP bit set will be greater than rxq->crc_len. However, the out-of-order execution of CPU may make the read ordering of the status and the rest of the descriptor fields in this function not be correct. The related codes are as following: rxdp = &rx_ring[rx_id]; #1 staterr = rte_le_to_cpu_32(rxdp->wb.upper.status_error); if (!(staterr & IXGBE_RXDADV_STAT_DD)) break; #2 rxd = *rxdp; The sentence #2 may be executed before sentence #1. This action is likely to make the ready packet zero length. If the packet is the first packet and has the EOP bit set, the above segmentation fault will happen. So, we should add a proper memory barrier to ensure the read ordering be correct. We also did the same thing in the ixgbe_recv_pkts() function to make the rxd data be valid even though we did not find segmentation fault in this function. Fixes: 8eecb3295aed ("ixgbe: add LRO support") Signed-off-by: Min Zhou Reviewed-by: Ruifeng Wang --- drivers/net/ixgbe/ixgbe_rxtx.c | 47 +++++++++++++++------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c index c9d6ca9efe..dd07f0961e 100644 --- a/drivers/net/ixgbe/ixgbe_rxtx.c +++ b/drivers/net/ixgbe/ixgbe_rxtx.c @@ -1818,11 +1818,22 @@ ixgbe_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->wb.upper.status_error; if (!(staterr & rte_cpu_to_le_32(IXGBE_RXDADV_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; /* @@ -2089,32 +2100,10 @@ ixgbe_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 ixgbe 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->wb.upper.status_error); @@ -2122,6 +2111,12 @@ next_desc: if (!(staterr & IXGBE_RXDADV_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-08-09 21:51:19.196958200 +0800 +++ 0037-net-ixgbe-add-proper-memory-barriers-in-Rx.patch 2023-08-09 21:51:18.174352000 +0800 @@ -1 +1 @@ -From 85e46c532bc76ebe07f6a397aa76211250aca59c Mon Sep 17 00:00:00 2001 +From 00f8c02c414b3fc3db882c328c2b2deb369050d2 Mon Sep 17 00:00:00 2001 @@ -4,0 +5,3 @@ +Cc: Xueming Li + +[ upstream commit 85e46c532bc76ebe07f6a397aa76211250aca59c ] @@ -50 +52,0 @@ -Cc: stable@dpdk.org @@ -59 +61 @@ -index 6cbb992823..61f17cd90b 100644 +index c9d6ca9efe..dd07f0961e 100644 @@ -62 +64 @@ -@@ -1817,11 +1817,22 @@ ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, +@@ -1818,11 +1818,22 @@ ixgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, @@ -85 +87 @@ -@@ -2088,32 +2099,10 @@ ixgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts, +@@ -2089,32 +2100,10 @@ ixgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts, @@ -122 +124 @@ -@@ -2121,6 +2110,12 @@ next_desc: +@@ -2122,6 +2111,12 @@ next_desc: