Skip to contentSkip to conversation

net: introduce skb_network_header_was_set()

PATCH In review Cong Wang 6 participants 11 messages Nov 21, 2018 – Jan 11, 2019

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/2 net: introduce skb_network_header_was_set()

---
 include/linux/skbuff.h | 5 +++++
 net/core/skbuff.c      | 2 ++
 2 files changed, 7 insertions(+)
include/linux/skbuff.h +5 -0
index a2e8297a5b00..afddb5c17ce5 100644
@@ -2444,6 +2444,11 @@ static inline u32 skb_network_header_len(const struct sk_buff *skb)
 	return skb->transport_header - skb->network_header;
 }
 
+static inline int skb_network_header_was_set(const struct sk_buff *skb)
+{
+	return skb->network_header != (typeof(skb->network_header))~0U;
+}
+
 static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
 {
 	return skb->inner_transport_header - skb->inner_network_header;
net/core/skbuff.c +2 -0
index 9a8a72cefe9b..b6ba923e7dc7 100644
@@ -227,6 +227,7 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
 	skb_reset_tail_pointer(skb);
 	skb->end = skb->tail + size;
 	skb->mac_header = (typeof(skb->mac_header))~0U;
+	skb->network_header = (typeof(skb->network_header))~0U;
 	skb->transport_header = (typeof(skb->transport_header))~0U;
 
 	/* make sure we initialize shinfo sequentially */
@@ -292,6 +293,7 @@ struct sk_buff *__build_skb(void *data, unsigned int frag_size)
 	skb_reset_tail_pointer(skb);
 	skb->end = skb->tail + size;
 	skb->mac_header = (typeof(skb->mac_header))~0U;
+	skb->network_header = (typeof(skb->network_header))~0U;
 	skb->transport_header = (typeof(skb->transport_header))~0U;
 
 	/* make sure we initialize shinfo sequentially */
Signature · 1 line
2.19.1
author
#1 lore raw

PATCH 2/2 net: dump whole skb data in netdev_rx_csum_fault()

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum fault. This patch introduces skb_dump() which dumps skb mac header, network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>
---
 include/linux/skbuff.h |  5 +++++
 net/core/dev.c         |  6 +-----
 net/core/skbuff.c      | 49 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 5 deletions(-)
include/linux/skbuff.h +5 -0
index afddb5c17ce5..844c0a7ff52f 100644
@@ -4218,5 +4218,10 @@ static inline __wsum lco_csum(struct sk_buff *skb)
 	return csum_partial(l4_hdr, csum_start - l4_hdr, partial);
 }
 
+#ifdef CONFIG_BUG
+void skb_dump(const char *level, const struct sk_buff *skb, bool dump_header,
+	      bool dump_mac_header, bool dump_network_header);
+#endif
+
 #endif	/* __KERNEL__ */
 #endif	/* _LINUX_SKBUFF_H */
net/core/dev.c +1 -5
index f2bfd2eda7b2..dc54c89fb4b1 100644
@@ -3097,11 +3097,7 @@ void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb)
 		pr_err("%s: hw csum failure\n", dev ? dev->name : "<unknown>");
 		if (dev)
 			pr_err("dev features: %pNF\n", &dev->features);
-		pr_err("skb len=%u data_len=%u pkt_type=%u gso_size=%u gso_type=%u nr_frags=%u ip_summed=%u csum=%x csum_complete_sw=%d csum_valid=%d csum_level=%u\n",
-		       skb->len, skb->data_len, skb->pkt_type,
-		       skb_shinfo(skb)->gso_size, skb_shinfo(skb)->gso_type,
-		       skb_shinfo(skb)->nr_frags, skb->ip_summed, skb->csum,
-		       skb->csum_complete_sw, skb->csum_valid, skb->csum_level);
+		skb_dump(KERN_ERR, skb, true, true, true);
 		dump_stack();
 	}
 }
net/core/skbuff.c +49 -0

52 lines not on this page · raw message

Signature · 1 line
2.19.1
#2 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 12 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum fault. This patch introduces skb_dump() which dumps skb mac header, network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---

net/core/skbuff.c void skb_condense(struct sk_buff *skb) · line 5584

Quoted 2 lines
net/core/skbuff.c +2 -0
+	print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET, 16, 1,
+		       skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe already pulled

(skb->head starting point, not skb->data)

Also we will miss the trimmed bytes if there were padding data.

And it seems the various bugs we have are all tied to the pulled or trimmed bytes.

Thanks.

