From patchwork Thu Dec 30 20:47:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 529091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D731C433EF for ; Thu, 30 Dec 2021 20:47:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242125AbhL3UrX (ORCPT ); Thu, 30 Dec 2021 15:47:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242120AbhL3UrX (ORCPT ); Thu, 30 Dec 2021 15:47:23 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C96B6C061574 for ; Thu, 30 Dec 2021 12:47:22 -0800 (PST) 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 92AC4B81D0C for ; Thu, 30 Dec 2021 20:47:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18820C36AEB; Thu, 30 Dec 2021 20:47:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640897240; bh=KSnKXK1DNQwCsaL3ThC9UdTMyty2vZpwfSQGblqSP1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V1Ak+0jQE/TsazMfR+lggQH5CkcsxfedXfOc5a1fuAdWE8/REW7tpRGS4k82uhDC3 2ZcL+9zmL+S/LrrRKCQRg4AyqJG66k8mMl55Z9D9UZMfANH7KV+T82iJaXebG43Oea 2xGyGyXg1yeEmelgwbmGz4uvAPm7Zs5iKK6ZBTWPNPayAtapCH3KWD2byfkIR8sL53 eN1d1AW5ox8rGM6ScW+Y06UoA2CZ1u05E7+Ues79hx/H4gAUAXz6xPtM2vo+zPaupv UHvNf/G+cz1WEC9c6Ub26gLIKjrOqYjiuxrgnBN9ECPHJSel9XZ9ly9u/O62BU2HdF MGMgPdNkMIG6A== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, sean.wang@mediatek.com, deren.wu@mediatek.com Subject: [PATCH 1/2] mt76: mt7921: fix a leftover race in runtime-pm Date: Thu, 30 Dec 2021 21:47:05 +0100 Message-Id: <65e65daddbcec420392befa3b4f9a6aaaea21315.1640897147.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fix a possible race in mt7921_pm_power_save_work() if rx/tx napi schedules ps_work and we are currently accessing device register on a different cpu. Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c index defef3496246..0744f6e42ba3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mac.c @@ -1553,6 +1553,14 @@ void mt7921_pm_power_save_work(struct work_struct *work) dev->fw_assert) goto out; + if (mutex_is_locked(&dev->mt76.mutex)) + /* if mt76 mutex is held we should not put the device + * to sleep since we are currently accessing device + * register map. We need to wait for the next power_save + * trigger. + */ + goto out; + if (time_is_after_jiffies(dev->pm.last_activity + delta)) { delta = dev->pm.last_activity + delta - jiffies; goto out; From patchwork Thu Dec 30 20:47:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 529477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08200C433FE for ; Thu, 30 Dec 2021 20:47:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242129AbhL3UrY (ORCPT ); Thu, 30 Dec 2021 15:47:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242120AbhL3UrY (ORCPT ); Thu, 30 Dec 2021 15:47:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1980C061574 for ; Thu, 30 Dec 2021 12:47:23 -0800 (PST) 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 97B076175E for ; Thu, 30 Dec 2021 20:47:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4F0AC36AE7; Thu, 30 Dec 2021 20:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1640897242; bh=yNUPp+rot4IrD4b61dLI7v633eGWz1ZDmrYfpqFKotw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KRVB+c9+H/LCbrLGtzvK92AxEy1un9pxynWuF0/12BqiPRBoTapfRRQ38PcCcRyvl bVriRfZwvM4x9SYnQhodmDY5Kg134hiKleFd0piAB9EzHfuGWHacqw0tw743aYT9MZ qrHAZsc04mkUZ5vUE0zJANTJLm7aLHt4WOuxls0ESDar1ZwQQaCVCTMsAXaQitw1Y4 mf+8UaXzw5it+JJsdw/mOTA2niaydVVOVt9ZbiDbbDPS+2zqRof56DJHXs/XeZsp+D 1uWvOGU2DqoY0nYet49VbgzHbq82R+T1gwPN+S1QLFyIgp38zC6mTuZgMBb/sa6nMp Yr1Qf0e04BQlQ== From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, sean.wang@mediatek.com, deren.wu@mediatek.com Subject: [PATCH 2/2] mt76: mt7615: fix a leftover race in runtime-pm Date: Thu, 30 Dec 2021 21:47:06 +0100 Message-Id: <3fd85e4025afdb6d37059071bcc18575ce3ef575.1640897147.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Fix a possible race in mt7615_pm_power_save_work() if rx/tx napi schedules ps_work and we are currently accessing device register on a different cpu. Fixes: db928f1ab9789 ("mt76: mt7663: rely on mt76_connac_pm_ref/mt76_connac_pm_unref in tx/rx napi") Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt7615/mac.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c index 2d81cbf2600c..bc72791cdcb5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/mac.c @@ -2131,6 +2131,14 @@ void mt7615_pm_power_save_work(struct work_struct *work) test_bit(MT76_HW_SCHED_SCANNING, &dev->mphy.state)) goto out; + if (mutex_is_locked(&dev->mt76.mutex)) + /* if mt76 mutex is held we should not put the device + * to sleep since we are currently accessing device + * register map. We need to wait for the next power_save + * trigger. + */ + goto out; + if (time_is_after_jiffies(dev->pm.last_activity + delta)) { delta = dev->pm.last_activity + delta - jiffies; goto out;