Skip to contentSkip to conversation

solos-pci: Increase headroom on received packets

PATCH Superseded David Woodhouse 3 participants 6 messages Sep 16, 2015 – Sep 18, 2015

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

PATCH 1/1 solos-pci: Increase headroom on received packets

A comment in include/linux/skbuff.h says that:

* Various parts of the networking layer expect at least 32 bytes of
* headroom, you should not reduce this.

This was demonstrated by a panic when handling fragmented IPv6 packets:
http://marc.info/?l=linux-netdev&m=144236093519172&w=2

It's not entirely clear if that comment is still valid — and if it is, perhaps netif_rx() ought to be enforcing it with a warning.

But either way, it is rather stupid from a performance point of view for us to be receiving packets into a buffer which doesn't have enough room to prepend an Ethernet header — it means that *every* incoming packet is going to be need to be reallocated. So let's fix that.

---
Tested in the DMA code path; I don't believe the DMA-capable devices can still be used in MMIO mode. Simon, Guy, would you be able to test the MMIO version?

drivers/atm/solos-pci.c +5 -3
index 74e18b0..be8225e 100644
@@ -805,13 +805,13 @@ static void solos_bh(unsigned long card_arg)
 					continue;
 				}
 
-				skb = alloc_skb(size + 1, GFP_ATOMIC);
+				skb = alloc_skb(size + NET_SKB_PAD + 1, GFP_ATOMIC);
 				if (!skb) {
 					if (net_ratelimit())
 						dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
 					continue;
 				}
-
+				skb_reserve(skb, NET_SKB_PAD);
 				memcpy_fromio(skb_put(skb, size),
 					      RX_BUF(card, port) + sizeof(*header),
 					      size);
