From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934942AbeAOQv2 (ORCPT + 1 other); Mon, 15 Jan 2018 11:51:28 -0500 Received: from merlin.infradead.org ([205.233.59.134]:41214 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934464AbeAOQua (ORCPT ); Mon, 15 Jan 2018 11:50:30 -0500 Message-Id: <20180115164909.894255586@infradead.org> User-Agent: quilt/0.63-1 Date: Mon, 15 Jan 2018 17:44:31 +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 3/4] x86/jump_label: Implement arch_static_assert() References: <20180115164428.498966552@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: Josh Poimboeuf Cc: Thomas Gleixner Cc: Borislav Petkov Signed-off-by: Peter Zijlstra (Intel) --- 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