From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751763AbeAPOhA (ORCPT + 1 other); Tue, 16 Jan 2018 09:37:00 -0500 Received: from merlin.infradead.org ([205.233.59.134]:51848 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291AbeAPOeq (ORCPT ); Tue, 16 Jan 2018 09:34:46 -0500 Message-Id: <20180116143241.293294318@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 16 Jan 2018 15:28:32 +0100 From: Peter Zijlstra To: David Woodhouse , Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Dave Hansen , Ashok Raj , Thomas Gleixner , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick , Peter Zijlstra , Borislav Petkov Subject: [PATCH v2 07/10] x86/jump_label: Implement arch_static_assert() References: <20180116142825.376986833@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-x86-asm-goto-assert.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: 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: Borislav Petkov Cc: Thomas Gleixner Cc: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/jump_label.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -62,6 +62,29 @@ static __always_inline bool arch_static_ return true; } +/* + * Annotation for objtool; asserts that the previous instruction is the + * jump_label patch site. Or rather, that the next instruction is a static + * branch target. + * + * Use like: + * + * if (static_branch_likely(key)) { + * arch_static_assert(); + * do_code(); + * } + * + * Also works with static_cpu_has(). + */ +static __always_inline void arch_static_assert(void) +{ + asm volatile ("1:\n\t" + ".pushsection .discard.jump_assert \n\t" + _ASM_ALIGN "\n\t" + _ASM_PTR "1b \n\t" + ".popsection \n\t"); +} + #ifdef CONFIG_X86_64 typedef u64 jump_label_t; #else