Skip to contentSkip to conversation

Fix several issues of virtio-net mergeable XDP

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

Subsystems (4)
lore
Share & tools
lore

Jason Wang

author
#0 lore raw

v2 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.

Changes from V1:
- check against 1 before decreasing instead of resetting to 1
- typoe fixes

Jason Wang (4):
virtio-net: correctly redirect linearized packet
virtio-net: correctly transmit XDP buff after linearizing
virtio-net: correctly check num_buf during err path
virtio-net: fix leaking page for gso packet during mergeable XDP

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

PATCH v2 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
author
#2 lore raw

PATCH v2 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
#3 lore raw

PATCH v2 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
#4 lore raw

PATCH v2 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
#5 lore raw

PATCH v2 3/4 virtio-net: correctly check num_buf during err path

In reply to Jason Wang

If we successfully linearize the packet, num_buf will be set to zero which may confuse error handling path which assumes num_buf is at least 1 and this can lead the code tries to pop the descriptor of next buffer. Fixing this by checking num_buf against 1 before decreasing.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 6260d65..326e247 100644
@@ -875,7 +875,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	rcu_read_unlock();
 err_skb:
 	put_page(page);
-	while (--num_buf) {
+	while (num_buf-- > 1) {
 		buf = virtqueue_get_buf(rq->vq, &len);
 		if (unlikely(!buf)) {
 			pr_debug("%s: rx error: %d buffers missing\n",
Signature · 1 line
2.7.4
author
#6 lore raw

PATCH v2 3/4 virtio-net: correctly check num_buf during err path

In reply to Jason Wang

If we successfully linearize the packet, num_buf will be set to zero which may confuse error handling path which assumes num_buf is at least 1 and this can lead the code tries to pop the descriptor of next buffer. Fixing this by checking num_buf against 1 before decreasing.

Fixes 4941d472bf95 ("virtio-net: do not reset during XDP set")
---
 drivers/net/virtio_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/virtio_net.c +1 -1
index 6260d65..326e247 100644
@@ -875,7 +875,7 @@ static struct sk_buff *receive_mergeable(struct net_device *dev,
 	rcu_read_unlock();
 err_skb:
 	put_page(page);
-	while (--num_buf) {
+	while (num_buf-- > 1) {
 		buf = virtqueue_get_buf(rq->vq, &len);
 		if (unlikely(!buf)) {
 			pr_debug("%s: rx error: %d buffers missing\n",
Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v2 4/4 virtio-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. While at it, remove useless comment as well.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
---
 drivers/net/virtio_net.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +7 -8
index 326e247..032e1ac 100644
@@ -707,6 +707,13 @@ 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.
+		 */
+		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
@@ -727,14 +734,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
#8 lore raw

PATCH v2 4/4 virtio-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. While at it, remove useless comment as well.

Cc John Fastabend <[email protected]>
Fixes 72979a6c3590 ("virtio_net: xdp, add slowpath case for non contiguous buffers")
---
 drivers/net/virtio_net.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/net/virtio_net.c +7 -8
index 326e247..032e1ac 100644
@@ -707,6 +707,13 @@ 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.
+		 */
+		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
@@ -727,14 +734,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
maintainer
#9 lore raw
In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Tue, 22 May 2018 11:44:27 +0800

Quoted 6 lines

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

Changes from V1:
- check against 1 before decreasing instead of resetting to 1
- typoe fixes

Series applied and queued up for -stable.

maintainer
#10 lore raw
In reply to Jason Wang

From: Jason Wang <[email protected]>
Date: Tue, 22 May 2018 11:44:27 +0800

Quoted 6 lines

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

Changes from V1:
- check against 1 before decreasing instead of resetting to 1
- typoe fixes

Series applied and queued up for -stable.