From patchwork Wed Oct 19 08:26:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 5550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp349351wrs; Wed, 19 Oct 2022 07:11:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ejhQQcrTCqPhUe6hnzSmfOe2wTXtaZbtPHYy3Gd5LeZ4cxpkJLNHD1QEXdPGyirPQVUmi X-Received: by 2002:a17:907:7fa4:b0:791:9307:9d6a with SMTP id qk36-20020a1709077fa400b0079193079d6amr6934588ejc.464.1666188709154; Wed, 19 Oct 2022 07:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666188709; cv=none; d=google.com; s=arc-20160816; b=BkY4VbRV9yJL8X5BHOU05W/nIMeQ+asxDUwrApAGc3VciPgJnsDaWeANvqsOK5DHoj qWop0qByQTRnJpLAZPiniUsjIoJnn9aqvo28BLfudkkfexMea9KNk5K+CmDkEZkBoZo4 y7Lafhlzwxv0C+xsvZPGP0oH6eE2ZmBJvOLcUSSJLBbuCRFdS5DrlXpMx9QWAKx22MBR zZJLC8ziq4NzFbdMfPlHFzp3ujeC1W6c3XZUl2i6UyJSTqYGz7a3h1ij3+oNkvh+6toj 4J4DMJ8WrAUv3JD9HUKQ8BCDRBcVsYKM+OCpFiD04FBOaG4tLnfDj7qvhp8r4x3tzM3M 0E7A== 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=qkpqt7ljuSe0j8/kwV5lFpkG3cVgSfObRlkGBfw0zOw=; b=GtqiUbHKTPiA3HudkvMlRsPJBGbIV4lh6xC+SwVN9AXuZ3CG81fua3rS1TDyHtxOj1 W9SMrBmD36SFJQ5ElYz9lJ0Ucjw5W/I9Sz2bF0lGAd5nRgUbntVfUc7jy6YbYGNyrFua AzuzFmBQNPR5aP1mN5Qx/Y5WoCDerOPqpAMguXT4gTg7QHl5gYLuxmpcAFuIyQT3NxhD 0qLaLf2PM7/Oa0hK6pnfOuNoDF1siCJbWTj7T+sB7gGoefFQ9tzVldjQQuZ7cdQGTcx6 p/dlfoU6OQY/vBINKYNqCIj5LiXp7y8NcSJxD9ZxfQLWJi60kH7FshHwIbTNaKV0LXGx gi5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xYSjYRYb; 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 e9-20020a056402190900b0045d9ceae633si9045855edz.55.2022.10.19.07.11.01; Wed, 19 Oct 2022 07:11: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=xYSjYRYb; 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 S230261AbiJSN4c (ORCPT + 99 others); Wed, 19 Oct 2022 09:56:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233824AbiJSNyI (ORCPT ); Wed, 19 Oct 2022 09:54:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F6D1DC822; Wed, 19 Oct 2022 06:36:56 -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 ams.source.kernel.org (Postfix) with ESMTPS id 2DC95B82388; Wed, 19 Oct 2022 08:50:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 810DBC433D6; Wed, 19 Oct 2022 08:50:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169434; bh=+Gu7QzlWRpwbVMYhNonG5PitRlXoTuYCdza+QJFhkd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xYSjYRYbOXpjr/m6gPmYL/GRNQ647U2sx8quYnxeiYRGCtTwR48GsSpDOU7koccM6 JakXJ1vOsC/srAGoX6m+NTRE/3StYQHisOJRE+LEKT0IacsQQz8UpmUm4xGCuJfeTz 2mp/b6lWiCQfcitah2UFpq691LhhsZUAxtOOF0tc= 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 6.0 276/862] wifi: mt76: mt7921s: fix race issue between reset and suspend/resume Date: Wed, 19 Oct 2022 10:26:03 +0200 Message-Id: <20221019083302.219343270@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747125492006390244?= X-GMAIL-MSGID: =?utf-8?q?1747125492006390244?= 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 487acd6e2be8..2face849fb4f 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; }