Skip to contentSkip to conversation

veth: check for NAPI instead of xdp_prog before xmit of XDP frame

PATCH Applied Toke Høiland-Jørgensen 4 participants 4 messages Apr 16, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 veth: check for NAPI instead of xdp_prog before xmit of XDP frame

The recent patch that tied enabling of veth NAPI to the GRO flag also has the nice side effect that a veth device can be the target of an XDP_REDIRECT without an XDP program needing to be loaded on the peer device. However, the patch adding this extra NAPI mode didn't actually change the check in veth_xdp_xmit() to also look at the new NAPI pointer, so let's fix that.

Fixes 6788fa154546 ("veth: allow enabling NAPI even without XDP")
---
 drivers/net/veth.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/veth.c +3 -4
index 15b2e3923c47..bdb7ce3cb054 100644
@@ -486,11 +486,10 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
 
 	rcv_priv = netdev_priv(rcv);
 	rq = &rcv_priv->rq[veth_select_rxq(rcv)];
-	/* Non-NULL xdp_prog ensures that xdp_ring is initialized on receive
-	 * side. This means an XDP program is loaded on the peer and the peer
-	 * device is up.
+	/* The napi pointer is set if NAPI is enabled, which ensures that
+	 * xdp_ring is initialized on receive side and the peer device is up.
 	 */
-	if (!rcu_access_pointer(rq->xdp_prog))
+	if (!rcu_access_pointer(rq->napi))
 		goto out;
 
 	max_len = rcv->mtu + rcv->hard_header_len + VLAN_HLEN;
Signature · 1 line
2.31.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Fri, 16 Apr 2021 17:47:45 +0200 Toke Høiland-Jørgensen <[email protected]>…

The recent patch that tied enabling of veth NAPI to the GRO flag also has the nice side effect that a veth device can be the target of an XDP_REDIRECT without an XDP program needing to be loaded on the peer device. However, the patch adding this extra NAPI mode didn't actually change the check in veth_xdp_xmit() to also look at the new NAPI pointer, so let's fix that.

Quoted 5 lines
Fixes 6788fa154546 ("veth: allow enabling NAPI even without XDP")
---
 drivers/net/veth.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Very happy to see this strange requirement of loading an xdp_prog on the veth peer (inside the netns) being lifted. Multiple people/users have hit this issue and complained. Thanks for the followup to fix this! :-)

Quoted 19 lines
drivers/net/veth.c +3 -4
index 15b2e3923c47..bdb7ce3cb054 100644
@@ -486,11 +486,10 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
 
 	rcv_priv = netdev_priv(rcv);
 	rq = &rcv_priv->rq[veth_select_rxq(rcv)];
-	/* Non-NULL xdp_prog ensures that xdp_ring is initialized on receive
-	 * side. This means an XDP program is loaded on the peer and the peer
-	 * device is up.
+	/* The napi pointer is set if NAPI is enabled, which ensures that
+	 * xdp_ring is initialized on receive side and the peer device is up.
 	 */
-	if (!rcu_access_pointer(rq->xdp_prog))
+	if (!rcu_access_pointer(rq->napi))
 		goto out;
 
 	max_len = rcv->mtu + rcv->hard_header_len + VLAN_HLEN;
Signature · 4 lines
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Toke Høiland-Jørgensen
Quoted 22 lines · Toke Høiland-Jørgensen

The recent patch that tied enabling of veth NAPI to the GRO flag also has the nice side effect that a veth device can be the target of an XDP_REDIRECT without an XDP program needing to be loaded on the peer device. However, the patch adding this extra NAPI mode didn't actually change the check in veth_xdp_xmit() to also look at the new NAPI pointer, so let's fix that.

Fixes 6788fa154546 ("veth: allow enabling NAPI even without XDP")
---
 drivers/net/veth.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/net/veth.c +0 -1
index 15b2e3923c47..bdb7ce3cb054 100644
@@ -486,11 +486,10 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
 
 	rcv_priv = netdev_priv(rcv);
 	rq = &rcv_priv->rq[veth_select_rxq(rcv)];
-	/* Non-NULL xdp_prog ensures that xdp_ring is initialized on receive

drivers/net/veth.c static int veth_xdp_xmit(struct net_device *dev, int n, · line 495

Quoted 10 lines
drivers/net/veth.c +3 -3
-	 * side. This means an XDP program is loaded on the peer and the peer
-	 * device is up.
+	/* The napi pointer is set if NAPI is enabled, which ensures that
+	 * xdp_ring is initialized on receive side and the peer device is up.
 	 */
-	if (!rcu_access_pointer(rq->xdp_prog))
+	if (!rcu_access_pointer(rq->napi))
 		goto out;
 
 	max_len = rcv->mtu + rcv->hard_header_len + VLAN_HLEN;

Thanks for the quick turn-around!

#3 lore raw
In reply to Toke Høiland-Jørgensen
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Fri, 16 Apr 2021 17:47:45 +0200 you wrote:

The recent patch that tied enabling of veth NAPI to the GRO flag also has the nice side effect that a veth device can be the target of an XDP_REDIRECT without an XDP program needing to be loaded on the peer device. However, the patch adding this extra NAPI mode didn't actually change the check in veth_xdp_xmit() to also look at the new NAPI pointer, so let's fix that.

[...]

Here is the summary with links:
- [net-next] veth: check for NAPI instead of xdp_prog before xmit of XDP frame

    https://git.kernel.org/netdev/net-next/c/0e672f306a28

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html