Received: by 2002:a05:6512:2355:0:0:0:0 with SMTP id p21csp73203lfu; Thu, 7 Apr 2022 20:43:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdCR4EXwxeCZiuvJLPCHoLUgkGIgVGJi2Wv/nc7aEElV74qcj+SjamwZHt0aKN12wJl6BB X-Received: by 2002:a17:90b:3005:b0:1cb:f2b:2d03 with SMTP id hg5-20020a17090b300500b001cb0f2b2d03mr7874259pjb.20.1649389421071; Thu, 07 Apr 2022 20:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649389421; cv=none; d=google.com; s=arc-20160816; b=VNNUOUGrOJ12BJ5t9tbdJoZVHgjilaAQMadVql72zOgTA17uRLNaVXSpkhNSsXRU5m kbXK9lqkNOS7X9iQdbYScPXx43uKsHsoKHRu53XGplw9eaVqlG5gngmDaOH8/Cpe4V5t C/gBWP32LSgq17NwUmGLh6jd+HxHSH1vFvpnT1VaLTPOmkl+/LyCyg/zP6pQSd1uVBmr LEQcq2RsD6mkSECYNHVQ1TcS2FDrzoavj/ILfvFQzzRVd0Gu3PkKIaDp3j4L5Esj7FZI v97IcKvuDm4hi5UDFTC/1gr2Did7jPtSJ25FYJhuuypO7Kdj1VvvwKyb/WhmbmbaZ1Zw 6vMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=k6Y40touXBPlqGD5E0/1aQ59uQLBFnTynFDeGb4onxU=; b=cm67cY9ry2zjSXwRHGOd0tZs45iTa0yc9mhgJ4/KUTIKqmufJcegSJGn1m7M27ICuw 3gFXJ78CLtWG0AH1+Tc6yrlAqWcIR2C7uNqk3XLUp8HZsrz29wojVF/6lVg7jccdIXum EX5eCv4elY2/ctcsMzpdlDGgBvuHohaZ8PKqjECveu8Ihiodixgm7humFYSiDpziwl73 OCvTbfziyp61/Oo2N9hxFi3XZs2Vml2dv3jDdy3+4HxB/jdkQ2097tH057cvIUOzf36Q S/qSxemzQ/fl4ijzwHiGINj9ICOOeSv5njRSV3/p/jgnqT8dwjwuf6KHq7wyIGK9BZLx gWeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s7-20020a170902a50700b00153b2d164b1si1350416plq.185.2022.04.07.20.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 20:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92D88182D9E; Thu, 7 Apr 2022 20:09:56 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233876AbiDHDLd (ORCPT + 99 others); Thu, 7 Apr 2022 23:11:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233915AbiDHDLZ (ORCPT ); Thu, 7 Apr 2022 23:11:25 -0400 Received: from zju.edu.cn (spam.zju.edu.cn [61.164.42.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E3711177D2A; Thu, 7 Apr 2022 20:09:12 -0700 (PDT) Received: from ubuntu.localdomain (unknown [10.15.192.164]) by mail-app2 (Coremail) with SMTP id by_KCgB3H0xRp09ighhTAQ--.27376S2; Fri, 08 Apr 2022 11:09: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 V4 09/11] drivers: infiniband: hw: Fix deadlock in irdma_cleanup_cm_core() Date: Fri, 8 Apr 2022 11:09:04 +0800 Message-Id: <20220408030904.34145-1-duoming@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: by_KCgB3H0xRp09ighhTAQ--.27376S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCw13Zr1Duw4kAF1ruF45KFg_yoW5Grykpr WDW3yakryq9r47Ka18Z3WkXF9xXwn5JFWjvrykt395AFs7XryjyF13AwnIqFZrJF9Fgrs3 uF4Fvry5CF9Iyr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk21xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW0oVCq3wA2z4x0Y4vEx4A2 jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52 x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWU GwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv 6cx26r4fKr1UJr1l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGw C20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48J MIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMI IF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUoOJ5UUUUU X-CM-SenderInfo: qssqjiasttq6lmxovvfxof0/1tbiAgYOAVZdtZFWjwAIs1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 add mod_timer() in order to guarantee the timer in irdma_schedule_cm_timer() and irdma_cm_timer_tick() could be executed. Signed-off-by: Duoming Zhou --- Changes in V4: - Add mod_timer() in order to guarantee the timer could be executed. drivers/infiniband/hw/irdma/cm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/irdma/cm.c b/drivers/infiniband/hw/irdma/cm.c index dedb3b7edd8..e4117b978bf 100644 --- a/drivers/infiniband/hw/irdma/cm.c +++ b/drivers/infiniband/hw/irdma/cm.c @@ -1184,6 +1184,8 @@ int irdma_schedule_cm_timer(struct irdma_cm_node *cm_node, if (!was_timer_set) { cm_core->tcp_timer.expires = new_send->timetosend; add_timer(&cm_core->tcp_timer); + } else { + mod_timer(&cm_core->tcp_timer, new_send->timetosend); } spin_unlock_irqrestore(&cm_core->ht_lock, flags); @@ -1367,6 +1369,8 @@ static void irdma_cm_timer_tick(struct timer_list *t) if (!timer_pending(&cm_core->tcp_timer)) { cm_core->tcp_timer.expires = nexttimeout; add_timer(&cm_core->tcp_timer); + } else { + mod_timer(&cm_core->tcp_timer, nexttimeout); } spin_unlock_irqrestore(&cm_core->ht_lock, flags); } @@ -3251,10 +3255,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); -- 2.17.1