From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 31F1BA0524 for ; Mon, 24 Feb 2020 07:36:40 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 21D421DBF; Mon, 24 Feb 2020 07:36:40 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id DC8D51DBF for ; Mon, 24 Feb 2020 07:36:38 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5D63731B; Sun, 23 Feb 2020 22:36:38 -0800 (PST) Received: from phil-VirtualBox.arm.com (A010647.Arm.com [10.170.243.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EA4C73F534; Sun, 23 Feb 2020 22:40:26 -0800 (PST) From: Phil Yang To: phil.yang@arm.com Cc: nd@arm.com, Honnappa Nagarahalli , stable@dpdk.org Date: Mon, 24 Feb 2020 14:36:29 +0800 Message-Id: <1582526190-14295-1-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-stable] [PATCH 1/2] lib/timer: protect timer subsystem initialized with lock X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" From: Honnappa Nagarahalli rte_timer_subsystem_initialized is a global variable that can be accessed by multiple processes simultaneously. Hence, any access to rte_timer_subsystem_initialized should be protected by rte_mcfg_timer_lock. Fixes: f9d6cd8bfe9e ("timer: fix resource leak in finalize") Cc: stable@dpdk.org Signed-off-by: Honnappa Nagarahalli Reviewed-by: Gavin Hu Reviewed-by: Phil Yang --- lib/librte_timer/rte_timer.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c index 89f2707..269e921 100644 --- a/lib/librte_timer/rte_timer.c +++ b/lib/librte_timer/rte_timer.c @@ -145,11 +145,13 @@ rte_timer_subsystem_init(void) const size_t mem_size = data_arr_size + sizeof(*rte_timer_mz_refcnt); bool do_full_init = true; - if (rte_timer_subsystem_initialized) - return -EALREADY; - rte_mcfg_timer_lock(); + if (rte_timer_subsystem_initialized) { + rte_mcfg_timer_unlock(); + return -EALREADY; + } + mz = rte_memzone_lookup(mz_name); if (mz == NULL) { mz = rte_memzone_reserve_aligned(mz_name, mem_size, @@ -183,27 +185,29 @@ rte_timer_subsystem_init(void) rte_timer_data_arr[default_data_id].internal_flags |= FL_ALLOCATED; (*rte_timer_mz_refcnt)++; - rte_mcfg_timer_unlock(); - rte_timer_subsystem_initialized = 1; + rte_mcfg_timer_unlock(); + return 0; } void rte_timer_subsystem_finalize(void) { - if (!rte_timer_subsystem_initialized) - return; - rte_mcfg_timer_lock(); + if (!rte_timer_subsystem_initialized) { + rte_mcfg_timer_unlock(); + return; + } + if (--(*rte_timer_mz_refcnt) == 0) rte_memzone_free(rte_timer_data_mz); - rte_mcfg_timer_unlock(); - rte_timer_subsystem_initialized = 0; + + rte_mcfg_timer_unlock(); } /* Initialize the timer handle tim for use */ -- 2.7.4