From patchwork Sat Oct 22 07:21:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1093252wrr; Sat, 22 Oct 2022 00:56:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5e7btP1aRySQcgqQg6AhWRc+YRlG/QDiAFkXjv5QbianCbphw3BF3nWhqud1P5MuTmLZNT X-Received: by 2002:a63:4752:0:b0:439:5dcc:fd78 with SMTP id w18-20020a634752000000b004395dccfd78mr19037055pgk.104.1666425395240; Sat, 22 Oct 2022 00:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425395; cv=none; d=google.com; s=arc-20160816; b=pD/w4+k1BUZayD7FpX0QL8gBtH1++hgL4T8B+EznDAdAMoK6k2pBXWId4U2HJh9IwK Z6k5M82E++0dUd2QecHgKXSR24nv/E4ZxYzqPVCP1N0b7oEHEqyuk6jrsEtoYxoDWGNE 0h0gbCY16a44VSFOdZmgMIQQG1cLRGsn0oWorvjypuSmh6RtBa9iUa0TPc76FavW1MOR KX8cuVfHWRSIsfY5XXJzqMoO3SoB+Sfvbnz3JOX8n5+dtlwFVvkLZ85F6PWIKyqabEve lTV2JOpStJtPyIS7ckEO0PSlNbDnA/8KbByYdQHfvK+jzFKsgsOhmw+l++45uAjnNkGM 4CHA== 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=5FdZHR8LyzLPdsluQybj3l862H6OItUQ2avF4COcTMA=; b=VSWRf09ivpd+VbBkeF7CFPW8jHXvwvzz03arIuhnYgys9ebNCHEMjQ/QcfFXUxgYyc qDjKLBrCKKtoLT65lMHi22AszNFaqN/TnCeSCvOYa3v4JiXj/GWPxx1BcwTynN75ytgM FfPZYpvQTM5d2P1ofj/l2CwwcHzcBwIlICfHquAM7OLLsTHVnOClMjZ9aXDH7u6f0m5k MRzuGXi2vOOErkdsGkg2c0IoGQU3AKh59FQtKOW4fxBFuv7CCH3b7jPSy/6jsSp+s6sn bdKiRLp4aQWN77XuCkA5C1NJ02eBLcQP4qoi6dgJyMyBbvglZkHKBTuKpOtrbcuaNE8L 5smg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HuGUvbrq; 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 b16-20020a170902d51000b001869394a38dsi121321plg.503.2022.10.22.00.56.22; Sat, 22 Oct 2022 00:56:35 -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=HuGUvbrq; 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 S232217AbiJVH4G (ORCPT + 99 others); Sat, 22 Oct 2022 03:56:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231789AbiJVHwi (ORCPT ); Sat, 22 Oct 2022 03:52:38 -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 6E1AB2CA7C7; Sat, 22 Oct 2022 00:46:52 -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 3935160B00; Sat, 22 Oct 2022 07:44:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 261BAC433C1; Sat, 22 Oct 2022 07:44:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424684; bh=mm2zaj2XYewV94kiPFrJN30t0TgqhWK83H/2Drtdujc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HuGUvbrqvK6tY9wnrXvv37N8Oa53eRoXMtYCDcNlpeid1/wVRQTR96kkP7vXNcogG DI1YVUQ3Q/U2vI+8WbJ3CohpO0IgswGngEUkGc5PFKdR4cU8/Mamg6NT035Kdei2n9 pwjTANdqH0xhN8OeiHnXP58lOMPio0fmz9QyJGj4= 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 238/717] wifi: mt76: mt7921s: fix race issue between reset and suspend/resume Date: Sat, 22 Oct 2022 09:21:57 +0200 Message-Id: <20221022072457.102513648@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?1747373675623430377?= X-GMAIL-MSGID: =?utf-8?q?1747373675623430377?= From: Sean Wang [ Upstream commit e86f10e6809add9132ecc2c6b3184ed59db7ca71 ] 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: ca74b9b907f9 ("mt76: mt7921s: add reset 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 --- drivers/net/wireless/mediatek/mt76/mt7921/sdio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c index af26d59fa2f0..5610c63fe1e6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/sdio.c @@ -206,6 +206,7 @@ static int mt7921s_suspend(struct device *__dev) pm->suspended = true; set_bit(MT76_STATE_SUSPEND, &mdev->phy.state); + flush_work(&dev->reset_work); cancel_delayed_work_sync(&pm->ps_work); cancel_work_sync(&pm->wake_work); @@ -261,6 +262,9 @@ static int mt7921s_suspend(struct device *__dev) clear_bit(MT76_STATE_SUSPEND, &mdev->phy.state); pm->suspended = false; + if (err < 0) + mt7921_reset(&dev->mt76); + return err; } @@ -276,7 +280,7 @@ static int mt7921s_resume(struct device *__dev) err = mt7921_mcu_drv_pmctrl(dev); if (err < 0) - return err; + goto failed; mt76_worker_enable(&mdev->tx_worker); mt76_worker_enable(&mdev->sdio.txrx_worker); @@ -288,11 +292,12 @@ static int mt7921s_resume(struct device *__dev) mt76_connac_mcu_set_deep_sleep(mdev, false); err = mt76_connac_mcu_set_hif_suspend(mdev, false); - if (err) - return err; - +failed: pm->suspended = false; + if (err < 0) + mt7921_reset(&dev->mt76); + return err; }