Skip to contentSkip to conversation

virtio-net: disable guest csum during XDP set

PATCH In review Jason Wang 2 participants 9 messages Nov 22, 2018 – Nov 26, 2018

Subsystems (4)
lore
Share & tools
lore
author
#1 lore raw

PATCH 2/2 virtio-net: fail XDP set if guest csum is negotiated

In reply to Jason Wang

We don't support partial csumed packet since its metadata will be lost or incorrect during XDP processing. So fail the XDP set if guest_csum feature is negotiated.

Fixes f600b6905015 ("virtio_net: Add XDP support")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>
---
 drivers/net/virtio_net.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +3 -2
index 9b5ace538824..cecfd77c9f3c 100644
@@ -2361,8 +2361,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 	    && (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) ||
 	        virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) ||
 	        virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) ||
-		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO))) {
-		NL_SET_ERR_MSG_MOD(extack, "Can't set XDP while host is implementing LRO, disable LRO first");
+		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) ||
+		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM))) {
+		NL_SET_ERR_MSG_MOD(extack, "Can't set XDP while host is implementing LRO/CSUM, disable LRO/CSUM first");
 		return -EOPNOTSUPP;
 	}
 
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 2/2 virtio-net: fail XDP set if guest csum is negotiated

In reply to Jason Wang

We don't support partial csumed packet since its metadata will be lost or incorrect during XDP processing. So fail the XDP set if guest_csum feature is negotiated.

Fixes f600b6905015 ("virtio_net: Add XDP support")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>
---
 drivers/net/virtio_net.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/virtio_net.c +3 -2
index 9b5ace538824..cecfd77c9f3c 100644
@@ -2361,8 +2361,9 @@ static int virtnet_xdp_set(struct net_device *dev, struct bpf_prog *prog,
 	    && (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO4) ||
 	        virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_TSO6) ||
 	        virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_ECN) ||
-		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO))) {
-		NL_SET_ERR_MSG_MOD(extack, "Can't set XDP while host is implementing LRO, disable LRO first");
+		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_UFO) ||
+		virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM))) {
+		NL_SET_ERR_MSG_MOD(extack, "Can't set XDP while host is implementing LRO/CSUM, disable LRO/CSUM first");
 		return -EOPNOTSUPP;
 	}
 
Signature · 1 line
2.17.1

Jason Wang

author
#0 lore raw

PATCH 1/2 virtio-net: disable guest csum during XDP set

We don't disable VIRTIO_NET_F_GUEST_CSUM if XDP was set. This means we can receive partial csumed packets with metadata kept in the vnet_hdr. This may have several side effects:

- It could be overridden by header adjustment, thus is might be not correct after XDP processing.
- There's no way to pass such metadata information through XDP_REDIRECT to another driver.
- XDP does not support checksum offload right now.

So simply disable guest csum if possible in this the case of XDP.

Fixes 3f93522ffab2d ("virtio-net: switch off offloads on demand if possible on XDP set")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>
---
 drivers/net/virtio_net.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/virtio_net.c +2 -6
index 3e2c041d76ac..9b5ace538824 100644
@@ -70,7 +70,8 @@ static const unsigned long guest_offloads[] = {
 	VIRTIO_NET_F_GUEST_TSO4,
 	VIRTIO_NET_F_GUEST_TSO6,
 	VIRTIO_NET_F_GUEST_ECN,
-	VIRTIO_NET_F_GUEST_UFO
+	VIRTIO_NET_F_GUEST_UFO,
+	VIRTIO_NET_F_GUEST_CSUM
 };
 
 struct virtnet_stat_desc {
@@ -2334,9 +2335,6 @@ static int virtnet_clear_guest_offloads(struct virtnet_info *vi)
 	if (!vi->guest_offloads)
 		return 0;
 
-	if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM))
-		offloads = 1ULL << VIRTIO_NET_F_GUEST_CSUM;
-
 	return virtnet_set_guest_offloads(vi, offloads);
 }
 
@@ -2346,8 +2344,6 @@ static int virtnet_restore_guest_offloads(struct virtnet_info *vi)
 
 	if (!vi->guest_offloads)
 		return 0;
-	if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_GUEST_CSUM))
-		offloads |= 1ULL << VIRTIO_NET_F_GUEST_CSUM;
 
 	return virtnet_set_guest_offloads(vi, offloads);
 }
Signature · 1 line
2.17.1
maintainer
#5 lore raw

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:30 +0800

Quoted 10 lines

