From patchwork Mon Mar 7 05:24:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?7KCV7J6s7ZuI?= X-Patchwork-Id: 550076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADD80C433EF for ; Mon, 7 Mar 2022 05:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234237AbiCGF1K (ORCPT ); Mon, 7 Mar 2022 00:27:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229827AbiCGF1J (ORCPT ); Mon, 7 Mar 2022 00:27:09 -0500 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C60F31AD94 for ; Sun, 6 Mar 2022 21:26:15 -0800 (PST) Received: from epcas2p2.samsung.com (unknown [182.195.41.54]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20220307052610epoutp04754123124ba9d899200783334c0837d6~aAfYLl9P30984009840epoutp04Z for ; Mon, 7 Mar 2022 05:26:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20220307052610epoutp04754123124ba9d899200783334c0837d6~aAfYLl9P30984009840epoutp04Z DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1646630770; bh=9tjq2zNlTSzLqr3qckKG9tmOLZlxb8W7Esn7UKQRyV0=; h=From:To:Cc:Subject:Date:References:From; b=lWlax/Hau5sbfWnYBPT1sgA9Hu/pcFW47J5vmrN7hoJPuGR4Phwk2GYNGztu5E2zB TGGj9ShVnOD6kXdWuA9jkibZwuSBCDM+B0YuH9yJbl1ndCb7eznb3INl5Ku499Gjv0 c9BpuldZY+lZdQakrso7a7/58x31ThpcFINfAYxk= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas2p2.samsung.com (KnoxPortal) with ESMTP id 20220307052609epcas2p25bc106c55f44992c76ba6489993e4e2e~aAfXiihYj1775517755epcas2p2R; Mon, 7 Mar 2022 05:26:09 +0000 (GMT) Received: from epsmges2p1.samsung.com (unknown [182.195.36.88]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4KBn4H2vwrz4x9QP; Mon, 7 Mar 2022 05:26:07 +0000 (GMT) Received: from epcas2p3.samsung.com ( [182.195.41.55]) by epsmges2p1.samsung.com (Symantec Messaging Gateway) with SMTP id 50.4C.51767.D6795226; Mon, 7 Mar 2022 14:26:05 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20220307052605epcas2p2b84f6db2642863ed61373070f508e200~aAfTw8EZd2036320363epcas2p2K; Mon, 7 Mar 2022 05:26:05 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20220307052605epsmtrp175691b06cd1275ed69afb439f3a7f8c2~aAfTwJ1Ui1024710247epsmtrp1d; Mon, 7 Mar 2022 05:26:05 +0000 (GMT) X-AuditID: b6c32a45-447ff7000000ca37-d5-6225976d1f84 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 87.5C.29871.D6795226; Mon, 7 Mar 2022 14:26:05 +0900 (KST) Received: from ubuntu.dsn.sec.samsung.com (unknown [12.36.155.120]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220307052605epsmtip11291b6c3684732bf2275c54f6d7f48e0~aAfTlCOcX0030500305epsmtip1_; Mon, 7 Mar 2022 05:26:05 +0000 (GMT) From: JaeHun Jung To: Felipe Balbi , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org (open list:USB XHCI DRIVER), linux-kernel@vger.kernel.org (open list), Seungchull Suh , Daehwan Jung , JaeHun Jung Subject: [PATCH] usb: dwc3: Add dwc3 lock for blocking interrupt storming Date: Mon, 7 Mar 2022 14:24:39 +0900 Message-Id: <1646630679-121585-1-git-send-email-jh0801.jung@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrJKsWRmVeSWpSXmKPExsWy7bCmuW7udNUkg5m3dCyOtT1ht7izYBqT RfPi9WwWdx/+YLG4vGsOm8WiZa3MFl13bzA6sHtsWtXJ5rF/7hp2j74tqxg9Pm+SC2CJyrbJ SE1MSS1SSM1Lzk/JzEu3VfIOjneONzUzMNQ1tLQwV1LIS8xNtVVy8QnQdcvMAbpASaEsMacU KBSQWFyspG9nU5RfWpKqkJFfXGKrlFqQklNgXqBXnJhbXJqXrpeXWmJlaGBgZApUmJCdsfXF W7aC78IV+7dPYG1gvCLQxcjBISFgIvH7LGsXIxeHkMAORom+r4/ZIZxPjBKrtt5hgXC+MUrc vNzM3MXICdbRvHYzE0RiL6PEw8WroKp+MEpsWHWPCaSKTUBbYt+cRewgtohAmMTEZfvAipgF bjNKrJh3gREkISzgKbG2YSoriM0ioCrx9tkksGZeAQ+JXwteskCsk5O4ea4TavUqdom3V5Ig bBeJV9/vsELYwhKvjm9hh7ClJF72t0HZxRKdmw4xgiyWEGhglPh2oIMJImEsMetZOyMoBJgF NCXW79KHBIayxJFbYGuZBfgkOg7/ZYcI80p0tAlBNKpKHGy8CXWZtMS33neMECUeEtuOcYOE hQRiJW5tbmOewCg7C2H8AkbGVYxiqQXFuempxUYFhvA4Ss7P3cQITlNarjsYJ7/9oHeIkYmD 8RCjBAezkgjv/fMqSUK8KYmVValF+fFFpTmpxYcYTYGhNZFZSjQ5H5go80riDU0sDUzMzAzN jUwNzJXEeb1SNiQKCaQnlqRmp6YWpBbB9D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qWEV99X1ZfNu2sv9PPIg65tBehiDJsOmiruXl2VnLTNa/Dw8eUG3wr3N t456zVHw3n9G931t8tFD+jGmBnfkOJSv1D/pSDjXFWV5hWPN9ZeN117NSFK5c3ySQrsFS9yp 5L4zu9fypElkpn9RemEnIfTUVdBsrUnprs+GxdIX5e7Jziq99e7oUV6tbaVKLMUZiYZazEXF iQDjvkCnjgIAAA== X-CMS-MailID: 20220307052605epcas2p2b84f6db2642863ed61373070f508e200 X-Msg-Generator: CA X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20220307052605epcas2p2b84f6db2642863ed61373070f508e200 References: Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Interrupt Storming occurred with a very low probability of occurrence. The occurrence of the problem is estimated to be caused by a race condition between the top half and bottom half of the interrupt service routine. It was confirmed that variables have values that cannot be held when ISR occurs through normal H / W irq. ===================================================================== (struct dwc3_event_buffer *) ev_buf = 0xFFFFFF88DE6A0380 ( (void *) buf = 0xFFFFFFC01594E000, (void *) cache = 0xFFFFFF88DDC14080, (unsigned int) length = 4096, (unsigned int) lpos = 0, (unsigned int) count = 0, << (unsigned int) flags = 1, << ===================================================================== "evt->count=0" and "evt->flags=DWC3_EVENT_PENDING" cannot be set at the same time. We estimate that a race condition occurred between dwc3_interrupt() and dwc3_process_event_buf() called by dwc3_gadget_process_pending_events(). So I try to block the race condition through spin_lock. Signed-off-by: JaeHun Jung --- drivers/usb/dwc3/gadget.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index a0c883f19a41..88f9ecf8cbfe 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -4172,6 +4172,7 @@ static irqreturn_t dwc3_thread_interrupt(int irq, void *_evt) static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt) { struct dwc3 *dwc = evt->dwc; + unsigned long flags; u32 amount; u32 count; @@ -4188,13 +4189,18 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt) * irq event handler completes before caching new event to prevent * losing events. */ - if (evt->flags & DWC3_EVENT_PENDING) + spin_lock_irqsave(&dwc->lock, flags); + if (evt->flags & DWC3_EVENT_PENDING) { + spin_unlock_irqrestore(&dwc->lock, flags); return IRQ_HANDLED; + } count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0)); count &= DWC3_GEVNTCOUNT_MASK; - if (!count) + if (!count) { + spin_unlock_irqrestore(&dwc->lock, flags); return IRQ_NONE; + } evt->count = count; evt->flags |= DWC3_EVENT_PENDING; @@ -4210,6 +4216,7 @@ static irqreturn_t dwc3_check_event_buf(struct dwc3_event_buffer *evt) memcpy(evt->cache, evt->buf, count - amount); dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count); + spin_unlock_irqrestore(&dwc->lock, flags); return IRQ_WAKE_THREAD; }