From: Chenghao Duan <duanchenghao@kylinos.cn>
To: Hengqi Chen <hengqi.chen@gmail.com>
Cc: yangtiezhu@loongson.cn, rostedt@goodmis.org, mhiramat@kernel.org,
mark.rutland@arm.com, chenhuacai@kernel.org, kernel@xen0n.name,
zhangtianyang@loongson.cn, masahiroy@kernel.org,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
bpf@vger.kernel.org, youling.tang@linux.dev,
jianghaoran@kylinos.cn, vincent.mc.li@gmail.com,
linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v4 6/7] LoongArch: BPF: Enhance the bpf_arch_text_poke() function
Date: Mon, 22 Dec 2025 09:50:10 +0800 [thread overview]
Message-ID: <20251222015010.GA119291@chenghao-pc> (raw)
In-Reply-To: <CAEyhmHRbacxpfTkPJq4MerBupH0bJkFfx8xGUvHMvGOzDDJUow@mail.gmail.com>
On Sat, Dec 20, 2025 at 10:07:25PM +0800, Hengqi Chen wrote:
> On Wed, Dec 17, 2025 at 2:15 PM Chenghao Duan <duanchenghao@kylinos.cn> wrote:
> >
> > Enhance the bpf_arch_text_poke() function to enable accurate location
> > of BPF program entry points.
> >
> > When modifying the entry point of a BPF program, skip the move t0, ra
> > instruction to ensure the correct logic and copy of the jump address.
> >
> > Signed-off-by: Chenghao Duan <duanchenghao@kylinos.cn>
> > ---
> > arch/loongarch/net/bpf_jit.c | 15 ++++++++++++++-
> > 1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/loongarch/net/bpf_jit.c b/arch/loongarch/net/bpf_jit.c
> > index 3dbabacc8856..0c16a1b18e8f 100644
> > --- a/arch/loongarch/net/bpf_jit.c
> > +++ b/arch/loongarch/net/bpf_jit.c
> > @@ -1290,6 +1290,10 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
> > void *new_addr)
>
> The signature of bpf_arch_text_poke() was changed in v6.19 ([1]), please rebase.
>
> [1]: https://github.com/torvalds/linux/commit/ae4a3160d19cd16b874737ebc1798c7bc2fe3c9e
Thank you for your review and for pointing out the API change in v6.19.
I believe my patch series already accounts for this. It was developed on
top of commit ae4a3160d19c ("bpf: specify the old and new poke_type for bpf_arch_text_poke"),
so all modifications to bpf_arch_text_poke() call sites within my
patches should already be using the updated signature.
Please let me know if you find any inconsistencies or if further
adjustments are needed.
Best regards,
Chenghao
>
> > {
> > int ret;
> > + unsigned long size = 0;
> > + unsigned long offset = 0;
> > + char namebuf[KSYM_NAME_LEN];
> > + void *image = NULL;
> > bool is_call;
> > u32 old_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
> > u32 new_insns[LOONGARCH_LONG_JUMP_NINSNS] = {[0 ... 4] = INSN_NOP};
> > @@ -1297,9 +1301,18 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type old_t,
> > /* Only poking bpf text is supported. Since kernel function entry
> > * is set up by ftrace, we rely on ftrace to poke kernel functions.
> > */
> > - if (!is_bpf_text_address((unsigned long)ip))
> > + if (!__bpf_address_lookup((unsigned long)ip, &size, &offset, namebuf))
> > return -ENOTSUPP;
> >
> > + image = ip - offset;
> > + /* zero offset means we're poking bpf prog entry */
> > + if (offset == 0)
> > + /* skip to the nop instruction in bpf prog entry:
> > + * move t0, ra
> > + * nop
> > + */
> > + ip = image + LOONGARCH_INSN_SIZE;
> > +
> > is_call = old_t == BPF_MOD_CALL;
> > ret = emit_jump_or_nops(old_addr, ip, old_insns, is_call);
> > if (ret)
> > --
> > 2.25.1
> >
next prev parent reply other threads:[~2025-12-22 1:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 6:14 [PATCH v4 0/7] Fix the failure issue of the module_attach test case Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 1/7] LoongArch: ftrace: Refactor register restoration in ftrace_common_return Chenghao Duan
2025-12-17 6:55 ` bot+bpf-ci
2025-12-18 1:26 ` Chenghao Duan
2025-12-18 15:26 ` Chris Mason
2025-12-17 6:14 ` [PATCH v4 2/7] LoongArch: Enable exception fixup for specific ADE subcode Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 3/7] LoongArch: BPF: Enable and fix trampoline-based tracing for module functions Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 4/7] LoongArch: BPF: Save return address register ra to t0 before trampoline Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 5/7] LoongArch: BPF: Adjust the jump offset of tail calls Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 6/7] LoongArch: BPF: Enhance the bpf_arch_text_poke() function Chenghao Duan
2025-12-20 14:07 ` Hengqi Chen
2025-12-22 1:50 ` Chenghao Duan [this message]
2025-12-23 2:23 ` Hengqi Chen
2025-12-23 8:49 ` Huacai Chen
2025-12-17 6:14 ` [PATCH v4 7/7] LoongArch: ftrace: Adjust register stack restore order in direct call trampolines Chenghao Duan
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=20251222015010.GA119291@chenghao-pc \
--to=duanchenghao@kylinos.cn \
--cc=bpf@vger.kernel.org \
--cc=chenhuacai@kernel.org \
--cc=hengqi.chen@gmail.com \
--cc=jianghaoran@kylinos.cn \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=masahiroy@kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=vincent.mc.li@gmail.com \
--cc=yangtiezhu@loongson.cn \
--cc=youling.tang@linux.dev \
--cc=zhangtianyang@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;
as well as URLs for NNTP newsgroup(s).