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