Skip to contentSkip to conversation

wireless: Allow registering more than one beacon listener.

PATCH In review [email protected] 3 participants 6 messages Oct 26, 2012 – Nov 5, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 wireless: Allow registering more than one beacon listener.

From: Ben Greear <[email protected]>

The commit:

commit 5e760230e42cf759bd923457ca2753aacf2e656e

Author: Johannes Berg <[email protected]>
Date:   Fri Nov 4 11:18:17 2011 +0100

cfg80211: allow registering to beacons

allowed only a single process to register for beacon events per wiphy. This breaks cases where a user may want two or more VIFs on a wiphy and run a seperate hostapd process on each vif.

This patch allows multiple beacon listeners, fixing the regression.

---
v2: Suggested changes from Johannes Berg.

 include/net/cfg80211.h |    3 +-
 net/mac80211/rx.c      |    2 +-
 net/wireless/core.c    |    7 ++++
 net/wireless/core.h    |    7 +++-
 net/wireless/nl80211.c |   88 ++++++++++++++++++++++++++++++++---------------
 5 files changed, 75 insertions(+), 32 deletions(-)
include/net/cfg80211.h +1 -2
index a7c0d15..8e0fa15 100644
@@ -3544,7 +3544,6 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  * @len: length of the frame
  * @freq: frequency the frame was received on
  * @sig_dbm: signal strength in mBm, or 0 if unknown
- * @gfp: allocation flags
  *
  * Use this function to report to userspace when a beacon was
  * received. It is not useful to call this when there is no
@@ -3552,7 +3551,7 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  */
 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 				 const u8 *frame, size_t len,
-				 int freq, int sig_dbm, gfp_t gfp);
+				 int freq, int sig_dbm);
 
 /**
  * cfg80211_can_beacon_sec_chan - test if ht40 on extension channel can be used
net/mac80211/rx.c +1 -1
index d07216a..7b1c5f3 100644
@@ -2187,7 +2187,7 @@ ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
 
 		cfg80211_report_obss_beacon(rx->local->hw.wiphy,
 					    rx->skb->data, rx->skb->len,
-					    status->freq, sig, GFP_ATOMIC);
+					    status->freq, sig);
 		rx->flags |= IEEE80211_RX_BEACON_REPORTED;
 	}
 
net/wireless/core.c +7 -0
index ce1ad77..9c3a657 100644
@@ -326,6 +326,8 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
 	mutex_init(&rdev->devlist_mtx);
 	mutex_init(&rdev->sched_scan_mtx);
 	INIT_LIST_HEAD(&rdev->wdev_list);
+	INIT_LIST_HEAD(&rdev->beacon_registrations);
+	spin_lock_init(&rdev->beacon_registrations_lock);
 	spin_lock_init(&rdev->bss_lock);
 	INIT_LIST_HEAD(&rdev->bss_list);
 	INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
@@ -699,10 +701,15 @@ EXPORT_SYMBOL(wiphy_unregister);
 void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
 {
 	struct cfg80211_internal_bss *scan, *tmp;
+	struct cfg80211_beacon_registration *reg, *treg;
 	rfkill_destroy(rdev->rfkill);
 	mutex_destroy(&rdev->mtx);
 	mutex_destroy(&rdev->devlist_mtx);
 	mutex_destroy(&rdev->sched_scan_mtx);
+	list_for_each_entry_safe(reg, treg, &rdev->beacon_registrations, list) {
+		list_del(&reg->list);
+		kfree(reg);
+	}
 	list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
 		cfg80211_put_bss(&scan->pub);
 	kfree(rdev);
net/wireless/core.h +6 -1
index b8eb743..e53831c 100644
@@ -55,7 +55,8 @@ struct cfg80211_registered_device {
 	int opencount; /* also protected by devlist_mtx */
 	wait_queue_head_t dev_wait;
 
-	u32 ap_beacons_nlportid;
+	struct list_head beacon_registrations;
+	spinlock_t beacon_registrations_lock;
 
 	/* protected by RTNL only */
 	int num_running_ifaces;
@@ -260,6 +261,10 @@ enum cfg80211_chan_mode {
 	CHAN_MODE_EXCLUSIVE,
 };
 
