macvtap: Correctly set tap features when IFF_VNET_HDR is disabled.
Subsystems (2)
PATCH v2 1/1 macvtap: Correctly set tap features when IFF_VNET_HDR is disabled.
When the user turns off IFF_VNET_HDR flag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.
To solve, allow processing of TUNSETOFFLOAD when IFF_VNET_HDR is disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update the TUN_FEATURES mask to include all checksum options as the underlying device may have something other then HW_CSUM set.
Change since v1:
- Removed the call to update offloads when IFF_VNET_HDR is turned off.
- Changed the macvtap version of TUN_OFFLOADS to include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads without vnet_hdr support as error.
--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/macvtap.c +7 -5
@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/*
@@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ; +/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; + features = vlan->dev->features;if (arg &TUN_F_CSUM ) {
@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ; -/* TODO: only accept frames with the features that -got enabled for forwarded frames */ -if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock ();
Signature · 1 line
1.8.1.4
Quoted 11 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.
This last looks like a completely unrelated change, does it not?
Would be nice to have it in a separate patchset with some examples of broken configurations.
Quoted 26 lines
Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +1
-1@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/*
drivers/net/macvtap.c static int set_offload(struct macvtap_queue *q, unsigned long arg) · line 1032
Quoted 9 lines
drivers/net/macvtap.c +6
-0@@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ; +/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; +
This function has a single caller so it should matter, but I'm just curious why are you moving the test here from macvtap_ioctl?
drivers/net/macvtap.c static long macvtap_ioctl(struct file *file, unsigned int cmd, · line 1159
Quoted 9 lines
drivers/net/macvtap.c +0
-2features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ; -/* TODO: only accept frames with the features that -got enabled for forwarded frames */
Why do you drop this btw? you disagree we should do this eventually? Maybe a separate patch too.
Quoted 7 lines
drivers/net/macvtap.c +0
-2-if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock ();Signature · 1 line
1.8.1.4
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.
Quoted 4 lines
This last looks like a completely unrelated change, does it not?
Would be nice to have it in a separate patchset with some examples of broken configurations.
sure. can do.
Quoted 30 lines
Quoted 30 lines
Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +1
-1@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/* @@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ;
Quoted 11 lines
drivers/net/macvtap.c static int set_offload(struct macvtap_queue *q, unsigned long arg) · line 1032
Quoted 6 lines
drivers/net/macvtap.c +6
-0+/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; +This function has a single caller so it should matter, but I'm just curious why are you moving the test here from
macvtap_ioctl?
I thought the same thing. I can certainly move it back. Will make the patch smaller.
Quoted 7 lines
Quoted 7 lines
drivers/net/macvtap.c +0
-0features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ;
Quoted 5 lines
drivers/net/macvtap.c static long macvtap_ioctl(struct file *file, unsigned int cmd, · line 1159
Quoted 2 lines
drivers/net/macvtap.c +0
-2-/* TODO: only accept frames with the features that -got enabled for forwarded frames */ Why do you drop this btw? you disagree we should do this eventually? Maybe a separate patch too.
I thought that this comment related to the check for VNET_HDR. I am having a hard time understanding the meaning behind this comment. Is the meaning that if GSO is disabled, we shouldn't accept GSO? This kind the reverse of what we've been doing.
Or is more along the lines of dropping dropping GSO_GRE for now since we don't support that offload function yet?
-vlad
Quoted 8 lines
Quoted 8 lines
drivers/net/macvtap.c +0
-3-if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock (); --1.8.1.4
Quoted 79 lines · Vlad Yasevich
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.Quoted 4 lines
This last looks like a completely unrelated change, does it not?
Would be nice to have it in a separate patchset with some examples of broken configurations.sure. can do.
Quoted 30 lines
Quoted 30 lines
Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +1
-1@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/* @@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ;Quoted 11 lines
drivers/net/macvtap.c static int set_offload(struct macvtap_queue *q, unsigned long arg) · line 1032
Quoted 6 lines
drivers/net/macvtap.c +6
-0+/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; +This function has a single caller so it should matter, but I'm just curious why are you moving the test here from
macvtap_ioctl?I thought the same thing. I can certainly move it back. Will make the patch smaller.
Quoted 7 lines
Quoted 7 lines
drivers/net/macvtap.c +0
-0features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ;Quoted 5 lines
drivers/net/macvtap.c static long macvtap_ioctl(struct file *file, unsigned int cmd, · line 1159
Quoted 2 lines
drivers/net/macvtap.c +0
-2-/* TODO: only accept frames with the features that -got enabled for forwarded frames */ Why do you drop this btw? you disagree we should do this eventually? Maybe a separate patch too.
Quoted 4 lines
I thought that this comment related to the check for
VNET_HDR. I am having a hard time understanding the meaning behind this comment. Is the meaning that if GSO is disabled, we shouldn't accept GSO? This kind the reverse of what we've been doing.
I see, you mean 3e4f8b787370978733ca6cae452720a4f0c296b8 actually addressed this comment?
I think you are right, and we can drop it, though maybe cleaner to do it by a separate patch.
Quoted 4 lines
Or is more along the lines of dropping dropping
GSO_GREfor now since we don't support that offload function yet?-vlad
Confused. What don't we support?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/macvtap.c +0
-3-if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock (); --1.8.1.4
Quoted 4 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.
Just to clarify - is there some userspace that actually triggers this?
Quoted 57 lines
To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +7
-5@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/* @@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ; +/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; + features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ; -/* TODO: only accept frames with the features that -got enabled for forwarded frames */ -if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock ();Signature · 1 line
1.8.1.4
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.Just to clarify - is there some userspace that actually triggers this?
Yes. The configuration that triggers is running windows guest which uses non-virtio driver over macvtap.
The issue is that in non-virtio configuration, libvirt turns off IFF_VNET_HDR support in macvtap. Later, windows guest end up trying to change offload capabilities. Win7 (and others that don't support GSO) will try to turn off offloads and that operation will fail. Thus GSO packets will get queued to the socket without vnet hdr support.
-vlad
Quoted 59 lines
Quoted 59 lines
To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +7
-6@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/* @@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ; +/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; + features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ; -/* TODO: only accept frames with the features that -got enabled for forwarded frames */ -if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock (); --1.8.1.4
Quoted 13 lines · Vlad Yasevich
Quoted 8 lines · Michael S. Tsirkin
Quoted 4 lines · Vlad Yasevich
When the user turns off
IFF_VNET_HDRflag, attempts to change offload features via TUNSETOFFLOAD do not work. This could cause GSO packets to be delivered to the user when the user is not prepared to handle them.Just to clarify - is there some userspace that actually triggers this?
Yes. The configuration that triggers is running windows guest which uses non-virtio driver over macvtap.
Quoted 7 lines
The issue is that in non-virtio configuration, libvirt turns off
IFF_VNET_HDRsupport in macvtap. Later, windows guest end up trying to change offload capabilities. Win7 (and others that don't support GSO) will try to turn off offloads and that operation will fail. Thus GSO packets will get queued to the socket without vnet hdr support.-vlad
OK so I'm guessing the root of the problem is that offloads default to on for macvtap.
Quoted 37 lines
Quoted 37 lines
Quoted 37 lines
To solve, allow processing of TUNSETOFFLOAD when
IFF_VNET_HDRis disabled. Treat any attempt to enable offloads as an error in this case.
We also need to update theTUN_FEATURESmask to include all checksum options as the underlying device may have something other thenHW_CSUMset.Change since v1:
- Removed the call to update offloads whenIFF_VNET_HDRis turned off.
- Changed the macvtap version ofTUN_OFFLOADSto include all checksum offloads since the physical nic may have them set.
- Treat enabling of offloads withoutvnet_hdrsupport as error.Signed-off-by Vlad Yasevich <[email protected]>--- drivers/net/macvtap.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/net/macvtap.c +1
-1@@ -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 | \ +#define TUN_OFFLOADS (NETIF_F_ALL_CSUM | NETIF_F_TSO_ECN | NETIF_F_TSO | \ NETIF_F_TSO6 | NETIF_F_UFO)#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)/* @@ -1024,6 +1024,12 @@ static int set_offload(struct macvtap_queue *q, unsigned long arg)if (!vlan)return -ENOLINK ;
Quoted 6 lines
Quoted 6 lines
drivers/net/macvtap.c static int set_offload(struct macvtap_queue *q, unsigned long arg) · line 1032
Quoted 6 lines
drivers/net/macvtap.c +6
-0+/* If the user is trying to set offloads while IFF_VNET_HDR is +* off, report it as an error. +*/ +if (!(q->flags &IFF_VNET_HDR ) && arg) +return -EINVAL ; +
So now you can disable hdr versus offloads in any order, but you still must first enable hdr and then the offloads. Which looks asymmetrical.
Maybe just drop this completely? You can get an invalid state temporarily but we live with it e.g. for packet sockets.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/net/macvtap.c +0
-5features = vlan->dev->features;if (arg &TUN_F_CSUM ) {@@ -1155,10 +1161,6 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd, TUN_F_TSO_ECN | TUN_F_UFO))return -EINVAL ; -/* TODO: only accept frames with the features that -got enabled for forwarded frames */ -if (!(q->flags &IFF_VNET_HDR )) -return -EINVAL ;rtnl_lock (); ret =set_offload (q, arg);rtnl_unlock (); --1.8.1.4