Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp3927061rwi; Sat, 22 Oct 2022 02:21:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7h8KtIvCM1HBhSzcHB9mw6FhuFJMUCBFMG2U71dN20PdIIKyvcYEJ1AF50gJ69IZq0qFSI X-Received: by 2002:a63:4f19:0:b0:43b:ddc9:387c with SMTP id d25-20020a634f19000000b0043bddc9387cmr19332343pgb.333.1666430479728; Sat, 22 Oct 2022 02:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666430479; cv=none; d=google.com; s=arc-20160816; b=rkDfOJTxONri05eiEjUoOnnr+7VKKvjf6Ucg2BVnghjmin83+Wgam/lNLya+wJ59Vx NN2gMCUj52leVxXnNzw7cPvCW5X4V7VTzYQMs2+oB7ZG1qxc/ShxOOoN4ZcqqoP3WJoF +9rdIgw/7lhCmIoqh96c5kuw6m/d61DjotsRfty3Bcr6L0KUoh83ir5UDflwVdczwdlI M9Lk2Y7vVLdVxayw+eZ0QkcEyvVjauR++Um0PnwNqpI5Osb09K7Ea13o4iJxsegqgIlD gmxJ06zNjd1vmOoYyRwUntoe9Wo7ORt8v3zjekS50d1qsYswxmNCuRiUhe6G3T72N0TS 5z8g== 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=ZElE0e6Xzws/B2ARTYCQX2o/rPJrO+egUleYANk82Cc=; b=H0+Cp8mp3eANM57IBr/tGcicVTje5EtAEs4ehHuup+9/8eNCZVztKoqRt/EC1kuuUp 5uZFGDKHYyLBUQTRgvyNTOitkWh+22f4tV1mwhsczZfxbGuD2kenmmDVWKd6pUrYsYlD y/tgeYwJwrSySKo6knHV55dlAcyB+X7123uBZgWeSIbUePsy7Jn96zPm/XMp0c4LBb3q vacUBqUKpvetyyBi+8lUzcK1XYZttjCkoecHk8dOUIFDrU1wjaRvEkYs84wcOy6C/Hl/ lxhvM194XA03GXITpEEG3W+Ws+n9Nn4yo6TuTocYujn/5M3CMi7PD43o1StgqxLzB+pO jseA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N79iC+Jc; 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 c13-20020a63d14d000000b00439e032756fsi25022639pgj.65.2022.10.22.02.21.08; Sat, 22 Oct 2022 02:21:19 -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=N79iC+Jc; 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 S231958AbiJVH5L (ORCPT + 99 others); Sat, 22 Oct 2022 03:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231962AbiJVHxL (ORCPT ); Sat, 22 Oct 2022 03:53:11 -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 323A92CA7D0; Sat, 22 Oct 2022 00:46:54 -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 D6DDA60BB8; Sat, 22 Oct 2022 07:44:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8E9AC433C1; Sat, 22 Oct 2022 07:44:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424687; bh=7ZzkCr20JnkiwmkmTiSJfuITjuLNjcYgYZSQfOnkhSM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N79iC+JcO5weRvZgVn0krGCT9RebZqcYSzXC+7EDBbPBfjVApnhVDxel+lTAtZuZn XtRyhcBgB0m5bd39zEa7cukjRzHT0KZt8STTfqFc0cf2dKi+BOZ1lgLRxCTuoUIsr+ eFQEH6sNgcDXNdL9VYaT+wxcBVdyXQcuKB6WUl/g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, YN Chen , Sean Wang , Felix Fietkau , Sasha Levin Subject: [PATCH 5.19 239/717] wifi: mt76: mt7921u: fix race issue between reset and suspend/resume Date: Sat, 22 Oct 2022 09:21:58 +0200 Message-Id: <20221022072457.262097154@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.3 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: Sean Wang [ Upstream commit 86f15d043ba7f13211d5c3e41961c3381fb12880 ] It is unexpected that the reset work is running simultaneously with the suspend or resume context and it is possible that reset work is still running even after mt7921 is suspended if we don't fix the race issue. Thus, the suspend procedure should be waiting until the reset is completed at the beginning and ignore the subsequent the reset requests. In case there is an error that happens during either suspend or resume handler, we will schedule a reset task to recover the error before returning the error code to ensure we can immediately fix the error there. Fixes: df3e4143ba8a ("mt76: mt7921u: add suspend/resume support") Co-developed-by: YN Chen Signed-off-by: YN Chen Signed-off-by: Sean Wang Signed-off-by: Felix Fietkau Signed-off-by: Sasha Levin --- .../net/wireless/mediatek/mt76/mt7921/usb.c | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/usb.c b/drivers/net/wireless/mediatek/mt76/mt7921/usb.c index dc38baef273a..25b4a8001b9e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/usb.c @@ -292,11 +292,15 @@ static void mt7921u_disconnect(struct usb_interface *usb_intf) static int mt7921u_suspend(struct usb_interface *intf, pm_message_t state) { struct mt7921_dev *dev = usb_get_intfdata(intf); + struct mt76_connac_pm *pm = &dev->pm; int err; + pm->suspended = true; + flush_work(&dev->reset_work); + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, true); if (err) - return err; + goto failed; mt76u_stop_rx(&dev->mt76); mt76u_stop_tx(&dev->mt76); @@ -304,11 +308,20 @@ static int mt7921u_suspend(struct usb_interface *intf, pm_message_t state) set_bit(MT76_STATE_SUSPEND, &dev->mphy.state); return 0; + +failed: + pm->suspended = false; + + if (err < 0) + mt7921_reset(&dev->mt76); + + return err; } static int mt7921u_resume(struct usb_interface *intf) { struct mt7921_dev *dev = usb_get_intfdata(intf); + struct mt76_connac_pm *pm = &dev->pm; bool reinit = true; int err, i; @@ -330,16 +343,23 @@ static int mt7921u_resume(struct usb_interface *intf) if (reinit || mt7921_dma_need_reinit(dev)) { err = mt7921u_dma_init(dev, true); if (err) - return err; + goto failed; } clear_bit(MT76_STATE_SUSPEND, &dev->mphy.state); err = mt76u_resume_rx(&dev->mt76); if (err < 0) - return err; + goto failed; + + err = mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); +failed: + pm->suspended = false; + + if (err < 0) + mt7921_reset(&dev->mt76); - return mt76_connac_mcu_set_hif_suspend(&dev->mt76, false); + return err; } #endif /* CONFIG_PM */ -- 2.35.1