+struct cfg80211_beacon_registration {
+	struct list_head list;
+	u32 nlportid;
+};
 
 /* free object */
 extern void cfg80211_dev_free(struct cfg80211_registered_device *rdev);
net/wireless/nl80211.c +60 -28

133 lines not on this page · raw message

Signature · 1 line
1.7.3.4
maintainer
#1 lore raw

Thanks Ben,

I was going to apply this but it looks like I missed something on the previous review:

Quoted 5 lines

void cfg80211_report_obss_beacon(struct wiphy *wiphy,

(quoted diff) +1 -1
 				 const u8 *frame, size_t len,
-				 int freq, int sig_dbm, gfp_t gfp)
+				 int freq, int sig_dbm)
 {

...

Quoted 1 line
(quoted diff) +1 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	spin_unlock_bh(&rdev->beacon_registrations_lock);

I have a feeling this is incorrect, this is called with BHs disabled, so if we disable/enable BHs here we end up with BHs enabled even if the caller wanted them disabled, no?

So I suppose unless we need to be able to call this from hard interrupt in some driver (unlikely) we should add a change like this:

include/net/cfg80211.h +1 -0
index 10a7f45..3b6a11a 100644
@@ -3544,6 +3544,7 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
  * Use this function to report to userspace when a beacon was
  * received. It is not useful to call this when there is no
  * netdev that is in AP/GO mode.
+ * The function must be called with BHs disabled.
  */
 void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 				 const u8 *frame, size_t len,
net/wireless/nl80211.c +4 -4
index 15ddbb8..5ff24ef 100644
@@ -8942,11 +8942,11 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 
 	trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
 
-	spin_lock_bh(&rdev->beacon_registrations_lock);
+	spin_lock(&rdev->beacon_registrations_lock);
 	list_for_each_entry(reg, &rdev->beacon_registrations, list) {
 		msg = nlmsg_new(len + 100, GFP_ATOMIC);
 		if (!msg) {
-			spin_unlock_bh(&rdev->beacon_registrations_lock);
+			spin_unlock(&rdev->beacon_registrations_lock);
 			return;
 		}
 
@@ -8966,11 +8966,11 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 
 		genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
 	}
-	spin_unlock_bh(&rdev->beacon_registrations_lock);
+	spin_unlock(&rdev->beacon_registrations_lock);
 	return;
 
  nla_put_failure:
-	spin_unlock_bh(&rdev->beacon_registrations_lock);
+	spin_unlock(&rdev->beacon_registrations_lock);
 	if (hdr)
 		genlmsg_cancel(msg, hdr);
 	nlmsg_free(msg);

johannes

author
#2 lore raw
Quoted 15 lines · Johannes Berg

Thanks Ben,

I was going to apply this but it looks like I missed something on the previous review:

Quoted 5 lines

void cfg80211_report_obss_beacon(struct wiphy *wiphy,
const u8 *frame, size_t len,

(quoted diff) +1 -1
-				 int freq, int sig_dbm, gfp_t gfp)
+				 int freq, int sig_dbm)
  {

...

Quoted 1 line
(quoted diff) +1 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);

...

Quoted 8 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	spin_unlock_bh(&rdev->beacon_registrations_lock);

I have a feeling this is incorrect, this is called with BHs disabled, so if we disable/enable BHs here we end up with BHs enabled even if the caller wanted them disabled, no?

So I suppose unless we need to be able to call this from hard interrupt in some driver (unlikely) we should add a change like this:

I get confused with the various types of spin-locks, and I just copied this code from the mgt frames logic.

I did run some tests and my code seems stable, but I could just be getting lucky.

Do you want me to roll in your changes below and re-submit, or do you want to just make the updates?

Thanks,
Ben

Quoted 49 lines
include/net/cfg80211.h +1 -0
index 10a7f45..3b6a11a 100644
@@ -3544,6 +3544,7 @@ void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
   * Use this function to report to userspace when a beacon was
   * received. It is not useful to call this when there is no
   * netdev that is in AP/GO mode.
