From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755666AbeARO6e (ORCPT ); Thu, 18 Jan 2018 09:58:34 -0500 Received: from merlin.infradead.org ([205.233.59.134]:46802 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755201AbeARO6G (ORCPT ); Thu, 18 Jan 2018 09:58:06 -0500 Message-Id: <20180118140152.059904070@infradead.org> User-Agent: quilt/0.63-1 Date: Thu, 18 Jan 2018 14:48:10 +0100 From: Peter Zijlstra From: Peter Zijlstra To: David Woodhouse , Thomas Gleixner , Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Dave Hansen , Ashok Raj , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick , Jason Baron , Peter Zijlstra , Borislav Petkov Subject: [PATCH 10/35] x86/jump_label: Implement arch_static_assert() References: <20180118134800.711245485@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 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