From: Leon Hwang <leon.hwang@linux.dev>
To: Tiezhu Yang <yangtiezhu@loongson.cn>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>
Cc: loongarch@lists.linux.dev, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v1] bpf: Fix unaligned interpreter panic on JIT fallback path
Date: Thu, 11 Jun 2026 15:37:11 +0800 [thread overview]
Message-ID: <aaca5c93-3b03-4fa2-9653-87c396e5ec7e@linux.dev> (raw)
In-Reply-To: <20260611070009.26257-1-yangtiezhu@loongson.cn>
On 11/6/26 15:00, Tiezhu Yang wrote:
[...]
>
> +/*
> + * Rewrite the helper call offset for inlined helpers when fallback to
> + * the interpreter happens due to JIT compilation failure or JIT disabled.
> + */
> +static void bpf_fixup_fallback_inline_helpers(struct bpf_verifier_env *env, struct bpf_prog *fp)
> +{
> + struct bpf_insn *insn = fp->insnsi;
> + const struct bpf_func_proto *fn;
> + int i;
> +
> + if (!env || !env->ops->get_func_proto)
> + return;
> +
> + for (i = 0; i < fp->len; i++, insn++) {
> + if (insn->code == (BPF_JMP | BPF_CALL) && insn->src_reg == 0) {
> + if (bpf_jit_inlines_helper_call(insn->imm)) {
> + fn = env->ops->get_func_proto(insn->imm, fp);
> + if (fn && fn->func)
> + insn->imm = fn->func - __bpf_call_base;
Might have pointer-to-integer warning?
> + }
> + }
> + }
> +}
> +
> struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct bpf_prog *fp,
> int *err)
> {
> @@ -2639,6 +2663,15 @@ struct bpf_prog *__bpf_prog_select_runtime(struct bpf_verifier_env *env, struct
>
> fp = bpf_prog_jit_compile(env, fp);
> bpf_prog_jit_attempt_done(fp);
> +
> + /*
> + * If JIT compilation failed or is disabled (!fp->jited), we are
> + * about to fall back to the interpreter path. Fix up the call
> + * offsets to prevent unaligned memory access panic.
> + */
> + if (!fp->jited)
> + bpf_fixup_fallback_inline_helpers(env, fp);
> +
Better to move it after (!fp->jited && jit_needed)?
Thanks,
Leon
> if (!fp->jited && jit_needed) {
> *err = -ENOTSUPP;
> return fp;
next prev parent reply other threads:[~2026-06-11 7:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 7:00 [PATCH bpf-next v1] bpf: Fix unaligned interpreter panic on JIT fallback path Tiezhu Yang
2026-06-11 7:37 ` Leon Hwang [this message]
2026-06-11 8:40 ` Tiezhu Yang
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=aaca5c93-3b03-4fa2-9653-87c396e5ec7e@linux.dev \
--to=leon.hwang@linux.dev \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--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