Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18864747rwd; Wed, 28 Jun 2023 01:33:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57rMsilhq4gwSafi0xPwNJd1duRjr1nq07vW4kFJydiLeFNUZLyUafse5srP0IbXUfKg18 X-Received: by 2002:a17:90b:1a8b:b0:262:fba6:59b5 with SMTP id ng11-20020a17090b1a8b00b00262fba659b5mr5120075pjb.24.1687941180353; Wed, 28 Jun 2023 01:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687941180; cv=none; d=google.com; s=arc-20160816; b=fTPVgZ83krqXJPrgTaFocUEs0Dn+urVwlsjbTxlFggspGldmSaLZnhAKP8qE9b0K0g 6nCt3q/9Cam71HLpm2pfR4XTebY3UPUX2EVNOmLSf/ByvvR0v6vHW0V757ewVUg7Vkhc PkzCOIMKKOHcf/ahPA2Eb6m08q2YQ/w4w4CVlVnEQ1+CER/zop3+z3UrW4r7vSo66+1s oox0yss+noaJl1lFqDXlOvATkOJq8k/6LZVrOOYUR7ZlR3PRr7O4D+xuf+AyMdlr9zZI Es6csGvmBhYPpzw27KExqU2/iRiooLVxtzzTj5vudtiUFPI1exVFQymjP/8v4v45S93E wDbQ== 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 :dkim-signature; bh=KcRIZBylUodGg6xfwSa+s03103SVj3Aromni82wUePU=; fh=cJQ3twlmI4QBTLSgPSF+oYxoSfObvBFQEJji1V4R3tE=; b=rXwwG6tSFc2V5eLRf/+lTfhn1TYshPc9xaaBIxqckDaBv0J2twQ6wyoLCedN8pqdpl +W4jS+/L+2deiGjqzdaNATiyCRYwqM27KMso4VnXkOIKJ9Vz1Aj8GjsH/nqBmOM7Pjse DrstAaaEtVPaHP2evcKSiwTiIn7ixYRmyOkKZK1d5zy7Xvg4PYkWIy+cNMczj15dycJM d7DCM6fTXSQDTNyqzFKTETCjyPYOIWI4m8s9uv49/iiHBsRCNwqZ/0pZfwfpl2bImQNY yZfS9kvrs+jurET/CXN5hnMBlWudyTF1fRXMK/07swTT7mlfhdRo43qw44HrRvajVf3V 1Bpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=B0FEtoQp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h3-20020a17090aa88300b00258ee17486bsi8911655pjq.160.2023.06.28.01.32.48; Wed, 28 Jun 2023 01:33:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=B0FEtoQp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233867AbjF1IKO (ORCPT + 99 others); Wed, 28 Jun 2023 04:10:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233133AbjF1IFt (ORCPT ); Wed, 28 Jun 2023 04:05:49 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B888C2D73; Wed, 28 Jun 2023 01:04:15 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b44b5adfd3so4480533a34.3; Wed, 28 Jun 2023 01:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687939455; x=1690531455; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KcRIZBylUodGg6xfwSa+s03103SVj3Aromni82wUePU=; b=B0FEtoQpRUb3J8puVJuM9Z+DAcx79qLsl1w20PIMSoW4+yRiYUaQN3bn7R0yXE5ZAz l1ymLC0TymQw8OU29lcj3ntJEgUZm2u6v4pJb75KJ91bmJqVF9hvi4Go5HQQMBy8pOdf /JE6w+szmm4YpDn5Q+r2m4gbhlXHf2JsT/PAz31EoUWmC37Pw/aOwWu4BswTB27Z6eRq Xw4pzqweeQgSy5nvfh7ITDDkQjQokZ0dPImddUYfsazUy4PnLb6PnQ5dZZUmPYcTC3VB ZczUvJQra1SOR5flzQ6qs/bDl11iyD67i7V1lUJ9+nZOT0zOqq+pXjElrRyE/NpRlhrJ NjuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687939455; x=1690531455; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KcRIZBylUodGg6xfwSa+s03103SVj3Aromni82wUePU=; b=dx+rmfYEVZySYxLfSDrMPy9b2RpcvyN0W97+/2UBpYOd15zjIFrkO9eXSnFg9+j6wG pjlZnq2ZHQV3n99WYdKUybmiGHMVKjah9n/QIZv5moPHRS5/jQk5i021cqZYkzxaeqM8 5F+MoLJf7ItSlZmYSxhEdLCjs7I4cjzG8ogN22U5jsE3nM9krxJTt5K0dkhMVtMwdEvz RspK9W5nSZUAUIAN9jUoR/jZJ2KxVceU1g6K+50EDn/vYCjHusZEPSmMFzETz6WNYw+Z eJ7uel6nQCmS7HbWXxTtfg1BXuowdgKXAcNFAP1OFN8UM9ErPRwKT1ZtMAUj0hJl6PDf lKew== X-Gm-Message-State: AC+VfDzYVJWzkRFJrgsi7Vn8SXxw1I9nGOMv6sauHshbBwe0MBeQE3nI 4/fufVo2sIOYri8jABNZhCF8qZDA8bnOSw== X-Received: by 2002:a05:6a20:914a:b0:10b:8e96:561 with SMTP id x10-20020a056a20914a00b0010b8e960561mr26061871pzc.62.1687928408592; Tue, 27 Jun 2023 22:00:08 -0700 (PDT) Received: from 377044c6c369.cse.ust.hk (191host097.mobilenet.cse.ust.hk. [143.89.191.97]) by smtp.gmail.com with ESMTPSA id c24-20020a170902d91800b001b80f3717d5sm3544632plz.123.2023.06.27.22.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jun 2023 22:00:07 -0700 (PDT) From: Chengfeng Ye To: dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca, leon@kernel.org Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Chengfeng Ye Subject: [PATCH] IB/hfi1: Fix potential deadlock on &sde->flushlist_lock Date: Wed, 28 Jun 2023 04:59:25 +0000 Message-Id: <20230628045925.5261-1-dg573847474@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 As &sde->flushlist_lock is acquired by timer sdma_err_progress_check() through layer of calls under softirq context, other process context code acquiring the lock should disable irq. Possible deadlock scenario sdma_send_txreq() -> spin_lock(&sde->flushlist_lock) -> sdma_err_progress_check() -> __sdma_process_event() -> sdma_set_state() -> sdma_flush() -> spin_lock_irqsave(&sde->flushlist_lock, flags) (deadlock here) This flaw was found using an experimental static analysis tool we are developing for irq-related deadlock. The tentative patch fix the potential deadlock by spin_lock_irqsave(). Signed-off-by: Chengfeng Ye --- drivers/infiniband/hw/hfi1/sdma.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/sdma.c b/drivers/infiniband/hw/hfi1/sdma.c index bb2552dd29c1..0431f575c861 100644 --- a/drivers/infiniband/hw/hfi1/sdma.c +++ b/drivers/infiniband/hw/hfi1/sdma.c @@ -2371,9 +2371,9 @@ int sdma_send_txreq(struct sdma_engine *sde, tx->sn = sde->tail_sn++; trace_hfi1_sdma_in_sn(sde, tx->sn); #endif - spin_lock(&sde->flushlist_lock); + spin_lock_irqsave(&sde->flushlist_lock, flags); list_add_tail(&tx->list, &sde->flushlist); - spin_unlock(&sde->flushlist_lock); + spin_unlock_irqrestore(&sde->flushlist_lock, flags); iowait_inc_wait_count(wait, tx->num_desc); queue_work_on(sde->cpu, system_highpri_wq, &sde->flush_worker); ret = -ECOMM; @@ -2459,7 +2459,7 @@ int sdma_send_txlist(struct sdma_engine *sde, struct iowait_work *wait, *count_out = total_count; return ret; unlock_noconn: - spin_lock(&sde->flushlist_lock); + spin_lock_irqsave(&sde->flushlist_lock, flags); list_for_each_entry_safe(tx, tx_next, tx_list, list) { tx->wait = iowait_ioww_to_iow(wait); list_del_init(&tx->list); @@ -2472,7 +2472,7 @@ int sdma_send_txlist(struct sdma_engine *sde, struct iowait_work *wait, flush_count++; iowait_inc_wait_count(wait, tx->num_desc); } - spin_unlock(&sde->flushlist_lock); + spin_unlock_irqrestore(&sde->flushlist_lock, flags); queue_work_on(sde->cpu, system_highpri_wq, &sde->flush_worker); ret = -ECOMM; goto update_tail; -- 2.17.1