Re: [PATCH v2 05/10] rtw88: iterate over vif/sta list non-atomically

From: Ping-Ke Shih
Date: Wed Jun 08 2022 - 22:55:53 EST


On Mon, 2022-05-30 at 15:54 +0200, Sascha Hauer wrote:
> The driver uses ieee80211_iterate_active_interfaces_atomic()
> and ieee80211_iterate_stations_atomic() in several places and does
> register accesses in the iterators. This doesn't cope with upcoming
> USB support as registers can only be accessed non-atomically.
>
> Split these into a two stage process: First use the atomic iterator
> functions to collect all active interfaces or stations on a list, then
> iterate over the list non-atomically and call the iterator on each
> entry.
>
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> Suggested-by: Pkshih <pkshih@xxxxxxxxxxx>
> ---
>
> Notes:
> Changes since v1:
> - Change subject
> - Add some lockdep_assert_held(&rtwdev->mutex);
> - make locally used functions static
> - Add comment how &rtwdev->mutex protects us from stations/interfaces
> being deleted between collecting them and iterating over them.
>
> drivers/net/wireless/realtek/rtw88/phy.c | 6 +-
> drivers/net/wireless/realtek/rtw88/ps.c | 2 +-
> drivers/net/wireless/realtek/rtw88/util.c | 103 ++++++++++++++++++++++
> drivers/net/wireless/realtek/rtw88/util.h | 12 ++-
> 4 files changed, 116 insertions(+), 7 deletions(-)
>
>

[...]

> +
> +struct rtw_vifs_entry {
> + struct list_head list;
> + struct ieee80211_vif *vif;
> + u8 mac[ETH_ALEN];
> +};
> +
> +struct rtw_iter_vifs_data {
> + struct rtw_dev *rtwdev;
> + struct list_head list;
> +};
> +
> +void rtw_collect_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)

You do this change in patch "rtw88: Add common USB chip support".
Please move to here.

-void rtw_collect_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
+static void rtw_collect_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)

> +{
> + struct rtw_iter_vifs_data *iter_stas = data;
> + struct rtw_vifs_entry *vifs_entry;
> +
> + vifs_entry = kmalloc(sizeof(*vifs_entry), GFP_ATOMIC);
> + if (!vifs_entry)
> + return;
> +
> + vifs_entry->vif = vif;
> + ether_addr_copy(vifs_entry->mac, mac);
> + list_add_tail(&vifs_entry->list, &iter_stas->list);
> +}
> +
> +void rtw_iterate_vifs(struct rtw_dev *rtwdev,
> + void (*iterator)(void *data, u8 *mac,
> + struct ieee80211_vif *vif),
> + void *data)
> +{
> + struct rtw_iter_vifs_data iter_data;
> + struct rtw_vifs_ent

[...]

> diff --git a/drivers/net/wireless/realtek/rtw88/util.h b/drivers/net/wireless/realtek/rtw88/util.h
> index 0c23b5069be0b..dc89655254002 100644
> --- a/drivers/net/wireless/realtek/rtw88/util.h
> +++ b/drivers/net/wireless/realtek/rtw88/util.h
> @@ -7,9 +7,6 @@
>
> struct rtw_dev;
>
> -#define rtw_iterate_vifs(rtwdev, iterator, data) \
> - ieee80211_iterate_active_interfaces(rtwdev->hw, \
> - IEEE80211_IFACE_ITER_NORMAL, iterator, data)
> #define rtw_iterate_vifs_atomic(rtwdev, iterator, data) \
> ieee80211_iterate_active_interfaces_atomic(rtwdev->hw, \
> IEEE80211_IFACE_ITER_NORMAL, iterator, data)

After read Martin's patches, I think we can review all places where use
_aotmic version of vif and sta, even we don't really meet problem for now.
Then, use non-atomic version if possible.

Ping-Ke