[no subject]

2020-06-11 Thread ndesaulniers

Date: Thu, 11 Jun 2020 15:38:38 -0700
From: Nick Desaulniers 
To: Michael Ellerman ,
christophe.le...@c-s.fr, seg...@kernel.crashing.org
Cc: Christophe Leroy ,
Benjamin Herrenschmidt ,
Paul Mackerras , npig...@gmail.com,
seg...@kernel.crashing.org, linuxppc-...@lists.ozlabs.org,
linux-kernel@vger.kernel.org, clang-built-li...@googlegroups.com
Subject: Re: [PATCH v4 1/2] powerpc/uaccess: Implement unsafe_put_user()
 using 'asm goto'
Message-ID: <20200611223838.ga60...@google.com>
References:  
<23e680624680a9a5405f4b88740d2596d4b17c26.1587143308.git.christophe.le...@c-s.fr>

 <49ybky13szz9...@ozlabs.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <49ybky13szz9...@ozlabs.org>

On Fri, May 29, 2020 at 02:24:16PM +1000, Michael Ellerman wrote:

On Fri, 2020-04-17 at 17:08:51 UTC, Christophe Leroy wrote:
> unsafe_put_user() is designed to take benefit of 'asm goto'.
>
> Instead of using the standard __put_user() approach and branch
> based on the returned error, use 'asm goto' and make the
> exception code branch directly to the error label. There is
> no code anymore in the fixup section.
>
> This change significantly simplifies functions using
> unsafe_put_user()
...
>
> Signed-off-by: Christophe Leroy 
> Reviewed-by: Segher Boessenkool 



Applied to powerpc topic/uaccess-ppc, thanks.



https://git.kernel.org/powerpc/c/334710b1496af8a0960e70121f850e209c20958f



cheers


Hello!  It seems this patch broke our ppc32 builds, and we had to
disable them [0]. :(

From what I can tell, though Michael mentioned this was merged on May
29, but our CI of -next was green for ppc32 until June 4, then mainline
went red June 6.  So this patch only got 2 days of soak time before the
merge window opened.

A general issue with the -next workflow seems to be that patches get
different amounts of soak time.  For higher risk patches like this one,
can I please ask that they be help back a release if close to the merge
window?

Segher, Cristophe, I suspect Clang is missing support for the %L and %U
output templates [1]. I've implemented support for some of these before
in Clang via the documentation at [2], but these seem to be machine
specific? Can you please point me to documentation/unit tests/source for
these so that I can figure out what they should be doing, and look into
implementing them in Clang?

(Apologies for the tone off this email; I had typed up a nice fuller
report with links, but it seemed that mutt wrote out an empty postponed
file, and I kind of just want to put my laptop in the garbage right now.
I suspect our internal SMTP tool will also mess up some headers, but
lets see (Also, too lazy+angry right now to solve).)

[0] https://github.com/ClangBuiltLinux/continuous-integration/pull/279
[1] https://bugs.llvm.org/show_bug.cgi?id=46186
[2]  
https://gcc.gnu.org/onlinedocs/gccint/Output-Template.html#Output-Template


[PATCH] lib/raid6: use vdupq_n_u8 to avoid endianness warnings

2019-02-25 Thread ndesaulniers
Clang warns: vector initializers are not compatible with NEON intrinsics
in big endian mode [-Wnonportable-vector-initialization]

While this is usually the case, it's not an issue for this case since
we're initializing the uint8x16_t (16x uint8_t's) with the same value.

Instead, use vdupq_n_u8 which both compilers lower into a single movi
instruction: https://godbolt.org/z/vBrgzt

This avoids the static storage for a constant value.

Link: https://github.com/ClangBuiltLinux/linux/issues/214
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
 lib/raid6/neon.uc| 5 ++---
 lib/raid6/recov_neon_inner.c | 7 ++-
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/lib/raid6/neon.uc b/lib/raid6/neon.uc
index d5242f544551..b7c68030da4f 100644
--- a/lib/raid6/neon.uc
+++ b/lib/raid6/neon.uc
@@ -28,7 +28,6 @@
 
 typedef uint8x16_t unative_t;
 
-#define NBYTES(x) ((unative_t){x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x})
 #define NSIZE  sizeof(unative_t)
 
 /*
@@ -61,7 +60,7 @@ void raid6_neon$#_gen_syndrome_real(int disks, unsigned long 
bytes, void **ptrs)
int d, z, z0;
 
register unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
-   const unative_t x1d = NBYTES(0x1d);
+   const unative_t x1d = vdupq_n_u8(0x1d);
 
z0 = disks - 3; /* Highest data disk */
p = dptr[z0+1]; /* XOR parity */
@@ -92,7 +91,7 @@ void raid6_neon$#_xor_syndrome_real(int disks, int start, int 
stop,
int d, z, z0;
 
register unative_t wd$$, wq$$, wp$$, w1$$, w2$$;
-   const unative_t x1d = NBYTES(0x1d);
+   const unative_t x1d = vdupq_n_u8(0x1d);
 
z0 = stop;  /* P/Q right side optimization */
p = dptr[disks-2];  /* XOR parity */
diff --git a/lib/raid6/recov_neon_inner.c b/lib/raid6/recov_neon_inner.c
index 8cd20c9f834a..7d00c31a6547 100644
--- a/lib/raid6/recov_neon_inner.c
+++ b/lib/raid6/recov_neon_inner.c
@@ -10,11 +10,6 @@
 
 #include 
 
