[PATCH 3/4] x86/jump_label: Implement arch_static_assert()
From: Peter Zijlstra
Date: Mon Jan 15 2018 - 11:51:31 EST
Implement the static (branch) assertion. It simply emits the address
of the next instruction into a special section which objtool will read
and validate against either __jump_table or .altinstructions.
Use like:
if (static_branch_likely(_key)) {
arch_static_assert();
/* do stuff */
}
Or
if (static_cpu_has(_feat)) {
arch_static_assert();
/* do stuff */
}
Cc: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
---
arch/x86/include/asm/jump_label.h | 9 +++++++++
1 file changed, 9 insertions(+)
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -62,6 +62,15 @@ static __always_inline bool arch_static_
return true;
}
+static __always_inline void arch_static_assert(void)
+{
+ asm volatile ("1:\n\t"
+ ".pushsection .discard.jump_assert, \"aw\" \n\t"
+ _ASM_ALIGN "\n\t"
+ _ASM_PTR "1b \n\t"
+ ".popsection \n\t");
+}
+
#ifdef CONFIG_X86_64
typedef u64 jump_label_t;
#else