author
#3 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 16 lines · Eric Dumazet
Quoted 10 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum fault. This patch introduces skb_dump() which dumps skb mac header, network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---

Quoted 6 lines

net/core/skbuff.c void skb_condense(struct sk_buff *skb) · line 5584

Quoted 2 lines
net/core/skbuff.c +2 -0
+     print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET, 16, 1,
+                    skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe already pulled

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no? Is there anything between skb->head and mac header?

Quoted 4 lines

Also we will miss the trimmed bytes if there were padding data.
And it seems the various bugs we have are all tied to the pulled or trimmed bytes.

Unless I miss something, the tailing padding data should be in range [iphdr->tot_len, skb->len]. No?

Thanks

#4 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 21 lines · Cong Wang
Quoted 19 lines · Eric Dumazet
Quoted 14 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum fault. This patch introduces skb_dump() which dumps skb mac header, network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---

net/core/skbuff.c +2 -0
+     print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET, 16, 1,
+                    skb->data, skb->len, false);
Quoted 6 lines
Quoted 3 lines

As I mentioned to David, we want all the bytes that were maybe already pulled

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no? Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE value.

Quoted 8 lines
Quoted 5 lines

Also we will miss the trimmed bytes if there were padding data.
And it seems the various bugs we have are all tied to the pulled or trimmed bytes.

Unless I miss something, the tailing padding data should be in range [iphdr->tot_len, skb->len]. No?

Not after we did the pskb_trim_rcsum() call, since it has effectively reduced skb->len by the number of padding bytes.

#5 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 28 lines · Eric Dumazet
Quoted 26 lines · Cong Wang
Quoted 23 lines · Eric Dumazet
Quoted 7 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum
fault. This patch introduces skb_dump() which dumps skb mac header,
network header and its whole skb->data too.

Quoted 8 lines
Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---
+ print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET,
16, 1,
+ skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe already pulled

(skb->head starting point, not skb->data)

Quoted 9 lines
Quoted 3 lines

Hmm, with mac header and network header, it is effectively from skb->head, no?
Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE value.

Normally the driver keeps some headroom @skb->head, so the actual mac header starts @ skb->head + driver_specific_headroom

for example in mlx5 we do:
va = page_addr + offset
build_skb(va)
/* skb->data = va + headroom */
skb_reserve(mlx5_headroom)

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Also we will miss the trimmed bytes if there were padding data. And it seems the various bugs we have are all tied to the pulled or trimmed bytes.

Unless I miss something, the tailing padding data should be in range
[iphdr->tot_len, skb->len]. No?

Not after we did the pskb_trim_rcsum() call, since it has effectively reduced skb->len by the number of padding bytes.

author
#6 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 34 lines · Saeed Mahameed
Quoted 32 lines · Eric Dumazet
Quoted 29 lines · Cong Wang
Quoted 19 lines · Eric Dumazet
Quoted 7 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum
fault. This patch introduces skb_dump() which dumps skb mac header,
network header and its whole skb->data too.

Quoted 8 lines
Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---
+ print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET,
16, 1,
+ skb->data, skb->len, false);

Quoted 4 lines

As I mentioned to David, we want all the bytes that were maybe already pulled

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no?
Is there anything between skb->head and mac header?

Quoted 8 lines
Quoted 5 lines

Oh, I guess we wanted a single hex dump, or we need some user program to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE value.

Normally the driver keeps some headroom @skb->head, so the actual mac header starts @ skb->head + driver_specific_headroom

Good to know, but this headroom isn't covered by skb->csum, so not useful here, right? The skb->csum for mlx5 only covers network header and its payload.

#7 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 45 lines · Cong Wang
Quoted 43 lines · Saeed Mahameed
Quoted 41 lines · Eric Dumazet
Quoted 25 lines · Cong Wang
Quoted 23 lines · Eric Dumazet
Quoted 11 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum
fault. This patch introduces skb_dump() which dumps skb mac header,
network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>
Quoted 5 lines

