Received: by 2002:a05:7412:4e10:b0:e2:908c:2ebd with SMTP id gb16csp43043rdb; Mon, 6 Nov 2023 23:17:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWwnSSrHKj4YmdXETzZr1bqJfDPTA+ob+98HxmVV1dv95OXfIFDCMBSsiHbwYQRTC3EH2Q X-Received: by 2002:a17:902:d490:b0:1cc:5920:1d1c with SMTP id c16-20020a170902d49000b001cc59201d1cmr23375682plg.48.1699341445054; Mon, 06 Nov 2023 23:17:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699341445; cv=none; d=google.com; s=arc-20160816; b=mf54r21bUvWQaVJQfGdSvciTFoTDztfXD99s7VvykIGEcNBRnNyBLGCR2yzNTkWP8s pz4PuGysMwEpymUZUwBhNvqVAjiutI5CBv/EZZwoLcrvASMZZebdpJEShioYJVxnxB3a dAPgJx8e0Wftw6w8ViTOfF3r8S2MMQZwNLqBV9xs3ZrLxorwwfMcC3AjieJdXuVwKuHo vZDnEvtEHMqCGBAq8VeFG4PSS8+kTKH4sr6My7veGxHlpa6LOpMwNdQd/ZDt/9rLHAZl +9iLDoWFWrSW9MZ/v0JSt+7u5JsjRFLGxuQeBkfQLPxNzXMjB9jhbkCxVsHqIq4M3p1s 8Lmw== 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=c22HVGQNNbHCzJdzQ6OlClcb1N10zdXR7XIevb40yuA=; fh=7y8XBjHEOFaIi1bWwlOqynzp3kMu6S1xEU1Lbig9USo=; b=EKk2Sw+HgfHm+5V1UlAvE59PEI+Efoo347Af1Sp7pktqcnV4DwTZzRLfyaeUTru80F cy0Vyo2KqjWJ6z3fXG6+j1l1DyF5h+9lwllAI73mCccGktzcda8I3nYEnxIS+wY9XP8f Y6lobVqIxt3VosRCbZh+Pwzcfxm9zuuMmF1zePcCYOCF6aFxKONsyI3uRTdNkVXt8hW4 wLcj5E/jVKwkHk4FZ/gmlpD3c7CHyoW1CtFku0+jes1r0Pir9ekBqyauJJ8+/6xEMnr2 +QxWaTfgxPkBaJeP5D9Q5coeuPYZOPvP5hcaCMHgVSRMuUPkc+9ZxVOSdmf6nooTnjh/ cTyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="WaTYrw/X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m17-20020a170902f21100b001cc2ebd2c3dsi8961502plc.161.2023.11.06.23.17.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 23:17:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="WaTYrw/X"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 13CD88116E4C; Mon, 6 Nov 2023 23:17:24 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233549AbjKGHRU (ORCPT + 99 others); Tue, 7 Nov 2023 02:17:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233550AbjKGHRS (ORCPT ); Tue, 7 Nov 2023 02:17:18 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E69171C; Mon, 6 Nov 2023 23:17:03 -0800 (PST) Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A76BHpp027977; Tue, 7 Nov 2023 07:16:27 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=c22HVGQNNbHCzJdzQ6OlClcb1N10zdXR7XIevb40yuA=; b=WaTYrw/X2UqG33Z2WuArd233vWKvBTk51PQy78jbtIfmX1CVI+NL6qlUxRouk0YcP9uG 9X/Nt7Bk18pjvtAXuDxepfo144JDCvzmiAf2t65C1m40ccCO53Y/D/XPDc/NXBRb3TZC ZVUtLidaDstZ4wtagqla3XtjrY/3oRQKvgqVbJTwmGTk51o+n3bQmanjhafZ5xpsFSSs y/jTmWAeobRsg7wvsvGNb6nRYi5/bHEAgCbsjaFb+UqT6w8czVnkXpvROQ5tFU5knDtl R7G/igN0OSYtmWiby8ecKnQBYG3INho6b6A42bPtweUiPa5Dwxwy/Kk1d/67I4D3XK/2 KQ== 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 3u72avswwg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 07 Nov 2023 07:16:27 +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 3A77G8GS008365; Tue, 7 Nov 2023 07:16:08 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 3u5f1kdxjs-1; Tue, 07 Nov 2023 07:16:08 +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 3A77G8ok008359; Tue, 7 Nov 2023 07:16:08 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 3A77G83f008358; Tue, 07 Nov 2023 07:16:08 +0000 Received: by cbsp-sh-gv.qualcomm.com (Postfix, from userid 4098150) id 783385442; Tue, 7 Nov 2023 15:16:07 +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 , stable@vger.kernel.org, Qiang Yu Subject: [PATCH v3 1/4] bus: mhi: host: Add spinlock to protect WP access when queueing TREs Date: Tue, 7 Nov 2023 15:16:02 +0800 Message-Id: <1699341365-47737-2-git-send-email-quic_qianyu@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1699341365-47737-1-git-send-email-quic_qianyu@quicinc.com> References: <1699341365-47737-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: -c4mk4Ixz3x-Q8qczvdFQfY0IY_Qzz79 X-Proofpoint-GUID: -c4mk4Ixz3x-Q8qczvdFQfY0IY_Qzz79 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-06_15,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 mlxlogscore=332 impostorscore=0 phishscore=0 bulkscore=0 adultscore=0 priorityscore=1501 clxscore=1011 spamscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311070059 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_NONE, SPF_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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 23:17:24 -0800 (PST) From: Bhaumik Bhatt Protect WP accesses such that multiple threads queueing buffers for incoming data do not race. Cc: Fixes: 189ff97cca53 ("bus: mhi: core: Add support for data transfer") Signed-off-by: Bhaumik Bhatt Signed-off-by: Qiang Yu --- drivers/bus/mhi/host/main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/bus/mhi/host/main.c b/drivers/bus/mhi/host/main.c index 6cf1145..c9415b0 100644 --- a/drivers/bus/mhi/host/main.c +++ b/drivers/bus/mhi/host/main.c @@ -1205,6 +1205,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; @@ -1222,8 +1225,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); @@ -1240,6 +1245,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