Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4481594imw; Tue, 19 Jul 2022 07:25:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uYS9QeNq6j9u1vHbgjAgSvVs+EGBjDzdw3q31vT6/Tx5yUhHHE5zqE/tTv/1c8H+Z7FaZG X-Received: by 2002:a17:906:4482:b0:70a:19e3:d18a with SMTP id y2-20020a170906448200b0070a19e3d18amr30976892ejo.510.1658240724475; Tue, 19 Jul 2022 07:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658240724; cv=none; d=google.com; s=arc-20160816; b=Yt1hW1gJc6IxJF/Q1+U6zYf5nnQnuIMTYPITivtBPONpgN0Qnc7pIYGmk3xPTE4PYm 7RErT2DEZ5iTPlA4LNDDfBTOzndeqZZFRS8We/wwP4rGLx9AcN3Y0/VC8zvcK2pRlhPT WffehgSGZ5n9iwoRQu0EJpTYn9BJThptl7X/p0triS0rOOjb3UsNp6riP8MqJ7+GEoJ0 J6vex8sjWQwFzPK1qoffCP8EZQPTz+zYWsCvd/frC9Yw82abrf6w22STafH2bErQwgBH E2PygFwR3TJaUDkuZQHZES9qXyBeKSPe/n6qGaabsgn1HzZxCLaEdeTAyrnqwGc6sMk2 KPVQ== 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=6PpyDwJi0ZmIlnJ732HudB5QzTywSGP7zIhOO6Nq1Kc=; b=RXgLEbVHnJEGvLjMRTodahc7IWUA4Rs9VjN3aGCFGp0bwFxXKMAgGGHLfA83caAI/R 7fglxMQFC42+qmwlxtckhQ/jAxFFHqHcz6lCdSeyngPhtm6nUpwSR2AHv2ARHooSULcq cehHtqOoZVtsvCzCH1+gRpTYS7KFS/y19SBmT4cSieeQMXhDDsFKxZfZswtNvBWpJbHf C47B2ETXHWCApJ6FA0vyf0OYqoop8Eo2Js7OmSlNWBB3dqdwpc/qFHFKQnRjrdlhirA0 U4+4i2/tZKmEtKGqfB8u0nE3+RTr8xBzr5PTw48msyD7VSvMh1OlU5H023FeENQPIswU mKgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=F5KyIUYs; 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 r23-20020a170906549700b0072b3a923e6csi16617234ejo.974.2022.07.19.07.24.59; Tue, 19 Jul 2022 07:25:24 -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=F5KyIUYs; 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 S241581AbiGSMr0 (ORCPT + 99 others); Tue, 19 Jul 2022 08:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241567AbiGSMp0 (ORCPT ); Tue, 19 Jul 2022 08:45:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 437C389E8D; Tue, 19 Jul 2022 05:18:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1DBB661826; Tue, 19 Jul 2022 12:17:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5959C341D0; Tue, 19 Jul 2022 12:17:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233062; bh=2gp7DdC32qpng2GORGOCcMiwSXXYzxqNPUfp1HwzPBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F5KyIUYsQGrFf5xGMpMvzeixgDmBdIhvSCuflI8bZFd0yPrNd4xj/bQK2DAhpWVK0 l/Hdp2Y1w8kujBeT0XqvK9A9vidfkEbv15QNHrS5ZcVOlF054/38pFwjmaczcNcU6c yYcNQcazLLtl2angb62mMdtvGsq2FHCzGd7HA9EM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen Subject: [PATCH 5.15 160/167] usb: dwc3: gadget: Fix event pending check Date: Tue, 19 Jul 2022 13:54:52 +0200 Message-Id: <20220719114711.966066385@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114656.750574879@linuxfoundation.org> References: <20220719114656.750574879@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 @@ -4149,7 +4149,6 @@ static irqreturn_t dwc3_process_event_bu } evt->count = 0; - evt->flags &= ~DWC3_EVENT_PENDING; ret = IRQ_HANDLED; /* Unmask interrupt */ @@ -4162,6 +4161,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; }