@@ -869,8 +869,10 @@ static void solos_bh(unsigned long card_arg)
 		/* Allocate RX skbs for any ports which need them */
 		if (card->using_dma && card->atmdev[port] &&
 		    !card->rx_skb[port]) {
-			struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
+			struct sk_buff *skb = alloc_skb(RX_DMA_SIZE + NET_SKB_PAD,
+							GFP_ATOMIC);
 			if (skb) {
+				skb_reserve(skb, NET_SKB_PAD);
 				SKB_CB(skb)->dma_addr =
 					dma_map_single(&card->dev->dev, skb->data,
 						       RX_DMA_SIZE, DMA_FROM_DEVICE);
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#1 lore raw
Quoted 16 lines · David Woodhouse

A comment in include/linux/skbuff.h says that:

* Various parts of the networking layer expect at least 32 bytes of
* headroom, you should not reduce this.

This was demonstrated by a panic when handling fragmented IPv6 packets:
http://marc.info/?l=linux-netdev&m=144236093519172&w=2

It's not entirely clear if that comment is still valid — and if it is, perhaps netif_rx() ought to be enforcing it with a warning.

But either way, it is rather stupid from a performance point of view for us to be receiving packets into a buffer which doesn't have enough room to prepend an Ethernet header — it means that *every* incoming packet is going to be need to be reallocated. So let's fix that.

Quoted 5 lines

---
Tested in the DMA code path; I don't believe the DMA-capable devices can still be used in MMIO mode. Simon, Guy, would you be able to test the MMIO version?

You should use netdev_alloc_skb() : This helper is better for rx skbs, as it allows for better packing of frames in GRO or TCP stack.

Also netdev_alloc_skb_ip_align() might handle the NET_IP_ALIGN stuff for arches that care.

#2 lore raw
Quoted 2 lines · Eric Dumazet

You should use netdev_alloc_skb() : This helper is better for rx skbs, as it allows for better packing of frames in GRO or TCP stack.

OK, thanks. I don't have a netdev (this is an ATM device) but I can use dev_alloc_skb().

Quoted 2 lines

Also netdev_alloc_skb_ip_align() might handle the NET_IP_ALIGN stuff for arches that care.

I'd briefly considered NET_IP_ALIGN but decided against it because this isn't Ethernet and my hardware header is a nice sane 8 bytes, not 14.

But actually, the primary use cases for this are PPPoATM — with 2 bytes of PPP frame type, and PPPoE over BR2684 — with 14 bytes of Ethernet header. So NET_IP_ALIGN would actually make sense.

Unfortunately the FPGA can't do DMA to unaligned addresses, so I can't do it in the DMA case. I can do it for the MMIO code path though (which I still haven't tested).

I'll send a new patch in a moment...

Signature · 1 line
dwmw2
#3 lore raw

PATCH v2 1/1 solos-pci: Increase headroom on received packets

In reply to Eric Dumazet

A comment in include/linux/skbuff.h says that:

* Various parts of the networking layer expect at least 32 bytes of
* headroom, you should not reduce this.

This was demonstrated by a panic when handling fragmented IPv6 packets:
http://marc.info/?l=linux-netdev&m=144236093519172&w=2

It's not entirely clear if that comment is still valid — and if it is, perhaps netif_rx() ought to be enforcing it with a warning.

But either way, it is rather stupid from a performance point of view for us to be receiving packets into a buffer which doesn't have enough room to prepend an Ethernet header — it means that *every* incoming packet is going to be need to be reallocated. So let's fix that.

---

drivers/atm/solos-pci.c +10 -2
index 74e18b0..3d7fb65 100644
@@ -805,7 +805,12 @@ static void solos_bh(unsigned long card_arg)
 					continue;
 				}
 
-				skb = alloc_skb(size + 1, GFP_ATOMIC);
+				/* Use netdev_alloc_skb() because it adds NET_SKB_PAD of
+				 * headroom, and ensures we can route packets back out an
+				 * Ethernet interface (for example) without having to
+				 * reallocate. Adding NET_IP_ALIGN also ensures that both
+				 * PPPoATM and PPPoEoBR2684 packets end up aligned. */
+				skb = netdev_alloc_skb_ip_align(NULL, size + 1);
 				if (!skb) {
 					if (net_ratelimit())
 						dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
@@ -869,7 +874,10 @@ static void solos_bh(unsigned long card_arg)
 		/* Allocate RX skbs for any ports which need them */
 		if (card->using_dma && card->atmdev[port] &&
 		    !card->rx_skb[port]) {
-			struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
+			/* Unlike the MMIO case (qv) we can't add NET_IP_ALIGN
+			 * here; the FPGA can only DMA to addresses which are
+			 * aligned to 4 bytes. */
+			struct sk_buff *skb = dev_alloc_skb(RX_DMA_SIZE);
 			if (skb) {
 				SKB_CB(skb)->dma_addr =
 					dma_map_single(&card->dev->dev, skb->data,
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
Acked-by on v2 1/1
#4 lore raw
Quoted 11 lines · David Woodhouse

A comment in include/linux/skbuff.h says that:

* Various parts of the networking layer expect at least 32 bytes of
* headroom, you should not reduce this.

This was demonstrated by a panic when handling fragmented IPv6 packets:
http://marc.info/?l=linux-netdev&m=144236093519172&w=2

It's not entirely clear if that comment is still valid — and if it is, perhaps netif_rx() ought to be enforcing it with a warning.

Quoted 7 lines

But either way, it is rather stupid from a performance point of view for us to be receiving packets into a buffer which doesn't have enough room to prepend an Ethernet header — it means that *every* incoming packet is going to be need to be reallocated. So let's fix that.

---

LGTM

maintainer Applied
#5 lore raw
In reply to David Woodhouse

From: David Woodhouse <[email protected]>
Date: Wed, 16 Sep 2015 12:35:00 +0100

Quoted 11 lines

A comment in include/linux/skbuff.h says that:

* Various parts of the networking layer expect at least 32 bytes of
* headroom, you should not reduce this.

This was demonstrated by a panic when handling fragmented IPv6 packets:
http://marc.info/?l=linux-netdev&m=144236093519172&w=2

It's not entirely clear if that comment is still valid ― and if it is, perhaps netif_rx() ought to be enforcing it with a warning.

Quoted 6 lines

But either way, it is rather stupid from a performance point of view for us to be receiving packets into a buffer which doesn't have enough room to prepend an Ethernet header ― it means that *every* incoming packet is going to be need to be reallocated. So let's fix that.

Applied, thanks David.