public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Martin KaFai Lau <martin.lau@linux.dev>
To: Paul Chaignon <paul.chaignon@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Amery Hung <ameryhung@gmail.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 5/5] selftests/bpf: Test direct packet access on non-linear skbs
Date: Tue, 7 Oct 2025 11:01:32 -0700	[thread overview]
Message-ID: <62e288f3-9917-4218-84f7-01e2eb27130c@linux.dev> (raw)
In-Reply-To: <302cd8554710d04986925df1737c787c09b5ff65.1759843268.git.paul.chaignon@gmail.com>

On 10/7/25 6:38 AM, Paul Chaignon wrote:
> +#define access_test_non_linear(name, type, desc, retval, linear_sz, off)			\
> +	SEC(type)										\
> +	__description("direct packet access: " #name " (non-linear, " type ", " desc ")")	\
> +	__success __retval(retval)								\
> +	__linear_size(linear_sz)								\
> +	__naked void access_non_linear_##name(void)						\
> +	{											\
> +		asm volatile ("									\
> +		r2 = *(u32*)(r1 + %[skb_data]);							\
> +		r3 = *(u32*)(r1 + %[skb_data_end]);						\
> +		r0 = r2;									\
> +		r0 += %[offset];								\
> +		if r0 > r3 goto l0_%=;								\
> +		r0 = *(u8*)(r0 - 1);								\
> +		r0 = 0;										\
> +		exit;										\
> +	l0_%=:	r0 = 1;										\
> +		exit;										\
> +	"	:										\
> +		: __imm_const(skb_data, offsetof(struct __sk_buff, data)),			\
> +		  __imm_const(skb_data_end, offsetof(struct __sk_buff, data_end)),		\
> +		  __imm_const(offset, off)							\
> +		: __clobber_all);								\
> +	}
> +
> +access_test_non_linear(test31, "tc", "too short eth", 1, ETH_HLEN, 22);
> +access_test_non_linear(test32, "tc", "too short 1", 1, 1, 22);
> +access_test_non_linear(test33, "tc", "long enough", 0, 22, 22);
> +access_test_non_linear(test34, "cgroup_skb/ingress", "too short eth", 1, ETH_HLEN, 8);
> +access_test_non_linear(test35, "cgroup_skb/ingress", "too short 1", 1, 1, 8);
> +access_test_non_linear(test36, "cgroup_skb/ingress", "long enough", 0, 22, 8);
> +
> +SEC("tc")
> +__description("direct packet access: test36 (non-linear, linearized)")
> +__success __retval(0)
> +__linear_size(ETH_HLEN)
> +__naked void access_non_linear_linearized(void)
> +{
> +	asm volatile ("									\
> +	r6 = r1;									\
> +	r2 = 22;									\
> +	call %[bpf_skb_pull_data];							\
> +	r2 = *(u32*)(r6 + %[skb_data]);							\
> +	r3 = *(u32*)(r6 + %[skb_data_end]);						\
> +	r0 = r2;									\
> +	r0 += 22;									\
> +	if r0 > r3 goto l0_%=;								\
> +	r0 = *(u8*)(r0 - 1);								\
> +	exit;										\
> +l0_%=:	r0 = 1;										\
> +	exit;										\
> +"	:
> +	: __imm(bpf_skb_pull_data),
> +	  __imm_const(skb_data, offsetof(struct __sk_buff, data)),
> +	  __imm_const(skb_data_end, offsetof(struct __sk_buff, data_end))
> +	: __clobber_all);
> +}

Does it have to be in asm?


  reply	other threads:[~2025-10-07 18:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-07 13:36 [PATCH bpf-next v6 0/5] Support non-linear skbs for BPF_PROG_TEST_RUN Paul Chaignon
2025-10-07 13:37 ` [PATCH bpf-next v6 1/5] bpf: Refactor cleanup of bpf_prog_test_run_skb Paul Chaignon
2025-10-07 13:37 ` [PATCH bpf-next v6 2/5] bpf: Reorder bpf_prog_test_run_skb initialization Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 3/5] bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN Paul Chaignon
2025-10-07 17:59   ` Martin KaFai Lau
2025-10-09 13:32     ` Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 4/5] selftests/bpf: Support non-linear flag in test loader Paul Chaignon
2025-10-07 13:38 ` [PATCH bpf-next v6 5/5] selftests/bpf: Test direct packet access on non-linear skbs Paul Chaignon
2025-10-07 18:01   ` Martin KaFai Lau [this message]
2025-10-09 13:44     ` Paul Chaignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=62e288f3-9917-4218-84f7-01e2eb27130c@linux.dev \
    --to=martin.lau@linux.dev \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=paul.chaignon@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox