diff mbox series

[RFC] xen: Work around Clang-IAS macro expansion bug.

Message ID 20230217001914.762929-1-andrew.cooper3@citrix.com (mailing list archive)
State New, archived
Headers show
Series [RFC] xen: Work around Clang-IAS macro expansion bug. | expand

Commit Message

Andrew Cooper Feb. 17, 2023, 12:19 a.m. UTC
https://github.com/llvm/llvm-project/issues/60792

RFC.  I very much dislike this patch, but it does work for me.

Why the parameter name of foo?  Turns out I found a different Clang-IAS
bug/misfeature when trying to name the parameter uniq.

  In file included from arch/x86/asm-macros.c:3:
  ./arch/x86/include/asm/spec_ctrl_asm.h:139:5: error: \u used with no following hex digits; treating as '\' followed by identifier [-Werror,-Wunicode]
  .L\@\uniq\()fill_rsb_loop:
      ^

It appears you can't have any macro parameters beginning with a u.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>
---
 xen/arch/x86/include/asm/spec_ctrl.h     |  4 ++--
 xen/arch/x86/include/asm/spec_ctrl_asm.h | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

Comments

Andrew Cooper Feb. 17, 2023, 10:37 a.m. UTC | #1
On 17/02/2023 12:19 am, Andrew Cooper wrote:
> https://github.com/llvm/llvm-project/issues/60792
>
> RFC.  I very much dislike this patch, but it does work for me.
>
> Why the parameter name of foo?  Turns out I found a different Clang-IAS
> bug/misfeature when trying to name the parameter uniq.
>
>   In file included from arch/x86/asm-macros.c:3:
>   ./arch/x86/include/asm/spec_ctrl_asm.h:139:5: error: \u used with no following hex digits; treating as '\' followed by identifier [-Werror,-Wunicode]
>   .L\@\uniq\()fill_rsb_loop:
>       ^
>
> It appears you can't have any macro parameters beginning with a u.

It's worth saying that I can't repro this in more simple setups, so it
likely specific to some of the gymnastics we do in asm-macros.c

Also, I was hoping to try and sort out the macro such that it had

.macro ... uniq=\@

reducing the internal complexity, but I couldn't find any form of that
that GAS was happy with.  Suggestions welcome.

~Andrew
diff mbox series

Patch

diff --git a/xen/arch/x86/include/asm/spec_ctrl.h b/xen/arch/x86/include/asm/spec_ctrl.h
index 3cf8a7d304d4..cd727be7c689 100644
--- a/xen/arch/x86/include/asm/spec_ctrl.h
+++ b/xen/arch/x86/include/asm/spec_ctrl.h
@@ -83,7 +83,7 @@  static always_inline void spec_ctrl_new_guest_context(void)
     wrmsrl(MSR_PRED_CMD, PRED_CMD_IBPB);
 
     /* (ab)use alternative_input() to specify clobbers. */
-    alternative_input("", "DO_OVERWRITE_RSB", X86_BUG_IBPB_NO_RET,
+    alternative_input("", "DO_OVERWRITE_RSB foo=%=", X86_BUG_IBPB_NO_RET,
                       : "rax", "rcx");
 }
 
@@ -172,7 +172,7 @@  static always_inline void spec_ctrl_enter_idle(struct cpu_info *info)
      *
      * (ab)use alternative_input() to specify clobbers.
      */
-    alternative_input("", "DO_OVERWRITE_RSB", X86_FEATURE_SC_RSB_IDLE,
+    alternative_input("", "DO_OVERWRITE_RSB foo=%=", X86_FEATURE_SC_RSB_IDLE,
                       : "rax", "rcx");
 }
 
diff --git a/xen/arch/x86/include/asm/spec_ctrl_asm.h b/xen/arch/x86/include/asm/spec_ctrl_asm.h
index fab27ff5532b..06455c5663bb 100644
--- a/xen/arch/x86/include/asm/spec_ctrl_asm.h
+++ b/xen/arch/x86/include/asm/spec_ctrl_asm.h
@@ -117,7 +117,7 @@ 
 .L\@_done:
 .endm
 
-.macro DO_OVERWRITE_RSB tmp=rax
+.macro DO_OVERWRITE_RSB tmp=rax foo=
 /*
  * Requires nothing
  * Clobbers \tmp (%rax by default), %rcx
@@ -136,27 +136,27 @@ 
     mov $16, %ecx                   /* 16 iterations, two calls per loop */
     mov %rsp, %\tmp                 /* Store the current %rsp */
 
-.L\@_fill_rsb_loop:
+.L\@\foo\()fill_rsb_loop:
 
     .irp n, 1, 2                    /* Unrolled twice. */
-    call .L\@_insert_rsb_entry_\n   /* Create an RSB entry. */
+    call .L\@\foo\()insert_rsb_entry_\n   /* Create an RSB entry. */
     int3                            /* Halt rogue speculation. */
 
-.L\@_insert_rsb_entry_\n:
+.L\@\foo\()insert_rsb_entry_\n:
     .endr
 
     sub $1, %ecx
-    jnz .L\@_fill_rsb_loop
+    jnz .L\@\foo\()fill_rsb_loop
     mov %\tmp, %rsp                 /* Restore old %rsp */
 
 #ifdef CONFIG_XEN_SHSTK
     mov $1, %ecx
     rdsspd %ecx
     cmp $1, %ecx
-    je .L\@_shstk_done
+    je .L\@\foo\()shstk_done
     mov $64, %ecx                   /* 64 * 4 bytes, given incsspd */
     incsspd %ecx                    /* Restore old SSP */
-.L\@_shstk_done:
+.L\@\foo\()shstk_done:
 #endif
 .endm