Skip to contentSkip to conversation

mac80211: partially fix skb->cb use

PATCH In review Johannes Berg 5 participants 16 messages Jul 29, 2008 – Jul 30, 2008

Subsystems (3)
lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 mac80211: partially fix skb->cb use

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

---
This fixes wireless. At least it works on my WPA network, I haven't actually tested a broken kernel.

 drivers/net/wireless/ath5k/base.c           |    2 -
 drivers/net/wireless/b43/xmit.c             |    2 -
 drivers/net/wireless/b43legacy/xmit.c       |    2 -
 drivers/net/wireless/iwlwifi/iwl-tx.c       |    2 -
 drivers/net/wireless/iwlwifi/iwl3945-base.c |    2 -
 drivers/net/wireless/rt2x00/rt2x00mac.c     |    2 -
 include/linux/skbuff.h                      |    5 ++
 include/net/mac80211.h                      |    6 ---
 net/core/skbuff.c                           |    3 +
 net/mac80211/main.c                         |    8 ----
 net/mac80211/mlme.c                         |    8 +---
 net/mac80211/tx.c                           |   47 ++++++++++++----------------
 net/mac80211/wme.c                          |    3 +
 13 files changed, 40 insertions(+), 52 deletions(-)
include/net/mac80211.h +0 -6
@@ -206,8 +206,6 @@ struct ieee80211_bss_conf {
  * These flags are used with the @flags member of &ieee80211_tx_info.
  *
  * @IEEE80211_TX_CTL_REQ_TX_STATUS: request TX status callback for this frame.
- * @IEEE80211_TX_CTL_DO_NOT_ENCRYPT: send this frame without encryption;
- *	e.g., for EAPOL frame
  * @IEEE80211_TX_CTL_USE_RTS_CTS: use RTS-CTS before sending frame
  * @IEEE80211_TX_CTL_USE_CTS_PROTECT: use CTS protection for the frame (e.g.,
  *	for combined 802.11g / 802.11b networks)
@@ -220,7 +218,6 @@ struct ieee80211_bss_conf {
  * @IEEE80211_TX_CTL_SHORT_PREAMBLE: TBD
  * @IEEE80211_TX_CTL_LONG_RETRY_LIMIT: this frame should be send using the
  *	through set_retry_limit configured long retry value
- * @IEEE80211_TX_CTL_EAPOL_FRAME: internal to mac80211
  * @IEEE80211_TX_CTL_SEND_AFTER_DTIM: send this frame after DTIM beacon
  * @IEEE80211_TX_CTL_AMPDU: this frame should be sent as part of an A-MPDU
  * @IEEE80211_TX_CTL_OFDM_HT: this frame can be sent in HT OFDM rates. number
@@ -253,7 +250,6 @@ struct ieee80211_bss_conf {
  */
 enum mac80211_tx_control_flags {
 	IEEE80211_TX_CTL_REQ_TX_STATUS		= BIT(0),
-	IEEE80211_TX_CTL_DO_NOT_ENCRYPT		= BIT(1),
 	IEEE80211_TX_CTL_USE_RTS_CTS		= BIT(2),
 	IEEE80211_TX_CTL_USE_CTS_PROTECT	= BIT(3),
 	IEEE80211_TX_CTL_NO_ACK			= BIT(4),
@@ -263,7 +259,6 @@ enum mac80211_tx_control_flags {
 	IEEE80211_TX_CTL_FIRST_FRAGMENT		= BIT(8),
 	IEEE80211_TX_CTL_SHORT_PREAMBLE		= BIT(9),
 	IEEE80211_TX_CTL_LONG_RETRY_LIMIT	= BIT(10),
-	IEEE80211_TX_CTL_EAPOL_FRAME		= BIT(11),
 	IEEE80211_TX_CTL_SEND_AFTER_DTIM	= BIT(12),
 	IEEE80211_TX_CTL_AMPDU			= BIT(13),
 	IEEE80211_TX_CTL_OFDM_HT		= BIT(14),
@@ -323,7 +318,6 @@ struct ieee80211_tx_info {
 			struct ieee80211_vif *vif;
 			struct ieee80211_key_conf *hw_key;
 			unsigned long jiffies;
-			int ifindex;
 			u16 aid;
 			s8 rts_cts_rate_idx, alt_retry_rate_idx;
 			u8 retry_limit;
net/mac80211/tx.c +21 -26

142 lines not on this page · raw message

net/mac80211/mlme.c +2 -6
@@ -606,7 +606,6 @@ void ieee80211_sta_tx(struct net_device 
 		      int encrypt)
 {
 	struct ieee80211_sub_if_data *sdata;
-	struct ieee80211_tx_info *info;
 
 	sdata = IEEE80211_DEV_TO_SUB_IF(dev);
 	skb->dev = sdata->local->mdev;
@@ -614,11 +613,8 @@ void ieee80211_sta_tx(struct net_device 
 	skb_set_network_header(skb, 0);
 	skb_set_transport_header(skb, 0);
 
-	info = IEEE80211_SKB_CB(skb);
-	memset(info, 0, sizeof(struct ieee80211_tx_info));
-	info->control.ifindex = sdata->dev->ifindex;
-	if (!encrypt)
-		info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT;
+	skb->iif = sdata->dev->ifindex;
+	skb->do_not_encrypt = !encrypt;
 
 	dev_queue_xmit(skb);
 }
include/linux/skbuff.h +4 -1
@@ -316,7 +316,10 @@ struct sk_buff {
 #ifdef CONFIG_IPV6_NDISC_NODETYPE
 	__u8			ndisc_nodetype:2;
 #endif
-	/* 14 bit hole */
+#if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
+	__u8			do_not_encrypt:1;
+#endif
+	/* 0/13/14 bit hole */
 
 #ifdef CONFIG_NET_DMA
 	dma_cookie_t		dma_cookie;
net/core/skbuff.c +3 -0
@@ -485,6 +485,9 @@ static struct sk_buff *__skb_clone(struc
 	C(head);
 	C(data);
 	C(truesize);
+#if defined(CONFIG_MAC80211) || defined(CONFIG_MAC80211_MODULE)
+	C(do_not_encrypt);
+#endif
 	atomic_set(&n->users, 1);
 
 	atomic_inc(&(skb_shinfo(skb)->dataref));
net/mac80211/main.c +1 -7
@@ -1233,18 +1233,12 @@ static void ieee80211_tasklet_handler(un
 /* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
  * make a prepared TX frame (one that has been given to hw) to look like brand
  * new IEEE 802.11 frame that is ready to go through TX processing again.
- * Also, tx_packet_data in cb is restored from tx_control. */
+ */
 static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
 				      struct ieee80211_key *key,
 				      struct sk_buff *skb)
 {
 	int hdrlen, iv_len, mic_len;
-	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-
-	info->flags &=	IEEE80211_TX_CTL_REQ_TX_STATUS |
-			IEEE80211_TX_CTL_DO_NOT_ENCRYPT |
-			IEEE80211_TX_CTL_REQUEUE |
-			IEEE80211_TX_CTL_EAPOL_FRAME;
 
 	hdrlen = ieee80211_get_hdrlen_from_skb(skb);
 
drivers/net/wireless/ath5k/base.c +1 -1
@@ -1224,7 +1224,7 @@ ath5k_txbuf_setup(struct ath5k_softc *sc
 
 	pktlen = skb->len;
 
-	if (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT)) {
+	if (info->control.hw_key) {
 		keyidx = info->control.hw_key->hw_key_idx;
 		pktlen += info->control.icv_len;
 	}
drivers/net/wireless/b43/xmit.c +1 -1
@@ -192,7 +192,7 @@ int b43_generate_txhdr(struct b43_wldev 
 	const struct b43_phy *phy = &dev->phy;
 	const struct ieee80211_hdr *wlhdr =
 	    (const struct ieee80211_hdr *)fragment_data;
-	int use_encryption = (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT));
+	int use_encryption = !!info->control.hw_key;
 	__le16 fctl = wlhdr->frame_control;
 	struct ieee80211_rate *fbrate;
 	u8 rate, rate_fb;
drivers/net/wireless/b43legacy/xmit.c +1 -1
@@ -192,7 +192,7 @@ static int generate_txhdr_fw3(struct b43
 			       u16 cookie)
 {
 	const struct ieee80211_hdr *wlhdr;
-	int use_encryption = (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT));
+	int use_encryption = !!info->control.hw_key;
 	u16 fctl;
 	u8 rate;
 	struct ieee80211_rate *rate_fb;
drivers/net/wireless/iwlwifi/iwl-tx.c +1 -1
@@ -906,7 +906,7 @@ int iwl_tx_skb(struct iwl_priv *priv, st
 	 * first entry */
 	iwl_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
 
-	if (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT))
+	if (info->control.hw_key)
 		iwl_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb, sta_id);
 
 	/* Set up TFD's 2nd entry to point directly to remainder of skb,
drivers/net/wireless/iwlwifi/iwl3945-base.c +1 -1
@@ -2667,7 +2667,7 @@ static int iwl3945_tx_skb(struct iwl3945
 	 * first entry */
 	iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
 
-	if (!(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT))
+	if (info->control.hw_key)
 		iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
 
 	/* Set up TFD's 2nd entry to point directly to remainder of skb,
drivers/net/wireless/rt2x00/rt2x00mac.c +1 -1
@@ -63,7 +63,7 @@ static int rt2x00mac_tx_rts_cts(struct r
 	 */
 	memcpy(skb->cb, frag_skb->cb, sizeof(skb->cb));
 	rts_info = IEEE80211_SKB_CB(skb);
-	rts_info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT;
+	rts_info->control.hw_key = NULL;
 	rts_info->flags &= ~IEEE80211_TX_CTL_USE_RTS_CTS;
 	rts_info->flags &= ~IEEE80211_TX_CTL_USE_CTS_PROTECT;
 	rts_info->flags &= ~IEEE80211_TX_CTL_REQ_TX_STATUS;
net/mac80211/wme.c +3 -0
@@ -188,6 +188,9 @@ int ieee80211_ht_agg_queue_add(struct ie
 {
 	int i;
 
+	/* XXX: currently broken due to cb/requeue use */
+	return -EPERM;
+
 	/* prepare the filter and save it for the SW queue
 	 * matching the received HW queue */
 
maintainer
#1 lore raw

From: Johannes Berg <[email protected]>
Date: Tue, 29 Jul 2008 11:32:07 +0200

Quoted 11 lines

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

---
This fixes wireless. At least it works on my WPA network, I haven't actually tested a broken kernel.

This looks mostly fine to me.

I'd like to see some success reports from folks having trouble currently.

#2 lore raw
In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

What about about ieee80211_get_rate(hw, const struct ieee80211_tx_info *c). It's used in tx path in the drivers and info is fetched from cb

Tomas

author maintainer
#3 lore raw
Quoted 11 lines · Tomas Winkler
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

What about about ieee80211_get_rate(hw, const struct ieee80211_tx_info *c). It's used in tx path in the drivers and info is fetched from cb

So what about it? mac80211 builds the info in skb->cb just fine before it passes the frame to the driver.

johannes

#4 lore raw
Quoted 10 lines · Johannes Berg
Quoted 9 lines · Tomas Winkler
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

Quoted 5 lines
Quoted 2 lines

What about about ieee80211_get_rate(hw, const struct ieee80211_tx_info *c). It's used in tx path in the drivers and info is fetched from cb

So what about it? mac80211 builds the info in skb->cb just fine before it passes the frame to the driver.

Sorry my mistake. This is built after the packet get to master xmit Tomas

#5 lore raw
In reply to Johannes Berg
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

On net/mac80211/rx.c:ieee80211_data_to_8023() cb is used for mesh frames to save the original mesh header. Then if the frame has to be forwarded, the frame is queued on the virtual interface and net/mac80211/tx.c:ieee80211_subif_start_xmit() expects the mesh header to remain in the cb if the frame is not originally from the local host. It's a different step from the one you mention, but as I understand it it may suffer the same problem right?

Signature · 2 lines
Luis Carlos Cobo Rus       GnuPG ID: 44019B60
cozybit Inc.
author maintainer
#6 lore raw
Quoted 8 lines · Luis Carlos Cobo
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

Quoted 7 lines

On net/mac80211/rx.c:ieee80211_data_to_8023() cb is used for mesh frames to save the original mesh header. Then if the frame has to be forwarded, the frame is queued on the virtual interface and net/mac80211/tx.c:ieee80211_subif_start_xmit() expects the mesh header to remain in the cb if the frame is not originally from the local host. It's a different step from the one you mention, but as I understand it it may suffer the same problem right?

Indeed, that cannot be done. Good point, I'd thought that case was different.

johannes

#7 lore raw
Quoted 17 lines · Johannes Berg
Quoted 8 lines · Luis Carlos Cobo
Quoted 6 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

Quoted 7 lines

On net/mac80211/rx.c:ieee80211_data_to_8023() cb is used for mesh frames to save the original mesh header. Then if the frame has to be forwarded, the frame is queued on the virtual interface and net/mac80211/tx.c:ieee80211_subif_start_xmit() expects the mesh header to remain in the cb if the frame is not originally from the local host. It's a different step from the one you mention, but as I understand it it may suffer the same problem right?

Quoted 2 lines

Indeed, that cannot be done. Good point, I'd thought that case was different.

One of the options I was thinking about when implemented that was to do the forwarding in what was once equivalent to ieee80211_data_to_8023() function. Then we do not have to do 802.11->802.3->802.11 series of conversions, and we would send the frames to be forwarded directly to the master device, speeding up things a bit.

I think the most elegant solution would be to add a rx handler to be run before ieee80211_data_to_8023() dealing with forwarding and sending frames directly to the master device. Would it make sense to deal there too with the forwarding for APs and VLAN interfaces done in ieee80211_deliver_skb?

Signature · 2 lines
Luis Carlos Cobo Rus       GnuPG ID: 44019B60
cozybit Inc.
author maintainer
#8 lore raw
Quoted 5 lines · Luis Carlos Cobo

One of the options I was thinking about when implemented that was to do the forwarding in what was once equivalent to ieee80211_data_to_8023() function. Then we do not have to do 802.11->802.3->802.11 series of conversions, and we would send the frames to be forwarded directly to the master device, speeding up things a bit.

That sounds sane to me, then you don't need the cb at all, do you? Can just send it to the master dev with skb->do_not_encrypt set, right?

In fact, looking at the code, there seems to be a bug with promisc, are you sure it's allowed to netif_rx/dev_queue_xmit the same frame?

Quoted 3 lines

I think the most elegant solution would be to add a rx handler to be run before ieee80211_data_to_8023() dealing with forwarding and sending frames directly to the master device.

That sounds reasonable.

Quoted 3 lines

Would it make sense to deal there
too with the forwarding for APs and VLAN interfaces done in ieee80211_deliver_skb?

I don't think so. AP mode doesn't really forward MPDUs but MSDUs, which should make a difference when encryption is enabled.

johannes

#9 lore raw
Quoted 2 lines · Johannes Berg

That sounds sane to me, then you don't need the cb at all, do you? Can just send it to the master dev with skb->do_not_encrypt set, right?

Right.

Quoted 2 lines

In fact, looking at the code, there seems to be a bug with promisc, are you sure it's allowed to netif_rx/dev_queue_xmit the same frame?

I see, not doing a copy on that case. Yeah, that needs to be fixed, I'll take care of it.

Signature · 2 lines
Luis Carlos Cobo Rus       GnuPG ID: 44019B60
cozybit Inc.
author maintainer
#10 lore raw
Quoted 5 lines · Luis Carlos Cobo
Quoted 2 lines · Johannes Berg

That sounds sane to me, then you don't need the cb at all, do you? Can just send it to the master dev with skb->do_not_encrypt set, right?

Right.

Ok. How is that supposed to work with crypto? Do each two peers negotiate a key and forwarding just doesn't change anything so crypto is effectively end-to-end?

Quoted 5 lines
Quoted 2 lines

In fact, looking at the code, there seems to be a bug with promisc, are you sure it's allowed to netif_rx/dev_queue_xmit the same frame?

I see, not doing a copy on that case. Yeah, that needs to be fixed, I'll take care of it.

Thanks.

johannes

#13 lore raw
In reply to Johannes Berg
Quoted 11 lines · Johannes Berg

This patch fixes mac80211 to not use the skb->cb over the queue step from virtual interfaces to the master. The patch also, for now, disables aggregation because that would still require requeuing, will fix that in a separate patch. There are two other places (software requeue and powersaving stations) where requeue can happen, but that is not currently used by any drivers/not possible to use respectively.

---
This fixes wireless. At least it works on my WPA network, I haven't actually tested a broken kernel.

This patch fixes my broken 2.6.27-rc1 kernel using b43, which had not worked since the new networking stuff was merged.

I'm pretty discouraged that a change that has such an impact on wireless never made it to wireless-testing, where this kind of defect should have been found and fixed long before it ever got into mainline.

Larry

author maintainer
#14 lore raw
Quoted 6 lines
Quoted 3 lines

This fixes wireless. At least it works on my WPA network, I haven't actually tested a broken kernel.

This patch fixes my broken 2.6.27-rc1 kernel using b43, which had not worked since the new networking stuff was merged.

Thanks for the heads-up.

Quoted 3 lines

I'm pretty discouraged that a change that has such an impact on wireless never made it to wireless-testing, where this kind of defect should have been found and fixed long before it ever got into mainline.

I had tested earlier versions of davem's patches, and those worked fine. and I guess that since he was not aware that mac80211 had always been using skb->cb in illegal ways, he couldn't realise how it would break wireless.

johannes

#11 lore raw
In reply to Johannes Berg
Quoted 3 lines · Johannes Berg

Ok. How is that supposed to work with crypto? Do each two peers negotiate a key and forwarding just doesn't change anything so crypto is effectively end-to-end?

Actually not, crypto is per link (per hop). We don't have a schedule to support that but anyway, where do you suggest to save the mesh header in this case?

Signature · 2 lines
Luis Carlos Cobo Rus       GnuPG ID: 44019B60
cozybit Inc.
maintainer
#15 lore raw
In reply to Larry Finger

From: Larry Finger <[email protected]>
Date: Tue, 29 Jul 2008 09:47:00 -0500

Quoted 3 lines

I'm pretty discouraged that a change that has such an impact on wireless never made it to wireless-testing, where this kind of defect should have been found and fixed long before it ever got into mainline.

Considering the fact that all of the wireless folks were having their wireless summit in Ottawa when all of this was going on, I highly doubt it would have made one ounce of difference.

That's the only reason this took so long to resolve.

author maintainer
#12 lore raw
In reply to Luis Carlos Cobo
Quoted 8 lines · Luis Carlos Cobo
Quoted 3 lines · Johannes Berg

Ok. How is that supposed to work with crypto? Do each two peers negotiate a key and forwarding just doesn't change anything so crypto is effectively end-to-end?

Actually not, crypto is per link (per hop). We don't have a schedule to support that but anyway, where do you suggest to save the mesh header in this case?

Can we just retransmit the frame directly to the master interface, with all that still intact?

johannes