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 C7A0B432DA for ; Wed, 8 Nov 2023 20:26:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C2F9642E1E; Wed, 8 Nov 2023 20:26:28 +0100 (CET) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by mails.dpdk.org (Postfix) with ESMTP id DBA3D40395 for ; Wed, 8 Nov 2023 20:26:27 +0100 (CET) Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-32f7bd27c2aso15681f8f.2 for ; Wed, 08 Nov 2023 11:26:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699471587; x=1700076387; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y7DwYux4rbLKmAl+AmTvIDHR+VZMmpCoGOGBMcsbdHk=; b=I2WaBPDnOPpq6WLaaUrKZaZmOgUnqtAW7IQ2uY16zmZvPcWR82qYOdmQQKzTmpT6e9 5+5DmxQvH1bsvaw87wSGfp4N/JzeWSKXehMJ8dldynT0CvDxqyGRFcwTq54PxzvO+mbh jYXxq2ke4tNTUgNndGHBJDRk9O1+qdh8aO6m/OqCLuiQ6FQbh8xx3529qA99AcpyrFlS 8Tzcr8IamY/WtaARMGintqH5OJ9r0gJdfJRTbi2MFnaB6RDTjg+Og/dLkE4zhKzYMsVx lHlaWAA693Nr8O3gzKFe4F7EOdUvpd475hwuhsxRDnyAJUWjWoKU29v8zAaNFb6nZ2Ub p64Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699471587; x=1700076387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y7DwYux4rbLKmAl+AmTvIDHR+VZMmpCoGOGBMcsbdHk=; b=vNUiGpzcmICDS+PqMnurYPm3GZC7oE8JJevBrPcchayt0bASWs9lu2BJqGTOn8CmwH t/WCJ8U360uOX+G30zScdN9h78mW9MgVlibOSMnBdXGtZXPHCp8T+g7y7ADc7aQYedZp GqW18hQSPvOKHI/u7LhG3GV5OO9X6LggaLBdgBTCsWPQPZKHD4k6A5xtsaK1So+LsNM3 1yG38pqJbWvrnKRG74QE4v2EvYOjCkcqnUSXaA/gTmsTgo11+0hMAXzBURrl6UP7B1Nx 9RFOwa0ysjjONQowv/RCaGjI1gNyIsyG7LA9vinEDubNqNYA9ue/uKDSOE8WYlfZX+vZ sx6w== X-Gm-Message-State: AOJu0Yxc4nXRP6xISK9HGiKrZneGkk1ROxop87mS4VEqVWIhnh4L4R1z NSujrjej7q349B79LepMK0m1p+nmwmHwqw== X-Google-Smtp-Source: AGHT+IFBDvCTmVdznA2hTVLBRHbmr62JWaxtUt9CVEcZgQrzXLJLhtewPr9G0DjO3B9Bd98SPI6Z+g== X-Received: by 2002:adf:f04c:0:b0:32d:5cc0:2f0c with SMTP id t12-20020adff04c000000b0032d5cc02f0cmr2378915wro.40.1699471587501; Wed, 08 Nov 2023 11:26:27 -0800 (PST) Received: from localhost ([2a01:4b00:d307:1000:f1d3:eb5e:11f4:a7d9]) by smtp.gmail.com with ESMTPSA id g16-20020a5d5550000000b0032de6f95fb3sm5578745wrw.40.2023.11.08.11.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 11:26:26 -0800 (PST) From: luca.boccassi@gmail.com To: Jiawen Wu Cc: dpdk stable Subject: patch 'net/txgbe: add proper memory barriers in Rx' has been queued to stable release 20.11.10 Date: Wed, 8 Nov 2023 19:25:15 +0000 Message-Id: <20231108192535.922238-17-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231108192535.922238-1-luca.boccassi@gmail.com> References: <20231018235930.3144-41-luca.boccassi@gmail.com> <20231108192535.922238-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 20.11.10 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/10/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://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/4cac7f3cd2acfdba14d300fe6e86c7ace3b3a865 Thanks. Luca Boccassi --- >From 4cac7f3cd2acfdba14d300fe6e86c7ace3b3a865 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 [ 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 ae6aa07a01..a630e533a7 100644 --- a/drivers/net/txgbe/txgbe_rxtx.c +++ b/drivers/net/txgbe/txgbe_rxtx.c @@ -1405,11 +1405,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; /* @@ -1655,32 +1666,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); @@ -1688,6 +1677,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.39.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2023-11-08 19:23:52.869234053 +0000 +++ 0017-net-txgbe-add-proper-memory-barriers-in-Rx.patch 2023-11-08 19:23:51.785396541 +0000 @@ -1 +1 @@ -From 5bf954b7d91ad20ee87befbad9fdb53f03dd488b Mon Sep 17 00:00:00 2001 +From 4cac7f3cd2acfdba14d300fe6e86c7ace3b3a865 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 5bf954b7d91ad20ee87befbad9fdb53f03dd488b ] + @@ -19 +20,0 @@ -Cc: stable@dpdk.org @@ -23,2 +24,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 +28 @@ -index 834ada886a..1cd4b25965 100644 +index ae6aa07a01..a630e533a7 100644 @@ -30,10 +31 @@ -@@ -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 && -@@ -1476,11 +1476,22 @@ txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, +@@ -1405,11 +1405,22 @@ txgbe_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, @@ -57 +49 @@ -+ rte_atomic_thread_fence(rte_memory_order_acquire); ++ rte_atomic_thread_fence(__ATOMIC_ACQUIRE); @@ -62 +54 @@ -@@ -1726,32 +1737,10 @@ txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts, +@@ -1655,32 +1666,10 @@ txgbe_recv_pkts_lro(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts, @@ -99 +91 @@ -@@ -1759,6 +1748,12 @@ next_desc: +@@ -1688,6 +1677,12 @@ next_desc: @@ -107 +99 @@ -+ rte_atomic_thread_fence(rte_memory_order_acquire); ++ rte_atomic_thread_fence(__ATOMIC_ACQUIRE);