linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] arm64: Delete the space separator in __emit_inst
@ 2020-04-14 16:32 Fangrui Song
  2020-04-15 12:07 ` Catalin Marinas
  0 siblings, 1 reply; 2+ messages in thread
From: Fangrui Song @ 2020-04-14 16:32 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: Catalin Marinas, Will Deacon, Mark Rutland, Nick Desaulniers,
	clang-built-linux, Ilie Halip, Jian Cai, Fangrui Song

In assembly, many instances of __emit_inst(x) expand to a directive. In
a few places __emit_inst(x) is used as an assembler macro argument. For
example, in arch/arm64/kvm/hyp/entry.S

  ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN)

expands to the following by the C preprocessor:

  alternative_insn nop, .inst (0xd500401f | ((0) << 16 | (4) << 5) | ((!!1) << 8)), 4, 1

Both comma and space are separators, with an exception that content
inside a pair of parentheses/quotes is not split, so the clang
integrated assembler splits the arguments to:

   nop, .inst, (0xd500401f | ((0) << 16 | (4) << 5) | ((!!1) << 8)), 4, 1

GNU as preprocesses the input with do_scrub_chars(). Its arm64 backend
(along with many other non-x86 backends) sees:

  alternative_insn nop,.inst(0xd500401f|((0)<<16|(4)<<5)|((!!1)<<8)),4,1
  # .inst(...) is parsed as one argument

while its x86 backend sees:

  alternative_insn nop,.inst (0xd500401f|((0)<<16|(4)<<5)|((!!1)<<8)),4,1
  # The extra space before '(' makes the whole .inst (...) parsed as two arguments

The non-x86 backend's behavior is considered unintentional
(https://sourceware.org/bugzilla/show_bug.cgi?id=25750).
So drop the space separator inside `.inst (...)` to make the clang
integrated assembler work.

Suggested-by: Ilie Halip <ilie.halip@gmail.com>
Signed-off-by: Fangrui Song <maskray@google.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Link: https://github.com/ClangBuiltLinux/linux/issues/939
---
 arch/arm64/include/asm/sysreg.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h
index ebc622432831..c4ac0ac25a00 100644
--- a/arch/arm64/include/asm/sysreg.h
+++ b/arch/arm64/include/asm/sysreg.h
@@ -49,7 +49,9 @@
 #ifndef CONFIG_BROKEN_GAS_INST
 
 #ifdef __ASSEMBLY__
-#define __emit_inst(x)			.inst (x)
+// The space separator is omitted so that __emit_inst(x) can be parsed as
+// either an assembler directive or an assembler macro argument.
+#define __emit_inst(x)			.inst(x)
 #else
 #define __emit_inst(x)			".inst " __stringify((x)) "\n\t"
 #endif
-- 
2.26.0.110.g2183baf09c-goog


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

* Re: [PATCH v2] arm64: Delete the space separator in __emit_inst
  2020-04-14 16:32 [PATCH v2] arm64: Delete the space separator in __emit_inst Fangrui Song
@ 2020-04-15 12:07 ` Catalin Marinas
  0 siblings, 0 replies; 2+ messages in thread
From: Catalin Marinas @ 2020-04-15 12:07 UTC (permalink / raw)
  To: Fangrui Song
  Cc: linux-arm-kernel, linux-kernel, Will Deacon, Mark Rutland,
	Nick Desaulniers, clang-built-linux, Ilie Halip, Jian Cai

On Tue, Apr 14, 2020 at 09:32:55AM -0700, Fangrui Song wrote:
> In assembly, many instances of __emit_inst(x) expand to a directive. In
> a few places __emit_inst(x) is used as an assembler macro argument. For
> example, in arch/arm64/kvm/hyp/entry.S
> 
>   ALTERNATIVE(nop, SET_PSTATE_PAN(1), ARM64_HAS_PAN, CONFIG_ARM64_PAN)
> 
> expands to the following by the C preprocessor:
> 
>   alternative_insn nop, .inst (0xd500401f | ((0) << 16 | (4) << 5) | ((!!1) << 8)), 4, 1
> 
> Both comma and space are separators, with an exception that content
> inside a pair of parentheses/quotes is not split, so the clang
> integrated assembler splits the arguments to:
> 
>    nop, .inst, (0xd500401f | ((0) << 16 | (4) << 5) | ((!!1) << 8)), 4, 1
> 
> GNU as preprocesses the input with do_scrub_chars(). Its arm64 backend
> (along with many other non-x86 backends) sees:
> 
>   alternative_insn nop,.inst(0xd500401f|((0)<<16|(4)<<5)|((!!1)<<8)),4,1
>   # .inst(...) is parsed as one argument
> 
> while its x86 backend sees:
> 
>   alternative_insn nop,.inst (0xd500401f|((0)<<16|(4)<<5)|((!!1)<<8)),4,1
>   # The extra space before '(' makes the whole .inst (...) parsed as two arguments
> 
> The non-x86 backend's behavior is considered unintentional
> (https://sourceware.org/bugzilla/show_bug.cgi?id=25750).
> So drop the space separator inside `.inst (...)` to make the clang
> integrated assembler work.
> 
> Suggested-by: Ilie Halip <ilie.halip@gmail.com>
> Signed-off-by: Fangrui Song <maskray@google.com>
> Reviewed-by: Mark Rutland <mark.rutland@arm.com>
> Link: https://github.com/ClangBuiltLinux/linux/issues/939

Queued for 5.7. Thanks.

-- 
Catalin

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

end of thread, other threads:[~2020-04-15 12:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14 16:32 [PATCH v2] arm64: Delete the space separator in __emit_inst Fangrui Song
2020-04-15 12:07 ` Catalin Marinas

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).