-static const uint8x16_t x0f = {
-   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
-   0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
-};
-
 #ifdef CONFIG_ARM
 /*
  * AArch32 does not provide this intrinsic natively because it does not
@@ -41,6 +36,7 @@ void __raid6_2data_recov_neon(int bytes, uint8_t *p, uint8_t 
*q, uint8_t *dp,
uint8x16_t pm1 = vld1q_u8(pbmul + 16);
uint8x16_t qm0 = vld1q_u8(qmul);
uint8x16_t qm1 = vld1q_u8(qmul + 16);
+   uint8x16_t x0f = vdupq_n_u8(0x0f);
 
/*
 * while ( bytes-- ) {
@@ -87,6 +83,7 @@ void __raid6_datap_recov_neon(int bytes, uint8_t *p, uint8_t 
*q, uint8_t *dq,
 {
uint8x16_t qm0 = vld1q_u8(qmul);
uint8x16_t qm1 = vld1q_u8(qmul + 16);
+   uint8x16_t x0f = vdupq_n_u8(0x0f);
 
/*
 * while (bytes--) {
-- 
2.21.0.rc2.261.ga7da99ff1b-goog



[PATCH v2 4/4] Makefile: lld: set -O2 linker flag when linking with LLD

2019-02-11 Thread ndesaulniers
For arm64:
0.34% size improvement with lld -O2 over lld for vmlinux.
3.3% size improvement with lld -O2 over lld for Image.lz4-dtb.

Link: https://github.com/ClangBuiltLinux/linux/issues/343
Suggested-by: Rui Ueyama 
Suggested-by: Nathan Chancellor 
Reviewed-by: Nathan Chancellor 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Changes V1->V2:
* add tested and reviewed by tags.

 Makefile | 4 
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 00e8e01d23fc..8011555745aa 100644
--- a/Makefile
+++ b/Makefile
@@ -718,6 +718,10 @@ else
 KBUILD_CFLAGS += -Wno-unused-but-set-variable
 endif
 
+ifdef CONFIG_LD_IS_LLD
+KBUILD_LDFLAGS += -O2
+endif
+
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS  += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH v2 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD

2019-02-11 Thread ndesaulniers
This causes an issue when trying to build with `make LD=ld.lld` if
ld.lld and the rest of your cross tools aren't in the same directory
(ex. /usr/local/bin) (as is the case for Android's build system), as the
GCC_TOOLCHAIN_DIR then gets set based on `which $(LD)` which will point
where LLVM tools are, not GCC/binutils tools are located.

Instead, select the GCC_TOOLCHAIN_DIR based on another tool provided by
binutils for which LLVM does not provide a substitute for, such as
elfedit.

Fixes commit 785f11aa595b ("kbuild: Add better clang cross build support")

Link: https://github.com/ClangBuiltLinux/linux/issues/341
Suggested-by: Nathan Chancellor 
Reviewed-by: Nathan Chancellor 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Changes V1->V2:
* add reviewed and tested tags.

 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 86cf35d1d79d..d3b65e96d183 100644
--- a/Makefile
+++ b/Makefile
@@ -492,7 +492,7 @@ endif
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS:= --target=$(notdir $(CROSS_COMPILE:%-=%))
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS+= --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH v2 0/4] Improve kernel LLD support

2019-02-11 Thread ndesaulniers
This patch cleans up a few places in the Makefile to make way for
landing LLD support in the kernel.  There are still a few arch specific
fixes that need to get upstreamed, but this core set of patches should
be arch independent.

Some very rough numbers: LLD is improving the overall build time of
Google Pixel kernels by about 9%.  The build is mostly dominated by
compilation, but LLD is able to shave off quite a bit of time.

One of the included patches helps get LLD linked kernels to competitive
binary size, but there still some bugs in LLD causing it not to discard
certain sections.  Once that's fixed, I estimate an LLD linked kernel to
be just barely smaller than a BFD linked kernel (less than 1%).

Folks looking to test should use LLD built from source, as I recently
fixed a bug in LLD that prevented LLD linked kernel modules from being
loadable.

$ make LD=ld.lld

Nick Desaulniers (4):
  init/Kconfig: add config support for detecting linker
  Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD
  Makefile: lld: tell clang to use lld
  Makefile: lld: set -O2 linker flag when linking with LLD

Changes since v1:
* collect reviewed-by, sugguested-by, tested-by tags.
* move where -fuse-ld=lld is added to CFLAGS.

 Makefile | 9 -
 init/Kconfig | 9 +
 2 files changed, 17 insertions(+), 1 deletion(-)

-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH v2 3/4] Makefile: lld: tell clang to use lld

2019-02-11 Thread ndesaulniers
This is needed because clang doesn't select which linker to use based on
$LD but rather -fuse-ld=lld. This is problematic especially for
cc-ldoption, which checks for linker flag support via invoking the
compiler, rather than the linker.

Link: https://github.com/ClangBuiltLinux/linux/issues/342
Suggested-by: Nathan Chancellor 
Reviewed-by: Nathan Chancellor 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Changes V1->V2:
* add reviewed and tested by tags.
* move this addition up 2 statments so that it's properly added to
  KBUILD_*FLAGS as per Nathan.

 Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Makefile b/Makefile
index d3b65e96d183..00e8e01d23fc 100644
--- a/Makefile
+++ b/Makefile
@@ -500,6 +500,9 @@ ifneq ($(GCC_TOOLCHAIN),)
 CLANG_FLAGS+= --gcc-toolchain=$(GCC_TOOLCHAIN)
 endif
 CLANG_FLAGS+= -no-integrated-as
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS+= -fuse-ld=lld
+endif
 KBUILD_CFLAGS  += $(CLANG_FLAGS)
 KBUILD_AFLAGS  += $(CLANG_FLAGS)
 export CLANG_FLAGS
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH v2 1/4] init/Kconfig: add config support for detecting linker

2019-02-11 Thread ndesaulniers
Similar to how we differentiate between CONFIG_CC_IS_GCC and
CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and
CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things
for different linkers.

Cc: Sami Tolvanen 
Suggested-by: Sedat Dilek 
Reviewed-by: Kees Cook 
Reviewed-by: Nathan Chancellor 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Changes V1->V2:
* Add suggested, reviewed, and tested by tags.

 init/Kconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index c9386a365eea..b6046dcf7794 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
bool
depends on !UML
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH 0/4] Improve kernel LLD support

2019-02-07 Thread ndesaulniers
This patch cleans up a few places in the Makefile to make way for
landing LLD support in the kernel.  There are still a few arch specific
fixes that need to get upstreamed, but this core set of patches should
be arch independent.

Some very rough numbers: LLD is improving the overall build time of
Google Pixel kernels by about 9%.  The build is mostly dominated by
compilation, but LLD is able to shave off quite a bit of time.

One of the included patches helps get LLD linked kernels to competitive
binary size, but there still some bugs in LLD causing it not to discard
certain sections.  Once that's fixed, I estimate an LLD linked kernel to
be just barely smaller than a BFD linked kernel (less than 1%).

Folks looking to test should use LLD built from source, as I recently
fixed a bug in LLD that prevented LLD linked kernel modules from being
loadable.

$ make LD=ld.lld

Nick Desaulniers (4):
  init/Kconfig: add config support for detecting linker
  Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD
  Makefile: lld: tell clang to use lld
  Makefile: lld: set -O2 linker flag when linking with LLD

 Makefile | 9 -
 init/Kconfig | 9 +
 2 files changed, 17 insertions(+), 1 deletion(-)

-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH 2/4] Makefile: clang: choose GCC_TOOLCHAIN_DIR not on LD

2019-02-07 Thread ndesaulniers
This causes an issue when trying to build with `make LD=ld.lld` if
ld.lld and the rest of your cross tools aren't in the same directory
(ex. /usr/local/bin) (as is the case for Android's build system), as the
GCC_TOOLCHAIN_DIR then gets set based on `which $(LD)` which will point
where LLVM tools are, not GCC/binutils tools are located.

Instead, select the GCC_TOOLCHAIN_DIR based on another tool provided by
binutils for which LLVM does not provide a substitute for, such as
elfedit.

Fixes commit 785f11aa595b ("kbuild: Add better clang cross build support")

Link: https://github.com/ClangBuiltLinux/linux/issues/341
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 3142e67d03f1..0eae4277206e 100644
--- a/Makefile
+++ b/Makefile
@@ -492,7 +492,7 @@ endif
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
 ifneq ($(CROSS_COMPILE),)
 CLANG_FLAGS:= --target=$(notdir $(CROSS_COMPILE:%-=%))
-GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
+GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
 CLANG_FLAGS+= --prefix=$(GCC_TOOLCHAIN_DIR)
 GCC_TOOLCHAIN  := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
 endif
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH 3/4] Makefile: lld: tell clang to use lld

2019-02-07 Thread ndesaulniers
This is needed because clang doesn't select which linker to use based on
$LD but rather -fuse-ld=$(LD). This is problematic especially for
cc-ldoption, which checks for linker flag support via invoking the
compiler, rather than the linker.

Link: https://github.com/ClangBuiltLinux/linux/issues/342
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Makefile b/Makefile
index 0eae4277206e..6307c17259ea 100644
--- a/Makefile
+++ b/Makefile
@@ -502,6 +502,9 @@ endif
 CLANG_FLAGS+= -no-integrated-as
 KBUILD_CFLAGS  += $(CLANG_FLAGS)
 KBUILD_AFLAGS  += $(CLANG_FLAGS)
+ifneq ($(shell $(LD) --version 2>&1 | head -n 1 | grep LLD),)
+CLANG_FLAGS+= -fuse-ld=lld
+endif
 export CLANG_FLAGS
 endif
 
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH 4/4] Makefile: lld: set -O2 linker flag when linking with LLD

2019-02-07 Thread ndesaulniers
-O2 enables tail merging of string table strings.

For arm64:
0.34% size improvement with lld -O2 over lld for vmlinux.
3.30% size improvement with lld -O2 over lld for Image.lz4-dtb.

Link: https://github.com/ClangBuiltLinux/linux/issues/343
Suggested-by: Rui Ueyama 
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
 Makefile | 4 
 1 file changed, 4 insertions(+)

diff --git a/Makefile b/Makefile
index 6307c17259ea..c07208ec49d4 100644
--- a/Makefile
+++ b/Makefile
@@ -718,6 +718,10 @@ else
 KBUILD_CFLAGS += -Wno-unused-but-set-variable
 endif
 
+ifdef CONFIG_LD_IS_LLD
+KBUILD_LDFLAGS += -O2
+endif
+
 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
 ifdef CONFIG_FRAME_POINTER
 KBUILD_CFLAGS  += -fno-omit-frame-pointer -fno-optimize-sibling-calls
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH 1/4] init/Kconfig: add config support for detecting linker

2019-02-07 Thread ndesaulniers
Similar to how we differentiate between CONFIG_CC_IS_GCC and
CONFIG_CC_IS_CLANG, add CONFIG_LD_IS_BFD, CONFIG_LD_IS_GOLD, and
CONFIG_LD_IS_LLD.

This simiplifies patches to Makefiles that need to do different things
for different linkers.

Cc: Nathan Chancellor 
Cc: Sami Tolvanen 
Signed-off-by: Nick Desaulniers 
---
 init/Kconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index c9386a365eea..b6046dcf7794 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -26,6 +26,15 @@ config CLANG_VERSION
 config CC_HAS_ASM_GOTO
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
 
+config LD_IS_BFD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU ld')
+
+config LD_IS_GOLD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'GNU gold')
+
+config LD_IS_LLD
+   def_bool $(success,$(LD) --version | head -n 1 | grep -q 'LLD')
+
 config CONSTRUCTORS
bool
depends on !UML
-- 
2.20.1.791.gb4d0f1c61a-goog



[PATCH] drm/amd/display: add -msse2 to prevent Clang from emitting libcalls to undefined SW FP routines

2019-01-24 Thread ndesaulniers
arch/x86/Makefile disables SSE and SSE2 for the whole kernel.  The
AMDGPU drivers modified in this patch re-enable SSE but not SSE2.  Turn
on SSE2 to support emitting double precision floating point instructions
rather than calls to non-existent (usually available from gcc_s or
compiler_rt) floating point helper routines.

Link: https://gcc.gnu.org/onlinedocs/gccint/Soft-float-library-routines.html
Link: https://github.com/ClangBuiltLinux/linux/issues/327
Cc: sta...@vger.kernel.org # 4.19
Reported-by: S, Shirish 
Reported-by: Matthias Kaehlcke 
Suggested-by: James Y Knight 
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
Tested-by: Guenter Roeck 
---
 drivers/gpu/drm/amd/display/dc/calcs/Makefile | 2 +-
 drivers/gpu/drm/amd/display/dc/dml/Makefile   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/calcs/Makefile 
b/drivers/gpu/drm/amd/display/dc/calcs/Makefile
index 95f332ee3e7e..dc85a3c088af 100644
--- a/drivers/gpu/drm/amd/display/dc/calcs/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/calcs/Makefile
@@ -30,7 +30,7 @@ else ifneq ($(call cc-option, -mstack-alignment=16),)
cc_stack_align := -mstack-alignment=16
 endif
 
-calcs_ccflags := -mhard-float -msse $(cc_stack_align)
+calcs_ccflags := -mhard-float -msse -msse2 $(cc_stack_align)
 
 CFLAGS_dcn_calcs.o := $(calcs_ccflags)
 CFLAGS_dcn_calc_auto.o := $(calcs_ccflags)
diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile 
b/drivers/gpu/drm/amd/display/dc/dml/Makefile
index d97ca6528f9d..33c7d7588712 100644
--- a/drivers/gpu/drm/amd/display/dc/dml/Makefile
+++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile
@@ -30,7 +30,7 @@ else ifneq ($(call cc-option, -mstack-alignment=16),)
cc_stack_align := -mstack-alignment=16
 endif
 
-dml_ccflags := -mhard-float -msse $(cc_stack_align)
+dml_ccflags := -mhard-float -msse -msse2 $(cc_stack_align)
 
 CFLAGS_display_mode_lib.o := $(dml_ccflags)
 CFLAGS_display_pipe_clocks.o := $(dml_ccflags)
-- 
2.20.1.321.g9e740568ce-goog



[PATCH v2] x86/build: Mark per-cpu symbols as absolute

2018-12-19 Thread ndesaulniers
From: Rafael Ávila de Espíndola 

The kernel has many variables that it wants to have per CPU. It is
similar to how each thread wants a copy of a thread local variable.

To access such variable, the code has to find the offset of that
variable in the per cpu block and add it to the address of the current
brock for that cpu.

Section 3.10.8 of ld.bfd's documentation states:
```
For expressions involving numbers, relative addresses and absolute
addresses, ld follows these rules to evaluate terms:

Other binary operations, that is, between two relative addresses
not in the same section, or between a relative address and an
absolute address, first convert any non-absolute term to an
absolute address before applying the operator."
```

Note that ld.lld does not implement this behavior. Instead, we can
explicitly mark non-absolute terms ABSOLUTE via linker script. This is
no functional change for ld.bfd which coverts the term to ABSOLUTE
anyways as specified above.

Reported-by: Dmitry Golovin 
Tested-by: Dmitry Golovin 
Suggested-by: Borislav Petkov 
Suggested-by: Michael Matz 
Signed-off-by: Tri Vo 
Signed-off-by: Nick Desaulniers 
Signed-off-by: Rafael Ávila de Espíndola 
[nd: commit message updated as per Boris' and Michael's sugguestions]
---
Changes from v1 -> v2: commit message updated

 arch/x86/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 0d618ee634ac..ee3b5c7d662e 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -401,7 +401,7 @@ SECTIONS
  * Per-cpu symbols which need to be offset from __per_cpu_load
  * for the boot processor.
  */
