From: Xu Kuohai <xukuohai@huaweicloud.com>
To: Peilin Ye <yepeilin@google.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
Puranjay Mohan <puranjay@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Josh Don <joshdon@google.com>,
Barret Rhoden <brho@google.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 2/2] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic()
Date: Mon, 30 Dec 2024 16:44:26 +0800 [thread overview]
Message-ID: <6763d7c3-7971-477f-aa47-cb2fdf4b08e2@huaweicloud.com> (raw)
In-Reply-To: <953c7241e82496cb7a8b5a8724028ad646cd0896.1735342016.git.yepeilin@google.com>
On 12/28/2024 7:36 AM, Peilin Ye wrote:
> Currently in emit_{lse,ll_sc}_atomic(), if there is an offset, we add it
> to the base address by emitting two instructions, for example:
>
> 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 combine the above into a single A64_ADD_I
> instruction if 'is_addsub_imm(off)' is true, or an A64_SUB_I, if
> 'is_addsub_imm(-off)' is true.
>
> Suggested-by: Xu Kuohai <xukuohai@huaweicloud.com>
> Signed-off-by: Peilin Ye <yepeilin@google.com>
> ---
> Hi all,
>
> This was pointed out by Xu in [1] . Tested on x86-64, using
> PLATFORM=aarch64 CROSS_COMPILE=aarch64-linux-gnu- vmtest.sh:
>
> LSE:
> * ./test_progs-cpuv4 -a atomics,arena_atomics
> 2/15 PASSED, 0 SKIPPED, 0 FAILED
> * ./test_verifier
> 790 PASSED, 0 SKIPPED, 0 FAILED
>
> LL/SC:
> (In vmtest.sh, changed '-cpu' QEMU option from 'cortex-a76' to
> 'cortex-a57', to make LSE atomics unavailable.)
> * ./test_progs-cpuv4 -a atomics
> 1/7 PASSED, 0 SKIPPED, 0 FAILED
> * ./test_verifier
> 790 PASSED, 0 SKIPPED, 0 FAILED
>
> Thanks,
> Peilin Ye
>
> [1] https://lore.kernel.org/bpf/f704019d-a8fa-4cf5-a606-9d8328360a3e@huaweicloud.com/
>
> arch/arm64/net/bpf_jit_comp.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> index 9040033eb1ea..f15bbe92fed9 100644
> --- a/arch/arm64/net/bpf_jit_comp.c
> +++ b/arch/arm64/net/bpf_jit_comp.c
> @@ -649,8 +649,14 @@ 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);
> + if (is_addsub_imm(off)) {
> + emit(A64_ADD_I(1, tmp, reg, off), ctx);
> + } else if (is_addsub_imm(-off)) {
> + emit(A64_SUB_I(1, tmp, reg, -off), ctx);
> + } else {
> + emit_a64_mov_i(1, tmp, off, ctx);
> + emit(A64_ADD(1, tmp, tmp, reg), ctx);
> + }
> reg = tmp;
> }
> if (arena) {
> @@ -721,7 +727,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) {
> @@ -730,11 +736,15 @@ 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) {
> + if (is_addsub_imm(off)) {
> + emit(A64_ADD_I(1, tmp, reg, off), ctx);
> + } else if (is_addsub_imm(-off)) {
> + emit(A64_SUB_I(1, tmp, reg, -off), ctx);
> + } else {
> + emit_a64_mov_i(1, tmp, off, ctx);
> + emit(A64_ADD(1, tmp, tmp, reg), ctx);
> + }
> reg = tmp;
> }
>
Thanks, this looks good to me, but we now have serveral repetitive code
snippets like this. It would be better to refactor them into a common
function.
next prev parent reply other threads:[~2024-12-30 8:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-27 23:35 [PATCH bpf-next 1/2] bpf, arm64: Simplify if logic in emit_lse_atomic() Peilin Ye
2024-12-27 23:36 ` [PATCH bpf-next 2/2] bpf, arm64: Emit A64_{ADD,SUB}_I when possible in emit_{lse,ll_sc}_atomic() Peilin Ye
2024-12-30 8:44 ` Xu Kuohai [this message]
2024-12-30 23:25 ` Peilin Ye
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=6763d7c3-7971-477f-aa47-cb2fdf4b08e2@huaweicloud.com \
--to=xukuohai@huaweicloud.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brho@google.com \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=joshdon@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=puranjay@kernel.org \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=will@kernel.org \
--cc=yepeilin@google.com \
--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
all inboxes | Powered by JetHome®