[PATCH 11/16] x86: probe assembler capabilities via kconfig instead of makefile

0 views
Skip to first unread message

Masahiro Yamada

unread,
Mar 24, 2020, 4:49:37 AM3/24/20
to linux-...@vger.kernel.org, David S . Miller, Linus Torvalds, Kees Cook, clang-bu...@googlegroups.com, Herbert Xu, linux-...@vger.kernel.org, Ingo Molnar, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, x...@kernel.org, linux-...@vger.kernel.org, Jason A. Donenfeld, Masahiro Yamada
From: "Jason A. Donenfeld" <Ja...@zx2c4.com>

Doing this probing inside of the Makefiles means we have a maze of
ifdefs inside the source code and child Makefiles that need to make
proper decisions on this too. Instead, we do it at Kconfig time, like
many other compiler and assembler options, which allows us to set up the
dependencies normally for full compilation units. In the process, the
ADX test changes to use %eax instead of %r10 so that it's valid in both
32-bit and 64-bit mode.

Signed-off-by: Jason A. Donenfeld <Ja...@zx2c4.com>
Signed-off-by: Masahiro Yamada <masa...@kernel.org>
---

arch/x86/Kconfig | 2 ++
arch/x86/Kconfig.assembler | 22 ++++++++++++++++++++++
arch/x86/Makefile | 15 ---------------
3 files changed, 24 insertions(+), 15 deletions(-)
create mode 100644 arch/x86/Kconfig.assembler

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index beea77046f9b..707673227837 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2935,3 +2935,5 @@ config HAVE_ATOMIC_IOMAP
source "drivers/firmware/Kconfig"

source "arch/x86/kvm/Kconfig"
+
+source "arch/x86/Kconfig.assembler"
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
new file mode 100644
index 000000000000..46868ec7b723
--- /dev/null
+++ b/arch/x86/Kconfig.assembler
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Jason A. Donenfeld <Ja...@zx2c4.com>. All Rights Reserved.
+
+# binutils >= 2.22
+config AS_AVX2
+ def_bool $(as-instr,vpbroadcastb %xmm0$(comma)%ymm1)
+
+# binutils >= 2.25
+config AS_AVX512
+ def_bool $(as-instr,vpmovm2b %k1$(comma)%zmm5)
+
+# binutils >= 2.24
+config AS_SHA1_NI
+ def_bool $(as-instr,sha1msg1 %xmm0$(comma)%xmm1)
+
+# binutils >= 2.24
+config AS_SHA256_NI
+ def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1)
+
+# binutils >= 2.23
+config AS_ADX
+ def_bool $(as-instr,adox %eax$(comma)%eax)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 4c57cb3018fb..b65ec63c7db7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -177,21 +177,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
endif

-# does binutils support specific instructions?
-# binutils >= 2.22
-avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
-# binutils >= 2.25
-avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
-# binutils >= 2.24
-sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
-# binutils >= 2.24
-sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
-# binutils >= 2.23
-adx_instr := $(call as-instr,adox %r10$(comma)%r10,-DCONFIG_AS_ADX=1)
-
-KBUILD_AFLAGS += $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
-KBUILD_CFLAGS += $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr) $(adx_instr)
-
KBUILD_LDFLAGS := -m elf_$(UTS_MACHINE)

#
--
2.17.1

Nick Desaulniers

unread,
Mar 24, 2020, 1:01:54 PM3/24/20
to Masahiro Yamada, LKML, David S . Miller, Linus Torvalds, Kees Cook, clang-built-linux, Herbert Xu, open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Ingo Molnar, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Linux Kbuild mailing list, Jason A. Donenfeld
Can 11 just be rebased with 8 dropped?
> --
> You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-li...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200324084821.29944-12-masahiroy%40kernel.org.



--
Thanks,
~Nick Desaulniers

Jason A. Donenfeld

unread,
Mar 24, 2020, 1:17:18 PM3/24/20
to Nick Desaulniers, Masahiro Yamada, LKML, David S . Miller, Linus Torvalds, Kees Cook, clang-built-linux, Herbert Xu, open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Ingo Molnar, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Linux Kbuild mailing list
On Tue, Mar 24, 2020 at 11:01 AM Nick Desaulniers
<ndesau...@google.com> wrote:
>
> Can 11 just be rebased with 8 dropped?

8 adds comments to one place. 11 moves them to another place, while
doing other things.

