sharkcz / rpms / kernel

Forked from rpms/kernel 6 years ago
Clone
9006cf8
From: Eric Dumazet <edumazet@google.com>
9006cf8
9006cf8
Steinar reported reallocations of skb->head with IPv6, leading to
9006cf8
a warning in skb_try_coalesce()
9006cf8
9006cf8
It turns out iwl3945 has several problems :
9006cf8
9006cf8
1) skb->truesize is underestimated. 
9006cf8
   We really consume PAGE_SIZE bytes for a fragment,
9006cf8
   not the frame length.
9006cf8
2) 128 bytes of initial headroom is a bit low and forces reallocations.
9006cf8
3) We can avoid consuming a full page for small enough frames.
9006cf8
9006cf8
Reported-by: Steinar H. Gunderson <sesse@google.com>
9006cf8
Signed-off-by: Eric Dumazet <edumazet@google.com>
9006cf8
Cc: Paul Stewart <pstew@google.com>
9006cf8
---
9006cf8
v3: use regular memcpy(skb_put(...),...)
9006cf8
v2: SMALL_PACKET_SIZE define
9006cf8
9006cf8
 drivers/net/wireless/iwlegacy/3945.c |   31 +++++++++++++++----------
9006cf8
 1 file changed, 19 insertions(+), 12 deletions(-)
9006cf8
9006cf8
diff --git a/drivers/net/wireless/iwlegacy/3945.c b/drivers/net/wireless/iwlegacy/3945.c
9006cf8
index c092033..f09e257 100644
9006cf8
--- a/drivers/net/wireless/iwlegacy/3945.c
9006cf8
+++ b/drivers/net/wireless/iwlegacy/3945.c
9006cf8
@@ -475,6 +475,8 @@ il3945_is_network_packet(struct il_priv *il, struct ieee80211_hdr *header)
9006cf8
 	}
9006cf8
 }
9006cf8
 
9006cf8
+#define SMALL_PACKET_SIZE 256
9006cf8
+
9006cf8
 static void
9006cf8
 il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
9006cf8
 			       struct ieee80211_rx_status *stats)
9006cf8
@@ -483,14 +485,13 @@ il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
9006cf8
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
9006cf8
 	struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
9006cf8
 	struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
9006cf8
-	u16 len = le16_to_cpu(rx_hdr->len);
9006cf8
+	u32 len = le16_to_cpu(rx_hdr->len);
9006cf8
 	struct sk_buff *skb;
9006cf8
 	__le16 fc = hdr->frame_control;
9006cf8
+	u32 fraglen = PAGE_SIZE << il->hw_params.rx_page_order;
9006cf8
 
9006cf8
 	/* We received data from the HW, so stop the watchdog */
9006cf8
-	if (unlikely
9006cf8
-	    (len + IL39_RX_FRAME_SIZE >
9006cf8
-	     PAGE_SIZE << il->hw_params.rx_page_order)) {
9006cf8
+	if (unlikely(len + IL39_RX_FRAME_SIZE > fraglen)) {
9006cf8
 		D_DROP("Corruption detected!\n");
9006cf8
 		return;
9006cf8
 	}
9006cf8
@@ -506,26 +507,32 @@ il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
9006cf8
 		D_INFO("Woke queues - frame received on passive channel\n");
9006cf8
 	}
9006cf8
 
9006cf8
-	skb = dev_alloc_skb(128);
9006cf8
+	skb = dev_alloc_skb(SMALL_PACKET_SIZE);
9006cf8
 	if (!skb) {
9006cf8
 		IL_ERR("dev_alloc_skb failed\n");
9006cf8
 		return;
9006cf8
 	}
9006cf8
 
9006cf8
 	if (!il3945_mod_params.sw_crypto)
9006cf8
-		il_set_decrypted_flag(il, (struct ieee80211_hdr *)rxb_addr(rxb),
9006cf8
+		il_set_decrypted_flag(il, (struct ieee80211_hdr *)pkt,
9006cf8
 				      le32_to_cpu(rx_end->status), stats);
9006cf8
 
9006cf8
-	skb_add_rx_frag(skb, 0, rxb->page,
9006cf8
-			(void *)rx_hdr->payload - (void *)pkt, len,
9006cf8
-			len);
9006cf8
-
9006cf8
+	/* If frame is small enough to fit into skb->head, copy it
9006cf8
+	 * and do not consume a full page
9006cf8
+	 */
9006cf8
+	if (len <= SMALL_PACKET_SIZE) {
9006cf8
+		memcpy(skb_put(skb, len), rx_hdr->payload, len);
9006cf8
+	} else {
9006cf8
+		skb_add_rx_frag(skb, 0, rxb->page,
9006cf8
+				(void *)rx_hdr->payload - (void *)pkt, len,
9006cf8
+				fraglen);
9006cf8
+		il->alloc_rxb_page--;
9006cf8
+		rxb->page = NULL;
9006cf8
+	}
9006cf8
 	il_update_stats(il, false, fc, len);
9006cf8
 	memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
9006cf8
 
9006cf8
 	ieee80211_rx(il->hw, skb);
9006cf8
-	il->alloc_rxb_page--;
9006cf8
-	rxb->page = NULL;
9006cf8
 }
9006cf8
 
9006cf8
 #define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
9006cf8
9006cf8