From patchwork Mon Dec 11 06:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 17820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6866389vqy; Sun, 10 Dec 2023 22:43:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFoPnTDIDIuryw0dRTFdY9qRXqq6k7pKF2drEhevqVT7kaLTLp1n3DunPao4GfgjT8vyMU5 X-Received: by 2002:a17:90a:d70b:b0:28a:26bf:bd64 with SMTP id y11-20020a17090ad70b00b0028a26bfbd64mr2817086pju.27.1702276994935; Sun, 10 Dec 2023 22:43:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702276994; cv=none; d=google.com; s=arc-20160816; b=oWSC/brM6CJoI0/S/ifESnT/l6OYcBBikTRCcpf0Ju8Dws9XuC+gIP1VXXldXbEbP8 MJ7sgoAvtUrnijj1R5l36JV2ecNW+KDPhCrlhR4uEUfYiS0jnjPGN5bmKnm2DjYp/Xk/ 5kPmmbcJrAMrdx6Dkh19mpMVSL2bwcvNCM+yKChBeVnsgymNU/wBWoW8LdVCzCG9sQJy YQh6jQkVLj+011j98PgZzEwv5z7ISpfrpggSfF71nicLpESW9GJ++9t2mZtnnWWWCSAt lrHPBnW27ds+39jWGHvHX1ge1fdwJ2U4UBsZ5y5TIbTRj5MANVbF/AnEea1uTsaW/4Lh Sv5g== 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=gDmF3Z8bpvyT2isGQR96C4xl9uFFMECarS08e0Gntcs=; fh=f4KQnOf4DL3FZ4rINpxCCB681RH9plJXTbAzdkN1cKE=; b=OoMe2LI+HxZdTzg1CfXy0bY5PyKVsTWfaXo6dJYvlX/Rd+l/PsETq3LCvcoX2pD3fo f98RuAz1tqymIbrGmHVgEXpQpqlh9kqyozYet3esIOPljK4TpWDeJSwTc06oGyydeImm Y2Fd6fd+08DytTxPMWHg95EG5e6a18aW/N5Mp5DvDgsu1Rls9MAwoCSJJpawWyKY58T7 6kUzLVzBUD3+55+sJ3+INvz3OS8uRK/Rc8nykSxxzJiwfNVr9Bqf0+U5RzRtnTITe7KC wJe5lQvQNcdMtCgJUFEhVYEo/9zS3PkFWuOI5pJI874bdhkA6xe+mmOmoeZEBuOUH6Gk TDEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=meBN3Vtn; 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id nd17-20020a17090b4cd100b0028526216f31si5778558pjb.106.2023.12.10.22.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 22:43:14 -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=meBN3Vtn; 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 A6BF18095001; Sun, 10 Dec 2023 22:43:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233510AbjLKGnF (ORCPT + 99 others); Mon, 11 Dec 2023 01:43:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229570AbjLKGnD (ORCPT ); Mon, 11 Dec 2023 01:43:03 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 672E5B5; Sun, 10 Dec 2023 22:43:09 -0800 (PST) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BB5kZCJ028438; Mon, 11 Dec 2023 06:42:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id; s=qcppdkim1; bh=gDmF3Z8bpvyT 2isGQR96C4xl9uFFMECarS08e0Gntcs=; b=meBN3VtnBit3X/I56N8Mulby2qUZ 60VL2VBdetWqFQsffLIArcxS9LWuIl/R1hkO5ZDQBhPYnOzORVlASlrn/03WaxcM m4p0b653azm1MffIPcHn6wTUrny1wCXmaFECl2aukrNpOVvZX4pK3mhagUT8nZq1 mzn+J/5QtGrYZz/4UovCYx5NUeb4PxderLl6Lknb4dOBZUsJQt8u+W91XOUt01t8 q5K9B8TBSxaYiYYhSNvEwL14Om27r35HS5CqXpvrFWp5pHF4kguwIqq13DzmpiWB J13v33o9YQgLgZeWdXuEbtngNsKsTR+EkXkuwK1Lg09vvS/fQ6kPqulqsA== 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 3uvney2gkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Dec 2023 06:42:57 +0000 (GMT) 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 3BB6gtkt026134; Mon, 11 Dec 2023 06:42:55 GMT Received: from pps.reinject (localhost [127.0.0.1]) by APTAIPPMTA02.qualcomm.com (PPS) with ESMTP id 3uvhak8ycp-1; Mon, 11 Dec 2023 06:42:55 +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 3BB6gtsb026128; Mon, 11 Dec 2023 06:42:55 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 3BB6gtG5026127; Mon, 11 Dec 2023 06:42:55 +0000 Received: by cbsp-sh-gv.qualcomm.com (Postfix, from userid 4098150) id 016C355E7; Mon, 11 Dec 2023 14:42:53 +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, Qiang Yu Subject: [PATCH v5 0/2] bus: mhi: host: Add lock to avoid race when ringing channel DB Date: Mon, 11 Dec 2023 14:42:50 +0800 Message-Id: <1702276972-41296-1-git-send-email-quic_qianyu@quicinc.com> X-Mailer: git-send-email 2.7.4 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-GUID: SS15zwtudvQ1jNPVx9kJqxPv_KROnGsh X-Proofpoint-ORIG-GUID: SS15zwtudvQ1jNPVx9kJqxPv_KROnGsh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 impostorscore=0 mlxlogscore=536 mlxscore=0 phishscore=0 spamscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312110054 X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,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]); Sun, 10 Dec 2023 22:43:13 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784966802008095968 X-GMAIL-MSGID: 1784966802008095968 1. We need a write lock in mhi_gen_tre otherwise there is race of the WP used for ringing channel DB between mhi_queue and M0 transition. 2. We can not invoke local_bh_enable() when irqs are disabled, so move read_lock_irqsave() under the mhi_gen_tre() since we add write_lock_bh() in mhi_gen_tre(). 3. Unlock xfer_cb to prevent potential lockup v1 -> v2: Added write_unlock_bh(&mhi_chan->lock) in mhi_gen_tre() before return because of error process. v2 -> v3: 1. split protecting WP and unlocking xfer_cb into two patches 2. Add a new patch to stop processing buffer and eventof a disabled or stopped channel. v3 -> v4: 1. Modify commit message 2. Add unlock operation before return error v4 -> v5: 1. Squash "protecting WP" and "Take irqsave lock" into one patch 2. Drop patch 3/4 of patch v4 Bhaumik Bhatt (1): bus: mhi: host: Add spinlock to protect WP access when queueing TREs Qiang Yu (1): bus: mhi: host: Drop chan lock before queuing buffers drivers/bus/mhi/host/main.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-)