From: Jakub Sitnicki <jakub@cloudflare.com>
To: Yonghong Song <yhs@meta.com>
Cc: baomingtong001@208suo.com, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev, song@kernel.org,
yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@google.com, haoluo@google.com, jolsa@kernel.org,
mykolal@fb.com, shuah@kernel.org,
Jakub Kicinski <kuba@kernel.org>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests/bpf: Remove unneeded variable "ret"
Date: Tue, 13 Jun 2023 20:13:00 +0200 [thread overview]
Message-ID: <87pm5z9q36.fsf@cloudflare.com> (raw)
In-Reply-To: <53510828-ee5b-1d91-0f85-b79da4422741@meta.com>
On Tue, Jun 13, 2023 at 06:42 AM -07, Yonghong Song wrote:
> On 6/13/23 1:50 AM, baomingtong001@208suo.com wrote:
>> Fix the following coccicheck warning:
>> tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c:28:14-17: Unneeded
>> variable: "ret".
>> Return "1".
>> Signed-off-by: Mingtong Bao <baomingtong001@208suo.com>
>> ---
>> tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>> diff --git a/tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c
>> b/tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c
>> index 4a9f63bea66c..7f0146682577 100644
>> --- a/tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c
>> +++ b/tools/testing/selftests/bpf/progs/tailcall_bpf2bpf6.c
>> @@ -25,10 +25,9 @@ static __noinline
>> int subprog_tail(struct __sk_buff *skb)
>> {
>> /* Don't propagate the constant to the caller */
>> - volatile int ret = 1;
>> bpf_tail_call_static(skb, &jmp_table, 0);
>> - return ret;
>> + return 1;
>
> Please pay attention to the comment:
> /* Don't propagate the constant to the caller */
> which clearly says 'constant' is not preferred.
>
> The patch introduced this change is:
> 5e0b0a4c52d30 selftests/bpf: Test tail call counting with bpf2bpf and data
> on stack
>
> The test intentionally want to:
> 'Specifically when the size of data allocated on BPF stack is not a
> multiple on 8.'
>
> Note that with volatile and without volatile, the generated
> code will be different and it will result in different
> verification path.
>
> cc Jakub for further clarification.
Yonghong is right. We can't replace it like that.
Compiler is smart and pull up the constant into subprog_tail() caller.
And it doesn't have the slightest idea that bpf_tail_call_static() is
actually tail call (destroy frame + jump) and control doesn't return to
subprog_tail().
(You can read more about BPF tail calls in [1] and [2] if they are not
familiar.)
IOW, we need an r0 store to happen after a call to BPF tail call helper
(call 12) to remain in subprog_tail body for the regression test to
work:
$ llvm-objdump -d --no-show-raw-insn tailcall_bpf2bpf6.bpf.o
tailcall_bpf2bpf6.bpf.o: file format elf64-bpf
Disassembly of section .text:
0000000000000000 <subprog_tail>:
0: r6 = r1
1: w1 = 1
2: *(u32 *)(r10 - 4) = r1
3: r7 = 0 ll
5: r1 = r6
6: r2 = r7
7: r3 = 0
8: call 12
9: r0 = *(u32 *)(r10 - 4) <-- this must stay
10: exit
You could take a shot at replacing it with inline asm, if you want.
[1] https://docs.cilium.io/en/stable/bpf/architecture/#bpf-to-bpf-calls
[2] https://blog.cloudflare.com/assembly-within-bpf-tail-calls-on-x86-and-arm/
prev parent reply other threads:[~2023-06-13 18:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230613084315.62021-1-luojianhong@cdjrlc.com>
[not found] ` <6228af14241b831be4bae6ebcd63799e@208suo.com>
2023-06-13 13:42 ` [PATCH] selftests/bpf: Remove unneeded variable "ret" Yonghong Song
2023-06-13 18:13 ` Jakub Sitnicki [this message]
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=87pm5z9q36.fsf@cloudflare.com \
--to=jakub@cloudflare.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=baomingtong001@208suo.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mykolal@fb.com \
--cc=sdf@google.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yhs@fb.com \
--cc=yhs@meta.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.