BPF List
 help / color / mirror / Atom feed
From: Menglong Dong <menglong.dong@linux.dev>
To: yangtiezhu@loongson.cn, Hengqi Chen <hengqi.chen@gmail.com>
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, chenhuacai@kernel.org,
	vincent.mc.li@gmail.com, menglong8.dong@gmail.com,
	loongarch@lists.linux.dev, bpf@vger.kernel.org,
	Hengqi Chen <hengqi.chen@gmail.com>
Subject: Re: [PATCH 1/3] LoongArch: BPF: Introduce emit_store_stack_imm64() helper
Date: Wed, 04 Mar 2026 10:04:02 +0800	[thread overview]
Message-ID: <4716621.LvFx2qVVIh@7940hx> (raw)
In-Reply-To: <20260226065952.4082859-2-hengqi.chen@gmail.com>

On 2026/2/26 14:59 Hengqi Chen <hengqi.chen@gmail.com> write:
> Introduce a helper to store 64-bit immediate on the trampoline stack.
> The helper will be used in the next patch. Also refactor the existing
> code to use this helper.
> 
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>  arch/loongarch/net/bpf_jit.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> index 3bd89f55960d..e3deb0da6a50 100644
> --- a/arch/loongarch/net/bpf_jit.c
> +++ b/arch/loongarch/net/bpf_jit.c
> @@ -1480,6 +1480,12 @@ static void restore_args(struct jit_ctx *ctx, int nargs, int args_off)
>  	}
>  }

LGTM.

Reviewed-by: Menglong Dong <menglong8.dong@gmail.com>

>  
> +static void emit_store_stack_imm64(struct jit_ctx *ctx, int reg, int stack_off, u64 imm64)
> +{
> +	move_imm(ctx, reg, imm64, false);
> +	emit_insn(ctx, std, reg, LOONGARCH_GPR_FP, stack_off);
> +}
> +
>  static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l,
>  			   int args_off, int retval_off, int run_ctx_off, bool save_ret)
>  {
> @@ -1488,12 +1494,11 @@ static int invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_link *l,
>  	struct bpf_prog *p = l->link.prog;
>  	int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
>  
> -	if (l->cookie) {
> -		move_imm(ctx, LOONGARCH_GPR_T1, l->cookie, false);
> -		emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -run_ctx_off + cookie_off);
> -	} else {
> +	if (l->cookie)
> +		emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1,
> +				      -run_ctx_off + cookie_off, l->cookie);
> +	else
>  		emit_insn(ctx, std, LOONGARCH_GPR_ZERO, LOONGARCH_GPR_FP, -run_ctx_off + cookie_off);
> -	}
>  
>  	/* arg1: prog */
>  	move_imm(ctx, LOONGARCH_GPR_A0, (const s64)p, false);
> @@ -1726,14 +1731,11 @@ static int __arch_prepare_bpf_trampoline(struct jit_ctx *ctx, struct bpf_tramp_i
>  	emit_insn(ctx, std, LOONGARCH_GPR_S1, LOONGARCH_GPR_FP, -sreg_off);
>  
>  	/* store ip address of the traced function */
> -	if (flags & BPF_TRAMP_F_IP_ARG) {
> -		move_imm(ctx, LOONGARCH_GPR_T1, (const s64)func_addr, false);
> -		emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -ip_off);
> -	}
> +	if (flags & BPF_TRAMP_F_IP_ARG)
> +		emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -ip_off, (u64)func_addr);
>  
>  	/* store nargs number */
> -	move_imm(ctx, LOONGARCH_GPR_T1, nargs, false);
> -	emit_insn(ctx, std, LOONGARCH_GPR_T1, LOONGARCH_GPR_FP, -nargs_off);
> +	emit_store_stack_imm64(ctx, LOONGARCH_GPR_T1, -nargs_off, nargs);
>  
>  	store_args(ctx, nargs, args_off);
>  
> -- 
> 2.43.5
> 
> 
> 





  reply	other threads:[~2026-03-04  2:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26  6:59 [PATCH 0/3] bpf: fsession support for LoongArch Hengqi Chen
2026-02-26  6:59 ` [PATCH 1/3] LoongArch: BPF: Introduce emit_store_stack_imm64() helper Hengqi Chen
2026-03-04  2:04   ` Menglong Dong [this message]
2026-02-26  6:59 ` [PATCH 2/3] LoongArch: BPF: Add fsession support for trampolines Hengqi Chen
2026-03-04  2:11   ` Menglong Dong
2026-02-26  6:59 ` [PATCH bpf-next 3/3] bpf/selftests: Enable fsession tests for LoongArch Hengqi Chen
2026-02-27  1:59   ` Vincent Li
2026-03-04  1:43   ` Menglong Dong
2026-03-04  2:51 ` [PATCH 0/3] bpf: fsession support " Menglong Dong
2026-04-22  8:18 ` Huacai 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=4716621.LvFx2qVVIh@7940hx \
    --to=menglong.dong@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hengqi.chen@gmail.com \
    --cc=loongarch@lists.linux.dev \
    --cc=martin.lau@linux.dev \
    --cc=menglong8.dong@gmail.com \
    --cc=vincent.mc.li@gmail.com \
    --cc=yangtiezhu@loongson.cn \
    /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