xdp: RX checksum metadata hint and checksum assertion over redirect
Subsystems (9)
cover xdp: RX checksum metadata hint and checksum assertion over redirect
This series lets XDP programs work with the hardware RX checksum verdict:
read what the NIC concluded about a packet, and carry a "the L4 checksum is correct" assertion across a redirect so the stack does not revalidate it in software.
When an XDP program redirects a frame to a cpumap (or any other path that rebuilds an skb from an xdp_frame via __xdp_build_skb_from_frame()), the HW RX checksum status is lost and the stack revalidates the L4 checksum in software.
Two kfuncs are added:
- bpf_xdp_metadata_rx_csum(): a device-bound RX-metadata hint, like the existing rx_hash / rx_vlan_tag ones. It reports enum xdp_csum_status (XDP_CSUM_NONE / XDP_CSUM_VERIFIED) and is implemented for mlx5e, ice and veth.
- bpf_xdp_assert_rx_csum(): a generic, non-device-bound kfunc that lets the program assert the L4 checksum is correct. It sets a buff flag that rides into the xdp_frame, and __xdp_build_skb_from_frame() turns it into skb->ip_summed = CHECKSUM_UNNECESSARY. The kernel cannot verify the assertion; the program takes responsibility, as it already does when rewriting packet contents.
Posted as RFC to get feedback on:
- whether the read hint (bpf_xdp_metadata_rx_csum() and its driver support) belongs in this series at all. bpf_xdp_assert_rx_csum() is self-contained and already covers the main use case: a program that computes or fixes the L4 checksum itself, or trusts the source, and wants the rebuilt skb to skip software revalidation. The read hint is an optimization for programs that did not touch the payload and only want to relay the hardware verdict. These could just as well be two independent series (assert-only first);
- the kfunc naming, bpf_xdp_assert_rx_csum() in particular.
Testing:
- new selftest xdp_cpumap_rx_csum drives a frame through a native-XDP veth into a cpumap redirect and checks, via fexit on __xdp_build_skb_from_frame(), that the rebuilt skb is CHECKSUM_UNNECESSARY iff the program called bpf_xdp_assert_rx_csum();
- xdp_metadata calls bpf_xdp_metadata_rx_csum() over veth and checks both
verdicts: XDP_CSUM_NONE for an AF_XDP-injected frame and XDP_CSUM_VERIFIED for one sent through the stack.
Vladimir Vdovin (7):
xdp: let XDP programs assert the RX checksum over redirect selftests/bpf: add test for bpf_xdp_assert_rx_csum over cpumap
xdp: add bpf_xdp_metadata_rx_csum() RX metadata kfunc net/mlx5e: support the rx_csum XDP metadata hint
ice: support the rx_csum XDP metadata hint
veth: support the rx_csum XDP metadata hint selftests/bpf: cover bpf_xdp_metadata_rx_csum in xdp_metadata
Documentation/netlink/specs/netdev.yaml | 5 + drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 32 ++++ .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 23 +++ drivers/net/veth.c | 23 +++ include/net/xdp.h | 23 +++ include/uapi/linux/netdev.h | 3 + net/core/xdp.c | 73 ++++++++- tools/include/uapi/linux/netdev.h | 3 + .../bpf/prog_tests/xdp_cpumap_rx_csum.c | 150 ++++++++++++++++++ .../selftests/bpf/prog_tests/xdp_metadata.c | 10 ++ .../selftests/bpf/progs/bpf_tracing_net.h | 1 + .../bpf/progs/test_xdp_cpumap_rx_csum.c | 51 ++++++ .../selftests/bpf/progs/xdp_metadata.c | 9 ++ tools/testing/selftests/bpf/xdp_metadata.h | 8 + 14 files changed, 412 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c
base-commit: f456c1922c49e6be5ce407ddb74a6e61af5b65cf
Signature · 1 line
2.47.0
RFC PATCH 1/7 xdp: let XDP programs assert the RX checksum over redirect
When an XDP program redirects a frame to a cpumap (or any other path that rebuilds an skb from an xdp_frame via __xdp_build_skb_from_frame()), the HW RX checksum status is lost and the stack revalidates the L4 checksum in software.
Add a non-dev-bound kfunc, bpf_xdp_assert_rx_csum(), that lets the program assert the L4 checksum is correct. It sets XDP_FLAGS_RX_CSUM_UNNECESSARY on the buffer; the flag rides into the xdp_frame and __xdp_build_skb_from_frame() turns it into skb->ip_summed = CHECKSUM_UNNECESSARY. The kernel cannot verify the assertion, the program takes responsibility, the same way it is already trusted to rewrite arbitrary packet contents.
--- include/net/xdp.h | 11 +++++++++++ net/core/xdp.c | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-)
include/net/xdp.h +11 -0
@@ -81,6 +81,11 @@ enum xdp_buff_flags {* XDP program is not attached. */ XDP_FLAGS_FRAGS_UNREADABLE =BIT (2 ), +/* XDP program asserts the L4 checksum is correct, so the skb built +* out of this frame (e.g. on the cpumap redirect path) can be marked +* CHECKSUM_UNNECESSARY instead of being validated in software. +*/ + XDP_FLAGS_RX_CSUM_UNNECESSARY = BIT(3), }; struct xdp_buff {
@@ -316,6 +321,12 @@ xdp_frame_get_skb_flags(const struct xdp_frame *frame)return frame->flags; } +static __always_inline bool +xdp_frame_rx_csum_unnecessary (const struct xdp_frame *frame) +{ +return !!(frame->flags &XDP_FLAGS_RX_CSUM_UNNECESSARY ); +} +#define XDP_BULK_QUEUE_SIZE 16struct xdp_frame_bulk {int count;
net/core/xdp.c +48 -2
75 lines not on this page · raw message
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [RFC PATCH bpf-next v1 1/7] xdp: let XDP programs assert the RX checksum over redirect
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The XDP_FLAGS_RX_CSUM_UNNECESSARY flag is lost when an AF_XDP zero-copy buffer is converted to…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The XDP_FLAGS_RX_CSUM_UNNECESSARY flag is lost when an AF_XDP zero-copy buffer is converted to an xdp_frame during XDP_REDIRECT. --
commit ba787c7855bcf7d5c0ecdc2fe7e6a11cde6a4c00
Author: Vladimir Vdovin <[email protected]>
xdp: let XDP programs assert the RX checksum over redirect
This patch adds a non-dev-bound kfunc, bpf_xdp_assert_rx_csum(), allowing XDP programs to assert that an L4 checksum is correct. It sets a new flag on the buffer, XDP_FLAGS_RX_CSUM_UNNECESSARY, which is translated to CHECKSUM_UNNECESSARY when an skb is built out of the frame.
Quoted 4 lines
net/core/xdp.c +0
-0
[ ... ]
Quoted 16 lines
net/core/xdp.c +12
-0@@ -961,6 +964,31 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,return -EOPNOTSUPP ; } +/** +* bpf_xdp_assert_rx_csum - Assert the packet's L4 checksum is correct. +* @ctx: XDP context pointer. +* +* Mark the frame so that an skb later built out of it (e.g. on the cpumap +* redirect path, see __xdp_build_skb_from_frame()) is set to +* CHECKSUM_UNNECESSARY instead of being validated in software when it enters +* the stack. +* +* This is an assertion made by the XDP program: the kernel cannot verify it. +* The program takes responsibility for the checksum being correct, the same +* way it is already trusted to rewrite arbitrary packet contents. If the
net/core/xdp.c __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx, · line 988
Quoted 10 lines
net/core/xdp.c +10
-0+* program modifies L4 data after calling this kfunc the assertion may no +* longer hold. +* +* Return: 0. +*/ +__bpf_kfunc int bpf_xdp_assert_rx_csum(struct xdp_md *ctx) +{ +struct xdp_buff *xdp = (struct xdp_buff *)ctx; + + xdp->flags |=XDP_FLAGS_RX_CSUM_UNNECESSARY ;
[Severity: Medium]
Does this flag get lost when an AF_XDP zero-copy buffer is redirected?
Looking at xdp_convert_zc_to_xdp_frame() in net/core/xdp.c, it initializes the new frame with memset() but does not copy the flags from the original xdp_buff:
net/core/xdp.c:xdp_convert_zc_to_xdp_frame() {
...
memset(xdpf, 0, sizeof(*xdpf));
...
xdpf->frame_sz = PAGE_SIZE;
xdpf->mem_type = MEM_TYPE_PAGE_ORDER0;
xsk_buff_free(xdp);
return xdpf;
}Should xdp_convert_zc_to_xdp_frame() be updated to copy xdp->flags to xdpf->flags so the RX checksum assertion survives redirect for zero-copy frames?
Quoted 4 lines
net/core/xdp.c +3
-0+return 0 ; +} +__bpf_kfunc_end_defs ();
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RFC PATCH 2/7 selftests/bpf: add test for bpf_xdp_assert_rx_csum over cpumap
In reply to Vladimir VdovinDrive a frame through a native-XDP veth into a cpumap redirect and observe, via fexit on __xdp_build_skb_from_frame(), that the rebuilt skb is CHECKSUM_UNNECESSARY when the program called bpf_xdp_assert_rx_csum() and CHECKSUM_NONE otherwise. fexit is used because cpumap GRO would otherwise normalize ip_summed before any later hook can observe it.
--- .../bpf/prog_tests/xdp_cpumap_rx_csum.c | 150 ++++++++++++++++++ .../selftests/bpf/progs/bpf_tracing_net.h | 1 + .../bpf/progs/test_xdp_cpumap_rx_csum.c | 51 ++++++ 3 files changed, 202 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +150 -0
@@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <net/if.h> +#include <linux/if_ether.h> +#include <linux/if_link.h> +#include <linux/if_packet.h> +#include <linux/ipv6.h> +#include <netinet/in.h> +#include <netinet/udp.h> +#include <sys/socket.h> + +#include "test_progs.h" +#include "network_helpers.h" +#include <bpf/bpf_endian.h> +#include "test_xdp_cpumap_rx_csum.skel.h" + +#define TEST_NS "xdp_cm_csum_ns" +#define UDP_TEST_PORT 7777 + +/* Kernel skb->ip_summed values, not exported to userspace headers. */ +#define CHECKSUM_NONE 0 +#define CHECKSUM_UNNECESSARY 1 + +struct udp_pkt { +struct ethhdr eth; +struct ipv6hdr iph; +struct udphdr udp; +__u8 payload[16 ]; +} __packed; + +static struct udp_pkt pkt = { + .eth.h_proto =__bpf_constant_htons (ETH_P_IPV6 ), + .eth.h_dest = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff }, + .eth.h_source = {0x66 ,0x77 ,0x88 ,0x99 ,0xaa ,0xbb }, + .iph.version =6 , + .iph.nexthdr =IPPROTO_UDP , + .iph.payload_len =__bpf_constant_htons (sizeof (struct udphdr ) +16 ), + .iph.hop_limit =64 , + .udp.source =__bpf_constant_htons (1 ), + .udp.dest =__bpf_constant_htons (UDP_TEST_PORT ), + .udp.len =__bpf_constant_htons (sizeof (struct udphdr ) +16 ), +}; + +/* Inject one frame on veth0; it is received on veth1 where native XDP +* redirects it into the cpumap. Report the ip_summed the rebuilt skb carried. +*/ +static int inject_and_observe (struct test_xdp_cpumap_rx_csum *skel,int sfd, +int ifindex_src,bool assert_csum,int *ip_summed) +{ +struct sockaddr_ll sll = { + .sll_family =AF_PACKET , + .sll_ifindex = ifindex_src, + .sll_halen =0 , + }; +int i, n; + + skel->bss->assert_csum = assert_csum; + skel->bss->seen = false; + skel->data->observed_ip_summed =-1 ; + + n =sendto (sfd, &pkt,sizeof (pkt),0 , (void *)&sll,sizeof (sll)); +if (!ASSERT_EQ (n,sizeof (pkt),"sendto" )) +return -1 ; + +/* The skb is built asynchronously by the cpumap kthread. */ +for (i =0 ; i <20 && !skel->bss->seen; i++) +usleep (50000 ); + +if (!ASSERT_TRUE (skel->bss->seen,"skb built from frame" )) +return -1 ; + + *ip_summed = skel->data->observed_ip_summed; +return 0 ; +} + +void test_xdp_cpumap_rx_csum (void ) +{ +struct test_xdp_cpumap_rx_csum *skel =NULL ; +struct bpf_cpumap_val val = { .qsize =192 }; +struct bpf_link *fexit_link =NULL ; +struct nstoken *nstoken =NULL ; +int err, map_fd, ifindex_dst =0 , ifindex_src, sfd =-1 , ip_summed; +bool xdp_attached = false; +__u32 idx =0 ; + +SYS (out,"ip netns add %s" ,TEST_NS ); + nstoken =open_netns (TEST_NS ); +if (!ASSERT_OK_PTR (nstoken,"open_netns" )) + goto out; + +/* veth pair: a frame TX'd on veth0 is RX'd on veth1. */ +SYS (out,"ip link add veth0 type veth peer name veth1" ); +SYS (out,"ip link set veth0 up" ); +SYS (out,"ip link set veth1 up" ); + + skel =test_xdp_cpumap_rx_csum__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel open_and_load" )) + goto out; + +/* cpumap entry without a program: a plain redirect that forces the +* frame->skb conversion in __xdp_build_skb_from_frame(). +*/ + map_fd =bpf_map__fd (skel->maps.cpu_map); + err =bpf_map_update_elem (map_fd, &idx, &val,0 ); +if (!ASSERT_OK (err,"cpumap update" )) + goto out; + + ifindex_dst =if_nametoindex ("veth1" ); + ifindex_src =if_nametoindex ("veth0" ); +if (!ASSERT_GT (ifindex_dst,0 ,"veth1 ifindex" ) || + !ASSERT_GT (ifindex_src,0 ,"veth0 ifindex" )) + goto out; + +/* Native XDP so the redirect goes through xdp_convert_buff_to_frame(), +* which propagates the rx-csum flag into the frame. Generic mode would +* redirect a ready-made skb and never hit our code path. +*/ + err =bpf_xdp_attach (ifindex_dst,bpf_program__fd (skel->progs.xdp_redir), +XDP_FLAGS_DRV_MODE ,NULL ); +if (!ASSERT_OK (err,"attach native xdp" )) + goto out; + xdp_attached = true; + + fexit_link =bpf_program__attach (skel->progs.on_build); +if (!ASSERT_OK_PTR (fexit_link,"attach fexit" )) + goto out; + + sfd =socket (AF_PACKET ,SOCK_RAW ,htons (ETH_P_ALL )); +if (!ASSERT_GE (sfd,0 ,"AF_PACKET socket" )) + goto out; + +/* Program asserts the checksum -> CHECKSUM_UNNECESSARY. */ +if (!inject_and_observe (skel, sfd, ifindex_src, true, &ip_summed)) +ASSERT_EQ (ip_summed,CHECKSUM_UNNECESSARY , +"ip_summed marked unnecessary" ); + +/* No assertion -> skb is left CHECKSUM_NONE for the stack to validate. */ +if (!inject_and_observe (skel, sfd, ifindex_src, false, &ip_summed)) +ASSERT_EQ (ip_summed,CHECKSUM_NONE ,"ip_summed left none" ); + +out: +if (sfd >=0 ) +close (sfd); +bpf_link__destroy (fexit_link); +if (xdp_attached) +bpf_xdp_detach (ifindex_dst,XDP_FLAGS_DRV_MODE ,NULL ); +test_xdp_cpumap_rx_csum__destroy (skel); +if (nstoken) +close_netns (nstoken); +SYS_NOFAIL ("ip netns del %s" ,TEST_NS ); +}
tools/testing/selftests/bpf/progs/bpf_tracing_net.h +1 -0
@@ -87,6 +87,7 @@#define TCPOLEN_SACK_PERM 2#define CHECKSUM_NONE 0 +#define CHECKSUM_UNNECESSARY 1#define CHECKSUM_PARTIAL 3#define IFNAMSIZ 16
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [RFC PATCH bpf-next v1 2/7] selftests/bpf: add test for bpf_xdp_assert_rx_csum over cpumap
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The XDP program redirects all IPv6 packets unconditionally without filtering for the specific…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The XDP program redirects all IPv6 packets unconditionally without filtering for the specific test UDP packet, causing the test to be flaky due to background IPv6 noise (e.g., MLD/ND).
- [Low] Multi-line comments do not follow the required BPF subsystem style.
--
commit 846ee2231e17e81d931043f95937a20e26145ff4
Author: Vladimir Vdovin <[email protected]>
selftests/bpf: add test for bpf_xdp_assert_rx_csum over cpumap
This commit adds a selftest to verify that the bpf_xdp_assert_rx_csum helper properly propagates checksum status through a cpumap redirect. It uses an XDP program and an fexit hook on __xdp_build_skb_from_frame to observe the resulting ip_summed value.
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +0
-0
[ ... ]
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +2
-0+static struct udp_pkt pkt = { + .eth.h_proto =__bpf_constant_htons (ETH_P_IPV6 ),
[ ... ]
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c line 45
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +6
-0+ .udp.len = __bpf_constant_htons(sizeof(struct udphdr) + 16), +}; + +/* Inject one frame on veth0; it is received on veth1 where native XDP +* redirects it into the cpumap. Report the ip_summed the rebuilt skb carried. +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred BPF subsystem style? The guidelines suggest putting the opening /* on its own line.
Quoted 1 line
+static int inject_and_observe(struct
test_xdp_cpumap_rx_csum*skel, int sfd,
[ ... ]
Quoted 2 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +2
-0+void test_xdp_cpumap_rx_csum (void ) +{
[ ... ]
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c line 101
Quoted 7 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +7
-0+ skel =test_xdp_cpumap_rx_csum__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel open_and_load" )) + goto out; + +/* cpumap entry without a program: a plain redirect that forces the +* frame->skb conversion in __xdp_build_skb_from_frame(). +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred BPF subsystem style?
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +1
-0+ map_fd =bpf_map__fd (skel->maps.cpu_map);
[ ... ]
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c line 116
Quoted 10 lines
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +10
-0+ ifindex_dst =if_nametoindex ("veth1" ); + ifindex_src =if_nametoindex ("veth0" ); +if (!ASSERT_GT (ifindex_dst,0 ,"veth1 ifindex" ) || + !ASSERT_GT (ifindex_src,0 ,"veth0 ifindex" )) + goto out; + +/* Native XDP so the redirect goes through xdp_convert_buff_to_frame(), +* which propagates the rx-csum flag into the frame. Generic mode would +* redirect a ready-made skb and never hit our code path. +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred BPF subsystem style?
Quoted 1 line
tools/testing/selftests/bpf/prog_tests/xdp_cpumap_rx_csum.c new file +1
-0+ err = bpf_xdp_attach(ifindex_dst, bpf_program__fd(skel->progs.xdp_redir),
[ ... ]
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +0
-0
[ ... ]
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c line 29
Quoted 6 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +6
-0+SEC("xdp") +int xdp_redir (struct xdp_md *ctx) +{ +/* Assert the L4 checksum so the skb built on the cpumap redirect +* path is marked CHECKSUM_UNNECESSARY instead of validated in software. +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred BPF subsystem style?
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c line 34
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +5
-0+if (assert_csum) +bpf_xdp_assert_rx_csum (ctx); + +return bpf_redirect_map (&cpu_map,0 ,0 ); +}
[Severity: Medium]
Will this unconditionally redirect all packets (including background noise like IPv6 MLD/ND) to the cpu_map? If the kernel generates asynchronous background packets when the veth interfaces are brought up, could this cause the test to be flaky?
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c line 39
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +5
-0+ +/* Observe ip_summed exactly as __xdp_build_skb_from_frame() leaves it, before +* GRO in the cpumap kthread can normalize it. tc-ingress would be too late: +* GRO software-validates a CHECKSUM_NONE skb and marks it UNNECESSARY anyway. +*/
[Severity: Low]
This isn't a bug, but does this multi-line comment follow the preferred BPF subsystem style?
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c line 44
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +5
-0+SEC("fexit/__xdp_build_skb_from_frame") +int BPF_PROG (on_build ,struct xdp_frame *xdpf,struct sk_buff *skb, +struct net_device *dev,struct sk_buff *ret) +{ +if (ret && ret->protocol ==bpf_htons (ETH_P_IPV6 )) {
[Severity: Medium]
Since the check only looks for ETH_P_IPV6, could this inadvertently capture background IPv6 noise like MLD/ND packets and short-circuit the test loop in inject_and_observe() with an unexpected ip_summed value? Might it be safer to filter for the specific test UDP packet?
Quoted 5 lines
tools/testing/selftests/bpf/progs/test_xdp_cpumap_rx_csum.c new file +5
-0+ observed_ip_summed = ret->ip_summed; + seen = true; + } +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RFC PATCH 3/7 xdp: add bpf_xdp_metadata_rx_csum() RX metadata kfunc
In reply to Vladimir VdovinAdd a device-bound RX-metadata kfunc that reports the hardware checksum verdict (enum xdp_csum_status: XDP_CSUM_NONE / XDP_CSUM_VERIFIED) through a new xmo_rx_csum operation, so an XDP program can make an informed decision (e.g. call bpf_xdp_assert_rx_csum()) instead of trusting blindly. Wire it into the XDP_METADATA_KFUNC machinery and advertise it via NETDEV_XDP_RX_METADATA_CSUM.
--- Documentation/netlink/specs/netdev.yaml | 5 +++++ include/net/xdp.h | 12 ++++++++++++ include/uapi/linux/netdev.h | 3 +++ net/core/xdp.c | 23 +++++++++++++++++++++++ tools/include/uapi/linux/netdev.h | 3 +++ 5 files changed, 46 insertions(+)
Documentation/netlink/specs/netdev.yaml +5 -0
@@ -61,6 +61,11 @@ definitions: doc: | Device is capable of exposing receive packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). + - + name: csum + doc: | + Device is capable of exposing receive packet checksum status via + bpf_xdp_metadata_rx_csum(). - type: flags name: xsk-flags
include/net/xdp.h +12 -0
@@ -597,6 +597,10 @@ void xdp_attachment_setup(struct xdp_attachment_info *info, NETDEV_XDP_RX_METADATA_VLAN_TAG, \ bpf_xdp_metadata_rx_vlan_tag, \ xmo_rx_vlan_tag) \ + XDP_METADATA_KFUNC(XDP_METADATA_KFUNC_RX_CSUM, \ + NETDEV_XDP_RX_METADATA_CSUM, \ + bpf_xdp_metadata_rx_csum, \ + xmo_rx_csum) \ enum xdp_rx_metadata { #define XDP_METADATA_KFUNC(name, _, __, ___) name,
@@ -654,12 +658,20 @@ enum xdp_rss_hash_type { XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR, }; +/* Checksum status reported by bpf_xdp_metadata_rx_csum(). */ +enum xdp_csum_status { +XDP_CSUM_NONE =0 ,/* HW did not validate the checksum */ +XDP_CSUM_VERIFIED ,/* HW validated the L4 checksum; it is correct */ +}; +struct xdp_metadata_ops {int (*xmo_rx_timestamp)(const struct xdp_md *ctx,u64 *timestamp);int (*xmo_rx_hash)(const struct xdp_md *ctx,u32 *hash,enum xdp_rss_hash_type *rss_type);int (*xmo_rx_vlan_tag)(const struct xdp_md *ctx,__be16 *vlan_proto,u16 *vlan_tci); +int (*xmo_rx_csum)(const struct xdp_md *ctx, +enum xdp_csum_status *csum_status); };#ifdef CONFIG_NET
include/uapi/linux/netdev.h +3 -0
@@ -47,11 +47,14 @@ enum netdev_xdp_act {* hash via bpf_xdp_metadata_rx_hash(). * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive * packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). +* @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet +* checksum status via bpf_xdp_metadata_rx_csum(). */ enum netdev_xdp_rx_metadata {NETDEV_XDP_RX_METADATA_TIMESTAMP =1 ,NETDEV_XDP_RX_METADATA_HASH =2 ,NETDEV_XDP_RX_METADATA_VLAN_TAG =4 , +NETDEV_XDP_RX_METADATA_CSUM =8 , };/**
net/core/xdp.c +23 -0
@@ -964,6 +964,29 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,return -EOPNOTSUPP ; } +/** +* bpf_xdp_metadata_rx_csum - Read the device's RX checksum verdict. +* @ctx: XDP context pointer. +* @csum_status: Destination pointer for the checksum status. +* +* Report what the hardware concluded about the packet's checksum, so the +* program can decide whether to assert it (e.g. via bpf_xdp_assert_rx_csum() +* before a cpumap redirect) instead of having the stack validate it again. +* +* On ``XDP_CSUM_VERIFIED`` the device has checked the L4 checksum and it is +* correct. ``XDP_CSUM_NONE`` means the device did not validate it. +* +* Return: +* * Returns 0 on success or ``-errno`` on error. +* * ``-EOPNOTSUPP`` : device driver doesn't implement kfunc +* * ``-ENODATA`` : checksum information is not available +*/ +__bpf_kfunc int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +return -EOPNOTSUPP ; +} +/** * bpf_xdp_assert_rx_csum - Assert the packet's L4 checksum is correct. * @ctx: XDP context pointer.
tools/include/uapi/linux/netdev.h +3 -0
@@ -47,11 +47,14 @@ enum netdev_xdp_act {* hash via bpf_xdp_metadata_rx_hash(). * @NETDEV_XDP_RX_METADATA_VLAN_TAG: Device is capable of exposing receive * packet VLAN tag via bpf_xdp_metadata_rx_vlan_tag(). +* @NETDEV_XDP_RX_METADATA_CSUM: Device is capable of exposing receive packet +* checksum status via bpf_xdp_metadata_rx_csum(). */ enum netdev_xdp_rx_metadata {NETDEV_XDP_RX_METADATA_TIMESTAMP =1 ,NETDEV_XDP_RX_METADATA_HASH =2 ,NETDEV_XDP_RX_METADATA_VLAN_TAG =4 , +NETDEV_XDP_RX_METADATA_CSUM =8 , };/**
Signature · 1 line
2.47.0
RFC PATCH 4/7 net/mlx5e: support the rx_csum XDP metadata hint
In reply to Vladimir VdovinImplement xmo_rx_csum by reading CQE_L3_OK/CQE_L4_OK, mirroring the verdict mlx5e_handle_csum() uses for CHECKSUM_UNNECESSARY. CHECKSUM_COMPLETE is intentionally not surfaced: it is already disabled while an XDP program is loaded.
--- .../net/ethernet/mellanox/mlx5/core/en/xdp.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en/xdp.c +23 -0
@@ -277,10 +277,33 @@ static int mlx5e_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto,return 0 ; } +static int mlx5e_xdp_rx_csum (const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +const struct mlx5e_xdp_buff *_ctx = (void *)ctx; +const struct mlx5_cqe64 *cqe = _ctx->cqe; + +if (unlikely (!(_ctx->xdp.rxq->dev->features &NETIF_F_RXCSUM ))) +return -ENODATA ; + +/* Same verdict the normal RX path uses for CHECKSUM_UNNECESSARY. +* CHECKSUM_COMPLETE is deliberately not surfaced here: it is disabled +* while an XDP program is loaded (see mlx5e_handle_csum()). +*/ +if (likely ((cqe->hds_ip_ext &CQE_L3_OK ) && + (cqe->hds_ip_ext &CQE_L4_OK ))) + *csum_status =XDP_CSUM_VERIFIED ; +else + *csum_status =XDP_CSUM_NONE ; + +return 0 ; +} +const struct xdp_metadata_ops mlx5e_xdp_metadata_ops = { .xmo_rx_timestamp = mlx5e_xdp_rx_timestamp, .xmo_rx_hash = mlx5e_xdp_rx_hash, .xmo_rx_vlan_tag = mlx5e_xdp_rx_vlan_tag, + .xmo_rx_csum = mlx5e_xdp_rx_csum, };struct mlx5e_xsk_tx_complete {
Signature · 1 line
2.47.0
RFC PATCH 5/7 ice: support the rx_csum XDP metadata hint
In reply to Vladimir VdovinImplement xmo_rx_csum from the Rx flex descriptor status0 bits (L3L4P set and no XSUM_L4E), mirroring ice_rx_csum(). Return -ENODATA when RX checksum offload (NETIF_F_RXCSUM) is disabled, since the status bits are not meaningful then.
--- drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +32 -0
@@ -594,8 +594,40 @@ static int ice_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto,return 0 ; } +/** +* ice_xdp_rx_csum - RX checksum XDP hint handler +* @ctx: XDP buff pointer +* @csum_status: destination for the checksum verdict +* +* Report whether the hardware validated the packet's L4 checksum, mirroring +* the verdict ice_rx_csum() uses for CHECKSUM_UNNECESSARY. Return -ENODATA +* when RX checksum offload is disabled, since the status bits are not +* meaningful then. +*/ +static int ice_xdp_rx_csum (const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +const struct libeth_xdp_buff *xdp_ext = (void *)ctx; +struct ice_rx_ring *rx_ring; +u16 status0; + + rx_ring =libeth_xdp_buff_to_rq (xdp_ext,typeof (*rx_ring), xdp_rxq); +if (!(rx_ring->netdev->features &NETIF_F_RXCSUM )) +return -ENODATA ; + + status0 =le16_to_cpu (xdp_ext->desc->wb.status_error0); +if ((status0 &BIT (ICE_RX_FLEX_DESC_STATUS0_L3L4P_S )) && + !(status0 &BIT (ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S ))) + *csum_status =XDP_CSUM_VERIFIED ; +else + *csum_status =XDP_CSUM_NONE ; + +return 0 ; +} +const struct xdp_metadata_ops ice_xdp_md_ops = { .xmo_rx_timestamp = ice_xdp_rx_hw_ts, .xmo_rx_hash = ice_xdp_rx_hash, .xmo_rx_vlan_tag = ice_xdp_rx_vlan_tag, + .xmo_rx_csum = ice_xdp_rx_csum, };
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [RFC PATCH bpf-next v1 5/7] ice: support the rx_csum XDP metadata hint
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] Incomplete checksum validation logic improperly reports `XDP_CSUM_VERIFIED` for packets with IP or…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Incomplete checksum validation logic improperly reports XDP_CSUM_VERIFIED for packets with IP or outer header checksum errors.
- [Low] Dereferencing a void * pointer causes a compilation error.
--
commit 3569f119a8bc81475b62415df37c17d04819a768
Author: Vladimir Vdovin <[email protected]>
ice: support the rx_csum XDP metadata hint
This commit implements the xmo_rx_csum XDP metadata hint for the ice driver by reading the Rx flex descriptor status bits. It mirrors ice_rx_csum() and returns -ENODATA when hardware checksum offload is disabled.
Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +0
-0
[ ... ]
drivers/net/ethernet/intel/ice/ice_txrx_lib.c static int ice_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, · line 618
Quoted 12 lines
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +12
-0+static int ice_xdp_rx_csum (const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +const struct libeth_xdp_buff *xdp_ext = (void *)ctx; +struct ice_rx_ring *rx_ring; +u16 status0; + + rx_ring =libeth_xdp_buff_to_rq (xdp_ext,typeof (*rx_ring), xdp_rxq); +if (!(rx_ring->netdev->features &NETIF_F_RXCSUM )) +return -ENODATA ; + + status0 =le16_to_cpu (xdp_ext->desc->wb.status_error0);
[Severity: Low]
Does this code compile? Looking at include/net/libeth/xdp.h, libeth_xdp_buff->desc is defined as const void *. Attempting to access the wb member directly on a void pointer will cause a compilation error.
drivers/net/ethernet/intel/ice/ice_txrx_lib.c static int ice_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, · line 621
Quoted 3 lines
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +3
-0+if ((status0 &BIT (ICE_RX_FLEX_DESC_STATUS0_L3L4P_S )) && + !(status0 &BIT (ICE_RX_FLEX_DESC_STATUS0_XSUM_L4E_S ))) + *csum_status =XDP_CSUM_VERIFIED ;
[Severity: High]
Does this code improperly report XDP_CSUM_VERIFIED for packets with outer header or IP checksum errors?
Unlike ice_rx_csum() which validates IP and outer header errors, this condition only checks that L3/L4 are present and that there is no inner L4 checksum error (XSUM_L4E_S). If a packet has a corrupted IP checksum or a corrupted outer UDP checksum in a tunnel (XSUM_EUDPE_S or XSUM_IPE_S), it appears this will bypass the error flags and still return XDP_CSUM_VERIFIED.
Quoted 5 lines
drivers/net/ethernet/intel/ice/ice_txrx_lib.c +5
-0+else + *csum_status =XDP_CSUM_NONE ; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
RFC PATCH 6/7 veth: support the rx_csum XDP metadata hint
In reply to Vladimir VdovinImplement xmo_rx_csum from skb->ip_summed. veth has no real hardware; this surfaces whatever checksum verdict the skb already carries and makes the metadata kfunc testable without a NIC.
--- drivers/net/veth.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/net/veth.c +23 -0
@@ -1700,6 +1700,28 @@ static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto,return err; } +static int veth_xdp_rx_csum (const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +const struct veth_xdp_buff *_ctx = (void *)ctx; +const struct sk_buff *skb = _ctx->skb; + +if (!skb) +return -ENODATA ; + +/* veth has no real hardware; surface whatever checksum verdict the +* skb already carries (e.g. CHECKSUM_PARTIAL/UNNECESSARY from a local +* sender or a previous validation). +*/ +if (skb->ip_summed ==CHECKSUM_UNNECESSARY || + skb->ip_summed ==CHECKSUM_PARTIAL ) + *csum_status =XDP_CSUM_VERIFIED ; +else + *csum_status =XDP_CSUM_NONE ; + +return 0 ; +} +static const struct net_device_ops veth_netdev_ops = { .ndo_init = veth_dev_init, .ndo_open = veth_open,
@@ -1725,6 +1747,7 @@ static const struct xdp_metadata_ops veth_xdp_metadata_ops = { .xmo_rx_timestamp = veth_xdp_rx_timestamp, .xmo_rx_hash = veth_xdp_rx_hash, .xmo_rx_vlan_tag = veth_xdp_rx_vlan_tag, + .xmo_rx_csum = veth_xdp_rx_csum, };#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [RFC PATCH bpf-next v1 6/7] veth: support the rx_csum XDP metadata hint
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Incorrectly mapping CHECKSUM_PARTIAL to XDP_CSUM_VERIFIED violates the metadata kfunc UAPI and…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrectly mapping CHECKSUM_PARTIAL to XDP_CSUM_VERIFIED violates the metadata kfunc UAPI and leads to corrupted checksums on forwarded packets. --
commit 43f8c99f073896fcdca62b5034e71d604e446b2b
Author: Vladimir Vdovin <[email protected]>
veth: support the rx_csum XDP metadata hint
This commit implements xmo_rx_csum from skb->ip_summed. It surfaces whatever checksum verdict the skb already carries, making the metadata kfunc testable without a NIC since veth has no real hardware.
Quoted 4 lines
drivers/net/veth.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/veth.c +0
-0@@ -1700,6 +1700,28 @@ static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto,
[ ... ]
Quoted 6 lines
drivers/net/veth.c +6
-0+static int veth_xdp_rx_csum (const struct xdp_md *ctx, +enum xdp_csum_status *csum_status) +{ +const struct veth_xdp_buff *_ctx = (void *)ctx; +const struct sk_buff *skb = _ctx->skb; +
drivers/net/veth.c static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, · line 1718
Quoted 10 lines
drivers/net/veth.c +10
-0+if (!skb) +return -ENODATA ; + +/* veth has no real hardware; surface whatever checksum verdict the +* skb already carries (e.g. CHECKSUM_PARTIAL/UNNECESSARY from a local +* sender or a previous validation). +*/ +if (skb->ip_summed ==CHECKSUM_UNNECESSARY || + skb->ip_summed ==CHECKSUM_PARTIAL ) + *csum_status =XDP_CSUM_VERIFIED ;
[Severity: High]
Does mapping CHECKSUM_PARTIAL to XDP_CSUM_VERIFIED introduce a regression by violating the metadata kfunc UAPI? CHECKSUM_PARTIAL indicates that the payload checksum is incomplete.
If a packet is generated locally and sent over veth, it can carry skb->ip_summed == CHECKSUM_PARTIAL. If an XDP program reads this metadata via bpf_xdp_metadata_rx_csum(), it will see XDP_CSUM_VERIFIED. If the program then forwards the packet out a physical NIC via bpf_redirect(), the transmitted packet would have an incomplete, invalid checksum on the wire since only the pseudo-header checksum was computed.
Quoted 5 lines
drivers/net/veth.c +5
-0+else + *csum_status =XDP_CSUM_NONE ; + +return 0 ; +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
RFC PATCH 7/7 selftests/bpf: cover bpf_xdp_metadata_rx_csum in xdp_metadata
In reply to Vladimir VdovinCall bpf_xdp_metadata_rx_csum() in the xdp_metadata program and export the status to userspace. veth surfaces skb->ip_summed: a frame injected via AF_XDP carries no checksum context (XDP_CSUM_NONE), while one sent through the stack is CHECKSUM_PARTIAL (XDP_CSUM_VERIFIED). Assert each.
--- tools/testing/selftests/bpf/prog_tests/xdp_metadata.c | 10 ++++++++++ tools/testing/selftests/bpf/progs/xdp_metadata.c | 9 +++++++++ tools/testing/selftests/bpf/xdp_metadata.h | 8 ++++++++ 3 files changed, 27 insertions(+)
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +10 -0
@@ -310,6 +310,16 @@ static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp)if (!ASSERT_NEQ (meta->rx_hash,0 ,"rx_hash" ))return -1 ; +/* veth surfaces the checksum verdict from skb->ip_summed. A packet +* injected via AF_XDP carries no checksum context and is CHECKSUM_NONE, +* while one sent through the stack is CHECKSUM_PARTIAL and reads back as +* verified. +*/ +if (!ASSERT_EQ (meta->rx_csum_status, + sent_from_af_xdp ?XDP_META_CSUM_NONE :XDP_META_CSUM_VERIFIED , +"rx_csum_status" )) +return -1 ; +if (!sent_from_af_xdp) {if (!ASSERT_NEQ (meta->rx_hash_type &XDP_RSS_TYPE_L4 ,0 ,"rx_hash_type" ))return -1 ;
tools/testing/selftests/bpf/progs/xdp_metadata.c +9 -0
@@ -33,6 +33,8 @@ extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash, extern int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto, __u16 *vlan_tci) __ksym; +extern int bpf_xdp_metadata_rx_csum(const struct xdp_md *ctx, + enum xdp_csum_status *csum_status) __ksym; SEC("xdp")int rx (struct xdp_md *ctx)
@@ -43,6 +45,7 @@ int rx(struct xdp_md *ctx)struct udphdr *udp =NULL ;struct iphdr *iph =NULL ;struct xdp_meta *meta; +enum xdp_csum_status csum_status;u64 timestamp =-1 ;int ret;
@@ -99,6 +102,12 @@ int rx(struct xdp_md *ctx)bpf_xdp_metadata_rx_vlan_tag (ctx, &meta->rx_vlan_proto, &meta->rx_vlan_tci); + ret =bpf_xdp_metadata_rx_csum (ctx, &csum_status); +if (ret <0 ) + meta->rx_csum_err = ret; +else + meta->rx_csum_status = csum_status; +return bpf_redirect_map (&xsk, ctx->rx_queue_index,XDP_PASS ); }
tools/testing/selftests/bpf/xdp_metadata.h +8 -0
@@ -30,6 +30,10 @@ enum xdp_meta_field { XDP_META_FIELD_VLAN_TAG = BIT(2), }; +/* Mirror of enum xdp_csum_status (include/net/xdp.h) for userspace asserts. */ +#define XDP_META_CSUM_NONE 0 +#define XDP_META_CSUM_VERIFIED 1 + struct xdp_meta { union { __u64 rx_timestamp;
@@ -48,5 +52,9 @@ struct xdp_meta { };__s32 rx_vlan_tag_err; }; +union { +__u32 rx_csum_status; +__s32 rx_csum_err; + };enum xdp_meta_field hint_valid; };
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [RFC PATCH bpf-next v1 7/7] selftests/bpf: cover bpf_xdp_metadata_rx_csum in xdp_metadata
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The newly added multi-line comment in `verify_xsk_metadata` violates the BPF subsystem comment…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added multi-line comment in verify_xsk_metadata violates the BPF subsystem comment style guidelines. --
commit f8507da4f2875a0c3ae86814a72a21202665e4a5
Author: Vladimir Vdovin <[email protected]>
selftests/bpf: cover bpf_xdp_metadata_rx_csum in xdp_metadata
This commit updates the xdp_metadata test to call bpf_xdp_metadata_rx_csum() and export its status to userspace. It then asserts the expected checksum status depending on whether the frame was injected via AF_XDP or sent through the stack.
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp) · line 317
Quoted 13 lines
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c +5
-0@@ -310,6 +310,16 @@ static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp)if (!ASSERT_NEQ (meta->rx_hash,0 ,"rx_hash" ))return -1 ; +/* veth surfaces the checksum verdict from skb->ip_summed. A packet +* injected via AF_XDP carries no checksum context and is CHECKSUM_NONE, +* while one sent through the stack is CHECKSUM_PARTIAL and reads back as +* verified. +*/
[Severity: Low]
This isn't a bug, but does this comment format match the BPF subsystem multi-line comment style guidelines?
The BPF subsystem typically requires the opening /* to be on its own line, rather than sharing a line with the first row of text.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Quoted 38 lines · Vladimir Vdovin
This series lets XDP programs work with the hardware RX checksum verdict:
read what the NIC concluded about a packet, and carry a "the L4 checksum is correct" assertion across a redirect so the stack does not revalidate it in software.When an XDP program redirects a frame to a cpumap (or any other path that rebuilds an skb from an
xdp_framevia__xdp_build_skb_from_frame()), the HW RX checksum status is lost and the stack revalidates the L4 checksum in software.Two kfuncs are added:
-
bpf_xdp_metadata_rx_csum(): a device-bound RX-metadata hint, like the existingrx_hash/rx_vlan_tagones. It reports enumxdp_csum_status(XDP_CSUM_NONE/XDP_CSUM_VERIFIED) and is implemented for mlx5e, ice and veth.-
bpf_xdp_assert_rx_csum(): a generic, non-device-bound kfunc that lets the program assert the L4 checksum is correct. It sets a buff flag that rides into thexdp_frame, and__xdp_build_skb_from_frame()turns it intoskb->ip_summed=CHECKSUM_UNNECESSARY. The kernel cannot verify the assertion; the program takes responsibility, as it already does when rewriting packet contents.Posted as RFC to get feedback on:
- whether the read hint (
bpf_xdp_metadata_rx_csum()and its driver support) belongs in this series at all.bpf_xdp_assert_rx_csum()is self-contained and already covers the main use case: a program that computes or fixes the L4 checksum itself, or trusts the source, and wants the rebuilt skb to skip software revalidation. The read hint is an optimization for programs that did not touch the payload and only want to relay the hardware verdict. These could just as well be two independent series (assert-only first);
- the kfunc naming,bpf_xdp_assert_rx_csum()in particular.Testing:
Quoted 7 lines
- new selftest
xdp_cpumap_rx_csumdrives a frame through a native-XDP veth into a cpumap redirect and checks, via fexit on__xdp_build_skb_from_frame(), that the rebuilt skb isCHECKSUM_UNNECESSARYiff the program calledbpf_xdp_assert_rx_csum();
-xdp_metadatacallsbpf_xdp_metadata_rx_csum()over veth and checks both
verdicts:XDP_CSUM_NONEfor an AF_XDP-injected frame andXDP_CSUM_VERIFIEDfor one sent through the stack.
This was posted somewhat recently from Lorenzo (and had a fair bit of discussion), but there haven't been a follow up:
https://lore.kernel.org/bpf/[email protected]/
Quoted 47 lines · Stanislav Fomichev
Quoted 38 lines · Vladimir Vdovin
This series lets XDP programs work with the hardware RX checksum verdict:
read what the NIC concluded about a packet, and carry a "the L4 checksum is correct" assertion across a redirect so the stack does not revalidate it in software.When an XDP program redirects a frame to a cpumap (or any other path that rebuilds an skb from an
xdp_framevia__xdp_build_skb_from_frame()), the HW RX checksum status is lost and the stack revalidates the L4 checksum in software.Two kfuncs are added:
-
bpf_xdp_metadata_rx_csum(): a device-bound RX-metadata hint, like the existingrx_hash/rx_vlan_tagones. It reports enumxdp_csum_status(XDP_CSUM_NONE/XDP_CSUM_VERIFIED) and is implemented for mlx5e, ice and veth.-
bpf_xdp_assert_rx_csum(): a generic, non-device-bound kfunc that lets the program assert the L4 checksum is correct. It sets a buff flag that rides into thexdp_frame, and__xdp_build_skb_from_frame()turns it intoskb->ip_summed=CHECKSUM_UNNECESSARY. The kernel cannot verify the assertion; the program takes responsibility, as it already does when rewriting packet contents.Posted as RFC to get feedback on:
- whether the read hint (
bpf_xdp_metadata_rx_csum()and its driver support) belongs in this series at all.bpf_xdp_assert_rx_csum()is self-contained and already covers the main use case: a program that computes or fixes the L4 checksum itself, or trusts the source, and wants the rebuilt skb to skip software revalidation. The read hint is an optimization for programs that did not touch the payload and only want to relay the hardware verdict. These could just as well be two independent series (assert-only first);
- the kfunc naming,bpf_xdp_assert_rx_csum()in particular.Testing:
Quoted 7 lines
- new selftest
xdp_cpumap_rx_csumdrives a frame through a native-XDP veth into a cpumap redirect and checks, via fexit on__xdp_build_skb_from_frame(), that the rebuilt skb isCHECKSUM_UNNECESSARYiff the program calledbpf_xdp_assert_rx_csum();
-xdp_metadatacallsbpf_xdp_metadata_rx_csum()over veth and checks both
verdicts:XDP_CSUM_NONEfor an AF_XDP-injected frame andXDP_CSUM_VERIFIEDfor one sent through the stack.
Quoted 3 lines
This was posted somewhat recently from Lorenzo (and had a fair bit of discussion), but there haven't been a follow up:
https://lore.kernel.org/bpf/[email protected]/
Hi Vladimir and Stanislav,
AFAIK in my series we are just missing the drv self-test requested by Jakub. I have not the time to look into it yet.
@Vladimir: if you have any free-cycles, do you agree to introduce the missing
test requested by Jakub to my series? Thanks in advance.
Regards,
Lorenzo
Hi Lorenzo,
Sorry -- I blindly missed your earlier RX-checksum series before I posted mine, thanks Stanislav for the pointer.
To answer your question: yes, I'm happy to take on the driver selftest Jakub asked for.
As for my own series, the read side clearly overlaps yours and you own it, so I'll drop my bpf_xdp_metadata_rx_csum() hint and its driver bits.
What's left that is genuinely separate is the "assertion" half -- a non-dev-bound bpf_xdp_assert_rx_csum() that preserves the HW verdict across a cpumap/redirect: it sets a flag on the xdp_buff that rides into the xdp_frame and becomes skb->ip_summed = CHECKSUM_UNNECESSARY in __xdp_build_skb_from_frame().
Should I resend that as a small standalone series (v2, assert-only)? It also looks like a PoC that you and Jakub discussed on v3 [1].
A few things I'd like to confirm before writing the test:
1. API for v4. In the v3 discussion you agreed to rework the API to report both COMPLETE and UNNECESSARY (+ csum_level), per Jakub. Do you plan to send that in v4, or should the driver selftest target the current v3 signature (enum xdp_checksum + cksum_meta)? I'd rather write the test against the API you intend to keep.
2. Documented behavior. The selftest is meant to "check the documented expectation", so which rule should it assert -- "a driver must never report CHECKSUM_COMPLETE while an XDP program is attached", or that the driver downgrades/repairs COMPLETE on the XDP_PASS path? I'll write the doc paragraph and the test to match whatever we settle on.
3. Drivers. Your series adds veth and ice; I don't see mlx5e -- was that intentional (left to the driver maintainers)? I had an mlx5e implementation in my v1 and I'm happy to contribute it to your series if it's useful.
For the test itself I was thinking of extending tools/testing/selftests/drivers/net/hw/xdp_metadata.py, gated on the new "checksum" xdp-rx-metadata feature, with good-csum / bad-csum / modify + XDP_PASS cases. Does that match what you and Jakub had in mind?
[1] https://lore.kernel.org/bpf/[email protected]/
Thanks,
Vladimir
Quoted 1 line
Hi Lorenzo,
Hi Vladimir,
Quoted 3 lines
Sorry -- I blindly missed your earlier RX-checksum series before I posted mine, thanks Stanislav for the pointer.
No worries. My series is just adding a new kfunc to report the rx-csum result to an ebpf program running on the NIC. It does not take into account the XDP_REDIRECT use-case. This is orthogonal and we can work on it later.
Quoted 3 lines
To answer your question: yes, I'm happy to take on the driver selftest Jakub asked for.
Cool, thx :)
Quoted 4 lines
As for my own series, the read side clearly overlaps yours and you own it, so I'll drop my
bpf_xdp_metadata_rx_csum()hint and its driver bits.
Quoted 8 lines
What's left that is genuinely separate is the "assertion" half -- a non-dev-bound
bpf_xdp_assert_rx_csum()that preserves the HW verdict across a cpumap/redirect: it sets a flag on thexdp_buffthat rides into thexdp_frameand becomesskb->ip_summed=CHECKSUM_UNNECESSARYin__xdp_build_skb_from_frame().Should I resend that as a small standalone series (v2, assert-only)? It also looks like a PoC that you and Jakub discussed on v3 [1].
I think we should address the 'CHECKSUM_COMPLETE' use case for it, let's work on the problem later, even Jesper is interested in it ;)
Quoted 8 lines
A few things I'd like to confirm before writing the test:
1. API for v4. In the v3 discussion you agreed to rework the API to report both COMPLETE and UNNECESSARY (+
csum_level), per Jakub. Do you plan to send that in v4, or should the driver selftest target the current v3 signature (enumxdp_checksum+cksum_meta)? I'd rather write the test against the API you intend to keep.
IIRC I addressed the request (the code is in [0]). What is missing is just the self-test.
Quoted 6 lines
2. Documented behavior. The selftest is meant to "check the documented expectation", so which rule should it assert -- "a driver must never report
CHECKSUM_COMPLETEwhile an XDP program is attached", or that the driver downgrades/repairs COMPLETE on theXDP_PASSpath? I'll write the doc paragraph and the test to match whatever we settle on.
ack
Quoted 5 lines
3. Drivers. Your series adds veth and ice; I don't see mlx5e -- was that intentional (left to the driver maintainers)? I had an mlx5e implementation in my v1 and I'm happy to contribute it to your series if it's useful.
My series does not intend to address all the drivers :)
Quoted 5 lines
For the test itself I was thinking of extending
tools/testing/selftests/drivers/net/hw/xdp_metadata.py, gated on the new "checksum" xdp-rx-metadata feature, with good-csum / bad-csum / modify +XDP_PASScases. Does that match what you and Jakub had in mind?
That was my idea too.
Regards,
Lorenzo
Quoted 5 lines
[1] https://lore.kernel.org/bpf/[email protected]/
Thanks,
Vladimir
[0] https://github.com/LorenzoBianconi/net-next/commits/b4/bpf-xdp-meta-rxcksum/
Jesper Dangaard Brouer
maintainerOn 02/07/2026 16.52, Lorenzo Bianconi wrote:
[...]
Quoted 7 lines
Quoted 7 lines
What's left that is genuinely separate is the "assertion" half -- a non-dev-bound
bpf_xdp_assert_rx_csum()that preserves the HW verdict across a cpumap/redirect: it sets a flag on thexdp_buffthat rides into thexdp_frameand becomesskb->ip_summed=CHECKSUM_UNNECESSARYin__xdp_build_skb_from_frame().
Quoted 6 lines
Quoted 2 lines
Should I resend that as a small standalone series (v2, assert-only)? It also looks like a PoC that you and Jakub discussed on v3 [1].
I think we should address the '
CHECKSUM_COMPLETE' use case for it, let's work on the problem later, even Jesper is interested in it ;)
Yes, I'm very interested in this use-case of transferring HW offload info when XDP_REDIRECT'ing into CPUMAP or veth. In my patchset[1] I've added rx_hash, rx_vlan_tag, and rx_timestamp, but not csum as it was not available. My short term use-case is: RX-hash as setting it earlier allows the GRO engine to hash flows (see dev_gro_receive[2]), plus it carries info on packet protocol type TCP/UDP IPv4/IPv6.
- [1] https://lore.kernel.org/all/175146824674.1421237.18351246421763677468.stgit@firesoul/#r
- [2] https://elixir.bootlin.com/linux/v7.1.2/source/net/core/gro.c#L477
The long term[3] vision behind the patchset is that xdp_frame becomes the "mini-SKB" that carries enough offload info to avoid allocating SKBs in the driver. The ICE driver is very close to this vision. See [4] where it calls xdp_build_skb_from_buff() and later fills out SKB fields with HW offloads (ice_process_skb_fields).
What I'm asking is that we generalize this idea of transferring or storing HW offloads, that are relevant to the SKB. My patchset makes info avail to both xdp_buff and xdp_frame by storing data[5] in the packet top headroom (extending xdp_frame). And like your patch[6] use xdp_buff_flags to tell with is active. You patch only needed a single flag as you only handle CHECKSUM_UNNECESSARY, but Lorenzo's patch also have CHECKSUM_COMPLETE, for which we need to store a csum.
I cannot remember if it was Kuba or Eric that suggested (at netdevconf) that instead of using a fixed struct, that I should use the same scheme as SKB extensions. We could call it SKB core-extensions, to signal the possibility to move existing SKB member into this area.
--Jesper
- [3] https://lore.kernel.org/all/[email protected]/
- [4] https://elixir.bootlin.com/linux/v7.1.2/source/drivers/net/ethernet/intel/ice/ice_txrx.c#L1044-L1060
- [5] https://lore.kernel.org/all/175146829944.1421237.13943404585579626611.stgit@firesoul/
- [6] https://lore.kernel.org/all/[email protected]/
cover selftests: drv-net: XDP RX checksum metadata test
In reply to Lorenzo BianconiHi Lorenzo,
Here is the driver selftest for your XDP RX checksum series, as discussed. It is written against your b4/bpf-xdp-meta-rxcksum branch (the bitmask ip_summed + cksum/cksum_level API) and applies on top of it rebased onto net-next, since the drv-net xdp_metadata.py test it extends only exists there. Feel free to pick it straight into v4.
It adds an xdp_rx_csum program to xdp_metadata.bpf.o and two cases gated on the "checksum" xdp-rx-metadata feature (SKIP on devices without it, e.g. netdevsim):
- xdp_rx_csum_valid (tcp/udp variants): traffic with a correct checksum from the remote endpoint must be reported with a usable verdict (CHECKSUM_UNNECESSARY and/or CHECKSUM_COMPLETE);
- xdp_rx_csum_invalid: UDP with a corrupted L4 checksum (net/lib csum -E) must not be reported as CHECKSUM_UNNECESSARY.
One question on the invalid case: I assert only that UNNECESSARY is not set for a corrupted checksum (COMPLETE may still legitimately be reported, since it carries the raw sum for wrong packets too). Is that the documented expectation you and Jakub want the test to encode, or should it be stricter?
Thanks,
Vladimir
Vladimir Vdovin (1):
selftests: drv-net: add XDP RX checksum metadata tests
.../selftests/drivers/net/hw/xdp_metadata.py | 103 ++++++++++++++++ .../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++++-- 2 files changed, 202 insertions(+), 13 deletions(-)
Signature · 1 line
2.47.0
PATCH 1/1 selftests: drv-net: add XDP RX checksum metadata tests
Extend the xdp_metadata.py driver test with coverage for bpf_xdp_metadata_rx_checksum().
Add an xdp_rx_csum program to xdp_metadata.bpf.o that reads the RX checksum verdict and stores the ip_summed bitmask, the hw checksum value and the checksum level into a map. The L4 port/protocol filter is the same as in the existing xdp_rss_hash program, so move it into a common helper.
The new cases only run on devices whose driver implements the xmo_rx_checksum callback, detected through the "checksum" bit of the xdp-rx-metadata-features netlink attribute; on other devices they report SKIP:
- xdp_rx_csum_valid (tcp/udp variants): traffic with a correct checksum sent from the remote endpoint must be reported with a usable verdict, i.e. CHECKSUM_UNNECESSARY and/or CHECKSUM_COMPLETE;
- xdp_rx_csum_invalid: UDP packets with a corrupted L4 checksum (sent with the net/lib csum tool) must not be reported as CHECKSUM_UNNECESSARY.
--- .../selftests/drivers/net/hw/xdp_metadata.py | 103 ++++++++++++++++ .../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++++-- 2 files changed, 202 insertions(+), 13 deletions(-)
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +103 -0
@@ -8,6 +8,8 @@ These tests load device-bound XDP programs from xdp_metadata.bpf.o that call metadata kfuncs, send traffic, and verify the extracted metadata via BPF maps. """ +import time + from lib.py import ksft_run, ksft_eq, ksft_exit, ksft_ge, ksft_ne, ksft_pr from lib.py import KsftNamedVariant, ksft_variants from lib.py import CmdExitFailure, KsftSkipEx, NetDrvEpEnv
@@ -81,8 +83,22 @@ _RSS_KEY_TYPE = 1 _RSS_KEY_PKT_CNT = 2 _RSS_KEY_ERR_CNT = 3 +_CSUM_KEY_IP_SUMMED = 0 +_CSUM_KEY_CKSUM = 1 +_CSUM_KEY_LEVEL = 2 +_CSUM_KEY_PKT_CNT = 3 +_CSUM_KEY_ERR_CNT = 4 + XDP_RSS_L4 = 0x8 # BIT(3) from enum xdp_rss_hash_type +# Mirror of enum xdp_checksum from include/net/xdp.h +XDP_CHECKSUM_NONE = 0x1 +XDP_CHECKSUM_UNNECESSARY = 0x2 +XDP_CHECKSUM_COMPLETE = 0x4 + +# Fixed destination port of the net/lib csum tool +_CSUM_TOOL_PORT = 34000 + @ksft_variants([ KsftNamedVariant("tcp", "tcp"),
@@ -130,6 +146,91 @@ def test_xdp_rss_hash(cfg, proto): f"RSS hash type should include L4 for {proto.upper()} traffic") +def _require_rx_csum_meta(cfg): + """Skip unless the device exposes XDP RX checksum metadata.""" + dev_info = cfg.netnl.dev_get({"ifindex": cfg.ifindex}) + rx_meta = dev_info.get("xdp-rx-metadata-features", []) + if "checksum" not in rx_meta: + raise KsftSkipEx("device does not support XDP rx checksum metadata") + + +@ksft_variants([ + KsftNamedVariant("tcp", "tcp"), + KsftNamedVariant("udp", "udp"), +]) +def test_xdp_rx_csum_valid(cfg, proto): + """Test RX checksum metadata for packets with a correct checksum. + + Loads the xdp_rx_csum program, sends traffic with a valid L4 checksum + from the remote endpoint, and verifies that the device reported a + usable checksum verdict (CHECKSUM_UNNECESSARY and/or a + CHECKSUM_COMPLETE value) via bpf_xdp_metadata_rx_checksum(). + """ + _require_rx_csum_meta(cfg) + + prog_info = _load_xdp_metadata_prog(cfg, "xdp_rx_csum") + + port = rand_port() + bpf_map_set("map_xdp_setup", _SETUP_KEY_PORT, port) + + csum_map_id = prog_info["maps"]["map_csum"] + + _send_probe(cfg, port, proto=proto) + + csum = bpf_map_dump(csum_map_id) + + pkt_cnt = csum.get(_CSUM_KEY_PKT_CNT, 0) + err_cnt = csum.get(_CSUM_KEY_ERR_CNT, 0) + ip_summed = csum.get(_CSUM_KEY_IP_SUMMED, 0) + + ksft_ge(pkt_cnt, 1, comment="should have received at least one packet") + ksft_eq(err_cnt, 0, comment=f"RX checksum error count: {err_cnt}") + + ksft_pr(f" ip_summed: {ip_summed:#x} cksum: " + f"{csum.get(_CSUM_KEY_CKSUM, 0):#010x} " + f"level: {csum.get(_CSUM_KEY_LEVEL, 0)}") + ksft_ne(ip_summed & (XDP_CHECKSUM_UNNECESSARY | XDP_CHECKSUM_COMPLETE), 0, + "device should report a checksum verdict for a valid packet") + + +def test_xdp_rx_csum_invalid(cfg): + """Test RX checksum metadata for packets with a corrupted checksum. + + Sends UDP packets with an intentionally bad L4 checksum using the + net/lib csum tool and verifies the device does not claim it validated + them: the CHECKSUM_UNNECESSARY bit must not be set. + """ + _require_rx_csum_meta(cfg) + + ipver = cfg.addr_ipver + bin_remote = cfg.remote.deploy(cfg.net_lib_dir / "csum") + + prog_info = _load_xdp_metadata_prog(cfg, "xdp_rx_csum") + + bpf_map_set("map_xdp_setup", _SETUP_KEY_PORT, _CSUM_TOOL_PORT) + + csum_map_id = prog_info["maps"]["map_csum"] + + cmd(f"{bin_remote} -i {cfg.remote_ifname} -n 20 -{ipver} " + f"-S {cfg.remote_addr} -D {cfg.addr} -r 1 -T -E", + host=cfg.remote) + + # no receiver to synchronize against; let NAPI drain the last packets + time.sleep(1) + + csum = bpf_map_dump(csum_map_id) + + pkt_cnt = csum.get(_CSUM_KEY_PKT_CNT, 0) + ip_summed = csum.get(_CSUM_KEY_IP_SUMMED, 0) + + ksft_ge(pkt_cnt, 1, comment="should have received at least one packet") + + ksft_pr(f" ip_summed: {ip_summed:#x}") + ksft_eq(ip_summed & XDP_CHECKSUM_UNNECESSARY, 0, + "device must not report CHECKSUM_UNNECESSARY for a corrupted " + "checksum") + + def main(): """Run XDP metadata kfunc tests against a real device.""" with NetDrvEpEnv(__file__) as cfg:
@@ -137,6 +238,8 @@ def main(): ksft_run( [ test_xdp_rss_hash, + test_xdp_rx_csum_valid, + test_xdp_rx_csum_invalid, ], args=(cfg,)) ksft_exit()
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +99 -13
180 lines not on this page · raw message
Signature · 1 line
2.47.0
[email protected]
AI reviewRe: [PATCH bpf-next 1/1] selftests: drv-net: add XDP RX checksum metadata tests
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] The BPF program overwrites checksum metadata on every packet, which may cause TCP tests to…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The BPF program overwrites checksum metadata on every packet, which may cause TCP tests to spuriously fail if trailing control packets lack checksum offload.
- [Low] Multi-line comments do not follow the mandatory BPF subsystem comment style (opening /* must be on its own line).
--
--- Patch [1]: [PATCH bpf-next 1/1] selftests: drv-net: add XDP RX checksum metadata tests --- commit d0f16a1bf595df9c0de880826075e44c316407e0
Author: Vladimir Vdovin <[email protected]>
selftests: drv-net: add XDP RX checksum metadata tests
Extend the xdp_metadata driver tests with coverage for bpf_xdp_metadata_rx_checksum(). Adds a BPF program to read and store the verdict, and Python tests to validate both valid and invalid RX checksums.
Quoted 4 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +0
-0
[ ... ]
Quoted 5 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +1
-0@@ -130,6 +146,91 @@ def test_xdp_rss_hash(cfg, proto): f"RSS hash type should include L4 for {proto.upper()} traffic") +def _require_rx_csum_meta(cfg):
[ ... ]
Quoted 5 lines
+@ksft_variants([
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +4
-0+ KsftNamedVariant("tcp", "tcp"), + KsftNamedVariant("udp", "udp"), +]) +def test_xdp_rx_csum_valid(cfg, proto):
[ ... ]
Quoted 4 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +4
-0+ csum = bpf_map_dump(csum_map_id) + + pkt_cnt = csum.get(_CSUM_KEY_PKT_CNT, 0) + err_cnt = csum.get(_CSUM_KEY_ERR_CNT, 0)
tools/testing/selftests/drivers/net/hw/xdp_metadata.py def test_xdp_rss_hash(cfg, proto): · line 193
Quoted 10 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +10
-0+ ip_summed = csum.get(_CSUM_KEY_IP_SUMMED, 0) + + ksft_ge(pkt_cnt, 1, comment="should have received at least one packet") + ksft_eq(err_cnt, 0, comment=f"RX checksum error count: {err_cnt}") + + ksft_pr(f" ip_summed: {ip_summed:#x} cksum: " + f"{csum.get(_CSUM_KEY_CKSUM, 0):#010x} " + f"level: {csum.get(_CSUM_KEY_LEVEL, 0)}") + ksft_ne(ip_summed & (XDP_CHECKSUM_UNNECESSARY | XDP_CHECKSUM_COMPLETE), 0, + "device should report a checksum verdict for a valid packet")
[Severity: Medium]
Will this test sporadically fail for TCP traffic? Since multiple packets might be exchanged, the final state of ip_summed could be from a trailing control packet (like FIN or RST) that lacks checksum offload, leading to a failure here.
Quoted 3 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +3
-0+ + +def test_xdp_rx_csum_invalid(cfg):
[ ... ]
Quoted 4 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +0
-0
[ ... ]
tools/testing/selftests/net/lib/xdp_metadata.bpf.c struct { · line 46
Quoted 7 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +3
-0@@ -40,6 +41,24 @@ struct {__uint (max_entries,4 ); } map_rss SEC(".maps"); +/* RX checksum results: key 0 = ip_summed bitmask, key 1 = hw cksum value, +* key 2 = cksum level, key 3 = packet count, key 4 = error count. +*/
[Severity: Low]
This isn't a bug, but the BPF subsystem prefers multi-line comments to have the opening /* on its own line. Could this be adjusted?
Quoted 2 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +2
-0+enum { +CSUM_KEY_IP_SUMMED =0 ,
[ ... ]
tools/testing/selftests/net/lib/xdp_metadata.bpf.c enum xdp_rss_hash_type { · line 79
Quoted 7 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +3
-0@@ -55,8 +74,20 @@ enum xdp_rss_hash_type { XDP_RSS_L4_ICMP = 1U << 8, }; +/* Mirror of enum xdp_checksum from include/net/xdp.h. +* Needed because the enum is not part of UAPI headers. +*/
[Severity: Low]
This isn't a bug, but could the opening /* be placed on its own line to match BPF comment style?
Quoted 2 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +2
-0+enum xdp_checksum { +XDP_CHECKSUM_NONE =1U <<0 ,
[ ... ]
tools/testing/selftests/net/lib/xdp_metadata.bpf.c static __always_inline __u16 get_dest_port(void *l4, void *data_end, · line 114
Quoted 9 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +3
-2@@ -78,41 +109,39 @@ static __always_inline __u16 get_dest_port(void *l4, void *data_end,return 0 ; } -SEC("xdp") -int xdp_rss_hash (struct xdp_md *ctx) +/* Return true when the packet matches the L4 protocol and destination +* port configured in map_xdp_setup (zero/unset filters match anything). +*/
[Severity: Low]
This isn't a bug, but could the opening /* be placed on its own line to match BPF comment style?
Quoted 2 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +1
-0+static __always_inline bool xdp_match_setup(struct xdp_md *ctx) {
[ ... ]
Quoted 7 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +3
-0@@ -160,4 +204,46 @@ int xdp_rss_hash(struct xdp_md *ctx)return XDP_PASS ; } +SEC("xdp") +int xdp_rx_csum (struct xdp_md *ctx) +{
[ ... ]
tools/testing/selftests/net/lib/xdp_metadata.bpf.c int xdp_rss_hash(struct xdp_md *ctx) · line 232
Quoted 13 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +13
-0+ ret =bpf_xdp_metadata_rx_checksum (ctx, &ip_summed, &cksum, + &cksum_level); +if (ret <0 ) { + key =CSUM_KEY_ERR_CNT ; + cnt =bpf_map_lookup_elem (&map_csum, &key); +if (cnt) +__sync_fetch_and_add (cnt,1 ); +return XDP_PASS ; + } + + key =CSUM_KEY_IP_SUMMED ; + val = (__u32 )ip_summed; +bpf_map_update_elem (&map_csum, &key, &val,BPF_ANY );
[Severity: Medium]
Does this update overwrite the checksum metadata on every packet? If so, the map will only contain the verdict of the last processed packet, which could be an empty control packet without checksum offload, leading to incorrect test failures. Can we accumulate the results or only update if the packet carries a payload?
Quoted 7 lines
tools/testing/selftests/net/lib/xdp_metadata.bpf.c +7
-0+ + key =CSUM_KEY_CKSUM ; +bpf_map_update_elem (&map_csum, &key, &cksum,BPF_ANY ); + + key =CSUM_KEY_LEVEL ; + val = cksum_level; +bpf_map_update_elem (&map_csum, &key, &val,BPF_ANY );
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/6c7a059057d309e999b706b5b547be9c620ce544.1783514455.git.deliran@verdict.gg?part=1
[email protected]
AI reviewRe: [PATCH bpf-next 1/1] selftests: drv-net: add XDP RX checksum metadata tests
In reply to Vladimir VdovinThis isn't a bug, but XDP_CHECKSUM_NONE does not seem to be used anywhere in the test; was it intended to mirror the full enum for documentation, or could it be dropped to match the nearby…
Quoted 4 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +0
-0
[ ... ]
Quoted 6 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +2
-0@@ -81,8 +83,22 @@ _RSS_KEY_TYPE = 1 _RSS_KEY_PKT_CNT = 2 _RSS_KEY_ERR_CNT = 3 +_CSUM_KEY_IP_SUMMED = 0 +_CSUM_KEY_CKSUM = 1
tools/testing/selftests/drivers/net/hw/xdp_metadata.py _RSS_KEY_TYPE = 1 · line 97
Quoted 10 lines
tools/testing/selftests/drivers/net/hw/xdp_metadata.py +8
-0+_CSUM_KEY_LEVEL = 2 +_CSUM_KEY_PKT_CNT = 3 +_CSUM_KEY_ERR_CNT = 4 + XDP_RSS_L4 = 0x8 # BIT(3) from enum xdp_rss_hash_type +# Mirror of enum xdp_checksum from include/net/xdp.h +XDP_CHECKSUM_NONE = 0x1 +XDP_CHECKSUM_UNNECESSARY = 0x2 +XDP_CHECKSUM_COMPLETE = 0x4
This isn't a bug, but XDP_CHECKSUM_NONE does not seem to be used anywhere in the test; was it intended to mirror the full enum for documentation, or could it be dropped to match the nearby XDP_RSS_L4 which defines only the bit it uses?
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/28945032378
Re: [PATCH bpf-next 0/1] selftests: drv-net: XDP RX checksum metadata test
In reply to Vladimir VdovinQuoted 1 line
Hi Lorenzo,
Hi Vladimir,
Quoted 11 lines
Here is the driver selftest for your XDP RX checksum series, as discussed. It is written against your b4/bpf-xdp-meta-rxcksum branch (the bitmask
ip_summed+ cksum/cksum_level API) and applies on top of it rebased onto net-next, since the drv-netxdp_metadata.pytest it extends only exists there. Feel free to pick it straight into v4.It adds an
xdp_rx_csumprogram to xdp_metadata.bpf.o and two cases gated on the "checksum" xdp-rx-metadata feature (SKIP on devices without it, e.g. netdevsim):
Quoted 6 lines
-
xdp_rx_csum_valid(tcp/udp variants): traffic with a correct checksum from the remote endpoint must be reported with a usable verdict (CHECKSUM_UNNECESSARYand/orCHECKSUM_COMPLETE);-
xdp_rx_csum_invalid: UDP with a corrupted L4 checksum (net/lib csum -E) must not be reported asCHECKSUM_UNNECESSARY.
thx for working on it. Unfortunately I do not have the time to look into it a the moment. I rebased my b4/bpf-xdp-meta-rxcksum branch on top of net-next one. Feel free to repost it adding your patch on top of it.
Regards,
Lorenzo
Quoted 21 lines
One question on the invalid case: I assert only that UNNECESSARY is not set for a corrupted checksum (COMPLETE may still legitimately be reported, since it carries the raw sum for wrong packets too). Is that the documented expectation you and Jakub want the test to encode, or should it be stricter?
Thanks,
VladimirVladimir Vdovin (1):
selftests: drv-net: add XDP RX checksum metadata tests.../selftests/drivers/net/hw/xdp_metadata.py | 103 ++++++++++++++++ .../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++++-- 2 files changed, 202 insertions(+), 13 deletions(-)Signature · 1 line
2.47.0