-#define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
+#define INIT_PER_CPU(x) init_per_cpu__##x = ABSOLUTE(x) + __per_cpu_load
 INIT_PER_CPU(gdt_page);
 INIT_PER_CPU(irq_stack_union);
 
-- 
2.20.1.415.g653613c723-goog



[PATCH] sparc: vdso: Drop implicit common-page-size linker flag

2018-12-10 Thread ndesaulniers
GNU linker's -z common-page-size's default value is based on the target
architecture. arch/sparc/vdso/Makefile sets it to the architecture
default, which is implicit and redundant. Drop it.

Link: https://lkml.kernel.org/r/20181206191231.192355-1-ndesaulni...@google.com
Signed-off-by: Nick Desaulniers 
---
 arch/sparc/vdso/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/sparc/vdso/Makefile b/arch/sparc/vdso/Makefile
index a6e18ca4cc18..74e97f77e23b 100644
--- a/arch/sparc/vdso/Makefile
+++ b/arch/sparc/vdso/Makefile
@@ -34,7 +34,7 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
 CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m elf64_sparc -soname linux-vdso.so.1 --no-undefined \
-   -z max-page-size=8192 -z common-page-size=8192
+   -z max-page-size=8192
 
 $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
$(call if_changed,vdso)
-- 
2.20.0.rc2.403.gdbc3b29805-goog



