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 9502242ECF for ; Thu, 20 Jul 2023 17:26:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 90FCE427F5; Thu, 20 Jul 2023 17:26:29 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id AA8EA427F5 for ; Thu, 20 Jul 2023 17:26:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689866788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ya3gB/XFbHLIybwJExFy5mj8KxGiNEbt5AY57cRNLvQ=; b=Tl0nkbT2Y5C9XvxOCPky6BftLBMWLMTkaZbFr8BVAgcwhLt4q7Pt+H0rU3z8jU8vMoJA7W UeCDGKFdKSiq8e1w5gtbkavvbS2jdkZT+ClPfLu5wZPV9a1iD0ZDioDo7SElCi55NKtS0E bHmi4x9EBPmJDiL3FVub3ZsjsjV+s/E= Received: from mimecast-mx02.redhat.com (66.187.233.88 [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-450-rWoDr7VkON6YWObwwl8Gxg-1; Thu, 20 Jul 2023 11:20:21 -0400 X-MC-Unique: rWoDr7VkON6YWObwwl8Gxg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF8F28870DD; Thu, 20 Jul 2023 15:20:13 +0000 (UTC) Received: from rh.redhat.com (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02E394CD0E3; Thu, 20 Jul 2023 15:20:12 +0000 (UTC) From: Kevin Traynor To: Bruce Richardson Cc: dpdk stable Subject: patch 'eal: avoid calling cleanup twice' has been queued to stable release 21.11.5 Date: Thu, 20 Jul 2023 16:17:24 +0100 Message-ID: <20230720151942.262154-13-ktraynor@redhat.com> In-Reply-To: <20230720151942.262154-1-ktraynor@redhat.com> References: <20230720151942.262154-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 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 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 --- 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 +#include + #include #include #include +#include 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@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 @@ -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