+ * The function must be called with BHs disabled.
   */
  void cfg80211_report_obss_beacon(struct wiphy *wiphy,
  				 const u8 *frame, size_t len,
net/wireless/nl80211.c +4 -4
index 15ddbb8..5ff24ef 100644
@@ -8942,11 +8942,11 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 
  	trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
 
-	spin_lock_bh(&rdev->beacon_registrations_lock);
+	spin_lock(&rdev->beacon_registrations_lock);
  	list_for_each_entry(reg, &rdev->beacon_registrations, list) {
  		msg = nlmsg_new(len + 100, GFP_ATOMIC);
  		if (!msg) {
-			spin_unlock_bh(&rdev->beacon_registrations_lock);
+			spin_unlock(&rdev->beacon_registrations_lock);
  			return;
  		}
 
@@ -8966,11 +8966,11 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
 
  		genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
  	}
-	spin_unlock_bh(&rdev->beacon_registrations_lock);
+	spin_unlock(&rdev->beacon_registrations_lock);
  	return;
 
   nla_put_failure:
-	spin_unlock_bh(&rdev->beacon_registrations_lock);
+	spin_unlock(&rdev->beacon_registrations_lock);
  	if (hdr)
  		genlmsg_cancel(msg, hdr);
  	nlmsg_free(msg);

johannes

Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com
maintainer
#3 lore raw
Quoted 8 lines · Ben Greear
Quoted 8 lines
Quoted 1 line
(quoted diff) +1 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	spin_unlock_bh(&rdev->beacon_registrations_lock);

I have a feeling this is incorrect, this is called with BHs disabled, so if we disable/enable BHs here we end up with BHs enabled even if the caller wanted them disabled, no?

Quoted 5 lines
Quoted 2 lines

So I suppose unless we need to be able to call this from hard interrupt in some driver (unlikely) we should add a change like this:

I get confused with the various types of spin-locks, and I just copied this code from the mgt frames logic.

Uh, that looks like a bug there as well then?

Quoted 2 lines

I did run some tests and my code seems stable, but I could just be getting lucky.

Hmm I guess it depends on the driver, I suppose enabling BHs inside one doesn't actually do anything, and it would only really matter for drivers using ieee80211_rx_ni()?

Quoted 2 lines

Do you want me to roll in your changes below and re-submit, or do you want to just make the updates?

I can do the update, I guess I'll sort out the mgmt frame part as well.

johannes

#4 lore raw
Quoted 10 lines · Johannes Berg
Quoted 8 lines · Ben Greear
Quoted 8 lines
Quoted 1 line
(quoted diff) +1 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	spin_unlock_bh(&rdev->beacon_registrations_lock);

I have a feeling this is incorrect, this is called with BHs disabled, so if we disable/enable BHs here we end up with BHs enabled even if the caller wanted them disabled, no?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

So I suppose unless we need to be able to call this from hard interrupt in some driver (unlikely) we should add a change like this:

I get confused with the various types of spin-locks, and I just copied this code from the mgt frames logic.

Uh, that looks like a bug there as well then?

As far as I know, local_bh_enable/local_bh_disable (which are used by spin_lock_bh) are re-entrant. Using them from a BH-disabled context is safe. All I can find with a few simple google searches confirms this.

- Felix

maintainer
#5 lore raw
Quoted 14 lines · Felix Fietkau
Quoted 13 lines · Johannes Berg
Quoted 11 lines · Ben Greear
Quoted 10 lines
Quoted 1 line
(quoted diff) +1 -0
+	spin_lock_bh(&rdev->beacon_registrations_lock);

...

Review

Quoted 1 line
(quoted diff) +1 -0
+	spin_unlock_bh(&rdev->beacon_registrations_lock);

I have a feeling this is incorrect, this is called with BHs disabled, so if we disable/enable BHs here we end up with BHs enabled even if the caller wanted them disabled, no?

So I suppose unless we need to be able to call this from hard interrupt in some driver (unlikely) we should add a change like this:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I get confused with the various types of spin-locks, and I just copied this code from the mgt frames logic.

Uh, that looks like a bug there as well then?

As far as I know, local_bh_enable/local_bh_disable (which are used by spin_lock_bh) are re-entrant. Using them from a BH-disabled context is safe. All I can find with a few simple google searches confirms this.

Hm yeah I must've confused it with something, I'll apply the patch.

johannes