All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm
@ 2021-12-21 13:57 Lorenzo Bianconi
  2021-12-21 15:07 ` Kalle Valo
  2021-12-22 17:54 ` Kalle Valo
  0 siblings, 2 replies; 4+ messages in thread
From: Lorenzo Bianconi @ 2021-12-21 13:57 UTC (permalink / raw)
  To: kvalo; +Cc: nbd, lorenzo.bianconi, linux-wireless, deren.wu, sean.wang, sven

Fix a possible race enabling/disabling runtime-pm between
mt7921_pm_set() and mt7921_poll_rx() since mt7921_pm_wake_work()
always schedules rx-napi callback and it will trigger
mt7921_pm_power_save_work routine putting chip to in low-power state
during mt7921_pm_set processing.

Suggested-by: Deren Wu <deren.wu@mediatek.com>
Tested-by: Deren Wu <deren.wu@mediatek.com>
Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c |  3 ---
 drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c  | 12 +++++++++---
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
index af43bcb54578..306e9eaea917 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mac.c
@@ -7,9 +7,6 @@ int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm)
 {
 	struct mt76_dev *dev = phy->dev;
 
-	if (!pm->enable)
-		return 0;
-
 	if (mt76_is_usb(dev))
 		return 0;
 
diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c
index 7cdfdf83529f..86fd7292b229 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/debugfs.c
@@ -276,7 +276,7 @@ mt7921_pm_set(void *data, u64 val)
 	struct mt7921_dev *dev = data;
 	struct mt76_connac_pm *pm = &dev->pm;
 
-	mt7921_mutex_acquire(dev);
+	mutex_lock(&dev->mt76.mutex);
 
 	if (val == pm->enable)
 		goto out;
@@ -285,7 +285,11 @@ mt7921_pm_set(void *data, u64 val)
 		pm->stats.last_wake_event = jiffies;
 		pm->stats.last_doze_event = jiffies;
 	}
-	pm->enable = val;
+	/* make sure the chip is awake here and ps_work is scheduled
+	 * just at end of the this routine.
+	 */
+	pm->enable = false;
+	mt76_connac_pm_wake(&dev->mphy, pm);
 
 	ieee80211_iterate_active_interfaces(mt76_hw(dev),
 					    IEEE80211_IFACE_ITER_RESUME_ALL,
@@ -293,8 +297,10 @@ mt7921_pm_set(void *data, u64 val)
 
 	mt76_connac_mcu_set_deep_sleep(&dev->mt76, pm->ds_enable);
 
+	pm->enable = val;
+	mt76_connac_power_save_sched(&dev->mphy, pm);
 out:
-	mt7921_mutex_release(dev);
+	mutex_unlock(&dev->mt76.mutex);
 
 	return 0;
 }
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm
  2021-12-21 13:57 [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm Lorenzo Bianconi
@ 2021-12-21 15:07 ` Kalle Valo
  2021-12-21 15:10   ` Lorenzo Bianconi
  2021-12-22 17:54 ` Kalle Valo
  1 sibling, 1 reply; 4+ messages in thread
From: Kalle Valo @ 2021-12-21 15:07 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: nbd, lorenzo.bianconi, linux-wireless, deren.wu, sean.wang, sven

Lorenzo Bianconi <lorenzo@kernel.org> writes:

> Fix a possible race enabling/disabling runtime-pm between
> mt7921_pm_set() and mt7921_poll_rx() since mt7921_pm_wake_work()
> always schedules rx-napi callback and it will trigger
> mt7921_pm_power_save_work routine putting chip to in low-power state
> during mt7921_pm_set processing.
>
> Suggested-by: Deren Wu <deren.wu@mediatek.com>
> Tested-by: Deren Wu <deren.wu@mediatek.com>
> Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

We are in -rc6 already, so I would prefer to take this to
wireless-drivers-next instead. Is that ok?

Felix, ack?

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm
  2021-12-21 15:07 ` Kalle Valo
@ 2021-12-21 15:10   ` Lorenzo Bianconi
  0 siblings, 0 replies; 4+ messages in thread
From: Lorenzo Bianconi @ 2021-12-21 15:10 UTC (permalink / raw)
  To: Kalle Valo
  Cc: nbd, lorenzo.bianconi, linux-wireless, deren.wu, sean.wang, sven

[-- Attachment #1: Type: text/plain, Size: 979 bytes --]

> Lorenzo Bianconi <lorenzo@kernel.org> writes:
> 
> > Fix a possible race enabling/disabling runtime-pm between
> > mt7921_pm_set() and mt7921_poll_rx() since mt7921_pm_wake_work()
> > always schedules rx-napi callback and it will trigger
> > mt7921_pm_power_save_work routine putting chip to in low-power state
> > during mt7921_pm_set processing.
> >
> > Suggested-by: Deren Wu <deren.wu@mediatek.com>
> > Tested-by: Deren Wu <deren.wu@mediatek.com>
> > Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> We are in -rc6 already, so I would prefer to take this to
> wireless-drivers-next instead. Is that ok?

I think wireless-drivers-next is fine since the bug is not so critical.

Regards,
Lorenzo

> 
> Felix, ack?
> 
> -- 
> https://patchwork.kernel.org/project/linux-wireless/list/
> 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm
  2021-12-21 13:57 [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm Lorenzo Bianconi
  2021-12-21 15:07 ` Kalle Valo
@ 2021-12-22 17:54 ` Kalle Valo
  1 sibling, 0 replies; 4+ messages in thread
From: Kalle Valo @ 2021-12-22 17:54 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: nbd, lorenzo.bianconi, linux-wireless, deren.wu, sean.wang, sven

Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Fix a possible race enabling/disabling runtime-pm between
> mt7921_pm_set() and mt7921_poll_rx() since mt7921_pm_wake_work()
> always schedules rx-napi callback and it will trigger
> mt7921_pm_power_save_work routine putting chip to in low-power state
> during mt7921_pm_set processing.
> 
> Suggested-by: Deren Wu <deren.wu@mediatek.com>
> Tested-by: Deren Wu <deren.wu@mediatek.com>
> Fixes: 1d8efc741df8 ("mt76: mt7921: introduce Runtime PM support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Patch applied to wireless-drivers-next.git, thanks.

d430dffbe9dd mt76: mt7921: fix a possible race enabling/disabling runtime-pm

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/0f3e075a2033dc05f09dab4059e5be8cbdccc239.1640094847.git.lorenzo@kernel.org/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-22 17:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-21 13:57 [PATCH wireless-drivers] mt76: mt7921: fix a possible race enabling/disabling runtime-pm Lorenzo Bianconi
2021-12-21 15:07 ` Kalle Valo
2021-12-21 15:10   ` Lorenzo Bianconi
2021-12-22 17:54 ` Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.