From: Emil Tsalapatis <emil@etsalapatis.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com,
memxor@gmail.com, daniel@iogearbox.net,
Emil Tsalapatis <emil@etsalapatis.com>
Subject: [PATCH bpf-next 0/7] bpf: Inline IRQ enter/exit instructions
Date: Tue, 27 Oct 2026 16:28:13 +0000 [thread overview]
Message-ID: <20261027162820.10887-1-emil@etsalapatis.com> (raw)
The functions bpf_local_irq_save and bpf_local_irq_restore are only
a couple instructions long, since they are thin wrappers around
local_irq_save()/local_irq_restore(). However, they still require
a full call along with caller register save and restore. Since these
functions are used extensively in performance-critical code like
spinlocks, it is desireable to reduce their overhead.
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. There is no functional difference between the emitted code
and local_irq_save/restore(). Inlining reduces the overall latency of
a no-op critical sections from 47ns to 29ns on a high-end Zen 5 machine.
Add support for this inlining to the x86 and aarch64 JITs. The fixup
does not happen for JITs without explicit support, or for kernel
configurations that change the code run during local_irq_save/restore().
Mark the functions as fastcalls to remove caller register pushing and
popping. The calls are only marked as fastcalls when they are valid
for inlining, so the calls are not marked if not eligible or in
architectures that do not support inlining.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
Emil Tsalapatis (7):
bpf: Add internal IRQ save and restore instructions
x86, bpf: JIT internal IRQ save and restore instructions
arm64, bpf: JIT internal IRQ save and restore instructions
bpf: Inline local IRQ kfunc calls during verifier fixup
selftests/bpf: Test local IRQ kfunc inlining
bpf: Enable fastcall for inlined local IRQ kfuncs
selftests/bpf: Verify register preservation for IRQ fastcalls
arch/arm64/net/bpf_jit.h | 8 ++
arch/arm64/net/bpf_jit_comp.c | 34 +++++
arch/x86/net/bpf_jit_comp.c | 22 +++
include/linux/filter.h | 13 ++
kernel/bpf/core.c | 5 +
kernel/bpf/disasm.c | 8 ++
kernel/bpf/helpers.c | 4 +-
kernel/bpf/verifier.c | 17 +++
.../selftests/bpf/prog_tests/irq_fastcall.c | 71 ++++++++++
.../selftests/bpf/prog_tests/irq_jit.c | 128 ++++++++++++++++++
tools/testing/selftests/bpf/progs/irq.c | 24 ++++
.../selftests/bpf/progs/irq_fastcall.c | 56 ++++++++
tools/testing/selftests/bpf/progs/irq_jit.c | 55 ++++++++
13 files changed, 443 insertions(+), 2 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/irq_fastcall.c
create mode 100644 tools/testing/selftests/bpf/prog_tests/irq_jit.c
create mode 100644 tools/testing/selftests/bpf/progs/irq_fastcall.c
create mode 100644 tools/testing/selftests/bpf/progs/irq_jit.c
--
2.52.0
next reply other threads:[~2026-10-27 16:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 16:28 Emil Tsalapatis [this message]
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 ` [PATCH bpf-next 0/7] bpf: Inline IRQ enter/exit instructions Alexei Starovoitov
2026-10-28 1:55 ` 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=20261027162820.10887-1-emil@etsalapatis.com \
--to=emil@etsalapatis.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox