diff mbox series

[net-next,RFC,v1,1/4] veth: use same bpf_xdp_adjust_head check as generic-XDP

Message ID 169272714720.1975370.12172959079424954030.stgit@firesoul (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series veth: reduce reallocations of SKBs when XDP bpf-prog is loaded | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers warning 4 maintainers not CCed: daniel@iogearbox.net ast@kernel.org bpf@vger.kernel.org john.fastabend@gmail.com
netdev/build_clang success Errors and warnings before: 1353 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jesper Dangaard Brouer Aug. 22, 2023, 5:59 p.m. UTC
This is a consistency patch, no functional change.

Both veth_xdp_rcv_skb() and bpf_prog_run_generic_xdp() checks if XDP bpf_prog
adjusted packet head via BPF-helper bpf_xdp_adjust_head(). The order of
subtracting orig_data and xdp->data are opposite between the two functions. This
is confusing when reviewing and reading the code.

This patch choose to follow generic-XDP and adjust veth_xdp_rcv_skb().

In veth_xdp_rcv_skb() the skb_mac_header length have been __skb_push()'ed.
Thus, we skip the skb->mac_header adjustments like bpf_prog_run_generic_xdp()
and instead do a skb_reset_mac_header() as skb->data point to Eth header.

Signed-off-by: Jesper Dangaard Brouer <hawk@kernel.org>
---
 drivers/net/veth.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 953f6d8f8db0..be7b62f57087 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -897,12 +897,13 @@  static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,
 	rcu_read_unlock();
 
 	/* check if bpf_xdp_adjust_head was used */
-	off = orig_data - xdp->data;
-	if (off > 0)
-		__skb_push(skb, off);
-	else if (off < 0)
-		__skb_pull(skb, -off);
-
+	off = xdp->data - orig_data;
+	if (off) {
+		if (off > 0)
+			__skb_pull(skb, off);
+		else if (off < 0)
+			__skb_push(skb, -off);
+	}
 	skb_reset_mac_header(skb);
 
 	/* check if bpf_xdp_adjust_tail was used */