Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3178186rdb; Wed, 13 Sep 2023 04:47:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBpggbc64l3R4l6s6g9PvPWcK+9PZvjRawqkcdRszYCJuyPeAdNa/tvAwiSHToHwwrBvyF X-Received: by 2002:a05:6e02:1545:b0:34b:f3b:77b5 with SMTP id j5-20020a056e02154500b0034b0f3b77b5mr2138902ilu.30.1694605619814; Wed, 13 Sep 2023 04:46:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694605619; cv=none; d=google.com; s=arc-20160816; b=mLsrzbu/+Yy/k44i1MA/L72KeNiBvSE5iP7jYQRdfYeVGanupcD9BYSKmU+7goP7A8 EXS57jpLB8kBTOtUe+9+9tIqH3qIEHh13h3M/KxZj4FH4oFGHaiBAm+OksQdCBbWsMIq sbyVDW0uI6KbwnAf4JZT45xTgZcKtgVv2R5hdljkZynx267tN4kADrplS5/HyLs3pDaV eMPBpzvZBU+JSP8r/5XBE3BBGbPNvADHuCyxj6QG6bG+KHxQ08ESglQNxRcfSV5+lI/v 9urEcbKhQnhYglM0tNyjUbeyQK2DKZownz1Y1kPj8Vf6odQsFyBz7lJFBx7csjeuxDse Bitw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=mO3rBAaVXtSNSRsg3Ptl9WyhXkiJ3zI3uSXq8/3XVB8=; fh=4oDiqjZ+kO0YjW1XhTF3VNsdYS1A8OqsmCCpSjWZ0rE=; b=Poz+WDxoqcIkFulSBIIQTwvWa9wMZitEBKQQFNpQHqzDQjdyRexqqQjhFSNh5xF/cT 9m1P6SaqXPBrfwWOOMDQLvIOoXmwTtJ+NI4lGIxMmk4RE9lJsckZjtha6FMMDY5PE+fG IQHTdn4Fw4iT+PSizIbuZ584HTNuwYvIFSZLWUNDeccwKaeKs0RWoaTtCcYYlN3LbVCl ca+9/hCGf4n/9x+/aqHfXDgGBUkBEv06tCPgHtEHA5c/2m14v5qK9AVO1U9JZQEJ4Lxx bwHc9Sv1jDbL1IfvCKXuGcMuyJrORCIfLGR77VBY5r1QF5cSRg/fk/1OmhGRviet8qU2 3cxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=P9eBfJem; 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=quicinc.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a35-20020a631a63000000b00563ee04bbafsi9477079pgm.837.2023.09.13.04.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:46:59 -0700 (PDT) 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=@quicinc.com header.s=qcppdkim1 header.b=P9eBfJem; 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=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D4C4B81E0FC9; Wed, 13 Sep 2023 01:48:33 -0700 (PDT) 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 S239061AbjIMIs3 (ORCPT + 99 others); Wed, 13 Sep 2023 04:48:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239103AbjIMIsY (ORCPT ); Wed, 13 Sep 2023 04:48:24 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A86D11998; Wed, 13 Sep 2023 01:48:20 -0700 (PDT) Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38D8ZAJU025716; Wed, 13 Sep 2023 08:47:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=qcppdkim1; bh=mO3rBAaVXtSNSRsg3Ptl9WyhXkiJ3zI3uSXq8/3XVB8=; b=P9eBfJemNULX+EeqDiKz/wS9mP5Rya5aQGgdJV6648qNnpnSpqv/2Enr1vywLvLhDXtn AAOQC3nHkxgvRzMU9GwiwWXiVfQaPJc/XiBp42W/Xd2GKNgD20BQtY9Q2c/wuLS9FqKK jHd3oF3Fkdn2YikgKTa16QdMyc4P2yZWWw647oV2qjfaZiTOoNHbHX4nkHo565e0SBL2 U4hDcWo6HW3U+jQ2V42mnNuE6H7i+udi8SNC1owJscAL/Z6DaSbrbqjhVV39IafANFDs T5/dyszW8LSMIZr2BwBos17vU3A4L9fdHHhcLG6UUtu7lcWTKs49gkQkEtMVwKLbNYmn Hw== Received: from aptaippmta02.qualcomm.com (tpe-colo-wan-fw-bordernet.qualcomm.com [103.229.16.4]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t2y8js3xt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 Sep 2023 08:47:48 +0000 Received: from pps.filterd (APTAIPPMTA02.qualcomm.com [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTP id 38D8ljQA017785; Wed, 13 Sep 2023 08:47:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 3t0hskhgys-1; Wed, 13 Sep 2023 08:47:45 +0000 Received: from APTAIPPMTA02.qualcomm.com (APTAIPPMTA02.qualcomm.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 38D8ljif017780; Wed, 13 Sep 2023 08:47:45 GMT Received: from cbsp-sh-gv.qualcomm.com (CBSP-SH-gv.ap.qualcomm.com [10.231.249.68]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 38D8liom017779; Wed, 13 Sep 2023 08:47:45 +0000 Received: by cbsp-sh-gv.qualcomm.com (Postfix, from userid 4098150) id 1927A4DDF; Wed, 13 Sep 2023 16:47:44 +0800 (CST) From: Qiang Yu To: mani@kernel.org, quic_jhugo@quicinc.com Cc: 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 , Qiang Yu Subject: [PATCH v2 1/2] bus: mhi: host: Add spinlock to protect WP access when queueing TREs Date: Wed, 13 Sep 2023 16:47:40 +0800 Message-Id: <1694594861-12691-2-git-send-email-quic_qianyu@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1694594861-12691-1-git-send-email-quic_qianyu@quicinc.com> References: <1694594861-12691-1-git-send-email-quic_qianyu@quicinc.com> X-QCInternal: smtphost X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: Evqdl4VAY2GIVNWfcL5N-uHIGw0U_0Nz X-Proofpoint-GUID: Evqdl4VAY2GIVNWfcL5N-uHIGw0U_0Nz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-13_02,2023-09-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 phishscore=0 impostorscore=0 spamscore=0 mlxlogscore=596 malwarescore=0 priorityscore=1501 clxscore=1015 mlxscore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309130070 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]); Wed, 13 Sep 2023 01:48:34 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email 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. 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