Skip to content

Commit

Permalink
wifi: cfg80211: remove wdev mutex
Browse files Browse the repository at this point in the history
Since we're now protecting everything with the wiphy mutex
(and were really using it for almost everything before),
there's no longer any real reason to have a separate wdev
mutex. It may feel better, but really has no value.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Sep 11, 2023
1 parent a7614b4 commit 076fc87
Show file tree
Hide file tree
Showing 35 changed files with 300 additions and 974 deletions.
4 changes: 2 additions & 2 deletions drivers/net/wireless/ath/ath6kl/cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,9 +1118,9 @@ void ath6kl_cfg80211_ch_switch_notify(struct ath6kl_vif *vif, int freq,
ath6kl_band_2ghz.ht_cap.ht_supported) ?
NL80211_CHAN_HT20 : NL80211_CHAN_NO_HT);

mutex_lock(&vif->wdev.mtx);
wiphy_lock(vif->ar->wiphy);
cfg80211_ch_switch_notify(vif->ndev, &chandef, 0, 0);
mutex_unlock(&vif->wdev.mtx);
wiphy_unlock(vif->ar->wiphy);
}

static int ath6kl_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/marvell/mwifiex/11h.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ void mwifiex_dfs_chan_sw_work_queue(struct work_struct *work)

mwifiex_dbg(priv->adapter, MSG,
"indicating channel switch completion to kernel\n");
mutex_lock(&priv->wdev.mtx);
wiphy_lock(priv->wdev.wiphy);
cfg80211_ch_switch_notify(priv->netdev, &priv->dfs_chandef, 0, 0);
mutex_unlock(&priv->wdev.mtx);
wiphy_unlock(priv->wdev.wiphy);
}
4 changes: 2 additions & 2 deletions drivers/net/wireless/quantenna/qtnfmac/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ qtnf_event_handle_freq_change(struct qtnf_wmac *mac,
if (!vif->netdev)
continue;

mutex_lock(&vif->wdev.mtx);
wiphy_lock(priv_to_wiphy(vif->mac));
cfg80211_ch_switch_notify(vif->netdev, &chandef, 0, 0);
mutex_unlock(&vif->wdev.mtx);
wiphy_unlock(priv_to_wiphy(vif->mac));
}

