From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81A7C54720 for ; Wed, 14 Aug 2024 05:24:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723613073; cv=none; b=D7qRYentGC9kZQLoGS/UfdUOsP7UVCL72A78Vu0HSWL6BOtOp5FZNY93nNKE0bZ7txd6z0O3PXKhHG6InVwYIc73jBQUKthcCDC89mPeP+cWUUDr1fpd4iq2IH9NyP4LSv+TcGHVKW85pOYk23wd4wdJiN+wrS0I7uWQ8kTKq4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723613073; c=relaxed/simple; bh=0Jg37okIgoHvF/we1XydAONF+6YuWA/o+HS/lIy1XCE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:From:In-Reply-To: Content-Type:References; b=OiTUJG4hQqT+EDjU5niP5ZdW8FWrhRCt4Ta77iM7GnzhMQQRJVgsAeBHU8fuxBo3gRkNUOUFThDHdjmXZE3GAqnO6itWEsrO6AIzRNL5EfgnwFJU7PxYlpjmS8/jpNU+dfjHIQ3ObwcqUocRVfIiIXBA5JRhB5lOG3Y3tCHlri4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=tlrPlieY; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="tlrPlieY" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20240814052427epoutp03e8e5ede78ae3a638f992161dc8ada5a3~rgPPmQzYd1050210502epoutp03J for ; Wed, 14 Aug 2024 05:24:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20240814052427epoutp03e8e5ede78ae3a638f992161dc8ada5a3~rgPPmQzYd1050210502epoutp03J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1723613067; bh=tgim6fGfnoteNGPRHZsa18v9V1WUkoyXRCy+g53ak1M=; h=Date:Subject:To:Cc:From:In-Reply-To:References:From; b=tlrPlieYbmE9ez89DP17eRbm4CMGiw2ja8obGfP+e/FgjfjC4uvTeN9SCxEqREdAQ ClJ2ZdAr7qwV0eao4VlwX2uu1Yw2CTew9dnXavmHp2PAJ23zozIRGH3rYUptm+NSLA 3+9xGPh/mzDEdW52rIS+2Q8CWgp7cApNmrr+Nagw= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas5p1.samsung.com (KnoxPortal) with ESMTP id 20240814052426epcas5p15d1ab7ff38b6dca0daf8100be24744f0~rgPPJ_yG72642726427epcas5p1E; Wed, 14 Aug 2024 05:24:26 +0000 (GMT) Received: from epsmgec5p1new.samsung.com (unknown [182.195.38.176]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4WkGs45TQyz4x9Pp; Wed, 14 Aug 2024 05:24:24 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmgec5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id E5.7D.08855.88F3CB66; Wed, 14 Aug 2024 14:24:24 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20240814045941epcas5p4df2673c284c3b3fc372ef3d75ee769e1~rf5nSrCt01110511105epcas5p4Y; Wed, 14 Aug 2024 04:59:41 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20240814045941epsmtrp23715f522932946fe0a5cbe25ef8ae322~rf5nRqCXw2056320563epsmtrp2i; Wed, 14 Aug 2024 04:59:41 +0000 (GMT) X-AuditID: b6c32a44-15fb870000002297-c9-66bc3f886966 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id DF.37.19367.CB93CB66; Wed, 14 Aug 2024 13:59:40 +0900 (KST) Received: from [107.122.5.126] (unknown [107.122.5.126]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20240814045938epsmtip1c0d55b73d28bb612aa43db441ec3b0b2~rf5lKyV790771507715epsmtip1l; Wed, 14 Aug 2024 04:59:38 +0000 (GMT) Message-ID: <45a638d0-57e0-405f-bbb0-8159d73cc8b6@samsung.com> Date: Wed, 14 Aug 2024 10:29:37 +0530 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] usb: dwc3: core: Prevent USB core invalid event buffer address access To: Thinh Nguyen Cc: "gregkh@linuxfoundation.org" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "jh0801.jung@samsung.com" , "dh10.jung@samsung.com" , "naushad@samsung.com" , "akash.m5@samsung.com" , "rc93.raju@samsung.com" , "taehyun.cho@samsung.com" , "hongpooh.kim@samsung.com" , "eomji.oh@samsung.com" , "shijie.cai@samsung.com" , "stable@vger.kernel.org" Content-Language: en-US From: Selvarasu Ganesan In-Reply-To: <20240813231744.p4hd4kbhlotjzgmz@synopsys.com> Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCJsWRmVeSWpSXmKPExsWy7b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H8bcafp1cvPeur89sizlFWZDhn x4y1ryZel6x6kupkWPTo3JwNXG8WekqoalZ+VF+U6XWdu/XFskA+MTWt34JJbBYOVVfCr+un rnD9YtirJc9fd8TIOcAwbLWrtmaD6W7vmWzGZ5Tsc7Y2eCuxFGckGmoxFxUnAgCSboROIwMA AA== X-CMS-MailID: 20240814045941epcas5p4df2673c284c3b3fc372ef3d75ee769e1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20240808120605epcas5p2c9164533413706da5f7fa2ed624318cd References: <20240808120507.1464-1-selvarasu.g@samsung.com> <20240809232804.or5kccyf7yebbqm6@synopsys.com> <98e0cf35-f729-43e2-97f2-06120052a1cc@samsung.com> <20240813231744.p4hd4kbhlotjzgmz@synopsys.com> On 8/14/2024 4:47 AM, Thinh Nguyen wrote: > On Sat, Aug 10, 2024, Selvarasu Ganesan wrote: >> On 8/10/2024 4:58 AM, Thinh Nguyen wrote: >>> On Thu, Aug 08, 2024, Selvarasu Ganesan wrote: >>>> This commit addresses an issue where the USB core could access an >>>> invalid event buffer address during runtime suspend, potentially causing >>>> SMMU faults and other memory issues. The problem arises from the >>>> following sequence. >>>> 1. In dwc3_gadget_suspend, there is a chance of a timeout when >>>> moving the USB core to the halt state after clearing the >>>> run/stop bit by software. >>>> 2. In dwc3_core_exit, the event buffer is cleared regardless of >>>> the USB core's status, which may lead to an SMMU faults and >>> This is a workaround to your specific setup behavior. Please document in >>> the commit message which platforms are impacted. >> Please correct me if i am wrong. I dont think this workaround only >> applicable our specific setup. It could be a common issue across all >> other vendor platforms, and it's required to must check the controller >> status before clear the event buffers address.  What you think is it >> really required to mention the platform details in commit message? > How can it be a common issue, the suspend sequence hasn't completed in > the dwc3 driver but yet the buffer is no longer accessible? Also, as you > noted, we don't know the exact condition for the SMMU fault, and this > isn't reproducible all the time. Agree. Will update platform detail in next version. > >>>> other memory issues. if the USB core tries to access the event >>>> buffer address. >>>> >>>> To prevent this issue, this commit ensures that the event buffer address >>>> is not cleared by software when the USB core is active during runtime >>>> suspend by checking its status before clearing the buffer address. >>>> >>>> Cc: stable@vger.kernel.org >>> We can keep the stable tag, but there's no issue with the commit below. >> >> By mistaken I mentioned wrong commit ID. The correct commit id would be >> 660e9bde74d69 ("usb: dwc3: remove num_event_buffers"). > The above commit isn't the issue either. If it is, then the problem > should still exist prior to that. This issue still persists in older kernels (6.1.X) as well. We believed that it could be a common issue due to the missing condition for checking the controller status in the mentioned commit above. We require this fix in all stable kernel for the Exynos platform. Is it fine to only mention the "Cc" tag in this case? > >>>> Fixes: 89d7f9629946 ("usb: dwc3: core: Skip setting event buffers for host only controllers") >>>> Signed-off-by: Selvarasu Ganesan >>>> --- >>>> >>>> Changes in v2: >>>> - Added separate check for USB controller status before cleaning the >>>> event buffer. >>>> - Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/lkml/20240722145617.537-1-selvarasu.g@samsung.com/__;!!A4F2R9G_pg!cvZmnaxTWtJKR4ZDRZDa-8mvxpvkf5KPx57IwSXTSEtEFIVkPullR7sTYP0AM9de0xFbHLKdM_5jzBUiBL3f9SuioYE$ >>>> --- >>>> drivers/usb/dwc3/core.c | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c >>>> index 734de2a8bd21..5b67d9bca71b 100644 >>>> --- a/drivers/usb/dwc3/core.c >>>> +++ b/drivers/usb/dwc3/core.c >>>> @@ -564,10 +564,15 @@ int dwc3_event_buffers_setup(struct dwc3 *dwc) >>>> void dwc3_event_buffers_cleanup(struct dwc3 *dwc) >>>> { >>>> struct dwc3_event_buffer *evt; >>>> + u32 reg; >>>> >>>> if (!dwc->ev_buf) >>>> return; >>>> >>> Please add comment here why we need this and which platform is impacted >>> should we need to go back and test. >> Do you want add comment as like below?. If yes, As i said earlier not >> required to mention our platform name as it could be a common issue >> across all the other vendor platforms. > See note above. Noted. > >> /*Prevent USB controller invalid event buffer address access >> in Exynos platform if USB controller still in active.*/ > Perhaps this: > > /* > * Exynos platforms may not be able to access event buffer if the > * controller failed to halt on dwc3_core_exit(). Thanks for the suggestions. Will update platform detail in next version. > */ > > BR, > Thinh > >>>> + reg = dwc3_readl(dwc->regs, DWC3_DSTS); >>>> + if (!(reg & DWC3_DSTS_DEVCTRLHLT)) >>>> + return; >>>> + >>>> evt = dwc->ev_buf; >>>> >>>> evt->lpos = 0; >>>> -- >>>> 2.17.1 >>>> >>> Thanks, >>> Thinh