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 7753EA0524; Mon, 24 Feb 2020 07:42:33 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id ECACC1BFA5; Mon, 24 Feb 2020 07:42:32 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id C38681BE85; Mon, 24 Feb 2020 07:42:31 +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 3A11330E; Sun, 23 Feb 2020 22:42:31 -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 1798E3F534; Sun, 23 Feb 2020 22:46:17 -0800 (PST) From: Phil Yang To: rsanford@akamai.com, erik.g.carrillo@intel.com, dev@dpdk.org Cc: david.marchand@redhat.com, anatoly.burakov@intel.com, thomas@monjalon.net, jerinj@marvell.com, hemant.agrawal@nxp.com, Honnappa.Nagarahalli@arm.com, gavin.hu@arm.com, phil.yang@arm.com, nd@arm.com, Honnappa Nagarahalli , stable@dpdk.org Date: Mon, 24 Feb 2020 14:42:18 +0800 Message-Id: <1582526539-14360-1-git-send-email-phil.yang@arm.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH 1/2] lib/timer: protect timer subsystem initialized with lock X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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