From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x224mCS6ONnNzCBzOvHdWkwLCZf9wppOQvi/8Uo06HsLPvzgFtJcQXUxBUG30llc5hGro6o7+ ARC-Seal: i=1; a=rsa-sha256; t=1516721589; cv=none; d=google.com; s=arc-20160816; b=mVh4l5eK4CZWO1Qb3oreB46GSbXPHgkMq/BhzlVHg0yZ+eeALm0Ezqg2fbgbWMgPKO A8b0pvTYu5DUokLLRCvoNOC0xxX/Ix+NNXj3bjpx6Cx1o4ncKz9yD4EpU2VJnu7LeXin NaoQzFLMzTXKqkGYX/e6iSuTouiOhUc9x6++Qq7LEOFWfrcYiXKrcditDKjyoFOHc7Z/ iEYKuVtMM96uXEyqqPYaBWY6HWeIdOmiPVL0aIhuA3CpM5B/L+6hALaATvSpeDqyBZey ocMwt+hZV82e5JdWrNh1MJPBNK0s/3/lrbOVs0x+A/xd2OAaxz9XqbpdIDKt69vQVLJr NubQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature:arc-authentication-results; bh=f5K6Z12cWNfe7zxU/cKBTUhGNeZqZjLacxeggSQfFtg=; b=JKwAAAhS9tPzSZjpjXb6xf/aj4dZzSoPrjLz0Ey2GF4W2U5Oj33QwBYs36zuy7xC9P 4LG3FU2OoQaccjq2nKjgljjvRL8k2B/D7hZPCPXIALGjPjJZLrAWLYgkmkYgisNcuAom uJ07aKDPbW2ykmt3q25eGUU/Vto/yi/RXlC/f9JAc4jF/rFWYEECbwHI//mmvJbsR/X3 3S4cA08RxlHWEdGoUr1pZypRYNSB/J/HUKAzk4r4p9ZsZ9L64TFRC8wcT5h8VjYiuaW/ /O2ByHUPniWJFiWiNXvC4auYZg+QkwhClOw95pymwohvIoUc+ErXSzKg9PwJhYitxzNH 9y3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=hkC447Y6; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=hkC447Y6; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Message-Id: <20180123152639.284663884@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 23 Jan 2018 16:26:01 +0100 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 22/24] x86/jump_label: Implement arch_static_assert() References: <20180123152539.374360046@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-x86-asm-goto-assert.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590397857742473210?= X-GMAIL-MSGID: =?utf-8?q?1590397857742473210?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: 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