drivers/net,ipv6: Fix IPv6 fragment ID selection for virtio
Subsystems (6)
v2 cover drivers/net,ipv6: Fix IPv6 fragment ID selection for virtio
The virtio net protocol supports UFO but does not provide for passing a fragment ID for fragmentation of IPv6 packets. We used to generate a fragment ID wherever such a packet was fragmented, but currently we always use ID=0!
v2: Add blank lines after declarations
Ben.
Ben Hutchings (2):
drivers/net: Disable UFO through virtio
drivers/net,ipv6: Select IPv6 fragment idents for virtio UFO packets
drivers/net/macvtap.c | 16 ++++++++-------- drivers/net/tun.c | 25 ++++++++++++++++--------- drivers/net/virtio_net.c | 24 ++++++++++++++---------- include/net/ipv6.h | 2 ++ net/ipv6/output_core.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 27 deletions(-)
Signature · 2 lines
Ben Hutchings The program is absolutely right; therefore, the computer must be wrong.
PATCH v2 1/2 drivers/net: Disable UFO through virtio
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol.
Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse.
Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and virtio_net completely until we have a proper solution.
We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this.
--- drivers/net/macvtap.c | 13 +++++-------- drivers/net/tun.c | 19 +++++++++++-------- drivers/net/virtio_net.c | 24 ++++++++++++++---------- 3 files changed, 30 insertions(+), 26 deletions(-)
drivers/net/macvtap.c +5 -8
@@ -65,7 +65,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_UFO) + NETIF_F_TSO6)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)#define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG)
@@ -569,6 +569,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb, 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 :
@@ -614,8 +616,6 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb, 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; elseBUG ();if (sinfo->gso_type &SKB_GSO_TCP_ECN )
@@ -950,9 +950,6 @@ 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
@@ -963,7 +960,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 |NETIF_F_UFO )) +if (feature_mask & (NETIF_F_TSO |NETIF_F_TSO6 )) features |=RX_OFFLOADS ;else features &= ~RX_OFFLOADS ;
@@ -1064,7 +1061,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_UFO )) +TUN_F_TSO_ECN ))return -EINVAL ;rtnl_lock ();
drivers/net/tun.c +11 -8
@@ -174,7 +174,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_UFO) + NETIF_F_TSO6)int vnet_hdr_sz;int sndbuf;
@@ -1149,8 +1149,18 @@ 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);
@@ -1251,8 +1261,6 @@ 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",
@@ -1762,11 +1770,6 @@ 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
drivers/net/virtio_net.c +14 -10
@@ -491,8 +491,17 @@ static void receive_buf(struct receive_queue *rq, void *buf, unsigned int len)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 ;
@@ -881,8 +890,6 @@ 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; elseBUG ();if (skb_shinfo (skb)->gso_type &SKB_GSO_TCP_ECN )
@@ -1705,7 +1712,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 |NETIF_F_UFO + dev->hw_features |=NETIF_F_TSO |NETIF_F_TSO_ECN |NETIF_F_TSO6 ; }/* Individual feature bits: what can host handle? */
@@ -1715,11 +1722,9 @@ 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 |NETIF_F_UFO ); + dev->features |= dev->hw_features &NETIF_F_ALL_TSO ;/* (!csum && gso) case will be fixed by register_netdev() */ }if (virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_CSUM ))
@@ -1757,8 +1762,7 @@ 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_UFO )) +virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_ECN )) vi->big_packets = true;if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF ))
@@ -1952,9 +1956,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_UFO ,VIRTIO_NET_F_HOST_TSO6 , +VIRTIO_NET_F_HOST_TSO4 ,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_UFO , +VIRTIO_NET_F_GUEST_ECN ,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 ,
Signature · 2 lines
Ben Hutchings The program is absolutely right; therefore, the computer must be wrong.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
drivers/net/tun.c static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · line 1160
Quoted 10 lines · Ben Hutchings
drivers/net/tun.c +9
-0+ { +static bool warned; + +if (!warned) { + warned = true; +netdev_warn (tun->dev, +"%s: using disabled UFO feature; please fix this program\n" , + current->comm); + }
It might be time to add netdev_warn_once() ;)
Alternatively, you could use
pr_warn_once("%s: using disabled UFO feature; please fix this program\n",
tun->dev->name, current->comm);Re: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
Quoted 15 lines · Eric Dumazet
drivers/net/tun.c static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, · line 1160
Quoted 10 lines · Ben Hutchings
drivers/net/tun.c +9
-0+ { +static bool warned; + +if (!warned) { + warned = true; +netdev_warn (tun->dev, +"%s: using disabled UFO feature; please fix this program\n" , + current->comm); + }It might be time to add
netdev_warn_once();)
Could do. I'm trying to make small fixes that are suitable for stable.
Quoted 3 lines
Alternatively, you could use
pr_warn_once("%s: using disabled UFO feature; please fix this program\n", tun->dev->name, current->comm);
That's missing a "%s: ", but yes that would also work.
Ben.
Signature · 2 lines
Ben Hutchings The program is absolutely right; therefore, the computer must be wrong.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
Quoted 1 line · Ben Hutchings
Could do. I'm trying to make small fixes that are suitable for stable.
Oh right, makes sense ;)
Michael S. Tsirkin
maintainerRe: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
In reply to Ben HutchingsQuoted 13 lines · Ben Hutchings
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol.
Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse.
Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and
virtio_netcompletely until we have a proper solution.
Quoted 6 lines
We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this.
Signed-off-by Ben Hutchings <[email protected]>Fixes 916e4cf46d02 ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data")
There's something I don't understand here. I see:
NETIF_F_UFO_BIT, /* ... UDPv4 fragmentation */
this comment is wrong then?
The patches drastically regress performance for UDPv4 for VMs only, but isn't it likely many other devices based their code on this comment?
How about we disable UFO for IPv6 globally, and put the flag back in?
We can then gradually add NETIF_F_UFO6_BIT for devices that actually support UFO for IPv6.
Thoughts?
Quoted 205 lines
--- drivers/net/macvtap.c | 13 +++++-------- drivers/net/tun.c | 19 +++++++++++-------- drivers/net/virtio_net.c | 24 ++++++++++++++---------- 3 files changed, 30 insertions(+), 26 deletions(-)drivers/net/macvtap.c +5
-8@@ -65,7 +65,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_UFO) + NETIF_F_TSO6)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)#define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG)@@ -569,6 +569,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb, 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 :@@ -614,8 +616,6 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb, 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; elseBUG ();if (sinfo->gso_type &SKB_GSO_TCP_ECN )@@ -950,9 +950,6 @@ 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 @@ -963,7 +960,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 |NETIF_F_UFO )) +if (feature_mask & (NETIF_F_TSO |NETIF_F_TSO6 )) features |=RX_OFFLOADS ;else features &= ~RX_OFFLOADS ;@@ -1064,7 +1061,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_UFO )) +TUN_F_TSO_ECN ))return -EINVAL ;rtnl_lock ();drivers/net/tun.c +11
-8@@ -174,7 +174,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_UFO) + NETIF_F_TSO6)int vnet_hdr_sz;int sndbuf;@@ -1149,8 +1149,18 @@ 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);@@ -1251,8 +1261,6 @@ 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",@@ -1762,11 +1770,6 @@ 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 drivers/net/virtio_net.c +14
-10@@ -491,8 +491,17 @@ static void receive_buf(struct receive_queue *rq, void *buf, unsigned int len)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 ;@@ -881,8 +890,6 @@ 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; elseBUG ();if (skb_shinfo (skb)->gso_type &SKB_GSO_TCP_ECN )@@ -1705,7 +1712,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 |NETIF_F_UFO + dev->hw_features |=NETIF_F_TSO |NETIF_F_TSO_ECN |NETIF_F_TSO6 ; }/* Individual feature bits: what can host handle? */ @@ -1715,11 +1722,9 @@ 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 |NETIF_F_UFO ); + dev->features |= dev->hw_features &NETIF_F_ALL_TSO ;/* (!csum && gso) case will be fixed by register_netdev() */ }if (virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_CSUM ))@@ -1757,8 +1762,7 @@ 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_UFO )) +virtio_has_feature (vdev,VIRTIO_NET_F_GUEST_ECN )) vi->big_packets = true;if (virtio_has_feature (vdev,VIRTIO_NET_F_MRG_RXBUF ))@@ -1952,9 +1956,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_UFO ,VIRTIO_NET_F_HOST_TSO6 , +VIRTIO_NET_F_HOST_TSO4 ,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_UFO , +VIRTIO_NET_F_GUEST_ECN ,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 ,Signature · 10 lines
-- Ben Hutchings The program is absolutely right; therefore, the computer must be wrong. _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
Quoted 18 lines · Michael S. Tsirkin
Quoted 17 lines · Ben Hutchings
Quoted 17 lines
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol.
Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse.
Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and
virtio_netcompletely until we have a proper solution.We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Signed-off-by Ben Hutchings <[email protected]>Fixes 916e4cf46d02 ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data")There's something I don't understand here. I see:
NETIF_F_UFO_BIT, /* ... UDPv4 fragmentation */this comment is wrong then?
Looks wrong, at least ufo6 depends check this bit in ip6_output.c
Re: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
In reply to Michael S. TsirkinQuoted 22 lines · Michael S. Tsirkin
Quoted 13 lines · Ben Hutchings
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol.
Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse.
Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and
virtio_netcompletely until we have a proper solution.Quoted 6 lines
We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this.
Signed-off-by Ben Hutchings <[email protected]>Fixes 916e4cf46d02 ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data")
Quoted 5 lines
There's something I don't understand here. I see:
NETIF_F_UFO_BIT, /* ... UDPv4 fragmentation */this comment is wrong then?
Yes.
Quoted 2 lines
The patches drastically regress performance for UDPv4 for VMs only, but isn't it likely many other devices based their code on this comment?
There's only one hardware driver that implements UFO (s2io), and it does handle IPv6.
Quoted 4 lines
How about we disable UFO for IPv6 globally, and put the flag back in?
We can then gradually addNETIF_F_UFO6_BITfor devices that actually support UFO for IPv6.
Since the corresponding virtio feature bit is understood to include UFO/IPv6, and existing VMs rely on that, I don't see what this solves.
Ben.
Signature · 3 lines
Ben Hutchings Beware of bugs in the above code; I have only proved it correct, not tried it. - Donald Knuth
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH v2 net 1/2] drivers/net: Disable UFO through virtio
Quoted 42 lines · Ben Hutchings
Quoted 22 lines · Michael S. Tsirkin
Quoted 13 lines · Ben Hutchings
IPv6 does not allow fragmentation by routers, so there is no fragmentation ID in the fixed header. UFO for IPv6 requires the ID to be passed separately, but there is no provision for this in the virtio net protocol.
Until recently our software implementation of UFO/IPv6 generated a new ID, but this was a bug. Now we will use ID=0 for any UFO/IPv6 packet passed through a tap, which is even worse.
Unfortunately there is no distinction between UFO/IPv4 and v6 features, so disable UFO on taps and
virtio_netcompletely until we have a proper solution.Quoted 6 lines
We cannot depend on VM managers respecting the tap feature flags, so keep accepting UFO packets but log a warning the first time we do this.
Signed-off-by Ben Hutchings <[email protected]>Fixes 916e4cf46d02 ("ipv6: reuse ip6_frag_id from ip6_ufo_append_data")Quoted 5 lines
There's something I don't understand here. I see:
NETIF_F_UFO_BIT, /* ... UDPv4 fragmentation */this comment is wrong then?
Yes.
Quoted 2 lines
The patches drastically regress performance for UDPv4 for VMs only, but isn't it likely many other devices based their code on this comment?
There's only one hardware driver that implements UFO (s2io), and it does handle IPv6.
Quoted 4 lines
How about we disable UFO for IPv6 globally, and put the flag back in?
We can then gradually addNETIF_F_UFO6_BITfor devices that actually support UFO for IPv6.
Quoted 4 lines
Since the corresponding virtio feature bit is understood to include UFO/IPv6, and existing VMs rely on that, I don't see what this solves.
Ben.
I'm confused. Patching virtio has 0 effect on existing VMs - they are running old drivers anyway.
Here's the proposal for guest side:
- Add NETIF_F_UFO6_BIT, set in s2io.
- Teach IPv6 to check NETIF_F_UFO6_BIT and not NETIF_F_UFO_BIT.
What is accomplishes is good speed for virtio with UDP over IPv4, and correct, slower transmission for IPv6.
Of course this does not help old guests but your patch to which I'm replying doesn't affect old guests either.
Or did I miss something?
Quoted 4 lines
Signature · 3 lines
Ben Hutchings Beware of bugs in the above code; I have only proved it correct, not tried it. - Donald Knuth
PATCH v2 2/2 drivers/net,ipv6: Select IPv6 fragment idents for virtio UFO packets
In reply to Ben HutchingsUFO is now disabled on all drivers that work with virtio net headers, but userland may try to send UFO/IPv6 packets anyway. Instead of sending with ID=0, we should select identifiers on their behalf (as we used to).
--- drivers/net/macvtap.c | 3 +++ drivers/net/tun.c | 6 +++++- include/net/ipv6.h | 2 ++ net/ipv6/output_core.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-)
drivers/net/macvtap.c +3 -0
@@ -16,6 +16,7 @@#include <linux/idr.h> #include <linux/fs.h> +#include <net/ipv6.h> #include <net/net_namespace.h> #include <net/rtnetlink.h> #include <net/sock.h>
@@ -572,6 +573,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,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 ;
drivers/net/tun.c +5 -1
@@ -65,6 +65,7 @@#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>
@@ -1139,6 +1140,8 @@ 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 ) {
@@ -1159,6 +1162,8 @@ 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 :
@@ -1189,7 +1194,6 @@ 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);
include/net/ipv6.h +2 -0
@@ -671,6 +671,8 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addreturn __ipv6_addr_diff (a1, a2,sizeof (struct in6_addr )); } +void ipv6_proxy_select_ident (struct sk_buff *skb); +int ip6_dst_hoplimit (struct dst_entry *dst); static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
net/ipv6/output_core.c +34 -0
@@ -3,11 +3,45 @@* not configured or static. These functions are needed by GSO/GRO implementation. */ #include <linux/export.h> +#include <net/ip.h> #include <net/ipv6.h> #include <net/ip6_fib.h> #include <net/addrconf.h> #include <net/secure_seq.h> +/* This function exists only for tap drivers that must support broken +* clients requesting UFO without specifying an IPv6 fragment ID. +* +* This is similar to ipv6_select_ident() but we use an independent hash +* seed to limit information leakage. +* +* The network header must be set before calling this. +*/ +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; + + addrs =skb_header_pointer (skb, +skb_network_offset (skb) + + offsetof(struct ipv6hdr , saddr), +sizeof (buf), buf); +if (!addrs) +return ; + +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); +} +EXPORT_SYMBOL_GPL (ipv6_proxy_select_ident); +int ip6_find_1stfragopt (struct sk_buff *skb,u8 **nexthdr) {u16 offset =sizeof (struct ipv6hdr );
Signature · 2 lines
Ben Hutchings The program is absolutely right; therefore, the computer must be wrong.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
PATCH v2 2/2 drivers/net,ipv6: Select IPv6 fragment idents for virtio UFO packets
In reply to Ben HutchingsUFO is now disabled on all drivers that work with virtio net headers, but userland may try to send UFO/IPv6 packets anyway. Instead of sending with ID=0, we should select identifiers on their behalf (as we used to).
--- drivers/net/macvtap.c | 3 +++ drivers/net/tun.c | 6 +++++- include/net/ipv6.h | 2 ++ net/ipv6/output_core.c | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-)
drivers/net/macvtap.c +3 -0
@@ -16,6 +16,7 @@#include <linux/idr.h> #include <linux/fs.h> +#include <net/ipv6.h> #include <net/net_namespace.h> #include <net/rtnetlink.h> #include <net/sock.h>
@@ -572,6 +573,8 @@ static int macvtap_skb_from_vnet_hdr(struct sk_buff *skb,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 ;
drivers/net/tun.c +5 -1
@@ -65,6 +65,7 @@#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>
@@ -1139,6 +1140,8 @@ 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 ) {
@@ -1159,6 +1162,8 @@ 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 :
@@ -1189,7 +1194,6 @@ 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);
include/net/ipv6.h +2 -0
@@ -671,6 +671,8 @@ static inline int ipv6_addr_diff(const struct in6_addr *a1, const struct in6_addreturn __ipv6_addr_diff (a1, a2,sizeof (struct in6_addr )); } +void ipv6_proxy_select_ident (struct sk_buff *skb); +int ip6_dst_hoplimit (struct dst_entry *dst); static inline int ip6_sk_dst_hoplimit(struct ipv6_pinfo *np, struct flowi6 *fl6,
net/ipv6/output_core.c +34 -0
@@ -3,11 +3,45 @@* not configured or static. These functions are needed by GSO/GRO implementation. */ #include <linux/export.h> +#include <net/ip.h> #include <net/ipv6.h> #include <net/ip6_fib.h> #include <net/addrconf.h> #include <net/secure_seq.h> +/* This function exists only for tap drivers that must support broken +* clients requesting UFO without specifying an IPv6 fragment ID. +* +* This is similar to ipv6_select_ident() but we use an independent hash +* seed to limit information leakage. +* +* The network header must be set before calling this. +*/ +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; + + addrs =skb_header_pointer (skb, +skb_network_offset (skb) + + offsetof(struct ipv6hdr , saddr), +sizeof (buf), buf); +if (!addrs) +return ; + +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); +} +EXPORT_SYMBOL_GPL (ipv6_proxy_select_ident); +int ip6_find_1stfragopt (struct sk_buff *skb,u8 **nexthdr) {u16 offset =sizeof (struct ipv6hdr );
Signature · 2 lines
Ben Hutchings The program is absolutely right; therefore, the computer must be wrong.
David Miller
maintainerFrom: Ben Hutchings <[email protected]>
Date: Thu, 30 Oct 2014 18:26:32 +0000
Quoted 6 lines
The virtio net protocol supports UFO but does not provide for passing a fragment ID for fragmentation of IPv6 packets. We used to generate a fragment ID wherever such a packet was fragmented, but currently we always use ID=0!
v2: Add blank lines after declarations
Series applied and queued up for -stable, thanks Ben.