Subject: Re: [PATCH v9 bpf-next 2/2] selftests/bpf: Add selftests for the invocation of bpf_lwt_xmit_push_encap

From: Martin KaFai Lau <[email-masked]>
Date: Tue, 3 Mar 2026 13:13:59 -0800

On 3/2/26 11:44 PM, Feng Yang wrote:
> From: Feng Yang <[email-masked]>
> 
> Calling bpf_lwt_xmit_push_encap will not cause a crash when dst is missing.
> 
> Signed-off-by: Feng Yang <[email-masked]>
> ---
>   .../selftests/bpf/progs/verifier_lwt.c        | 20 +++++++++++++++++++
>   1 file changed, 20 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/verifier_lwt.c b/tools/testing/selftests/bpf/progs/verifier_lwt.c
> index 5ab746307309..9cef07e6eceb 100644
> --- a/tools/testing/selftests/bpf/progs/verifier_lwt.c
> +++ b/tools/testing/selftests/bpf/progs/verifier_lwt.c
> @@ -231,4 +231,24 @@ __naked void not_permitted_for_lwt_prog(void)
>   	: __clobber_all);
>   }
>   
> +SEC("lwt_xmit")
> +__description("missing dst when calling bpf_lwt_xmit_push_encap")
> +__success __retval(0)
> +__naked void missing_dst_call_bpf_lwt_xmit_push_encap(void)
> +{
> +	asm volatile ("					\
> +	r9 = 69;					\

hmm... I just noticed this.

69 is the ip version and ihl?

> +	r3 = r10;					\
> +	r3 += -32;					\
> +	*(u64 *)(r3 + 0) = r9;				\

This will not work in big endian. Although x86 arch is enough to cover 
this test, these little things (e.g., the value 69, unnecessary asm 
...etc) make this test hard to read.

Let's bite the bullet and move this bpf test prog out of verifier_lwt.c. 
It is not testing the verifier to begin with. No need to write in asm 
either. Create its own progs/lwt_misc.c test file for misc lwt tests. 
Create a corresponding prog_tests/lwt_misc.c also. Write the bpf prog in 
C instead of asm. Use "char iph[20];" for the iph and init "iph[0] = 
0x45". Search for RUN_TESTS() usage in prog_tests/. It is pretty 
straightforward.

pw-bot: cr

> +	r2 = 2;						\
> +	r4 = 20;					\
> +	call %[bpf_lwt_push_encap];			\
> +	r0 = 0;						\
> +	exit;						\
> +"	:
> +	: __imm(bpf_lwt_push_encap)
> +	: __clobber_all);
> +}
> +
>   char _license[] SEC("license") = "GPL";