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 05B5642CBC for ; Thu, 15 Jun 2023 03:33:36 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0039A42BAC; Thu, 15 Jun 2023 03:33:35 +0200 (CEST) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) by mails.dpdk.org (Postfix) with ESMTP id A0FB440E0F for ; Thu, 15 Jun 2023 03:33:34 +0200 (CEST) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-3f8c65020dfso14552645e9.2 for ; Wed, 14 Jun 2023 18:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686792814; x=1689384814; 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=2tHzaJ/86i1gGRPDZGpdNgGtkNtn85+u5iLUgnnma2U=; b=d2J3DME0+37Baac162FImXlgAscm8XAd5FbvlPEvo91fLPSXFGRc1kh488zNFvYHeK DHjiWpAsmiDlL/oVcrO02NOA2Z4Sm3PqB1s3mtUczQtSAlY42yi9xihQ2ytEtezZcIdh iA9XZDTz61DLB1/1+gYvtpvk4eM6yfRO0bwRvYtwnfq/OhdvMAv9GCIISArJP8xgB/Lw IgaarniL2nogmZCg4k2zkLwS5xvU6+zhwYr2W+DMXConv3rcei27bfUU3fxMcynEvKH2 J/XtNRt0x9MYFZquBHFBZaLyTmQFAv5gbidtpYjC3qFb+oNr/RSf/JqNkNTNMgPY6w+q 51yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686792814; x=1689384814; 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=2tHzaJ/86i1gGRPDZGpdNgGtkNtn85+u5iLUgnnma2U=; b=LrQZ1Hcdr+xNqshAA4mOJ7eMTTwmaT0RuAVaVZnsh8n+b3dd44ta03BoQryRaxWPkU PHtp7USRUggtP1kNy0FPYhMygT3rGSVDc8rLOO4onVQAuwpurtvXyhKNsLqMgXfMsqo3 CneBZ7pSHpOBH90jKvAv7FT091b8KnzVUo+VvCgievdzdL4fkRK47zRjj/3/k0MKIzMc vFFNxN1lt/w/e/jHmpVbPYUvjVaXuK8guPSZkPoTKl/9zIyUUN1M/B4lA9IKplvNWrMA xcJM1amjQ0bpU753NG8unAK7EJAcv1hpkQStGJ7OOZmGEzvDDfgT7wOmryYUcFknOiSt /oIA== X-Gm-Message-State: AC+VfDxLtvpn/OdnO2hG08mBGjfcofXdEpAXDdOQkCD7IFWapzNH7Rpa 2LIfD92ml3QJhNG95bcpgtQF8iyZlMiMkg== X-Google-Smtp-Source: ACHHUZ5sPuobGBMswwUXK1pR5HiSPcdIq+u9mVLC44uR2LASRe1cL0Z8cBAQwEomfDRTC7a2LLFXkg== X-Received: by 2002:a05:600c:22cf:b0:3f4:2374:3512 with SMTP id 15-20020a05600c22cf00b003f423743512mr12829744wmg.18.1686792814239; Wed, 14 Jun 2023 18:33:34 -0700 (PDT) Received: from localhost ([137.220.119.58]) by smtp.gmail.com with ESMTPSA id n6-20020a7bcbc6000000b003f6f6a6e769sm18686233wmi.17.2023.06.14.18.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jun 2023 18:33:33 -0700 (PDT) From: luca.boccassi@gmail.com To: Bruce Richardson Cc: dpdk stable Subject: patch 'eal: avoid calling cleanup twice' has been queued to stable release 20.11.9 Date: Thu, 15 Jun 2023 02:32:06 +0100 Message-Id: <20230615013258.1439718-11-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230615013258.1439718-1-luca.boccassi@gmail.com> References: <20230615013258.1439718-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.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 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/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 +#include + #include #include #include +#include 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@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 @@ -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,