patch 'eal: avoid calling cleanup twice' has been queued to stable release 21.11.5

Kevin Traynor ktraynor at redhat.com
Thu Jul 20 17:17:24 CEST 2023


Hi,

FYI, your patch has been queued to stable release 21.11.5

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 07/25/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/kevintraynor/dpdk-stable

This queued commit can be viewed at:
https://github.com/kevintraynor/dpdk-stable/commit/e506470227c99f0112b5ecf933f68b6fa876c1b7

Thanks.

Kevin

---
>From e506470227c99f0112b5ecf933f68b6fa876c1b7 Mon Sep 17 00:00:00 2001
From: Bruce Richardson <bruce.richardson at intel.com>
Date: Thu, 1 Jun 2023 17:08:55 +0100
Subject: [PATCH] eal: avoid calling cleanup twice

[ upstream commit a4a2ac988679b3802a574e7bb72154da177449a4 ]

If an app calls rte_eal_cleanup() inside it's own code, then cleanup
could be called a second time automatically when the app exits. While
mostly harmless, we can avoid any potential issues by guaranteeing that
cleanup only gets called once, in the same way that eal_init only ever
gets called once.

Note: This patch only touches Linux and FreeBSD. Windows EAL does not
have run-once guard on the init function, so omitting it in the cleanup
function.

Fixes: aec9c13c5257 ("eal: add function to release internal resources")

Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
 lib/eal/common/eal_common_debug.c |  5 ++++-
 lib/eal/freebsd/eal.c             | 10 ++++++++++
 lib/eal/linux/eal.c               | 10 ++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c
index 15418e957f..37c7c308b9 100644
--- a/lib/eal/common/eal_common_debug.c
+++ b/lib/eal/common/eal_common_debug.c
@@ -4,7 +4,10 @@
 
 #include <stdarg.h>
+#include <errno.h>
+
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_debug.h>
+#include <rte_errno.h>
 
 void
@@ -38,5 +41,5 @@ rte_exit(int exit_code, const char *format, ...)
 	va_end(ap);
 
-	if (rte_eal_cleanup() != 0)
+	if (rte_eal_cleanup() != 0 && rte_errno != EALREADY)
 		RTE_LOG(CRIT, EAL,
 			"EAL could not release all resources\n");
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 717d1f0b9a..66553089fa 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -983,4 +983,14 @@ int
 rte_eal_cleanup(void)
 {
+	static uint32_t run_once;
+	uint32_t has_run = 0;
+
+	if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
+			__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
+		RTE_LOG(WARNING, EAL, "Already called cleanup\n");
+		rte_errno = EALREADY;
+		return -1;
+	}
+
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 84c42679bf..862d526658 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -1355,4 +1355,14 @@ int
 rte_eal_cleanup(void)
 {
+	static uint32_t run_once;
+	uint32_t has_run = 0;
+
+	if (!__atomic_compare_exchange_n(&run_once, &has_run, 1, 0,
+					__ATOMIC_RELAXED, __ATOMIC_RELAXED)) {
+		RTE_LOG(WARNING, EAL, "Already called cleanup\n");
+		rte_errno = EALREADY;
+		return -1;
+	}
+
 	/* if we're in a primary process, we need to mark hugepages as freeable
 	 * so that finalization can release them back to the system.
-- 
2.41.0

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-07-20 16:17:56.817039384 +0100
+++ 0013-eal-avoid-calling-cleanup-twice.patch	2023-07-20 16:17:54.456749670 +0100
@@ -1 +1 @@
-From a4a2ac988679b3802a574e7bb72154da177449a4 Mon Sep 17 00:00:00 2001
+From e506470227c99f0112b5ecf933f68b6fa876c1b7 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit a4a2ac988679b3802a574e7bb72154da177449a4 ]
+
@@ -17 +18,0 @@
-Cc: stable at dpdk.org
@@ -21 +22 @@
- lib/eal/common/eal_common_debug.c |  4 +++-
+ lib/eal/common/eal_common_debug.c |  5 ++++-
@@ -24 +25 @@
- 3 files changed, 23 insertions(+), 1 deletion(-)
+ 3 files changed, 24 insertions(+), 1 deletion(-)
@@ -27 +28 @@
-index dcb554af1e..9cac9c6390 100644
+index 15418e957f..37c7c308b9 100644
@@ -30 +31,2 @@
-@@ -5,8 +5,10 @@
+@@ -4,7 +4,10 @@
+ 
@@ -32 +33,0 @@
- #include <stdlib.h>
@@ -34 +35 @@
- 
++
@@ -41 +42 @@
-@@ -40,5 +42,5 @@ rte_exit(int exit_code, const char *format, ...)
+@@ -38,5 +41,5 @@ rte_exit(int exit_code, const char *format, ...)
@@ -49 +50 @@
-index 7daf22e314..78ffb45c59 100644
+index 717d1f0b9a..66553089fa 100644
@@ -52 +53 @@
-@@ -903,4 +903,14 @@ int
+@@ -983,4 +983,14 @@ int
@@ -68 +69 @@
-index ae323cd492..90e05fe4de 100644
+index 84c42679bf..862d526658 100644
@@ -71 +72 @@
-@@ -1366,4 +1366,14 @@ int
+@@ -1355,4 +1355,14 @@ int



More information about the stable mailing list