Re: [PATCH] Kconfig: Explicitly disable asm goto w/ outputs on gcc-11 (and earlier)

From: Linus Torvalds
Date: Wed Feb 14 2024 - 13:44:21 EST


On Sun, 11 Feb 2024 at 03:12, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> So, I'd suggest at least limit the workaround to known-bad compilers.

Based on the current state of

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921

I would suggest this attached kernel patch, which makes the manual
"volatile" the default case (since it should make no difference except
for the known gcc issue), and limits the extra empty asm serialization
to gcc versions older than 12.1.0.

But Jakub is clearly currently trying to figure out exactly what was
going wrong, so things may change. Maybe the commit he bisected to
happened to just accidentally hide the real issue.

Linus
include/linux/compiler-gcc.h | 12 +++---------
include/linux/compiler_types.h | 11 ++++++++++-
2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index c1a963be7d28..d181d2703bba 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -67,21 +67,15 @@
/*
* GCC 'asm goto' with outputs miscompiles certain code sequences:
*
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110420
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110422
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921
*
* Work it around via the same compiler barrier quirk that we used
* to use for the old 'asm goto' workaround.
- *
- * Also, always mark such 'asm goto' statements as volatile: all
- * asm goto statements are supposed to be volatile as per the
- * documentation, but some versions of gcc didn't actually do
- * that for asms with outputs:
- *
- * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98619
*/
+#if GCC_VERSION < 120100
#define asm_goto_output(x...) \
do { asm volatile goto(x); asm (""); } while (0)
+#endif

#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP)
#define __HAVE_BUILTIN_BSWAP32__
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 663d8791c871..3bb5a9d16eaa 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -362,8 +362,17 @@ struct ftrace_likely_data {
#define __member_size(p) __builtin_object_size(p, 1)
#endif

+/*
+ * "asm goto" is documented to always be volatile, but some versions
+ * of gcc don't actually do that:
+ *
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103979
+ *
+ * So we'll just do it manually unless we have other more extensive
+ * workarounds.
+ */
#ifndef asm_goto_output
-#define asm_goto_output(x...) asm goto(x)
+#define asm_goto_output(x...) asm volatile goto(x)
#endif

#ifdef CONFIG_CC_HAS_ASM_INLINE