From patchwork Mon Feb 24 06:42:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Yang X-Patchwork-Id: 183762 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp17417ile; Sun, 23 Feb 2020 22:42:33 -0800 (PST) X-Google-Smtp-Source: APXvYqw3GnAUmCSL0YO4jqcFRYuCpluD8BGyAx54ZWLKnv9cvYW+4+j/08WrtTrpxPtAy/pHB89f X-Received: by 2002:a05:6402:1659:: with SMTP id s25mr44555524edx.219.1582526553843; Sun, 23 Feb 2020 22:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582526553; cv=none; d=google.com; s=arc-20160816; b=hcZ4dmDh9JvHvSsrZYWdHVRHsrW9yxFAYPmuCgDm5+gUYvfL5rQ7iMJOjOcogaII+z 91R5ld1VtR2KilkIBb9P6+GaBSw9OB8jdmYV/xYtUOfdgp40sygEX7DhgAgEwhj+2AVA IKGWMZopibRLE+G9cNz1u17cbCD0c32w6dQs/JZXirfW+9wKn7PGHxWkhBCtUz27bFN/ fBDOlwlob06f2gvDpfZa7Ji96RijMp0FiPYI/+8gfheKcJOxVGQtqWsYAj/UBP2/vxA9 fn46jWiwij/+UHNe7quxabD3Pn3rVkKOs/wbr8tC4k+5QnJv0oS/bNCFS5TguYvgRTso SuwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:message-id:date:cc:to :from; bh=1IwBNXTtS3w+svi77F8oZ4aYA0Loke0LVYAhg8GfKrg=; b=r2UgFsVKR0kmknhLOncgqUI98lEMSOySc5FABotm2UJOCC2gUnv0ffae023Sc9jQJs lE2su1Q7MQiZw+yaIpRSSKFYFUjc8mr57pAu964jYZBKHXLhFBM/+ZRESwLDH+mK9LPZ 5V2q3UuTFt0mXVUQ9dZ7V89++delwnmkBM5rdmEXoP7Y0JOtTGh1pPeHWntGCYvvZ81V jVjNC3fmLD3WMFRFvW+1mQOrAKDd8BNNrS51dsumqrTYALa/jjL1Rjis3qafTghDor/f GzDdjorJDH9DpVbcE/M4RsxhjZuulFece0X0cj2avrjilRpC3alkmp+OGDzwTUe3X/IU mxSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id w8si6914126edx.441.2020.02.23.22.42.33; Sun, 23 Feb 2020 22:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org 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(-) -- 2.7.4 Acked-by: Erik Gabriel Carrillo 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 */