From patchwork Wed Oct 19 08:26:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp215921wrs; Wed, 19 Oct 2022 02:17:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7uwxbFEgDdcGb5+VuWgmSH8pmK4WwgJBvnDjHOLaWvuNcFXcjBbqjJmQb+ry3tOIA8bv9j X-Received: by 2002:a05:6402:3512:b0:45d:4f99:6151 with SMTP id b18-20020a056402351200b0045d4f996151mr6361225edd.74.1666171022439; Wed, 19 Oct 2022 02:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666171022; cv=none; d=google.com; s=arc-20160816; b=SLD9dCzN+5faQnR+lLeSU8lJoX6KPsTX98+f+R2YgTL/SJ/RzVolIFXhzYf1GvUET6 zZLIASb5EK2QCHMzkJ0PiJdE/oegQWOUtjerjh3h2hTxyPgkMbDv9QyQo/YbX9LNsCmD /j4BuQOGuTAQ3N0Fs94gy0p13k6qOmqixX8v0Df9P8Fj3zJ+OZ6SSUQ2dV/K/90Xzfp7 chndRfSFiO9JhesApxx7dhRMhOOG0TpQhH3lqXicnwyttDqK5gXm6PMCHl36t18njcEh N+0KQKt1412ZlJiF4YE86UorXxLbiTZsPjBHJgl8gE/N6gTprxurZ/0CffrR5Mjb4FJg H8IQ== 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=mSMtweZNEf8HqZV3PlHLoWqEumGOtI3+vXVTAGqxsDo=; b=KJlKiIhWNVjOCS4BPb8/pYLjRU1QCIM3etPNM8Tpdr7ZnrJWhIwMaPCoItHK+O8HPD zQBq9sxbqQhkFIdEGdaQbtpyZnb8OS2OIH9ubtvIhXqoHktFFwm5EGaO/3BTPvlbuOIS 4Fj8fzmTbpMh/aw0T+YKDd+olYXHr6AQwk0CP9XB2lYU6RFqXoitnnZ9GUOHA+sUsDQR os6DLDlD2lvyrom4AWC0qVgmSM0KhWWqD/q8Y9VXH4XBRCXFqNSHQF6+387/02pojZWU 7gPEuiE9HD5r9bGuXS4mPCaFFwlTY19rOQD+eeNdmiDYXVl8N/wAZa+CT6ohIQIDbM+1 9LNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jgaYDsgT; 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 dd17-20020a1709069b9100b0077cfec3a52fsi15073204ejc.839.2022.10.19.02.16.38; Wed, 19 Oct 2022 02:17:02 -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=jgaYDsgT; 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 S233069AbiJSJQB (ORCPT + 99 others); Wed, 19 Oct 2022 05:16:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbiJSJNC (ORCPT ); Wed, 19 Oct 2022 05:13:02 -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 F06B6BCBA2; Wed, 19 Oct 2022 02:03:14 -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 AE05361879; Wed, 19 Oct 2022 08:52:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1741C433D6; Wed, 19 Oct 2022 08:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169522; bh=h2b9klU9HPAy6q0Q6MKdBI8G1gu0t6l4l0Iv3oCvsdw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgaYDsgTIJL70M5YOyOzIIlVx991R3OGuH6XdlEgFrG77Q7T34/FSAT0b+f0avdAw CQ0i/t+2YGYPjuq8hedTpG2pcTA2OMDAP5eI4ckqMN6DNSC6vm/y+1FlptERVDYJD2 xQhLi2FS46MQeUTzuplL5b7HBVWm2s5KdILqcrLc= 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 275/862] wifi: mt76: mt7921e: fix race issue between reset and suspend/resume Date: Wed, 19 Oct 2022 10:26:02 +0200 Message-Id: <20221019083302.177387254@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?1747106946067018376?= X-GMAIL-MSGID: =?utf-8?q?1747106946067018376?= From: Sean Wang [ Upstream commit ff6c4a6449793e9718ef2e9ad46864b63022648e ] 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: 0c1ce9884607 ("mt76: mt7921: add wifi 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/mac.c | 5 +++++ drivers/net/wireless/mediatek/mt76/mt7921/pci.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index 47f0aa81ab02..6bd9fc9228a2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -780,6 +780,7 @@ void mt7921_mac_reset_work(struct work_struct *work) void mt7921_reset(struct mt76_dev *mdev) { struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76); + struct mt76_connac_pm *pm = &dev->pm; if (!dev->hw_init_done) return; @@ -787,8 +788,12 @@ void mt7921_reset(struct mt76_dev *mdev) if (dev->hw_full_reset) return; + if (pm->suspended) + return; + queue_work(dev->mt76.wq, &dev->reset_work); } +EXPORT_SYMBOL_GPL(mt7921_reset); void mt7921_mac_update_mib_stats(struct mt7921_phy *phy) { diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c index ea3069d18c35..2b015dacbba2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/pci.c @@ -367,6 +367,7 @@ static int mt7921_pci_suspend(struct device *device) int i, err; pm->suspended = true; + flush_work(&dev->reset_work); cancel_delayed_work_sync(&pm->ps_work); cancel_work_sync(&pm->wake_work); @@ -428,6 +429,9 @@ static int mt7921_pci_suspend(struct device *device) restore_suspend: pm->suspended = false; + if (err < 0) + mt7921_reset(&dev->mt76); + return err; } @@ -441,7 +445,7 @@ static int mt7921_pci_resume(struct device *device) err = mt7921_mcu_drv_pmctrl(dev); if (err < 0) - return err; + goto failed; mt7921_wpdma_reinit_cond(dev); @@ -471,11 +475,12 @@ static int mt7921_pci_resume(struct device *device) mt76_connac_mcu_set_deep_sleep(&dev->mt76, 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; }