From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Emil Tsalapatis" <emil@etsalapatis.com>, <bpf@vger.kernel.org>
Cc: <andrii@kernel.org>, <eddyz87@gmail.com>, <memxor@gmail.com>,
<daniel@iogearbox.net>
Subject: Re: [PATCH bpf-next 0/7] bpf: Inline IRQ enter/exit instructions
Date: Tue, 27 Oct 2026 16:53:08 +0000 [thread overview]
Message-ID: <DMFRZIXSG0M2.YYE6X1OWNQWL@gmail.com> (raw)
In-Reply-To: <20261027162820.10887-1-emil@etsalapatis.com>
On Tue, Oct 27, 2026 at 09:28 AM Emil Tsalapatis <emil@etsalapatis.com> wrote:
> Add inlining for those functions. The inlining happens in two stages.
> First replace the call itself with a special BPF instruction denoting
> an IRQ disable-and save, or restore-and-enable. Those instructions
> are translated by the architecture-specific JIT into the corresponding
> operation.
No. That doesn't scale. We cannot add new insns for every to-be-inlined kfunc.
See bpf_jit_inlines_helper_call().
Like:
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6a2fe3d..c1c9a1c 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -3495,6 +3495,17 @@ populate_extable:
}
if (!imm32)
return -EINVAL;
+ if (src_reg == BPF_PSEUDO_KFUNC_CALL && bpf_jit_inlines_kfunc_call(func)) {
+ if (func == (u8 *)bpf_local_irq_save) {
+ /* pushfq; pop [rdi]; cli */
+ EMIT4(0x9C, 0x8F, 0x07, 0xFA);
+ } else {
+ /* test dword ptr [rdi], X86_EFLAGS_IF; je 1f; sti; 1: */
+ EMIT2_off32(0xF7, 0x07, X86_EFLAGS_IF);
+ EMIT3(X86_JE, 1, 0xFB);
+ }
+ break;
+ }
if (src_reg == BPF_PSEUDO_KFUNC_CALL) {
fm = bpf_jit_find_kfunc_model(bpf_prog, insn);
if (!fm)
@@ -5116,6 +5127,14 @@ bool bpf_jit_supports_kfunc_call(void)
return true;
}
+bool bpf_jit_inlines_kfunc_call(void *func)
+{
+ if (!IS_ENABLED(CONFIG_BPF_SYSCALL) || IS_ENABLED(CONFIG_TRACE_IRQFLAGS) ||
+ cpu_feature_enabled(X86_FEATURE_XENPV))
+ return false;
+ return func == bpf_local_irq_save || func == bpf_local_irq_restore;
+}
...
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 648abe1..26b6a9d 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -5197,8 +5197,8 @@ BTF_ID_FLAGS(func, bpf_get_kmem_cache, KF_PERFMON)
BTF_ID_FLAGS(func, bpf_iter_kmem_cache_new, KF_ITER_NEW | KF_SLEEPABLE)
BTF_ID_FLAGS(func, bpf_iter_kmem_cache_next, KF_ITER_NEXT | KF_RET_NULL | KF_SLEEPABLE)
BTF_ID_FLAGS(func, bpf_iter_kmem_cache_destroy, KF_ITER_DESTROY | KF_SLEEPABLE)
-BTF_ID_FLAGS(func, bpf_local_irq_save)
-BTF_ID_FLAGS(func, bpf_local_irq_restore)
+BTF_ID_FLAGS(func, bpf_local_irq_save, KF_FASTCALL)
+BTF_ID_FLAGS(func, bpf_local_irq_restore, KF_FASTCALL)
and corresponding bits in bpf_get_call_summary()...
but before doing any of that there gotta be performance numbers that it's worth doing.
pw-bot: cr
next prev parent reply other threads:[~2026-10-27 16:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 16:28 [PATCH bpf-next 0/7] bpf: Inline IRQ enter/exit instructions Emil Tsalapatis
2026-10-27 16:28 ` [PATCH bpf-next 1/7] bpf: Add internal IRQ save and restore instructions Emil Tsalapatis
2026-10-27 16:28 ` [PATCH bpf-next 2/7] x86, bpf: JIT " Emil Tsalapatis
2026-10-27 16:28 ` [PATCH bpf-next 3/7] arm64, " Emil Tsalapatis
2026-10-27 17:10 ` bot+bpf-ci
2026-10-27 16:28 ` [PATCH bpf-next 4/7] bpf: Inline local IRQ kfunc calls during verifier fixup Emil Tsalapatis
2026-10-27 16:28 ` [PATCH bpf-next 5/7] selftests/bpf: Test local IRQ kfunc inlining Emil Tsalapatis
2026-10-27 16:46 ` sashiko-bot
2026-10-27 17:10 ` bot+bpf-ci
2026-10-27 16:28 ` [PATCH bpf-next 6/7] bpf: Enable fastcall for inlined local IRQ kfuncs Emil Tsalapatis
2026-10-27 16:28 ` [PATCH bpf-next 7/7] selftests/bpf: Verify register preservation for IRQ fastcalls Emil Tsalapatis
2026-10-27 17:10 ` bot+bpf-ci
2026-10-27 16:53 ` Alexei Starovoitov [this message]
2026-10-28 1:55 ` [PATCH bpf-next 0/7] bpf: Inline IRQ enter/exit instructions Emil Tsalapatis
2026-10-28 16:56 ` Kumar Kartikeya Dwivedi
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=DMFRZIXSG0M2.YYE6X1OWNQWL@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.