stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Nick Desaulniers <ndesaulniers@google.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Sasha Levin <sashal@kernel.org>,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org,
	luc.vanoostenryck@gmail.com, adobriyan@gmail.com,
	linux-sparse@vger.kernel.org
Subject: [PATCH AUTOSEL 5.15 08/33] x86/bug: Merge annotate_reachable() into _BUG_FLAGS() asm
Date: Tue, 15 Feb 2022 10:28:06 -0500	[thread overview]
Message-ID: <20220215152831.580780-8-sashal@kernel.org> (raw)
In-Reply-To: <20220215152831.580780-1-sashal@kernel.org>

From: Nick Desaulniers <ndesaulniers@google.com>

[ Upstream commit bfb1a7c91fb7758273b4a8d735313d9cc388b502 ]

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 <ndesaulniers@google.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20220202205557.2260694-1-ndesaulniers@google.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 84b87538a15de..bab883c0b6fee 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 429dcebe2b992..0f7fd205ab7ea 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();		\
-- 
2.34.1


  parent reply	other threads:[~2022-02-15 15:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 15:27 [PATCH AUTOSEL 5.15 01/33] ARM: OMAP2+: hwmod: Add of_node_put() before break Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 02/33] ARM: OMAP2+: adjust the location of put_device() call in omapdss_init_of Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 03/33] phy: usb: Leave some clocks running during suspend Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 04/33] staging: vc04_services: Fix RCU dereference check Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 05/33] phy: phy-mtk-tphy: Fix duplicated argument in phy-mtk-tphy Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 06/33] usb: usb251xb: add boost-up property support Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 07/33] irqchip/sifive-plic: Add missing thead,c900-plic match string Sasha Levin
2022-02-15 15:28 ` Sasha Levin [this message]
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 09/33] netfilter: conntrack: don't refresh sctp entries in closed state Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 10/33] ksmbd: fix same UniqueId for dot and dotdot entries Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 11/33] ksmbd: don't align last entry offset in smb2 query directory Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 12/33] arm64: dts: meson-gx: add ATF BL32 reserved-memory region Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 13/33] arm64: dts: meson-g12: " Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 14/33] arm64: dts: meson-g12: drop BL32 region from SEI510/SEI610 Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 15/33] pidfd: fix test failure due to stack overflow on some arches Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 16/33] selftests: fixup build warnings in pidfd / clone3 tests Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 17/33] mm: io_uring: allow oom-killer from io_uring_setup Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 18/33] ACPI: PM: Revert "Only mark EC GPE for wakeup on Intel systems" Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 19/33] kconfig: let 'shell' return enough output for deep path names Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 20/33] scsi: lpfc: Remove NVMe support if kernel has NVME_FC disabled Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 21/33] scsi: lpfc: Reduce log messages seen after firmware download Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 22/33] ata: libata-core: Disable TRIM on M88V29 Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 23/33] soc: aspeed: lpc-ctrl: Block error printing on probe defer cases Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 24/33] xprtrdma: fix pointer derefs in error cases of rpcrdma_ep_create Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 25/33] drm/rockchip: dw_hdmi: Do not leave clock enabled in error case Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 26/33] tracing: Fix tp_printk option related with tp_printk_stop_on_boot Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 27/33] NFSD: Fix offset type in I/O trace points Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 28/33] display/amd: decrease message verbosity about watermarks table failure Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 29/33] drm/amd/display: Cap pflip irqs per max otg number Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 30/33] drm/amd/display: fix yellow carp wm clamping Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 31/33] net: usb: qmi_wwan: Add support for Dell DW5829e Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 32/33] net: macb: Align the dma and coherent dma masks Sasha Levin
2022-02-15 15:28 ` [PATCH AUTOSEL 5.15 33/33] kconfig: fix failing to generate auto.conf Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220215152831.580780-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=adobriyan@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=mingo@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).