From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Valentin Schneider" <vschneid@redhat.com>,
"Dave Hansen" <dave.hansen@intel.com>,
"Viktor Malik" <vmalik@redhat.com>, <bpf@vger.kernel.org>
Cc: "Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Song Liu" <song@kernel.org>,
"Yonghong Song" <yonghong.song@linux.dev>,
"Jiri Olsa" <jolsa@kernel.org>,
"Emil Tsalapatis" <emil@etsalapatis.com>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"John Fastabend" <john.fastabend@gmail.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Borislav Petkov" <bp@alien8.de>,
"Peter Zijlstra" <peterz@infradead.org>,
"Josh Poimboeuf" <jpoimboe@kernel.org>,
"Pawan Gupta" <pawan.kumar.gupta@linux.intel.com>,
"Ingo Molnar" <mingo@redhat.com>,
"Dave Hansen" <dave.hansen@linux.intel.com>, <x86@kernel.org>,
"H. Peter Anvin" <hpa@zytor.com>,
"Tomas Glozar" <tglozar@redhat.com>,
"Greg KH" <gregkh@kernel.org>
Subject: Re: [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF
Date: Fri, 04 Dec 2026 19:42:21 +0000 [thread overview]
Message-ID: <DNC7DS9HOMRB.2BZDDXJNMKFT2@gmail.com> (raw)
In-Reply-To: <xhsmhpkvhlz1b.mognet@vschneid-thinkpadt14sgen2i.remote.csb>
On Fri, Dec 04, 2026 at 09:46 AM Valentin Schneider <vschneid@redhat.com> wrote:
> On 04/12/26 08:37, Dave Hansen wrote:
>> The NOHZ_FULL people aren't running untrusted code anyway. So I'm not
>> sure why they care in the first place other than being confused.
>>
>> Shouldn't you be getting them all running mitigations=off in the first
>> place?
>
> That would make our lives so much easier :-) Unfortunately, no... AIUI with
> Openshift we can have all sorts of things running on the HK CPUs, it's all
> containerized but that doesn't really count anymore.
if untrusted tasks stay on HK CPUs there is no need to track every prog.
Lets flush HK CPUs as today and track nohz_full CPUs only.
So JIT marks the CPU in the epilogue of unprivileged cBPF only.
I'm strongly against penalizing eBPF.
Instead of patches 1 and 2:
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 1abeb9a..8ad4a94 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -444,6 +444,7 @@ extern void write_ibpb(void);
#ifdef CONFIG_BPF_JIT
extern void bpf_arch_ibpb(void);
+DECLARE_PER_CPU(bool, x86_cbpf_ran);
#endif
#ifdef CONFIG_X86_64
diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 4ced10c..baefb8f 100644
--- a/arch/x86/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
@@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/nospec.h>
#include <linux/prctl.h>
+#include <linux/sched/isolation.h>
#include <linux/sched/smt.h>
#include <linux/pgtable.h>
#include <linux/bpf.h>
@@ -2251,14 +2252,24 @@ static void __init spectre_v2_update_mitigation(void)
}
#ifdef CONFIG_BPF_JIT
+/* Set by JITed unprivileged cBPF on exit, with nohz_full= only */
+DEFINE_PER_CPU(bool, x86_cbpf_ran);
+
static void __bpf_arch_ibpb(void *unused)
{
+ this_cpu_write(x86_cbpf_ran, false);
write_ibpb();
}
+static bool bpf_cpu_needs_ibpb(int cpu, void *unused)
+{
+ return housekeeping_cpu(cpu, HK_TYPE_KERNEL_NOISE) ||
+ READ_ONCE(per_cpu(x86_cbpf_ran, cpu));
+}
+
void bpf_arch_ibpb(void)
{
- on_each_cpu(__bpf_arch_ibpb, NULL, 1);
+ on_each_cpu_cond(bpf_cpu_needs_ibpb, __bpf_arch_ibpb, NULL, 1);
}
static bool __init cpu_wants_ibpb_bpf(void)
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index c3edda0..4edf578 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -13,6 +13,7 @@
#include <linux/bpf_unwind.h>
#include <linux/bpf_verifier.h>
#include <linux/memory.h>
+#include <linux/sched/isolation.h>
#include <linux/sort.h>
#include <linux/extable.h>
#include <asm/extable.h>
@@ -3913,6 +3914,13 @@ emit_jmp:
!ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN)) {
if (emit_spectre_bhb_barrier(&prog, ip, bpf_prog))
return -EINVAL;
+ if (static_branch_unlikely(&bpf_pred_flush_enabled) &&
+ housekeeping_enabled(HK_TYPE_KERNEL_NOISE)) {
+ /* mov byte ptr gs:[x86_cbpf_ran], 1 */
+ EMIT4_off32(0x65, 0xC6, 0x04, 0x25,
+ (u32)(unsigned long)&x86_cbpf_ran);
+ EMIT1(1);
+ }
}
/* Deallocate outgoing args 7+ area and the slot of BPF_REG_ARENA_SP. */
emit_add_rsp(&prog, outgoing_rsp + (arena_sp_save ? 8 : 0));
pw-bot: cr
prev parent reply other threads:[~2026-12-04 19:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:44 [PATCH bpf-next 0/2] bpf, x86: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program Viktor Malik
2026-12-04 14:03 ` sashiko-bot
2026-12-04 15:22 ` Viktor Malik
2026-12-04 14:51 ` Valentin Schneider
2026-12-04 16:27 ` Dave Hansen
2026-12-04 16:45 ` Viktor Malik
2026-12-04 13:44 ` [PATCH bpf-next 2/2] x86/bugs: Restrict BPF JIT IBPB flush to CPUs that ran BPF Viktor Malik
2026-12-04 14:17 ` sashiko-bot
2026-12-04 15:33 ` Viktor Malik
2026-12-04 14:51 ` Valentin Schneider
2026-12-04 15:01 ` [PATCH bpf-next 0/2] bpf, x86: " Valentin Schneider
2026-12-04 16:37 ` Dave Hansen
2026-12-04 17:46 ` Valentin Schneider
2026-12-04 19:42 ` Alexei Starovoitov [this message]
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=DNC7DS9HOMRB.2BZDDXJNMKFT2@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=gregkh@kernel.org \
--cc=hpa@zytor.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=jpoimboe@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mingo@redhat.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=song@kernel.org \
--cc=tglozar@redhat.com \
--cc=tglx@kernel.org \
--cc=vmalik@redhat.com \
--cc=vschneid@redhat.com \
--cc=x86@kernel.org \
--cc=yonghong.song@linux.dev \
/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