From: Hengqi Chen <hengqi.chen@gmail.com>
To: bpf@vger.kernel.org, loongarch@lists.linux.dev
Cc: hengqi.chen@gmail.com
Subject: [PATCH 1/2] LoongArch: BPF: Treat function address as 64-bit value
Date: Sun, 12 Feb 2023 11:52:35 +0800 [thread overview]
Message-ID: <20230212035236.1436532-2-hengqi.chen@gmail.com> (raw)
In-Reply-To: <20230212035236.1436532-1-hengqi.chen@gmail.com>
Let's always use 4 instructions for function address in JIT.
So that the instruction sequences don't change between the first
pass and the extra pass for function calls.
Fixes: 5dc615520c4d ("LoongArch: Add BPF JIT support")
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
arch/loongarch/net/bpf_jit.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
index c4b1947ebf76..2d952110be72 100644
--- a/arch/loongarch/net/bpf_jit.c
+++ b/arch/loongarch/net/bpf_jit.c
@@ -446,6 +446,27 @@ static int add_exception_handler(const struct bpf_insn *insn,
return 0;
}
+static inline void emit_addr_move(struct jit_ctx *ctx, enum loongarch_gpr rd, u64 addr)
+{
+ u64 imm_11_0, imm_31_12, imm_51_32, imm_63_52;
+
+ /* lu12iw rd, imm_31_12 */
+ imm_31_12 = (addr >> 12) & 0xfffff;
+ emit_insn(ctx, lu12iw, rd, imm_31_12);
+
+ /* ori rd, rd, imm_11_0 */
+ imm_11_0 = addr & 0xfff;
+ emit_insn(ctx, ori, rd, rd, imm_11_0);
+
+ /* lu32id rd, imm_51_32 */
+ imm_51_32 = (addr >> 32) & 0xfffff;
+ emit_insn(ctx, lu32id, rd, imm_51_32);
+
+ /* lu52id rd, rd, imm_63_52 */
+ imm_63_52 = (addr >> 52) & 0xfff;
+ emit_insn(ctx, lu52id, rd, rd, imm_63_52);
+}
+
static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool extra_pass)
{
u8 tm = -1;
@@ -841,7 +862,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext
if (ret < 0)
return ret;
- move_imm(ctx, t1, func_addr, is32);
+ emit_addr_move(ctx, t1, func_addr);
emit_insn(ctx, jirl, t1, LOONGARCH_GPR_RA, 0);
move_reg(ctx, regmap[BPF_REG_0], LOONGARCH_GPR_A0);
break;
--
2.31.1
next prev parent reply other threads:[~2023-02-12 3:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-12 3:52 [PATCH 0/2] Allow mixing bpf2bpf calls with tailcalls on LoongArch Hengqi Chen
2023-02-12 3:52 ` Hengqi Chen [this message]
2023-02-13 3:01 ` [PATCH 1/2] LoongArch: BPF: Treat function address as 64-bit value Tiezhu Yang
2023-02-13 3:18 ` Tiezhu Yang
2023-02-14 15:36 ` Hengqi Chen
2023-02-12 3:52 ` [PATCH 2/2] LoongArch: BPF: Support mixing bpf2bpf and tailcalls Hengqi Chen
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=20230212035236.1436532-2-hengqi.chen@gmail.com \
--to=hengqi.chen@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=loongarch@lists.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