Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4370899imw; Tue, 19 Jul 2022 05:31:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u5gOishXAneyQRIDkPG0HlWZovSi+HxY2BPvBFEkmxyRcNMMK9wA0MVRgFPBSfJaMvfq7E X-Received: by 2002:a05:6402:4016:b0:43a:f310:9522 with SMTP id d22-20020a056402401600b0043af3109522mr42982053eda.200.1658233891740; Tue, 19 Jul 2022 05:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233891; cv=none; d=google.com; s=arc-20160816; b=tvkwoEtbrJY4OrCWfrbrlcoOqjZCkFb71Owr7uSZINj4Ov8AoeeWPoWKPsLahkFdUD PWjQNUmSYfyruln6EPIqR2xNTt+PZ6h1nFErsQPlaC/ef160Epx3bEHJJMPIZCM9QQPZ Nscpf0Ff6GNyFN/dLBL+sJA3OqzIjJgazvQbvPUoSIe14hmLYuBOE8ZEWJBtPrOu6jUQ mdfjuslXB8oKRbZKeVtU7VK1FkTnhsPT92sr0CQ1I6BBMyaZ6IwqH+WiAD55iqcePzNh dcmkvF8gEGt4GjLCpy4dsA3Da8F9tcKXikJR1RTOtWPXdCH1R2sXKdXg+jEmITUFHNzd iH4g== 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=HXG3pQiPVL9LgeP7cUoJ0puHT9ZpEkxHCi8a6rXv39E=; b=V0I0DNusIGXUoz+uwQZcqs2BkC+v2p/uDE8SiqiKgczxIgvZEnTJ5/lR49vU16NAtg toHn0VUBGkcBHUxl9PkNMo9oDEFzIzIW5jyP3jqyj2GrQhU5Uz0vzPHJZiVVisluOEnl RrfOCO/6yolPLeeUuIPH1ijiolcT787z3hCWLt06vjOOwmyCIvwMgBm7NKvK6tvET8U8 nCNS0GQAhKkspBTb3DLXXdwePoWzTrGSZnok62XHm7ROkG/2GOn1D6zbVAReK5BqqWD+ 1PwtZX2xp9M45eChBn330owCIwdRI03k+sRprIUmfBAF5xrwCaUOXXGSCAAT/0Lhu0VQ d3nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HwFG1XZ8; 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 v20-20020aa7d9d4000000b0043a96b5da4esi15522705eds.90.2022.07.19.05.31.06; Tue, 19 Jul 2022 05:31:31 -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=HwFG1XZ8; 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 S238102AbiGSMGp (ORCPT + 99 others); Tue, 19 Jul 2022 08:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238538AbiGSMEr (ORCPT ); Tue, 19 Jul 2022 08:04:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E96948EB8; Tue, 19 Jul 2022 05:00:48 -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 AB2946163C; Tue, 19 Jul 2022 12:00:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90341C341C6; Tue, 19 Jul 2022 12:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232046; bh=UC9oYzbLVB9auI6uoTPgZgVi9M4Vt7Mw8732lQCv/sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HwFG1XZ8EkkAvD0QG5gEqL0Spaf7z9BZp1sOErz9/C6Cfppi1iLl2IWKk62R/Vzaf YAHSc4VYF9/TlVtDqhaENh/Q6iW1gJ4ofmHHUiV1wx2ROjG9A65VnxPQnqqD5KrlJn 9S4YtkZKOriOni6DsWK7ZxJDH0wOwJukmEAarUtw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen Subject: [PATCH 4.19 43/48] usb: dwc3: gadget: Fix event pending check Date: Tue, 19 Jul 2022 13:54:20 +0200 Message-Id: <20220719114523.658787215@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114518.915546280@linuxfoundation.org> References: <20220719114518.915546280@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 @@ -3187,7 +3187,6 @@ static irqreturn_t dwc3_process_event_bu } evt->count = 0; - evt->flags &= ~DWC3_EVENT_PENDING; ret = IRQ_HANDLED; /* Unmask interrupt */ @@ -3200,6 +3199,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; }