Re: [PATCH bpf-next v9 4/5] bpf, x86: Emit ENDBR for indirect jump targets
From: Xu Kuohai
Date: Mon Mar 23 2026 - 09:49:13 EST
On 3/14/2026 9:35 PM, Leon Hwang wrote:
On 2026/3/14 14:48, Xu Kuohai wrote:
On 3/13/2026 6:15 PM, Leon Hwang wrote:
+#ifdef CONFIG_X86_KERNEL_IBTNIT: is this CONFIG check necessary?
+ if (bpf_insn_is_indirect_target(env, bpf_prog, i - 1))
+ EMIT_ENDBR();
+#endif
EMIT_ENDBR already checks it.
#ifdef CONFIG_X86_KERNEL_IBT
#define EMIT_ENDBR() EMIT(gen_endbr(), 4)
#define EMIT_ENDBR_POISON() EMIT(gen_endbr_poison(), 4)
#else
#define EMIT_ENDBR()
#define EMIT_ENDBR_POISON()
#endif
Well, the code was originally written exactly without the #ifdef, but it
triggered
-Wempty-body warning: https://lore.kernel.org/bpf/202603051414.AAMjmOHv-
lkp@xxxxxxxxx/.
Let's update the macros instead, which can avoid the build warning and
get rid of the CONFIG check as well.
#define EMIT_ENDBR() do { } while (0)
#define EMIT_ENDBR_POISON() do { } while (0)
The way of "do { } while (0)" is commonly used in kernel.
Sorry for the delay. This makes sense to me. The code looks much cleaner
without the #ifdef, thanks!
Thanks,
Leon