From patchwork Sat Oct 22 07:21:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093536wrr; Sat, 22 Oct 2022 00:57:38 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tazmBosrDZL84avNdCMYtTcQoE564tUihkdNBMQxhuYBrs64n4Tq6Iqg6olumtLxNPlqh X-Received: by 2002:a17:902:7d87:b0:17f:9cd0:2e03 with SMTP id a7-20020a1709027d8700b0017f9cd02e03mr23161669plm.164.1666425457779; Sat, 22 Oct 2022 00:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425457; cv=none; d=google.com; s=arc-20160816; b=ivHDavPfIcU7p3POtCYqbv+a+JCvIQ0+BSgxCp4EjjZ2TNQVZNb4YWM8UMvwf3vxBt VMHv6ckpPzz85v/oe2v7Fwt6s3zP8z+x8cBlXQMcY2pfu+lBgtrr108Q3JFuAPR6plvO DQHj+hRADenH3PXQnWuAQ82pQVSexBgNBkZjqFiMo3vo+l7ICpqn2R4/iIa/Akd4vyEo xFZcityz3dSsttxxm6FTvcTUoG4kUe5QFeSZMJ4yCgDCPt5UcnjQAKuYvLYzbQwST4PP JEF3beuwIHO1F4LCtfGz/NA4BkWAWjClORkpG26oPWu25IMIblJWSwqsljWu8X7NxiXY Wp7A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 64-20020a630243000000b0046ed54becf6si2330943pgc.678.2022.10.22.00.57.25; Sat, 22 Oct 2022 00:57:37 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747373740893918218?= X-GMAIL-MSGID: =?utf-8?q?1747373740893918218?= 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 */