llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue
@ 2025-08-27  3:15 Feng Yang
  2025-08-27  4:03 ` Alexei Starovoitov
  2025-08-27  4:48 ` Eduard Zingerman
  0 siblings, 2 replies; 5+ messages in thread
From: Feng Yang @ 2025-08-27  3:15 UTC (permalink / raw)
  To: ast, daniel, john.fastabend, andrii, martin.lau, eddyz87, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, linux-kselftest, llvm

From: Feng Yang <yangfeng@kylinos.cn>

The following issue occurs when compiling with clang version 17.0.6,
but not with version 18.1.8. Add a version restriction to fix this problem.

progs/compute_live_registers.c:251:3: error: invalid operand for instruction
  251 |                 "r0 = 1;"
      |                 ^
<inline asm>:1:22: note: instantiated into assembly here
    1 |         r0 = 1;r2 = 2;if r1 & 0x7 goto +1;exit;r0 = r2;exit;
      |                             ^
1 error generated.

Fixes: 4a4b84ba9e453 ("selftests/bpf: verify jset handling in CFG computation")
Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
---
 tools/testing/selftests/bpf/progs/compute_live_registers.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c
index 6884ab99a421..56aec43f206f 100644
--- a/tools/testing/selftests/bpf/progs/compute_live_registers.c
+++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c
@@ -240,6 +240,7 @@ __naked void if2(void)
 		::: __clobber_all);
 }
 
+#if __clang_major__ >= 18
 /* Verifier misses that r2 is alive if jset is not handled properly */
 SEC("socket")
 __log_level(2)
@@ -255,6 +256,7 @@ __naked void if3_jset_bug(void)
 		"exit;"
 		::: __clobber_all);
 }
+#endif
 
 SEC("socket")
 __log_level(2)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue
  2025-08-27  3:15 [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue Feng Yang
@ 2025-08-27  4:03 ` Alexei Starovoitov
  2025-08-27  4:48 ` Eduard Zingerman
  1 sibling, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2025-08-27  4:03 UTC (permalink / raw)
  To: Feng Yang
  Cc: Alexei Starovoitov, Daniel Borkmann, John Fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Eduard, Song Liu,
	Yonghong Song, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	bpf, LKML, open list:KERNEL SELFTEST FRAMEWORK, clang-built-linux

On Tue, Aug 26, 2025 at 8:16 PM Feng Yang <yangfeng59949@163.com> wrote:
>
> From: Feng Yang <yangfeng@kylinos.cn>
>
> The following issue occurs when compiling with clang version 17.0.6,
> but not with version 18.1.8. Add a version restriction to fix this problem.
>
> progs/compute_live_registers.c:251:3: error: invalid operand for instruction
>   251 |                 "r0 = 1;"
>       |                 ^
> <inline asm>:1:22: note: instantiated into assembly here
>     1 |         r0 = 1;r2 = 2;if r1 & 0x7 goto +1;exit;r0 = r2;exit;
>       |                             ^
> 1 error generated.

and once it compiles what happens next ?

pw-bot: cr

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue
  2025-08-27  3:15 [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue Feng Yang
  2025-08-27  4:03 ` Alexei Starovoitov
@ 2025-08-27  4:48 ` Eduard Zingerman
  2025-08-27  8:24   ` Feng Yang
  1 sibling, 1 reply; 5+ messages in thread
From: Eduard Zingerman @ 2025-08-27  4:48 UTC (permalink / raw)
  To: Feng Yang, ast, daniel, john.fastabend, andrii, martin.lau, song,
	yonghong.song, kpsingh, sdf, haoluo, jolsa
  Cc: bpf, linux-kernel, linux-kselftest, llvm

On Wed, 2025-08-27 at 11:15 +0800, Feng Yang wrote:
> From: Feng Yang <yangfeng@kylinos.cn>
> 
> The following issue occurs when compiling with clang version 17.0.6,
> but not with version 18.1.8. Add a version restriction to fix this problem.
> 
> progs/compute_live_registers.c:251:3: error: invalid operand for instruction
>   251 |                 "r0 = 1;"
>       |                 ^
> <inline asm>:1:22: note: instantiated into assembly here
>     1 |         r0 = 1;r2 = 2;if r1 & 0x7 goto +1;exit;r0 = r2;exit;
>       |                             ^
> 1 error generated.
> 
> Fixes: 4a4b84ba9e453 ("selftests/bpf: verify jset handling in CFG computation")
> Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
> ---
>  tools/testing/selftests/bpf/progs/compute_live_registers.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> index 6884ab99a421..56aec43f206f 100644
> --- a/tools/testing/selftests/bpf/progs/compute_live_registers.c
> +++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> @@ -240,6 +240,7 @@ __naked void if2(void)
>  		::: __clobber_all);
>  }
>  
> +#if __clang_major__ >= 18

Instead of guarding this with compiler version, could you please use
progs/bpf_misc.h:__imm_insn() macro for the jset instruction?

>  /* Verifier misses that r2 is alive if jset is not handled properly */
>  SEC("socket")
>  __log_level(2)
> @@ -255,6 +256,7 @@ __naked void if3_jset_bug(void)
>  		"exit;"
>  		::: __clobber_all);
>  }
> +#endif
>  
>  SEC("socket")
>  __log_level(2)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue
  2025-08-27  4:48 ` Eduard Zingerman
@ 2025-08-27  8:24   ` Feng Yang
  2025-08-27 10:21     ` Eduard Zingerman
  0 siblings, 1 reply; 5+ messages in thread
From: Feng Yang @ 2025-08-27  8:24 UTC (permalink / raw)
  To: eddyz87
  Cc: andrii, ast, bpf, daniel, haoluo, john.fastabend, jolsa, kpsingh,
	linux-kernel, linux-kselftest, llvm, martin.lau, sdf, song,
	yangfeng59949, yonghong.song

On Tue, 26 Aug 2025 21:48:43 -0700, Eduard Zingerman <eddyz87@gmail.com> wrote:

> On Wed, 2025-08-27 at 11:15 +0800, Feng Yang wrote:
> > From: Feng Yang <yangfeng@kylinos.cn>
> > 
> > The following issue occurs when compiling with clang version 17.0.6,
> > but not with version 18.1.8. Add a version restriction to fix this problem.
> > 
> > progs/compute_live_registers.c:251:3: error: invalid operand for instruction
> >   251 |                 "r0 = 1;"
> >       |                 ^
> > <inline asm>:1:22: note: instantiated into assembly here
> >     1 |         r0 = 1;r2 = 2;if r1 & 0x7 goto +1;exit;r0 = r2;exit;
> >       |                             ^
> > 1 error generated.
> > 
> > Fixes: 4a4b84ba9e453 ("selftests/bpf: verify jset handling in CFG computation")
> > Signed-off-by: Feng Yang <yangfeng@kylinos.cn>
> > ---
> >  tools/testing/selftests/bpf/progs/compute_live_registers.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> > index 6884ab99a421..56aec43f206f 100644
> > --- a/tools/testing/selftests/bpf/progs/compute_live_registers.c
> > +++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> > @@ -240,6 +240,7 @@ __naked void if2(void)
> >  		::: __clobber_all);
> >  }
> >  
> > +#if __clang_major__ >= 18

