wifi: ath12k: switch to using wiphy_lock()
v2 cover wifi: ath12k: switch to using wiphy_lock()
From: Kalle Valo <[email protected]>
Convert all uses of struct ath12k::conf_mutex to use struct wiphy::mtx, which is already used by mac80211, and remove conf_mutex from ath12k. This way we have one mutex less in ath12k and simpler locking design.
I'm submitting this as RFC as I have only tested these patches and need to investigate how this affects MLO implementation.
v2:
* rebase to ath-202409051620
* patch 1: ath12k_wow_op_suspend(): remove extra wiphy_lock()/unlock() (Baochen)
* patch 1: fix clang warnings about unused labels (Johannes)
* patch 2: s/no/now/ (Jeff)
* patch 4: ath12k_sta_rc_update_wk(): fix wiphy_priv() usage
v1: https://patchwork.kernel.org/project/linux-wireless/cover/[email protected]/
Kalle Valo (4):
wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
wifi: ath12k: cleanup unneeded labels
wifi: ath12k: ath12k_mac_op_set_key(): remove exit label
wifi: ath12k: convert struct ath12k_sta::update_wk to use struct
wiphy_work
drivers/net/wireless/ath/ath12k/core.c | 6 +- drivers/net/wireless/ath/ath12k/core.h | 7 +- drivers/net/wireless/ath/ath12k/debugfs.c | 4 +- .../wireless/ath/ath12k/debugfs_htt_stats.c | 26 +- drivers/net/wireless/ath/ath12k/mac.c | 363 +++++++----------- drivers/net/wireless/ath/ath12k/peer.c | 6 +- drivers/net/wireless/ath/ath12k/wow.c | 26 +- 7 files changed, 183 insertions(+), 255 deletions(-)
base-commit: 903aaf66edc97dd5b9e3118d19677291051a9c40
Signature · 1 line
2.39.5
RFC PATCH v2 1/4 wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
From: Kalle Valo <[email protected]>
Switch from using driver specific ar->conf_mutex to wiphy->mtx. The benefits are:
* one lock less and simplified locking
* possibility to use wiphy_work_queue() without other locks
Most of the mac80211 ops are called within wiphy_lock(), most notable exception being tx op. This can be checked with lockdep_assert_wiphy() from net/mac80211/driver-ops.[ch] and I veried that by manually going through all the ops in ath12k_ops which had lockdep_assert_wiphy().
The conversion was simple:
* All conf_mutex lock() and unlock() calls which already were called under wiphy_lock() I replaced with lockdep_assert_wiphy().
* The rest of conf_mutex calls I replaced with wiphy_lock() and wiphy_unlock().
* All lockdep_asset_held(conf_mutex) calls I replaced with lockdep_assert_wiphy().
There is now a new sparse warning, but to keep this long patch simple the labels will be cleaned up in following patches:
drivers/net/wireless/ath/ath12k/mac.c:6635:1: warning: statement expected after label
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/core.c | 6 +- drivers/net/wireless/ath/ath12k/core.h | 5 +- drivers/net/wireless/ath/ath12k/debugfs.c | 4 +- .../wireless/ath/ath12k/debugfs_htt_stats.c | 26 +- drivers/net/wireless/ath/ath12k/mac.c | 273 +++++++----------- drivers/net/wireless/ath/ath12k/peer.c | 6 +- drivers/net/wireless/ath/ath12k/wow.c | 26 +- 7 files changed, 143 insertions(+), 203 deletions(-)
drivers/net/wireless/ath/ath12k/core.c +3 -3
@@ -1004,7 +1004,7 @@ void ath12k_core_halt(struct ath12k *ar) {struct ath12k_base *ab = ar->ab; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy); ar->num_created_vdevs =0 ; ar->allocated_vdev_map =0 ;
@@ -1087,9 +1087,9 @@ static void ath12k_core_post_reconfigure_recovery(struct ath12k_base *ab)for (j =0 ; j < ah->num_radio; j++) { ar = &ah->radio[j]; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);ath12k_core_halt (ar); -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy); }break ;
drivers/net/wireless/ath/ath12k/core.h +1 -4
@@ -562,10 +562,7 @@ struct ath12k {u32 num_stations;u32 max_num_stations;bool monitor_present; -/* To synchronize concurrent synchronous mac80211 callback operations, -* concurrent debugfs configuration and concurrent FW statistics events. -*/ -struct mutex conf_mutex; +/* protects the radio specific data like debug stats, ppdu_stats_info stats, * vdev_stop_status info, scan data, ath12k_sta info, ath12k_vif info, * channel context data, survey info, test mode data.
drivers/net/wireless/ath/ath12k/debugfs.c +2 -2
@@ -15,14 +15,14 @@ static ssize_t ath12k_write_simulate_radar(struct file *file,struct ath12k *ar = file->private_data;int ret; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy); ret =ath12k_wmi_simulate_radar (ar);if (ret) goto exit; ret = count; exit: -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return ret; }
drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c +13 -13
@@ -1627,9 +1627,9 @@ static ssize_t ath12k_read_htt_stats_type(struct file *file,char buf[32 ];size_t len; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy); type = ar->debug.htt_stats.type; -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy); len =scnprintf (buf,sizeof (buf),"%u\n" , type);
@@ -1662,7 +1662,7 @@ static ssize_t ath12k_write_htt_stats_type(struct file *file, type >= ATH12K_DBG_HTT_NUM_EXT_STATS)return -EINVAL ; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy); ar->debug.htt_stats.type = type; ar->debug.htt_stats.cfg_param[0 ] = cfg_param[0 ];
@@ -1670,7 +1670,7 @@ static ssize_t ath12k_write_htt_stats_type(struct file *file, ar->debug.htt_stats.cfg_param[2 ] = cfg_param[2 ]; ar->debug.htt_stats.cfg_param[3 ] = cfg_param[3 ]; -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return count; }
@@ -1691,7 +1691,7 @@ static int ath12k_debugfs_htt_stats_req(struct ath12k *ar)int ret, pdev_id;struct htt_ext_stats_cfg_params cfg_params = {0 }; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);init_completion (&stats_req->htt_stats_rcvd);
@@ -1741,7 +1741,7 @@ static int ath12k_open_htt_stats(struct inode *inode,if (type ==ATH12K_DBG_HTT_EXT_STATS_RESET )return -EPERM ; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);if (ah->state !=ATH12K_HW_STATE_ON ) { ret = -ENETDOWN ;
@@ -1776,14 +1776,14 @@ static int ath12k_open_htt_stats(struct inode *inode, file->private_data = stats_req; -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return 0 ; out:kfree (stats_req); ar->debug.htt_stats.stats_req =NULL ; err_unlock: -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return ret; }
@@ -1793,10 +1793,10 @@ static int ath12k_release_htt_stats(struct inode *inode, {struct ath12k *ar = inode->i_private; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);kfree (file->private_data); ar->debug.htt_stats.stats_req =NULL ; -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return 0 ; }
@@ -1840,7 +1840,7 @@ static ssize_t ath12k_write_htt_stats_reset(struct file *file, type == ATH12K_DBG_HTT_EXT_STATS_RESET)return -E2BIG ; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy); cfg_params.cfg0 =HTT_STAT_DEFAULT_RESET_START_OFFSET ; param_pos = (type >>5 ) +1 ;
@@ -1866,12 +1866,12 @@ static ssize_t ath12k_write_htt_stats_reset(struct file *file, 0ULL);if (ret) {ath12k_warn (ar->ab,"failed to send htt stats request: %d\n" , ret); -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return ret; } ar->debug.htt_stats.reset = type; -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy);return count; }
drivers/net/wireless/ath/ath12k/mac.c +109 -164
1,050 lines not on this page · raw message
drivers/net/wireless/ath/ath12k/peer.c +3 -3
@@ -186,7 +186,7 @@ void ath12k_peer_cleanup(struct ath12k *ar, u32 vdev_id)struct ath12k_peer *peer, *tmp;struct ath12k_base *ab = ar->ab; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);spin_lock_bh (&ab->base_lock);list_for_each_entry_safe (peer, tmp, &ab->peers, list) {
@@ -235,7 +235,7 @@ int ath12k_peer_delete(struct ath12k *ar, u32 vdev_id, u8 *addr) {int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);reinit_completion (&ar->peer_delete_done);
@@ -268,7 +268,7 @@ int ath12k_peer_create(struct ath12k *ar, struct ath12k_vif *arvif,struct ath12k_peer *peer;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);if (ar->num_peers > (ar->max_num_peers -1 )) { ath12k_warn(ar->ab,
drivers/net/wireless/ath/ath12k/wow.c +12 -14
@@ -132,7 +132,7 @@ static int ath12k_wow_cleanup(struct ath12k *ar)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) { ret =ath12k_wow_vif_cleanup (arvif);
@@ -476,7 +476,7 @@ static int ath12k_wow_set_wakeups(struct ath12k *ar,struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) {if (ath12k_wow_is_p2p_vdev (arvif))
@@ -535,7 +535,7 @@ static int ath12k_wow_nlo_cleanup(struct ath12k *ar)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) {if (ath12k_wow_is_p2p_vdev (arvif))
@@ -558,7 +558,7 @@ static int ath12k_wow_set_hw_filter(struct ath12k *ar)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) {if (arvif->vdev_type !=WMI_VDEV_TYPE_STA )
@@ -584,7 +584,7 @@ static int ath12k_wow_clear_hw_filter(struct ath12k *ar)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) {if (arvif->vdev_type !=WMI_VDEV_TYPE_STA )
@@ -735,7 +735,7 @@ static int ath12k_wow_arp_ns_offload(struct ath12k *ar, bool enable)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy); offload =kmalloc (sizeof (*offload),GFP_KERNEL );if (!offload)
@@ -769,7 +769,7 @@ static int ath12k_gtk_rekey_offload(struct ath12k *ar, bool enable)struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) { if (arvif->vdev_type != WMI_VDEV_TYPE_STA ||
@@ -827,7 +827,7 @@ static int ath12k_wow_set_keepalive(struct ath12k *ar,struct ath12k_vif *arvif;int ret; -lockdep_assert_held (&ar->conf_mutex); +lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);list_for_each_entry (arvif, &ar->arvifs, list) { ret =ath12k_mac_vif_set_keepalive (arvif, method, interval);
@@ -845,7 +845,7 @@ int ath12k_wow_op_suspend(struct ieee80211_hw *hw,struct ath12k *ar =ath12k_ah_to_ar (ah,0 );int ret; -mutex_lock (&ar->conf_mutex); +lockdep_assert_wiphy (hw->wiphy); ret =ath12k_wow_cleanup (ar);if (ret) {
@@ -913,7 +913,6 @@ int ath12k_wow_op_suspend(struct ieee80211_hw *hw,ath12k_wow_cleanup (ar); exit: -mutex_unlock (&ar->conf_mutex);return ret ?1 :0 ; }
@@ -922,9 +921,9 @@ void ath12k_wow_op_set_wakeup(struct ieee80211_hw *hw, bool enabled)struct ath12k_hw *ah =ath12k_hw_to_ah (hw);struct ath12k *ar =ath12k_ah_to_ar (ah,0 ); -mutex_lock (&ar->conf_mutex); +lockdep_assert_wiphy (hw->wiphy); +device_set_wakeup_enable (ar->ab->dev, enabled); -mutex_unlock (&ar->conf_mutex); }int ath12k_wow_op_resume (struct ieee80211_hw *hw)
@@ -933,7 +932,7 @@ int ath12k_wow_op_resume(struct ieee80211_hw *hw)struct ath12k *ar =ath12k_ah_to_ar (ah,0 );int ret; -mutex_lock (&ar->conf_mutex); +lockdep_assert_wiphy (hw->wiphy); ret =ath12k_hif_resume (ar->ab);if (ret) {
@@ -995,7 +994,6 @@ int ath12k_wow_op_resume(struct ieee80211_hw *hw) } } -mutex_unlock (&ar->conf_mutex);return ret; }
Signature · 1 line
2.39.5
RFC PATCH v2 2/4 wifi: ath12k: cleanup unneeded labels
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
After removing the conf_mutex in the previous patch there are now unnecessary labels in mac.c. Sparse also warns one instance of it:
drivers/net/wireless/ath/ath12k/mac.c:6635:1: warning: statement expected after label
Remove the labels and instead use directly return.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/mac.c | 56 +++++++++++---------------- 1 file changed, 22 insertions(+), 34 deletions(-)
drivers/net/wireless/ath/ath12k/mac.c +22 -34
@@ -1279,24 +1279,23 @@ static int ath12k_mac_config(struct ath12k *ar, u32 changed) ar->monitor_conf_enabled = conf->flags &IEEE80211_CONF_MONITOR ;if (ar->monitor_conf_enabled) {if (ar->monitor_vdev_created) - goto exit; +return ret; ret =ath12k_mac_monitor_vdev_create (ar);if (ret) - goto exit; +return ret; ret =ath12k_mac_monitor_start (ar);if (ret) goto err_mon_del; }else {if (!ar->monitor_vdev_created) - goto exit; +return ret; ret =ath12k_mac_monitor_stop (ar);if (ret) - goto exit; +return ret;ath12k_mac_monitor_vdev_delete (ar); } } -exit:return ret; err_mon_del:
@@ -4716,10 +4715,9 @@ static int ath12k_mac_op_sta_set_txpwr(struct ieee80211_hw *hw,if (ret) {ath12k_warn (ar->ab,"failed to set tx power for station ret: %d\n" , ret); - goto out; +return ret; } -out:return ret; }
@@ -6472,7 +6470,7 @@ static int ath12k_mac_vdev_create(struct ath12k *ar, struct ieee80211_vif *vif)if (ret) {ath12k_warn (ab,"failed to create WMI vdev %d: %d\n" , arvif->vdev_id, ret); - goto err; +return ret; } ar->num_created_vdevs++;
@@ -6589,13 +6587,13 @@ static int ath12k_mac_vdev_create(struct ath12k *ar, struct ieee80211_vif *vif)if (ret) {ath12k_warn (ar->ab,"failed to delete peer vdev_id %d addr %pM\n" , arvif->vdev_id, vif->addr); - goto err; +return ret; } ret =ath12k_wait_for_peer_delete_done (ar, arvif->vdev_id, vif->addr);if (ret) - goto err; +return ret; ar->num_peers--; }
@@ -7627,21 +7625,18 @@ ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw, arvif->vdev_type != WMI_VDEV_TYPE_MONITOR && !ath12k_peer_exist_by_vdev_id(ab, arvif->vdev_id)) {memcpy (&arvif->chanctx, ctx,sizeof (*ctx)); - ret =0 ; - goto out; +return 0 ; } -if (WARN_ON (arvif->is_started)) { - ret = -EBUSY ; - goto out; - } +if (WARN_ON (arvif->is_started)) +return -EBUSY ;if (arvif->vdev_type ==WMI_VDEV_TYPE_MONITOR ) { ret =ath12k_mac_monitor_start (ar);if (ret) - goto out; +return ret; arvif->is_started = true; - goto out; +return ret; } ret =ath12k_mac_vdev_start (arvif, ctx);
@@ -7649,7 +7644,7 @@ ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,ath12k_warn (ab,"failed to start vdev %i addr %pM on freq %d: %d\n" , arvif->vdev_id, vif->addr, ctx->def.chan->center_freq, ret); - goto out; +return ret; }if (arvif->vdev_type !=WMI_VDEV_TYPE_MONITOR && ar->monitor_vdev_created)
@@ -7659,7 +7654,6 @@ ath12k_mac_op_assign_vif_chanctx(struct ieee80211_hw *hw,/* TODO: Setup ps and cts/rts protection */ -out:return ret; }
@@ -8127,10 +8121,8 @@ ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, ldpc = !!(ar->ht_cap_info &WMI_HT_CAP_LDPC ); sgi = mask->control[band].gi; -if (sgi ==NL80211_TXRATE_FORCE_LGI ) { - ret = -EINVAL ; - goto out; - } +if (sgi ==NL80211_TXRATE_FORCE_LGI ) +return -EINVAL ;/* mac80211 doesn't support sending a fixed HT/VHT MCS alone, rather it * requires passing at least one of used basic rates along with them.
@@ -8146,7 +8138,7 @@ ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,if (ret) {ath12k_warn (ar->ab,"failed to get single legacy rate for vdev %i: %d\n" , arvif->vdev_id, ret); - goto out; +return ret; } ieee80211_iterate_stations_atomic(hw, ath12k_mac_disable_peer_fixed_rate,
@@ -8191,8 +8183,7 @@ ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw,*/ ath12k_warn (ar->ab,"Setting more than one MCS Value in bitrate mask not supported\n" ); - ret = -EINVAL ; - goto out; +return -EINVAL ; } ieee80211_iterate_stations_atomic(hw,
@@ -8211,7 +8202,6 @@ ath12k_mac_op_set_bitrate_mask(struct ieee80211_hw *hw, arvif->vdev_id, ret); } -out:return ret; }
@@ -8522,7 +8512,7 @@ static int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw,spin_unlock_bh (&ar->data_lock);if (ret) - goto exit; +return ret; scan_time_msec = hw->wiphy->max_remain_on_channel_duration *2 ;
@@ -8531,10 +8521,8 @@ static int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, arg.num_chan =1 ; arg.chan_list =kcalloc (arg.num_chan,sizeof (*arg.chan_list),GFP_KERNEL ); -if (!arg.chan_list) { - ret = -ENOMEM ; - goto exit; - } +if (!arg.chan_list) +return -ENOMEM ; arg.vdev_id = arvif->vdev_id; arg.scan_id =ATH12K_SCAN_ID ;
@@ -8572,7 +8560,7 @@ static int ath12k_mac_op_remain_on_channel(struct ieee80211_hw *hw, free_chan_list:kfree (arg.chan_list); -exit: +return ret; }
Signature · 1 line
2.39.5
RFC PATCH v2 3/4 wifi: ath12k: ath12k_mac_op_set_key(): remove exit label
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
In ath12k_mac_op_set_key() removing the exit label was a bit more complex as checkpatch complained about the unnecessary else branch after a return. So remove the else branch and remove now the unncessary ret initialisation.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/mac.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/net/wireless/ath/ath12k/mac.c +10 -12
@@ -3942,7 +3942,7 @@ static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd,struct ath12k_peer *peer;struct ath12k_sta *arsta;const u8 *peer_addr; -int ret =0 ; +int ret;u32 flags =0 ;lockdep_assert_wiphy (ath12k_ar_to_hw (ar)->wiphy);
@@ -3970,14 +3970,13 @@ static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd,if (cmd ==SET_KEY ) {ath12k_warn (ab,"cannot install key for non-existent peer %pM\n" , peer_addr); - ret = -EOPNOTSUPP ; - goto exit; - }else { -/* if the peer doesn't exist there is no key to disable -* anymore -*/ - goto exit; +return -EOPNOTSUPP ; } + +/* if the peer doesn't exist there is no key to disable +* anymore +*/ +return 0 ; }if (key->flags &IEEE80211_KEY_FLAG_PAIRWISE )
@@ -3988,13 +3987,13 @@ static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd, ret =ath12k_install_key (arvif, key, cmd, peer_addr, flags);if (ret) {ath12k_warn (ab,"ath12k_install_key failed (%d)\n" , ret); - goto exit; +return ret; } ret =ath12k_dp_rx_peer_pn_replay_config (arvif, peer_addr, cmd, key);if (ret) {ath12k_warn (ab,"failed to offload PN replay detection %d\n" , ret); - goto exit; +return ret; }spin_lock_bh (&ab->base_lock);
@@ -4040,8 +4039,7 @@ static int ath12k_mac_set_key(struct ath12k *ar, enum set_key_cmd cmd,spin_unlock_bh (&ab->base_lock); -exit: -return ret; +return 0 ; } static int ath12k_mac_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Signature · 1 line
2.39.5
RFC PATCH v2 4/4 wifi: ath12k: convert struct ath12k_sta::update_wk to use struct wiphy_work
In reply to Kalle ValoFrom: Kalle Valo <[email protected]>
As ath12k is now converted to use wiphy lock we can convert ath12k_sta_rc_update_wk() to use wiphy_work_queue(). This is just for consistency.
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/core.h | 2 +- drivers/net/wireless/ath/ath12k/mac.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath12k/core.h +1 -1
@@ -451,7 +451,7 @@ struct ath12k_sta {u32 smps;enum hal_pn_type pn_type; -struct work_struct update_wk; +struct wiphy_work update_wk;struct rate_info txrate;struct rate_info last_txrate;u64 rx_duration;
drivers/net/wireless/ath/ath12k/mac.c +8 -6
@@ -4258,7 +4258,7 @@ static int ath12k_station_disassoc(struct ath12k *ar,return 0 ; } -static void ath12k_sta_rc_update_wk (struct work_struct *wk) +static void ath12k_sta_rc_update_wk (struct wiphy *wiphy,struct wiphy_work *work) {struct ath12k *ar;struct ath12k_vif *arvif;
@@ -4274,7 +4274,9 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)struct ath12k_wmi_peer_assoc_arg peer_arg;enum wmi_phy_mode peer_phymode; - arsta = container_of(wk, struct ath12k_sta, update_wk); +lockdep_assert_wiphy (wiphy); + + arsta = container_of(work, struct ath12k_sta, update_wk); sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); arvif = arsta->arvif; ar = arvif->ar;
@@ -4571,7 +4573,7 @@ static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw,/* cancel must be done outside the mutex to avoid deadlock */ if ((old_state ==IEEE80211_STA_NONE && new_state ==IEEE80211_STA_NOTEXIST )) -cancel_work_sync (&arsta->update_wk); +wiphy_work_cancel (hw->wiphy, &arsta->update_wk); ar =ath12k_get_ar_by_vif (hw, vif);if (!ar) {
@@ -4585,7 +4587,7 @@ static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, new_state == IEEE80211_STA_NONE) {memset (arsta,0 ,sizeof (*arsta)); arsta->arvif = arvif; -INIT_WORK (&arsta->update_wk, ath12k_sta_rc_update_wk); +wiphy_work_init (&arsta->update_wk, ath12k_sta_rc_update_wk); ret =ath12k_mac_station_add (ar, vif, sta);if (ret)
@@ -4792,7 +4794,7 @@ static void ath12k_mac_op_sta_rc_update(struct ieee80211_hw *hw,spin_unlock_bh (&ar->data_lock); -ieee80211_queue_work (hw, &arsta->update_wk); +wiphy_work_queue (hw->wiphy, &arsta->update_wk); } static int ath12k_conf_tx_uapsd(struct ath12k_vif *arvif,
@@ -8065,7 +8067,7 @@ static void ath12k_mac_set_bitrate_mask_iter(void *data, arsta->changed |=IEEE80211_RC_SUPP_RATES_CHANGED ;spin_unlock_bh (&ar->data_lock); -ieee80211_queue_work (ath12k_ar_to_hw (ar), &arsta->update_wk); +wiphy_work_queue (ath12k_ar_to_hw (ar)->wiphy, &arsta->update_wk); } static void ath12k_mac_disable_peer_fixed_rate(void *data,
Signature · 1 line
2.39.5
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
In reply to Kalle Valodrivers/net/wireless/ath/ath12k/mac.c static void ath12k_sta_rc_update_wk(struct work_struct *wk) · line 4304
Quoted 6 lines · Kalle Valo
drivers/net/wireless/ath/ath12k/mac.c +1
-1@@ -4310,7 +4301,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)spin_unlock_bh (&ar->data_lock); -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);
note in patch 4/4 ath12k_sta::update_wk is converted to use wiphy_work. While a wiphy work item is running wiphy lock is held already. So here try to acquire wiphy lock once again will lead to a deadlock.
Quoted 10 lines
drivers/net/wireless/ath/ath12k/mac.c +1
-1nss =max_t (u32,1 , nss); nss = min(nss, max(ath12k_mac_max_ht_nss(ht_mcs_mask),@@ -4426,7 +4417,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk) } } err_rc_bw_changed: -mutex_unlock (&ar->conf_mutex); +wiphy_unlock (ath12k_ar_to_hw (ar)->wiphy); }
Re: [PATCH RFC v2 4/4] wifi: ath12k: convert struct ath12k_sta::update_wk to use struct wiphy_work
In reply to Kalle ValoQuoted 52 lines · Kalle Valo
From: Kalle Valo <[email protected]>
As ath12k is now converted to use wiphy lock we can convert
ath12k_sta_rc_update_wk()to usewiphy_work_queue(). This is just for consistency.Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
Signed-off-by Kalle Valo <[email protected]>--- drivers/net/wireless/ath/ath12k/core.h | 2 +- drivers/net/wireless/ath/ath12k/mac.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-)drivers/net/wireless/ath/ath12k/core.h +1
-1@@ -451,7 +451,7 @@ struct ath12k_sta {u32 smps;enum hal_pn_type pn_type; -struct work_struct update_wk; +struct wiphy_work update_wk;struct rate_info txrate;struct rate_info last_txrate;u64 rx_duration;drivers/net/wireless/ath/ath12k/mac.c +4
-2@@ -4258,7 +4258,7 @@ static int ath12k_station_disassoc(struct ath12k *ar,return 0 ; } -static void ath12k_sta_rc_update_wk (struct work_struct *wk) +static void ath12k_sta_rc_update_wk (struct wiphy *wiphy,struct wiphy_work *work) {struct ath12k *ar;struct ath12k_vif *arvif;@@ -4274,7 +4274,9 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)struct ath12k_wmi_peer_assoc_arg peer_arg;enum wmi_phy_mode peer_phymode; - arsta = container_of(wk, struct ath12k_sta, update_wk); +lockdep_assert_wiphy (wiphy); + + arsta = container_of(work, struct ath12k_sta, update_wk); sta = container_of((void *)arsta, struct ieee80211_sta, drv_priv); arvif = arsta->arvif; ar = arvif->ar;
drivers/net/wireless/ath/ath12k/mac.c static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, · line 4573
Quoted 1 line
drivers/net/wireless/ath/ath12k/mac.c +0
-0@@ -4571,7 +4573,7 @@ static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw,/* cancel must be done outside the mutex to avoid deadlock */
remove this comment
drivers/net/wireless/ath/ath12k/mac.c static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, · line 4576
Quoted 4 lines
drivers/net/wireless/ath/ath12k/mac.c +1
-1if ((old_state ==IEEE80211_STA_NONE && new_state ==IEEE80211_STA_NOTEXIST )) -cancel_work_sync (&arsta->update_wk); +wiphy_work_cancel (hw->wiphy, &arsta->update_wk);
with wiphy lock used, the race condition with ar->conf_mutex is gone so deadlock is not possible. therefore we don;t need to do work cancel individually here, better to squash this hunk into the other one. This also achieves symmetry.
} else if ((old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST)) {
...
/* I mean here */
...
}Quoted 30 lines
drivers/net/wireless/ath/ath12k/mac.c +3
-3ar =ath12k_get_ar_by_vif (hw, vif);if (!ar) {@@ -4585,7 +4587,7 @@ static int ath12k_mac_op_sta_state(struct ieee80211_hw *hw, new_state == IEEE80211_STA_NONE) {memset (arsta,0 ,sizeof (*arsta)); arsta->arvif = arvif; -INIT_WORK (&arsta->update_wk, ath12k_sta_rc_update_wk); +wiphy_work_init (&arsta->update_wk, ath12k_sta_rc_update_wk); ret =ath12k_mac_station_add (ar, vif, sta);if (ret)@@ -4792,7 +4794,7 @@ static void ath12k_mac_op_sta_rc_update(struct ieee80211_hw *hw,spin_unlock_bh (&ar->data_lock); -ieee80211_queue_work (hw, &arsta->update_wk); +wiphy_work_queue (hw->wiphy, &arsta->update_wk); } static int ath12k_conf_tx_uapsd(struct ath12k_vif *arvif,@@ -8065,7 +8067,7 @@ static void ath12k_mac_set_bitrate_mask_iter(void *data, arsta->changed |=IEEE80211_RC_SUPP_RATES_CHANGED ;spin_unlock_bh (&ar->data_lock); -ieee80211_queue_work (ath12k_ar_to_hw (ar), &arsta->update_wk); +wiphy_work_queue (ath12k_ar_to_hw (ar)->wiphy, &arsta->update_wk); } static void ath12k_mac_disable_peer_fixed_rate(void *data,
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
In reply to Kalle ValoQuoted 5 lines · Kalle Valo
There is now a new sparse warning, but to keep this long patch simple the labels will be cleaned up in following patches:
drivers/net/wireless/ath/ath12k/mac.c:6635:1: warning: statement expected after label
I believe this is a compiler error on some compilers (in particular clang), so you probably need to combine patches a little bit.
drivers/net/wireless/ath/ath12k/debugfs.c static ssize_t ath12k_write_simulate_radar(struct file *file, · line 18
Quoted 7 lines
+++
b/drivers/net/wireless/ath/ath12k/debugfs.cdrivers/net/wireless/ath/ath12k/debugfs.c +1
-1@@ -15,14 +15,14 @@ static ssize_t ath12k_write_simulate_radar(struct file *file,struct ath12k *ar = file->private_data;int ret; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);
I don't think this is an issue here, but I'm not sure if you're aware that in general, locking the wiphy mutex in some debugfs file handlers can lead to deadlocks, specifically if those files are later _removed_ while holding the wiphy lock, as is e.g. the case for station, netdev and link debugfs files. For this, we have wiphy_locked_debugfs_read() and wiphy_locked_debugfs_write() [1].
[1] you are not required to understand how they are implemented ;-)
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_sta_rc_update_wk(struct work_struct *wk) · line 4304
Quoted 6 lines
drivers/net/wireless/ath/ath12k/mac.c +1
-1@@ -4310,7 +4301,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)spin_unlock_bh (&ar->data_lock); -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);
Baochen already pointed out that you seem to not remove this later in patch 4, but in this patch alone you also introduce a bug (that lockdep should point out to you), which is that you cancel_work_sync() this in ath12k_mac_op_sta_state(), which clearly holds the wiphy mutex already.
This causes a deadlock. It's fine after patch 4:
Review static void ath12k_sta_rc_update_wk(struct work_struct *wk)
Quoted 5 lines
(quoted diff) +1
-1/* cancel must be done outside the mutex to avoid deadlock */ if ((old_state == IEEE80211_STA_NONE && new_state == IEEE80211_STA_NOTEXIST)) - cancel_work_sync(&arsta->update_wk); + wiphy_work_cancel(hw->wiphy, &arsta->update_wk);
since for wiphy work it's required to ca<ll it with the mutex held./
You really should remove that comment too though, and perhaps then the code can be simplified by moving this to the later code also handling removal (none->notexist transition).
johannes
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
In reply to Baochen QiangQuoted 5 lines · Baochen Qiang
Quoted 4 lines · Kalle Valo
drivers/net/wireless/ath/ath12k/mac.c +0
-0@@ -4310,7 +4301,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)spin_unlock_bh (&ar->data_lock);
Quoted 7 lines
Review static void ath12k_sta_rc_update_wk(struct work_struct *wk) · line 4304
Quoted 2 lines
(quoted diff) +1
-1- mutex_lock(&ar->conf_mutex); + wiphy_lock(ath12k_ar_to_hw(ar)->wiphy);note in patch 4/4
ath12k_sta::update_wkis converted to usewiphy_work. While a wiphy work item is running wiphy lock is held already. So here try to acquire wiphy lock once again will lead to a deadlock.
Ouch again, thanks for catching this! This time I actually tested changing bitrates and it shouldn't deadlock in v3. But I did notice sleeping while atomic warnings (even without this patchset) and decided to fix those in the same patchset as well.
Oh, and WCN6855 firmware was also crashing whenever I tried to change the bitrates. But let's handle that separately.
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
In reply to Johannes BergQuoted 9 lines · Johannes Berg
Quoted 5 lines · Kalle Valo
There is now a new sparse warning, but to keep this long patch simple the labels will be cleaned up in following patches:
drivers/net/wireless/ath/ath12k/mac.c:6635:1: warning: statement expected after labelI believe this is a compiler error on some compilers (in particular clang), so you probably need to combine patches a little bit.
I had actually already fixed this but forgot to update the commit message, did that now in v3.
Quoted 15 lines
drivers/net/wireless/ath/ath12k/debugfs.c static ssize_t ath12k_write_simulate_radar(struct file *file, · line 18
Quoted 7 lines
+++
b/drivers/net/wireless/ath/ath12k/debugfs.cdrivers/net/wireless/ath/ath12k/debugfs.c +1
-1@@ -15,14 +15,14 @@ static ssize_t ath12k_write_simulate_radar(struct file *file,struct ath12k *ar = file->private_data;int ret; -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);I don't think this is an issue here, but I'm not sure if you're aware that in general, locking the wiphy mutex in some debugfs file handlers can lead to deadlocks, specifically if those files are later _removed_ while holding the wiphy lock, as is e.g. the case for station, netdev and link debugfs files. For this, we have
wiphy_locked_debugfs_read()andwiphy_locked_debugfs_write()[1].
Quoted 1 line
[1] you are not required to understand how they are implemented ;-)
Thanks, this is good to know. I'm not that worried about that, at least it's not showing up in my tests, so my plan is to fix that in a separate patchset.
Quoted 14 lines
drivers/net/wireless/ath/ath12k/mac.c static void ath12k_sta_rc_update_wk(struct work_struct *wk) · line 4304
Quoted 6 lines
drivers/net/wireless/ath/ath12k/mac.c +1
-1@@ -4310,7 +4301,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)spin_unlock_bh (&ar->data_lock); -mutex_lock (&ar->conf_mutex); +wiphy_lock (ath12k_ar_to_hw (ar)->wiphy);Baochen already pointed out that you seem to not remove this later in patch 4, but in this patch alone you also introduce a bug (that lockdep should point out to you), which is that you
cancel_work_sync()this inath12k_mac_op_sta_state(), which clearly holds the wiphy mutex already.This causes a deadlock. It's fine after patch 4:
Quoted 7 lines
Review static void ath12k_sta_rc_update_wk(struct work_struct *wk)
Quoted 5 lines
(quoted diff) +1
-1/* cancel must be done outside the mutex to avoid deadlock */ if ((old_state == IEEE80211_STA_NONE && new_state == IEEE80211_STA_NOTEXIST)) - cancel_work_sync(&arsta->update_wk); + wiphy_work_cancel(hw->wiphy, &arsta->update_wk);since for wiphy work it's required to ca<ll it with the mutex held./
Excellent find! I fixed it so that I moved this patch before switching to use wiphy_lock(). There should not be a deadlock anymore, hopefully :)
Quoted 3 lines
You really should remove that comment too though, and perhaps then the code can be simplified by moving this to the later code also handling removal (
none->notexisttransition).
Good point. In v3 I added a new patch for this.
Thanks again for the review, I owe you so many beers[1] that it's starting to get difficult to store them ;)
[1] https://en.wikipedia.org/wiki/Karhu_(beer)
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
Quoted 7 lines · Kalle Valo
Quoted 7 lines
I don't think this is an issue here, but I'm not sure if you're aware that in general, locking the wiphy mutex in some debugfs file handlers can lead to deadlocks, specifically if those files are later _removed_ while holding the wiphy lock, as is e.g. the case for station, netdev and link debugfs files. For this, we have
wiphy_locked_debugfs_read()andwiphy_locked_debugfs_write()[1].
Quoted 5 lines
Quoted 1 line
[1] you are not required to understand how they are implemented ;-)
Thanks, this is good to know. I'm not that worried about that, at least it's not showing up in my tests, so my plan is to fix that in a separate patchset.
I don't think you'd ever even find that in tests, as far as I know lockdep cannot track these dependencies, and to actually deadlock you'd have to have the debugfs file(s) kept open by userspace while they're removed.
In any case, just wanted to give a heads-up that this might be required in some (future) cases, I didn't see any here where it was needed.
johannes
Re: [PATCH RFC v2 1/4] wifi: ath12k: switch to using wiphy_lock() and remove ar->conf_mutex
In reply to Kalle ValoQuoted 15 lines · Kalle Valo
Quoted 5 lines · Baochen Qiang
Quoted 4 lines · Kalle Valo
drivers/net/wireless/ath/ath12k/mac.c +0
-0@@ -4310,7 +4301,7 @@ static void ath12k_sta_rc_update_wk(struct work_struct *wk)spin_unlock_bh (&ar->data_lock);Quoted 7 lines
Review static void ath12k_sta_rc_update_wk(struct work_struct *wk) · line 4304
Quoted 2 lines
(quoted diff) +1
-1- mutex_lock(&ar->conf_mutex); + wiphy_lock(ath12k_ar_to_hw(ar)->wiphy);note in patch 4/4
ath12k_sta::update_wkis converted to usewiphy_work. While a wiphy work item is running wiphy lock is held already. So here try to acquire wiphy lock once again will lead to a deadlock.
Quoted 7 lines
Ouch again, thanks for catching this! This time I actually tested changing bitrates and it shouldn't deadlock in v3. But I did notice sleeping while atomic warnings (even without this patchset) and decided to fix those in the same patchset as well.
Oh, and WCN6855 firmware was also crashing whenever I tried to change the bitrates. But let's handle that separately.
Bah, I of course mean WCN7850. Too many chipsets...
Signature · 3 lines
https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches