From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, memxor@gmail.com
Subject: Re: [PATCH bpf-next v2 07/17] bpf, x86: Add JIT support for callx
Date: Wed, 23 Sep 2026 22:33:12 -0700 [thread overview]
Message-ID: <fff46b2598a74aa51a8d686829522b6f490aa677.camel@gmail.com> (raw)
In-Reply-To: <20260924031042.1690890-8-alexei.starovoitov@gmail.com>
On Thu, 2026-09-24 at 03:10 +0000, Alexei Starovoitov wrote:
...
> diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
> index d4a980140b48..9fbef7504e51 100644
> --- a/arch/x86/net/bpf_jit_comp.c
> +++ b/arch/x86/net/bpf_jit_comp.c
> @@ -749,6 +749,46 @@ static void emit_indirect_jump(u8 **pprog, int bpf_reg, u8 *ip)
> *pprog = prog;
> }
>
> +static void __emit_indirect_call(u8 **pprog, int reg, bool ereg)
> +{
> + u8 *prog = *pprog;
> +
> + if (ereg)
> + EMIT1(0x41);
> +
> + EMIT2(0xFF, 0xD0 + reg);
> +
> + *pprog = prog;
> +}
> +
> +/* call *bpf_reg */
> +static int emit_indirect_call(u8 **pprog, int bpf_reg, u8 *ip)
> +{
> + u8 *prog = *pprog;
> + int reg = reg2hex[bpf_reg];
> + bool ereg = is_ereg(bpf_reg);
> + int err = 0;
> +
> + if (cpu_feature_enabled(X86_FEATURE_INDIRECT_THUNK_ITS)) {
> + OPTIMIZER_HIDE_VAR(reg);
This is quite unexpected. LLM points to [1].
A comment would be nice.
[1] commit be8a096521ca ("x86,bpf: Avoid IBT objtool warning")
> + err = emit_call(&prog, its_static_thunk(reg + 8*ereg), ip);
> + } else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE_LFENCE)) {
> + EMIT_LFENCE();
> + __emit_indirect_call(&prog, reg, ereg);
> + } else if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) {
> + OPTIMIZER_HIDE_VAR(reg);
> + if (cpu_feature_enabled(X86_FEATURE_CALL_DEPTH))
> + err = emit_call(&prog, &__x86_indirect_call_thunk_array[reg + 8*ereg], ip);
> + else
> + err = emit_call(&prog, &__x86_indirect_thunk_array[reg + 8*ereg], ip);
> + } else {
> + __emit_indirect_call(&prog, reg, ereg);
> + }
> +
> + *pprog = prog;
> + return err;
> +}
> +
> static void emit_return(u8 **pprog, u8 *ip)
> {
> u8 *prog = *pprog;
> @@ -2941,6 +2981,24 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
> break;
> }
>
> + /* callx: call of a bpf subprog whose address is in dst_reg */
> + case BPF_JMP | BPF_CALL | BPF_X:
> + /*
> + * The verifier makes sure that callees of callx are
> + * not tail call reachable, hence unlike a direct call
> + * of a subprog there is no need to pass
> + * tail_call_cnt_ptr in rax.
> + */
> + if (priv_frame_ptr) {
> + push_r9(&prog);
> + ip += 2;
LLM tells me the following:
This matters when emit_indirect_call() emits a relative call to a mitigation thunk:
displacement = thunk_address - (call_address + 5)
Without ip += 2, that displacement would be calculated from the
push’s address, and the call would land two bytes past the intended
target.
Which is not obvious at all.
Is it the reason for += 2?
> + }
> + if (emit_indirect_call(&prog, insn->dst_reg, ip))
> + return -EINVAL;
> + if (priv_frame_ptr)
> + pop_r9(&prog);
> + break;
> +
> case BPF_JMP | BPF_TAIL_CALL:
> if (imm32)
> emit_bpf_tail_call_direct(bpf_prog,
...
next prev parent reply other threads:[~2026-09-24 5:33 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 3:10 [PATCH bpf-next v2 00/17] bpf: Indirect calls of bpf subprogs (callx) Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 01/17] bpf: Fix infinite loop in check_max_stack_depth() Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 02/17] selftests/bpf: Test recursion through a global function and a callback Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 03/17] bpf: Keep functions with address taken when removing dead code Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 04/17] bpf: Prepare static analysis passes for callx instruction Alexei Starovoitov
2026-09-24 3:56 ` bot+bpf-ci
2026-09-24 4:18 ` Eduard Zingerman
2026-09-24 3:10 ` [PATCH bpf-next v2 05/17] bpf: Add callx instruction to call bpf subprogs indirectly Alexei Starovoitov
2026-09-24 3:28 ` sashiko-bot
2026-09-24 3:10 ` [PATCH bpf-next v2 06/17] bpf: Add callx calls to the call graph Alexei Starovoitov
2026-09-24 3:26 ` sashiko-bot
2026-09-24 3:56 ` bot+bpf-ci
2026-09-24 5:00 ` Eduard Zingerman
2026-09-24 3:10 ` [PATCH bpf-next v2 07/17] bpf, x86: Add JIT support for callx Alexei Starovoitov
2026-09-24 5:33 ` Eduard Zingerman [this message]
2026-09-24 3:10 ` [PATCH bpf-next v2 08/17] bpf, arm64: " Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 09/17] bpf: Discover subprogs described by func_info Alexei Starovoitov
2026-09-24 5:42 ` Eduard Zingerman
2026-09-24 3:10 ` [PATCH bpf-next v2 10/17] bpf: Recognize pointers to functions in read-only maps Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 11/17] libbpf: Support pointers to static functions in data when linking Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 12/17] libbpf: Resolve pointers to functions in read-only data Alexei Starovoitov
2026-09-24 3:27 ` sashiko-bot
2026-09-24 3:10 ` [PATCH bpf-next v2 13/17] libbpf: Treat .data.rel.ro as " Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 14/17] libbpf: Support pointers to functions in read-only data in light skeleton Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 15/17] selftests/bpf: Add tests for callx Alexei Starovoitov
2026-09-24 3:56 ` bot+bpf-ci
2026-09-24 3:10 ` [PATCH bpf-next v2 16/17] selftests/bpf: Add tests for callx through pointers in read-only data Alexei Starovoitov
2026-09-24 3:10 ` [PATCH bpf-next v2 17/17] bpf, docs: Document callx instruction Alexei Starovoitov
2026-09-24 5:50 ` [PATCH bpf-next v2 00/17] bpf: Indirect calls of bpf subprogs (callx) patchwork-bot+netdevbpf
2026-09-24 5:55 ` Eduard Zingerman
2026-09-24 6:00 ` Alexei Starovoitov
2026-09-24 17:50 ` Ihor Solodrai
2026-09-24 18:09 ` Alexei Starovoitov
2026-09-28 23:13 ` Ihor Solodrai
2026-09-29 6:04 ` Alexei Starovoitov
2026-09-29 16:40 ` Ihor Solodrai
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=fff46b2598a74aa51a8d686829522b6f490aa677.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=memxor@gmail.com \
/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