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

luca.boccassi at gmail.com luca.boccassi at gmail.com
Thu Jun 15 03:32:06 CEST 2023


Hi,

FYI, your patch has been queued to stable release 20.11.9

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/17/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/91127d04df1641e517396d07c76e3c4208bcd967

Thanks.

Luca Boccassi

---
>From 91127d04df1641e517396d07c76e3c4208bcd967 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/librte_eal/common/eal_common_debug.c |  5 ++++-
 lib/librte_eal/freebsd/eal.c             | 10 ++++++++++
 lib/librte_eal/linux/eal.c               | 10 ++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_debug.c b/lib/librte_eal/common/eal_common_debug.c
index 15418e957f..37c7c308b9 100644
--- a/lib/librte_eal/common/eal_common_debug.c
+++ b/lib/librte_eal/common/eal_common_debug.c
@@ -3,9 +3,12 @@
  */
 
 #include <stdarg.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, ...)
@@ -37,7 +40,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/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 6f9f12911e..cda713ded8 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -981,6 +981,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/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 5814f9ce69..04942854a3 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -1352,6 +1352,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.39.2

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2023-06-15 01:56:35.323684306 +0100
+++ 0011-eal-avoid-calling-cleanup-twice.patch	2023-06-15 01:56:34.515540167 +0100
@@ -1 +1 @@
-From a4a2ac988679b3802a574e7bb72154da177449a4 Mon Sep 17 00:00:00 2001
+From 91127d04df1641e517396d07c76e3c4208bcd967 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit a4a2ac988679b3802a574e7bb72154da177449a4 ]
+
@@ -17 +18,0 @@
-Cc: stable at dpdk.org
@@ -21,10 +22,11 @@
- 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 @@
+ lib/librte_eal/common/eal_common_debug.c |  5 ++++-
+ lib/librte_eal/freebsd/eal.c             | 10 ++++++++++
+ lib/librte_eal/linux/eal.c               | 10 ++++++++++
+ 3 files changed, 24 insertions(+), 1 deletion(-)
+
+diff --git a/lib/librte_eal/common/eal_common_debug.c b/lib/librte_eal/common/eal_common_debug.c
+index 15418e957f..37c7c308b9 100644
+--- a/lib/librte_eal/common/eal_common_debug.c
++++ b/lib/librte_eal/common/eal_common_debug.c
+@@ -3,9 +3,12 @@
+  */
@@ -33 +34,0 @@
- #include <stdlib.h>
@@ -35 +36 @@
- 
++
@@ -43 +44 @@
-@@ -39,7 +41,7 @@ rte_exit(int exit_code, const char *format, ...)
+@@ -37,7 +40,7 @@ rte_exit(int exit_code, const char *format, ...)
@@ -52,5 +53,5 @@
-diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
-index 7daf22e314..78ffb45c59 100644
---- a/lib/eal/freebsd/eal.c
-+++ b/lib/eal/freebsd/eal.c
-@@ -902,6 +902,16 @@ rte_eal_init(int argc, char **argv)
+diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
+index 6f9f12911e..cda713ded8 100644
+--- a/lib/librte_eal/freebsd/eal.c
++++ b/lib/librte_eal/freebsd/eal.c
+@@ -981,6 +981,16 @@ rte_eal_init(int argc, char **argv)
@@ -73,5 +74,5 @@
-diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
-index ae323cd492..90e05fe4de 100644
---- a/lib/eal/linux/eal.c
-+++ b/lib/eal/linux/eal.c
-@@ -1365,6 +1365,16 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
+diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
+index 5814f9ce69..04942854a3 100644
+--- a/lib/librte_eal/linux/eal.c
++++ b/lib/librte_eal/linux/eal.c
+@@ -1352,6 +1352,16 @@ mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,


More information about the stable mailing list