Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4373447imw; Tue, 19 Jul 2022 05:34:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vgU3WmGk73lFGK//HecH0xqQGZOPbOAbBYdy3IKi9qzLwVLNPinxuxhUexL6UGcaeJ8AB7 X-Received: by 2002:a17:902:ce05:b0:16b:e725:6f6c with SMTP id k5-20020a170902ce0500b0016be7256f6cmr33332428plg.110.1658234051968; Tue, 19 Jul 2022 05:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658234051; cv=none; d=google.com; s=arc-20160816; b=FbX2Jre/1aA+Wa+0zehM4Fdr9rY9HLqnSnZk2n7Yrf8BUtaJtT6q2LGmjUXbuLzrVO eTGhrXKjpo5o8LSl343CrY4X1YQ7Qxqzi1IjtApJVIgvBDzA+01ZE0mYHG1AwujY6nNh Llc+oXBjliqcmIU46BRle214iJTVQ29FknGDcRQWyMAgdYb2JG9CGEf2Nok8ld4X+Los iSYcyyxEqaKXNjCtPwPvxB8v0/uwYg9sgiP4ATkbdlPk/5KghFb4y/Qr+s0pyeaMyvDK HtL0whGoQ1l5NK+RTL44/dm6n1bnVKs7v9F3BVhjNahWhpdBhmw8d06WTo99LnZrq31u yduA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pV+2i4CVcDswtWS9UJYbQ4uNeM3RqIET5K1yKU8k5Fk=; b=vS1tQPEnIPRuPZR4f+o1kEERcv+LsTK+G7TgV+UfJjhPuis95Z+ebchrWd5BmWSgLH 1jnFCvD5i04p1deRD16N3kZGt2ZEQY9WJ0dUmT+StQKtRlCF0e7/gNZHN8EDYUQx8RJc T+no0Cv0DUBwzb6+9YuVN5k1qn5fvvkwzyvd/YtdJGiYILsFg/xV+eeoDSkBLOkBoit5 gysExBgT9g2BjFyuRvsROcLFPOF8aWWvA3lAM4xwQ5aMcB8dGse/xR1XDFEhq6dNexZC zj7syi99G5h58bv2fmJgnBWajvlSiQ5dYo3PTfFdB7/yJgLw/iXTld37v2KlI36K5m45 p6iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ySrUqNTJ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a170902e55200b0016cf03900d9si8173963plf.622.2022.07.19.05.33.56; Tue, 19 Jul 2022 05:34:11 -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=@linuxfoundation.org header.s=korg header.b=ySrUqNTJ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239858AbiGSM1P (ORCPT + 99 others); Tue, 19 Jul 2022 08:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239713AbiGSMZZ (ORCPT ); Tue, 19 Jul 2022 08:25:25 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99AD7509E0; Tue, 19 Jul 2022 05:09:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 48D9FB81B98; Tue, 19 Jul 2022 12:09:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73CA4C36AE9; Tue, 19 Jul 2022 12:09:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232575; bh=d7oSOougbccn39NI/rBopjts/SuX7tcbX+JuMVyU66A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ySrUqNTJLxxEHiwFWTOAddEKvyGQWdK7RyLETIC6PutNcnZw7aGTyDg8zoxJpTbkx K1iQvtRekWiP33bVaYKpI4Uo1XJ7RlMlDIEYESVe+w32rzPNCk4MGtt2LBAPdjrTla 7yLeWqp8oU9PTW/JyZX88W8zpVdbI8xeRFGP00BU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen Subject: [PATCH 5.10 105/112] usb: dwc3: gadget: Fix event pending check Date: Tue, 19 Jul 2022 13:54:38 +0200 Message-Id: <20220719114637.220624404@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Thinh Nguyen commit 7441b273388b9a59d8387a03ffbbca9d5af6348c upstream. The DWC3_EVENT_PENDING flag is used to protect against invalid call to top-half interrupt handler, which can occur when there's a delay in software detection of the interrupt line deassertion. However, the clearing of this flag was done prior to unmasking the interrupt line, creating opportunity where the top-half handler can come. This breaks the serialization and creates a race between the top-half and bottom-half handler, resulting in losing synchronization between the controller and the driver when processing events. To fix this, make sure the clearing of the DWC3_EVENT_PENDING is done at the end of the bottom-half handler. Fixes: d325a1de49d6 ("usb: dwc3: gadget: Prevent losing events in event cache") Cc: stable@vger.kernel.org Signed-off-by: Thinh Nguyen Link: https://lore.kernel.org/r/8670aaf1cf52e7d1e6df2a827af2d77263b93b75.1656380429.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3781,7 +3781,6 @@ static irqreturn_t dwc3_process_event_bu } evt->count = 0; - evt->flags &= ~DWC3_EVENT_PENDING; ret = IRQ_HANDLED; /* Unmask interrupt */ @@ -3794,6 +3793,9 @@ static irqreturn_t dwc3_process_event_bu dwc3_writel(dwc->regs, DWC3_DEV_IMOD(0), dwc->imod_interval); } + /* Keep the clearing of DWC3_EVENT_PENDING at the end */ + evt->flags &= ~DWC3_EVENT_PENDING; + return ret; }