* [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic()
@ 2025-01-03 2:02 Peilin Ye
2025-01-03 2:03 ` [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i() Peilin Ye
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Peilin Ye @ 2025-01-03 2:02 UTC (permalink / raw)
To: bpf
Cc: Peilin Ye, Xu Kuohai, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Puranjay Mohan, Catalin Marinas, Will Deacon,
Josh Don, Barret Rhoden, linux-arm-kernel, linux-kernel
Delete that unnecessary outer if clause. No functional change.
Signed-off-by: Peilin Ye <yepeilin@google.com>
---
arch/arm64/net/bpf_jit_comp.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 66708b95493a..9040033eb1ea 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -648,16 +648,14 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
const s16 off = insn->off;
u8 reg = dst;
- if (off || arena) {
- if (off) {
- emit_a64_mov_i(1, tmp, off, ctx);
- emit(A64_ADD(1, tmp, tmp, dst), ctx);
- reg = tmp;
- }
- if (arena) {
- emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx);
- reg = tmp;
- }
+ if (off) {
+ emit_a64_mov_i(1, tmp, off, ctx);
+ emit(A64_ADD(1, tmp, tmp, dst), ctx);
+ reg = tmp;
+ }
+ if (arena) {
+ emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx);
+ reg = tmp;
}
switch (insn->imm) {
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i()
2025-01-03 2:02 [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
@ 2025-01-03 2:03 ` Peilin Ye
2025-01-03 2:04 ` [PATCH bpf-next v2 3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic() Peilin Ye
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Peilin Ye @ 2025-01-03 2:03 UTC (permalink / raw)
To: bpf
Cc: Peilin Ye, Xu Kuohai, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Puranjay Mohan, Catalin Marinas, Will Deacon,
Josh Don, Barret Rhoden, linux-arm-kernel, linux-kernel
As suggested by Xu, factor out emit_a64_add_i() for later use. No
functional change.
Suggested-by: Xu Kuohai <xukuohai@huaweicloud.com>
Signed-off-by: Peilin Ye <yepeilin@google.com>
---
arch/arm64/net/bpf_jit_comp.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 9040033eb1ea..8ee9528d8795 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -267,6 +267,19 @@ static bool is_addsub_imm(u32 imm)
return !(imm & ~0xfff) || !(imm & ~0xfff000);
}
+static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
+ const int tmp, const s32 imm, struct jit_ctx *ctx)
+{
+ if (is_addsub_imm(imm)) {
+ emit(A64_ADD_I(is64, dst, src, imm), ctx);
+ } else if (is_addsub_imm(-imm)) {
+ emit(A64_SUB_I(is64, dst, src, -imm), ctx);
+ } else {
+ emit_a64_mov_i(is64, tmp, imm, ctx);
+ emit(A64_ADD(is64, dst, src, tmp), ctx);
+ }
+}
+
/*
* There are 3 types of AArch64 LDR/STR (immediate) instruction:
* Post-index, Pre-index, Unsigned offset.
@@ -1144,14 +1157,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
/* dst = dst OP imm */
case BPF_ALU | BPF_ADD | BPF_K:
case BPF_ALU64 | BPF_ADD | BPF_K:
- if (is_addsub_imm(imm)) {
- emit(A64_ADD_I(is64, dst, dst, imm), ctx);
- } else if (is_addsub_imm(-imm)) {
- emit(A64_SUB_I(is64, dst, dst, -imm), ctx);
- } else {
- emit_a64_mov_i(is64, tmp, imm, ctx);
- emit(A64_ADD(is64, dst, dst, tmp), ctx);
- }
+ emit_a64_add_i(is64, dst, dst, tmp, imm, ctx);
break;
case BPF_ALU | BPF_SUB | BPF_K:
case BPF_ALU64 | BPF_SUB | BPF_K:
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH bpf-next v2 3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic()
2025-01-03 2:02 [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
2025-01-03 2:03 ` [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i() Peilin Ye
@ 2025-01-03 2:04 ` Peilin Ye
2025-01-06 6:42 ` [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Xu Kuohai
2025-01-06 14:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Peilin Ye @ 2025-01-03 2:04 UTC (permalink / raw)
To: bpf
Cc: Peilin Ye, Xu Kuohai, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Puranjay Mohan, Catalin Marinas, Will Deacon,
Josh Don, Barret Rhoden, linux-arm-kernel, linux-kernel
Currently in emit_{lse,ll_sc}_atomic(), if there is an offset, we add it
to the base address by doing e.g.:
if (off) {
emit_a64_mov_i(1, tmp, off, ctx);
emit(A64_ADD(1, tmp, tmp, dst), ctx);
...
As pointed out by Xu, we can use emit_a64_add_i() (added in the previous
patch) instead, which tries to combine the above into a single A64_ADD_I
or A64_SUB_I when possible.
Suggested-by: Xu Kuohai <xukuohai@huaweicloud.com>
Signed-off-by: Peilin Ye <yepeilin@google.com>
---
change in v2:
* move the logic into a helper (added in v2 2/3) and use it (Xu)
v1: https://lore.kernel.org/bpf/953c7241e82496cb7a8b5a8724028ad646cd0896.1735342016.git.yepeilin@google.com/
arch/arm64/net/bpf_jit_comp.c | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 8ee9528d8795..8446848edddb 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -662,8 +662,7 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
u8 reg = dst;
if (off) {
- emit_a64_mov_i(1, tmp, off, ctx);
- emit(A64_ADD(1, tmp, tmp, dst), ctx);
+ emit_a64_add_i(1, tmp, reg, tmp, off, ctx);
reg = tmp;
}
if (arena) {
@@ -734,7 +733,7 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
const s32 imm = insn->imm;
const s16 off = insn->off;
const bool isdw = BPF_SIZE(code) == BPF_DW;
- u8 reg;
+ u8 reg = dst;
s32 jmp_offset;
if (BPF_MODE(code) == BPF_PROBE_ATOMIC) {
@@ -743,11 +742,8 @@ static int emit_ll_sc_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
return -EINVAL;
}
- if (!off) {
- reg = dst;
- } else {
- emit_a64_mov_i(1, tmp, off, ctx);
- emit(A64_ADD(1, tmp, tmp, dst), ctx);
+ if (off) {
+ emit_a64_add_i(1, tmp, reg, tmp, off, ctx);
reg = tmp;
}
--
2.47.1.613.gc27f4b7a9f-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic()
2025-01-03 2:02 [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
2025-01-03 2:03 ` [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i() Peilin Ye
2025-01-03 2:04 ` [PATCH bpf-next v2 3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic() Peilin Ye
@ 2025-01-06 6:42 ` Xu Kuohai
2025-01-06 14:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Xu Kuohai @ 2025-01-06 6:42 UTC (permalink / raw)
To: Peilin Ye, bpf
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Puranjay Mohan, Catalin Marinas, Will Deacon, Josh Don,
Barret Rhoden, linux-arm-kernel, linux-kernel
On 1/3/2025 10:02 AM, Peilin Ye wrote:
> Delete that unnecessary outer if clause. No functional change.
>
> Signed-off-by: Peilin Ye <yepeilin@google.com>
> ---
> arch/arm64/net/bpf_jit_comp.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 66708b95493a..9040033eb1ea 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -648,16 +648,14 @@ static int emit_lse_atomic(const struct bpf_insn *insn, struct jit_ctx *ctx)
> const s16 off = insn->off;
> u8 reg = dst;
>
> - if (off || arena) {
> - if (off) {
> - emit_a64_mov_i(1, tmp, off, ctx);
> - emit(A64_ADD(1, tmp, tmp, dst), ctx);
> - reg = tmp;
> - }
> - if (arena) {
> - emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx);
> - reg = tmp;
> - }
> + if (off) {
> + emit_a64_mov_i(1, tmp, off, ctx);
> + emit(A64_ADD(1, tmp, tmp, dst), ctx);
> + reg = tmp;
> + }
> + if (arena) {
> + emit(A64_ADD(1, tmp, reg, arena_vm_base), ctx);
> + reg = tmp;
> }
>
> switch (insn->imm) {
Thanks for the improvements.
For the series:
Acked-by: Xu Kuohai <xukuohai@huawei.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic()
2025-01-03 2:02 [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
` (2 preceding siblings ...)
2025-01-06 6:42 ` [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Xu Kuohai
@ 2025-01-06 14:20 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-01-06 14:20 UTC (permalink / raw)
To: Peilin Ye
Cc: bpf, xukuohai, ast, daniel, andrii, martin.lau, eddyz87, song,
yonghong.song, john.fastabend, kpsingh, sdf, haoluo, jolsa,
puranjay, catalin.marinas, will, joshdon, brho, linux-arm-kernel,
linux-kernel
Hello:
This series was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Fri, 3 Jan 2025 02:02:53 +0000 you wrote:
> Delete that unnecessary outer if clause. No functional change.
>
> Signed-off-by: Peilin Ye <yepeilin@google.com>
> ---
> arch/arm64/net/bpf_jit_comp.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
Here is the summary with links:
- [bpf-next,v2,1/3] bpf, arm64: Simplify if logic in emit_lse_atomic()
https://git.kernel.org/bpf/bpf-next/c/0a5807219a86
- [bpf-next,v2,2/3] bpf, arm64: Factor out emit_a64_add_i()
https://git.kernel.org/bpf/bpf-next/c/66bb58ac06c2
- [bpf-next,v2,3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic()
https://git.kernel.org/bpf/bpf-next/c/8c21f88407d2
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] 5+ messages in thread
end of thread, other threads:[~2025-01-06 14:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-03 2:02 [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
2025-01-03 2:03 ` [PATCH bpf-next v2 2/3] bpf, arm64: Factor out emit_a64_add_i() Peilin Ye
2025-01-03 2:04 ` [PATCH bpf-next v2 3/3] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic() Peilin Ye
2025-01-06 6:42 ` [PATCH bpf-next v2 1/3] bpf, arm64: Simplify if logic in emit_lse_atomic() Xu Kuohai
2025-01-06 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