Vladislav Yasevich
2015-Jan-30 19:27 UTC
[PATCH v2 0/3] Restore UFO support to virtio_net devices
commit 3d0ad09412ffe00c9afa201d01effdb6023d09b4 Author: Ben Hutchings <ben at decadent.org.uk> Date: Thu Oct 30 18:27:12 2014 +0000 drivers/net: Disable UFO through virtio Turned off UFO support to virtio-net based devices due to issues with IPv6 fragment id generation for UFO packets. The issue was that IPv6 UFO/GSO implementation expects the fragment id to be supplied in skb_shinfo(). However, for packets generated by the VMs, the fragment id is not supplied which causes all IPv6 fragments to have the id of 0. The problem is that turning off UFO support on tap/macvtap as well as virtio devices caused issues with migrations. Migrations would fail when moving a vm from a kernel supporting expecting UFO to work to the newer kernels that disabled UFO. This series provides a partial solution to address the migration issue. The series allows us to track whether skb_shinfo()->ip6_frag_id has been set by treating value of 0 as unset. This lets GSO code to generate fragment ids if they are necessary (ex: packet was generated by VM or packet socket). Since v1: - Removed the skb bit and use value of 0 as tracker. - Used Eric's suggestion to set fragment id as 0x80000000 if id generation procedure yeilded a 0 result. - Consolidated ipv6 id genration code. Vladislav Yasevich (3): ipv6: Select fragment id during UFO segmentation if not set. Revert "drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO packets" Revert "drivers/net: Disable UFO through virtio" drivers/net/macvtap.c | 16 ++++++++-------- drivers/net/tun.c | 25 +++++++++---------------- drivers/net/virtio_net.c | 24 ++++++++++-------------- include/net/ipv6.h | 3 +++ net/ipv6/ip6_output.c | 10 ++++------ net/ipv6/output_core.c | 28 ++++++++++++++++++++++------ net/ipv6/udp_offload.c | 10 +++++++++- 7 files changed, 65 insertions(+), 51 deletions(-) -- 1.9.3
Vladislav Yasevich
2015-Jan-30 19:27 UTC
[PATCH v2 1/3] ipv6: Select fragment id during UFO segmentation if not set.
If the IPv6 fragment id has not been set and we perform fragmentation due to UFO, select a new fragment id. We now consider a fragment id of 0 as unset and if id selection process returns 0 (after all the pertrubations), we set it to 0x80000000, thus giving us ample space not to create collisions with the next packet we may have to fragment. When doing UFO integrity checking, we also select the fragment id if it has not be set yet. This is stored into the skb_shinfo() thus allowing UFO to function correclty. This patch also removes duplicate fragment id generation code and moves ipv6_select_ident() into the header as it may be used during GSO. Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com> --- include/net/ipv6.h | 3 +++ net/ipv6/ip6_output.c | 10 ++++------ net/ipv6/output_core.c | 28 ++++++++++++++++++++++------ net/ipv6/udp_offload.c | 10 +++++++++- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/include/net/ipv6.h b/include/net/ipv6.h index 4292929..9bf85d3 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -671,6 +671,9 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); } +u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst, + struct in6_addr *src); +void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt); void ipv6_proxy_select_ident(struct sk_buff *skb); int ip6_dst_hoplimit(struct dst_entry *dst); diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index ce69a12..5dc91fe 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -537,17 +537,15 @@ static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from) skb_copy_secmark(to, from); } -static void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) +void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) { static u32 ip6_idents_hashrnd __read_mostly; - u32 hash, id; + u32 id; net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd)); - hash = __ipv6_addr_jhash(&rt->rt6i_dst.addr, ip6_idents_hashrnd); - hash = __ipv6_addr_jhash(&rt->rt6i_src.addr, hash); - - id = ip_idents_reserve(hash, 1); + id = __ipv6_select_ident(ip6_idents_hashrnd, &rt->rt6i_dst.addr, + &rt->rt6i_src.addr); fhdr->identification = htonl(id); } diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c index 97f41a3..ceb857d 100644 --- a/net/ipv6/output_core.c +++ b/net/ipv6/output_core.c @@ -9,6 +9,24 @@ #include <net/addrconf.h> #include <net/secure_seq.h> +u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst, struct in6_addr *src) +{ + u32 hash, id; + + hash = __ipv6_addr_jhash(dst, hashrnd); + hash = __ipv6_addr_jhash(src, hash); + + /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve, + * set the hight order instead thus minimizing possible future + * collisions. + */ + id = ip_idents_reserve(hash, 1); + if (unlikely(!id)) + id = 1 << 31; + + return id; +} + /* This function exists only for tap drivers that must support broken * clients requesting UFO without specifying an IPv6 fragment ID. * @@ -22,7 +40,7 @@ void ipv6_proxy_select_ident(struct sk_buff *skb) static u32 ip6_proxy_idents_hashrnd __read_mostly; struct in6_addr buf[2]; struct in6_addr *addrs; - u32 hash, id; + u32 id; addrs = skb_header_pointer(skb, skb_network_offset(skb) + @@ -34,11 +52,9 @@ void ipv6_proxy_select_ident(struct sk_buff *skb) net_get_random_once(&ip6_proxy_idents_hashrnd, sizeof(ip6_proxy_idents_hashrnd)); - hash = __ipv6_addr_jhash(&addrs[1], ip6_proxy_idents_hashrnd); - hash = __ipv6_addr_jhash(&addrs[0], hash); - - id = ip_idents_reserve(hash, 1); - skb_shinfo(skb)->ip6_frag_id = htonl(id); + id = __ipv6_select_ident(ip6_proxy_idents_hashrnd, + &addrs[1], &addrs[0]); + skb_shinfo(skb)->ip6_frag_id = id; } EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident); diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c index b6aa8ed..a562769 100644 --- a/net/ipv6/udp_offload.c +++ b/net/ipv6/udp_offload.c @@ -52,6 +52,10 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss); + /* Set the IPv6 fragment id if not set yet */ + if (!skb_shinfo(skb)->ip6_frag_id) + ipv6_proxy_select_ident(skb); + segs = NULL; goto out; } @@ -108,7 +112,11 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); fptr->nexthdr = nexthdr; fptr->reserved = 0; - fptr->identification = skb_shinfo(skb)->ip6_frag_id; + if (skb_shinfo(skb)->ip6_frag_id) + fptr->identification = skb_shinfo(skb)->ip6_frag_id; + else + ipv6_select_ident(fptr, + (struct rt6_info *)skb_dst(skb)); /* Fragment the skb. ipv6 header and the remaining fields of the * fragment header are updated in ipv6_gso_segment() -- 1.9.3
Vladislav Yasevich
2015-Jan-30 19:27 UTC
[PATCH v2 2/3] Revert "drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO packets"
This reverts commit 5188cd44c55db3e92cd9e77a40b5baa7ed4340f7. Now that GSO layer can track if fragment id has been selected and can allocate one if necessary, we don't need to do this in tap and macvtap. This reverts most of the code and only keeps the new ipv6 fragment id generation function that is still needed. Fixes: 3d0ad09412ff (drivers/net: Disable UFO through virtio) Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com> --- drivers/net/macvtap.c | 3 --- drivers/net/tun.c | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 7df2217..0b86e46 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -17,7 +17,6 @@ #include <linux/fs.h> #include <linux/uio.h> -#include <net/ipv6.h> #include <net/net_namespace.h> #include <net/rtnetlink.h> #include <net/sock.h> @@ -589,8 +588,6 @@ static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q, pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n", current->comm); gso_type = SKB_GSO_UDP; - if (skb->protocol == htons(ETH_P_IPV6)) - ipv6_proxy_select_ident(skb); break; default: return -EINVAL; diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 8c8dc16..5ca42b7 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -65,7 +65,6 @@ #include <linux/nsproxy.h> #include <linux/virtio_net.h> #include <linux/rcupdate.h> -#include <net/ipv6.h> #include <net/net_namespace.h> #include <net/netns/generic.h> #include <net/rtnetlink.h> @@ -1167,8 +1166,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, break; } - skb_reset_network_header(skb); - if (gso.gso_type != VIRTIO_NET_HDR_GSO_NONE) { pr_debug("GSO!\n"); switch (gso.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { @@ -1189,8 +1186,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, current->comm); } skb_shinfo(skb)->gso_type = SKB_GSO_UDP; - if (skb->protocol == htons(ETH_P_IPV6)) - ipv6_proxy_select_ident(skb); break; } default: @@ -1221,6 +1216,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; } + skb_reset_network_header(skb); skb_probe_transport_header(skb, 0); rxhash = skb_get_hash(skb); -- 1.9.3
Vladislav Yasevich
2015-Jan-30 19:27 UTC
[PATCH v2 3/3] Revert "drivers/net: Disable UFO through virtio"
This reverts commit 3d0ad09412ffe00c9afa201d01effdb6023d09b4. Now that GSO functionality can correctly track if the fragment id has been selected and select a fragment id if necessary, we can re-enable UFO on tap/macvap and virtio devices. Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com> --- drivers/net/macvtap.c | 13 ++++++++----- drivers/net/tun.c | 19 ++++++++----------- drivers/net/virtio_net.c | 24 ++++++++++-------------- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c index 0b86e46..919f4fc 100644 --- a/drivers/net/macvtap.c +++ b/drivers/net/macvtap.c @@ -80,7 +80,7 @@ static struct cdev macvtap_cdev; static const struct proto_ops macvtap_socket_ops; #define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ - NETIF_F_TSO6) + NETIF_F_TSO6 | NETIF_F_UFO) #define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO) #define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG) @@ -585,8 +585,6 @@ static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q, gso_type = SKB_GSO_TCPV6; break; case VIRTIO_NET_HDR_GSO_UDP: - pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n", - current->comm); gso_type = SKB_GSO_UDP; break; default: @@ -633,6 +631,8 @@ static void macvtap_skb_to_vnet_hdr(struct macvtap_queue *q, vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; else if (sinfo->gso_type & SKB_GSO_TCPV6) vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; + else if (sinfo->gso_type & SKB_GSO_UDP) + vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP; else BUG(); if (sinfo->gso_type & SKB_GSO_TCP_ECN) @@ -962,6 +962,9 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg) if (arg & TUN_F_TSO6) feature_mask |= NETIF_F_TSO6; } + + if (arg & TUN_F_UFO) + feature_mask |= NETIF_F_UFO; } /* tun/tap driver inverts the usage for TSO offloads, where @@ -972,7 +975,7 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg) * When user space turns off TSO, we turn off GSO/LRO so that * user-space will not receive TSO frames. */ - if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6)) + if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_UFO)) features |= RX_OFFLOADS; else features &= ~RX_OFFLOADS; @@ -1087,7 +1090,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, case TUNSETOFFLOAD: /* let the user check for future flags */ if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 | - TUN_F_TSO_ECN)) + TUN_F_TSO_ECN | TUN_F_UFO)) return -EINVAL; rtnl_lock(); diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 5ca42b7..10f9e40 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -186,7 +186,7 @@ struct tun_struct { struct net_device *dev; netdev_features_t set_features; #define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \ - NETIF_F_TSO6) + NETIF_F_TSO6|NETIF_F_UFO) int vnet_hdr_sz; int sndbuf; @@ -1176,18 +1176,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; break; case VIRTIO_NET_HDR_GSO_UDP: - { - static bool warned; - - if (!warned) { - warned = true; - netdev_warn(tun->dev, - "%s: using disabled UFO feature; please fix this program\n", - current->comm); - } skb_shinfo(skb)->gso_type = SKB_GSO_UDP; break; - } default: tun->dev->stats.rx_frame_errors++; kfree_skb(skb); @@ -1294,6 +1284,8 @@ static ssize_t tun_put_user(struct tun_struct *tun, gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; else if (sinfo->gso_type & SKB_GSO_TCPV6) gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV6; + else if (sinfo->gso_type & SKB_GSO_UDP) + gso.gso_type = VIRTIO_NET_HDR_GSO_UDP; else { pr_err("unexpected GSO type: " "0x%x, gso_size %d, hdr_len %d\n", @@ -1742,6 +1734,11 @@ static int set_offload(struct tun_struct *tun, unsigned long arg) features |= NETIF_F_TSO6; arg &= ~(TUN_F_TSO4|TUN_F_TSO6); } + + if (arg & TUN_F_UFO) { + features |= NETIF_F_UFO; + arg &= ~TUN_F_UFO; + } } /* This gives the user a way to test for new features in future by diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 5ca9771..059fdf1 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -490,17 +490,8 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; break; case VIRTIO_NET_HDR_GSO_UDP: - { - static bool warned; - - if (!warned) { - warned = true; - netdev_warn(dev, - "host using disabled UFO feature; please fix it\n"); - } skb_shinfo(skb)->gso_type = SKB_GSO_UDP; break; - } case VIRTIO_NET_HDR_GSO_TCPV6: skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; break; @@ -888,6 +879,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6; + else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) + hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP; else BUG(); if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN) @@ -1748,7 +1741,7 @@ static int virtnet_probe(struct virtio_device *vdev) dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST; if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) { - dev->hw_features |= NETIF_F_TSO + dev->hw_features |= NETIF_F_TSO | NETIF_F_UFO | NETIF_F_TSO_ECN | NETIF_F_TSO6; } /* Individual feature bits: what can host handle? */ @@ -1758,9 +1751,11 @@ static int virtnet_probe(struct virtio_device *vdev) dev->hw_features |= NETIF_F_TSO6; if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN)) dev->hw_features |= NETIF_F_TSO_ECN; + if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO)) + dev->hw_features |= NETIF_F_UFO; if (gso) - dev->features |= dev->hw_features & NETIF_F_ALL_TSO; + dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO); /* (!csum && gso) case will be fixed by register_netdev() */ } if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM)) @@ -1798,7 +1793,8 @@ static int virtnet_probe(struct virtio_device *vdev) /* If we can receive ANY GSO packets, we must allocate large ones. */ if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) || - virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN)) + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) || + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO)) vi->big_packets = true; if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) @@ -1994,9 +1990,9 @@ static struct virtio_device_id id_table[] = { static unsigned int features[] = { VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, - VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_TSO6, + VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, - VIRTIO_NET_F_GUEST_ECN, + VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, -- 1.9.3
Michael S. Tsirkin
2015-Jan-31 17:11 UTC
[PATCH v2 1/3] ipv6: Select fragment id during UFO segmentation if not set.
On Fri, Jan 30, 2015 at 02:27:25PM -0500, Vladislav Yasevich wrote:> If the IPv6 fragment id has not been set and we perform > fragmentation due to UFO, select a new fragment id. > We now consider a fragment id of 0 as unset and if id selection > process returns 0 (after all the pertrubations), we set it to > 0x80000000, thus giving us ample space not to create collisions > with the next packet we may have to fragment. > > When doing UFO integrity checking, we also select the > fragment id if it has not be set yet. This is stored intos/be/been/> the skb_shinfo() thus allowing UFO to function correclty. > > This patch also removes duplicate fragment id generation code > and moves ipv6_select_ident() into the header as it may be > used during GSO. > > Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com>Acked-by: Michael S. Tsirkin <mst at redhat.com>> --- > include/net/ipv6.h | 3 +++ > net/ipv6/ip6_output.c | 10 ++++------ > net/ipv6/output_core.c | 28 ++++++++++++++++++++++------ > net/ipv6/udp_offload.c | 10 +++++++++- > 4 files changed, 38 insertions(+), 13 deletions(-) > > diff --git a/include/net/ipv6.h b/include/net/ipv6.h > index 4292929..9bf85d3 100644 > --- a/include/net/ipv6.h > +++ b/include/net/ipv6.h > @@ -671,6 +671,9 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_add > return __ipv6_addr_diff(a1, a2, sizeof(struct in6_addr)); > } > > +u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst, > + struct in6_addr *src); > +void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt); > void ipv6_proxy_select_ident(struct sk_buff *skb); > > int ip6_dst_hoplimit(struct dst_entry *dst); > diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c > index ce69a12..5dc91fe 100644 > --- a/net/ipv6/ip6_output.c > +++ b/net/ipv6/ip6_output.c > @@ -537,17 +537,15 @@ static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from) > skb_copy_secmark(to, from); > } > > -static void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) > +void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt) > { > static u32 ip6_idents_hashrnd __read_mostly; > - u32 hash, id; > + u32 id; > > net_get_random_once(&ip6_idents_hashrnd, sizeof(ip6_idents_hashrnd)); > > - hash = __ipv6_addr_jhash(&rt->rt6i_dst.addr, ip6_idents_hashrnd); > - hash = __ipv6_addr_jhash(&rt->rt6i_src.addr, hash); > - > - id = ip_idents_reserve(hash, 1); > + id = __ipv6_select_ident(ip6_idents_hashrnd, &rt->rt6i_dst.addr, > + &rt->rt6i_src.addr); > fhdr->identification = htonl(id); > } > > diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c > index 97f41a3..ceb857d 100644 > --- a/net/ipv6/output_core.c > +++ b/net/ipv6/output_core.c > @@ -9,6 +9,24 @@ > #include <net/addrconf.h> > #include <net/secure_seq.h> > > +u32 __ipv6_select_ident(u32 hashrnd, struct in6_addr *dst, struct in6_addr *src) > +{ > + u32 hash, id; > + > + hash = __ipv6_addr_jhash(dst, hashrnd); > + hash = __ipv6_addr_jhash(src, hash); > + > + /* Treat id of 0 as unset and if we get 0 back from ip_idents_reserve, > + * set the hight order instead thus minimizing possible future > + * collisions. > + */ > + id = ip_idents_reserve(hash, 1); > + if (unlikely(!id)) > + id = 1 << 31; > + > + return id; > +} > + > /* This function exists only for tap drivers that must support broken > * clients requesting UFO without specifying an IPv6 fragment ID. > * > @@ -22,7 +40,7 @@ void ipv6_proxy_select_ident(struct sk_buff *skb) > static u32 ip6_proxy_idents_hashrnd __read_mostly; > struct in6_addr buf[2]; > struct in6_addr *addrs; > - u32 hash, id; > + u32 id; > > addrs = skb_header_pointer(skb, > skb_network_offset(skb) + > @@ -34,11 +52,9 @@ void ipv6_proxy_select_ident(struct sk_buff *skb) > net_get_random_once(&ip6_proxy_idents_hashrnd, > sizeof(ip6_proxy_idents_hashrnd)); > > - hash = __ipv6_addr_jhash(&addrs[1], ip6_proxy_idents_hashrnd); > - hash = __ipv6_addr_jhash(&addrs[0], hash); > - > - id = ip_idents_reserve(hash, 1); > - skb_shinfo(skb)->ip6_frag_id = htonl(id); > + id = __ipv6_select_ident(ip6_proxy_idents_hashrnd, > + &addrs[1], &addrs[0]); > + skb_shinfo(skb)->ip6_frag_id = id; > } > EXPORT_SYMBOL_GPL(ipv6_proxy_select_ident); > > diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c > index b6aa8ed..a562769 100644 > --- a/net/ipv6/udp_offload.c > +++ b/net/ipv6/udp_offload.c > @@ -52,6 +52,10 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, > > skb_shinfo(skb)->gso_segs = DIV_ROUND_UP(skb->len, mss); > > + /* Set the IPv6 fragment id if not set yet */ > + if (!skb_shinfo(skb)->ip6_frag_id) > + ipv6_proxy_select_ident(skb); > + > segs = NULL; > goto out; > } > @@ -108,7 +112,11 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, > fptr = (struct frag_hdr *)(skb_network_header(skb) + unfrag_ip6hlen); > fptr->nexthdr = nexthdr; > fptr->reserved = 0; > - fptr->identification = skb_shinfo(skb)->ip6_frag_id; > + if (skb_shinfo(skb)->ip6_frag_id) > + fptr->identification = skb_shinfo(skb)->ip6_frag_id; > + else > + ipv6_select_ident(fptr, > + (struct rt6_info *)skb_dst(skb)); > > /* Fragment the skb. ipv6 header and the remaining fields of the > * fragment header are updated in ipv6_gso_segment() > -- > 1.9.3
Michael S. Tsirkin
2015-Jan-31 17:11 UTC
[PATCH v2 2/3] Revert "drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO packets"
On Fri, Jan 30, 2015 at 02:27:26PM -0500, Vladislav Yasevich wrote:> This reverts commit 5188cd44c55db3e92cd9e77a40b5baa7ed4340f7. > > Now that GSO layer can track if fragment id has been selected > and can allocate one if necessary, we don't need to do this in > tap and macvtap. This reverts most of the code and only keeps > the new ipv6 fragment id generation function that is still needed. > > Fixes: 3d0ad09412ff (drivers/net: Disable UFO through virtio) > Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com>Acked-by: Michael S. Tsirkin <mst at redhat.com>> --- > drivers/net/macvtap.c | 3 --- > drivers/net/tun.c | 6 +----- > 2 files changed, 1 insertion(+), 8 deletions(-) > > diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c > index 7df2217..0b86e46 100644 > --- a/drivers/net/macvtap.c > +++ b/drivers/net/macvtap.c > @@ -17,7 +17,6 @@ > #include <linux/fs.h> > #include <linux/uio.h> > > -#include <net/ipv6.h> > #include <net/net_namespace.h> > #include <net/rtnetlink.h> > #include <net/sock.h> > @@ -589,8 +588,6 @@ static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q, > pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n", > current->comm); > gso_type = SKB_GSO_UDP; > - if (skb->protocol == htons(ETH_P_IPV6)) > - ipv6_proxy_select_ident(skb); > break; > default: > return -EINVAL; > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 8c8dc16..5ca42b7 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -65,7 +65,6 @@ > #include <linux/nsproxy.h> > #include <linux/virtio_net.h> > #include <linux/rcupdate.h> > -#include <net/ipv6.h> > #include <net/net_namespace.h> > #include <net/netns/generic.h> > #include <net/rtnetlink.h> > @@ -1167,8 +1166,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > break; > } > > - skb_reset_network_header(skb); > - > if (gso.gso_type != VIRTIO_NET_HDR_GSO_NONE) { > pr_debug("GSO!\n"); > switch (gso.gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { > @@ -1189,8 +1186,6 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > current->comm); > } > skb_shinfo(skb)->gso_type = SKB_GSO_UDP; > - if (skb->protocol == htons(ETH_P_IPV6)) > - ipv6_proxy_select_ident(skb); > break; > } > default: > @@ -1221,6 +1216,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; > } > > + skb_reset_network_header(skb); > skb_probe_transport_header(skb, 0); > > rxhash = skb_get_hash(skb); > -- > 1.9.3
Michael S. Tsirkin
2015-Jan-31 17:11 UTC
[PATCH v2 3/3] Revert "drivers/net: Disable UFO through virtio"
On Fri, Jan 30, 2015 at 02:27:27PM -0500, Vladislav Yasevich wrote:> This reverts commit 3d0ad09412ffe00c9afa201d01effdb6023d09b4. > > Now that GSO functionality can correctly track if the fragment > id has been selected and select a fragment id if necessary, > we can re-enable UFO on tap/macvap and virtio devices. > > Signed-off-by: Vladislav Yasevich <vyasevic at redhat.com>Acked-by: Michael S. Tsirkin <mst at redhat.com>> --- > drivers/net/macvtap.c | 13 ++++++++----- > drivers/net/tun.c | 19 ++++++++----------- > drivers/net/virtio_net.c | 24 ++++++++++-------------- > 3 files changed, 26 insertions(+), 30 deletions(-) > > diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c > index 0b86e46..919f4fc 100644 > --- a/drivers/net/macvtap.c > +++ b/drivers/net/macvtap.c > @@ -80,7 +80,7 @@ static struct cdev macvtap_cdev; > static const struct proto_ops macvtap_socket_ops; > > #define TUN_OFFLOADS (NETIF_F_HW_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ > - NETIF_F_TSO6) > + NETIF_F_TSO6 | NETIF_F_UFO) > #define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO) > #define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG) > > @@ -585,8 +585,6 @@ static int macvtap_skb_from_vnet_hdr(struct macvtap_queue *q, > gso_type = SKB_GSO_TCPV6; > break; > case VIRTIO_NET_HDR_GSO_UDP: > - pr_warn_once("macvtap: %s: using disabled UFO feature; please fix this program\n", > - current->comm); > gso_type = SKB_GSO_UDP; > break; > default: > @@ -633,6 +631,8 @@ static void macvtap_skb_to_vnet_hdr(struct macvtap_queue *q, > vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4; > else if (sinfo->gso_type & SKB_GSO_TCPV6) > vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6; > + else if (sinfo->gso_type & SKB_GSO_UDP) > + vnet_hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP; > else > BUG(); > if (sinfo->gso_type & SKB_GSO_TCP_ECN) > @@ -962,6 +962,9 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg) > if (arg & TUN_F_TSO6) > feature_mask |= NETIF_F_TSO6; > } > + > + if (arg & TUN_F_UFO) > + feature_mask |= NETIF_F_UFO; > } > > /* tun/tap driver inverts the usage for TSO offloads, where > @@ -972,7 +975,7 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg) > * When user space turns off TSO, we turn off GSO/LRO so that > * user-space will not receive TSO frames. > */ > - if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6)) > + if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_UFO)) > features |= RX_OFFLOADS; > else > features &= ~RX_OFFLOADS; > @@ -1087,7 +1090,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, > case TUNSETOFFLOAD: > /* let the user check for future flags */ > if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 | > - TUN_F_TSO_ECN)) > + TUN_F_TSO_ECN | TUN_F_UFO)) > return -EINVAL; > > rtnl_lock(); > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index 5ca42b7..10f9e40 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -186,7 +186,7 @@ struct tun_struct { > struct net_device *dev; > netdev_features_t set_features; > #define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \ > - NETIF_F_TSO6) > + NETIF_F_TSO6|NETIF_F_UFO) > > int vnet_hdr_sz; > int sndbuf; > @@ -1176,18 +1176,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, > skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; > break; > case VIRTIO_NET_HDR_GSO_UDP: > - { > - static bool warned; > - > - if (!warned) { > - warned = true; > - netdev_warn(tun->dev, > - "%s: using disabled UFO feature; please fix this program\n", > - current->comm); > - } > skb_shinfo(skb)->gso_type = SKB_GSO_UDP; > break; > - } > default: > tun->dev->stats.rx_frame_errors++; > kfree_skb(skb); > @@ -1294,6 +1284,8 @@ static ssize_t tun_put_user(struct tun_struct *tun, > gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; > else if (sinfo->gso_type & SKB_GSO_TCPV6) > gso.gso_type = VIRTIO_NET_HDR_GSO_TCPV6; > + else if (sinfo->gso_type & SKB_GSO_UDP) > + gso.gso_type = VIRTIO_NET_HDR_GSO_UDP; > else { > pr_err("unexpected GSO type: " > "0x%x, gso_size %d, hdr_len %d\n", > @@ -1742,6 +1734,11 @@ static int set_offload(struct tun_struct *tun, unsigned long arg) > features |= NETIF_F_TSO6; > arg &= ~(TUN_F_TSO4|TUN_F_TSO6); > } > + > + if (arg & TUN_F_UFO) { > + features |= NETIF_F_UFO; > + arg &= ~TUN_F_UFO; > + } > } > > /* This gives the user a way to test for new features in future by > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > index 5ca9771..059fdf1 100644 > --- a/drivers/net/virtio_net.c > +++ b/drivers/net/virtio_net.c > @@ -490,17 +490,8 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq, > skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4; > break; > case VIRTIO_NET_HDR_GSO_UDP: > - { > - static bool warned; > - > - if (!warned) { > - warned = true; > - netdev_warn(dev, > - "host using disabled UFO feature; please fix it\n"); > - } > skb_shinfo(skb)->gso_type = SKB_GSO_UDP; > break; > - } > case VIRTIO_NET_HDR_GSO_TCPV6: > skb_shinfo(skb)->gso_type = SKB_GSO_TCPV6; > break; > @@ -888,6 +879,8 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb) > hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV4; > else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) > hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_TCPV6; > + else if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) > + hdr->hdr.gso_type = VIRTIO_NET_HDR_GSO_UDP; > else > BUG(); > if (skb_shinfo(skb)->gso_type & SKB_GSO_TCP_ECN) > @@ -1748,7 +1741,7 @@ static int virtnet_probe(struct virtio_device *vdev) > dev->features |= NETIF_F_HW_CSUM|NETIF_F_SG|NETIF_F_FRAGLIST; > > if (virtio_has_feature(vdev, VIRTIO_NET_F_GSO)) { > - dev->hw_features |= NETIF_F_TSO > + dev->hw_features |= NETIF_F_TSO | NETIF_F_UFO > | NETIF_F_TSO_ECN | NETIF_F_TSO6; > } > /* Individual feature bits: what can host handle? */ > @@ -1758,9 +1751,11 @@ static int virtnet_probe(struct virtio_device *vdev) > dev->hw_features |= NETIF_F_TSO6; > if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_ECN)) > dev->hw_features |= NETIF_F_TSO_ECN; > + if (virtio_has_feature(vdev, VIRTIO_NET_F_HOST_UFO)) > + dev->hw_features |= NETIF_F_UFO; > > if (gso) > - dev->features |= dev->hw_features & NETIF_F_ALL_TSO; > + dev->features |= dev->hw_features & (NETIF_F_ALL_TSO|NETIF_F_UFO); > /* (!csum && gso) case will be fixed by register_netdev() */ > } > if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM)) > @@ -1798,7 +1793,8 @@ static int virtnet_probe(struct virtio_device *vdev) > /* If we can receive ANY GSO packets, we must allocate large ones. */ > if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) || > virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6) || > - virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN)) > + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_ECN) || > + virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_UFO)) > vi->big_packets = true; > > if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) > @@ -1994,9 +1990,9 @@ static struct virtio_device_id id_table[] = { > static unsigned int features[] = { > VIRTIO_NET_F_CSUM, VIRTIO_NET_F_GUEST_CSUM, > VIRTIO_NET_F_GSO, VIRTIO_NET_F_MAC, > - VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_TSO6, > + VIRTIO_NET_F_HOST_TSO4, VIRTIO_NET_F_HOST_UFO, VIRTIO_NET_F_HOST_TSO6, > VIRTIO_NET_F_HOST_ECN, VIRTIO_NET_F_GUEST_TSO4, VIRTIO_NET_F_GUEST_TSO6, > - VIRTIO_NET_F_GUEST_ECN, > + VIRTIO_NET_F_GUEST_ECN, VIRTIO_NET_F_GUEST_UFO, > VIRTIO_NET_F_MRG_RXBUF, VIRTIO_NET_F_STATUS, VIRTIO_NET_F_CTRL_VQ, > VIRTIO_NET_F_CTRL_RX, VIRTIO_NET_F_CTRL_VLAN, > VIRTIO_NET_F_GUEST_ANNOUNCE, VIRTIO_NET_F_MQ, > -- > 1.9.3
Michael S. Tsirkin
2015-Jan-31 17:17 UTC
[PATCH v2 0/3] Restore UFO support to virtio_net devices
On Fri, Jan 30, 2015 at 02:27:24PM -0500, Vladislav Yasevich wrote:> commit 3d0ad09412ffe00c9afa201d01effdb6023d09b4 > Author: Ben Hutchings <ben at decadent.org.uk> > Date: Thu Oct 30 18:27:12 2014 +0000 > > drivers/net: Disable UFO through virtio > > Turned off UFO support to virtio-net based devices due to issues > with IPv6 fragment id generation for UFO packets. The issue > was that IPv6 UFO/GSO implementation expects the fragment id > to be supplied in skb_shinfo(). However, for packets generated > by the VMs, the fragment id is not supplied which causes all > IPv6 fragments to have the id of 0. > > The problem is that turning off UFO support on tap/macvtap > as well as virtio devices caused issues with migrations. > Migrations would fail when moving a vm from a kernel supporting > expecting UFO to work to the newer kernels that disabled UFO. > > This series provides a partial solution to address the migration > issue. The series allows us to track whether skb_shinfo()->ip6_frag_id > has been set by treating value of 0 as unset. > This lets GSO code to generate fragment ids if they are necessary > (ex: packet was generated by VM or packet socket). > > Since v1: > - Removed the skb bit and use value of 0 as tracker. > - Used Eric's suggestion to set fragment id as 0x80000000 if id > generation procedure yeilded a 0 result. > - Consolidated ipv6 id genration code.Looks good to me Acked-by: Michael S. Tsirkin <mst at redhat.com> Seems appropriate for stable as well.> Vladislav Yasevich (3): > ipv6: Select fragment id during UFO segmentation if not set. > Revert "drivers/net, ipv6: Select IPv6 fragment idents for virtio UFO > packets" > Revert "drivers/net: Disable UFO through virtio" > > drivers/net/macvtap.c | 16 ++++++++-------- > drivers/net/tun.c | 25 +++++++++---------------- > drivers/net/virtio_net.c | 24 ++++++++++-------------- > include/net/ipv6.h | 3 +++ > net/ipv6/ip6_output.c | 10 ++++------ > net/ipv6/output_core.c | 28 ++++++++++++++++++++++------ > net/ipv6/udp_offload.c | 10 +++++++++- > 7 files changed, 65 insertions(+), 51 deletions(-) > > -- > 1.9.3
David Miller
2015-Feb-02 06:19 UTC
[PATCH v2 0/3] Restore UFO support to virtio_net devices
From: Vladislav Yasevich <vyasevich at gmail.com> Date: Fri, 30 Jan 2015 14:27:24 -0500> commit 3d0ad09412ffe00c9afa201d01effdb6023d09b4 > Author: Ben Hutchings <ben at decadent.org.uk> > Date: Thu Oct 30 18:27:12 2014 +0000 > > drivers/net: Disable UFO through virtio > > Turned off UFO support to virtio-net based devices due to issues > with IPv6 fragment id generation for UFO packets. The issue > was that IPv6 UFO/GSO implementation expects the fragment id > to be supplied in skb_shinfo(). However, for packets generated > by the VMs, the fragment id is not supplied which causes all > IPv6 fragments to have the id of 0. > > The problem is that turning off UFO support on tap/macvtap > as well as virtio devices caused issues with migrations. > Migrations would fail when moving a vm from a kernel supporting > expecting UFO to work to the newer kernels that disabled UFO. > > This series provides a partial solution to address the migration > issue. The series allows us to track whether skb_shinfo()->ip6_frag_id > has been set by treating value of 0 as unset. > This lets GSO code to generate fragment ids if they are necessary > (ex: packet was generated by VM or packet socket). > > Since v1: > - Removed the skb bit and use value of 0 as tracker. > - Used Eric's suggestion to set fragment id as 0x80000000 if id > generation procedure yeilded a 0 result. > - Consolidated ipv6 id genration code.Series applied and queued up for -stable. There was some trailing whitespace in patch #1, which I fixed up.
David Miller
2015-Feb-02 06:28 UTC
[PATCH v2 0/3] Restore UFO support to virtio_net devices
From: David Miller <davem at davemloft.net> Date: Sun, 01 Feb 2015 22:19:35 -0800 (PST)> Series applied and queued up for -stable.I have to revert, this breaks the build. net/built-in.o: In function `udp6_ufo_fragment': udp_offload.c:(.text+0x103380): undefined reference to `ipv6_select_ident'
Seemingly Similar Threads
- [PATCH v3 net 1/3] ipv6: Select fragment id during UFO segmentation if not set.
- [PATCH v3 net 1/3] ipv6: Select fragment id during UFO segmentation if not set.
- [PATCH v2 1/3] ipv6: Select fragment id during UFO segmentation if not set.
- [PATCH 1/3] ipv6: Select fragment id during UFO/GSO segmentation if not set.
- [PATCH 1/3] ipv6: Select fragment id during UFO/GSO segmentation if not set.