[PATCH] ARM: VDSO: Drop implicit common-page-size linker flag

2018-12-10 Thread ndesaulniers
GNU linker's -z common-page-size's default value is based on the target
architecture. arch/arm/vdso/Makefile sets it to the architecture
default, which is implicit and redundant. Drop it.

Link: https://lkml.kernel.org/r/20181206191231.192355-1-ndesaulni...@google.com
Signed-off-by: Nick Desaulniers 
---
 arch/arm/vdso/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/vdso/Makefile b/arch/arm/vdso/Makefile
index f4efff9d3afb..8f2fac5acbc8 100644
--- a/arch/arm/vdso/Makefile
+++ b/arch/arm/vdso/Makefile
@@ -11,7 +11,7 @@ ccflags-y := -fPIC -fno-common -fno-builtin 
-fno-stack-protector
 ccflags-y += -DDISABLE_BRANCH_PROFILING
 
 VDSO_LDFLAGS := -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-soname=linux-vdso.so.1
-VDSO_LDFLAGS += -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
+VDSO_LDFLAGS += -Wl,-z,max-page-size=4096
 VDSO_LDFLAGS += -nostdlib -shared
 VDSO_LDFLAGS += $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
 VDSO_LDFLAGS += $(call cc-ldoption, -Wl$(comma)--build-id)
-- 
2.20.0.rc2.403.gdbc3b29805-goog



[PATCH] x86/um/vdso: Drop implicit common-page-size linker flag

2018-12-10 Thread ndesaulniers
GNU linker's -z common-page-size's default value is based on the target
architecture. arch/x86/entry/vdso/Makefile sets it to the architecture
default, which is implicit and redundant. Drop it.

Link: https://lkml.kernel.org/r/20181206191231.192355-1-ndesaulni...@google.com
Signed-off-by: Nick Desaulniers 
---
 arch/x86/um/vdso/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/um/vdso/Makefile b/arch/x86/um/vdso/Makefile
index 822ccdba93ad..bf94060fc06f 100644
--- a/arch/x86/um/vdso/Makefile
+++ b/arch/x86/um/vdso/Makefile
@@ -26,7 +26,7 @@ targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \
-   -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
+   -Wl,-z,max-page-size=4096
 
 $(obj)/vdso.o: $(src)/vdso.S $(obj)/vdso.so
 
-- 
2.20.0.rc2.403.gdbc3b29805-goog



[PATCH] x86/vdso: drop implicit common-page-size linker flag

2018-12-06 Thread ndesaulniers
These are implied by the target architecture and for x86_64 match the
max-page-size. The default for non-NaCl x86_64 is 0x1000 (4096).

In bfd the common page size is defined as 0x1000 (4096) for non-NaCl
x86_64 targets:

bfd/elf64-x86-64.c:
4998:#define ELF_COMMONPAGESIZE 0x1000

For gold, the common page size is defined as 0x1000 (4096) for non-NaCl
x86_64 targets:

gold/x86_64.cc:
1413:  0x1000, // common_pagesize (overridable by -z common-page-size)
1442:  0x1000, // common_pagesize (overridable by -z common-page-size)

(ELF_COMMONPAGESIZE also defaults to ELF_MAXPAGESIZE when not set
explicitly for a target architecture in bfd/elfxx-target.h, but that's
not relevant for x86_64).

Because it's implied by the target architecture, it's of questionable
use to implement in LLD.  This patch resolves one of the issues towards
using LLD to link an x86_64 kernel.

Fixes commit 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with
gettimeofday/clock_gettime/getcpu")

Link: https://bugs.llvm.org/show_bug.cgi?id=38774
Link: https://github.com/ClangBuiltLinux/linux/issues/31
Cc: Fangrui Song 
Cc: Andi Kleen 
Cc: Andi Kleen 
Reported-by: Dmitry Golovin 
Reported-by: Bill Wendling 
Suggested-by: Dmitry Golovin 
Suggested-by: Rui Ueyama 
Signed-off-by: Nick Desaulniers 
---
 arch/x86/entry/vdso/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 141d415a8c80..0624bf2266fd 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -47,7 +47,7 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
 CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
