Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451161imw; Tue, 19 Jul 2022 06:54:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uh5wetSomrMmJy/ytbabqs/GFFkBC3OIkl/nvP8WzB3eqsEZpc/Y1Ysew0Di4TDDEy7a/8 X-Received: by 2002:a17:907:2723:b0:72b:5af3:5a11 with SMTP id d3-20020a170907272300b0072b5af35a11mr30065956ejl.584.1658238889058; Tue, 19 Jul 2022 06:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238889; cv=none; d=google.com; s=arc-20160816; b=FfYuhLhEX9RgssRE8PYxfrJpEpliptpXKrzOHekZqDfso21zN/5MiSImOIgylca1fy b0kgV0NO1/xqr1jwiCeScLS80YccT1WIAzAJ/vOgO9drFbll281dOQns4XMjsgYOGhOQ EAtzqECNIK5jKgPh1swHnwDJzr/eED/3q7JYzsCVN7G+Ea9CkehkUpZMxf1oL7QAEcri cOb7/DxyMjjBsO8pmjimTvQ+0YU4vKBvC4Wx4IciTq0zGDE7+YLjK8Iqh6jPq9wDWxY5 g9jZ+rYNXpj6gU+7NwCkg30Q3CH6ITz9cSuS8wEI7bue9kjRnXloX/YzTaeGpCkl/HXW lOsw== 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=ZG0Gk31jxUeWisXG1++hcBnTweZjtSMma9X/iadk/u0=; b=xPjW8gIr5Pjn//8MQLtX4XGk8HmWoqVKzs4FoEY3R51XP+QneAji+L5nmAiCPcdqmX nRuswANoji2nHKnQdpTz42wXv6AKVEm20LDkHODH2iEWE+bIxespyXjPPlpffh94DCmf n0fHn4351L7D0J5lb1st7Bu86XCPOxbMVCDF8SzhakbJnxDf9aSNyP0bOzd23mpJSlgc RsyuYPBMLLNZI+wIyFUQZlNpCIOresPkpNJhCahshNBgkmstm6WF6whX9Trl4TsIRTQa IZ8o+GUAXMwi776ILG2heiJDunpj8WHiBWW7yZOhCF+EE0ER0PeA8Ko8K54JIQOUYdfL jRgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fzen81Eu; 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 m10-20020aa7c2ca000000b0043abd4a6f50si12311475edp.134.2022.07.19.06.54.24; Tue, 19 Jul 2022 06:54:49 -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=fzen81Eu; 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 S238904AbiGSMuv (ORCPT + 99 others); Tue, 19 Jul 2022 08:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241832AbiGSMtO (ORCPT ); Tue, 19 Jul 2022 08:49:14 -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 A83368E4E2; Tue, 19 Jul 2022 05:19:24 -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 2F1F761828; Tue, 19 Jul 2022 12:19:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1C5AC341C6; Tue, 19 Jul 2022 12:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658233162; bh=OhqI3tmN1jI+O03uvUGXiDsTMffZQnJe7ltreY4ykBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzen81EuWztvNBwKmn72cGSf6qEbuJbLUIyqlhMm/bXzfias71llWjsMK6TmIbGr+ X2CaXyKNcbIIs95YDNJ8suFVdK6OIS3VQs8KUFzJpyYzhlr9H4B6DhCrFC/IDOtUvY xLl9gpk1byHGulj6hwOmmQD3THHJDsSBMpkpbemY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thinh Nguyen Subject: [PATCH 5.18 003/231] usb: dwc3: gadget: Fix event pending check Date: Tue, 19 Jul 2022 13:51:28 +0200 Message-Id: <20220719114714.494293609@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114714.247441733@linuxfoundation.org> References: <20220719114714.247441733@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 @@ -4224,7 +4224,6 @@ static irqreturn_t dwc3_process_event_bu } evt->count = 0; - evt->flags &= ~DWC3_EVENT_PENDING; ret = IRQ_HANDLED; /* Unmask interrupt */ @@ -4236,6 +4235,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; }