Skip to contentSkip to conversation

Fix several issues of virtio-net mergeable XDP

PATCH Superseded Jason Wang 2 participants 22 messages May 21, 2018 – May 22, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

cover Fix several issues of virtio-net mergeable XDP

Hi:

Please review the patches that tries to fix sevreal issues of virtio-net mergeable XDP.

Thanks

Jason Wang (4):
virtio-net: correctly redirect linearized packet
virtio-net: correctly transmit XDP buff after linearizing
virtio-net: reset num_buf to 1 after linearizing packet
virito-net: fix leaking page for gso packet during mergeable XDP

 drivers/net/virtio_net.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH 1/4 virtio-net: correctly redirect linearized packet

After a linearized packet was redirected by XDP, we should not go for the err path which will try to pop buffers for the next packet and increase the drop counter. Fixing this by just drop the page refcnt for the original page.

Fixes 186b3c998c50 ("virtio-net: support XDP_REDIRECT")
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 770422e..c15d240 100644
@@ -787,7 +787,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		default:
Signature · 1 line
2.7.4
maintainer Acked-by on v1 1/4
#2 lore raw

Re: [PATCH net 1/4] virtio-net: correctly redirect linearized packet

Quoted 9 lines · Jason Wang

After a linearized packet was redirected by XDP, we should not go for the err path which will try to pop buffers for the next packet and increase the drop counter. Fixing this by just drop the page refcnt for the original page.

Fixes 186b3c998c50 ("virtio-net: support XDP_REDIRECT")
Quoted 19 lines
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 770422e..c15d240 100644
@@ -787,7 +787,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		default:
Signature · 1 line
2.7.4
maintainer Acked-by on v1 1/4
#3 lore raw

Re: [PATCH net 1/4] virtio-net: correctly redirect linearized packet

In reply to Jason Wang
Quoted 9 lines · Jason Wang

After a linearized packet was redirected by XDP, we should not go for the err path which will try to pop buffers for the next packet and increase the drop counter. Fixing this by just drop the page refcnt for the original page.

Fixes 186b3c998c50 ("virtio-net: support XDP_REDIRECT")
Quoted 19 lines
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 770422e..c15d240 100644
@@ -787,7 +787,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		default:
Signature · 1 line
2.7.4
author
#4 lore raw

PATCH 1/4 virtio-net: correctly redirect linearized packet

In reply to Jason Wang

After a linearized packet was redirected by XDP, we should not go for the err path which will try to pop buffers for the next packet and increase the drop counter. Fixing this by just drop the page refcnt for the original page.

Fixes 186b3c998c50 ("virtio-net: support XDP_REDIRECT")
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 770422e..c15d240 100644
@@ -787,7 +787,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		default:
Signature · 1 line
2.7.4
author
#5 lore raw

PATCH 2/4 virtio-net: correctly transmit XDP buff after linearizing

In reply to Jason Wang

We should not go for the error path after successfully transmitting a XDP buffer after linearizing. Since the error path may try to pop and drop next packet and increase the drop counters. Fixing this by simply drop the refcnt of original page and go for xmit path.

Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index c15d240..6260d65 100644
@@ -775,7 +775,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		case XDP_REDIRECT:
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH 2/4 virtio-net: correctly transmit XDP buff after linearizing

In reply to Jason Wang

We should not go for the error path after successfully transmitting a XDP buffer after linearizing. Since the error path may try to pop and drop next packet and increase the drop counters. Fixing this by simply drop the refcnt of original page and go for xmit path.

Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
Cc John Fastabend <[email protected]>
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index c15d240..6260d65 100644
@@ -775,7 +775,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		case XDP_REDIRECT:
Signature · 1 line
2.7.4
maintainer Acked-by on v1 2/4
#7 lore raw

Re: [PATCH net 2/4] virtio-net: correctly transmit XDP buff after linearizing

Quoted 8 lines · Jason Wang

