From: Viktor Malik <vmalik@redhat.com>
To: Dave Hansen <dave.hansen@intel.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
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>,
Valentin Schneider <vschneid@redhat.com>,
Tomas Glozar <tglozar@redhat.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: Track CPUs that have executed a BPF program
Date: Fri, 4 Dec 2026 17:45:05 +0100 [thread overview]
Message-ID: <3041c918-e336-4308-ba2a-1b5332ddb29d@redhat.com> (raw)
In-Reply-To: <0cb5c81d-d168-4b91-92fc-6aa5f8b27ff9@intel.com>
On 12/4/26 17:27, Dave Hansen wrote:
> On 12/4/26 05:44, Viktor Malik wrote:
>> +static __always_inline void bpf_prog_mark_ran(void)
>> +{
>> + bool *ran;
>> +
>> + if (!static_branch_unlikely(&bpf_pred_flush_enabled))
>> + return;
>> +
>> + ran = raw_cpu_ptr(&bpf_prog_ran);
>> + if (!READ_ONCE(*ran))
>> + WRITE_ONCE(*ran, true);
>> +}
>
> This is bizarrely complex.
>
> I obviously know why code might want to avoid dirtying a cacheline,
> especially when it might be shared. But this is per-cpu data. It's
> fundamentally not in other CPU caches.
>
> What's wrong with?
>
> if (static_branch_unlikely(&bpf_pred_flush_enabled))
>
> this_cpu_write(bpf_prog_ran, true);
This CPU's bpf_prog_ran is read from another CPU in bpf_ibpb_needed() so
I was probably overcautiously protecting the cacheline here. But that's
likely not worth the complexity so I'll update to your suggestion.
>> DEFINE_STATIC_KEY_FALSE(bpf_pred_flush_enabled);
>> +EXPORT_SYMBOL(bpf_pred_flush_enabled);
>> +
>> +/*
>> + * Set on a CPU once it has executed a JITed BPF program since the last
>> + * predictor flush; see bpf_prog_mark_ran() and bpf_arch_pred_flush().
>> + */
>> +DEFINE_PER_CPU(bool, bpf_prog_ran);
>> +EXPORT_PER_CPU_SYMBOL(bpf_prog_ran);
>
> What are the exports for? Any reason they're generic exports and not
> GPL-only?
The exports are needed for builds when __bpf_prog_run() gets inlined
into modules (XDP drivers, test_bpf.ko), otherwise the build failed on
modpost errors.
No reason not to make them GPL-only, I'll change that in v2.
Thanks for the review!
Viktor
next prev parent reply other threads:[~2026-12-04 16:45 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 [this message]
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
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=3041c918-e336-4308-ba2a-1b5332ddb29d@redhat.com \
--to=vmalik@redhat.com \
--cc=andrii@kernel.org \
--cc=ast@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=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=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