> Instead of guarding this with compiler version, could you please use
> progs/bpf_misc.h:__imm_insn() macro for the jset instruction?

I don't know much about assembly language. Could you tell me if the following changes are correct?

diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c
index 6884ab99a421..01d73ad76faf 100644
--- a/tools/testing/selftests/bpf/progs/compute_live_registers.c
+++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c
@@ -249,11 +249,13 @@ __naked void if3_jset_bug(void)
 	asm volatile (
 		"r0 = 1;"
 		"r2 = 2;"
-		"if r1 & 0x7 goto +1;"
+		".8byte %[jset];" /* same as 'if r1 & 0x7 goto +1;' */
 		"exit;"
 		"r0 = r2;"
 		"exit;"
-		::: __clobber_all);
+		:
+		: __imm_insn(jset, BPF_JMP_IMM(BPF_JSET, BPF_REG_1, 0x7, 1))
+		: __clobber_all);
 }


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue
  2025-08-27  8:24   ` Feng Yang
@ 2025-08-27 10:21     ` Eduard Zingerman
  0 siblings, 0 replies; 5+ messages in thread
From: Eduard Zingerman @ 2025-08-27 10:21 UTC (permalink / raw)
  To: Feng Yang
  Cc: andrii, ast, bpf, daniel, haoluo, john.fastabend, jolsa, kpsingh,
	linux-kernel, linux-kselftest, llvm, martin.lau, sdf, song,
	yonghong.song

On Wed, 2025-08-27 at 16:24 +0800, Feng Yang wrote:

[...]

> I don't know much about assembly language. Could you tell me if the following changes are correct?

Looks correct, should be similar to verifier_search_pruning.c:short_loop1().

Unfortunately, I'm afraid that the best source for assembly syntax doc
are llvm backend tests and sources, e.g.:
- https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/BPF/assembler-disassembler.s
- https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/BPF/assembler-disassembler-v4.s
- https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/BPF/BPFInstrInfo.td

The directives should gas compatible (subset supported by llvm):
- https://sourceware.org/binutils/docs/as/8byte.html

> diff --git a/tools/testing/selftests/bpf/progs/compute_live_registers.c b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> index 6884ab99a421..01d73ad76faf 100644
> --- a/tools/testing/selftests/bpf/progs/compute_live_registers.c
> +++ b/tools/testing/selftests/bpf/progs/compute_live_registers.c
> @@ -249,11 +249,13 @@ __naked void if3_jset_bug(void)
>  	asm volatile (
>  		"r0 = 1;"
>  		"r2 = 2;"
> -		"if r1 & 0x7 goto +1;"
> +		".8byte %[jset];" /* same as 'if r1 & 0x7 goto +1;' */
>  		"exit;"
>  		"r0 = r2;"
>  		"exit;"
> -		::: __clobber_all);
> +		:
> +		: __imm_insn(jset, BPF_JMP_IMM(BPF_JSET, BPF_REG_1, 0x7, 1))
> +		: __clobber_all);
>  }
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-27 10:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27  3:15 [PATCH bpf-next] selftests/bpf: Fix the invalid operand for instruction issue Feng Yang
2025-08-27  4:03 ` Alexei Starovoitov
2025-08-27  4:48 ` Eduard Zingerman
2025-08-27  8:24   ` Feng Yang
2025-08-27 10:21     ` Eduard Zingerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).