We should not go for the error path after successfully transmitting a XDP buffer after linearizing. Since the error path may try to pop and drop next packet and increase the drop counters. Fixing this by simply drop the refcnt of original page and go for xmit path.

Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
Cc John Fastabend <[email protected]>
Quoted 19 lines
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index c15d240..6260d65 100644
@@ -775,7 +775,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		case XDP_REDIRECT:
Signature · 1 line
2.7.4
maintainer Acked-by on v1 2/4
#8 lore raw

Re: [PATCH net 2/4] virtio-net: correctly transmit XDP buff after linearizing

In reply to Jason Wang
Quoted 8 lines · Jason Wang

We should not go for the error path after successfully transmitting a XDP buffer after linearizing. Since the error path may try to pop and drop next packet and increase the drop counters. Fixing this by simply drop the refcnt of original page and go for xmit path.

Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
Cc John Fastabend <[email protected]>
Quoted 19 lines
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index c15d240..6260d65 100644
@@ -775,7 +775,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			}
 			*xdp_xmit = true;
 			if (unlikely(xdp_page != page))
-				goto err_xdp;
+				put_page(page);
 			rcu_read_unlock();
 			goto xdp_xmit;
 		case XDP_REDIRECT:
Signature · 1 line
2.7.4
author
#9 lore raw

PATCH 3/4 virtio-net: reset num_buf to 1 after linearizing packet

In reply to Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +1 -0
index 6260d65..165a922 100644
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 						      &len);
 			if (!xdp_page)
 				goto err_xdp;
+			num_buf = 1;
 			offset = VIRTIO_XDP_HEADROOM;
 		} else {
 			xdp_page = page;
Signature · 1 line
2.7.4
#10 lore raw

Re: [PATCH net 3/4] virtio-net: reset num_buf to 1 after linearizing packet

Quoted 17 lines · Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +0 -0
index 6260d65..165a922 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 4 lines
drivers/net/virtio_net.c +1 -0
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 						      &len);
 			if (!xdp_page)
 				goto err_xdp;
+			num_buf = 1;

So this is tweaked here for the benefit of err_skb below. That's confusing and we won't remember to change it if we change the error handling.

How about fixing the error path?

