xen-netfront: Add support for IPv6 offloads
Subsystems (3)
PATCH v3 1/1 xen-netfront: Add support for IPv6 offloads
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
---
v3:
- Addressed comments raised by Annie Li
v2:
- Addressed comments raised by Ian Campbell
drivers/net/xen-netfront.c | 239 ++++++++++++++++++++++++++++++++++++++++---- include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)
drivers/net/xen-netfront.c +222 -17
@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 ) ? +XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;
@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff *skb,return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;
@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max) { -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ + target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) { +net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* maximally sized IP and TCP or UDP headers. +*/ +#define MAX_IP_HEADER 128 + +static int checksum_setup_ip (struct net_device *dev,struct sk_buff *skb) +{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy
@@ -879,40 +915,158 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : -if (!skb_partial_csum_set (skb,4 * iph->ihl, +if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : -if (!skb_partial_csum_set (skb,4 * iph->ihl, +if (!skb_partial_csum_set (skb, off, offsetof(struct udphdr , check))) goto out;if (recalculate_partial_csum) {struct udphdr *udph =udp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct udphdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_UDP ,0 ); }break ;default : -if (net_ratelimit ()) -pr_err ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , - iph->protocol); +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6 (struct net_device *dev,struct sk_buff *skb) +{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false; + +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ; + + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + +while ((off <=sizeof (struct ipv6hdr ) +ntohs (ipv6h->payload_len)) && + !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + +switch (nexthdr) { +case IPPROTO_TCP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct tcphdr , check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + nexthdr); goto out; }
@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err; + +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {
@@ -1232,6 +1405,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-ipv6-csum-offload" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )
@@ -1241,6 +1423,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }
@@ -1373,7 +1564,9 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features =NETIF_F_IP_CSUM |NETIF_F_SG |NETIF_F_TSO ; + netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;/* * Assume that all hw features are available for now. This set
@@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename,"feature-gso-tcpv6" ,"%d" ,1 ); +if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err =xenbus_printf (xbt, dev->nodename,"feature-ipv6-csum-offload" ,"%d" ,1 ); +if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )
include/linux/ipv6.h +2 -0
@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> #define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Paul Durrant <[email protected]>
Date: Tue, 26 Nov 2013 16:41:52 +0000
Quoted 4 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Signed-off-by Paul Durrant <[email protected]>
Please resubmit this when the net-next tree opens back up, thank you.
David Miller
maintainerFrom: Paul Durrant <[email protected]>
Date: Tue, 26 Nov 2013 16:41:52 +0000
Quoted 4 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Signed-off-by Paul Durrant <[email protected]>
Please resubmit this when the net-next tree opens back up, thank you.
Quoted 2 lines · Paul Durrant
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Quoted 58 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239 ++++++++++++++++++++++++++++++++++++++++---- include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +9
-4@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 ) ? +XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff *skb,return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)
Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/
Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {
Why not explicitly check whether__pskb_pull_tail() returned NULL ?
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* maximally sized IP and TCP or UDP headers. +*/
Comment style.
Quoted 29 lines
drivers/net/xen-netfront.c +13
-3+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip (struct net_device *dev,struct sk_buff *skb) +{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );
You can put these (off and sizeof) onto the same line.
Quoted 51 lines
drivers/net/xen-netfront.c +30
-6+if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : -if (!skb_partial_csum_set (skb,4 * iph->ihl, +if (!skb_partial_csum_set (skb, off, offsetof(struct udphdr , check))) goto out;if (recalculate_partial_csum) {struct udphdr *udph =udp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct udphdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_UDP ,0 ); }break ;default : -if (net_ratelimit ()) -pr_err ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , - iph->protocol); +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6 (struct net_device *dev,struct sk_buff *skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;
This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to is_fragment?)
Quoted 14 lines
drivers/net/xen-netfront.c +14
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ; + + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len)) &&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );
I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 13 lines
drivers/net/xen-netfront.c +13
-0+if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );
Here as well.
Quoted 44 lines
drivers/net/xen-netfront.c +40
-0+if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + +switch (nexthdr) { +case IPPROTO_TCP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct tcphdr , check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + nexthdr); goto out; }
drivers/net/xen-netfront.c out: · line 1081
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;
Initialize to -EPROTO (just to keep consistent with the rest of the file)
Quoted 52 lines
drivers/net/xen-netfront.c +34
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-ipv6-csum-offload" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }
drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 7 lines
drivers/net/xen-netfront.c +3
-1@@ -1373,7 +1564,9 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features =NETIF_F_IP_CSUM |NETIF_F_SG |NETIF_F_TSO ; + netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;
Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
Quoted 35 lines
drivers/net/xen-netfront.c +12
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename,"feature-gso-tcpv6" ,"%d" ,1 ); +if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err =xenbus_printf (xbt, dev->nodename,"feature-ipv6-csum-offload" ,"%d" ,1 ); +if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +2
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> #define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */
Quoted 8 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6 offloads
Quoted 6 lines
Quoted 2 lines · Paul Durrant
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to net/core/dev.c? It's not specific to netback/netfront usage.
Opinions?
Paul
Quoted 437 lines
Quoted 10 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 8 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 21 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +2
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> #define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */
Quoted 8 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6 offloads
Quoted 6 lines
Quoted 2 lines · Paul Durrant
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to net/core/dev.c? It's not specific to netback/netfront usage.
Opinions?
Paul
Quoted 437 lines
Quoted 10 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 8 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 21 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +2
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> #define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */
Quoted 8 lines · Paul Durrant
Quoted 8 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6 offloads
Quoted 8 lines
Quoted 5 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.
Will any of these routines be called for anything other than Xen networking?
I don't know about net/core/dev.c but given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Into xen-netcore.c or some such.
-boris
Quoted 434 lines
Opinions?
Paul
Quoted 419 lines
Quoted 9 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 7 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 15 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +0
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> Quoted 6 lines
include/linux/ipv6.h line 11
Quoted 6 lines
include/linux/ipv6.h +2
-0#define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 26 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 07 January 2014 14:54
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; Ian Campbell; Annie Li; David Vrabel
Subject: Re: [Xen-devel] [PATCH net-next v3] xen-netfront: Add support for IPv6 offloadsQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6offloads
Quoted 8 lines
Quoted 6 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
Quoted 8 lines
Quoted 1 line
The checksum related code essentially needs to be a duplicate of that in
netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.Will any of these routines be called for anything other than Xen networking?
I guess similar logic must be duplicated in other drivers - I can't believe that netback and netfront are the only ones to want to know where the TCP/UDP checksum field is located.
Quoted 4 lines
I don't know about
net/core/dev.cbut given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Intoxen-netcore.cor some such.
That's probably a pragmatic first step; I'll do that and post a patch series as v4.
Paul
Quoted 439 lines
-boris
Quoted 98 lines
Opinions?
Paul
Quoted 93 lines
Quoted 9 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?Quoted 8 lines
Quoted 8 lines
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header
Quoted 89 lines
Quoted 89 lines
plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
Quoted 11 lines
Quoted 11 lines
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header
Quoted 228 lines
Quoted 218 lines
plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 7 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 15 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +0
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> Quoted 6 lines
include/linux/ipv6.h line 11
Quoted 6 lines
include/linux/ipv6.h +2
-0#define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 26 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 07 January 2014 14:54
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; Ian Campbell; Annie Li; David Vrabel
Subject: Re: [Xen-devel] [PATCH net-next v3] xen-netfront: Add support for IPv6 offloadsQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6offloads
Quoted 8 lines
Quoted 6 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
Quoted 8 lines
Quoted 1 line
The checksum related code essentially needs to be a duplicate of that in
netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.Will any of these routines be called for anything other than Xen networking?
I guess similar logic must be duplicated in other drivers - I can't believe that netback and netfront are the only ones to want to know where the TCP/UDP checksum field is located.
Quoted 4 lines
I don't know about
net/core/dev.cbut given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Intoxen-netcore.cor some such.
That's probably a pragmatic first step; I'll do that and post a patch series as v4.
Paul
Quoted 439 lines
-boris
Quoted 98 lines
Opinions?
Paul
Quoted 93 lines
Quoted 9 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?Quoted 8 lines
Quoted 8 lines
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header
Quoted 89 lines
Quoted 89 lines
plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
Quoted 11 lines
Quoted 11 lines
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header
Quoted 228 lines
Quoted 218 lines
plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 7 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 15 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +0
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> Quoted 6 lines
include/linux/ipv6.h line 11
Quoted 6 lines
include/linux/ipv6.h +2
-0#define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 31 lines · Paul Durrant
Quoted 31 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 07 January 2014 14:54
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; Ian Campbell; Annie Li; David Vrabel
Subject: Re: [Xen-devel] [PATCH net-next v3] xen-netfront: Add support for IPv6 offloadsQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6offloads
Quoted 9 lines
Quoted 6 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in
netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.
Quoted 7 lines
Quoted 3 lines
Will any of these routines be called for anything other than Xen networking?
I guess similar logic must be duplicated in other drivers - I can't believe that netback and netfront are the only ones to want to know where the TCP/UDP checksum field is located.
Me neither. Given that we already have two consumers (albeit both *xen*) and that the functionality is generic in nature it seems to make sense to me to have it in a generic place.
Quoted 6 lines
Quoted 4 lines
I don't know about
net/core/dev.cbut given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Intoxen-netcore.cor some such.That's probably a pragmatic first step; I'll do that and post a patch series as v4.
I think this makes sense for code which has two consumers (both *xen*) but which is actually Xen specific. Obviously if the network maintainers don't think the checksum functionality is plausibly generically useful then we could put it here instead.
Ian.
Quoted 31 lines · Paul Durrant
Quoted 31 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 07 January 2014 14:54
To: Paul Durrant
Cc: [email protected]; [email protected]; Wei Liu; Ian Campbell; Annie Li; David Vrabel
Subject: Re: [Xen-devel] [PATCH net-next v3] xen-netfront: Add support for IPv6 offloadsQuoted 7 lines · Paul Durrant
Quoted 7 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6offloads
Quoted 9 lines
Quoted 6 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in
netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.
Quoted 7 lines
Quoted 3 lines
Will any of these routines be called for anything other than Xen networking?
I guess similar logic must be duplicated in other drivers - I can't believe that netback and netfront are the only ones to want to know where the TCP/UDP checksum field is located.
Me neither. Given that we already have two consumers (albeit both *xen*) and that the functionality is generic in nature it seems to make sense to me to have it in a generic place.
Quoted 6 lines
Quoted 4 lines
I don't know about
net/core/dev.cbut given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Intoxen-netcore.cor some such.That's probably a pragmatic first step; I'll do that and post a patch series as v4.
I think this makes sense for code which has two consumers (both *xen*) but which is actually Xen specific. Obviously if the network maintainers don't think the checksum functionality is plausibly generically useful then we could put it here instead.
Ian.
Quoted 8 lines · Paul Durrant
Quoted 8 lines
-----Original Message-----
From: Boris Ostrovsky [mailto:[email protected]]
Sent: 31 December 2013 19:10
To: Paul Durrant
Cc: [email protected]; [email protected]; Konrad Rzeszutek Wilk; David Vrabel; Ian Campbell; Wei Liu; Annie Li
Subject: Re: [PATCH net-next v3] xen-netfront: Add support for IPv6 offloads
Quoted 8 lines
Quoted 5 lines · Paul Durrant
Quoted 2 lines
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Thanks for the review.
The checksum related code essentially needs to be a duplicate of that in netback and it seems wasteful to have the code in both places. Could this code be moved perhaps to
net/core/dev.c? It's not specific to netback/netfront usage.
Will any of these routines be called for anything other than Xen networking?
I don't know about net/core/dev.c but given the large amount of duplicate code between netfront and netback I think factoring out should be done at least for these two. Into xen-netcore.c or some such.
-boris
Quoted 434 lines
Opinions?
Paul
Quoted 419 lines
Quoted 9 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
Quoted 7 lines
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239++++++++++++++++++++++++++++++++++++++++----
drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb,
Quoted 8 lines
include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +0
-0@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb,struct
net_device*dev)drivers/net/xen-netfront.c static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
Quoted 5 lines
drivers/net/xen-netfront.c +1
-1tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo(skb)->gso_type &
SKB_GSO_TCPV6) ?drivers/net/xen-netfront.c static int xennet_set_skb_gso(struct sk_buff
Quoted 6 lines
drivers/net/xen-netfront.c +2
-0+ XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff*skb,
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct
Quoted 22 lines
drivers/net/xen-netfront.c +6
-3return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct
netfront_info*np,drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {Why not explicitly check
whether__pskb_pull_tail()returned NULL ?drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 8 lines
drivers/net/xen-netfront.c +8
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 2 lines
drivers/net/xen-netfront.c +2
-0+* maximally sized IP and TCP or UDP headers. +*/ Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np,
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device*dev, struct
sk_buff*skb)Quoted 16 lines
drivers/net/xen-netfront.c +5
-3if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );You can put these (off and sizeof) onto the same line.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 938
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))Quoted 12 lines
drivers/net/xen-netfront.c +4
-2+ goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph- daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl, + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0offsetof(struct udphdr, check))) goto out; if (recalculate_partial_csum) { struct udphdr *udph = udp_hdr(skb); + + header_size = skb->network_header + + off + + sizeof(struct udphdr); + if (!maybe_pull_tail(skb, header_size,
MAX_IP_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 3 lines
drivers/net/xen-netfront.c +2
-0+ goto out; + udph->check = ~csum_tcpudp_magic(iph->saddr,
iph->daddr,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 8 lines
drivers/net/xen-netfront.c +1
-3- skb->len - iph->ihl*4 , + skb->len - off, IPPROTO_UDP, 0); }break ;default : -if (net_ratelimit ()) - pr_err("Attempting to checksum a non-TCP/UDPpacket, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 967
Quoted 2 lines
drivers/net/xen-netfront.c +1
-1- iph->protocol); + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 11 lines
drivers/net/xen-netfront.c +11
-0+ iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 5 lines
drivers/net/xen-netfront.c +5
-0+* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6(struct net_device *dev, struct sk_buff*skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to
is_fragment?)Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ;drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len))&&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1018
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 12 lines
drivers/net/xen-netfront.c +12
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );Here as well.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device · line 1031
Quoted 1 line
drivers/net/xen-netfront.c +1
-0+ if (!maybe_pull_tail(skb, header_size,
MAX_IPV6_HEADER))Quoted 28 lines
drivers/net/xen-netfront.c +28
-0+ goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + + switch (nexthdr) { + case IPPROTO_TCP: + if (!skb_partial_csum_set(skb, off,drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb)
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ offsetof(struct tcphdr, check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : + net_err_ratelimited("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n",
drivers/net/xen-netfront.c out: · line 1081
Quoted 11 lines
drivers/net/xen-netfront.c +4
-0+ nexthdr); goto out; }@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;Initialize to
-EPROTO(just to keep consistent with the rest of the file)drivers/net/xen-netfront.c static netdev_features_t
Quoted 20 lines
drivers/net/xen-netfront.c +16
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static netdev_features_t xennet_fix_features(struct net_device *dev,
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { + if (xenbus_scanf(XBT_NIL, np->xbdev->otherend, + "feature-ipv6-csum-offload", "%d", &val) <0)
drivers/net/xen-netfront.c static netdev_features_t
Quoted 10 lines
drivers/net/xen-netfront.c +6
-0+ val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_txennet_fix_features(struct
net_device*dev,drivers/net/xen-netfront.c static struct net_device
Quoted 16 lines
drivers/net/xen-netfront.c +9
-0features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }@@ -1373,7 +1564,9 @@ static struct net_device*xennet_create_dev(struct
xenbus_device*dev)drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev)
Quoted 4 lines
drivers/net/xen-netfront.c +0
-1netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
NETIF_F_TSO;drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 3 lines
drivers/net/xen-netfront.c +3
-0+ netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
drivers/net/xen-netfront.c again: · line 1947
Quoted 7 lines
drivers/net/xen-netfront.c +1
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6","%d", 1);
drivers/net/xen-netfront.c again:
Quoted 6 lines
drivers/net/xen-netfront.c +6
-0+if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", "%d", 1);
Quoted 15 lines
drivers/net/xen-netfront.c +5
-0+if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +0
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> Quoted 6 lines
include/linux/ipv6.h line 11
Quoted 6 lines
include/linux/ipv6.h +2
-0#define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */ _______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 2 lines · Paul Durrant
This patch adds support for IPv6 checksum offload and GSO when those features are available in the backend.
Sorry for late review. Mostly style comments.
Quoted 58 lines
Signed-off-by Paul Durrant <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc David Vrabel <[email protected]>Cc Ian Campbell <[email protected]>Cc Wei Liu <[email protected]>Cc Annie Li <[email protected]>---
v3:
- Addressed comments raised by Annie Liv2:
- Addressed comments raised by Ian Campbelldrivers/net/xen-netfront.c | 239 ++++++++++++++++++++++++++++++++++++++++---- include/linux/ipv6.h | 2 + 2 files changed, 224 insertions(+), 17 deletions(-)drivers/net/xen-netfront.c +9
-4@@ -616,7 +616,9 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) tx->flags |= XEN_NETTXF_extra_info; gso->u.gso.size =skb_shinfo (skb)->gso_size; - gso->u.gso.type =XEN_NETIF_GSO_TYPE_TCPV4 ; + gso->u.gso.type = (skb_shinfo (skb)->gso_type &SKB_GSO_TCPV6 ) ? +XEN_NETIF_GSO_TYPE_TCPV6 : +XEN_NETIF_GSO_TYPE_TCPV4 ; gso->u.gso.pad =0 ; gso->u.gso.features =0 ;@@ -808,15 +810,18 @@ static int xennet_set_skb_gso(struct sk_buff *skb,return -EINVAL ; } -/* Currently only TCPv4 S.O. is supported. */ -if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 ) { +if (gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV4 && + gso->u.gso.type !=XEN_NETIF_GSO_TYPE_TCPV6 ) {if (net_ratelimit ())pr_warn ("Bad GSO type %d\n" , gso->u.gso.type);return -EINVAL ; }skb_shinfo (skb)->gso_size = gso->u.gso.size; -skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; +skb_shinfo (skb)->gso_type = + (gso->u.gso.type ==XEN_NETIF_GSO_TYPE_TCPV4 ) ? +SKB_GSO_TCPV4 : +SKB_GSO_TCPV6 ;/* Header must be checked, and gso_segs computed. */ skb_shinfo (skb)->gso_type |=SKB_GSO_DODGY ;
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 865
Quoted 6 lines
drivers/net/xen-netfront.c +2
-1@@ -856,11 +861,42 @@ static RING_IDX xennet_fill_frags(struct netfront_info *np,return cons; } -static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +static inline bool maybe_pull_tail (struct sk_buff *skb,unsigned int min, +unsigned int max)
Should this routine return error code instead of a boolean? Otherwise it's not clear what "false" should mean --- whether it is that it failed to pull or that the pull wasn't needed.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 876
Quoted 13 lines
drivers/net/xen-netfront.c +10
-2{ -struct iphdr *iph; -int err = -EPROTO ; +int target; + +BUG_ON (max < min); + +if (!skb_is_nonlinear (skb) ||skb_headlen (skb) >= min) +return true; + +/* If we need to pullup then pullup to max, so we hopefully +* won't need to do it again. +*/
Comment style.
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 880
Quoted 4 lines
drivers/net/xen-netfront.c +4
-0+ target =min_t (int, skb->len, max); +__pskb_pull_tail (skb, target -skb_headlen (skb)); + +if (skb_headlen (skb) < min) {
Why not explicitly check whether__pskb_pull_tail() returned NULL ?
drivers/net/xen-netfront.c static RING_IDX xennet_fill_frags(struct netfront_info *np, · line 890
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+net_err_ratelimited ("Failed to pullup packet header\n" ); +return false; + } + +return true; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* maximally sized IP and TCP or UDP headers. +*/
Comment style.
Quoted 29 lines
drivers/net/xen-netfront.c +13
-3+#define MAX_IP_HEADER 128 + +static int checksum_setup_ip (struct net_device *dev,struct sk_buff *skb) +{ +struct iphdr *iph = (void *)skb->data; +unsigned int header_size; +unsigned int off;int recalculate_partial_csum =0 ; +int err = -EPROTO ;/* * A GSO SKB must be CHECKSUM_PARTIAL. However some buggy @@ -879,40 +915,158 @@ static int checksum_setup(struct net_device *dev, struct sk_buff *skb)if (skb->ip_summed !=CHECKSUM_PARTIAL )return 0 ; -if (skb->protocol !=htons (ETH_P_IP )) + off =sizeof (struct iphdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) goto out; - iph = (void *)skb->data; + off = iph->ihl *4 ;switch (iph->protocol) {case IPPROTO_TCP : - if (!skb_partial_csum_set(skb, 4 * iph->ihl,
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 937
Quoted 10 lines
drivers/net/xen-netfront.c +5
-0+if (!skb_partial_csum_set (skb, off, offsetof(struct tcphdr , check))) goto out;if (recalculate_partial_csum) {struct tcphdr *tcph =tcp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct tcphdr );
You can put these (off and sizeof) onto the same line.
Quoted 51 lines
drivers/net/xen-netfront.c +30
-6+if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + tcph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_TCP ,0 ); }break ;case IPPROTO_UDP : -if (!skb_partial_csum_set (skb,4 * iph->ihl, +if (!skb_partial_csum_set (skb, off, offsetof(struct udphdr , check))) goto out;if (recalculate_partial_csum) {struct udphdr *udph =udp_hdr (skb); + + header_size = skb->network_header + + off + +sizeof (struct udphdr ); +if (!maybe_pull_tail (skb, header_size,MAX_IP_HEADER )) + goto out; + udph->check = ~csum_tcpudp_magic (iph->saddr, iph->daddr, - skb->len - iph->ihl*4 , + skb->len - off,IPPROTO_UDP ,0 ); }break ;default : -if (net_ratelimit ()) -pr_err ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , - iph->protocol); +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + iph->protocol); + goto out; + } + + err =0 ; + +out: +return err; +} + +/* This value should be large enough to cover a tagged ethernet header plus +* an IPv6 header, all options, and a maximal TCP or UDP header. +*/ +#define MAX_IPV6_HEADER 256 + +static int checksum_setup_ipv6 (struct net_device *dev,struct sk_buff *skb)
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 992
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+{ +struct ipv6hdr *ipv6h = (void *)skb->data; +u8 nexthdr; +unsigned int header_size; +unsigned int off; +bool fragment; +bool done; +int err = -EPROTO ; + + done = false;
This should probably be moved down to the beginning of the while loop. And you also need to initialize fragment to "false" (and possibly rename it to is_fragment?)
Quoted 14 lines
drivers/net/xen-netfront.c +14
-0+ +/* A non-CHECKSUM_PARTIAL SKB does not require setup. */ +if (skb->ip_summed !=CHECKSUM_PARTIAL ) +return 0 ; + + off =sizeof (struct ipv6hdr ); + + header_size = skb->network_header + off; +if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = ipv6h->nexthdr; + + while ((off <= sizeof(struct ipv6hdr) + ntohs(ipv6h->payload_len)) &&
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1016
Quoted 10 lines
drivers/net/xen-netfront.c +10
-0+ !done) { +switch (nexthdr) { +case IPPROTO_DSTOPTS : +case IPPROTO_HOPOPTS : +case IPPROTO_ROUTING : { +struct ipv6_opt_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ipv6_opt_hdr );
I'd merge the last two lines.
drivers/net/xen-netfront.c static int checksum_setup(struct net_device *dev, struct sk_buff *skb) · line 1029
Quoted 13 lines
drivers/net/xen-netfront.c +13
-0+if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_optlen (hp); +break ; + } +case IPPROTO_AH : { +struct ip_auth_hdr *hp = (void *)(skb->data + off); + + header_size = skb->network_header + + off + +sizeof (struct ip_auth_hdr );
Here as well.
Quoted 44 lines
drivers/net/xen-netfront.c +40
-0+if (!maybe_pull_tail (skb, header_size,MAX_IPV6_HEADER )) + goto out; + + nexthdr = hp->nexthdr; + off +=ipv6_ahlen (hp); +break ; + } +case IPPROTO_FRAGMENT : + fragment = true; +/* fall through */ +default : + done = true; +break ; + } + } + +if (!done) { +net_err_ratelimited ("Failed to parse packet header\n" ); + goto out; + } + +if (fragment) { +net_err_ratelimited ("Packet is a fragment!\n" ); + goto out; + } + +switch (nexthdr) { +case IPPROTO_TCP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct tcphdr , check))) + goto out; +break ; +case IPPROTO_UDP : +if (!skb_partial_csum_set (skb, off, + offsetof(struct udphdr , check))) + goto out; +break ; +default : +net_err_ratelimited ("Attempting to checksum a non-TCP/UDP packet, dropping a protocol %d packet\n" , + nexthdr); goto out; }
drivers/net/xen-netfront.c out: · line 1081
Quoted 6 lines
drivers/net/xen-netfront.c +3
-0@@ -922,6 +1076,25 @@ out:return err; } +static int checksum_setup (struct net_device *dev,struct sk_buff *skb) +{ +int err;
Initialize to -EPROTO (just to keep consistent with the rest of the file)
Quoted 52 lines
drivers/net/xen-netfront.c +34
-0+ +switch (skb->protocol) { +case htons (ETH_P_IP ): + err =checksum_setup_ip (dev, skb); +break ; +case htons (ETH_P_IPV6 ): + err =checksum_setup_ipv6 (dev, skb); +break ; +default : + err = -EPROTO ; +break ; + } + +return err; +} +static int handle_incoming_queue (struct net_device *dev,struct sk_buff_head *rxq) {@@ -1232,6 +1405,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_SG ; } +if (features &NETIF_F_IPV6_CSUM ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-ipv6-csum-offload" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_IPV6_CSUM ; + } +if (features &NETIF_F_TSO ) {if (xenbus_scanf (XBT_NIL , np->xbdev->otherend,"feature-gso-tcpv4" ,"%d" , &val) <0 )@@ -1241,6 +1423,15 @@ static netdev_features_t xennet_fix_features(struct net_device *dev, features &= ~NETIF_F_TSO ; } +if (features &NETIF_F_TSO6 ) { +if (xenbus_scanf (XBT_NIL , np->xbdev->otherend, +"feature-gso-tcpv6" ,"%d" , &val) <0 ) + val =0 ; + +if (!val) + features &= ~NETIF_F_TSO6 ; + } +return features; }
drivers/net/xen-netfront.c static struct net_device *xennet_create_dev(struct xenbus_device *dev) · line 1569
Quoted 7 lines
drivers/net/xen-netfront.c +3
-1@@ -1373,7 +1564,9 @@ static struct net_device *xennet_create_dev(struct xenbus_device *dev)netif_napi_add (netdev, &np->napi, xennet_poll,64 ); netdev->features =NETIF_F_IP_CSUM |NETIF_F_RXCSUM |NETIF_F_GSO_ROBUST ; - netdev->hw_features =NETIF_F_IP_CSUM |NETIF_F_SG |NETIF_F_TSO ; + netdev->hw_features =NETIF_F_SG | +NETIF_F_IPV6_CSUM | +NETIF_F_TSO |NETIF_F_TSO6 ;
Can you merge these three lines and stay under 80? If not, merge either of the two of them.
-boris
Quoted 35 lines
drivers/net/xen-netfront.c +12
-0/* * Assume that all hw features are available for now. This set @@ -1751,6 +1944,18 @@ again: goto abort_transaction; } + err =xenbus_printf (xbt, dev->nodename,"feature-gso-tcpv6" ,"%d" ,1 ); +if (err) { + message ="writing feature-gso-tcpv6" ; + goto abort_transaction; + } + + err =xenbus_printf (xbt, dev->nodename,"feature-ipv6-csum-offload" ,"%d" ,1 ); +if (err) { + message ="writing feature-ipv6-csum-offload" ; + goto abort_transaction; + } + err =xenbus_transaction_end (xbt,0 );if (err) {if (err == -EAGAIN )include/linux/ipv6.h +2
-0@@ -4,6 +4,8 @@#include <uapi/linux/ipv6.h> #define ipv6_optlen (p) (((p)->hdrlen+1) << 3) +#define ipv6_ahlen (p) (((p)->hdrlen+2) << 2); +/* * This structure contains configuration options per IPv6 link. */