-   -z max-page-size=4096 -z common-page-size=4096
+   -z max-page-size=4096
 
 $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
$(call if_changed,vdso)
@@ -98,7 +98,7 @@ CFLAGS_REMOVE_vvar.o = -pg
 
 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
 VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
-  -z max-page-size=4096 -z common-page-size=4096
+  -z max-page-size=4096
 
 # x32-rebranded versions
 vobjx32s-y := $(vobjs-y:.o=-x32.o)
-- 
2.20.0.rc1.387.gf8505762e3-goog



[PATCH] x86/vdso: drop implicit common-page-size linker flag

2018-12-06 Thread ndesaulniers
These are implied by the target architecture and for x86_64 match the
max-page-size. The default for non-NaCl x86_64 is 0x1000 (4096).

In bfd the common page size is defined as 0x1000 (4096) for non-NaCl
x86_64 targets:

bfd/elf64-x86-64.c:
4998:#define ELF_COMMONPAGESIZE 0x1000

For gold, the common page size is defined as 0x1000 (4096) for non-NaCl
x86_64 targets:

gold/x86_64.cc:
1413:  0x1000, // common_pagesize (overridable by -z common-page-size)
1442:  0x1000, // common_pagesize (overridable by -z common-page-size)

(ELF_COMMONPAGESIZE also defaults to ELF_MAXPAGESIZE when not set
explicitly for a target architecture in bfd/elfxx-target.h, but that's
not relevant for x86_64).

Because it's implied by the target architecture, it's of questionable
use to implement in LLD.  This patch resolves one of the issues towards
using LLD to link an x86_64 kernel.

Fixes commit 2aae950b21e4 ("x86_64: Add vDSO for x86-64 with
gettimeofday/clock_gettime/getcpu")

Link: https://bugs.llvm.org/show_bug.cgi?id=38774
Link: https://github.com/ClangBuiltLinux/linux/issues/31
Cc: Fangrui Song 
Cc: Andi Kleen 
Cc: Andi Kleen 
Reported-by: Dmitry Golovin 
Reported-by: Bill Wendling 
Suggested-by: Dmitry Golovin 
Suggested-by: Rui Ueyama 
Signed-off-by: Nick Desaulniers 
---
 arch/x86/entry/vdso/Makefile | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 141d415a8c80..0624bf2266fd 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -47,7 +47,7 @@ targets += $(vdso_img_sodbg) $(vdso_img-y:%=vdso%.so)
 CPPFLAGS_vdso.lds += -P -C
 
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -soname linux-vdso.so.1 --no-undefined \
-   -z max-page-size=4096 -z common-page-size=4096
+   -z max-page-size=4096
 
 $(obj)/vdso64.so.dbg: $(obj)/vdso.lds $(vobjs) FORCE
$(call if_changed,vdso)
@@ -98,7 +98,7 @@ CFLAGS_REMOVE_vvar.o = -pg
 
 CPPFLAGS_vdsox32.lds = $(CPPFLAGS_vdso.lds)
 VDSO_LDFLAGS_vdsox32.lds = -m elf32_x86_64 -soname linux-vdso.so.1 \
-  -z max-page-size=4096 -z common-page-size=4096
+  -z max-page-size=4096
 
 # x32-rebranded versions
 vobjx32s-y := $(vobjs-y:.o=-x32.o)
-- 
2.20.0.rc1.387.gf8505762e3-goog



[PATCH v3] include/linux/compiler*.h: define asm_volatile_goto

2018-10-31 Thread ndesaulniers
asm_volatile_goto should also be defined for other compilers that support
asm goto.

Fixes commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h
mutually exclusive").

Signed-off-by: Nick Desaulniers 
---
V2 -> V3: update subject line & add reference to fixed commit.
V1 -> V2: drop changes to include/linux/compiler-gcc.h.


 include/linux/compiler_types.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 97cfe29b3f0a..6f1cb84a687b 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -151,6 +151,10 @@ struct ftrace_likely_data {
 #define __assume_aligned(a, ...)
 #endif
 
+#ifndef asm_volatile_goto
+#define asm_volatile_goto(x...) asm goto(x)
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH v3] include/linux/compiler*.h: define asm_volatile_goto

2018-10-31 Thread ndesaulniers
asm_volatile_goto should also be defined for other compilers that support
asm goto.

Fixes commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h
mutually exclusive").

Signed-off-by: Nick Desaulniers 
---
V2 -> V3: update subject line & add reference to fixed commit.
V1 -> V2: drop changes to include/linux/compiler-gcc.h.


 include/linux/compiler_types.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 97cfe29b3f0a..6f1cb84a687b 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -151,6 +151,10 @@ struct ftrace_likely_data {
 #define __assume_aligned(a, ...)
 #endif
 
+#ifndef asm_volatile_goto
+#define asm_volatile_goto(x...) asm goto(x)
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH v2] include/linux/compiler*.h: add version detection to asm_volatile_goto

2018-10-31 Thread ndesaulniers
asm_volatile_goto should also be defined for other compilers that support
asm goto.

Signed-off-by: Nick Desaulniers 
---
V1 -> V2: drop changes to include/linux/compiler-gcc.h.

 include/linux/compiler_types.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 97cfe29b3f0a..6f1cb84a687b 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -151,6 +151,10 @@ struct ftrace_likely_data {
 #define __assume_aligned(a, ...)
 #endif
 
+#ifndef asm_volatile_goto
+#define asm_volatile_goto(x...) asm goto(x)
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH v2] include/linux/compiler*.h: add version detection to asm_volatile_goto

2018-10-31 Thread ndesaulniers
asm_volatile_goto should also be defined for other compilers that support
asm goto.

Signed-off-by: Nick Desaulniers 
---
V1 -> V2: drop changes to include/linux/compiler-gcc.h.

 include/linux/compiler_types.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 97cfe29b3f0a..6f1cb84a687b 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -151,6 +151,10 @@ struct ftrace_likely_data {
 #define __assume_aligned(a, ...)
 #endif
 
+#ifndef asm_volatile_goto
+#define asm_volatile_goto(x...) asm goto(x)
+#endif
+
 /* Are two types/vars the same type (ignoring qualifiers)? */
 #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
 
-- 
2.19.1.568.g152ad8e336-goog



[PATCH v2] [PATCH] KEYS: trusted: fix -Wvarags warning

2018-10-22 Thread ndesaulniers
Fixes the warning reported by Clang:
security/keys/trusted.c:146:17: warning: passing an object that
undergoes default
  argument promotion to 'va_start' has undefined behavior [-Wvarargs]
va_start(argp, h3);
   ^
security/keys/trusted.c:126:37: note: parameter of type 'unsigned
char' is declared here
unsigned char *h2, unsigned char h3, ...)
   ^
Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
standards explicitly call this out as undefined behavior:

The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with ... or with a
type that is not compatible with the type that results after
application of the default argument promotions, the behavior is
undefined.

Link: https://github.com/ClangBuiltLinux/linux/issues/41
Link: https://www.eskimo.com/~scs/cclass/int/sx11c.html
Suggested-by: David Laight 
Suggested-by: Denis Kenzior 
Suggested-by: James Bottomley 
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
v1 -> v2:
* Don't reorder args, just use default function promotion type
of unsigned int.
* Add !! boolean cast as per Denis in
https://lkml.org/lkml/2018/10/12/838.
* Tested with gcc-8 and clang-8.

 include/keys/trusted.h  | 2 +-
 security/keys/trusted.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/keys/trusted.h b/include/keys/trusted.h
index adbcb6817826..0071298b9b28 100644
--- a/include/keys/trusted.h
+++ b/include/keys/trusted.h
@@ -38,7 +38,7 @@ enum {
 
 int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...);
+   unsigned char *h2, unsigned int h3, ...);
 int TSS_checkhmac1(unsigned char *buffer,
  const uint32_t command,
  const unsigned char *ononce,
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index ff6789365a12..335ce6d1cf6b 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -123,7 +123,7 @@ static int TSS_rawhmac(unsigned char *digest, const 
unsigned char *key,
  */
 int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...)
+   unsigned char *h2, unsigned int h3, ...)
 {
unsigned char paramdigest[SHA1_DIGEST_SIZE];
struct sdesc *sdesc;
@@ -139,7 +139,7 @@ int TSS_authhmac(unsigned char *digest, const unsigned char 
*key,
return PTR_ERR(sdesc);
}
 
-   c = h3;
+   c = !!h3;
ret = crypto_shash_init(>shash);
if (ret < 0)
goto out;
-- 
2.19.1.568.g152ad8e336-goog



[PATCH v2] [PATCH] KEYS: trusted: fix -Wvarags warning

2018-10-22 Thread ndesaulniers
Fixes the warning reported by Clang:
security/keys/trusted.c:146:17: warning: passing an object that
undergoes default
  argument promotion to 'va_start' has undefined behavior [-Wvarargs]
va_start(argp, h3);
   ^
security/keys/trusted.c:126:37: note: parameter of type 'unsigned
char' is declared here
unsigned char *h2, unsigned char h3, ...)
   ^
Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
standards explicitly call this out as undefined behavior:

