Re: Clang patch stacks for LTS kernels (v4.4 and v4.9) and status update

From: Sedat Dilek
Date: Tue May 22 2018 - 05:22:03 EST


Hi,

I looked again into the llvm-bug #37512 and mentioned patches, so I
give this a 2nd try (see attached patchset).

Regards,
- Sedat -
From 6b78d2ecfae1cd3de35c8871605f0881df174b35 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <nick.desaulniers@xxxxxxxxx>
Date: Sat, 7 Oct 2017 13:23:23 -0700
Subject: [PATCH 1/4] kbuild: clang: remove crufty HOSTCFLAGS

When compiling with `make CC=clang HOSTCC=clang`, I was seeing warnings
that clang did not recognize -fno-delete-null-pointer-checks for HOSTCC
targets. These were added in commit 61163efae020 ("kbuild: LLVMLinux:
Add Kbuild support for building kernel with Clang").

Clang does not support -fno-delete-null-pointer-checks, so adding it to
HOSTCFLAGS if HOSTCC is clang does not make sense.

It's not clear why the other warnings were disabled, and just for
HOSTCFLAGS, but I can remove them, add -Werror to HOSTCFLAGS and compile
with clang just fine.

Suggested-by: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
Signed-off-by: Nick Desaulniers <nick.desaulniers@xxxxxxxxx>
Signed-off-by: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
---
Makefile | 5 -----
1 file changed, 5 deletions(-)

diff --git a/Makefile b/Makefile
index 0a1f941899f4..0e4dec5fdba5 100644
--- a/Makefile
+++ b/Makefile
@@ -369,11 +369,6 @@ HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS)
HOSTLDFLAGS := $(HOST_LFS_LDFLAGS)
HOST_LOADLIBES := $(HOST_LFS_LIBS)

-ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
-HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
- -Wno-missing-field-initializers -fno-delete-null-pointer-checks
-endif
-
# Make variables (CC, etc...)
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
--
2.17.0

From 32f3dd55b9c8c5ce45ac8f90a2a5dd5cfab0f4df Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <nick.desaulniers@xxxxxxxxx>
Date: Sat, 6 Jan 2018 13:39:48 -0800
Subject: [PATCH 2/4] x86: xen: remove the use of VLAIS

Variable Length Arrays In Structs (VLAIS) is not supported by Clang, and
frowned upon by others.

https://lkml.org/lkml/2013/9/23/500

Here, the VLAIS was used because the size of the bitmap returned from
xen_mc_entry() depended on possibly (based on kernel configuration)
runtime sized data. Rather than declaring args as a VLAIS then calling
sizeof on *args, we calculate the appropriate sizeof args manually.
Further, we can get rid of the #ifdef's and rely on num_possible_cpus()
(thanks to a helpful checkpatch warning from an earlier version of this
patch).

Suggested-by: Juergen Gross <jgross@xxxxxxxx>
Signed-off-by: Nick Desaulniers <nick.desaulniers@xxxxxxxxx>
Reviewed-by: Juergen Gross <jgross@xxxxxxxx>
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
---
arch/x86/xen/mmu_pv.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
index 042e9c422b21..854d5aa90b02 100644
--- a/arch/x86/xen/mmu_pv.c
+++ b/arch/x86/xen/mmu_pv.c
@@ -1325,20 +1325,18 @@ static void xen_flush_tlb_others(const struct cpumask *cpus,
{
struct {
struct mmuext_op op;
-#ifdef CONFIG_SMP
- DECLARE_BITMAP(mask, num_processors);
-#else
DECLARE_BITMAP(mask, NR_CPUS);
-#endif
} *args;
struct multicall_space mcs;
+ const size_t mc_entry_size = sizeof(args->op) +
+ sizeof(args->mask[0]) * BITS_TO_LONGS(num_possible_cpus());

trace_xen_mmu_flush_tlb_others(cpus, info->mm, info->start, info->end);

if (cpumask_empty(cpus))
return; /* nothing to do */

- mcs = xen_mc_entry(sizeof(*args));
+ mcs = xen_mc_entry(mc_entry_size);
args = mcs.args;
args->op.arg2.vcpumask = to_cpumask(args->mask);

--
2.17.0

From 81eceff6658d6e750c7c0d0810ec3d6e66a0cd51 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@xxxxxxxxxxx>
Date: Tue, 22 May 2018 12:00:56 +0200
Subject: [PATCH 3/4] compiler-clang.h: Add __nostackprotector attribute v2

---
include/linux/compiler-clang.h | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
index 070f85d92c15..3fb36173bb99 100644
--- a/include/linux/compiler-clang.h
+++ b/include/linux/compiler-clang.h
@@ -21,3 +21,10 @@
#ifdef __noretpoline
#undef __noretpoline
#endif
+
+/* Clang version 7 (>= svn331925) supports no_stack_protector attribute
+ * which disables the stack protector on the specified function.
+ * For details see <https://bugs.llvm.org/show_bug.cgi?id=37512>.
+ */
+#undef __nostackprotector
+#define __nostackprotector __attribute__((no_stack_protector))
--
2.17.0

From 4bdace7d91eb044aa7245da1cdf8a3d52182b7e0 Mon Sep 17 00:00:00 2001
From: Sedat Dilek <sedat.dilek@xxxxxxxxxxx>
Date: Tue, 22 May 2018 12:07:24 +0200
Subject: [PATCH 4/4] x86/paravirt: Mark native_save_fl() with
__nostackprotector attribute v2

---
arch/x86/include/asm/irqflags.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
index 89f08955fff7..7e6765097adc 100644
--- a/arch/x86/include/asm/irqflags.h
+++ b/arch/x86/include/asm/irqflags.h
@@ -13,7 +13,7 @@
* Interrupt control:
*/

-static inline unsigned long native_save_fl(void)
+static inline __nostackprotector unsigned long native_save_fl(void)
{
unsigned long flags;

--
2.17.0