Your desire is to skip the first step? I guess there's no problem with
this, but I'm curious to learn why.

Masahiro Yamada

unread,
Mar 24, 2020, 1:22:25 PM3/24/20
to Jason A. Donenfeld, Nick Desaulniers, LKML, David S . Miller, Linus Torvalds, Kees Cook, clang-built-linux, Herbert Xu, open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Ingo Molnar, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Linux Kbuild mailing list
If desired, I will swap the order of 8 and 11.


--
Best Regards
Masahiro Yamada

Nick Desaulniers

unread,
Mar 24, 2020, 1:33:45 PM3/24/20
to Jason A. Donenfeld, Masahiro Yamada, LKML, David S . Miller, Linus Torvalds, Kees Cook, clang-built-linux, Herbert Xu, open list:HARDWARE RANDOM NUMBER GENERATOR CORE, Ingo Molnar, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Linux Kbuild mailing list
Before this series, there's no comments. After, the comments are in
arch/x86/Kconfig.assembler. Don't waste reviewers time by having other
patches in the set that move them around for fun. Just add them to the
final destination.

--
Thanks,
~Nick Desaulniers

Masahiro Yamada

unread,
Mar 26, 2020, 4:02:21 AM3/26/20
to linux-...@vger.kernel.org, Thomas Gleixner, Nick Desaulniers, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, x...@kernel.org, Jason A . Donenfeld, clang-bu...@googlegroups.com, Masahiro Yamada, Ingo Molnar, linux-...@vger.kernel.org
From: "Jason A. Donenfeld" <Ja...@zx2c4.com>

Doing this probing inside of the Makefiles means we have a maze of
ifdefs inside the source code and child Makefiles that need to make
proper decisions on this too. Instead, we do it at Kconfig time, like
many other compiler and assembler options, which allows us to set up the
dependencies normally for full compilation units. In the process, the
ADX test changes to use %eax instead of %r10 so that it's valid in both
32-bit and 64-bit mode.

Signed-off-by: Jason A. Donenfeld <Ja...@zx2c4.com>
Signed-off-by: Masahiro Yamada <masa...@kernel.org>
---

Changes in v2: None

arch/x86/Kconfig | 2 ++
arch/x86/Kconfig.assembler | 17 +++++++++++++++++
arch/x86/Makefile | 10 ----------
3 files changed, 19 insertions(+), 10 deletions(-)
create mode 100644 arch/x86/Kconfig.assembler

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index beea77046f9b..707673227837 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -2935,3 +2935,5 @@ config HAVE_ATOMIC_IOMAP
source "drivers/firmware/Kconfig"

source "arch/x86/kvm/Kconfig"
+
+source "arch/x86/Kconfig.assembler"
diff --git a/arch/x86/Kconfig.assembler b/arch/x86/Kconfig.assembler
new file mode 100644
index 000000000000..91230bf11a14
--- /dev/null
+++ b/arch/x86/Kconfig.assembler
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Jason A. Donenfeld <Ja...@zx2c4.com>. All Rights Reserved.
+
+config AS_AVX2
+ def_bool $(as-instr,vpbroadcastb %xmm0$(comma)%ymm1)
+
+config AS_AVX512
+ def_bool $(as-instr,vpmovm2b %k1$(comma)%zmm5)
+
+config AS_SHA1_NI
+ def_bool $(as-instr,sha1msg1 %xmm0$(comma)%xmm1)
+
+config AS_SHA256_NI
+ def_bool $(as-instr,sha256msg1 %xmm0$(comma)%xmm1)
+
+config AS_ADX
+ def_bool $(as-instr,adox %eax$(comma)%eax)
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index f32ef7b8d5ca..b65ec63c7db7 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -177,16 +177,6 @@ ifeq ($(ACCUMULATE_OUTGOING_ARGS), 1)
KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args,)
endif

-# does binutils support specific instructions?
-avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
-avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
-sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
-sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)

Nick Desaulniers

unread,
Mar 26, 2020, 1:49:49 PM3/26/20
to Masahiro Yamada, Linux Kbuild mailing list, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), Jason A . Donenfeld, clang-built-linux, Ingo Molnar, LKML
On Thu, Mar 26, 2020 at 1:02 AM Masahiro Yamada <masa...@kernel.org> wrote:
>
> From: "Jason A. Donenfeld" <Ja...@zx2c4.com>
>
> Doing this probing inside of the Makefiles means we have a maze of
> ifdefs inside the source code and child Makefiles that need to make
> proper decisions on this too. Instead, we do it at Kconfig time, like
> many other compiler and assembler options, which allows us to set up the
> dependencies normally for full compilation units. In the process, the
> ADX test changes to use %eax instead of %r10 so that it's valid in both
> 32-bit and 64-bit mode.