return 0;
Expand Down
6 changes: 1 addition & 5 deletions include/net/cfg80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -5938,8 +5938,6 @@ void wiphy_delayed_work_flush(struct wiphy *wiphy,
* @mgmt_registrations: list of registrations for management frames
* @mgmt_registrations_need_update: mgmt registrations were updated,
* need to propagate the update to the driver
* @mtx: mutex used to lock data in this struct, may be used by drivers
* and some API functions require it held
* @beacon_interval: beacon interval used on this device for transmitting
* beacons, 0 when not valid
* @address: The address for this device, valid only if @netdev is %NULL
Expand Down Expand Up @@ -5985,8 +5983,6 @@ struct wireless_dev {
struct list_head mgmt_registrations;
u8 mgmt_registrations_need_update:1;

struct mutex mtx;

bool use_4addr, is_running, registered, registering;

u8 address[ETH_ALEN] __aligned(sizeof(u16));
Expand Down Expand Up @@ -8589,7 +8585,7 @@ bool cfg80211_reg_can_beacon_relax(struct wiphy *wiphy,
* @link_id: the link ID for MLO, must be 0 for non-MLO
* @punct_bitmap: the new puncturing bitmap
*
* Caller must acquire wdev_lock, therefore must only be called from sleepable
* Caller must hold wiphy mutex, therefore must only be called from sleepable
* driver context!
*/
void cfg80211_ch_switch_notify(struct net_device *dev,
Expand Down
20 changes: 6 additions & 14 deletions include/net/mac80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,19 +643,15 @@ struct ieee80211_fils_discovery {
* @pwr_reduction: power constraint of BSS.
* @eht_support: does this BSS support EHT
* @eht_puncturing: bitmap to indicate which channels are punctured in this BSS
* @csa_active: marks whether a channel switch is going on. Internally it is
* write-protected by sdata_lock and local->mtx so holding either is fine
* for read access.
* @csa_active: marks whether a channel switch is going on.
* @csa_punct_bitmap: new puncturing bitmap for channel switch
* @mu_mimo_owner: indicates interface owns MU-MIMO capability
* @chanctx_conf: The channel context this interface is assigned to, or %NULL
* when it is not assigned. This pointer is RCU-protected due to the TX
* path needing to access it; even though the netdev carrier will always
* be off when it is %NULL there can still be races and packets could be
* processed after it switches back to %NULL.
* @color_change_active: marks whether a color change is ongoing. Internally it is
* write-protected by sdata_lock and local->mtx so holding either is fine
* for read access.
* @color_change_active: marks whether a color change is ongoing.
* @color_change_color: the bss color that will be used after the change.
* @ht_ldpc: in AP mode, indicates interface has HT LDPC capability.
* @vht_ldpc: in AP mode, indicates interface has VHT LDPC capability.
Expand Down Expand Up @@ -1974,22 +1970,18 @@ struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev);
*/
struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif);

/**
* lockdep_vif_mutex_held - for lockdep checks on link poiners
* @vif: the interface to check
*/
static inline bool lockdep_vif_mutex_held(struct ieee80211_vif *vif)
static inline bool lockdep_vif_wiphy_mutex_held(struct ieee80211_vif *vif)
{
return lockdep_is_held(&ieee80211_vif_to_wdev(vif)->mtx);
return lockdep_is_held(&ieee80211_vif_to_wdev(vif)->wiphy->mtx);
}

#define link_conf_dereference_protected(vif, link_id) \
rcu_dereference_protected((vif)->link_conf[link_id], \
lockdep_vif_mutex_held(vif))
lockdep_vif_wiphy_mutex_held(vif))

#define link_conf_dereference_check(vif, link_id) \
rcu_dereference_check((vif)->link_conf[link_id], \
lockdep_vif_mutex_held(vif))
lockdep_vif_wiphy_mutex_held(vif))

/**
* enum ieee80211_key_flags - key flags
Expand Down
43 changes: 8 additions & 35 deletions net/mac80211/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,7 @@ ieee80211_lookup_key(struct ieee80211_sub_if_data *sdata, int link_id,
struct ieee80211_key *key;

if (link_id >= 0) {
link = rcu_dereference_check(sdata->link[link_id],
lockdep_is_held(&sdata->wdev.mtx));
link = sdata_dereference(sdata->link[link_id], sdata);
if (!link)
return NULL;
}
Expand Down Expand Up @@ -896,12 +895,10 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
sdata = wiphy_dereference(local->hw.wiphy,
local->monitor_sdata);
if (sdata) {
sdata_lock(sdata);
ieee80211_link_release_channel(&sdata->deflink);
ret = ieee80211_link_use_channel(&sdata->deflink,
chandef,
IEEE80211_CHANCTX_EXCLUSIVE);
sdata_unlock(sdata);
}
} else {
if (local->open_count == local->monitors) {
Expand Down Expand Up @@ -1490,7 +1487,7 @@ static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
struct ieee80211_bss_conf *link_conf;
u64 changed = 0;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(wiphy);

link = sdata_dereference(sdata->link[params->link_id], sdata);
if (!link)
Expand Down Expand Up @@ -1549,7 +1546,6 @@ static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev,
sdata_dereference(sdata->link[link_id], sdata);
struct ieee80211_bss_conf *link_conf = link->conf;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

old_beacon = sdata_dereference(link->u.ap.beacon, sdata);
Expand Down Expand Up @@ -2163,14 +2159,7 @@ static int ieee80211_change_station(struct wiphy *wiphy,
}
}

/* we use sta_info_get_bss() so this might be different */
if (sdata != sta->sdata) {
mutex_lock_nested(&sta->sdata->wdev.mtx, 1);
err = sta_apply_parameters(local, sta, params);
mutex_unlock(&sta->sdata->wdev.mtx);
} else {
err = sta_apply_parameters(local, sta, params);
}
err = sta_apply_parameters(local, sta, params);
if (err)
return err;

Expand Down Expand Up @@ -3132,7 +3121,7 @@ int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
struct sta_info *sta;
bool tdls_peer_found = false;

lockdep_assert_held(&sdata->wdev.mtx);
lockdep_assert_wiphy(sdata->local->hw.wiphy);

if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
return -EINVAL;
Expand Down Expand Up @@ -3211,7 +3200,6 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
local->dynamic_ps_forced_timeout = timeout;

/* no change, but if automatic follow powersave */
sdata_lock(sdata);
for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
struct ieee80211_link_data *link;

Expand All @@ -3222,7 +3210,6 @@ static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
__ieee80211_request_smps_mgd(sdata, link,
link->u.mgd.req_smps);
}
sdata_unlock(sdata);

if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
Expand Down Expand Up @@ -3609,7 +3596,6 @@ static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
u64 changed = 0;
int err;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

/*
Expand Down Expand Up @@ -3681,20 +3667,16 @@ void ieee80211_csa_finalize_work(struct wiphy *wiphy, struct wiphy_work *work)
deflink.csa_finalize_work);
struct ieee80211_local *local = sdata->local;

sdata_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

/* AP might have been stopped while waiting for the lock. */
if (!sdata->vif.bss_conf.csa_active)
goto unlock;
return;

if (!ieee80211_sdata_running(sdata))
goto unlock;
return;

ieee80211_csa_finalize(sdata);

unlock:
sdata_unlock(sdata);
}

static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
Expand Down Expand Up @@ -3850,7 +3832,6 @@ __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
u64 changed = 0;
int err;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

if (!list_empty(&local->roc_list) || local->scanning)
Expand Down Expand Up @@ -4665,7 +4646,6 @@ static int ieee80211_color_change_finalize(struct ieee80211_sub_if_data *sdata)
u64 changed = 0;
int err;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

