From: Eric Dumazet <edumazet@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Uros Bizjak <ubizjak@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
x86@kernel.org, "H . Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Eric Dumazet <eric.dumazet@gmail.com>,
Eric Dumazet <edumazet@google.com>
Subject: [PATCH 1/2] clang: work around asm output constraint problems
Date: Fri, 19 Dec 2025 11:20:06 +0000 [thread overview]
Message-ID: <20251219112007.2827302-2-edumazet@google.com> (raw)
In-Reply-To: <20251219112007.2827302-1-edumazet@google.com>
Work around clang problems with "=rm" asm constraint.
clang seems to always chose the memory output, while it is almost
always the worst choice.
Add ASM_OUTPUT_RM so that we can replace "=rm" constraint
where it maters for clang, while not penalizing gcc.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Suggested-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
---
include/linux/compiler-clang.h | 7 +++++++
include/linux/compiler_types.h | 6 +++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index 107ce05bd16eb4a2ecb0f8cbf5c9efeab1845a1c..a82db8ab2812b9aa8851bf51daed3f81d2a41979 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -146,6 +146,13 @@
#define ASM_INPUT_G "ir"
#define ASM_INPUT_RM "r"
+/*
+ * clang has non optimal behavior with "=rm" constraints for asm outputs.
+ * It favors memory operand, forcing additional logic in tail functions
+ * when CONFIG_STACKPROTECTOR_STRONG=y.
+ */
+#define ASM_OUTPUT_RM "=r"
+
/*
* Declare compiler support for __typeof_unqual__() operator.
*
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 1280693766b9dd844ec7ca83053381799be12456..b66aa58dacd595546b17582df03a762dd23cb15c 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -548,13 +548,17 @@ struct ftrace_likely_data {
/*
* Clang has trouble with constraints with multiple
- * alternative behaviors (mainly "g" and "rm").
+ * alternative behaviors ("g" , "rm" and "=rm").
*/
#ifndef ASM_INPUT_G
#define ASM_INPUT_G "g"
#define ASM_INPUT_RM "rm"
#endif
+#ifndef ASM_OUTPUT_RM
+ #define ASM_OUTPUT_RM "=rm"
+#endif
+
#ifdef CONFIG_CC_HAS_ASM_INLINE
#define asm_inline asm __inline
#else
--
2.52.0.322.g1dd061c0dc-goog
next prev parent reply other threads:[~2025-12-19 11:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-19 11:20 [PATCH 0/2] x86: speedup local_irq_save() for clang Eric Dumazet
2025-12-19 11:20 ` Eric Dumazet [this message]
2025-12-20 22:32 ` [PATCH 1/2] clang: work around asm output constraint problems Linus Torvalds
2025-12-21 3:46 ` Eric Dumazet
2025-12-19 11:20 ` [PATCH 2/2] x86/irqflags: Use ASM_OUTPUT_RM in native_save_fl() Eric Dumazet
2025-12-21 21:39 ` H. Peter Anvin
2025-12-21 21:47 ` Eric Dumazet
2025-12-21 23:20 ` Linus Torvalds
2025-12-21 23:44 ` H. Peter Anvin
2025-12-22 1:38 ` Linus Torvalds
2025-12-22 4:25 ` H. Peter Anvin
2025-12-22 16:51 ` Andrew Cooper
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=20251219112007.2827302-2-edumazet@google.com \
--to=edumazet@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=eric.dumazet@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=ubizjak@gmail.com \
--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
all inboxes | Powered by JetHome®