2024-06-12 05:03:15

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH] x86/kconfig: add as-instr64 macro to properly evaluate AS_WRUSS

Some instructions are only available on the 64-bit architecture.

Bi-arch compilers that default to -m32 need the explicit -m64 option
to evaluate them properly.

Fixes: 18e66b695e78 ("x86/shstk: Add Kconfig option for shadow stack")
Reported-by: Dmitry Safonov <[email protected]>
Closes: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Masahiro Yamada <[email protected]>
---

arch/x86/Kconfig.assembler | 2 +-
scripts/Kconfig.include | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
index 59aedf32c4ea..6d20a6ce0507 100644
--- a/arch/x86/Kconfig.assembler
+++ b/arch/x86/Kconfig.assembler
@@ -36,6 +36,6 @@ config AS_VPCLMULQDQ
Supported by binutils >= 2.30 and LLVM integrated assembler

config AS_WRUSS
- def_bool $(as-instr,wrussq %rax$(comma)(%rbx))
+ def_bool $(as-instr64,wrussq %rax$(comma)(%rbx))
help
Supported by binutils >= 2.31 and LLVM integrated assembler
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index 3ee8ecfb8c04..3500a3d62f0d 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -33,7 +33,8 @@ ld-option = $(success,$(LD) -v $(1))

# $(as-instr,<instr>)
# Return y if the assembler supports <instr>, n otherwise
-as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
+as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) $(2) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
+as-instr64 = $(as-instr,$(1),$(m64-flag))

# check if $(CC) and $(LD) exist
$(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
--
2.43.0



2024-06-12 09:20:01

by Dmitry Safonov

[permalink] [raw]
Subject: Re: [PATCH] x86/kconfig: add as-instr64 macro to properly evaluate AS_WRUSS

On Wed, 12 Jun 2024 at 06:03, Masahiro Yamada <[email protected]> wrote:
>
> Some instructions are only available on the 64-bit architecture.
>
> Bi-arch compilers that default to -m32 need the explicit -m64 option
> to evaluate them properly.
>
> Fixes: 18e66b695e78 ("x86/shstk: Add Kconfig option for shadow stack")
> Reported-by: Dmitry Safonov <[email protected]>
> Closes: https://lore.kernel.org/all/[email protected]/
> Signed-off-by: Masahiro Yamada <[email protected]>

Thank you Masahiro, this works as well!
I guess I went on too generic path without an actual requirement for that.

Tested-by: Dmitry Safonov <[email protected]>

> ---
>
> arch/x86/Kconfig.assembler | 2 +-
> scripts/Kconfig.include | 3 ++-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
> index 59aedf32c4ea..6d20a6ce0507 100644
> --- a/arch/x86/Kconfig.assembler
> +++ b/arch/x86/Kconfig.assembler
> @@ -36,6 +36,6 @@ config AS_VPCLMULQDQ
> Supported by binutils >= 2.30 and LLVM integrated assembler
>
> config AS_WRUSS
> - def_bool $(as-instr,wrussq %rax$(comma)(%rbx))
> + def_bool $(as-instr64,wrussq %rax$(comma)(%rbx))
> help
> Supported by binutils >= 2.31 and LLVM integrated assembler
> diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
> index 3ee8ecfb8c04..3500a3d62f0d 100644
> --- a/scripts/Kconfig.include
> +++ b/scripts/Kconfig.include
> @@ -33,7 +33,8 @@ ld-option = $(success,$(LD) -v $(1))
>
> # $(as-instr,<instr>)
> # Return y if the assembler supports <instr>, n otherwise
> -as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
> +as-instr = $(success,printf "%b\n" "$(1)" | $(CC) $(CLANG_FLAGS) $(2) -Wa$(comma)--fatal-warnings -c -x assembler-with-cpp -o /dev/null -)
> +as-instr64 = $(as-instr,$(1),$(m64-flag))
>
> # check if $(CC) and $(LD) exist
> $(error-if,$(failure,command -v $(CC)),C compiler '$(CC)' not found)
> --
> 2.43.0
>
--
Dmitry