public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Menglong Dong <menglong.dong@linux.dev>
To: Menglong Dong <menglong8.dong@gmail.com>, Pu Lehui <pulehui@huawei.com>
Cc: bjorn@kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com,
	song@kernel.org, yonghong.song@linux.dev,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me,
	haoluo@google.com, jolsa@kernel.org, puranjay@kernel.org,
	pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu,
	alex@ghiti.fr, bpf@vger.kernel.org,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	jiang.biao@linux.dev
Subject: Re: [PATCH bpf-next v3 1/3] bpf, riscv: introduce emit_store_stack_imm64() for trampoline
Date: Sat, 07 Feb 2026 18:53:17 +0800	[thread overview]
Message-ID: <3042323.e9J7NaK4W3@7950hx> (raw)
In-Reply-To: <d6281121-b39b-41ac-a166-69dbfa1f4f79@huawei.com>

On 2026/2/7 09:13, Pu Lehui wrote:
> 
> On 2026/2/6 20:20, Menglong Dong wrote:
> > Introduce a helper to store 64-bit immediate on the trampoline stack with
> > a help of a register.
> > 
> > Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> > Tested-by: Björn Töpel <bjorn@kernel.org>
> > Acked-by: Björn Töpel <bjorn@kernel.org>
> > ---
> >   arch/riscv/net/bpf_jit_comp64.c | 25 ++++++++++++++-----------
> >   1 file changed, 14 insertions(+), 11 deletions(-)
> > 
> > diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> > index 37888abee70c..e4f45e2e7e2f 100644
> > --- a/arch/riscv/net/bpf_jit_comp64.c
> > +++ b/arch/riscv/net/bpf_jit_comp64.c
> > @@ -926,6 +926,14 @@ static void restore_stack_args(int nr_stack_args, int args_off, int stk_arg_off,
> >   	}
> >   }
> >   
> > +static void emit_store_stack_imm64(u8 reg, int stack_off, u64 imm64,
> > +				   struct rv_jit_context *ctx)
> 
> Some nit. The first parameter can be removed by using a fixed RV_REG_T1. 
> Also, placing imm64 before stack_off might looks better.

Hi, Lehui. When I implement the emit_store_stack_imm64() in x86,
Andrii suggested that we'd better use the register explicitly to indicate
the register is used. So maybe it's better to keep this part still?

I can place the imm64 before stack_off.

Thanks!
Menglong Dong

> 
> > +{
> > +	/* Load imm64 into reg and store it at [FP + stack_off]. */
> > +	emit_imm(reg, (s64)imm64, ctx);
> > +	emit_sd(RV_REG_FP, stack_off, reg, ctx);
> > +}
> > +
> >   static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_off,
> >   			   int run_ctx_off, bool save_ret, struct rv_jit_context *ctx)
> >   {
> > @@ -933,12 +941,10 @@ static int invoke_bpf_prog(struct bpf_tramp_link *l, int args_off, int retval_of
> >   	struct bpf_prog *p = l->link.prog;
> >   	int cookie_off = offsetof(struct bpf_tramp_run_ctx, bpf_cookie);
> >   
> > -	if (l->cookie) {
> > -		emit_imm(RV_REG_T1, l->cookie, ctx);
> > -		emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_T1, ctx);
> > -	} else {
> > +	if (l->cookie)
> > +		emit_store_stack_imm64(RV_REG_T1, -run_ctx_off + cookie_off, l->cookie, ctx);
> > +	else
> >   		emit_sd(RV_REG_FP, -run_ctx_off + cookie_off, RV_REG_ZERO, ctx);
> > -	}
> >   
> >   	/* arg1: prog */
> >   	emit_imm(RV_REG_A0, (const s64)p, ctx);
> > @@ -1123,13 +1129,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
> >   	emit_sd(RV_REG_FP, -sreg_off, RV_REG_S1, ctx);
> >   
> >   	/* store ip address of the traced function */
> > -	if (flags & BPF_TRAMP_F_IP_ARG) {
> > -		emit_imm(RV_REG_T1, (const s64)func_addr, ctx);
> > -		emit_sd(RV_REG_FP, -ip_off, RV_REG_T1, ctx);
> > -	}
> > +	if (flags & BPF_TRAMP_F_IP_ARG)
> > +		emit_store_stack_imm64(RV_REG_T1, -ip_off, (u64)func_addr, ctx); >
> > -	emit_li(RV_REG_T1, nr_arg_slots, ctx);
> > -	emit_sd(RV_REG_FP, -nregs_off, RV_REG_T1, ctx);
> > +	emit_store_stack_imm64(RV_REG_T1, -nregs_off, nr_arg_slots, ctx);
> >   
> >   	store_args(nr_arg_slots, args_off, ctx);
> >   
> 
> 





  reply	other threads:[~2026-02-07 10:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-06 12:19 [PATCH bpf-next v3 0/3] bpf: fsession support for riscv Menglong Dong
2026-02-06 12:20 ` [PATCH bpf-next v3 1/3] bpf, riscv: introduce emit_store_stack_imm64() for trampoline Menglong Dong
2026-02-07  1:13   ` Pu Lehui
2026-02-07 10:53     ` Menglong Dong [this message]
2026-02-08  1:58       ` Pu Lehui
2026-02-06 12:20 ` [PATCH bpf-next v3 2/3] bpf, riscv: add fsession support for trampolines Menglong Dong
2026-02-06 12:51   ` bot+bpf-ci
2026-02-06 13:42     ` Björn Töpel
2026-02-06 14:27       ` Menglong Dong
2026-02-06 20:22   ` kernel test robot
2026-02-06 21:47   ` kernel test robot
2026-02-06 12:20 ` [PATCH bpf-next v3 3/3] selftests/bpf: enable fsession_test on riscv64 Menglong Dong

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=3042323.e9J7NaK4W3@7950hx \
    --to=menglong.dong@linux.dev \
    --cc=alex@ghiti.fr \
    --cc=andrii@kernel.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=ast@kernel.org \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=jiang.biao@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=martin.lau@linux.dev \
    --cc=menglong8.dong@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=pulehui@huawei.com \
    --cc=puranjay@kernel.org \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --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