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 2/7] x86, bpf: JIT internal IRQ save and restore instructions
Date: Tue, 27 Oct 2026 16:28:15 +0000 [thread overview]
Message-ID: <20261027162820.10887-3-emil@etsalapatis.com> (raw)
In-Reply-To: <20261027162820.10887-1-emil@etsalapatis.com>
Implement the internal IRQ save/restore instruction in the x86-64 JIT,
using the encoded destination register as the flags pointer.
Save RFLAGS, disable interrupts and store the flags through that pointer.
Restore loads the saved flags and enables interrupts only when the saved
interrupt-enable bit is set.
Advertise support only when IRQ tracing and paravirtualized IRQ
operations do not require additional work.
Signed-off-by: Emil Tsalapatis <emil@etsalapatis.com>
---
arch/x86/net/bpf_jit_comp.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 6a2fe3d0039d..62833c0f7c97 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -3089,6 +3089,23 @@ static int do_jit(struct bpf_verifier_env *env, struct bpf_prog *bpf_prog, int *
EMIT_LFENCE();
break;
+ case BPF_ST | BPF_IRQ:
+ if (imm32 == BPF_IRQ_SAVE) {
+ EMIT1(0x9c);
+ EMIT2(0x41, add_1reg(0x58, BPF_REG_AX));
+ EMIT1(0xfa);
+ emit_stx(&prog, BPF_DW, dst_reg, BPF_REG_AX, 0);
+ } else if (imm32 == BPF_IRQ_RESTORE) {
+ emit_ldx(&prog, BPF_DW, BPF_REG_AX, dst_reg, 0);
+ maybe_emit_1mod(&prog, BPF_REG_AX, true);
+ EMIT2_off32(0xf7, add_1reg(0xc0, BPF_REG_AX), X86_EFLAGS_IF);
+ EMIT2(X86_JE, 1);
+ EMIT1(0xfb);
+ } else {
+ return -EINVAL;
+ }
+ break;
+
case BPF_ST | BPF_MEM | BPF_B:
case BPF_ST | BPF_MEM | BPF_H:
case BPF_ST | BPF_MEM | BPF_W:
@@ -5116,6 +5133,11 @@ bool bpf_jit_supports_kfunc_call(void)
return true;
}
+bool bpf_jit_supports_irq_save_restore(void)
+{
+ return !IS_ENABLED(CONFIG_TRACE_IRQFLAGS) && !IS_ENABLED(CONFIG_PARAVIRT_XXL);
+}
+
bool bpf_jit_supports_kfunc_ret_reg_pair(void)
{
return true;
--
2.52.0
next prev parent 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 [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 ` Emil Tsalapatis [this message]
2026-10-27 16:28 ` [PATCH bpf-next 3/7] arm64, bpf: JIT " 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-3-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 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.