The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with ... or with a
type that is not compatible with the type that results after
application of the default argument promotions, the behavior is
undefined.

Link: https://github.com/ClangBuiltLinux/linux/issues/41
Link: https://www.eskimo.com/~scs/cclass/int/sx11c.html
Suggested-by: David Laight 
Suggested-by: Denis Kenzior 
Suggested-by: James Bottomley 
Suggested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
v1 -> v2:
* Don't reorder args, just use default function promotion type
of unsigned int.
* Add !! boolean cast as per Denis in
https://lkml.org/lkml/2018/10/12/838.
* Tested with gcc-8 and clang-8.

 include/keys/trusted.h  | 2 +-
 security/keys/trusted.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/keys/trusted.h b/include/keys/trusted.h
index adbcb6817826..0071298b9b28 100644
--- a/include/keys/trusted.h
+++ b/include/keys/trusted.h
@@ -38,7 +38,7 @@ enum {
 
 int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...);
+   unsigned char *h2, unsigned int h3, ...);
 int TSS_checkhmac1(unsigned char *buffer,
  const uint32_t command,
  const unsigned char *ononce,
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index ff6789365a12..335ce6d1cf6b 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -123,7 +123,7 @@ static int TSS_rawhmac(unsigned char *digest, const 
unsigned char *key,
  */
 int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...)
+   unsigned char *h2, unsigned int h3, ...)
 {
unsigned char paramdigest[SHA1_DIGEST_SIZE];
struct sdesc *sdesc;
@@ -139,7 +139,7 @@ int TSS_authhmac(unsigned char *digest, const unsigned char 
*key,
return PTR_ERR(sdesc);
}
 
-   c = h3;
+   c = !!h3;
ret = crypto_shash_init(>shash);
if (ret < 0)
goto out;
-- 
2.19.1.568.g152ad8e336-goog



[PATCH] compiler-gcc: remove comment about gcc 4.5 from unreachable()

2018-10-15 Thread ndesaulniers
Remove the comment about being unable to detect __builtin_unreachable.
__builtin_unreachable was implemented in the GCC 4.5 timeframe. The
kernel's minimum supported version of GCC is 4.6 since commit
cafa0010cd51 ("Raise the minimum required gcc version to 4.6"). Commit
cb984d101b30 ("compiler-gcc: integrate the various compiler-gcc[345].h
files") shows that unreachable() had different guards based on GCC
version.

Suggested-by: Miguel Ojeda 
Signed-off-by: Nick Desaulniers 
---
 include/linux/compiler-gcc.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 4d36b27214fd..9890411b33d5 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -107,10 +107,6 @@
  * Mark a position in code as unreachable.  This can be used to
  * suppress control flow warnings after asm blocks that transfer
  * control elsewhere.
- *
- * Early snapshots of gcc 4.5 don't support this and we can't detect
- * this in the preprocessor, but we can live with this because they're
- * unreleased.  Really, we need to have autoconf for the kernel.
  */
 #define unreachable() \
do {\
-- 
2.19.1.331.ge82ca0e54c-goog



[PATCH] compiler-gcc: remove comment about gcc 4.5 from unreachable()

2018-10-15 Thread ndesaulniers
Remove the comment about being unable to detect __builtin_unreachable.
__builtin_unreachable was implemented in the GCC 4.5 timeframe. The
kernel's minimum supported version of GCC is 4.6 since commit
cafa0010cd51 ("Raise the minimum required gcc version to 4.6"). Commit
cb984d101b30 ("compiler-gcc: integrate the various compiler-gcc[345].h
files") shows that unreachable() had different guards based on GCC
version.

Suggested-by: Miguel Ojeda 
Signed-off-by: Nick Desaulniers 
---
 include/linux/compiler-gcc.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 4d36b27214fd..9890411b33d5 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -107,10 +107,6 @@
  * Mark a position in code as unreachable.  This can be used to
  * suppress control flow warnings after asm blocks that transfer
  * control elsewhere.
- *
- * Early snapshots of gcc 4.5 don't support this and we can't detect
- * this in the preprocessor, but we can live with this because they're
- * unreleased.  Really, we need to have autoconf for the kernel.
  */
 #define unreachable() \
do {\
-- 
2.19.1.331.ge82ca0e54c-goog



[PATCH] compiler.h: update definition of unreachable()

2018-10-15 Thread ndesaulniers
Fixes the objtool warning seen with Clang:
arch/x86/mm/fault.o: warning: objtool: no_context()+0x220: unreachable
instruction

Fixes commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h
mutually exclusive")

Josh noted that the fallback definition was meant to work around a
pre-gcc-4.6 bug. GCC still needs to work around
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365, so compiler-gcc.h
defines its own version of unreachable().  Clang and ICC can use this
shared definition.

Link: https://github.com/ClangBuiltLinux/linux/issues/204
Suggested-by: Andy Lutomirski 
Suggested-by: Josh Poimboeuf 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Miguel, would you mind taking this up in your new compiler attributes
tree?

 include/linux/compiler.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 681d866efb1e..8875fd3243fd 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -124,7 +124,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, 
int val,
 # define ASM_UNREACHABLE
 #endif
 #ifndef unreachable
-# define unreachable() do { annotate_reachable(); do { } while (1); } while (0)
+# define unreachable() do {\
+   annotate_unreachable(); \
+   __builtin_unreachable();\
+} while (0)
 #endif
 
 /*
-- 
2.19.0.605.g01d371f741-goog



[PATCH] compiler.h: update definition of unreachable()

2018-10-15 Thread ndesaulniers
Fixes the objtool warning seen with Clang:
arch/x86/mm/fault.o: warning: objtool: no_context()+0x220: unreachable
instruction

Fixes commit 815f0ddb346c ("include/linux/compiler*.h: make compiler-*.h
mutually exclusive")

Josh noted that the fallback definition was meant to work around a
pre-gcc-4.6 bug. GCC still needs to work around
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365, so compiler-gcc.h
defines its own version of unreachable().  Clang and ICC can use this
shared definition.

Link: https://github.com/ClangBuiltLinux/linux/issues/204
Suggested-by: Andy Lutomirski 
Suggested-by: Josh Poimboeuf 
Tested-by: Nathan Chancellor 
Signed-off-by: Nick Desaulniers 
---
Miguel, would you mind taking this up in your new compiler attributes
tree?

 include/linux/compiler.h | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 681d866efb1e..8875fd3243fd 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -124,7 +124,10 @@ void ftrace_likely_update(struct ftrace_likely_data *f, 
int val,
 # define ASM_UNREACHABLE
 #endif
 #ifndef unreachable
-# define unreachable() do { annotate_reachable(); do { } while (1); } while (0)
+# define unreachable() do {\
+   annotate_unreachable(); \
+   __builtin_unreachable();\
+} while (0)
 #endif
 
 /*
-- 
2.19.0.605.g01d371f741-goog



[PATCH] KEYS: trusted: fix -Wvarags warning

2018-10-11 Thread ndesaulniers
by swapping h2 and h3.

security/keys/trusted.c:146:17: warning: passing an object that
undergoes default
  argument promotion to 'va_start' has undefined behavior [-Wvarargs]
va_start(argp, h3);
   ^
security/keys/trusted.c:126:37: note: parameter of type 'unsigned
char' is declared here
unsigned char *h2, unsigned char h3, ...)
   ^

Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
standards explicitly call this out as undefined behavior:

The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with ... or with a
type that is not compatible with the type that results after
application of the default argument promotions, the behavior is
undefined.

Link: https://github.com/ClangBuiltLinux/linux/issues/41
Suggested-by: James Bottomley 
Signed-off-by: Nick Desaulniers 
---
 security/keys/trusted.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index b69d3b1777c2..d425b2b839af 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -123,7 +123,7 @@ static int TSS_rawhmac(unsigned char *digest, const 
unsigned char *key,
  */
 static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...)
+   unsigned char h2, unsigned char *h3, ...)
 {
unsigned char paramdigest[SHA1_DIGEST_SIZE];
struct sdesc *sdesc;
@@ -139,7 +139,7 @@ static int TSS_authhmac(unsigned char *digest, const 
unsigned char *key,
return PTR_ERR(sdesc);
}
 
-   c = h3;
+   c = h2;
ret = crypto_shash_init(>shash);
if (ret < 0)
goto out;
@@ -163,7 +163,7 @@ static int TSS_authhmac(unsigned char *digest, const 
unsigned char *key,
if (!ret)
ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
  paramdigest, TPM_NONCE_SIZE, h1,
- TPM_NONCE_SIZE, h2, 1, , 0, 0);
+ TPM_NONCE_SIZE, h3, 1, , 0, 0);
 out:
kzfree(sdesc);
return ret;
@@ -508,7 +508,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
if (pcrinfosize == 0) {
/* no pcr info specified */
ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
-  sess.enonce, td->nonceodd, cont,
+  sess.enonce, cont, td->nonceodd,
   sizeof(uint32_t), , SHA1_DIGEST_SIZE,
   td->encauth, sizeof(uint32_t), ,
   sizeof(uint32_t), , datalen, data, 0,
@@ -516,7 +516,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
} else {
/* pcr info specified */
ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
-  sess.enonce, td->nonceodd, cont,
+  sess.enonce, cont, td->nonceodd,
   sizeof(uint32_t), , SHA1_DIGEST_SIZE,
   td->encauth, sizeof(uint32_t), ,
   pcrinfosize, pcrinfo, sizeof(uint32_t),
@@ -608,12 +608,12 @@ static int tpm_unseal(struct tpm_buf *tb,
return ret;
}
ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
-  enonce1, nonceodd, cont, sizeof(uint32_t),
+  enonce1, cont, nonceodd, sizeof(uint32_t),
   , bloblen, blob, 0, 0);
if (ret < 0)
return ret;
ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE,
-  enonce2, nonceodd, cont, sizeof(uint32_t),
+  enonce2, cont, nonceodd, sizeof(uint32_t),
   , bloblen, blob, 0, 0);
if (ret < 0)
return ret;
-- 
2.19.0.605.g01d371f741-goog



[PATCH] KEYS: trusted: fix -Wvarags warning

2018-10-11 Thread ndesaulniers
by swapping h2 and h3.

security/keys/trusted.c:146:17: warning: passing an object that
undergoes default
  argument promotion to 'va_start' has undefined behavior [-Wvarargs]
va_start(argp, h3);
   ^
security/keys/trusted.c:126:37: note: parameter of type 'unsigned
char' is declared here
unsigned char *h2, unsigned char h3, ...)
   ^

Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
standards explicitly call this out as undefined behavior:

