2022-07-24 09:06:50

by Sean Wang

[permalink] [raw]
Subject: [PATCH 1/2] mt76: mt7921: add mt7921_mutex_acquire at mt7921_[start, stop]_ap

From: Sean Wang <[email protected]>

Add mt7921_mutex_acquire at mt7921_[start, stop]_ap to fix the race
with the context holding dev->muxtex and the driver might access the
device in low power state.

Fixes: 9d958b60ebc2 ("mt76: mt7921: fix command timeout in AP stop period")
Signed-off-by: Sean Wang <[email protected]>
---
.../net/wireless/mediatek/mt76/mt7921/main.c | 21 ++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
index 1438a9f8d1fd..7a4a3ed1817e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
@@ -1526,17 +1526,23 @@ mt7921_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct mt7921_dev *dev = mt7921_hw_dev(hw);
int err;

+ mt7921_mutex_acquire(dev);
+
err = mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid,
true);
if (err)
- return err;
+ goto failed;

err = mt7921_mcu_set_bss_pm(dev, vif, true);
if (err)
- return err;
+ goto failed;
+
+ err = mt7921_mcu_sta_update(dev, NULL, vif, true,
+ MT76_STA_INFO_STATE_NONE);
+failed:
+ mt7921_mutex_release(dev);

- return mt7921_mcu_sta_update(dev, NULL, vif, true,
- MT76_STA_INFO_STATE_NONE);
+ return err;
}

static void
@@ -1548,11 +1554,16 @@ mt7921_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
struct mt7921_dev *dev = mt7921_hw_dev(hw);
int err;

+ mt7921_mutex_acquire(dev);
+
err = mt7921_mcu_set_bss_pm(dev, vif, false);
if (err)
- return;
+ goto failed;

mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid, false);
+
+failed:
+ mt7921_mutex_release(dev);
}

const struct ieee80211_ops mt7921_ops = {
--
2.25.1


2022-07-25 08:03:47

by Lorenzo Bianconi

[permalink] [raw]
Subject: Re: [PATCH 1/2] mt76: mt7921: add mt7921_mutex_acquire at mt7921_[start, stop]_ap

> From: Sean Wang <[email protected]>
>
> Add mt7921_mutex_acquire at mt7921_[start, stop]_ap to fix the race
> with the context holding dev->muxtex and the driver might access the
> device in low power state.
>
> Fixes: 9d958b60ebc2 ("mt76: mt7921: fix command timeout in AP stop period")
> Signed-off-by: Sean Wang <[email protected]>
> ---
> .../net/wireless/mediatek/mt76/mt7921/main.c | 21 ++++++++++++++-----
> 1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/main.c b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> index 1438a9f8d1fd..7a4a3ed1817e 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt7921/main.c
> @@ -1526,17 +1526,23 @@ mt7921_start_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> struct mt7921_dev *dev = mt7921_hw_dev(hw);
> int err;
>
> + mt7921_mutex_acquire(dev);
> +
> err = mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid,
> true);
> if (err)
> - return err;
> + goto failed;
>
> err = mt7921_mcu_set_bss_pm(dev, vif, true);
> if (err)
> - return err;
> + goto failed;
> +
> + err = mt7921_mcu_sta_update(dev, NULL, vif, true,
> + MT76_STA_INFO_STATE_NONE);

nit: maybe better "out" instead of "failed"

> +failed:
> + mt7921_mutex_release(dev);
>
> - return mt7921_mcu_sta_update(dev, NULL, vif, true,
> - MT76_STA_INFO_STATE_NONE);
> + return err;
> }
>
> static void
> @@ -1548,11 +1554,16 @@ mt7921_stop_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> struct mt7921_dev *dev = mt7921_hw_dev(hw);
> int err;
>
> + mt7921_mutex_acquire(dev);
> +
> err = mt7921_mcu_set_bss_pm(dev, vif, false);
> if (err)
> - return;
> + goto failed;
>
> mt76_connac_mcu_uni_add_bss(phy->mt76, vif, &mvif->sta.wcid, false);
> +
> +failed:

same here

> + mt7921_mutex_release(dev);
> }
>
> const struct ieee80211_ops mt7921_ops = {
> --
> 2.25.1
>


Attachments:
(No filename) (2.02 kB)
signature.asc (235.00 B)
Download all attachments
Subject: Re: [PATCH 1/2] mt76: mt7921: add mt7921_mutex_acquire at mt7921_[start, stop]_ap

Il 24/07/22 10:58, [email protected] ha scritto:
> From: Sean Wang <[email protected]>
>
> Add mt7921_mutex_acquire at mt7921_[start, stop]_ap to fix the race
> with the context holding dev->muxtex and the driver might access the
> device in low power state.
>
> Fixes: 9d958b60ebc2 ("mt76: mt7921: fix command timeout in AP stop period")
> Signed-off-by: Sean Wang <[email protected]>

Tested-by: AngeloGioacchino Del Regno <[email protected]>

(P.S.: I agree with Lorenzo's nits.)