We don't disable VIRTIO_NET_F_GUEST_CSUM if XDP was set. This means we can receive partial csumed packets with metadata kept in the vnet_hdr. This may have several side effects:

- It could be overridden by header adjustment, thus is might be not correct after XDP processing.
- There's no way to pass such metadata information through XDP_REDIRECT to another driver.
- XDP does not support checksum offload right now.

Quoted 8 lines

So simply disable guest csum if possible in this the case of XDP.

Fixes 3f93522ffab2d ("virtio-net: switch off offloads on demand if possible on XDP set")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>

Applied and queued up for -stable.

We really should have a way to use the checksum provided if the XDP program returns XDP_PASS and does not modify the packet contents or size.

maintainer
#8 lore raw
In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:30 +0800

Quoted 10 lines

We don't disable VIRTIO_NET_F_GUEST_CSUM if XDP was set. This means we can receive partial csumed packets with metadata kept in the vnet_hdr. This may have several side effects:

- It could be overridden by header adjustment, thus is might be not correct after XDP processing.
- There's no way to pass such metadata information through XDP_REDIRECT to another driver.
- XDP does not support checksum offload right now.

Quoted 8 lines

So simply disable guest csum if possible in this the case of XDP.

Fixes 3f93522ffab2d ("virtio-net: switch off offloads on demand if possible on XDP set")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>

Applied and queued up for -stable.

We really should have a way to use the checksum provided if the XDP program returns XDP_PASS and does not modify the packet contents or size.

maintainer
#2 lore raw

Re: [PATCH net 2/2] virtio-net: fail XDP set if guest csum is negotiated

In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:31 +0800

Quoted 10 lines

We don't support partial csumed packet since its metadata will be lost or incorrect during XDP processing. So fail the XDP set if guest_csum feature is negotiated.

Fixes f600b6905015 ("virtio_net: Add XDP support")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>

Applied and queued up for -stable.

Same comments as for patch #1.

maintainer
#3 lore raw

Re: [PATCH net 2/2] virtio-net: fail XDP set if guest csum is negotiated

In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:31 +0800

Quoted 10 lines

We don't support partial csumed packet since its metadata will be lost or incorrect during XDP processing. So fail the XDP set if guest_csum feature is negotiated.

Fixes f600b6905015 ("virtio_net: Add XDP support")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>

Applied and queued up for -stable.

Same comments as for patch #1.

author
#6 lore raw
In reply to David Miller
Quoted 21 lines · David Miller

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:30 +0800

Quoted 10 lines

We don't disable VIRTIO_NET_F_GUEST_CSUM if XDP was set. This means we can receive partial csumed packets with metadata kept in the vnet_hdr. This may have several side effects:

- It could be overridden by header adjustment, thus is might be not correct after XDP processing.
- There's no way to pass such metadata information through XDP_REDIRECT to another driver.
- XDP does not support checksum offload right now.

Quoted 8 lines

So simply disable guest csum if possible in this the case of XDP.

Fixes 3f93522ffab2d ("virtio-net: switch off offloads on demand if possible on XDP set")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>
Quoted 5 lines

Applied and queued up for -stable.

We really should have a way to use the checksum provided if the XDP program returns XDP_PASS and does not modify the packet contents or size.

Yes, I think this may require the assistance of BPF verifier to set a flag or other. Then we can assume the metadata is safe to use.

Thanks

author
#7 lore raw
In reply to David Miller
Quoted 21 lines · David Miller

From: Jason Wang <[email protected]>
Date: Thu, 22 Nov 2018 14:36:30 +0800

Quoted 10 lines

We don't disable VIRTIO_NET_F_GUEST_CSUM if XDP was set. This means we can receive partial csumed packets with metadata kept in the vnet_hdr. This may have several side effects:

- It could be overridden by header adjustment, thus is might be not correct after XDP processing.
- There's no way to pass such metadata information through XDP_REDIRECT to another driver.
- XDP does not support checksum offload right now.

Quoted 8 lines

So simply disable guest csum if possible in this the case of XDP.

Fixes 3f93522ffab2d ("virtio-net: switch off offloads on demand if possible on XDP set")
Cc Jesper Dangaard Brouer <[email protected]>
Cc Pavel Popa <[email protected]>
Cc David Ahern <[email protected]>
Quoted 5 lines

Applied and queued up for -stable.

We really should have a way to use the checksum provided if the XDP program returns XDP_PASS and does not modify the packet contents or size.

Yes, I think this may require the assistance of BPF verifier to set a flag or other. Then we can assume the metadata is safe to use.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization