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 0318FA00C5; Wed, 14 Sep 2022 17:33:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 93A01427FF; Wed, 14 Sep 2022 17:33:27 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mails.dpdk.org (Postfix) with ESMTP id 9418E4021E; Wed, 14 Sep 2022 17:33:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663169605; x=1694705605; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=anzzft6slexbzIc4v7WGKL6WBmaz3E1wQMdI1qRgqm8=; b=n6xincbZUYCETolCqC7BGATcODiN77ZRTsDpmGU6xsAVRe+OCN046Hri GCoaV0qJAxIEjeOuZh6/4Pgi0UNR6n8zTg4IgsKlH1NmJOKHWQWLUGaOz /PCIxP8eV/mN7fJSxSc0F0uopeRKy74NkPsPiqAyapqV+lZwc+OH8rBY3 8h7I7l9clf4VPJTWNg0Jw8XBfqaT/AqQppkMPHy13tX+t2ggarV76i5P0 FGXC7DtcjDX7mFjMVxea8CL13WWa4DCTUL6HfGIZrO2YLmXxzdZL/XXGb C9CSQYPR1oBnCwtJ4ojOJcJG/TLfLSw805ntgaPD+i4kT1w4nMnEfFFax A==; X-IronPort-AV: E=McAfee;i="6500,9779,10470"; a="298457278" X-IronPort-AV: E=Sophos;i="5.93,315,1654585200"; d="scan'208";a="298457278" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Sep 2022 08:33:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,315,1654585200"; d="scan'208";a="679096666" Received: from txandevlnx322.an.intel.com ([10.123.117.44]) by fmsmga008.fm.intel.com with ESMTP; 14 Sep 2022 08:33:24 -0700 From: Naga Harish K S V To: jerinj@marvell.com Cc: dev@dpdk.org, erik.g.carrillo@intel.com, pbhagavatula@marvell.com, sthotton@marvell.com, stable@dpdk.org Subject: [PATCH v7 2/3] timer: fix function to stop all timers Date: Wed, 14 Sep 2022 10:33:18 -0500 Message-Id: <20220914153319.1887248-2-s.v.naga.harish.k@intel.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220914153319.1887248-1-s.v.naga.harish.k@intel.com> References: <20220914135147.1846550-1-s.v.naga.harish.k@intel.com> <20220914153319.1887248-1-s.v.naga.harish.k@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org There is a possibility of deadlock in this API, as same spinlock is tried to be acquired in nested manner. If the lcore that is stopping the timer is different from the lcore that owns the timer, the timer list lock is acquired in timer_del(), even if local_is_locked is true. Because the same lock was already acquired in rte_timer_stop_all(), the thread will hang. This patch removes the acquisition of nested lock. Fixes: 821c51267bcd63a ("timer: add function to stop all timers in a list") Cc: stable@dpdk.org Signed-off-by: Naga Harish K S V --- lib/timer/rte_timer.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/timer/rte_timer.c b/lib/timer/rte_timer.c index 9994813d0d..85d67573eb 100644 --- a/lib/timer/rte_timer.c +++ b/lib/timer/rte_timer.c @@ -580,7 +580,7 @@ rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks, } static int -__rte_timer_stop(struct rte_timer *tim, int local_is_locked, +__rte_timer_stop(struct rte_timer *tim, struct rte_timer_data *timer_data) { union rte_timer_status prev_status, status; @@ -602,7 +602,7 @@ __rte_timer_stop(struct rte_timer *tim, int local_is_locked, /* remove it from list */ if (prev_status.state == RTE_TIMER_PENDING) { - timer_del(tim, prev_status, local_is_locked, priv_timer); + timer_del(tim, prev_status, 0, priv_timer); __TIMER_STAT_ADD(priv_timer, pending, -1); } @@ -631,7 +631,7 @@ rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim) TIMER_DATA_VALID_GET_OR_ERR_RET(timer_data_id, timer_data, -EINVAL); - return __rte_timer_stop(tim, 0, timer_data); + return __rte_timer_stop(tim, timer_data); } /* loop until rte_timer_stop() succeed */ @@ -987,21 +987,16 @@ rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores, walk_lcore = walk_lcores[i]; priv_timer = &timer_data->priv_timer[walk_lcore]; - rte_spinlock_lock(&priv_timer->list_lock); - for (tim = priv_timer->pending_head.sl_next[0]; tim != NULL; tim = next_tim) { next_tim = tim->sl_next[0]; - /* Call timer_stop with lock held */ - __rte_timer_stop(tim, 1, timer_data); + __rte_timer_stop(tim, timer_data); if (f) f(tim, f_arg); } - - rte_spinlock_unlock(&priv_timer->list_lock); } return 0; -- 2.25.1