Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1905198rdf; Sun, 5 Nov 2023 20:41:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IFAwUnnZ7HiWvBr0tJk1bBO+MjhRFxH9e2PKzFtbWQ3lpOLniGzCadST5Mhv/aUo36xWiFa X-Received: by 2002:a05:620a:4785:b0:77a:148a:3d69 with SMTP id dt5-20020a05620a478500b0077a148a3d69mr24672445qkb.43.1699245709783; Sun, 05 Nov 2023 20:41:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699245709; cv=none; d=google.com; s=arc-20160816; b=oRi27BkiZXK1S+6rPa5/2IkBWOxsNIEpPTqLNF/qEvBjLE7MWF+SpxDdYABC4p1iUn HnoVN5GviZeReEQigXCB9NsY+BljgD6EhAaQ8RgPhCjOyM2gAknTjgA+YE4GP8PNxlII K30In5Ffu76S4h9gIZR2DBhITvq0NOUxNcULZp/hNFaYfL6TrQ7wWODiIr2vIG7TN9xo htCez6n9ZEUpwVJiOM44dTql73FG3x34i0yi8+SGKKJWIrSglAGxU8mIVIizC4YmmUd4 lJoZ8SBkLwx45e6n7mAWjOeE6jBxoX01XY3c3bWScN1TB+mvUj+HhE/4lWdGux6uniOf JSVg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=eYVVNgbDyvPvAjftWGHVq3yarHwzP/r3hpjW11Ck/KI=; fh=0uqM5rMdM4xlnjj5Jx5qU/vMyNNvEmLQ6bXKeDw3zRM=; b=BGKXmuJLza9Js0RdK6f4OHOCy/qVKgGDL51IVnRwP9ycYdMm/PDIzAxv5395UOLNgP 5gzNoiWQIhbE/yAzeioVgJsy4cvcLakrhmVulnZLFIegB89/cciN6Fd3iYkU7tW3D7ts pSQvHBTrL+wuwy8m/aweichhHGDapI9CJBDWXc4nnypTaI40EsePKZG4zQ7bpl9kYa6g 6oyk8EgV7AW76YZWpMJB/JnsGIvEnpBT+/V58J8l7klYG/cLlomTYORUGRpOVsnDTdvO +YxDi7kysXP3j7kN4AewuuQq/OutqCynTP6LqvFqqyPvgiOTTcgwcTd53hZRA/zVVvGk lGow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Peu4o7qw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bg10-20020a056a02010a00b005b7c45c3cabsi7893663pgb.857.2023.11.05.20.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 20:41:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Peu4o7qw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B03B6805FD1C; Sun, 5 Nov 2023 20:41:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230117AbjKFEli (ORCPT + 99 others); Sun, 5 Nov 2023 23:41:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229717AbjKFElh (ORCPT ); Sun, 5 Nov 2023 23:41:37 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAE30F2; Sun, 5 Nov 2023 20:41:34 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BE74C433C7; Mon, 6 Nov 2023 04:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699245694; bh=IIAQOZpGjXwc7fKWKRroagG6s2bx1zCT3L6uGLaxqXs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Peu4o7qwkZo0Z/MtDJwwNepcGBQMJdQbjgWPgzXc+T/RJql4g3M4oNSBYjfwm3zA8 D60CvLEE8mwOV7PvEoMIEr0N8CG6NJvNBQt51rV65D6wl33VBWMJcuxScTcqWD6BEn jjWBpUfGQcdxWVa16xNRGkao9uCTdhAbjK71voulOHuLOUn21VC4fWWJeRbz//adoV z+3EUB8vYniwy7gQ9qyvn2+adlyfL0J8E4SZPv59SCf338th4OPhS1kk7KYPE7bJzG ovbSinbVbc79rWH6cdf2MMMm/gvLJkcSKmk7W6H6O8cnG9Lbpn9XVpSNkdEpR/Gu3C 9a4KSxhSjHfKg== Date: Mon, 6 Nov 2023 10:11:26 +0530 From: Manivannan Sadhasivam To: Qiang Yu Cc: mani@kernel.org, quic_jhugo@quicinc.com, mhi@lists.linux.dev, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, quic_cang@quicinc.com, quic_mrana@quicinc.com, Bhaumik Bhatt Subject: Re: [PATCH v2 1/2] bus: mhi: host: Add spinlock to protect WP access when queueing TREs Message-ID: <20231106044126.GA2474@thinkpad> References: <1694594861-12691-1-git-send-email-quic_qianyu@quicinc.com> <1694594861-12691-2-git-send-email-quic_qianyu@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1694594861-12691-2-git-send-email-quic_qianyu@quicinc.com> X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 05 Nov 2023 20:41:46 -0800 (PST) On Wed, Sep 13, 2023 at 04:47:40PM +0800, Qiang Yu wrote: > From: Bhaumik Bhatt > > Protect WP accesses such that multiple threads queueing buffers for > incoming data do not race and access the same WP twice. Ensure read and > write locks for the channel are not taken in succession by dropping the > read lock from parse_xfer_event() such that a callback given to client > can potentially queue buffers and acquire the write lock in that process. > Any queueing of buffers should be done without channel read lock acquired > as it can result in multiple locks and a soft lockup. > This change is doing two things: 1. Unlocking xfer_cb to prevent potential lockup 2. Protecting mhi_gen_tre() against concurrent access So you should split this into two patches and also add Fixes tag if appropriate. - Mani > Signed-off-by: Bhaumik Bhatt > Signed-off-by: Qiang Yu > --- > drivers/bus/mhi/host/main.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c > index dcf627b..13c4b89 100644 > --- a/drivers/bus/mhi/host/main.c > +++ b/drivers/bus/mhi/host/main.c > @@ -642,6 +642,7 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, > mhi_del_ring_element(mhi_cntrl, tre_ring); > local_rp = tre_ring->rp; > > + read_unlock_bh(&mhi_chan->lock); > /* notify client */ > mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result); > > @@ -667,6 +668,7 @@ static int parse_xfer_event(struct mhi_controller *mhi_cntrl, > kfree(buf_info->cb_buf); > } > } > + read_lock_bh(&mhi_chan->lock); > } > break; > } /* CC_EOT */ > @@ -1204,6 +1206,9 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, > int eot, eob, chain, bei; > int ret; > > + /* Protect accesses for reading and incrementing WP */ > + write_lock_bh(&mhi_chan->lock); > + > buf_ring = &mhi_chan->buf_ring; > tre_ring = &mhi_chan->tre_ring; > > @@ -1221,8 +1226,10 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, > > if (!info->pre_mapped) { > ret = mhi_cntrl->map_single(mhi_cntrl, buf_info); > - if (ret) > + if (ret) { > + write_unlock_bh(&mhi_chan->lock); > return ret; > + } > } > > eob = !!(flags & MHI_EOB); > @@ -1239,6 +1246,8 @@ int mhi_gen_tre(struct mhi_controller *mhi_cntrl, struct mhi_chan *mhi_chan, > mhi_add_ring_element(mhi_cntrl, tre_ring); > mhi_add_ring_element(mhi_cntrl, buf_ring); > > + write_unlock_bh(&mhi_chan->lock); > + > return 0; > } > > -- > 2.7.4 > > -- மணிவண்ணன் சதாசிவம்