Message ID | 20230403025230.25035-3-chunfeng.yun@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2028390vqo; Sun, 2 Apr 2023 19:57:25 -0700 (PDT) X-Google-Smtp-Source: AKy350YLECybxDMeLgbR8ekEeb6Kut6ZK1a9214s5VHqDFQMa59e8UskBYw7KBbA0m7q3D5scK4U X-Received: by 2002:a17:90b:4c0b:b0:23e:fa90:ba34 with SMTP id na11-20020a17090b4c0b00b0023efa90ba34mr41109789pjb.37.1680490645519; Sun, 02 Apr 2023 19:57:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680490645; cv=none; d=google.com; s=arc-20160816; b=fZ3fK1RqCf86Q2vyPVXzgABvQiflUARtppdhsmjVasxKEYB7z6PCSIDQOZT2VsF3lZ BaZii4e9m9AJdDkYiaaghYDx8MnxFUQLCRmO9Xqw8tkhaS9GuIFjmnOr9qaPmUtHGCgw uiw7tyeofuap/lZVOoE9VbQBLRc3ppi55Q4qp4Dg6gpfbLBc/hIrPvJoNeCr3rxDvVaD PTDfClUkFr+kZNc4fJkqO6yeBSs+8VN1h73j+fIIpxSrKcdw1vsHiy+TypYh4kS0l0WE 5vFSWjB3dx5pQV6J6chjht1OfrgzKG44m1gjltJBYgvJ7dCv4oxZcN6VFh3LCrEClvTs lsYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XJGkgTRFlWvbPOn9hkUBqrXn/21qw2rzlQf9iREA0ho=; b=ObqETaMQ6AP8zqPVMxufJNTLpJQuzVQ5qacNcnZCNJr6L67GvmtuvoE4DfR6lA8TWN NTgeX6v7o+Ub/4wQdDU8koOtxy8Zahg/mLu1fBJSV2JnAPdM4FsG8V3YpE76e/X8kBdf QVXuksvf1ruwZWOLztnQ+tNDjPudfvFGCihwf0/B/rRHSyeSd3d9LMSl6lD4vUS7RjOF nbesnk/+ptxBAe6NvfB3QNC8QKD6f44miAhvz8CpOY34KJe01T5ABZRc+0FdK1+cWi3M jnJ/qWQnpNM7rQ6YSjjVTHDunrnjO4R3lYEhLHzdZTQ7S8IVVAjBia9nn2W7be5z6BJe +rLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=V6EcRFEj; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a3-20020a17090a854300b0023f9cb51eaesi11788538pjw.84.2023.04.02.19.57.13; Sun, 02 Apr 2023 19:57:25 -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=@mediatek.com header.s=dk header.b=V6EcRFEj; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230463AbjDCCxG (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Sun, 2 Apr 2023 22:53:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230413AbjDCCwx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 2 Apr 2023 22:52:53 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0C1FAD18; Sun, 2 Apr 2023 19:52:40 -0700 (PDT) X-UUID: 95f4d1e0d1ca11eda9a90f0bb45854f4-20230403 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=XJGkgTRFlWvbPOn9hkUBqrXn/21qw2rzlQf9iREA0ho=; b=V6EcRFEjapQncSMp+omsVjPUOvhZsXFPeHVryOLqwtPXw+UNLvlJTMjQWgORgUzseK9KEb38bxAxXNz08pOGssZfUBMy5sK3RPXoDNEgrvKwOC5G95vrYya5G5mf8RIDSw5iF1rU3OhUUAQab/aiUazA7LrY4rQgpfJkflGrVak=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:274f3a99-4ece-422f-bdff-89829c77d133,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:1,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:96 X-CID-INFO: VERSION:1.1.22,REQID:274f3a99-4ece-422f-bdff-89829c77d133,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:1,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:96 X-CID-META: VersionHash:120426c,CLOUDID:bb8f1db5-beed-4dfc-bd9c-e1b22fa6ccc4,B ulkID:230403105236RQ3NRNHT,BulkQuantity:0,Recheck:0,SF:38|29|28|17|19|48,T C:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-UUID: 95f4d1e0d1ca11eda9a90f0bb45854f4-20230403 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from <chunfeng.yun@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 624357530; Mon, 03 Apr 2023 10:52:34 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Mon, 3 Apr 2023 10:52:33 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Mon, 3 Apr 2023 10:52:33 +0800 From: Chunfeng Yun <chunfeng.yun@mediatek.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Rob Herring <robh+dt@kernel.org> CC: Chunfeng Yun <chunfeng.yun@mediatek.com>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Matthias Brugger <matthias.bgg@gmail.com>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, <linux-usb@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Eddie Hung <eddie.hung@mediatek.com>, Tianping Fang <tianping.fang@mediatek.com> Subject: [PATCH 3/7] usb: mtu3: fix KE at qmu transfer done irq handler Date: Mon, 3 Apr 2023 10:52:26 +0800 Message-ID: <20230403025230.25035-3-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230403025230.25035-1-chunfeng.yun@mediatek.com> References: <20230403025230.25035-1-chunfeng.yun@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, T_SPF_TEMPERROR,UNPARSEABLE_RELAY autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762122159020126561?= X-GMAIL-MSGID: =?utf-8?q?1762122159020126561?= |
Series |
[1/7] usb: mtu3: give back request when rx error happens
|
|
Commit Message
Chunfeng Yun (云春峰)
April 3, 2023, 2:52 a.m. UTC
When handle qmu transfer irq, it will unlock @mtu->lock before give back
request, if another thread hanlde disconnect event at the same time, and
try to disable ep, it may lock @mtu->lock and free qmu ring, then qmu
irq hanlder may get a NULL gpd, avoid the KE by checking gpd's value before
handling it.
e.g.
qmu done irq on cpu0 thread running on cpu1
qmu_done_tx()
handle gpd [0]
mtu3_requ_complete() mtu3_gadget_ep_disable()
unlock @mtu->lock
give back request lock @mtu->lock
mtu3_ep_disable()
mtu3_gpd_ring_free()
unlock @mtu->lock
lock @mtu->lock
get next gpd [1]
[1]: goto [0] to handle next gpd, and next gpd may be NULL.
Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
---
drivers/usb/mtu3/mtu3_qmu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
Il 03/04/23 04:52, Chunfeng Yun ha scritto: > When handle qmu transfer irq, it will unlock @mtu->lock before give back > request, if another thread hanlde disconnect event at the same time, and > try to disable ep, it may lock @mtu->lock and free qmu ring, then qmu > irq hanlder may get a NULL gpd, avoid the KE by checking gpd's value before KE == Kernel Error? I think you wanted to say KP == Kernel Panic instead. Also, s/hanlder/handler/g. > handling it. > > e.g. > qmu done irq on cpu0 thread running on cpu1 > > qmu_done_tx() > handle gpd [0] > mtu3_requ_complete() mtu3_gadget_ep_disable() > unlock @mtu->lock > give back request lock @mtu->lock > mtu3_ep_disable() > mtu3_gpd_ring_free() > unlock @mtu->lock > lock @mtu->lock > get next gpd [1] > > [1]: goto [0] to handle next gpd, and next gpd may be NULL. > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> This is a fix and needs a Fixes tag. Regards, Angelo
On Mon, 2023-04-03 at 14:31 +0200, AngeloGioacchino Del Regno wrote: > External email : Please do not click links or open attachments until > you have verified the sender or the content. > > > Il 03/04/23 04:52, Chunfeng Yun ha scritto: > > When handle qmu transfer irq, it will unlock @mtu->lock before give > > back > > request, if another thread hanlde disconnect event at the same > > time, and > > try to disable ep, it may lock @mtu->lock and free qmu ring, then > > qmu > > irq hanlder may get a NULL gpd, avoid the KE by checking gpd's > > value before > > KE == Kernel Error? I think you wanted to say KP == Kernel Panic > instead. > > Also, s/hanlder/handler/g. Ok, will modify it > > > handling it. > > > > e.g. > > qmu done irq on cpu0 thread running on cpu1 > > > > qmu_done_tx() > > handle gpd [0] > > mtu3_requ_complete() mtu3_gadget_ep_disable() > > unlock @mtu->lock > > give back request lock @mtu->lock > > mtu3_ep_disable() > > mtu3_gpd_ring_free() > > unlock @mtu->lock > > lock @mtu->lock > > get next gpd [1] > > > > [1]: goto [0] to handle next gpd, and next gpd may be NULL. > > > > > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> > > This is a fix and needs a Fixes tag. I usually add Fixes tag when the issue introduced by a patch except the original one when the driver applied. Thanks a lot > > Regards, > Angelo > >
Il 07/04/23 09:59, Chunfeng Yun (云春峰) ha scritto: > On Mon, 2023-04-03 at 14:31 +0200, AngeloGioacchino Del Regno wrote: >> External email : Please do not click links or open attachments until >> you have verified the sender or the content. >> >> >> Il 03/04/23 04:52, Chunfeng Yun ha scritto: >>> When handle qmu transfer irq, it will unlock @mtu->lock before give >>> back >>> request, if another thread hanlde disconnect event at the same >>> time, and >>> try to disable ep, it may lock @mtu->lock and free qmu ring, then >>> qmu >>> irq hanlder may get a NULL gpd, avoid the KE by checking gpd's >>> value before >> >> KE == Kernel Error? I think you wanted to say KP == Kernel Panic >> instead. >> >> Also, s/hanlder/handler/g. > Ok, will modify it >> >>> handling it. >>> >>> e.g. >>> qmu done irq on cpu0 thread running on cpu1 >>> >>> qmu_done_tx() >>> handle gpd [0] >>> mtu3_requ_complete() mtu3_gadget_ep_disable() >>> unlock @mtu->lock >>> give back request lock @mtu->lock >>> mtu3_ep_disable() >>> mtu3_gpd_ring_free() >>> unlock @mtu->lock >>> lock @mtu->lock >>> get next gpd [1] >>> >>> [1]: goto [0] to handle next gpd, and next gpd may be NULL. >> >> > >> > Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com> >> >> This is a fix and needs a Fixes tag. > I usually add Fixes tag when the issue introduced by a patch except the > original one when the driver applied. > If this patch is a fix for the "original driver", you shall still add a Fixes tag which advertises that this fixes the first commit, so the driver was broken from the very beginning. Thanks, Angelo.
diff --git a/drivers/usb/mtu3/mtu3_qmu.c b/drivers/usb/mtu3/mtu3_qmu.c index 66639f602a9d..3146a112141f 100644 --- a/drivers/usb/mtu3/mtu3_qmu.c +++ b/drivers/usb/mtu3/mtu3_qmu.c @@ -210,6 +210,7 @@ static struct qmu_gpd *advance_enq_gpd(struct mtu3_gpd_ring *ring) return ring->enqueue; } +/* @dequeue may be NULL if ring is unallocated or freed */ static struct qmu_gpd *advance_deq_gpd(struct mtu3_gpd_ring *ring) { if (ring->dequeue < ring->end) @@ -524,7 +525,7 @@ static void qmu_done_tx(struct mtu3 *mtu, u8 epnum) dev_dbg(mtu->dev, "%s EP%d, last=%p, current=%p, enq=%p\n", __func__, epnum, gpd, gpd_current, ring->enqueue); - while (gpd != gpd_current && !GET_GPD_HWO(gpd)) { + while (gpd && gpd != gpd_current && !GET_GPD_HWO(gpd)) { mreq = next_request(mep); @@ -563,7 +564,7 @@ static void qmu_done_rx(struct mtu3 *mtu, u8 epnum) dev_dbg(mtu->dev, "%s EP%d, last=%p, current=%p, enq=%p\n", __func__, epnum, gpd, gpd_current, ring->enqueue); - while (gpd != gpd_current && !GET_GPD_HWO(gpd)) { + while (gpd && gpd != gpd_current && !GET_GPD_HWO(gpd)) { mreq = next_request(mep);