Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp27570932rwd; Tue, 4 Jul 2023 05:03:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlEa1Csou35NG74FY9Iw7r6yHally6A70+b21Lof61i3UFfEsL+pYt4mzg94NeRQvj0RtgM4 X-Received: by 2002:a05:6a20:8e12:b0:12f:1f5e:afbd with SMTP id y18-20020a056a208e1200b0012f1f5eafbdmr1783049pzj.17.1688472180164; Tue, 04 Jul 2023 05:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688472180; cv=none; d=google.com; s=arc-20160816; b=0g7gaq6O3XfLbvMIRVCX5WVdlqLi79GL9CY/iw/+EHXwZYECNCILxMgT/y58MTy/hf 6Oypb3aPyl4b6IIJgMwqFoAsOPlwNRlV168HbymX/T70HHIlznVEjEzRShued6EqqzP5 eEYbcNhMsQfH9WQwMRmgVfuU/FMgEr1Xteh5ha8zXb59iYEJ0rOL/1h0D8sE8pOlw2FR vURiJ2olMoqkV2KLI1io1FL+JUGHMCS472kMvEosytrn8eamyY7WxbfPb1XKdYjhlv4a GAnpsqi+Nkb4UvTFdnMP/L0L+5OemwdbenGGbQVlkfgtG7aqDOoj0nmASrAibwCD95TY bArg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=+rcZQVeiTXdVRE/7294XvJdkKfrDVFm7s2DCcZ+OS6E=; fh=CmnicKRicaj24uoGCXUDoJ2mraB7IFaN62/uJKLg2dY=; b=xzKIEK1R6xerF6TIMoGBK/7DVIx1RmefvO/qiyU6W3hwNClctzIT8DShyR+c0nsvIG HD2oREV3LAxjZVxFVvhGKU2Mp1UOF4UfLNyJSzHOWStD0mmLJh++uwm4DBuvvnp1cEn4 aEFjlnz4TwiYu/SsYkYVPEiPn+2N2RP96SEvksuFGbTy3BfEYovjE4Fh0TcS3l6n7Id2 c+FVoNvTs2X4V/WVzAK44K1mJgwNyp/zl6gc/PAgrhK1W5MxFH1oEmDriU4rjpgAwKE8 0jrOjkBAvvzeVG+UIJfBZ4xrYxw82SNDd+1cG8K1QdfsAJT7Hj1lTLBTQDVQEWdcSTCr Sk4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DE9iaSVH; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a170902d2d200b001b8a69660bbsi1113504plc.156.2023.07.04.05.02.44; Tue, 04 Jul 2023 05:03: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=@kernel.org header.s=k20201202 header.b=DE9iaSVH; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbjGDLtA (ORCPT + 99 others); Tue, 4 Jul 2023 07:49:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbjGDLs5 (ORCPT ); Tue, 4 Jul 2023 07:48:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBBF4135; Tue, 4 Jul 2023 04:48:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4B54E6121F; Tue, 4 Jul 2023 11:48:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3914C433C7; Tue, 4 Jul 2023 11:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688471335; bh=GJkHeVjvMujvpKVUZcEumEtlW+Gx++DF0djb7kdfwkg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DE9iaSVHwYYugFEJ6VJBPzIKD1MTrwvPZuyPN1pD2IV0OQvmpjDwewHndbpTRTWH0 DFDFXq2/EDwcJhSHc/PZcgRJq1jA4uAxNxMx7DxaIzp+xtovXulNKKNEOfqM6HgwZZ kstFok8gLBDbqkw0jxVdeeGYID1YU7uiZpWAFhtqKTnGzCvN5wI9TkvYKEV8S8qHkH ydDcy5xNw0A1tztfenvCUQEWfE2BKo7MDH6on/1uS8t487kyHgnA02czTNwzomqu3b k3x+V/lwtMan1Kwsg6r8aotAgBbN072qcD8C2GIuFTZsDLKOsOfnhqHGnrXK9MGQyz hxPUEs9VePnTQ== Date: Tue, 4 Jul 2023 14:48:49 +0300 From: Leon Romanovsky To: Chengfeng Ye Cc: dennis.dalessandro@cornelisnetworks.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] IB/hfi1: Fix potential deadlock on &sde->flushlist_lock Message-ID: <20230704114849.GA6455@unreal> References: <20230628045925.5261-1-dg573847474@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230628045925.5261-1-dg573847474@gmail.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Wed, Jun 28, 2023 at 04:59:25AM +0000, Chengfeng Ye wrote: > 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; It can't work as exactly after "ret = -ECOMM;" line, there is "goto unlock" and there hfi1 calls to spin_unlock_irqrestore(..) with same "flags". Plus, we already in context where interrupts are stopped. Thanks > @@ -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 >