* [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro
@ 2024-04-02 2:54 Yonghong Song
2024-04-02 4:29 ` John Fastabend
2024-04-02 14:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Yonghong Song @ 2024-04-02 2:54 UTC (permalink / raw)
To: bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team,
Martin KaFai Lau
Currently, cond_break macro uses bytes to encode the may_goto insn.
Patch [1] in llvm implemented may_goto insn in BPF backend.
Replace byte-level encoding with llvm inline asm for better usability.
Using llvm may_goto insn is controlled by macro __BPF_FEATURE_MAY_GOTO.
[1] https://github.com/llvm/llvm-project/commit/0e0bfacff71859d1f9212205f8f873d47029d3fb
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
tools/testing/selftests/bpf/bpf_experimental.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index a5b9df38c162..3329ea080865 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -326,6 +326,16 @@ l_true: \
})
#endif
+#ifdef __BPF_FEATURE_MAY_GOTO
+#define cond_break \
+ ({ __label__ l_break, l_continue; \
+ asm volatile goto("may_goto %l[l_break]" \
+ :::: l_break); \
+ goto l_continue; \
+ l_break: break; \
+ l_continue:; \
+ })
+#else
#define cond_break \
({ __label__ l_break, l_continue; \
asm volatile goto("1:.byte 0xe5; \
@@ -337,6 +347,7 @@ l_true: \
l_break: break; \
l_continue:; \
})
+#endif
#ifndef bpf_nop_mov
#define bpf_nop_mov(var) \
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* RE: [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro
2024-04-02 2:54 [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro Yonghong Song
@ 2024-04-02 4:29 ` John Fastabend
2024-04-02 14:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: John Fastabend @ 2024-04-02 4:29 UTC (permalink / raw)
To: Yonghong Song, bpf
Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann, kernel-team,
Martin KaFai Lau
Yonghong Song wrote:
> Currently, cond_break macro uses bytes to encode the may_goto insn.
> Patch [1] in llvm implemented may_goto insn in BPF backend.
> Replace byte-level encoding with llvm inline asm for better usability.
> Using llvm may_goto insn is controlled by macro __BPF_FEATURE_MAY_GOTO.
>
> [1] https://github.com/llvm/llvm-project/commit/0e0bfacff71859d1f9212205f8f873d47029d3fb
>
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
> ---
> tools/testing/selftests/bpf/bpf_experimental.h | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index a5b9df38c162..3329ea080865 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -326,6 +326,16 @@ l_true: \
> })
> #endif
>
> +#ifdef __BPF_FEATURE_MAY_GOTO
> +#define cond_break \
> + ({ __label__ l_break, l_continue; \
> + asm volatile goto("may_goto %l[l_break]" \
> + :::: l_break); \
> + goto l_continue; \
> + l_break: break; \
> + l_continue:; \
> + })
> +#else
> #define cond_break \
> ({ __label__ l_break, l_continue; \
> asm volatile goto("1:.byte 0xe5; \
> @@ -337,6 +347,7 @@ l_true: \
> l_break: break; \
> l_continue:; \
> })
> +#endif
>
> #ifndef bpf_nop_mov
> #define bpf_nop_mov(var) \
> --
> 2.43.0
>
>
Acked-by: John Fastabend <john.fastabend@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro
2024-04-02 2:54 [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro Yonghong Song
2024-04-02 4:29 ` John Fastabend
@ 2024-04-02 14:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-02 14:20 UTC (permalink / raw)
To: Yonghong Song; +Cc: bpf, ast, andrii, daniel, kernel-team, martin.lau
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Mon, 1 Apr 2024 19:54:46 -0700 you wrote:
> Currently, cond_break macro uses bytes to encode the may_goto insn.
> Patch [1] in llvm implemented may_goto insn in BPF backend.
> Replace byte-level encoding with llvm inline asm for better usability.
> Using llvm may_goto insn is controlled by macro __BPF_FEATURE_MAY_GOTO.
>
> [1] https://github.com/llvm/llvm-project/commit/0e0bfacff71859d1f9212205f8f873d47029d3fb
>
> [...]
Here is the summary with links:
- [bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro
https://git.kernel.org/bpf/bpf-next/c/965c6167c93f
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-02 14:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-02 2:54 [PATCH bpf-next] selftests/bpf: Using llvm may_goto inline asm for cond_break macro Yonghong Song
2024-04-02 4:29 ` John Fastabend
2024-04-02 14:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox