All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/altcall: further refine clang workaround
@ 2024-07-25 10:56 Roger Pau Monne
  2024-07-25 13:18 ` Jan Beulich
  0 siblings, 1 reply; 14+ messages in thread
From: Roger Pau Monne @ 2024-07-25 10:56 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Jan Beulich, Andrew Cooper, Alejandro Vallejo

The current code in ALT_CALL_ARG() won't successfully workaround the clang
code-generation issue if the arg parameter has a size that's not a power of 2.
While there are no such sized parameters at the moment, improve the workaround
to also be effective when such sizes are used.

Instead of using a union with a long, add the necessary padding so that the
resulting struct always has the same size as a register, and let the compiler
zero-initialize the padding.

Reported-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/include/asm/alternative.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/include/asm/alternative.h b/xen/arch/x86/include/asm/alternative.h
index e63b45927643..c3e3a5e3f8a8 100644
--- a/xen/arch/x86/include/asm/alternative.h
+++ b/xen/arch/x86/include/asm/alternative.h
@@ -184,11 +184,11 @@ extern void alternative_branches(void);
  * https://github.com/llvm/llvm-project/issues/82598
  */
 #define ALT_CALL_ARG(arg, n)                                            \
-    register union {                                                    \
-        typeof(arg) e[sizeof(long) / sizeof(arg)];                      \
-        unsigned long r;                                                \
+    register struct {                                                   \
+        typeof(arg) e;                                                  \
+        char pad[sizeof(void *) - sizeof(arg)];                         \
     } a ## n ## _ asm ( ALT_CALL_arg ## n ) = {                         \
-        .e[0] = ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); })\
+        .e = ({ BUILD_BUG_ON(sizeof(arg) > sizeof(void *)); (arg); })   \
     }
 #else
 #define ALT_CALL_ARG(arg, n) \
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-07-29  8:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-25 10:56 [PATCH] x86/altcall: further refine clang workaround Roger Pau Monne
2024-07-25 13:18 ` Jan Beulich
2024-07-25 14:54   ` Roger Pau Monné
2024-07-25 15:00     ` Jan Beulich
2024-07-26  7:31       ` Roger Pau Monné
2024-07-26  7:36         ` Jan Beulich
2024-07-26  7:52           ` Roger Pau Monné
2024-07-26  8:05             ` Jan Beulich
2024-07-26 14:17               ` Alejandro Vallejo
2024-07-26 14:25                 ` Alejandro Vallejo
2024-07-26 15:18                   ` Roger Pau Monné
2024-07-26 16:25                     ` Alejandro Vallejo
2024-07-26 16:38                       ` Alejandro Vallejo
2024-07-29  8:14                         ` Roger Pau Monné

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.