virtio_net GSO/partial csum fixes
Subsystems (4)
cover virtio_net GSO/partial csum fixes
Hi Rusty,
Here's a few virtio_net fixes related to partial csums
and GSO. These come about from playing with the tun/tap based GSO patches you and Herbert posted earlier.
3/3 is the signifcant one - I didn't actually reproduce
the problem with virtio_net, but rather observed it with the tun/tap patch. In that case, packets which were sent by the guest with a partial csum were ending up with an incorrect csum when they were forwarded to a physical network.
Cheers,
Mark.
PATCH 1/3 virtio: Fix typo in virtio_net_hdr comments
--- include/linux/virtio_net.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/virtio_net.h +1 -1
@@ -38,7 +38,7 @@ struct virtio_net_hdr#define VIRTIO_NET_HDR_GSO_ECN 0x80 // TCP has ECN set__u8 gso_type;__u16 hdr_len;/* Ethernet + IP + tcp/udp hdrs */ -__u16 gso_size;/* Bytes to append to gso_hdr_len per frame */ +__u16 gso_size;/* Bytes to append to hdr_len per frame */ __u16 csum_start;/* Position to start checksumming from */ __u16 csum_offset;/* Offset after that to place checksum */ };
Signature · 1 line
1.5.4.1
PATCH 2/3 virtio_net: Trivial coding style fix
--- drivers/net/virtio_net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/virtio_net.c +1 -1
@@ -94,7 +94,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,if (hdr->flags &VIRTIO_NET_HDR_F_NEEDS_CSUM ) {pr_debug ("Needs csum!\n" ); -if (!skb_partial_csum_set (skb,hdr->csum_start,hdr->csum_offset)) +if (!skb_partial_csum_set (skb, hdr->csum_start, hdr->csum_offset)) goto frame_err; }
Signature · 1 line
1.5.4.1
PATCH 3/3 virtio_net: Fix skb->csum_start computation
hdr->csum_start is the offset from the start of the ethernet header to the transport layer checksum field. skb->csum_start is the offset from skb->head.
skb_partial_csum_set() assumes that skb->data points to the ethernet header - i.e. it computes skb->csum_start by adding the headroom to hdr->csum_start.
Since eth_type_trans() skb_pull()s the ethernet header, skb_partial_csum_set() should be called before eth_type_trans().
--- drivers/net/virtio_net.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/virtio_net.c +5 -3
@@ -86,9 +86,7 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb,BUG_ON (len >MAX_PACKET_LEN );skb_trim (skb, len); - skb->protocol =eth_type_trans (skb, dev); -pr_debug ("Receiving skb proto 0x%04x len %i type %i\n" , -ntohs (skb->protocol), skb->len, skb->pkt_type); + dev->stats.rx_bytes += skb->len; dev->stats.rx_packets++;
@@ -98,6 +96,10 @@ static void receive_skb(struct net_device *dev, struct sk_buff *skb, goto frame_err; } + skb->protocol =eth_type_trans (skb, dev); +pr_debug ("Receiving skb proto 0x%04x len %i type %i\n" , +ntohs (skb->protocol), skb->len, skb->pkt_type); +if (hdr->gso_type !=VIRTIO_NET_HDR_GSO_NONE ) {pr_debug ("GSO!\n" );switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN ) {
Signature · 1 line
1.5.4.1
Re: [PATCH 3/3] virtio_net: Fix skb->csum_start computation
Quoted 8 lines · Mark McLoughlin
hdr->csum_startis the offset from the start of the ethernet header to the transport layer checksum field.skb->csum_startis the offset fromskb->head.
skb_partial_csum_set()assumes thatskb->datapoints to the ethernet header - i.e. it computesskb->csum_startby adding the headroom tohdr->csum_start.
Quoted 5 lines
Since
eth_type_trans()skb_pull()s the ethernet header,skb_partial_csum_set()should be called beforeeth_type_trans().Signed-off-by Mark McLoughlin <[email protected]>
Good catch! Clearly shows I never ran this across a real Ethernet device :)
Thanks,
Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txtRe: [PATCH 3/3] virtio_net: Fix skb->csum_start computation
In reply to Mark McLoughlinQuoted 11 lines · On Tuesday 27 May 2008 21:20:47 Mark McLoughlin wrote:
hdr->csum_startis the offset from the start of the ethernet header to the transport layer checksum field.skb->csum_startis the offset fromskb->head.
skb_partial_csum_set()assumes thatskb->datapoints to the ethernet header - i.e. it computesskb->csum_startby adding the headroom tohdr->csum_start.Since
eth_type_trans()skb_pull()s the ethernet header,skb_partial_csum_set()should be called beforeeth_type_trans().
As should the rx_bytes += skb->len. Thanks for this!
Applied (and 1/3, the typo patch).
I'll backport this to -stable, as well.
Thanks,
Rusty.
Re: [PATCH 3/3] virtio_net: Fix skb->csum_start computation
In reply to Mark McLoughlinQuoted 11 lines · On Tuesday 27 May 2008 21:20:47 Mark McLoughlin wrote:
hdr->csum_startis the offset from the start of the ethernet header to the transport layer checksum field.skb->csum_startis the offset fromskb->head.
skb_partial_csum_set()assumes thatskb->datapoints to the ethernet header - i.e. it computesskb->csum_startby adding the headroom tohdr->csum_start.Since
eth_type_trans()skb_pull()s the ethernet header,skb_partial_csum_set()should be called beforeeth_type_trans().
As should the rx_bytes += skb->len. Thanks for this!
Applied (and 1/3, the typo patch).
I'll backport this to -stable, as well.
Thanks,
Rusty.
Re: [PATCH 2/3] virtio_net: Trivial coding style fix
In reply to Mark McLoughlindrivers/net/virtio_net.c static void receive_skb(struct net_device *dev, struct sk_buff *skb, · line 97
Quoted 2 lines · On Tuesday 27 May 2008 21:20:46 Mark McLoughlin wrote:
drivers/net/virtio_net.c +1
-1-if (!skb_partial_csum_set (skb,hdr->csum_start,hdr->csum_offset)) +if (!skb_partial_csum_set (skb, hdr->csum_start, hdr->csum_offset))
I compressed the whitespace to avoid going over 80 cols. A choice of lesser evils :)
Cheers,
Rusty.