* [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs
@ 2026-07-08 20:34 Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
` (5 more replies)
0 siblings, 6 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
Introduce bpf_xdp_metadata_rx_checksum() kfunc in order to load the HW
RX checksum results in the eBPF program bound to the NIC.
Implement xmo_rx_checksum callback for veth and ice drivers.
If the hardware detects a wrong/failed checksum, it will report
CHECKSUM_NONE in the packet metadata. Moreover, CHECKSUM_NONE will be
returned even if the NIC can't parse the packet (e.g. if it does not
support a specific protocol). A possible use case for
bpf_xdp_metadata_rx_checksum() would be to implement a XDP DDoS
application [1] combining the info from bpf_xdp_metadata_rx_checksum()
and bpf_xdp_metadata_rx_hash() kfuncs in order to filter packets with a
wrong/failed checksum.
This is a repost of Lorenzo's series, rebased on top of net-next, with
a new drv-net selftest for the RX checksum metadata added on top of it,
as Lorenzo suggested [2].
A note on the new selftest semantics: for traffic with a correct
checksum the test requires a usable verdict (CHECKSUM_UNNECESSARY
and/or CHECKSUM_COMPLETE) but reports SKIP on CHECKSUM_NONE, since the
API allows devices that do not verify the packets (e.g. veth reports
NONE for locally generated CHECKSUM_PARTIAL traffic). For corrupted
packets it only asserts that CHECKSUM_UNNECESSARY is not set, as
CHECKSUM_COMPLETE legitimately carries the raw checksum of bad packets
too.
[1] https://blog.cloudflare.com/unimog-cloudflares-edge-load-balancer/
[2] https://lore.kernel.org/r/ak5ox296M46FAcWX@lore-desk
---
Changes in v4:
- Report ip_summed as a bitmask of XDP_CHECKSUM_* values and return the
hw checksum and the checksum level via dedicated
bpf_xdp_metadata_rx_checksum() arguments
- Rebase on top of net-next
- Add a drv-net selftest for the XDP RX checksum metadata
- Link to v3: https://lore.kernel.org/r/20260217-bpf-xdp-meta-rxcksum-v3-0-30024c50ba71@kernel.org
Changes in v3:
- Remove leftover assignment from v2 in veth_xdp_rx_checksum()
- Fix typos
- Fix commit logs
- Link to v2: https://lore.kernel.org/r/20260213-bpf-xdp-meta-rxcksum-v2-0-a82c4802afbe@kernel.org
Changes in v2:
- Remove XDP_CHECKSUM_PARTIAL definition
- Improve veth_xdp_rx_checksum() callback
- Fix uninitialized case for cksum_meta in ice_get_rx_csum()
- Fix sparse warnings in ice driver
- Fix typos
- Link to v1: https://lore.kernel.org/r/20260210-bpf-xdp-meta-rxcksum-v1-0-e5d55caa0541@kernel.org
Changes in v1:
- Rebase on top of bpf-next
- Test ice driver using xdp_hw_metadata tool available in the bpf
kernel selftest
- Improve cover letter with an use-case for
bpf_xdp_metadata_rx_checksum()
- Link to RFC v2: https://lore.kernel.org/r/20250925-bpf-xdp-meta-rxcksum-v2-0-6b3fe987ce91@kernel.org
change-id: 20250925-bpf-xdp-meta-rxcksum-900685e2909d
Lorenzo Bianconi (5):
netlink: specs: Add XDP RX checksum capability to XDP metadata specs
net: veth: Add xmo_rx_checksum callback to veth driver
net: ice: Add xmo_rx_checksum callback
selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum
selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to
xdp_hw_metadat prog
Vladimir Vdovin (1):
selftests: drv-net: add XDP RX checksum metadata tests
Documentation/netlink/specs/netdev.yaml | 5 +
drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 123 ++++++++++++------
drivers/net/veth.c | 32 +++++
include/net/xdp.h | 18 +++
include/uapi/linux/netdev.h | 3 +
net/core/xdp.c | 32 +++++
tools/include/uapi/linux/netdev.h | 3 +
.../selftests/bpf/prog_tests/xdp_metadata.c | 9 ++
.../selftests/bpf/progs/xdp_hw_metadata.c | 7 +
.../selftests/bpf/progs/xdp_metadata.c | 2 +
tools/testing/selftests/bpf/xdp_hw_metadata.c | 31 +++++
tools/testing/selftests/bpf/xdp_metadata.h | 13 ++
.../selftests/drivers/net/hw/xdp_metadata.py | 110 ++++++++++++++++
.../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++--
14 files changed, 445 insertions(+), 55 deletions(-)
base-commit: 08030ddb87b4c6c6a2c03c82731b5e188f02f5b9
--
2.47.0
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
` (2 more replies)
2026-07-08 20:34 ` [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver Vladimir Vdovin
` (4 subsequent siblings)
5 siblings, 3 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
From: Lorenzo Bianconi <lorenzo@kernel.org>
Introduce XDP RX checksum capability to XDP metadata specs. XDP RX
checksum will be use by devices capable of exposing receive checksum
result via bpf_xdp_metadata_rx_checksum().
Moreover, introduce xmo_rx_checksum netdev callback in order to allow
the eBPF program bound to the device to retrieve the RX checksum result
computed by the hw NIC and reported via DMA descriptors.
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
Documentation/netlink/specs/netdev.yaml | 5 ++++
include/net/xdp.h | 18 ++++++++++++++
include/uapi/linux/netdev.h | 3 +++
net/core/xdp.c | 32 +++++++++++++++++++++++++
tools/include/uapi/linux/netdev.h | 3 +++
5 files changed, 61 insertions(+)
diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
index 5f143da7458c..6d0d90d3a614 100644
--- a/Documentation/netlink/specs/netdev.yaml
+++ b/Documentation/netlink/specs/netdev.yaml
@@ -61,6 +61,11 @@ definitions:
doc: |
Device is capable of exposing receive packet VLAN tag via
bpf_xdp_metadata_rx_vlan_tag().
+ -
+ name: checksum
+ doc: |
+ Device is capable of exposing receive checksum result via
+ bpf_xdp_metadata_rx_checksum().
-
type: flags
name: xsk-flags
diff --git a/include/net/xdp.h b/include/net/xdp.h
index aa742f413c35..e255ff786131 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -586,6 +586,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_CHECKSUM, \
+ NETDEV_XDP_RX_METADATA_CHECKSUM, \
+ bpf_xdp_metadata_rx_checksum, \
+ xmo_rx_checksum)
enum xdp_rx_metadata {
#define XDP_METADATA_KFUNC(name, _, __, ___) name,
@@ -643,12 +647,26 @@ enum xdp_rss_hash_type {
XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
};
+/* Please note the driver is required to invalidate the checksum if the NIC
+ * reports CHECKSUM_UNNECESSARY or CHECKSUM_COMPLETE and the eBPF program
+ * modifies the packet since it can change some fields validated by the
+ * checksum.
+ */
+enum xdp_checksum {
+ XDP_CHECKSUM_NONE = BIT(CHECKSUM_NONE),
+ XDP_CHECKSUM_UNNECESSARY = BIT(CHECKSUM_UNNECESSARY),
+ XDP_CHECKSUM_COMPLETE = BIT(CHECKSUM_COMPLETE),
+};
+
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_checksum)(const struct xdp_md *ctx,
+ enum xdp_checksum *ip_summed,
+ u32 *cksum, u8 *cksum_level);
};
#ifdef CONFIG_NET
diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
index 2f3ab75e8cc0..f8caade93c8c 100644
--- a/include/uapi/linux/netdev.h
+++ b/include/uapi/linux/netdev.h
@@ -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_CHECKSUM: Device is capable of exposing receive
+ * checksum result via bpf_xdp_metadata_rx_checksum().
*/
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_CHECKSUM = 8,
};
/**
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 9890a30584ba..9bcaa423ad17 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -961,6 +961,38 @@ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
return -EOPNOTSUPP;
}
+/**
+ * bpf_xdp_metadata_rx_checksum - Read XDP frame RX checksum.
+ * @ctx: XDP context pointer.
+ * @ip_summed: Return value pointer to a bitmask indicating available checksums.
+ * @cksum: Return value pointer indicating the hw checksum value.
+ * @cksum_level: Return value pointer indicating the checksum level result.
+ *
+ * In case of success, ``ip_summed`` is set to the RX checksum result. Possible
+ * values are:
+ * ``XDP_CHECKSUM_NONE``
+ * ``XDP_CHECKSUM_UNNECESSARY``
+ * ``XDP_CHECKSUM_COMPLETE``
+ * ``XDP_CHECKSUM_COMPLETE`` | ``XDP_CHECKSUM_UNNECESSARY``
+ *
+ * In case of success, ``cksum`` contains the checksum value calculated by the
+ * NIC. ``cksum`` is valid only if ``XDP_CHECKSUM_COMPLETE`` is set in
+ * ``ip_summed``. ``cksum_level`` contains the checksum level reported by the
+ * hw. ``cksum_level`` can be considered valid only if
+ * ``XDP_CHECKSUM_UNNECESSARY`` is set in ``ip_summed``.
+ *
+ * Return:
+ * * Returns 0 on success or ``-errno`` on error.
+ * * ``-EOPNOTSUPP`` : means device driver does not implement kfunc
+ * * ``-ENODATA`` : means no RX-checksum available for this frame
+ */
+__bpf_kfunc int bpf_xdp_metadata_rx_checksum(const struct xdp_md *ctx,
+ enum xdp_checksum *ip_summed,
+ u32 *cksum, u8 *cksum_level)
+{
+ return -EOPNOTSUPP;
+}
+
__bpf_kfunc_end_defs();
BTF_KFUNCS_START(xdp_metadata_kfunc_ids)
diff --git a/tools/include/uapi/linux/netdev.h b/tools/include/uapi/linux/netdev.h
index 2f3ab75e8cc0..f8caade93c8c 100644
--- a/tools/include/uapi/linux/netdev.h
+++ b/tools/include/uapi/linux/netdev.h
@@ -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_CHECKSUM: Device is capable of exposing receive
+ * checksum result via bpf_xdp_metadata_rx_checksum().
*/
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_CHECKSUM = 8,
};
/**
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:54 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback Vladimir Vdovin
` (3 subsequent siblings)
5 siblings, 2 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
From: Lorenzo Bianconi <lorenzo@kernel.org>
Implement xmo_rx_checksum callback in veth driver to report RX checksum
result to the eBPF program bounded to the veth device.
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
drivers/net/veth.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 1c5142149175..498d894d043d 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -1700,6 +1700,37 @@ static int veth_xdp_rx_vlan_tag(const struct xdp_md *ctx, __be16 *vlan_proto,
return err;
}
+static int veth_xdp_rx_checksum(const struct xdp_md *ctx,
+ enum xdp_checksum *ip_summed,
+ u32 *cksum, u8 *cksum_level)
+{
+ const struct veth_xdp_buff *_ctx = (void *)ctx;
+ const struct sk_buff *skb = _ctx->skb;
+
+ if (!skb)
+ return -ENODATA;
+
+ switch (skb->ip_summed) {
+ case CHECKSUM_COMPLETE:
+ *ip_summed = XDP_CHECKSUM_COMPLETE;
+ *cksum = skb->csum;
+ *cksum_level = 0;
+ break;
+ case CHECKSUM_UNNECESSARY:
+ *ip_summed = XDP_CHECKSUM_UNNECESSARY;
+ *cksum_level = skb->csum_level;
+ *cksum = 0;
+ break;
+ default:
+ *ip_summed = XDP_CHECKSUM_NONE;
+ *cksum_level = 0;
+ *cksum = 0;
+ break;
+ }
+
+ return 0;
+}
+
static const struct net_device_ops veth_netdev_ops = {
.ndo_init = veth_dev_init,
.ndo_open = veth_open,
@@ -1725,6 +1756,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_checksum = veth_xdp_rx_checksum,
};
#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:10 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 4/6] selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum Vladimir Vdovin
` (2 subsequent siblings)
5 siblings, 2 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
From: Lorenzo Bianconi <lorenzo@kernel.org>
Implement xmo_rx_checksum callback in ice driver to report RX checksum
result to the eBPF program bounded to the NIC.
Introduce ice_get_rx_csum utility routine in order to make the rx checksum
code reusable from ice_rx_csum()
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 123 ++++++++++++------
1 file changed, 81 insertions(+), 42 deletions(-)
diff --git a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
index e695a664e53d..3aa82ff03d9e 100644
--- a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
+++ b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
@@ -78,69 +78,48 @@ ice_rx_hash_to_skb(const struct ice_rx_ring *rx_ring,
libeth_rx_pt_set_hash(skb, hash, decoded);
}
-/**
- * ice_rx_gcs - Set generic checksum in skb
- * @skb: skb currently being received and modified
- * @rx_desc: receive descriptor
- */
-static void ice_rx_gcs(struct sk_buff *skb,
- const union ice_32b_rx_flex_desc *rx_desc)
-{
- const struct ice_32b_rx_flex_desc_nic *desc;
- u16 csum;
-
- desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
- skb->ip_summed = CHECKSUM_COMPLETE;
- csum = (__force u16)desc->raw_csum;
- skb->csum = csum_unfold((__force __sum16)swab16(csum));
-}
-
-/**
- * ice_rx_csum - Indicate in skb if checksum is good
- * @ring: the ring we care about
- * @skb: skb currently being received and modified
- * @rx_desc: the receive descriptor
- * @ptype: the packet type decoded by hardware
- *
- * skb->protocol must be set before this function is called
- */
static void
-ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
- union ice_32b_rx_flex_desc *rx_desc, u16 ptype)
+ice_get_rx_csum(const union ice_32b_rx_flex_desc *rx_desc, u16 ptype,
+ struct ice_rx_ring *ring, enum xdp_checksum *ip_summed,
+ u32 *cksum, u8 *cksum_level)
{
- struct libeth_rx_pt decoded;
+ struct libeth_rx_pt decoded = libie_rx_pt_parse(ptype);
u16 rx_status0, rx_status1;
bool ipv4, ipv6;
- /* Start with CHECKSUM_NONE and by default csum_level = 0 */
- skb->ip_summed = CHECKSUM_NONE;
-
- decoded = libie_rx_pt_parse(ptype);
if (!libeth_rx_pt_has_checksum(ring->netdev, decoded))
- return;
+ goto checksum_none;
rx_status0 = le16_to_cpu(rx_desc->wb.status_error0);
rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
-
if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
(decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||
decoded.inner_prot == LIBETH_RX_PT_INNER_ICMP)) {
- ice_rx_gcs(skb, rx_desc);
+ const struct ice_32b_rx_flex_desc_nic *desc;
+ __wsum wcsum;
+ u16 csum;
+
+ desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
+ *ip_summed = XDP_CHECKSUM_COMPLETE;
+ csum = (__force u16)desc->raw_csum;
+ wcsum = csum_unfold((__force __sum16)swab16(csum));
+ *cksum = (__force u32)wcsum;
+ *cksum_level = 0;
return;
}
/* check if HW has decoded the packet and checksum */
if (!(rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_L3L4P_S)))
- return;
+ goto checksum_none;
ipv4 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV4;
ipv6 = libeth_rx_pt_get_ip_ver(decoded) == LIBETH_RX_PT_OUTER_IPV6;
if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))) {
ring->vsi->back->hw_rx_eipe_error++;
- return;
+ goto checksum_none;
}
if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S))))
@@ -164,14 +143,51 @@ ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
* we need to bump the checksum level by 1 to reflect the fact that
* we are indicating we validated the inner checksum.
*/
- if (decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT)
- skb->csum_level = 1;
-
- skb->ip_summed = CHECKSUM_UNNECESSARY;
+ *cksum_level = decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT;
+ *ip_summed = XDP_CHECKSUM_UNNECESSARY;
+ *cksum = 0;
return;
checksum_fail:
ring->vsi->back->hw_csum_rx_error++;
+checksum_none:
+ *ip_summed = XDP_CHECKSUM_NONE;
+ *cksum_level = 0;
+ *cksum = 0;
+}
+
+/**
+ * ice_rx_csum - Indicate in skb if checksum is good
+ * @ring: the ring we care about
+ * @skb: skb currently being received and modified
+ * @rx_desc: the receive descriptor
+ * @ptype: the packet type decoded by hardware
+ *
+ * skb->protocol must be set before this function is called
+ */
+static void
+ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
+ union ice_32b_rx_flex_desc *rx_desc, u16 ptype)
+{
+ enum xdp_checksum ip_summed;
+ u8 cksum_level;
+ u32 cksum;
+
+ ice_get_rx_csum(rx_desc, ptype, ring, &ip_summed, &cksum,
+ &cksum_level);
+ switch (ip_summed) {
+ case XDP_CHECKSUM_UNNECESSARY:
+ skb->ip_summed = CHECKSUM_UNNECESSARY;
+ skb->csum_level = cksum_level;
+ break;
+ case XDP_CHECKSUM_COMPLETE:
+ skb->ip_summed = CHECKSUM_COMPLETE;
+ skb->csum = (__force __wsum)cksum;
+ break;
+ default:
+ skb->ip_summed = CHECKSUM_NONE;
+ break;
+ }
}
/**
@@ -566,6 +582,28 @@ static int ice_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
return 0;
}
+/**
+ * ice_xdp_rx_checksum - RX checksum XDP hint handler
+ * @ctx: XDP buff pointer
+ * @ip_summed: RX checksum result destination address
+ * @cksum: RX checksum value destination address
+ * @cksum_level: RX checksum level value destination address
+ */
+static int ice_xdp_rx_checksum(const struct xdp_md *ctx,
+ enum xdp_checksum *ip_summed,
+ u32 *cksum, u8 *cksum_level)
+{
+ const struct libeth_xdp_buff *xdp_ext = (void *)ctx;
+ const union ice_32b_rx_flex_desc *rx_desc = xdp_ext->desc;
+ struct ice_rx_ring *ring;
+
+ ring = libeth_xdp_buff_to_rq(xdp_ext, typeof(*ring), xdp_rxq);
+ ice_get_rx_csum(rx_desc, ice_get_ptype(rx_desc), ring, ip_summed,
+ cksum, cksum_level);
+
+ return 0;
+}
+
/**
* ice_xdp_rx_vlan_tag - VLAN tag XDP hint handler
* @ctx: XDP buff pointer
@@ -598,4 +636,5 @@ 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_checksum = ice_xdp_rx_checksum,
};
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 4/6] selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
` (2 preceding siblings ...)
2026-07-08 20:34 ` [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests Vladimir Vdovin
5 siblings, 0 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
From: Lorenzo Bianconi <lorenzo@kernel.org>
Introduce dedicated selftest for bpf_xdp_metadata_rx_checksum kfunc to
bpf selftest framework.
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
tools/testing/selftests/bpf/prog_tests/xdp_metadata.c | 9 +++++++++
tools/testing/selftests/bpf/progs/xdp_metadata.c | 2 ++
tools/testing/selftests/bpf/xdp_metadata.h | 9 +++++++++
3 files changed, 20 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
index 5c31054ad4a4..91de61c822f5 100644
--- a/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_metadata.c
@@ -310,6 +310,15 @@ static int verify_xsk_metadata(struct xsk *xsk, bool sent_from_af_xdp)
if (!ASSERT_NEQ(meta->rx_hash, 0, "rx_hash"))
return -1;
+ if (!ASSERT_EQ(meta->ip_summed, XDP_CHECKSUM_NONE, "rx_ip_summed"))
+ return -1;
+
+ if (!ASSERT_EQ(meta->cksum, 0, "rx_cksum"))
+ return -1;
+
+ if (!ASSERT_EQ(meta->cksum_level, 0, "rx_cksum_level"))
+ return -1;
+
if (!sent_from_af_xdp) {
if (!ASSERT_NEQ(meta->rx_hash_type & XDP_RSS_TYPE_L4, 0, "rx_hash_type"))
return -1;
diff --git a/tools/testing/selftests/bpf/progs/xdp_metadata.c b/tools/testing/selftests/bpf/progs/xdp_metadata.c
index 09bb8a038d52..af1e19d48d67 100644
--- a/tools/testing/selftests/bpf/progs/xdp_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_metadata.c
@@ -98,6 +98,8 @@ int rx(struct xdp_md *ctx)
bpf_xdp_metadata_rx_hash(ctx, &meta->rx_hash, &meta->rx_hash_type);
bpf_xdp_metadata_rx_vlan_tag(ctx, &meta->rx_vlan_proto,
&meta->rx_vlan_tci);
+ bpf_xdp_metadata_rx_checksum(ctx, &meta->ip_summed, &meta->cksum,
+ &meta->cksum_level);
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}
diff --git a/tools/testing/selftests/bpf/xdp_metadata.h b/tools/testing/selftests/bpf/xdp_metadata.h
index 87318ad1117a..bca09b94af26 100644
--- a/tools/testing/selftests/bpf/xdp_metadata.h
+++ b/tools/testing/selftests/bpf/xdp_metadata.h
@@ -30,6 +30,10 @@ enum xdp_meta_field {
XDP_META_FIELD_VLAN_TAG = BIT(2),
};
+#define XDP_CHECKSUM_NONE BIT(0)
+#define XDP_CHECKSUM_UNNECESSARY BIT(1)
+#define XDP_CHECKSUM_COMPLETE BIT(2)
+
struct xdp_meta {
union {
__u64 rx_timestamp;
@@ -48,5 +52,10 @@ struct xdp_meta {
};
__s32 rx_vlan_tag_err;
};
+ struct {
+ __u32 ip_summed;
+ __u32 cksum;
+ __u8 cksum_level;
+ };
enum xdp_meta_field hint_valid;
};
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
` (3 preceding siblings ...)
2026-07-08 20:34 ` [PATCH bpf-next v4 4/6] selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:45 ` sashiko-bot
2026-07-10 10:11 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests Vladimir Vdovin
5 siblings, 2 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
From: Lorenzo Bianconi <lorenzo@kernel.org>
Introduce the capability to dump HW rx checksum in xdp_hw_metadata
program via bpf_xdp_metadata_rx_checksum() kfunc.
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
.../selftests/bpf/progs/xdp_hw_metadata.c | 7 +++++
tools/testing/selftests/bpf/xdp_hw_metadata.c | 31 +++++++++++++++++++
tools/testing/selftests/bpf/xdp_metadata.h | 12 ++++---
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
index 330ece2eabdb..5eeadb7e27cf 100644
--- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
@@ -110,6 +110,13 @@ int rx(struct xdp_md *ctx)
else
meta->hint_valid |= XDP_META_FIELD_VLAN_TAG;
+ err = bpf_xdp_metadata_rx_checksum(ctx, &meta->ip_summed,
+ &meta->cksum, &meta->cksum_level);
+ if (err)
+ meta->rx_cksum_err = err;
+ else
+ meta->hint_valid |= XDP_META_FIELD_CHECKSUM;
+
__sync_add_and_fetch(&pkts_redir, 1);
return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
}
diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c b/tools/testing/selftests/bpf/xdp_hw_metadata.c
index 6db3b5555a22..c63a70a54075 100644
--- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
+++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
@@ -8,6 +8,7 @@
* - Metadata verified:
* - rx_timestamp
* - rx_hash
+ * - rx_checksum
*
* TX:
* - UDP 9091 packets trigger TX reply
@@ -219,6 +220,30 @@ static void print_vlan_tci(__u16 tag)
printf("PCP=%u, DEI=%d, VID=0x%X\n", pcp, dei, vlan_id);
}
+static void print_rx_cksum(__u8 ip_summed, __u32 cksum, __u8 cksum_level)
+{
+ const char *cksum_str;
+
+ switch (ip_summed) {
+ case XDP_CHECKSUM_COMPLETE | XDP_CHECKSUM_UNNECESSARY:
+ cksum_str = "CHECKSUM_COMPLETE,CHECKSUM_UNNECESSARY";
+ break;
+ case XDP_CHECKSUM_UNNECESSARY:
+ cksum_str = "CHECKSUM_UNNECESSARY";
+ break;
+ case XDP_CHECKSUM_COMPLETE:
+ cksum_str = "CHECKSUM_COMPLETE";
+ break;
+ case XDP_CHECKSUM_NONE:
+ default:
+ cksum_str = "CHECKSUM_NONE";
+ break;
+ }
+
+ printf("rx-cksum: %s, csum=0x%x, cksum_level=0x%x\n",
+ cksum_str, cksum, cksum_level);
+}
+
static void verify_xdp_metadata(void *data, clockid_t clock_id)
{
struct xdp_meta *meta;
@@ -254,6 +279,12 @@ static void verify_xdp_metadata(void *data, clockid_t clock_id)
printf("No rx_vlan_tci or rx_vlan_proto, err=%d\n",
meta->rx_vlan_tag_err);
}
+
+ if (meta->hint_valid & XDP_META_FIELD_CHECKSUM)
+ print_rx_cksum(meta->ip_summed, meta->cksum,
+ meta->cksum_level);
+ else
+ printf("No rx_cksum, err=%d\n", meta->rx_cksum_err);
}
static void verify_skb_metadata(int fd)
diff --git a/tools/testing/selftests/bpf/xdp_metadata.h b/tools/testing/selftests/bpf/xdp_metadata.h
index bca09b94af26..f864d4a8bd8c 100644
--- a/tools/testing/selftests/bpf/xdp_metadata.h
+++ b/tools/testing/selftests/bpf/xdp_metadata.h
@@ -28,6 +28,7 @@ enum xdp_meta_field {
XDP_META_FIELD_TS = BIT(0),
XDP_META_FIELD_RSS = BIT(1),
XDP_META_FIELD_VLAN_TAG = BIT(2),
+ XDP_META_FIELD_CHECKSUM = BIT(3),
};
#define XDP_CHECKSUM_NONE BIT(0)
@@ -52,10 +53,13 @@ struct xdp_meta {
};
__s32 rx_vlan_tag_err;
};
- struct {
- __u32 ip_summed;
- __u32 cksum;
- __u8 cksum_level;
+ union {
+ struct {
+ __u32 ip_summed;
+ __u32 cksum;
+ __u8 cksum_level;
+ };
+ __s32 rx_cksum_err;
};
enum xdp_meta_field hint_valid;
};
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
` (4 preceding siblings ...)
2026-07-08 20:34 ` [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Vladimir Vdovin
@ 2026-07-08 20:34 ` Vladimir Vdovin
2026-07-08 20:41 ` sashiko-bot
2026-07-10 10:12 ` Loktionov, Aleksandr
5 siblings, 2 replies; 18+ messages in thread
From: Vladimir Vdovin @ 2026-07-08 20:34 UTC (permalink / raw)
To: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski
Cc: Jakub Sitnicki, Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest, Vladimir Vdovin
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.
CHECKSUM_NONE is a legitimate verdict for a device that does not
verify the packets (e.g. veth reports it for locally generated
CHECKSUM_PARTIAL traffic), so it results in SKIP rather than in a
failure;
- 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.
Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
---
.../selftests/drivers/net/hw/xdp_metadata.py | 110 +++++++++++++++++
.../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++++--
2 files changed, 209 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/xdp_metadata.py b/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
index 33a1985356d9..1a623771477b 100644
--- a/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
+++ b/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
@@ -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,98 @@ 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 checksum verdict
+ reported via bpf_xdp_metadata_rx_checksum() is usable
+ (CHECKSUM_UNNECESSARY and/or a CHECKSUM_COMPLETE value).
+
+ CHECKSUM_NONE is a valid verdict for a device that did not verify
+ the packets (e.g. veth reports it for locally generated traffic,
+ which is CHECKSUM_PARTIAL on the skb), so it results in SKIP, not
+ in a failure.
+ """
+ _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, 0, "the program should have stored a checksum verdict")
+ if not ip_summed & (XDP_CHECKSUM_UNNECESSARY | XDP_CHECKSUM_COMPLETE):
+ raise KsftSkipEx("device did not verify the packet checksum "
+ "(CHECKSUM_NONE)")
+
+
+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 +245,8 @@ def main():
ksft_run(
[
test_xdp_rss_hash,
+ test_xdp_rx_csum_valid,
+ test_xdp_rx_csum_invalid,
],
args=(cfg,))
ksft_exit()
diff --git a/tools/testing/selftests/net/lib/xdp_metadata.bpf.c b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
index f71f59215239..70decae0a663 100644
--- a/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
+++ b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <stddef.h>
+#include <stdbool.h>
#include <linux/bpf.h>
#include <linux/in.h>
#include <linux/if_ether.h>
@@ -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.
+ */
+enum {
+ CSUM_KEY_IP_SUMMED = 0,
+ CSUM_KEY_CKSUM = 1,
+ CSUM_KEY_LEVEL = 2,
+ CSUM_KEY_PKT_CNT = 3,
+ CSUM_KEY_ERR_CNT = 4,
+};
+
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __type(key, __u32);
+ __type(value, __u32);
+ __uint(max_entries, 5);
+} map_csum SEC(".maps");
+
/* Mirror of enum xdp_rss_hash_type from include/net/xdp.h.
* Needed because the enum is not part of UAPI headers.
*/
@@ -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.
+ */
+enum xdp_checksum {
+ XDP_CHECKSUM_NONE = 1U << 0,
+ XDP_CHECKSUM_UNNECESSARY = 1U << 1,
+ XDP_CHECKSUM_COMPLETE = 1U << 2,
+};
+
extern int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, __u32 *hash,
enum xdp_rss_hash_type *rss_type) __ksym;
+extern int bpf_xdp_metadata_rx_checksum(const struct xdp_md *ctx,
+ enum xdp_checksum *ip_summed,
+ __u32 *cksum, __u8 *cksum_level) __ksym;
static __always_inline __u16 get_dest_port(void *l4, void *data_end,
__u8 protocol)
@@ -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).
+ */
+static __always_inline bool xdp_match_setup(struct xdp_md *ctx)
{
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
- enum xdp_rss_hash_type rss_type = 0;
struct ethhdr *eth = data;
__u8 l4_proto = 0;
- __u32 hash = 0;
- __u32 key, val;
void *l4 = NULL;
- __u32 *cnt;
- int ret;
+ __u32 key;
if ((void *)(eth + 1) > data_end)
- return XDP_PASS;
+ return false;
if (eth->h_proto == bpf_htons(ETH_P_IP)) {
struct iphdr *iph = (void *)(eth + 1);
if ((void *)(iph + 1) > data_end)
- return XDP_PASS;
+ return false;
l4_proto = iph->protocol;
l4 = (void *)(iph + 1);
} else if (eth->h_proto == bpf_htons(ETH_P_IPV6)) {
struct ipv6hdr *ip6h = (void *)(eth + 1);
if ((void *)(ip6h + 1) > data_end)
- return XDP_PASS;
+ return false;
l4_proto = ip6h->nexthdr;
l4 = (void *)(ip6h + 1);
}
if (!l4)
- return XDP_PASS;
+ return false;
/* Filter on the configured protocol (map_xdp_setup key XDP_PROTO).
* When set, only process packets matching the requested L4 protocol.
@@ -121,7 +150,7 @@ int xdp_rss_hash(struct xdp_md *ctx)
__s32 *proto_cfg = bpf_map_lookup_elem(&map_xdp_setup, &key);
if (proto_cfg && *proto_cfg != 0 && l4_proto != (__u8)*proto_cfg)
- return XDP_PASS;
+ return false;
/* Filter on the configured port (map_xdp_setup key XDP_PORT).
* Only applies to protocols with ports (UDP, TCP).
@@ -133,9 +162,24 @@ int xdp_rss_hash(struct xdp_md *ctx)
__u16 dest = get_dest_port(l4, data_end, l4_proto);
if (!dest || bpf_ntohs(dest) != (__u16)*port_cfg)
- return XDP_PASS;
+ return false;
}
+ return true;
+}
+
+SEC("xdp")
+int xdp_rss_hash(struct xdp_md *ctx)
+{
+ enum xdp_rss_hash_type rss_type = 0;
+ __u32 hash = 0;
+ __u32 key, val;
+ __u32 *cnt;
+ int ret;
+
+ if (!xdp_match_setup(ctx))
+ return XDP_PASS;
+
ret = bpf_xdp_metadata_rx_hash(ctx, &hash, &rss_type);
if (ret < 0) {
key = RSS_KEY_ERR_CNT;
@@ -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)
+{
+ enum xdp_checksum ip_summed = 0;
+ __u8 cksum_level = 0;
+ __u32 cksum = 0;
+ __u32 key, val;
+ __u32 *cnt;
+ int ret;
+
+ if (!xdp_match_setup(ctx))
+ return XDP_PASS;
+
+ 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);
+
+ 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);
+
+ key = CSUM_KEY_PKT_CNT;
+ cnt = bpf_map_lookup_elem(&map_csum, &key);
+ if (cnt)
+ __sync_fetch_and_add(cnt, 1);
+
+ return XDP_PASS;
+}
+
char _license[] SEC("license") = "GPL";
--
2.47.0
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests
2026-07-08 20:34 ` [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests Vladimir Vdovin
@ 2026-07-08 20:41 ` sashiko-bot
2026-07-10 10:12 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-07-08 20:41 UTC (permalink / raw)
To: Vladimir Vdovin; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Multi-line comments in BPF code use the incorrect style (text on the same line as the opening `/*`).
--
--- Patch [6]: [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests ---
commit 534009eb94d734041b26454f61107825d2b5f78e
Author: Vladimir Vdovin <deliran@verdict.gg>
selftests: drv-net: add XDP RX checksum metadata tests
This commit extends the xdp_metadata.py driver test with coverage for
bpf_xdp_metadata_rx_checksum(). It adds an xdp_rx_csum program to read
the RX checksum verdict and tests both valid and invalid RX checksum
scenarios on supported devices.
> diff --git a/tools/testing/selftests/net/lib/xdp_metadata.bpf.c b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
> index f71f59215239f..70decae0a6637 100644
> --- a/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
> +++ b/tools/testing/selftests/net/lib/xdp_metadata.bpf.c
[ ... ]
> @@ -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 modern BPF multi-line comment style requires
the opening /* to be on its own line. Could this be updated so the text
starts on the next line?
> +enum {
> + CSUM_KEY_IP_SUMMED = 0,
> + CSUM_KEY_CKSUM = 1,
[ ... ]
> @@ -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 this multi-line comment also has text on the same
line as the opening /*. Could this follow the preferred BPF multi-line
comment style?
> +enum xdp_checksum {
> + XDP_CHECKSUM_NONE = 1U << 0,
> + XDP_CHECKSUM_UNNECESSARY = 1U << 1,
[ ... ]
> @@ -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 the opening /* should be on its own line here as well
to match the preferred BPF comment style.
> +static __always_inline bool xdp_match_setup(struct xdp_md *ctx)
> {
> void *data_end = (void *)(long)ctx->data_end;
> void *data = (void *)(long)ctx->data;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708203410.45121-1-deliran@verdict.gg?part=6
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback
2026-07-08 20:34 ` [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback Vladimir Vdovin
@ 2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:10 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-07-08 20:43 UTC (permalink / raw)
To: Vladimir Vdovin; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The XDP metadata getter `ice_xdp_rx_checksum` calls `ice_get_rx_csum`, which increments hardware statistics (`hw_csum_rx_error` and `hw_rx_eipe_error`). This violates the expectation that BPF metadata getters are stateless/idempotent, allowing an eBPF program to arbitrarily inflate these statistics by repeatedly querying the checksum, and causes double-counting when `XDP_PASS` is used.
--
--- Patch [3]: [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback ---
commit 7b93052dd91e42401898b8ce9ae946cf9d0f21ec
Author: Lorenzo Bianconi <lorenzo@kernel.org>
net: ice: Add xmo_rx_checksum callback
This patch implements the xmo_rx_checksum callback in the ice driver to
report RX checksum results to eBPF programs. It introduces the
ice_get_rx_csum utility routine to make the checksum code reusable from
ice_rx_csum().
> diff --git a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> index e695a664e53d1..3aa82ff03d9e2 100644
> --- a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> +++ b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
[ ... ]
> +static void
> +ice_get_rx_csum(const union ice_32b_rx_flex_desc *rx_desc, u16 ptype,
> + struct ice_rx_ring *ring, enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> {
[ ... ]
> if (ipv4 && (rx_status0 & (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))) {
> ring->vsi->back->hw_rx_eipe_error++;
> - return;
> + goto checksum_none;
> }
[ ... ]
> checksum_fail:
> ring->vsi->back->hw_csum_rx_error++;
> +checksum_none:
> + *ip_summed = XDP_CHECKSUM_NONE;
> + *cksum_level = 0;
> + *cksum = 0;
> +}
[ ... ]
> +static int ice_xdp_rx_checksum(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> +{
> + const struct libeth_xdp_buff *xdp_ext = (void *)ctx;
> + const union ice_32b_rx_flex_desc *rx_desc = xdp_ext->desc;
> + struct ice_rx_ring *ring;
> +
> + ring = libeth_xdp_buff_to_rq(xdp_ext, typeof(*ring), xdp_rxq);
> + ice_get_rx_csum(rx_desc, ice_get_ptype(rx_desc), ring, ip_summed,
> + cksum, cksum_level);
[Severity: Medium]
Will this lead to inflated hardware error statistics?
The XDP metadata getter ice_xdp_rx_checksum() calls ice_get_rx_csum(), which
increments hardware statistics like hw_csum_rx_error and hw_rx_eipe_error when
a checksum error is detected.
Since XDP metadata getters can be queried multiple times by an eBPF program,
could this cause the statistics to be incremented multiple times for a single
packet?
Additionally, if the program returns XDP_PASS, the normal SKB receive path
will call ice_rx_csum(), which again calls ice_get_rx_csum(). Does this lead
to double-counting the errors for the same packet?
Could the statistics increments be decoupled from the metadata getter?
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708203410.45121-1-deliran@verdict.gg?part=3
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
@ 2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
2026-07-10 19:05 ` Stanislav Fomichev
2 siblings, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-07-08 20:43 UTC (permalink / raw)
To: Vladimir Vdovin; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added multi-line comment for `enum xdp_checksum` violates the strict BPF subsystem multi-line comment style.
--
--- Patch [1]: [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs ---
commit bd15750c5adb8990bb2bd31725238a0442a743f1
Author: Lorenzo Bianconi <lorenzo@kernel.org>
netlink: specs: Add XDP RX checksum capability to XDP metadata specs
Introduce XDP RX checksum capability to XDP metadata specs. It adds
the xmo_rx_checksum netdev callback to allow eBPF programs to retrieve
the RX checksum result computed by the hw NIC.
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index aa742f413c358..e255ff7861310 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
[ ... ]
> @@ -643,12 +647,26 @@ enum xdp_rss_hash_type {
> XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
> };
>
> +/* Please note the driver is required to invalidate the checksum if the NIC
> + * reports CHECKSUM_UNNECESSARY or CHECKSUM_COMPLETE and the eBPF program
> + * modifies the packet since it can change some fields validated by the
> + * checksum.
> + */
[Severity: Low]
This isn't a bug, but does this multi-line comment for enum xdp_checksum
violate the BPF subsystem comment style? The preferred kernel style for
multi-line comments has the opening /* on its own line:
/*
* Please note the driver is required to invalidate the checksum if the NIC
* reports CHECKSUM_UNNECESSARY...
*/
> +enum xdp_checksum {
> + XDP_CHECKSUM_NONE = BIT(CHECKSUM_NONE),
> + XDP_CHECKSUM_UNNECESSARY = BIT(CHECKSUM_UNNECESSARY),
> + XDP_CHECKSUM_COMPLETE = BIT(CHECKSUM_COMPLETE),
> +};
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708203410.45121-1-deliran@verdict.gg?part=1
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
2026-07-08 20:34 ` [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Vladimir Vdovin
@ 2026-07-08 20:45 ` sashiko-bot
2026-07-10 10:11 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-07-08 20:45 UTC (permalink / raw)
To: Vladimir Vdovin; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Addition of fields to `struct xdp_meta` changes its size from 32 bytes to 44 bytes, causing an alignment-induced offset mismatch between 64-bit BPF programs and 32-bit userspace architectures.
--
--- Patch [5]: [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog ---
commit 1839c76747e10e7e5dc96d9eb03c1675cdf0e646
Author: Lorenzo Bianconi <lorenzo@kernel.org>
selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
This patch introduces the capability to dump the HW rx checksum in the
xdp_hw_metadata program. It achieves this by using the new
bpf_xdp_metadata_rx_checksum() kfunc.
> diff --git a/tools/testing/selftests/bpf/xdp_metadata.h b/tools/testing/selftests/bpf/xdp_metadata.h
> index bca09b94af261..f864d4a8bd8c6 100644
> --- a/tools/testing/selftests/bpf/xdp_metadata.h
> +++ b/tools/testing/selftests/bpf/xdp_metadata.h
[ ... ]
> @@ -52,10 +53,13 @@ struct xdp_meta {
> };
> __s32 rx_vlan_tag_err;
> };
> - struct {
> - __u32 ip_summed;
> - __u32 cksum;
> - __u8 cksum_level;
> + union {
> + struct {
> + __u32 ip_summed;
> + __u32 cksum;
> + __u8 cksum_level;
> + };
> + __s32 rx_cksum_err;
> };
> enum xdp_meta_field hint_valid;
> };
[Severity: Medium]
Does this change create an alignment mismatch between the 64-bit BPF program
and 32-bit userspace architectures?
The addition of these fields changes the size of struct xdp_meta to 44 bytes.
On a 32-bit x86 system, the __u64 fields earlier in the struct require only
4-byte alignment, keeping the userspace struct size at exactly 44 bytes.
However, the BPF program runs in a 64-bit context where __u64 requires 8-byte
alignment, causing the compiler to pad the struct to 48 bytes.
When verify_xdp_metadata() is called in userspace:
meta = data - sizeof(*meta);
Userspace will subtract 44 bytes from the packet data pointer, while the
BPF program actually placed it at data - 48. Could this shift all metadata
reads by 4 bytes on 32-bit platforms, leading to incorrect results and
metadata corruption?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708203410.45121-1-deliran@verdict.gg?part=5
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver
2026-07-08 20:34 ` [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver Vladimir Vdovin
@ 2026-07-08 20:54 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: sashiko-bot @ 2026-07-08 20:54 UTC (permalink / raw)
To: Vladimir Vdovin; +Cc: bpf
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The XDP CHECKSUM_COMPLETE value returned by veth_xdp_rx_checksum lacks the MAC header contribution, causing XDP programs to compute incorrect checksums.
- [High] veth_xdp_rx_checksum incorrectly maps CHECKSUM_PARTIAL to XDP_CHECKSUM_NONE, causing XDP programs to drop valid locally generated traffic.
--
--- Patch [2]: [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver ---
commit 5a562d33c7a2a6e1ab983df15c58e768727ee475
Author: Lorenzo Bianconi <lorenzo@kernel.org>
Date: Wed Jul 8 20:34:06 2026 +0000
net: veth: Add xmo_rx_checksum callback to veth driver
Implement xmo_rx_checksum callback in veth driver to report RX checksum
result to the eBPF program bounded to the veth device.
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 1c51421491753..498d894d043da 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
[ ... ]
> +static int veth_xdp_rx_checksum(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> +{
> + const struct veth_xdp_buff *_ctx = (void *)ctx;
> + const struct sk_buff *skb = _ctx->skb;
> +
> + if (!skb)
> + return -ENODATA;
> +
> + switch (skb->ip_summed) {
> + case CHECKSUM_COMPLETE:
> + *ip_summed = XDP_CHECKSUM_COMPLETE;
> + *cksum = skb->csum;
[Severity: High]
Does this return a checksum that is out of sync with the packet data exposed
to the XDP program?
When the packet enters veth_xdp_rcv_skb(), the MAC header is pushed back
into the packet data so it is visible to the XDP program:
drivers/net/veth.c:veth_xdp_rcv_skb() {
...
__skb_push(skb, skb->data - skb_mac_header(skb));
...
}
However, it doesn't look like skb_postpush_rcsum() is called to update the
checksum. Since the earlier eth_type_trans() subtracted the MAC header from
skb->csum, returning skb->csum here means the XDP program will receive a
checksum that lacks the MAC header contribution, which might lead to a
checksum mismatch when the program validates the packet.
> + *cksum_level = 0;
> + break;
> + case CHECKSUM_UNNECESSARY:
> + *ip_summed = XDP_CHECKSUM_UNNECESSARY;
> + *cksum_level = skb->csum_level;
> + *cksum = 0;
> + break;
> + default:
[Severity: High]
Will CHECKSUM_PARTIAL fall through to this default case and be reported as
XDP_CHECKSUM_NONE?
Locally generated traffic transmitted through a veth device defaults to
skb->ip_summed == CHECKSUM_PARTIAL because veth advertises NETIF_F_HW_CSUM.
If this falls through to XDP_CHECKSUM_NONE, strict XDP firewalls might try
to manually validate the checksum. Since the payload checksum hasn't been
populated by hardware yet, the validation will fail and valid local
traffic will be incorrectly dropped. Should this explicitly handle
CHECKSUM_PARTIAL?
> + *ip_summed = XDP_CHECKSUM_NONE;
> + *cksum_level = 0;
> + *cksum = 0;
> + break;
> + }
> +
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708203410.45121-1-deliran@verdict.gg?part=2
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
@ 2026-07-10 10:09 ` Loktionov, Aleksandr
2026-07-10 19:05 ` Stanislav Fomichev
2 siblings, 0 replies; 18+ messages in thread
From: Loktionov, Aleksandr @ 2026-07-10 10:09 UTC (permalink / raw)
To: Vladimir Vdovin, Lorenzo Bianconi, Donald Hunter, Jakub Kicinski,
David S . Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Andrew Lunn,
Nguyen, Anthony L, Kitszel, Przemyslaw, Lobakin, Aleksander,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
Fijalkowski, Maciej
Cc: Jakub Sitnicki, netdev@vger.kernel.org, bpf@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org
> -----Original Message-----
> From: Vladimir Vdovin <deliran@verdict.gg>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <lorenzo@kernel.org>; Donald Hunter
> <donald.hunter@gmail.com>; Jakub Kicinski <kuba@kernel.org>; David S .
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Paolo Abeni <pabeni@redhat.com>; Simon Horman <horms@kernel.org>;
> Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann
> <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John
> Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Andrew Lunn <andrew+netdev@lunn.ch>; Nguyen,
> Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Andrii Nakryiko <andrii@kernel.org>;
> Martin KaFai Lau <martin.lau@linux.dev>; Eduard Zingerman
> <eddyz87@gmail.com>; Song Liu <song@kernel.org>; Yonghong Song
> <yonghong.song@linux.dev>; KP Singh <kpsingh@kernel.org>; Hao Luo
> <haoluo@google.com>; Jiri Olsa <jolsa@kernel.org>; Shuah Khan
> <shuah@kernel.org>; Fijalkowski, Maciej <maciej.fijalkowski@intel.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>; netdev@vger.kernel.org;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kselftest@vger.kernel.org; Vladimir Vdovin <deliran@verdict.gg>
> Subject: [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum
> capability to XDP metadata specs
>
> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Introduce XDP RX checksum capability to XDP metadata specs. XDP RX
> checksum will be use by devices capable of exposing receive checksum
> result via bpf_xdp_metadata_rx_checksum().
> Moreover, introduce xmo_rx_checksum netdev callback in order to allow
> the eBPF program bound to the device to retrieve the RX checksum
> result computed by the hw NIC and reported via DMA descriptors.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> Documentation/netlink/specs/netdev.yaml | 5 ++++
> include/net/xdp.h | 18 ++++++++++++++
> include/uapi/linux/netdev.h | 3 +++
> net/core/xdp.c | 32
> +++++++++++++++++++++++++
> tools/include/uapi/linux/netdev.h | 3 +++
> 5 files changed, 61 insertions(+)
>
> diff --git a/Documentation/netlink/specs/netdev.yaml
> b/Documentation/netlink/specs/netdev.yaml
> index 5f143da7458c..6d0d90d3a614 100644
> --- a/Documentation/netlink/specs/netdev.yaml
> +++ b/Documentation/netlink/specs/netdev.yaml
> @@ -61,6 +61,11 @@ definitions:
> doc: |
> Device is capable of exposing receive packet VLAN tag via
> bpf_xdp_metadata_rx_vlan_tag().
> + -
> + name: checksum
> + doc: |
> + Device is capable of exposing receive checksum result via
> + bpf_xdp_metadata_rx_checksum().
> -
> type: flags
> name: xsk-flags
> diff --git a/include/net/xdp.h b/include/net/xdp.h index
> aa742f413c35..e255ff786131 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -586,6 +586,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_CHECKSUM, \
> + NETDEV_XDP_RX_METADATA_CHECKSUM, \
> + bpf_xdp_metadata_rx_checksum, \
> + xmo_rx_checksum)
>
> enum xdp_rx_metadata {
> #define XDP_METADATA_KFUNC(name, _, __, ___) name, @@ -643,12 +647,26
> @@ enum xdp_rss_hash_type {
> XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP |
> XDP_RSS_L3_DYNHDR, };
>
> +/* Please note the driver is required to invalidate the checksum if
> the
> +NIC
> + * reports CHECKSUM_UNNECESSARY or CHECKSUM_COMPLETE and the eBPF
> +program
> + * modifies the packet since it can change some fields validated by
> the
> + * checksum.
> + */
> +enum xdp_checksum {
> + XDP_CHECKSUM_NONE = BIT(CHECKSUM_NONE),
> + XDP_CHECKSUM_UNNECESSARY = BIT(CHECKSUM_UNNECESSARY),
> + XDP_CHECKSUM_COMPLETE = BIT(CHECKSUM_COMPLETE),
> +};
> +
> 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_checksum)(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level);
> };
>
> #ifdef CONFIG_NET
> diff --git a/include/uapi/linux/netdev.h b/include/uapi/linux/netdev.h
> index 2f3ab75e8cc0..f8caade93c8c 100644
> --- a/include/uapi/linux/netdev.h
> +++ b/include/uapi/linux/netdev.h
> @@ -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_CHECKSUM: Device is capable of exposing
> receive
> + * checksum result via bpf_xdp_metadata_rx_checksum().
> */
> 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_CHECKSUM = 8,
> };
>
> /**
> diff --git a/net/core/xdp.c b/net/core/xdp.c index
> 9890a30584ba..9bcaa423ad17 100644
> --- a/net/core/xdp.c
> +++ b/net/core/xdp.c
> @@ -961,6 +961,38 @@ __bpf_kfunc int
> bpf_xdp_metadata_rx_vlan_tag(const struct xdp_md *ctx,
> return -EOPNOTSUPP;
> }
>
> +/**
> + * bpf_xdp_metadata_rx_checksum - Read XDP frame RX checksum.
> + * @ctx: XDP context pointer.
> + * @ip_summed: Return value pointer to a bitmask indicating available
> checksums.
> + * @cksum: Return value pointer indicating the hw checksum value.
> + * @cksum_level: Return value pointer indicating the checksum level
> result.
> + *
> + * In case of success, ``ip_summed`` is set to the RX checksum
> result.
> +Possible
> + * values are:
> + * ``XDP_CHECKSUM_NONE``
> + * ``XDP_CHECKSUM_UNNECESSARY``
> + * ``XDP_CHECKSUM_COMPLETE``
> + * ``XDP_CHECKSUM_COMPLETE`` | ``XDP_CHECKSUM_UNNECESSARY``
> + *
> + * In case of success, ``cksum`` contains the checksum value
> calculated
> +by the
> + * NIC. ``cksum`` is valid only if ``XDP_CHECKSUM_COMPLETE`` is set
> in
> + * ``ip_summed``. ``cksum_level`` contains the checksum level
> reported
> +by the
> + * hw. ``cksum_level`` can be considered valid only if
> + * ``XDP_CHECKSUM_UNNECESSARY`` is set in ``ip_summed``.
> + *
> + * Return:
> + * * Returns 0 on success or ``-errno`` on error.
> + * * ``-EOPNOTSUPP`` : means device driver does not implement kfunc
> + * * ``-ENODATA`` : means no RX-checksum available for this frame
> + */
> +__bpf_kfunc int bpf_xdp_metadata_rx_checksum(const struct xdp_md
> *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> +{
> + return -EOPNOTSUPP;
> +}
> +
> __bpf_kfunc_end_defs();
>
> BTF_KFUNCS_START(xdp_metadata_kfunc_ids)
> diff --git a/tools/include/uapi/linux/netdev.h
> b/tools/include/uapi/linux/netdev.h
> index 2f3ab75e8cc0..f8caade93c8c 100644
> --- a/tools/include/uapi/linux/netdev.h
> +++ b/tools/include/uapi/linux/netdev.h
> @@ -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_CHECKSUM: Device is capable of exposing
> receive
> + * checksum result via bpf_xdp_metadata_rx_checksum().
> */
> 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_CHECKSUM = 8,
> };
>
> /**
> --
> 2.47.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver
2026-07-08 20:34 ` [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver Vladimir Vdovin
2026-07-08 20:54 ` sashiko-bot
@ 2026-07-10 10:09 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: Loktionov, Aleksandr @ 2026-07-10 10:09 UTC (permalink / raw)
To: Vladimir Vdovin, Lorenzo Bianconi, Donald Hunter, Jakub Kicinski,
David S . Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Andrew Lunn,
Nguyen, Anthony L, Kitszel, Przemyslaw, Lobakin, Aleksander,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
Fijalkowski, Maciej
Cc: Jakub Sitnicki, netdev@vger.kernel.org, bpf@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org
> -----Original Message-----
> From: Vladimir Vdovin <deliran@verdict.gg>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <lorenzo@kernel.org>; Donald Hunter
> <donald.hunter@gmail.com>; Jakub Kicinski <kuba@kernel.org>; David S .
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Paolo Abeni <pabeni@redhat.com>; Simon Horman <horms@kernel.org>;
> Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann
> <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John
> Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Andrew Lunn <andrew+netdev@lunn.ch>; Nguyen,
> Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Andrii Nakryiko <andrii@kernel.org>;
> Martin KaFai Lau <martin.lau@linux.dev>; Eduard Zingerman
> <eddyz87@gmail.com>; Song Liu <song@kernel.org>; Yonghong Song
> <yonghong.song@linux.dev>; KP Singh <kpsingh@kernel.org>; Hao Luo
> <haoluo@google.com>; Jiri Olsa <jolsa@kernel.org>; Shuah Khan
> <shuah@kernel.org>; Fijalkowski, Maciej <maciej.fijalkowski@intel.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>; netdev@vger.kernel.org;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kselftest@vger.kernel.org; Vladimir Vdovin <deliran@verdict.gg>
> Subject: [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum
> callback to veth driver
>
> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Implement xmo_rx_checksum callback in veth driver to report RX
> checksum result to the eBPF program bounded to the veth device.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> drivers/net/veth.c | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c index
> 1c5142149175..498d894d043d 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -1700,6 +1700,37 @@ static int veth_xdp_rx_vlan_tag(const struct
> xdp_md *ctx, __be16 *vlan_proto,
> return err;
> }
>
> +static int veth_xdp_rx_checksum(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> +{
> + const struct veth_xdp_buff *_ctx = (void *)ctx;
> + const struct sk_buff *skb = _ctx->skb;
> +
> + if (!skb)
> + return -ENODATA;
> +
> + switch (skb->ip_summed) {
> + case CHECKSUM_COMPLETE:
> + *ip_summed = XDP_CHECKSUM_COMPLETE;
> + *cksum = skb->csum;
> + *cksum_level = 0;
> + break;
> + case CHECKSUM_UNNECESSARY:
> + *ip_summed = XDP_CHECKSUM_UNNECESSARY;
> + *cksum_level = skb->csum_level;
> + *cksum = 0;
> + break;
> + default:
> + *ip_summed = XDP_CHECKSUM_NONE;
> + *cksum_level = 0;
> + *cksum = 0;
> + break;
> + }
> +
> + return 0;
> +}
> +
> static const struct net_device_ops veth_netdev_ops = {
> .ndo_init = veth_dev_init,
> .ndo_open = veth_open,
> @@ -1725,6 +1756,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_checksum = veth_xdp_rx_checksum,
> };
>
> #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST |
> NETIF_F_HW_CSUM | \
> --
> 2.47.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback
2026-07-08 20:34 ` [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
@ 2026-07-10 10:10 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: Loktionov, Aleksandr @ 2026-07-10 10:10 UTC (permalink / raw)
To: Vladimir Vdovin, Lorenzo Bianconi, Donald Hunter, Jakub Kicinski,
David S . Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Andrew Lunn,
Nguyen, Anthony L, Kitszel, Przemyslaw, Lobakin, Aleksander,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
Fijalkowski, Maciej
Cc: Jakub Sitnicki, netdev@vger.kernel.org, bpf@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org
> -----Original Message-----
> From: Vladimir Vdovin <deliran@verdict.gg>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <lorenzo@kernel.org>; Donald Hunter
> <donald.hunter@gmail.com>; Jakub Kicinski <kuba@kernel.org>; David S .
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Paolo Abeni <pabeni@redhat.com>; Simon Horman <horms@kernel.org>;
> Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann
> <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John
> Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Andrew Lunn <andrew+netdev@lunn.ch>; Nguyen,
> Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Andrii Nakryiko <andrii@kernel.org>;
> Martin KaFai Lau <martin.lau@linux.dev>; Eduard Zingerman
> <eddyz87@gmail.com>; Song Liu <song@kernel.org>; Yonghong Song
> <yonghong.song@linux.dev>; KP Singh <kpsingh@kernel.org>; Hao Luo
> <haoluo@google.com>; Jiri Olsa <jolsa@kernel.org>; Shuah Khan
> <shuah@kernel.org>; Fijalkowski, Maciej <maciej.fijalkowski@intel.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>; netdev@vger.kernel.org;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kselftest@vger.kernel.org; Vladimir Vdovin <deliran@verdict.gg>
> Subject: [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum
> callback
>
> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Implement xmo_rx_checksum callback in ice driver to report RX checksum
> result to the eBPF program bounded to the NIC.
> Introduce ice_get_rx_csum utility routine in order to make the rx
> checksum code reusable from ice_rx_csum()
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> drivers/net/ethernet/intel/ice/ice_txrx_lib.c | 123 ++++++++++++-----
> -
> 1 file changed, 81 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> index e695a664e53d..3aa82ff03d9e 100644
> --- a/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> +++ b/drivers/net/ethernet/intel/ice/ice_txrx_lib.c
> @@ -78,69 +78,48 @@ ice_rx_hash_to_skb(const struct ice_rx_ring
> *rx_ring,
> libeth_rx_pt_set_hash(skb, hash, decoded); }
>
> -/**
> - * ice_rx_gcs - Set generic checksum in skb
> - * @skb: skb currently being received and modified
> - * @rx_desc: receive descriptor
> - */
> -static void ice_rx_gcs(struct sk_buff *skb,
> - const union ice_32b_rx_flex_desc *rx_desc)
> -{
> - const struct ice_32b_rx_flex_desc_nic *desc;
> - u16 csum;
> -
> - desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
> - skb->ip_summed = CHECKSUM_COMPLETE;
> - csum = (__force u16)desc->raw_csum;
> - skb->csum = csum_unfold((__force __sum16)swab16(csum));
> -}
> -
> -/**
> - * ice_rx_csum - Indicate in skb if checksum is good
> - * @ring: the ring we care about
> - * @skb: skb currently being received and modified
> - * @rx_desc: the receive descriptor
> - * @ptype: the packet type decoded by hardware
> - *
> - * skb->protocol must be set before this function is called
> - */
> static void
> -ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
> - union ice_32b_rx_flex_desc *rx_desc, u16 ptype)
> +ice_get_rx_csum(const union ice_32b_rx_flex_desc *rx_desc, u16 ptype,
> + struct ice_rx_ring *ring, enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> {
> - struct libeth_rx_pt decoded;
> + struct libeth_rx_pt decoded = libie_rx_pt_parse(ptype);
> u16 rx_status0, rx_status1;
> bool ipv4, ipv6;
>
> - /* Start with CHECKSUM_NONE and by default csum_level = 0 */
> - skb->ip_summed = CHECKSUM_NONE;
> -
> - decoded = libie_rx_pt_parse(ptype);
> if (!libeth_rx_pt_has_checksum(ring->netdev, decoded))
> - return;
> + goto checksum_none;
>
> rx_status0 = le16_to_cpu(rx_desc->wb.status_error0);
> rx_status1 = le16_to_cpu(rx_desc->wb.status_error1);
> -
> if ((ring->flags & ICE_RX_FLAGS_RING_GCS) &&
> rx_desc->wb.rxdid == ICE_RXDID_FLEX_NIC &&
> (decoded.inner_prot == LIBETH_RX_PT_INNER_TCP ||
> decoded.inner_prot == LIBETH_RX_PT_INNER_UDP ||
> decoded.inner_prot == LIBETH_RX_PT_INNER_ICMP)) {
> - ice_rx_gcs(skb, rx_desc);
> + const struct ice_32b_rx_flex_desc_nic *desc;
> + __wsum wcsum;
> + u16 csum;
> +
> + desc = (struct ice_32b_rx_flex_desc_nic *)rx_desc;
> + *ip_summed = XDP_CHECKSUM_COMPLETE;
> + csum = (__force u16)desc->raw_csum;
> + wcsum = csum_unfold((__force __sum16)swab16(csum));
> + *cksum = (__force u32)wcsum;
> + *cksum_level = 0;
> return;
> }
>
> /* check if HW has decoded the packet and checksum */
> if (!(rx_status0 & BIT(ICE_RX_FLEX_DESC_STATUS0_L3L4P_S)))
> - return;
> + goto checksum_none;
>
> ipv4 = libeth_rx_pt_get_ip_ver(decoded) ==
> LIBETH_RX_PT_OUTER_IPV4;
> ipv6 = libeth_rx_pt_get_ip_ver(decoded) ==
> LIBETH_RX_PT_OUTER_IPV6;
>
> if (ipv4 && (rx_status0 &
> (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_EIPE_S)))) {
> ring->vsi->back->hw_rx_eipe_error++;
> - return;
> + goto checksum_none;
> }
>
> if (ipv4 && (rx_status0 &
> (BIT(ICE_RX_FLEX_DESC_STATUS0_XSUM_IPE_S))))
> @@ -164,14 +143,51 @@ ice_rx_csum(struct ice_rx_ring *ring, struct
> sk_buff *skb,
> * we need to bump the checksum level by 1 to reflect the fact
> that
> * we are indicating we validated the inner checksum.
> */
> - if (decoded.tunnel_type >= LIBETH_RX_PT_TUNNEL_IP_GRENAT)
> - skb->csum_level = 1;
> -
> - skb->ip_summed = CHECKSUM_UNNECESSARY;
> + *cksum_level = decoded.tunnel_type >=
> LIBETH_RX_PT_TUNNEL_IP_GRENAT;
> + *ip_summed = XDP_CHECKSUM_UNNECESSARY;
> + *cksum = 0;
> return;
>
> checksum_fail:
> ring->vsi->back->hw_csum_rx_error++;
> +checksum_none:
> + *ip_summed = XDP_CHECKSUM_NONE;
> + *cksum_level = 0;
> + *cksum = 0;
> +}
> +
> +/**
> + * ice_rx_csum - Indicate in skb if checksum is good
> + * @ring: the ring we care about
> + * @skb: skb currently being received and modified
> + * @rx_desc: the receive descriptor
> + * @ptype: the packet type decoded by hardware
> + *
> + * skb->protocol must be set before this function is called */
> static
> +void ice_rx_csum(struct ice_rx_ring *ring, struct sk_buff *skb,
> + union ice_32b_rx_flex_desc *rx_desc, u16 ptype) {
> + enum xdp_checksum ip_summed;
> + u8 cksum_level;
> + u32 cksum;
> +
> + ice_get_rx_csum(rx_desc, ptype, ring, &ip_summed, &cksum,
> + &cksum_level);
> + switch (ip_summed) {
> + case XDP_CHECKSUM_UNNECESSARY:
> + skb->ip_summed = CHECKSUM_UNNECESSARY;
> + skb->csum_level = cksum_level;
> + break;
> + case XDP_CHECKSUM_COMPLETE:
> + skb->ip_summed = CHECKSUM_COMPLETE;
> + skb->csum = (__force __wsum)cksum;
> + break;
> + default:
> + skb->ip_summed = CHECKSUM_NONE;
> + break;
> + }
> }
>
> /**
> @@ -566,6 +582,28 @@ static int ice_xdp_rx_hash(const struct xdp_md
> *ctx, u32 *hash,
> return 0;
> }
>
> +/**
> + * ice_xdp_rx_checksum - RX checksum XDP hint handler
> + * @ctx: XDP buff pointer
> + * @ip_summed: RX checksum result destination address
> + * @cksum: RX checksum value destination address
> + * @cksum_level: RX checksum level value destination address */
> static
> +int ice_xdp_rx_checksum(const struct xdp_md *ctx,
> + enum xdp_checksum *ip_summed,
> + u32 *cksum, u8 *cksum_level)
> +{
> + const struct libeth_xdp_buff *xdp_ext = (void *)ctx;
> + const union ice_32b_rx_flex_desc *rx_desc = xdp_ext->desc;
> + struct ice_rx_ring *ring;
> +
> + ring = libeth_xdp_buff_to_rq(xdp_ext, typeof(*ring), xdp_rxq);
> + ice_get_rx_csum(rx_desc, ice_get_ptype(rx_desc), ring,
> ip_summed,
> + cksum, cksum_level);
> +
> + return 0;
> +}
> +
> /**
> * ice_xdp_rx_vlan_tag - VLAN tag XDP hint handler
> * @ctx: XDP buff pointer
> @@ -598,4 +636,5 @@ 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_checksum = ice_xdp_rx_checksum,
> };
> --
> 2.47.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
2026-07-08 20:34 ` [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Vladimir Vdovin
2026-07-08 20:45 ` sashiko-bot
@ 2026-07-10 10:11 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: Loktionov, Aleksandr @ 2026-07-10 10:11 UTC (permalink / raw)
To: Vladimir Vdovin, Lorenzo Bianconi, Donald Hunter, Jakub Kicinski,
David S . Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Andrew Lunn,
Nguyen, Anthony L, Kitszel, Przemyslaw, Lobakin, Aleksander,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
Fijalkowski, Maciej
Cc: Jakub Sitnicki, netdev@vger.kernel.org, bpf@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org
> -----Original Message-----
> From: Vladimir Vdovin <deliran@verdict.gg>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <lorenzo@kernel.org>; Donald Hunter
> <donald.hunter@gmail.com>; Jakub Kicinski <kuba@kernel.org>; David S .
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Paolo Abeni <pabeni@redhat.com>; Simon Horman <horms@kernel.org>;
> Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann
> <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John
> Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Andrew Lunn <andrew+netdev@lunn.ch>; Nguyen,
> Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Andrii Nakryiko <andrii@kernel.org>;
> Martin KaFai Lau <martin.lau@linux.dev>; Eduard Zingerman
> <eddyz87@gmail.com>; Song Liu <song@kernel.org>; Yonghong Song
> <yonghong.song@linux.dev>; KP Singh <kpsingh@kernel.org>; Hao Luo
> <haoluo@google.com>; Jiri Olsa <jolsa@kernel.org>; Shuah Khan
> <shuah@kernel.org>; Fijalkowski, Maciej <maciej.fijalkowski@intel.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>; netdev@vger.kernel.org;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kselftest@vger.kernel.org; Vladimir Vdovin <deliran@verdict.gg>
> Subject: [PATCH bpf-next v4 5/6] selftests/bpf: Add
> bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog
>
> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Introduce the capability to dump HW rx checksum in xdp_hw_metadata
> program via bpf_xdp_metadata_rx_checksum() kfunc.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> .../selftests/bpf/progs/xdp_hw_metadata.c | 7 +++++
> tools/testing/selftests/bpf/xdp_hw_metadata.c | 31
> +++++++++++++++++++
> tools/testing/selftests/bpf/xdp_metadata.h | 12 ++++---
> 3 files changed, 46 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> index 330ece2eabdb..5eeadb7e27cf 100644
> --- a/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/progs/xdp_hw_metadata.c
> @@ -110,6 +110,13 @@ int rx(struct xdp_md *ctx)
> else
> meta->hint_valid |= XDP_META_FIELD_VLAN_TAG;
>
> + err = bpf_xdp_metadata_rx_checksum(ctx, &meta->ip_summed,
> + &meta->cksum, &meta-
> >cksum_level);
> + if (err)
> + meta->rx_cksum_err = err;
> + else
> + meta->hint_valid |= XDP_META_FIELD_CHECKSUM;
> +
> __sync_add_and_fetch(&pkts_redir, 1);
> return bpf_redirect_map(&xsk, ctx->rx_queue_index, XDP_PASS);
> } diff --git a/tools/testing/selftests/bpf/xdp_hw_metadata.c
> b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> index 6db3b5555a22..c63a70a54075 100644
> --- a/tools/testing/selftests/bpf/xdp_hw_metadata.c
> +++ b/tools/testing/selftests/bpf/xdp_hw_metadata.c
> @@ -8,6 +8,7 @@
> * - Metadata verified:
> * - rx_timestamp
> * - rx_hash
> + * - rx_checksum
> *
> * TX:
> * - UDP 9091 packets trigger TX reply
> @@ -219,6 +220,30 @@ static void print_vlan_tci(__u16 tag)
> printf("PCP=%u, DEI=%d, VID=0x%X\n", pcp, dei, vlan_id); }
>
> +static void print_rx_cksum(__u8 ip_summed, __u32 cksum, __u8
> +cksum_level) {
> + const char *cksum_str;
> +
> + switch (ip_summed) {
> + case XDP_CHECKSUM_COMPLETE | XDP_CHECKSUM_UNNECESSARY:
> + cksum_str = "CHECKSUM_COMPLETE,CHECKSUM_UNNECESSARY";
> + break;
> + case XDP_CHECKSUM_UNNECESSARY:
> + cksum_str = "CHECKSUM_UNNECESSARY";
> + break;
> + case XDP_CHECKSUM_COMPLETE:
> + cksum_str = "CHECKSUM_COMPLETE";
> + break;
> + case XDP_CHECKSUM_NONE:
> + default:
> + cksum_str = "CHECKSUM_NONE";
> + break;
> + }
> +
> + printf("rx-cksum: %s, csum=0x%x, cksum_level=0x%x\n",
> + cksum_str, cksum, cksum_level); }
> +
> static void verify_xdp_metadata(void *data, clockid_t clock_id) {
> struct xdp_meta *meta;
> @@ -254,6 +279,12 @@ static void verify_xdp_metadata(void *data,
> clockid_t clock_id)
> printf("No rx_vlan_tci or rx_vlan_proto, err=%d\n",
> meta->rx_vlan_tag_err);
> }
> +
> + if (meta->hint_valid & XDP_META_FIELD_CHECKSUM)
> + print_rx_cksum(meta->ip_summed, meta->cksum,
> + meta->cksum_level);
> + else
> + printf("No rx_cksum, err=%d\n", meta->rx_cksum_err);
> }
>
> static void verify_skb_metadata(int fd) diff --git
> a/tools/testing/selftests/bpf/xdp_metadata.h
> b/tools/testing/selftests/bpf/xdp_metadata.h
> index bca09b94af26..f864d4a8bd8c 100644
> --- a/tools/testing/selftests/bpf/xdp_metadata.h
> +++ b/tools/testing/selftests/bpf/xdp_metadata.h
> @@ -28,6 +28,7 @@ enum xdp_meta_field {
> XDP_META_FIELD_TS = BIT(0),
> XDP_META_FIELD_RSS = BIT(1),
> XDP_META_FIELD_VLAN_TAG = BIT(2),
> + XDP_META_FIELD_CHECKSUM = BIT(3),
> };
>
> #define XDP_CHECKSUM_NONE BIT(0)
> @@ -52,10 +53,13 @@ struct xdp_meta {
> };
> __s32 rx_vlan_tag_err;
> };
> - struct {
> - __u32 ip_summed;
> - __u32 cksum;
> - __u8 cksum_level;
> + union {
> + struct {
> + __u32 ip_summed;
> + __u32 cksum;
> + __u8 cksum_level;
> + };
> + __s32 rx_cksum_err;
> };
> enum xdp_meta_field hint_valid;
> };
> --
> 2.47.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* RE: [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests
2026-07-08 20:34 ` [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests Vladimir Vdovin
2026-07-08 20:41 ` sashiko-bot
@ 2026-07-10 10:12 ` Loktionov, Aleksandr
1 sibling, 0 replies; 18+ messages in thread
From: Loktionov, Aleksandr @ 2026-07-10 10:12 UTC (permalink / raw)
To: Vladimir Vdovin, Lorenzo Bianconi, Donald Hunter, Jakub Kicinski,
David S . Miller, Eric Dumazet, Paolo Abeni, Simon Horman,
Alexei Starovoitov, Daniel Borkmann, Jesper Dangaard Brouer,
John Fastabend, Stanislav Fomichev, Andrew Lunn,
Nguyen, Anthony L, Kitszel, Przemyslaw, Lobakin, Aleksander,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, KP Singh, Hao Luo, Jiri Olsa, Shuah Khan,
Fijalkowski, Maciej
Cc: Jakub Sitnicki, netdev@vger.kernel.org, bpf@vger.kernel.org,
intel-wired-lan@lists.osuosl.org, linux-kselftest@vger.kernel.org
> -----Original Message-----
> From: Vladimir Vdovin <deliran@verdict.gg>
> Sent: Wednesday, July 8, 2026 10:34 PM
> To: Lorenzo Bianconi <lorenzo@kernel.org>; Donald Hunter
> <donald.hunter@gmail.com>; Jakub Kicinski <kuba@kernel.org>; David S .
> Miller <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>;
> Paolo Abeni <pabeni@redhat.com>; Simon Horman <horms@kernel.org>;
> Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann
> <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John
> Fastabend <john.fastabend@gmail.com>; Stanislav Fomichev
> <sdf@fomichev.me>; Andrew Lunn <andrew+netdev@lunn.ch>; Nguyen,
> Anthony L <anthony.l.nguyen@intel.com>; Kitszel, Przemyslaw
> <przemyslaw.kitszel@intel.com>; Lobakin, Aleksander
> <aleksander.lobakin@intel.com>; Andrii Nakryiko <andrii@kernel.org>;
> Martin KaFai Lau <martin.lau@linux.dev>; Eduard Zingerman
> <eddyz87@gmail.com>; Song Liu <song@kernel.org>; Yonghong Song
> <yonghong.song@linux.dev>; KP Singh <kpsingh@kernel.org>; Hao Luo
> <haoluo@google.com>; Jiri Olsa <jolsa@kernel.org>; Shuah Khan
> <shuah@kernel.org>; Fijalkowski, Maciej <maciej.fijalkowski@intel.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>; netdev@vger.kernel.org;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kselftest@vger.kernel.org; Vladimir Vdovin <deliran@verdict.gg>
> Subject: [PATCH bpf-next v4 6/6] 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.
> CHECKSUM_NONE is a legitimate verdict for a device that does not
> verify the packets (e.g. veth reports it for locally generated
> CHECKSUM_PARTIAL traffic), so it results in SKIP rather than in a
> failure;
>
> - 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.
>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> .../selftests/drivers/net/hw/xdp_metadata.py | 110 +++++++++++++++++
> .../selftests/net/lib/xdp_metadata.bpf.c | 112 ++++++++++++++++-
> -
> 2 files changed, 209 insertions(+), 13 deletions(-)
>
> diff --git a/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
> b/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
> index 33a1985356d9..1a623771477b 100644
> --- a/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
> +++ b/tools/testing/selftests/drivers/net/hw/xdp_metadata.py
> @@ -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,98 @@ def test_xdp_rss_hash(cfg, proto):
> f"RSS hash type should include L4 for {proto.upper()}
> traffic")
>
>
...
> char _license[] SEC("license") = "GPL";
> --
> 2.47.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
@ 2026-07-10 19:05 ` Stanislav Fomichev
2 siblings, 0 replies; 18+ messages in thread
From: Stanislav Fomichev @ 2026-07-10 19:05 UTC (permalink / raw)
To: Vladimir Vdovin
Cc: Lorenzo Bianconi, Donald Hunter, Jakub Kicinski, David S . Miller,
Eric Dumazet, Paolo Abeni, Simon Horman, Alexei Starovoitov,
Daniel Borkmann, Jesper Dangaard Brouer, John Fastabend,
Stanislav Fomichev, Andrew Lunn, Tony Nguyen, Przemek Kitszel,
Alexander Lobakin, Andrii Nakryiko, Martin KaFai Lau,
Eduard Zingerman, Song Liu, Yonghong Song, KP Singh, Hao Luo,
Jiri Olsa, Shuah Khan, Maciej Fijalkowski, Jakub Sitnicki,
Aleksandr Loktionov, netdev, bpf, intel-wired-lan,
linux-kselftest
On 07/08, Vladimir Vdovin wrote:
> From: Lorenzo Bianconi <lorenzo@kernel.org>
>
> Introduce XDP RX checksum capability to XDP metadata specs. XDP RX
> checksum will be use by devices capable of exposing receive checksum
> result via bpf_xdp_metadata_rx_checksum().
> Moreover, introduce xmo_rx_checksum netdev callback in order to allow
> the eBPF program bound to the device to retrieve the RX checksum result
> computed by the hw NIC and reported via DMA descriptors.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> Signed-off-by: Vladimir Vdovin <deliran@verdict.gg>
> ---
> Documentation/netlink/specs/netdev.yaml | 5 ++++
> include/net/xdp.h | 18 ++++++++++++++
> include/uapi/linux/netdev.h | 3 +++
> net/core/xdp.c | 32 +++++++++++++++++++++++++
> tools/include/uapi/linux/netdev.h | 3 +++
> 5 files changed, 61 insertions(+)
>
> diff --git a/Documentation/netlink/specs/netdev.yaml b/Documentation/netlink/specs/netdev.yaml
> index 5f143da7458c..6d0d90d3a614 100644
> --- a/Documentation/netlink/specs/netdev.yaml
> +++ b/Documentation/netlink/specs/netdev.yaml
> @@ -61,6 +61,11 @@ definitions:
> doc: |
> Device is capable of exposing receive packet VLAN tag via
> bpf_xdp_metadata_rx_vlan_tag().
> + -
> + name: checksum
> + doc: |
> + Device is capable of exposing receive checksum result via
> + bpf_xdp_metadata_rx_checksum().
> -
> type: flags
> name: xsk-flags
> diff --git a/include/net/xdp.h b/include/net/xdp.h
> index aa742f413c35..e255ff786131 100644
> --- a/include/net/xdp.h
> +++ b/include/net/xdp.h
> @@ -586,6 +586,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_CHECKSUM, \
> + NETDEV_XDP_RX_METADATA_CHECKSUM, \
> + bpf_xdp_metadata_rx_checksum, \
> + xmo_rx_checksum)
>
> enum xdp_rx_metadata {
> #define XDP_METADATA_KFUNC(name, _, __, ___) name,
> @@ -643,12 +647,26 @@ enum xdp_rss_hash_type {
> XDP_RSS_TYPE_L4_IPV6_SCTP_EX = XDP_RSS_TYPE_L4_IPV6_SCTP | XDP_RSS_L3_DYNHDR,
> };
[..]
> +/* Please note the driver is required to invalidate the checksum if the NIC
> + * reports CHECKSUM_UNNECESSARY or CHECKSUM_COMPLETE and the eBPF program
> + * modifies the packet since it can change some fields validated by the
> + * checksum.
> + */
Sorry, a bit confused about this part. IIUC this is in response to this
discussion https://lore.kernel.org/bpf/aaLYfWnuuf_ne72u@lore-desk/ ?
Looking at a few drivers:
- bnxt (bnxt_rx_pkt) does UNNECESSARY - ok
- mlx5 (mlx5e_handle_csum) does UNNECESSARY and skips COMPLETE if there is
bpf prog attached
- fbnic (fbnic_rx_csum) - can do COMPLETE even with xdp attached?
- gve (gve_rx) - can do COMPLETE even with xdp attached?
So none of the drivers invalidate anything (and nether the bpf machinery), some
choose to (correctly?) not report COMPLETE when there is XDP. So was the
discussion about documenting this and giving some guidance? This probably
belongs to that `DOC: skb checksums` section of include/linux/skbuff.h?
Also, can you add your new rx_checksum to
Documentation/networking/xdp-rx-metadata.rst's list of supported kfuncs?
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2026-07-10 19:07 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 20:34 [PATCH bpf-next v4 0/6] Add the capability to load HW RX checksum in eBPF programs Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 1/6] netlink: specs: Add XDP RX checksum capability to XDP metadata specs Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
2026-07-10 19:05 ` Stanislav Fomichev
2026-07-08 20:34 ` [PATCH bpf-next v4 2/6] net: veth: Add xmo_rx_checksum callback to veth driver Vladimir Vdovin
2026-07-08 20:54 ` sashiko-bot
2026-07-10 10:09 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 3/6] net: ice: Add xmo_rx_checksum callback Vladimir Vdovin
2026-07-08 20:43 ` sashiko-bot
2026-07-10 10:10 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 4/6] selftests/bpf: Add selftest support for bpf_xdp_metadata_rx_checksum Vladimir Vdovin
2026-07-08 20:34 ` [PATCH bpf-next v4 5/6] selftests/bpf: Add bpf_xdp_metadata_rx_checksum support to xdp_hw_metadat prog Vladimir Vdovin
2026-07-08 20:45 ` sashiko-bot
2026-07-10 10:11 ` Loktionov, Aleksandr
2026-07-08 20:34 ` [PATCH bpf-next v4 6/6] selftests: drv-net: add XDP RX checksum metadata tests Vladimir Vdovin
2026-07-08 20:41 ` sashiko-bot
2026-07-10 10:12 ` Loktionov, Aleksandr
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox