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

Xueming Li xuemingl at nvidia.com
Sun Jun 25 08:33:51 CEST 2023


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 06/27/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=94babf61c59fd4d0089e5131975fb3071c4247b6

Thanks.

Xueming Li <xuemingl at nvidia.com>

---
>From 94babf61c59fd4d0089e5131975fb3071c4247b6 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
Cc: Xueming Li <xuemingl at nvidia.com>

[ 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 |  4 +++-
 lib/eal/freebsd/eal.c             | 10 ++++++++++
 lib/eal/linux/eal.c               | 10 ++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/lib/eal/common/eal_common_debug.c b/lib/eal/common/eal_common_debug.c
index dcb554af1e..9cac9c6390 100644
--- a/lib/eal/common/eal_common_debug.c
+++ b/lib/eal/common/eal_common_debug.c
@@ -4,10 +4,12 @@
 
 #include <stdarg.h>
 #include <stdlib.h>
+#include <errno.h>
 
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_debug.h>
+#include <rte_errno.h>
 
 void
 __rte_panic(const char *funcname, const char *format, ...)
@@ -39,7 +41,7 @@ rte_exit(int exit_code, const char *format, ...)
 	rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap);
 	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");
 	exit(exit_code);
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index 390e4257ff..122daf6c1f 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -889,6 +889,16 @@ rte_eal_init(int argc, char **argv)
 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();
 	rte_service_finalize();
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index c76f026023..7b0eafd565 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -1354,6 +1354,16 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 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.25.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-06-25 14:31:58.929963600 +0800
+++ 0013-eal-avoid-calling-cleanup-twice.patch	2023-06-25 14:31:58.295773900 +0800
@@ -1 +1 @@
-From a4a2ac988679b3802a574e7bb72154da177449a4 Mon Sep 17 00:00:00 2001
+From 94babf61c59fd4d0089e5131975fb3071c4247b6 Mon Sep 17 00:00:00 2001
@@ -4,0 +5,3 @@
+Cc: Xueming Li <xuemingl at nvidia.com>
+
+[ upstream commit a4a2ac988679b3802a574e7bb72154da177449a4 ]
@@ -17 +19,0 @@
-Cc: stable at dpdk.org
@@ -53 +55 @@
-index 7daf22e314..78ffb45c59 100644
+index 390e4257ff..122daf6c1f 100644
@@ -56 +58 @@
-@@ -902,6 +902,16 @@ rte_eal_init(int argc, char **argv)
+@@ -889,6 +889,16 @@ rte_eal_init(int argc, char **argv)
@@ -74 +76 @@
-index ae323cd492..90e05fe4de 100644
+index c76f026023..7b0eafd565 100644
@@ -77 +79 @@
-@@ -1365,6 +1365,16 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
+@@ -1354,6 +1354,16 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,


More information about the stable mailing list