---
+ print_hex_dump(level, "skb data: ",
DUMP_PREFIX_OFFSET,
16, 1,
+ skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe
already pulled

Quoted 5 lines
Quoted 1 line

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no?
Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program
to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE
value.

Quoted 7 lines
Quoted 3 lines

Normally the driver keeps some headroom @skb->head, so the actual mac
header starts @ skb->head + driver_specific_headroom

Good to know, but this headroom isn't covered by skb->csum, so not useful here, right? The skb->csum for mlx5 only covers network header and its payload.

correct

#8 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

FWIW, I find the patch really useful - I applied it to my local dev repo (with minor changes) and use skb_dump() a lot now. It would be great if it makes its way into net-next in some form.

Quoted 57 lines · Saeed Mahameed
Quoted 45 lines · Cong Wang
Quoted 43 lines · Saeed Mahameed
Quoted 41 lines · Eric Dumazet
Quoted 25 lines · Cong Wang
Quoted 23 lines · Eric Dumazet
Quoted 11 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum
fault. This patch introduces skb_dump() which dumps skb mac header,
network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>
Quoted 5 lines

---
+ print_hex_dump(level, "skb data: ",
DUMP_PREFIX_OFFSET,
16, 1,
+ skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe
already pulled

Quoted 5 lines
Quoted 1 line

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no?
Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program
to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE
value.

Quoted 7 lines
Quoted 3 lines

Normally the driver keeps some headroom @skb->head, so the actual mac
header starts @ skb->head + driver_specific_headroom

Good to know, but this headroom isn't covered by skb->csum, so not useful here, right? The skb->csum for mlx5 only covers network header and its payload.

correct

#9 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

Quoted 4 lines · Peter Oskolkov

FWIW, I find the patch really useful - I applied it to my local dev repo (with minor changes) and use skb_dump() a lot now. It would be great if it makes its way into net-next in some form.

+1 very informative.

skb_warn_bad_offload would also benefit from more packet detail.

And please consider logging device info, too. I'm currently debugging a (non-reproducible so far, so relying purely on the log message) stack trace for a packet that triggers that warning in validate_xmit_skb on the path to an unknown virtual device.

Quoted 58 lines · Saeed Mahameed
Quoted 57 lines · Cong Wang
Quoted 45 lines
Quoted 43 lines · Saeed Mahameed
Quoted 41 lines · Eric Dumazet
Quoted 25 lines · Cong Wang
Quoted 23 lines · Eric Dumazet
Quoted 11 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum
fault. This patch introduces skb_dump() which dumps skb mac header,
network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>
Quoted 5 lines

---
+ print_hex_dump(level, "skb data: ",
DUMP_PREFIX_OFFSET,
16, 1,
+ skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe
already pulled

Quoted 5 lines
Quoted 1 line

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no?
Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program
to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE
value.

Quoted 7 lines
Quoted 3 lines

Normally the driver keeps some headroom @skb->head, so the actual mac
header starts @ skb->head + driver_specific_headroom

Good to know, but this headroom isn't covered by skb->csum, so not useful here, right? The skb->csum for mlx5 only covers network header and its payload.

correct

author
#10 lore raw

Re: [Patch net-next 2/2] net: dump whole skb data in netdev_rx_csum_fault()

In reply to Eric Dumazet
Quoted 25 lines · Eric Dumazet
Quoted 23 lines · Cong Wang
Quoted 21 lines · Eric Dumazet
Quoted 12 lines · Cong Wang

Currently, we only dump a few selected skb fields in netdev_rx_csum_fault(). It is not suffient for debugging checksum fault. This patch introduces skb_dump() which dumps skb mac header, network header and its whole skb->data too.

Cc Herbert Xu <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc David Miller <[email protected]>

---

net/core/skbuff.c void skb_condense(struct sk_buff *skb) · line 5584

Quoted 2 lines
net/core/skbuff.c +2 -0
+     print_hex_dump(level, "skb data: ", DUMP_PREFIX_OFFSET, 16, 1,
+                    skb->data, skb->len, false);

As I mentioned to David, we want all the bytes that were maybe already pulled

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

(skb->head starting point, not skb->data)

Hmm, with mac header and network header, it is effectively from skb->head, no? Is there anything between skb->head and mac header?

Oh, I guess we wanted a single hex dump, or we need some user program to be able to
rebuild from different memory zones the original CHECKSUM_COMPLETE value.

Yeah, I can remove the prefix and dump the complete packet as one single block. This means I also need to check where skb->data points to.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Also we will miss the trimmed bytes if there were padding data.
And it seems the various bugs we have are all tied to the pulled or trimmed bytes.

Quoted 6 lines
Quoted 2 lines

Unless I miss something, the tailing padding data should be in range [iphdr->tot_len, skb->len]. No?

Not after we did the pskb_trim_rcsum() call, since it has effectively reduced skb->len by the number of padding bytes.

Sure, this patch can't change where netdev_rx_csum_fault() gets called. We either need to move the checksum validation earlier, or move the trimming later, none of them belongs to this patch.

Thanks.