Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2656709pxb; Thu, 10 Feb 2022 02:35:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJznP2hktp7OLuXGztUzXC2mv6ds7l/CiU3PWn6cfQmKh6EwQqa5XDVm0HHZ9rLt9w4ZadxF X-Received: by 2002:a17:903:1250:: with SMTP id u16mr6723501plh.126.1644489300410; Thu, 10 Feb 2022 02:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644489300; cv=none; d=google.com; s=arc-20160816; b=rxRfbOtygpwSWbBDrMVkDtHAD9HA/+TkU3084byqyAfy5r20Kr1KE5DHopBBPeodkZ d2baZzL2paujN5lR3my44k9E+iQHcr8NLjTFQKK9+kWALp0xusW8aLwV5QlmgzW8MisT oLuC5xfJoZegFns5M8cayzm6SMY9VZOXuDYZNO0OQfslYxnXwybIx2S6tTbZ9nz8ZKDx QylbeEQk54X5mUFSQ6kIKNFnvjakIcBoUwxZhMd3Y5hndSDvAZlbkiWhi2axJQLNMVn9 esqDlRxg8SQbmhsuC2wI1jVYawwf3Q42EgvRrGZxisHKus23tHXYfyAxk7E+ui+7mtRa UqCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=zc0xH8itYv/4XoUiMkxXEZ2R9+uDkizmJaSXvpSeCIo=; b=ZVBHhlkqeUSY5lpFukIpScVLyvymELXN/GD9vF6LgmS5F/MYbnE7jUngKGcSh1ENn3 xZXzfwHHOk24CVh3Yo7+VTW9xpJwRjzeGTksi9UzHfoOSA9HLzPH9cXZqwqtsKdJy8w4 f9Kahq0JlZrPxFFxNc6iybZL4TlwPWKHPKOwPB96LC3dYSrpWOVcl6rmGCvWCOBItE5h yiLP9Y3dyK3/eNQRCEYoIbfEU/7JIsyD+kWsnxsT7cB62x/+eJHSKdL34VuPPaMB27bX edZhvFvkNY5GubjSLsow+2ayUIG3vghxxEGEVBE2C/iYQrv5g6a7ZX6uzJyJMBNjxKee wUyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=34yaGaMr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PfnEDuSk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8si8838937pgq.675.2022.02.10.02.34.48; Thu, 10 Feb 2022 02:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=34yaGaMr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=PfnEDuSk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238545AbiBJKD0 (ORCPT + 99 others); Thu, 10 Feb 2022 05:03:26 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:50886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237267AbiBJKDY (ORCPT ); Thu, 10 Feb 2022 05:03:24 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1A77C55; Thu, 10 Feb 2022 02:03:24 -0800 (PST) Date: Thu, 10 Feb 2022 10:03:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1644487401; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zc0xH8itYv/4XoUiMkxXEZ2R9+uDkizmJaSXvpSeCIo=; b=34yaGaMrytbAQWmX09fJ0plL77KI4TQlAjY5yjLq8u4ATrk1WcG1+bDQAmd/DbtFNuksS+ 7NPsKzihhbUGEPNavj1XVkuCfsU9vqPOYcNfO1nF21qjFOmSKPAJW3nbVps2yIOXOJXLfh i/uNllBsItEnilaNKXY22ByEtCNVCK5QKbMKhw/aTGj/sv1TlJeLg6maLszjJYm0JUDRO/ u6jqnZhMqywKMw6w8VPbrnh8elZkijrr6mkuZQzcXGkESfXve1cPWIyk/s16OMozMWffU2 9zpoCcnEMAvyCGlLV28JCkCn4PT3DpAvLj8AH17Lkt9i+DoiyKvR8cqZlVk07g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1644487401; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zc0xH8itYv/4XoUiMkxXEZ2R9+uDkizmJaSXvpSeCIo=; b=PfnEDuSk2T2tSP6sNd9i2Zf5HMW9EPkMMzspNxQDKepGJRXFuqDP4aMYI0tx2I6PQ4FdT4 JVlWG5BsUGT4tbAg== From: "tip-bot2 for Nick Desaulniers" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/urgent] x86/bug: Merge annotate_reachable() into _BUG_FLAGS() asm Cc: Nick Desaulniers , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220202205557.2260694-1-ndesaulniers@google.com> References: <20220202205557.2260694-1-ndesaulniers@google.com> MIME-Version: 1.0 Message-ID: <164448739969.16921.718126712933524460.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the objtool/urgent branch of tip: Commit-ID: bfb1a7c91fb7758273b4a8d735313d9cc388b502 Gitweb: https://git.kernel.org/tip/bfb1a7c91fb7758273b4a8d735313d9cc388b502 Author: Nick Desaulniers AuthorDate: Wed, 02 Feb 2022 12:55:53 -08:00 Committer: Josh Poimboeuf CommitterDate: Wed, 02 Feb 2022 14:41:04 -08:00 x86/bug: Merge annotate_reachable() into _BUG_FLAGS() asm In __WARN_FLAGS(), we had two asm statements (abbreviated): asm volatile("ud2"); asm volatile(".pushsection .discard.reachable"); These pair of statements are used to trigger an exception, but then help objtool understand that for warnings, control flow will be restored immediately afterwards. The problem is that volatile is not a compiler barrier. GCC explicitly documents this: > Note that the compiler can move even volatile asm instructions > relative to other code, including across jump instructions. Also, no clobbers are specified to prevent instructions from subsequent statements from being scheduled by compiler before the second asm statement. This can lead to instructions from subsequent statements being emitted by the compiler before the second asm statement. Providing a scheduling model such as via -march= options enables the compiler to better schedule instructions with known latencies to hide latencies from data hazards compared to inline asm statements in which latencies are not estimated. If an instruction gets scheduled by the compiler between the two asm statements, then objtool will think that it is not reachable, producing a warning. To prevent instructions from being scheduled in between the two asm statements, merge them. Also remove an unnecessary unreachable() asm annotation from BUG() in favor of __builtin_unreachable(). objtool is able to track that the ud2 from BUG() terminates control flow within the function. Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile Link: https://github.com/ClangBuiltLinux/linux/issues/1483 Signed-off-by: Nick Desaulniers Signed-off-by: Josh Poimboeuf Link: https://lore.kernel.org/r/20220202205557.2260694-1-ndesaulniers@google.com --- arch/x86/include/asm/bug.h | 20 +++++++++++--------- include/linux/compiler.h | 21 +++++---------------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h index 84b8753..bab883c 100644 --- a/arch/x86/include/asm/bug.h +++ b/arch/x86/include/asm/bug.h @@ -22,7 +22,7 @@ #ifdef CONFIG_DEBUG_BUGVERBOSE -#define _BUG_FLAGS(ins, flags) \ +#define _BUG_FLAGS(ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ @@ -31,7 +31,8 @@ do { \ "\t.word %c1" "\t# bug_entry::line\n" \ "\t.word %c2" "\t# bug_entry::flags\n" \ "\t.org 2b+%c3\n" \ - ".popsection" \ + ".popsection\n" \ + extra \ : : "i" (__FILE__), "i" (__LINE__), \ "i" (flags), \ "i" (sizeof(struct bug_entry))); \ @@ -39,14 +40,15 @@ do { \ #else /* !CONFIG_DEBUG_BUGVERBOSE */ -#define _BUG_FLAGS(ins, flags) \ +#define _BUG_FLAGS(ins, flags, extra) \ do { \ asm_inline volatile("1:\t" ins "\n" \ ".pushsection __bug_table,\"aw\"\n" \ "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ "\t.word %c0" "\t# bug_entry::flags\n" \ "\t.org 2b+%c1\n" \ - ".popsection" \ + ".popsection\n" \ + extra \ : : "i" (flags), \ "i" (sizeof(struct bug_entry))); \ } while (0) @@ -55,7 +57,7 @@ do { \ #else -#define _BUG_FLAGS(ins, flags) asm volatile(ins) +#define _BUG_FLAGS(ins, flags, extra) asm volatile(ins) #endif /* CONFIG_GENERIC_BUG */ @@ -63,8 +65,8 @@ do { \ #define BUG() \ do { \ instrumentation_begin(); \ - _BUG_FLAGS(ASM_UD2, 0); \ - unreachable(); \ + _BUG_FLAGS(ASM_UD2, 0, ""); \ + __builtin_unreachable(); \ } while (0) /* @@ -75,9 +77,9 @@ do { \ */ #define __WARN_FLAGS(flags) \ do { \ + __auto_type f = BUGFLAG_WARNING|(flags); \ instrumentation_begin(); \ - _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \ - annotate_reachable(); \ + _BUG_FLAGS(ASM_UD2, f, ASM_REACHABLE); \ instrumentation_end(); \ } while (0) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 429dceb..0f7fd20 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -117,14 +117,6 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, */ #define __stringify_label(n) #n -#define __annotate_reachable(c) ({ \ - asm volatile(__stringify_label(c) ":\n\t" \ - ".pushsection .discard.reachable\n\t" \ - ".long " __stringify_label(c) "b - .\n\t" \ - ".popsection\n\t" : : "i" (c)); \ -}) -#define annotate_reachable() __annotate_reachable(__COUNTER__) - #define __annotate_unreachable(c) ({ \ asm volatile(__stringify_label(c) ":\n\t" \ ".pushsection .discard.unreachable\n\t" \ @@ -133,24 +125,21 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, }) #define annotate_unreachable() __annotate_unreachable(__COUNTER__) -#define ASM_UNREACHABLE \ - "999:\n\t" \ - ".pushsection .discard.unreachable\n\t" \ - ".long 999b - .\n\t" \ +#define ASM_REACHABLE \ + "998:\n\t" \ + ".pushsection .discard.reachable\n\t" \ + ".long 998b - .\n\t" \ ".popsection\n\t" /* Annotate a C jump table to allow objtool to follow the code flow */ #define __annotate_jump_table __section(".rodata..c_jump_table") #else -#define annotate_reachable() #define annotate_unreachable() +# define ASM_REACHABLE #define __annotate_jump_table #endif -#ifndef ASM_UNREACHABLE -# define ASM_UNREACHABLE -#endif #ifndef unreachable # define unreachable() do { \ annotate_unreachable(); \