BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	 Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>
Subject: Re: [PATCH bpf-next 3/3] selftests/bpf: Add some tests related to 'may_goto 0' insns
Date: Thu, 16 Jan 2025 11:49:04 -0800	[thread overview]
Message-ID: <ef0761e2c9fb451a292a7c59cc7a7d5b02dce790.camel@gmail.com> (raw)
In-Reply-To: <20250116055139.605195-1-yonghong.song@linux.dev>

On Wed, 2025-01-15 at 21:51 -0800, Yonghong Song wrote:
> Add both asm-based and C-based tests which have 'may_goto 0' insns.
> 
> For the following code in C-based test,
>    int i, tmp[3];
>    for (i = 0; i < 3 && can_loop; i++)
>        tmp[i] = 0;
> 
> The clang compiler (clang 19 and 20) generates
>    may_goto 2
>    may_goto 1
>    may_goto 0
>    r1 = 0
>    r2 = 0
>    r3 = 0
> 
> The above asm codes are due to llvm pass SROAPass. This ensures the
> successful verification since tmp[0-2] are initialized.  Otherwise,
> the code without SROAPass like
>    may_goto 5
>    r1 = 0
>    may_goto 3
>    r2 = 0
>    may_goto 1
>    r3 = 0
> will have verification failure.
> 
> Although from the source code C-based test should have verification
> failure, clang compiler optimization generates code with successful
> verification. If gcc generates different asm codes than clang, the
> following code can be used for gcc:
>    int i, tmp[3];
>    for (i = 0; i < 3; i++)
>        tmp[i] = 0;
> 
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
> ---

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

> +SEC("raw_tp")
> +__description("may_goto batch with offsets 2/1/0")
> +__arch_x86_64
> +__xlated("0: r0 = 1")
> +__xlated("1: exit")
> +__success
> +__naked void may_goto_batch_1(void)
> +{
> +	asm volatile (
> +	".8byte %[may_goto1];"
> +	".8byte %[may_goto2];"
> +	".8byte %[may_goto3];"
> +	"r0 = 1;"
> +	".8byte %[may_goto1];"
> +	".8byte %[may_goto2];"
> +	".8byte %[may_goto3];"
> +	"exit;"
> +	:
> +	: __imm_insn(may_goto1, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 2 /* offset */, 0)),
> +	  __imm_insn(may_goto2, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 1 /* offset */, 0)),
> +	  __imm_insn(may_goto3, BPF_RAW_INSN(BPF_JMP | BPF_JCOND, 0, 0, 0 /* offset */, 0))

Rant: may_goto3 that does +0 jump is a bit confusing :)

> +	: __clobber_all);
> +}

[...]


      reply	other threads:[~2025-01-16 19:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-16  5:51 [PATCH bpf-next 0/3] bpf: Allow 'may_goto 0' instruction Yonghong Song
2025-01-16  5:51 ` [PATCH bpf-next 1/3] " Yonghong Song
2025-01-16 19:23   ` Eduard Zingerman
2025-01-16  5:51 ` [PATCH bpf-next 2/3] bpf: Remove " Yonghong Song
2025-01-16 19:42   ` Eduard Zingerman
2025-01-17  1:45     ` Alexei Starovoitov
2025-01-17  3:43       ` Yonghong Song
2025-01-16  5:51 ` [PATCH bpf-next 3/3] selftests/bpf: Add some tests related to 'may_goto 0' insns Yonghong Song
2025-01-16 19:49   ` Eduard Zingerman [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=ef0761e2c9fb451a292a7c59cc7a7d5b02dce790.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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