Does KConfig generate -D<foo> flags for KBUILD_CFLAGS and KBUILD_AFLAGS?
Looks like lib/raid6/test/Makefile also generates some of these?
--
Thanks,
~Nick Desaulniers

Jason A. Donenfeld

unread,
Mar 26, 2020, 3:54:00 PM3/26/20
to Nick Desaulniers, Masahiro Yamada, Linux Kbuild mailing list, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), clang-built-linux, Ingo Molnar, LKML
On Thu, Mar 26, 2020 at 11:49 AM Nick Desaulniers
<ndesau...@google.com> wrote:
>
> On Thu, Mar 26, 2020 at 1:02 AM Masahiro Yamada <masa...@kernel.org> wrote:
> >
> > From: "Jason A. Donenfeld" <Ja...@zx2c4.com>
> >
> > Doing this probing inside of the Makefiles means we have a maze of
> > ifdefs inside the source code and child Makefiles that need to make
> > proper decisions on this too. Instead, we do it at Kconfig time, like
> > many other compiler and assembler options, which allows us to set up the
> > dependencies normally for full compilation units. In the process, the
> > ADX test changes to use %eax instead of %r10 so that it's valid in both
> > 32-bit and 64-bit mode.
>
> Does KConfig generate -D<foo> flags for KBUILD_CFLAGS and KBUILD_AFLAGS?

kconfig sticks everything it's got into include/generated/autoconf.h.
That's how you're able to use all those #ifdef CONFIG_* macros
already. This change moves things from a command line -D to the
autoconf.h file.

> Looks like lib/raid6/test/Makefile also generates some of these?

raid6 has its own crazy thing going on. The test directory compiles
that code for use in userspace. You might argue that its whole
situation is non-standard and weird and should be reworked
differently, but that seems like fodder for a different patchset on
the linux-raid list.

Nick Desaulniers

unread,
Mar 26, 2020, 4:00:50 PM3/26/20
to Jason A. Donenfeld, Masahiro Yamada, Linux Kbuild mailing list, Thomas Gleixner, Borislav Petkov, Peter Zijlstra, H . Peter Anvin, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT), clang-built-linux, Ingo Molnar, LKML
On Thu, Mar 26, 2020 at 12:54 PM Jason A. Donenfeld <Ja...@zx2c4.com> wrote:
>
> On Thu, Mar 26, 2020 at 11:49 AM Nick Desaulniers
> <ndesau...@google.com> wrote:
> >
> > On Thu, Mar 26, 2020 at 1:02 AM Masahiro Yamada <masa...@kernel.org> wrote:
> > >
> > > From: "Jason A. Donenfeld" <Ja...@zx2c4.com>
> > >
> > > Doing this probing inside of the Makefiles means we have a maze of
> > > ifdefs inside the source code and child Makefiles that need to make
> > > proper decisions on this too. Instead, we do it at Kconfig time, like
> > > many other compiler and assembler options, which allows us to set up the
> > > dependencies normally for full compilation units. In the process, the
> > > ADX test changes to use %eax instead of %r10 so that it's valid in both
> > > 32-bit and 64-bit mode.
> >
> > Does KConfig generate -D<foo> flags for KBUILD_CFLAGS and KBUILD_AFLAGS?
>
> kconfig sticks everything it's got into include/generated/autoconf.h.
> That's how you're able to use all those #ifdef CONFIG_* macros
> already. This change moves things from a command line -D to the
> autoconf.h file.

Cool, I wondered how that was wired up. Though seeing the word
"autoconf" brings on PTSD for me.
Patch LGTM.
Reviewed-by: Nick Desaulniers <ndesau...@google.com>

>
> > Looks like lib/raid6/test/Makefile also generates some of these?
>
> raid6 has its own crazy thing going on. The test directory compiles
> that code for use in userspace. You might argue that its whole
> situation is non-standard and weird and should be reworked
> differently, but that seems like fodder for a different patchset on
> the linux-raid list.



--
Thanks,
~Nick Desaulniers
Reply all
Reply to author
Forward
0 new messages