From patchwork Fri Apr 8 01:01:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Duoming Zhou X-Patchwork-Id: 12805985 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F585C433F5 for ; Fri, 8 Apr 2022 01:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbiDHBDP (ORCPT ); Thu, 7 Apr 2022 21:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230169AbiDHBDO (ORCPT ); Thu, 7 Apr 2022 21:03:14 -0400 Received: from zju.edu.cn (mail.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AE262028B9; Thu, 7 Apr 2022 18:01:11 -0700 (PDT) Received: from ubuntu.localdomain (unknown [10.15.192.164]) by mail-app4 (Coremail) with SMTP id cS_KCgCXDaVPiU9imQ7qAA--.29743S2; Fri, 08 Apr 2022 09:01:08 +0800 (CST) From: Duoming Zhou To: linux-kernel@vger.kernel.org Cc: linux-rdma@vger.kernel.org, jgg@ziepe.ca, shiraz.saleem@intel.com, mustafa.ismail@intel.com, dan.carpenter@oracle.com, Duoming Zhou Subject: [PATCH V3 09/11] drivers: infiniband: hw: Fix deadlock in irdma_cleanup_cm_core() Date: Fri, 8 Apr 2022 09:01:02 +0800 Message-Id: <20220408010102.32180-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cS_KCgCXDaVPiU9imQ7qAA--.29743S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCw13Zr1DtryDZw43Kr48WFg_yoW5Grykpr WDWw4f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.org There is a deadlock in irdma_cleanup_cm_core(), which is shown below: (Thread 1) | (Thread 2) | irdma_schedule_cm_timer() irdma_cleanup_cm_core() | add_timer() spin_lock_irqsave() //(1) | (wait a time) ... | irdma_cm_timer_tick() del_timer_sync() | spin_lock_irqsave() //(2) (wait timer to stop) | ... We hold cm_core->ht_lock in position (1) of thread 1 and use del_timer_sync() to wait timer to stop, but timer handler also need cm_core->ht_lock in position (2) of thread 2. As a result, irdma_cleanup_cm_core() will block forever. This patch removes the check of timer_pending() in irdma_cleanup_cm_core(), because the del_timer_sync() function will just return directly if there isn't a pending timer. As a result, the lock is redundant, because there is no resource it could protect. What`s more, we change the check of timer_pending() in order to guarantee the add_timer() in irdma_schedule_cm_timer() and irdma_cm_timer_tick() could be executed. Signed-off-by: Duoming Zhou --- Changes in V3: - Change the check of timer_pending(). drivers/infiniband/hw/irdma/cm.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c index dedb3b7edd8..1901792fd73 100644 --- a/drivers/infiniband/hw/irdma/cm.c +++ b/drivers/infiniband/hw/irdma/cm.c @@ -1181,7 +1181,7 @@ int irdma_schedule_cm_timer(struct irdma_cm_node *cm_node, spin_lock_irqsave(&cm_core->ht_lock, flags); was_timer_set = timer_pending(&cm_core->tcp_timer); - if (!was_timer_set) { + if (was_timer_set) { cm_core->tcp_timer.expires = new_send->timetosend; add_timer(&cm_core->tcp_timer); } @@ -1364,7 +1364,7 @@ static void irdma_cm_timer_tick(struct timer_list *t) if (settimer) { spin_lock_irqsave(&cm_core->ht_lock, flags); - if (!timer_pending(&cm_core->tcp_timer)) { + if (timer_pending(&cm_core->tcp_timer)) { cm_core->tcp_timer.expires = nexttimeout; add_timer(&cm_core->tcp_timer); } @@ -3251,10 +3251,7 @@ void irdma_cleanup_cm_core(struct irdma_cm_core *cm_core) if (!cm_core) return; - spin_lock_irqsave(&cm_core->ht_lock, flags); - if (timer_pending(&cm_core->tcp_timer)) - del_timer_sync(&cm_core->tcp_timer); - spin_unlock_irqrestore(&cm_core->ht_lock, flags); + del_timer_sync(&cm_core->tcp_timer); destroy_workqueue(cm_core->event_wq); cm_core->dev->ws_reset(&cm_core->iwdev->vsi);