The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with ... or with a
type that is not compatible with the type that results after
application of the default argument promotions, the behavior is
undefined.

Link: https://github.com/ClangBuiltLinux/linux/issues/41
Suggested-by: James Bottomley 
Signed-off-by: Nick Desaulniers 
---
 security/keys/trusted.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index b69d3b1777c2..d425b2b839af 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -123,7 +123,7 @@ static int TSS_rawhmac(unsigned char *digest, const 
unsigned char *key,
  */
 static int TSS_authhmac(unsigned char *digest, const unsigned char *key,
unsigned int keylen, unsigned char *h1,
-   unsigned char *h2, unsigned char h3, ...)
+   unsigned char h2, unsigned char *h3, ...)
 {
unsigned char paramdigest[SHA1_DIGEST_SIZE];
struct sdesc *sdesc;
@@ -139,7 +139,7 @@ static int TSS_authhmac(unsigned char *digest, const 
unsigned char *key,
return PTR_ERR(sdesc);
}
 
-   c = h3;
+   c = h2;
ret = crypto_shash_init(>shash);
if (ret < 0)
goto out;
@@ -163,7 +163,7 @@ static int TSS_authhmac(unsigned char *digest, const 
unsigned char *key,
if (!ret)
ret = TSS_rawhmac(digest, key, keylen, SHA1_DIGEST_SIZE,
  paramdigest, TPM_NONCE_SIZE, h1,
- TPM_NONCE_SIZE, h2, 1, , 0, 0);
+ TPM_NONCE_SIZE, h3, 1, , 0, 0);
 out:
kzfree(sdesc);
return ret;
@@ -508,7 +508,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
if (pcrinfosize == 0) {
/* no pcr info specified */
ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
-  sess.enonce, td->nonceodd, cont,
+  sess.enonce, cont, td->nonceodd,
   sizeof(uint32_t), , SHA1_DIGEST_SIZE,
   td->encauth, sizeof(uint32_t), ,
   sizeof(uint32_t), , datalen, data, 0,
@@ -516,7 +516,7 @@ static int tpm_seal(struct tpm_buf *tb, uint16_t keytype,
} else {
/* pcr info specified */
ret = TSS_authhmac(td->pubauth, sess.secret, SHA1_DIGEST_SIZE,
-  sess.enonce, td->nonceodd, cont,
+  sess.enonce, cont, td->nonceodd,
   sizeof(uint32_t), , SHA1_DIGEST_SIZE,
   td->encauth, sizeof(uint32_t), ,
   pcrinfosize, pcrinfo, sizeof(uint32_t),
@@ -608,12 +608,12 @@ static int tpm_unseal(struct tpm_buf *tb,
return ret;
}
ret = TSS_authhmac(authdata1, keyauth, TPM_NONCE_SIZE,
-  enonce1, nonceodd, cont, sizeof(uint32_t),
+  enonce1, cont, nonceodd, sizeof(uint32_t),
   , bloblen, blob, 0, 0);
if (ret < 0)
return ret;
ret = TSS_authhmac(authdata2, blobauth, TPM_NONCE_SIZE,
-  enonce2, nonceodd, cont, sizeof(uint32_t),
+  enonce2, cont, nonceodd, sizeof(uint32_t),
   , bloblen, blob, 0, 0);
if (ret < 0)
return ret;
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2] x86/boot: define CC_HAVE_ASM_GOTO

2018-09-27 Thread ndesaulniers
Early prototypes of Clang with asm goto support produce 6 instances of
the following warning:

In file included from arch/x86/boot/compressed/misc.h:20:
In file included from ./include/linux/elf.h:5:
In file included from ./arch/x86/include/asm/elf.h:8:
In file included from ./include/linux/thread_info.h:38:
In file included from ./arch/x86/include/asm/thread_info.h:53:
./arch/x86/include/asm/cpufeature.h:150:2: warning: "Compiler lacks
ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
[-W#warnings]
your compiler arguments"
 ^

Since 6 files under arch/x86/boot/compressed/ include
arch/x86/boot/compressed/misc.h AND
arch/x86/boot/compressed/Makefile happens to redefine KBUILD_CFLAGS,
which set these variables in the top level MAKEFILE.

Suggested-by: Borislav Petkov 
Signed-off-by: Nick Desaulniers 
---
v1 -> v2:
  Updated commit message to provide more context as per Borislav.

 arch/x86/boot/compressed/Makefile | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 28764dacf018..158c0b4e178a 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -56,6 +56,13 @@ KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z 
noreloc-overflow" \
 endif
 LDFLAGS_vmlinux := -T
 
+# check for 'asm goto'
+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) 
$(KBUILD_CFLAGS)), y)
+  CC_HAVE_ASM_GOTO := 1
+  KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+  KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+endif
+
 hostprogs-y:= mkpiggy
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
-- 
2.19.0.605.g01d371f741-goog



[PATCH v2] x86/boot: define CC_HAVE_ASM_GOTO

2018-09-27 Thread ndesaulniers
Early prototypes of Clang with asm goto support produce 6 instances of
the following warning:

In file included from arch/x86/boot/compressed/misc.h:20:
In file included from ./include/linux/elf.h:5:
In file included from ./arch/x86/include/asm/elf.h:8:
In file included from ./include/linux/thread_info.h:38:
In file included from ./arch/x86/include/asm/thread_info.h:53:
./arch/x86/include/asm/cpufeature.h:150:2: warning: "Compiler lacks
ASM_GOTO support. Add -D __BPF_TRACING__ to your compiler arguments"
[-W#warnings]
your compiler arguments"
 ^

Since 6 files under arch/x86/boot/compressed/ include
arch/x86/boot/compressed/misc.h AND
arch/x86/boot/compressed/Makefile happens to redefine KBUILD_CFLAGS,
which set these variables in the top level MAKEFILE.

Suggested-by: Borislav Petkov 
Signed-off-by: Nick Desaulniers 
---
v1 -> v2:
  Updated commit message to provide more context as per Borislav.

 arch/x86/boot/compressed/Makefile | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/arch/x86/boot/compressed/Makefile 
b/arch/x86/boot/compressed/Makefile
index 28764dacf018..158c0b4e178a 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -56,6 +56,13 @@ KBUILD_LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z 
noreloc-overflow" \
 endif
 LDFLAGS_vmlinux := -T
 
+# check for 'asm goto'
+ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) 
$(KBUILD_CFLAGS)), y)
+  CC_HAVE_ASM_GOTO := 1
+  KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+  KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+endif
+
 hostprogs-y:= mkpiggy
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
 
-- 
2.19.0.605.g01d371f741-goog