- while (--num_buf) {
+ while (num_buf-- > 1) {

Seems more robust to me.

Quoted 5 lines
drivers/net/virtio_net.c +0 -0
 			offset = VIRTIO_XDP_HEADROOM;
 		} else {
 			xdp_page = page;
Signature · 1 line
2.7.4
author
#11 lore raw

Re: [PATCH net 3/4] virtio-net: reset num_buf to 1 after linearizing packet

Quoted 32 lines · Michael S. Tsirkin
Quoted 17 lines · Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
  drivers/net/virtio_net.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +0 -0
index 6260d65..165a922 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 4 lines
drivers/net/virtio_net.c +1 -0
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  						      &len);
  			if (!xdp_page)
  				goto err_xdp;
+			num_buf = 1;

So this is tweaked here for the benefit of err_skb below. That's confusing and we won't remember to change it if we change the error handling.

How about fixing the error path?

(quoted diff) +1 -1
-        while (--num_buf) {
+        while (num_buf-- > 1) {
Quoted 1 line

Seems more robust to me.

Looks good, will do this in V2.

Thanks

Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0 -0
  			offset = VIRTIO_XDP_HEADROOM;
  		} else {
  			xdp_page = page;
Signature · 1 line
2.7.4

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

author
#12 lore raw

Re: [PATCH net 3/4] virtio-net: reset num_buf to 1 after linearizing packet

In reply to Michael S. Tsirkin
Quoted 32 lines · Michael S. Tsirkin
Quoted 17 lines · Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
  drivers/net/virtio_net.c | 1 +
  1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +0 -0
index 6260d65..165a922 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 4 lines
drivers/net/virtio_net.c +1 -0
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  						      &len);
  			if (!xdp_page)
  				goto err_xdp;
+			num_buf = 1;

So this is tweaked here for the benefit of err_skb below. That's confusing and we won't remember to change it if we change the error handling.

How about fixing the error path?

(quoted diff) +1 -1
-        while (--num_buf) {
+        while (num_buf-- > 1) {
Quoted 1 line

Seems more robust to me.

Looks good, will do this in V2.

Thanks

Quoted 6 lines
Quoted 6 lines
drivers/net/virtio_net.c +0 -0
  			offset = VIRTIO_XDP_HEADROOM;
  		} else {
  			xdp_page = page;
Signature · 1 line
2.7.4
#13 lore raw

Re: [PATCH net 3/4] virtio-net: reset num_buf to 1 after linearizing packet

In reply to Jason Wang
Quoted 17 lines · Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +0 -0
index 6260d65..165a922 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 725

Quoted 4 lines
drivers/net/virtio_net.c +1 -0
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 						      &len);
 			if (!xdp_page)
 				goto err_xdp;
+			num_buf = 1;

So this is tweaked here for the benefit of err_skb below. That's confusing and we won't remember to change it if we change the error handling.

How about fixing the error path?

- while (--num_buf) {
+ while (num_buf-- > 1) {

Seems more robust to me.

Quoted 5 lines
drivers/net/virtio_net.c +0 -0
 			offset = VIRTIO_XDP_HEADROOM;
 		} else {
 			xdp_page = page;
Signature · 1 line
2.7.4
author
#14 lore raw

PATCH 3/4 virtio-net: reset num_buf to 1 after linearizing packet

In reply to Jason Wang

If we successfully linearize the packets, num_buf were set to zero which was wrong since we now have only 1 buffer to be used for e.g in the error path of receive_mergeable(). Zero num_buf will lead the code try to pop the buffers of next packet and drop it. Fixing this by set num_buf to 1 if we successfully linearize the packet.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio_net.c +1 -0
index 6260d65..165a922 100644
@@ -722,6 +722,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 						      &len);
 			if (!xdp_page)
 				goto err_xdp;
+			num_buf = 1;
 			offset = VIRTIO_XDP_HEADROOM;
 		} else {
 			xdp_page = page;
Signature · 1 line
2.7.4
author
#15 lore raw

PATCH 4/4 virito-net: fix leaking page for gso packet during mergeable XDP

In reply to Jason Wang

We need to drop refcnt to xdp_page if we see a gso packet. Otherwise it will be leaked. Fixing this by moving the check of gso packet above the linearizing logic.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
---
 drivers/net/virtio_net.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +8 -8
index 165a922..f8db809 100644
@@ -707,6 +707,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		void *data;
 		u32 act;
 
+		/* Transient failure which in theory could occur if
+		 * in-flight packets from before XDP was enabled reach
+		 * the receive path after XDP is loaded. In practice I
+		 * was not able to create this condition.
+		 */
+		if (unlikely(hdr->hdr.gso_type))
+			goto err_xdp;
+
 		/* This happens when rx buffer size is underestimated
 		 * or headroom is not enough because of the buffer
 		 * was refilled before XDP is set. This should only
@@ -728,14 +736,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			xdp_page = page;
 		}
 
-		/* Transient failure which in theory could occur if
-		 * in-flight packets from before XDP was enabled reach
-		 * the receive path after XDP is loaded. In practice I
-		 * was not able to create this condition.
-		 */
-		if (unlikely(hdr->hdr.gso_type))
-			goto err_xdp;
-
 		/* Allow consuming headroom but reserve enough space to push
 		 * the descriptor on if we get an XDP_TX return code.
 		 */
Signature · 1 line
2.7.4
#16 lore raw

Re: [PATCH net 4/4] virito-net: fix leaking page for gso packet during mergeable XDP

Quoted 7 lines · Jason Wang

We need to drop refcnt to xdp_page if we see a gso packet. Otherwise it will be leaked. Fixing this by moving the check of gso packet above the linearizing logic.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")

typo in subject

Quoted 9 lines
---
 drivers/net/virtio_net.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +0 -0
index 165a922..f8db809 100644

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 713

Quoted 7 lines
drivers/net/virtio_net.c +4 -0
@@ -707,6 +707,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		void *data;
 		u32 act;
 
+		/* Transient failure which in theory could occur if
+		 * in-flight packets from before XDP was enabled reach
+		 * the receive path after XDP is loaded. In practice I
+		 * was not able to create this condition.

BTW we should probably drop the last sentence. It says in theory, should be enough.

Quoted 24 lines
drivers/net/virtio_net.c +4 -8
+		 */
+		if (unlikely(hdr->hdr.gso_type))
+			goto err_xdp;
+
 		/* This happens when rx buffer size is underestimated
 		 * or headroom is not enough because of the buffer
 		 * was refilled before XDP is set. This should only
@@ -728,14 +736,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			xdp_page = page;
 		}
 
-		/* Transient failure which in theory could occur if
-		 * in-flight packets from before XDP was enabled reach
-		 * the receive path after XDP is loaded. In practice I
-		 * was not able to create this condition.
-		 */
-		if (unlikely(hdr->hdr.gso_type))
-			goto err_xdp;
-
 		/* Allow consuming headroom but reserve enough space to push
 		 * the descriptor on if we get an XDP_TX return code.
 		 */
Signature · 1 line
2.7.4
author
#17 lore raw

Re: [PATCH net 4/4] virito-net: fix leaking page for gso packet during mergeable XDP

Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Jason Wang

We need to drop refcnt to xdp_page if we see a gso packet. Otherwise it will be leaked. Fixing this by moving the check of gso packet above the linearizing logic.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")

typo in subject

Let me fix it in V2.

Quoted 12 lines
Quoted 12 lines
---
  drivers/net/virtio_net.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +0 -0
index 165a922..f8db809 100644
@@ -707,6 +707,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  		void *data;
  		u32 act;
 
Quoted 5 lines

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 713

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		/* Transient failure which in theory could occur if
+		 * in-flight packets from before XDP was enabled reach
+		 * the receive path after XDP is loaded. In practice I
+		 * was not able to create this condition.

BTW we should probably drop the last sentence. It says in theory, should be enough.

Ok.

Thanks

Quoted 11 lines
Quoted 11 lines
drivers/net/virtio_net.c +4 -0
+		 */
+		if (unlikely(hdr->hdr.gso_type))
+			goto err_xdp;
+
  		/* This happens when rx buffer size is underestimated
  		 * or headroom is not enough because of the buffer
  		 * was refilled before XDP is set. This should only
@@ -728,14 +736,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  			xdp_page = page;
  		}
 
Quoted 13 lines
Quoted 13 lines
drivers/net/virtio_net.c +0 -8
-		/* Transient failure which in theory could occur if
-		 * in-flight packets from before XDP was enabled reach
-		 * the receive path after XDP is loaded. In practice I
-		 * was not able to create this condition.
-		 */
-		if (unlikely(hdr->hdr.gso_type))
-			goto err_xdp;
-
  		/* Allow consuming headroom but reserve enough space to push
  		 * the descriptor on if we get an XDP_TX return code.
  		 */
Signature · 1 line
2.7.4

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

author
#18 lore raw

Re: [PATCH net 4/4] virito-net: fix leaking page for gso packet during mergeable XDP

In reply to Michael S. Tsirkin
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Jason Wang

We need to drop refcnt to xdp_page if we see a gso packet. Otherwise it will be leaked. Fixing this by moving the check of gso packet above the linearizing logic.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")

typo in subject

Let me fix it in V2.

Quoted 12 lines
Quoted 12 lines
---
  drivers/net/virtio_net.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +0 -0
index 165a922..f8db809 100644
@@ -707,6 +707,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  		void *data;
  		u32 act;
 
Quoted 5 lines

drivers/net/virtio_net.c static struct sk_buff *receive_mergeable(struct net_device *dev, · line 713

Quoted 4 lines
drivers/net/virtio_net.c +4 -0
+		/* Transient failure which in theory could occur if
+		 * in-flight packets from before XDP was enabled reach
+		 * the receive path after XDP is loaded. In practice I
+		 * was not able to create this condition.

BTW we should probably drop the last sentence. It says in theory, should be enough.

Ok.

Thanks

Quoted 24 lines
Quoted 24 lines
drivers/net/virtio_net.c +4 -8
+		 */
+		if (unlikely(hdr->hdr.gso_type))
+			goto err_xdp;
+
  		/* This happens when rx buffer size is underestimated
  		 * or headroom is not enough because of the buffer
  		 * was refilled before XDP is set. This should only
@@ -728,14 +736,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
  			xdp_page = page;
  		}
 
-		/* Transient failure which in theory could occur if
-		 * in-flight packets from before XDP was enabled reach
-		 * the receive path after XDP is loaded. In practice I
-		 * was not able to create this condition.
-		 */
-		if (unlikely(hdr->hdr.gso_type))
-			goto err_xdp;
-
  		/* Allow consuming headroom but reserve enough space to push
  		 * the descriptor on if we get an XDP_TX return code.
  		 */
Signature · 1 line
2.7.4
author
#19 lore raw

PATCH 4/4 virito-net: fix leaking page for gso packet during mergeable XDP

In reply to Jason Wang

We need to drop refcnt to xdp_page if we see a gso packet. Otherwise it will be leaked. Fixing this by moving the check of gso packet above the linearizing logic.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
---
 drivers/net/virtio_net.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +8 -8
index 165a922..f8db809 100644
@@ -707,6 +707,14 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 		void *data;
 		u32 act;
 
+		/* Transient failure which in theory could occur if
+		 * in-flight packets from before XDP was enabled reach
+		 * the receive path after XDP is loaded. In practice I
+		 * was not able to create this condition.
+		 */
+		if (unlikely(hdr->hdr.gso_type))
+			goto err_xdp;
+
 		/* This happens when rx buffer size is underestimated
 		 * or headroom is not enough because of the buffer
 		 * was refilled before XDP is set. This should only
@@ -728,14 +736,6 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 			xdp_page = page;
 		}
 
-		/* Transient failure which in theory could occur if
-		 * in-flight packets from before XDP was enabled reach
-		 * the receive path after XDP is loaded. In practice I
-		 * was not able to create this condition.
-		 */
-		if (unlikely(hdr->hdr.gso_type))
-			goto err_xdp;
-
 		/* Allow consuming headroom but reserve enough space to push
 		 * the descriptor on if we get an XDP_TX return code.
 		 */
Signature · 1 line
2.7.4
#20 lore raw
In reply to Jason Wang
Quoted 6 lines · Jason Wang

Hi:

Please review the patches that tries to fix sevreal issues of virtio-net mergeable XDP.

Thanks

I think we should do 3/4 differently.
The rest looks good, and probably needed on stable.

Thanks!

Quoted 11 lines

Jason Wang (4):
virtio-net: correctly redirect linearized packet
virtio-net: correctly transmit XDP buff after linearizing
virtio-net: reset num_buf to 1 after linearizing packet
virito-net: fix leaking page for gso packet during mergeable XDP

 drivers/net/virtio_net.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4
#21 lore raw
In reply to Jason Wang
Quoted 6 lines · Jason Wang

Hi:

Please review the patches that tries to fix sevreal issues of virtio-net mergeable XDP.

Thanks

I think we should do 3/4 differently.
The rest looks good, and probably needed on stable.

Thanks!

Quoted 11 lines

Jason Wang (4):
virtio-net: correctly redirect linearized packet
virtio-net: correctly transmit XDP buff after linearizing
virtio-net: reset num_buf to 1 after linearizing packet
virito-net: fix leaking page for gso packet during mergeable XDP

 drivers/net/virtio_net.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
Signature · 1 line
2.7.4