Re: [PATCH net-next 3/5] selftests/xsk: expand XSKMAP capacity and add length-based XDP program

[email protected]
Newsgroups org.kernel.vger.netdev,org.kernel.vger.bpf
Message-ID <97709c816a1c08068dc591e29a29a36d5ccdf56446ed96d8cac3e409b4057796@mail.kernel.org>
> diff --git a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c b/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
> index 023d8befd4cab..543b61df3a2b1 100644
> --- a/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c
> +++ b/tools/testing/selftests/bpf/progs/xsk_xdp_progs.c

[ ... ]

> @@ -75,6 +75,23 @@ SEC("xdp") int xsk_xdp_shared_umem(struct xdp_md *xdp)
>  	return bpf_redirect_map(&xsk, idx, XDP_DROP);
>  }
>
> +SEC("xdp") int xsk_xdp_shared_umem_length_based(struct xdp_md *xdp)
> +{
> +	void *data = (void *)(long)xdp->data;
> +	void *data_end = (void *)(long)xdp->data_end;
> +	__u32 pkt_len = data_end - data;
> +
> +	/*
> +	 * Route packets by total XDP-visible packet length (data_end - data):
> +	 * - Socket 0: packets <= SHARED_UMEM_LEN_SPLIT bytes
> +	 * - Socket 1: packets > SHARED_UMEM_LEN_SPLIT bytes
> +	 */
> +	if (pkt_len <= SHARED_UMEM_LEN_SPLIT)
> +		return bpf_redirect_map(&xsk, 0, XDP_DROP);
> +	else
> +		return bpf_redirect_map(&xsk, 1, XDP_DROP);
> +}

This isn't a bug, but could this comment be trimmed to a single line
like the one in xsk_xdp_shared_umem() above, and the trailing space
after the opening '/*' dropped so checkpatch stays quiet?

> diff --git a/tools/testing/selftests/bpf/xsk_xdp_common.h b/tools/testing/selftests/bpf/xsk_xdp_common.h
> index 45810ff552dae..bd9b5dcf8c8ee 100644
> --- a/tools/testing/selftests/bpf/xsk_xdp_common.h
> +++ b/tools/testing/selftests/bpf/xsk_xdp_common.h
> @@ -3,7 +3,8 @@
>  #ifndef XSK_XDP_COMMON_H_
>  #define XSK_XDP_COMMON_H_
>
> -#define MAX_SOCKETS 2
> +#define MAX_SOCKETS 4
> +#define SHARED_UMEM_LEN_SPLIT 64
>  #define PKT_HDR_ALIGN (sizeof(struct ethhdr) + 2) /* Just to align the data in the packet */

This isn't a bug, but since xsk_xdp_common.h is visible to test_xsk.c
too, would it be worth deriving the test's short/long lengths from
SHARED_UMEM_LEN_SPLIT (or noting why 64 is the right split) so the two
sides cannot drift apart?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/31554903166
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.