sdata->vif.bss_conf.color_change_active = false;
Expand All @@ -4692,20 +4672,16 @@ void ieee80211_color_change_finalize_work(struct wiphy *wiphy,
deflink.color_change_finalize_work);
struct ieee80211_local *local = sdata->local;

sdata_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

/* AP might have been stopped while waiting for the lock. */
if (!sdata->vif.bss_conf.color_change_active)
goto unlock;
return;

if (!ieee80211_sdata_running(sdata))
goto unlock;
return;

ieee80211_color_change_finalize(sdata);

unlock:
sdata_unlock(sdata);
}

void ieee80211_color_collision_detection_work(struct work_struct *work)
Expand All @@ -4716,9 +4692,7 @@ void ieee80211_color_collision_detection_work(struct work_struct *work)
color_collision_detect_work);
struct ieee80211_sub_if_data *sdata = link->sdata;

sdata_lock(sdata);
cfg80211_obss_color_collision_notify(sdata->dev, link->color_bitmap);
sdata_unlock(sdata);
}

void ieee80211_color_change_finish(struct ieee80211_vif *vif)
Expand Down Expand Up @@ -4762,7 +4736,6 @@ ieee80211_color_change(struct wiphy *wiphy, struct net_device *dev,
u64 changed = 0;
int err;

sdata_assert_lock(sdata);
lockdep_assert_wiphy(local->hw.wiphy);

if (sdata->vif.bss_conf.nontransmitted)
Expand Down
10 changes: 1 addition & 9 deletions net/mac80211/debugfs_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ static int ieee80211_set_smps(struct ieee80211_link_data *link,
{
struct ieee80211_sub_if_data *sdata = link->sdata;
struct ieee80211_local *local = sdata->local;
int err;

if (sdata->vif.driver_flags & IEEE80211_VIF_DISABLE_SMPS_OVERRIDE)
return -EOPNOTSUPP;
Expand All @@ -340,11 +339,7 @@ static int ieee80211_set_smps(struct ieee80211_link_data *link,
if (sdata->vif.type != NL80211_IFTYPE_STATION)
return -EOPNOTSUPP;

sdata_lock(sdata);
err = __ieee80211_request_smps_mgd(link->sdata, link, smps_mode);
sdata_unlock(sdata);

return err;
return __ieee80211_request_smps_mgd(link->sdata, link, smps_mode);
}

static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
Expand Down Expand Up @@ -416,16 +411,13 @@ static ssize_t ieee80211_if_parse_tkip_mic_test(
case NL80211_IFTYPE_STATION:
fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
/* BSSID SA DA */
sdata_lock(sdata);
if (!sdata->u.mgd.associated) {
sdata_unlock(sdata);
dev_kfree_skb(skb);
return -ENOTCONN;
}
memcpy(hdr->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
memcpy(hdr->addr3, addr, ETH_ALEN);
sdata_unlock(sdata);
break;
default:
dev_kfree_skb(skb);
Expand Down
2 changes: 0 additions & 2 deletions net/mac80211/driver-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ int drv_assign_vif_chanctx(struct ieee80211_local *local,
might_sleep();
lockdep_assert_wiphy(local->hw.wiphy);

drv_verify_link_exists(sdata, link_conf);
if (!check_sdata_in_driver(sdata))
return -EIO;

Expand Down Expand Up @@ -329,7 +328,6 @@ void drv_unassign_vif_chanctx(struct ieee80211_local *local,
might_sleep();
lockdep_assert_wiphy(local->hw.wiphy);

drv_verify_link_exists(sdata, link_conf);
if (!check_sdata_in_driver(sdata))
return;

Expand Down
14 changes: 0 additions & 14 deletions net/mac80211/driver-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,14 +996,6 @@ static inline void drv_change_chanctx(struct ieee80211_local *local,
trace_drv_return_void(local);
}

static inline void drv_verify_link_exists(struct ieee80211_sub_if_data *sdata,
struct ieee80211_bss_conf *link_conf)
{
/* deflink always exists, so need to check only for other links */
if (sdata->deflink.conf != link_conf)
sdata_assert_lock(sdata);
}

int drv_assign_vif_chanctx(struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata,
struct ieee80211_bss_conf *link_conf,
Expand All @@ -1022,9 +1014,6 @@ static inline int drv_start_ap(struct ieee80211_local *local,
{
int ret = 0;

/* make sure link_conf is protected */
drv_verify_link_exists(sdata, link_conf);

might_sleep();
lockdep_assert_wiphy(local->hw.wiphy);

Expand All @@ -1045,9 +1034,6 @@ static inline void drv_stop_ap(struct ieee80211_local *local,
might_sleep();
lockdep_assert_wiphy(local->hw.wiphy);

/* make sure link_conf is protected */
drv_verify_link_exists(sdata, link_conf);

if (!check_sdata_in_driver(sdata))
return;

Expand Down
Loading

0 comments on commit 076fc87

Please sign in to comment.