Skip to contentSkip to conversation

s390: only build for new CPUs with clang

PATCH Applied Arnd Bergmann 4 participants 12 messages Apr 15, 2019 – May 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 s390: only build for new CPUs with clang

llvm does does not understand -march=z9-109 and older target specifiers, so disable the respective Kconfig settings and the logic to make the boot code work on old systems when building with clang.

Part of the early boot code is normally compiled with -march=z900 for maximum compatibility. This also has to get changed with clang to the oldest supported ISA, which is -march=z10 here.

---
 arch/s390/Kconfig       |  6 ++++++
 arch/s390/boot/Makefile | 18 ++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)
arch/s390/Kconfig +6 -0
index 8cd860cba4d1..1a2eec61196d 100644
@@ -240,6 +240,7 @@ choice
 
 config MARCH_Z900
 	bool "IBM zSeries model z800 and z900"
+	depends on !CC_IS_CLANG
 	select HAVE_MARCH_Z900_FEATURES
 	help
 	  Select this to enable optimizations for model z800/z900 (2064 and
@@ -248,6 +249,7 @@ config MARCH_Z900
 
 config MARCH_Z990
 	bool "IBM zSeries model z890 and z990"
+	depends on !CC_IS_CLANG
 	select HAVE_MARCH_Z990_FEATURES
 	help
 	  Select this to enable optimizations for model z890/z990 (2084 and
@@ -256,6 +258,7 @@ config MARCH_Z990
 
 config MARCH_Z9_109
 	bool "IBM System z9"
+	depends on !CC_IS_CLANG
 	select HAVE_MARCH_Z9_109_FEATURES
 	help
 	  Select this to enable optimizations for IBM System z9 (2094 and
@@ -347,12 +350,15 @@ config TUNE_DEFAULT
 
 config TUNE_Z900
 	bool "IBM zSeries model z800 and z900"
+	depends on !CC_IS_CLANG
 
 config TUNE_Z990
 	bool "IBM zSeries model z890 and z990"
+	depends on !CC_IS_CLANG
 
 config TUNE_Z9_109
 	bool "IBM System z9"
+	depends on !CC_IS_CLANG
 
 config TUNE_Z10
 	bool "IBM System z10"
arch/s390/boot/Makefile +12 -6
index c844eaf24ed7..c6a6b6dd3d52 100644
@@ -12,18 +12,24 @@ KBUILD_AFLAGS := $(KBUILD_AFLAGS_DECOMPRESSOR)
 KBUILD_CFLAGS := $(KBUILD_CFLAGS_DECOMPRESSOR)
 
 #
-# Use -march=z900 for als.c to be able to print an error
+# Use minimum architecture for als.c to be able to print an error
 # message if the kernel is started on a machine which is too old
 #
-ifneq ($(CC_FLAGS_MARCH),-march=z900)
+ifndef CONFIG_CC_IS_CLANG
+CC_FLAGS_MARCH_MINIMUM := -march=z900
+else
+CC_FLAGS_MARCH_MINIMUM := -march=z10
+endif
+
+ifneq ($(CC_FLAGS_MARCH),$(CC_FLAGS_MARCH_MINIMUM))
 AFLAGS_REMOVE_head.o		+= $(CC_FLAGS_MARCH)
-AFLAGS_head.o			+= -march=z900
+AFLAGS_head.o			+= $(CC_FLAGS_MARCH_MINIMUM)
 AFLAGS_REMOVE_mem.o		+= $(CC_FLAGS_MARCH)
-AFLAGS_mem.o			+= -march=z900
+AFLAGS_mem.o			+= $(CC_FLAGS_MARCH_MINIMUM)
 CFLAGS_REMOVE_als.o		+= $(CC_FLAGS_MARCH)
-CFLAGS_als.o			+= -march=z900
+CFLAGS_als.o			+= $(CC_FLAGS_MARCH_MINIMUM)
 CFLAGS_REMOVE_sclp_early_core.o	+= $(CC_FLAGS_MARCH)
-CFLAGS_sclp_early_core.o	+= -march=z900
+CFLAGS_sclp_early_core.o	+= $(CC_FLAGS_MARCH_MINIMUM)
 endif
 
 CFLAGS_sclp_early_core.o += -I$(srctree)/drivers/s390/char
Signature · 1 line
2.20.0
#1 lore raw

PATCH v2 2/4 s390: boot, purgatory: pass $(CLANG_FLAGS) where needed

The purgatory and boot Makefiles do not inherit the original cflags, so clang falls back to the default target architecture when building it, typically this would be x86 when cross-compiling.

Add $(CLANG_FLAGS) everywhere so we pass the correct --target=s390x-linux option when cross-compiling.

---
 arch/s390/Makefile           | 4 ++--
 arch/s390/purgatory/Makefile | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/s390/Makefile +2 -2
index 9c079a506325..9a228786e34f 100644
@@ -17,9 +17,9 @@ KBUILD_CFLAGS_MODULE += -fPIC
 KBUILD_AFLAGS	+= -m64
 KBUILD_CFLAGS	+= -m64
 aflags_dwarf	:= -Wa,-gdwarf-2
-KBUILD_AFLAGS_DECOMPRESSOR := -m64 -D__ASSEMBLY__
+KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -D__ASSEMBLY__
 KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf))
-KBUILD_CFLAGS_DECOMPRESSOR := -m64 -O2
+KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2
 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
 KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float
 KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables
arch/s390/purgatory/Makefile +1 -0
index ce6a3f75065b..ecd0b3847fef 100644
@@ -22,6 +22,7 @@ KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes
 KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare
 KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding
 KBUILD_CFLAGS += -c -MD -Os -m64 -msoft-float -fno-common
+KBUILD_CFLAGS += $(CLANG_FLAGS)
 KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
 KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
 
Signature · 1 line
2.20.0
Reviewed-by on v2 2/4
#2 lore raw

Re: [PATCH v2 2/4] s390: boot, purgatory: pass $(CLANG_FLAGS) where needed

Quoted 8 lines · Arnd Bergmann

The purgatory and boot Makefiles do not inherit the original cflags, so clang falls back to the default target architecture when building it, typically this would be x86 when cross-compiling.

Add $(CLANG_FLAGS) everywhere so we pass the correct --target=s390x-linux option when cross-compiling.

Quoted 36 lines
---
 arch/s390/Makefile           | 4 ++--
 arch/s390/purgatory/Makefile | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
arch/s390/Makefile +2 -2
index 9c079a506325..9a228786e34f 100644
@@ -17,9 +17,9 @@ KBUILD_CFLAGS_MODULE += -fPIC
 KBUILD_AFLAGS	+= -m64
 KBUILD_CFLAGS	+= -m64
 aflags_dwarf	:= -Wa,-gdwarf-2
-KBUILD_AFLAGS_DECOMPRESSOR := -m64 -D__ASSEMBLY__
+KBUILD_AFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -D__ASSEMBLY__
 KBUILD_AFLAGS_DECOMPRESSOR += $(if $(CONFIG_DEBUG_INFO),$(aflags_dwarf))
-KBUILD_CFLAGS_DECOMPRESSOR := -m64 -O2
+KBUILD_CFLAGS_DECOMPRESSOR := $(CLANG_FLAGS) -m64 -O2
 KBUILD_CFLAGS_DECOMPRESSOR += -DDISABLE_BRANCH_PROFILING -D__NO_FORTIFY
 KBUILD_CFLAGS_DECOMPRESSOR += -fno-delete-null-pointer-checks -msoft-float
 KBUILD_CFLAGS_DECOMPRESSOR += -fno-asynchronous-unwind-tables
arch/s390/purgatory/Makefile +1 -0
index ce6a3f75065b..ecd0b3847fef 100644
@@ -22,6 +22,7 @@ KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes
 KBUILD_CFLAGS += -Wno-pointer-sign -Wno-sign-compare
 KBUILD_CFLAGS += -fno-zero-initialized-in-bss -fno-builtin -ffreestanding
 KBUILD_CFLAGS += -c -MD -Os -m64 -msoft-float -fno-common
+KBUILD_CFLAGS += $(CLANG_FLAGS)
 KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
 KBUILD_AFLAGS := $(filter-out -DCC_USING_EXPOLINE,$(KBUILD_AFLAGS))
 
Signature · 1 line
2.20.0
#3 lore raw

Re: [PATCH v2 2/4] s390: boot, purgatory: pass $(CLANG_FLAGS) where needed

Quoted 5 lines · Nathan Chancellor
Quoted 4 lines · Arnd Bergmann

The purgatory and boot Makefiles do not inherit the original cflags, so clang falls back to the default target architecture when building it, typically this would be x86 when cross-compiling.

Quoted 11 lines
Quoted 4 lines

Add $(CLANG_FLAGS) everywhere so we pass the correct --target=s390x-linux option when cross-compiling.

Quoted 4 lines
---
 arch/s390/Makefile           | 4 ++--
 arch/s390/purgatory/Makefile | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

Applied, thanks.

#4 lore raw

PATCH v2 3/4 s390: drop CONFIG_VIRT_TO_BUS

In reply to Arnd Bergmann

VIRT_TO_BUS is only used for legacy device PCI and ISA drivers using virt_to_bus() instead of the streaming DMA mapping API, and the remaining drivers generally don't work on 64-bit architectures.

Two of these drivers also cause a build warning on s390, so instead of trying to fix that, let's just disable the option as we do on most architectures now.

---
 arch/s390/Kconfig | 1 -
 1 file changed, 1 deletion(-)
arch/s390/Kconfig +0 -1
index 1a2eec61196d..25e0e7375166 100644
@@ -188,7 +188,6 @@ config S390
 	select TTY
 	select VIRT_CPU_ACCOUNTING
 	select ARCH_HAS_SCALED_CPUTIME
-	select VIRT_TO_BUS
 	select HAVE_NMI
 
 
Signature · 1 line
2.20.0
#5 lore raw

Re: [PATCH v2 3/4] s390: drop CONFIG_VIRT_TO_BUS

Quoted 4 lines · Arnd Bergmann

VIRT_TO_BUS is only used for legacy device PCI and ISA drivers using virt_to_bus() instead of the streaming DMA mapping API, and the remaining drivers generally don't work on 64-bit architectures.

Quoted 8 lines

Two of these drivers also cause a build warning on s390, so instead of trying to fix that, let's just disable the option as we do on most architectures now.

---
 arch/s390/Kconfig | 1 -
 1 file changed, 1 deletion(-)

Applied, thanks.

#6 lore raw

PATCH v2 4/4 s390: fix clang -Wpointer-sign warnigns in boot code

In reply to Arnd Bergmann

The arch/s390/boot directory is built with its own set of compiler options that does not include -Wno-pointer-sign like the rest of the kernel does, this causes a lot of harmess but correct warnings when building with clang.

For the atomics, we can add type casts to avoid the warnings, for everything else the easiest way is to slightly adapt the types to be more consistent.

---
 arch/s390/boot/ipl_parm.c       |  2 +-
 arch/s390/include/asm/bitops.h  | 12 ++++++------
 arch/s390/include/asm/ebcdic.h  |  2 +-
 arch/s390/include/asm/lowcore.h |  2 +-
 drivers/s390/char/sclp.h        |  4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)
arch/s390/boot/ipl_parm.c +1 -1
index 36beb56de021..3f2f0a9f1dad 100644
@@ -51,7 +51,7 @@ void store_ipl_parmblock(void)
 		early_ipl_block_valid = 1;
 }
 
-static size_t scpdata_length(const char *buf, size_t count)
+static size_t scpdata_length(const u8 *buf, size_t count)
 {
 	while (count) {
 		if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
arch/s390/include/asm/bitops.h +6 -6
index d1f8a4d94cca..9900d655014c 100644
@@ -73,7 +73,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *ptr)
 	}
 #endif
 	mask = 1UL << (nr & (BITS_PER_LONG - 1));
-	__atomic64_or(mask, addr);
+	__atomic64_or(mask, (long *)addr);
 }
 
 static inline void clear_bit(unsigned long nr, volatile unsigned long *ptr)
@@ -94,7 +94,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *ptr)
 	}
 #endif
 	mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
-	__atomic64_and(mask, addr);
+	__atomic64_and(mask, (long *)addr);
 }
 
 static inline void change_bit(unsigned long nr, volatile unsigned long *ptr)
@@ -115,7 +115,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *ptr)
 	}
 #endif
 	mask = 1UL << (nr & (BITS_PER_LONG - 1));
-	__atomic64_xor(mask, addr);
+	__atomic64_xor(mask, (long *)addr);
 }
 
 static inline int
@@ -125,7 +125,7 @@ test_and_set_bit(unsigned long nr, volatile unsigned long *ptr)
 	unsigned long old, mask;
 
 	mask = 1UL << (nr & (BITS_PER_LONG - 1));
-	old = __atomic64_or_barrier(mask, addr);
+	old = __atomic64_or_barrier(mask, (long *)addr);
 	return (old & mask) != 0;
 }
 
@@ -136,7 +136,7 @@ test_and_clear_bit(unsigned long nr, volatile unsigned long *ptr)
 	unsigned long old, mask;
 
 	mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
-	old = __atomic64_and_barrier(mask, addr);
+	old = __atomic64_and_barrier(mask, (long *)addr);
 	return (old & ~mask) != 0;
 }
 
@@ -147,7 +147,7 @@ test_and_change_bit(unsigned long nr, volatile unsigned long *ptr)
 	unsigned long old, mask;
 
 	mask = 1UL << (nr & (BITS_PER_LONG - 1));
-	old = __atomic64_xor_barrier(mask, addr);
+	old = __atomic64_xor_barrier(mask, (long *)addr);
 	return (old & mask) != 0;
 }
 
arch/s390/include/asm/ebcdic.h +1 -1
index 29441beb92e6..d3ce6adacb10 100644
@@ -20,7 +20,7 @@ extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */
 extern __u8 _ebc_toupper[256]; /* EBCDIC -> uppercase */
 
 static inline void
-codepage_convert(const __u8 *codepage, volatile __u8 * addr, unsigned long nr)
+codepage_convert(const __u8 *codepage, volatile char* addr, unsigned long nr)
 {
 	if (nr-- <= 0)
 		return;
arch/s390/include/asm/lowcore.h +1 -1
index cc0947e08b6f..f3a637afd485 100644
@@ -128,7 +128,7 @@ struct lowcore {
 	/* SMP info area */
 	__u32	cpu_nr;				/* 0x0398 */
 	__u32	softirq_pending;		/* 0x039c */
-	__u32	preempt_count;			/* 0x03a0 */
+	__s32	preempt_count;			/* 0x03a0 */
 	__u32	spinlock_lockval;		/* 0x03a4 */
 	__u32	spinlock_index;			/* 0x03a8 */
 	__u32	fpu_flags;			/* 0x03ac */
drivers/s390/char/sclp.h +2 -2
index 367e9d384d85..5918479ffa0e 100644
@@ -365,14 +365,14 @@ sclp_ascebc(unsigned char ch)
 
 /* translate string from EBCDIC to ASCII */
 static inline void
-sclp_ebcasc_str(unsigned char *str, int nr)
+sclp_ebcasc_str(char *str, int nr)
 {
 	(MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
 }
 
 /* translate string from ASCII to EBCDIC */
 static inline void
-sclp_ascebc_str(unsigned char *str, int nr)
+sclp_ascebc_str(char *str, int nr)
 {
 	(MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
 }
Signature · 1 line
2.20.0
#7 lore raw

Re: [PATCH v2 4/4] s390: fix clang -Wpointer-sign warnigns in boot code

Quoted 4 lines · Arnd Bergmann

The arch/s390/boot directory is built with its own set of compiler options that does not include -Wno-pointer-sign like the rest of the kernel does, this causes a lot of harmess but correct warnings

s/harmess/harmless/

Quoted 78 lines

when building with clang.

For the atomics, we can add type casts to avoid the warnings, for everything else the easiest way is to slightly adapt the types to be more consistent.

---
 arch/s390/boot/ipl_parm.c       |  2 +-
 arch/s390/include/asm/bitops.h  | 12 ++++++------
 arch/s390/include/asm/ebcdic.h  |  2 +-
 arch/s390/include/asm/lowcore.h |  2 +-
 drivers/s390/char/sclp.h        |  4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)
arch/s390/boot/ipl_parm.c +1 -1
index 36beb56de021..3f2f0a9f1dad 100644
@@ -51,7 +51,7 @@ void store_ipl_parmblock(void)
                early_ipl_block_valid = 1;
 }
 
-static size_t scpdata_length(const char *buf, size_t count)
+static size_t scpdata_length(const u8 *buf, size_t count)
 {
        while (count) {
                if (buf[count - 1] != '\0' && buf[count - 1] != ' ')
arch/s390/include/asm/bitops.h +5 -5
index d1f8a4d94cca..9900d655014c 100644
@@ -73,7 +73,7 @@ static inline void set_bit(unsigned long nr, volatile unsigned long *ptr)
        }
 #endif
        mask = 1UL << (nr & (BITS_PER_LONG - 1));
-       __atomic64_or(mask, addr);
+       __atomic64_or(mask, (long *)addr);
 }
 
 static inline void clear_bit(unsigned long nr, volatile unsigned long *ptr)
@@ -94,7 +94,7 @@ static inline void clear_bit(unsigned long nr, volatile unsigned long *ptr)
        }
 #endif
        mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
-       __atomic64_and(mask, addr);
+       __atomic64_and(mask, (long *)addr);
 }
 
 static inline void change_bit(unsigned long nr, volatile unsigned long *ptr)
@@ -115,7 +115,7 @@ static inline void change_bit(unsigned long nr, volatile unsigned long *ptr)
        }
 #endif
        mask = 1UL << (nr & (BITS_PER_LONG - 1));
-       __atomic64_xor(mask, addr);
+       __atomic64_xor(mask, (long *)addr);
 }
 
 static inline int
@@ -125,7 +125,7 @@ test_and_set_bit(unsigned long nr, volatile unsigned long *ptr)
        unsigned long old, mask;
 
        mask = 1UL << (nr & (BITS_PER_LONG - 1));
-       old = __atomic64_or_barrier(mask, addr);
+       old = __atomic64_or_barrier(mask, (long *)addr);
        return (old & mask) != 0;
 }
 
@@ -136,7 +136,7 @@ test_and_clear_bit(unsigned long nr, volatile unsigned long *ptr)
        unsigned long old, mask;
 
        mask = ~(1UL << (nr & (BITS_PER_LONG - 1)));
-       old = __atomic64_and_barrier(mask, addr);
+       old = __atomic64_and_barrier(mask, (long *)addr);
        return (old & ~mask) != 0;
 }
 

arch/s390/include/asm/bitops.h test_and_change_bit(unsigned long nr, volatile unsigned long *ptr) · line 150

Quoted 5 lines
arch/s390/include/asm/bitops.h +1 -1
@@ -147,7 +147,7 @@ test_and_change_bit(unsigned long nr, volatile unsigned long *ptr)
        unsigned long old, mask;
 
        mask = 1UL << (nr & (BITS_PER_LONG - 1));
-       old = __atomic64_xor_barrier(mask, addr);
+       old = __atomic64_xor_barrier(mask, (long *)addr);

Thanks for the follow up. This hunk and above all LGTM.

Quoted 8 lines
arch/s390/include/asm/bitops.h +0 -0
        return (old & mask) != 0;
 }
 
arch/s390/include/asm/ebcdic.h +0 -0
index 29441beb92e6..d3ce6adacb10 100644

arch/s390/include/asm/ebcdic.h extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */ · line 26

Quoted 8 lines
arch/s390/include/asm/ebcdic.h +1 -1
@@ -20,7 +20,7 @@ extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */
 extern __u8 _ebc_toupper[256]; /* EBCDIC -> uppercase */
 
 static inline void
-codepage_convert(const __u8 *codepage, volatile __u8 * addr, unsigned long nr)
+codepage_convert(const __u8 *codepage, volatile char* addr, unsigned long nr)
 {
        if (nr-- <= 0)
                return;

There are many call sites of ASCEBC which is defined in terms of this function. Do they all use char*? grep shows an explicit cast to unsigned char* in drivers/s390/char/tape_std.c for example.

arch/s390/include/asm/lowcore.h struct lowcore { · line 131

Quoted 10 lines
arch/s390/include/asm/lowcore.h +1 -1
index cc0947e08b6f..f3a637afd485 100644
@@ -128,7 +128,7 @@ struct lowcore {
        /* SMP info area */
        __u32   cpu_nr;                         /* 0x0398 */
        __u32   softirq_pending;                /* 0x039c */
-       __u32   preempt_count;                  /* 0x03a0 */
+       __s32   preempt_count;                  /* 0x03a0 */

This change is less obvious. Do you still have the warning for that this hunk fixes?

Quoted 27 lines
arch/s390/include/asm/lowcore.h +0 -0
        __u32   spinlock_lockval;               /* 0x03a4 */
        __u32   spinlock_index;                 /* 0x03a8 */
        __u32   fpu_flags;                      /* 0x03ac */
drivers/s390/char/sclp.h +2 -3
index 367e9d384d85..5918479ffa0e 100644
@@ -365,14 +365,14 @@ sclp_ascebc(unsigned char ch)
 
 /* translate string from EBCDIC to ASCII */
 static inline void
-sclp_ebcasc_str(unsigned char *str, int nr)
+sclp_ebcasc_str(char *str, int nr)
 {
        (MACHINE_IS_VM) ? EBCASC(str, nr) : EBCASC_500(str, nr);
 }
 
 /* translate string from ASCII to EBCDIC */
 static inline void
-sclp_ascebc_str(unsigned char *str, int nr)
+sclp_ascebc_str(char *str, int nr)
 {
        (MACHINE_IS_VM) ? ASCEBC(str, nr) : ASCEBC_500(str, nr);
 }
--

2.20.0

Signature · 2 lines
Thanks,
~Nick Desaulniers
#8 lore raw

Re: [PATCH v2 4/4] s390: fix clang -Wpointer-sign warnigns in boot code

Quoted 13 lines · Nick Desaulniers' via Clang Built Linux

arch/s390/include/asm/ebcdic.h extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */ · line 26

Quoted 9 lines
arch/s390/include/asm/ebcdic.h +1 -1
@@ -20,7 +20,7 @@ extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */
 extern __u8 _ebc_toupper[256]; /* EBCDIC -> uppercase */
 
 static inline void
-codepage_convert(const __u8 *codepage, volatile __u8 * addr, unsigned long nr)
+codepage_convert(const __u8 *codepage, volatile char* addr, unsigned long nr)
 {
        if (nr-- <= 0)
                return;

There are many call sites of ASCEBC which is defined in terms of this function. Do they all use char*? grep shows an explicit cast to unsigned char* in drivers/s390/char/tape_std.c for example.

Generally speaking, the kernel is full of Wpointer-sign warnings, that's why this warning is disabled in the top-level Makefile by default. My patch fixes the ones in the s390 boot code that is not built with those default flags, but I made no attempt to fix the rest of the kernel.

Fun fact: on most architectures, 'char' is signed, but on s390 and 32-bit arm it is unsigned. The compiler treats 'char', 'unsigned char' and 'signed char'
as three distinct types here for that reason.

Quoted 5 lines
Quoted 5 lines
arch/s390/include/asm/lowcore.h +0 -0
index cc0947e08b6f..f3a637afd485 100644
@@ -128,7 +128,7 @@ struct lowcore {
Quoted 8 lines

arch/s390/include/asm/lowcore.h struct lowcore { · line 131

Quoted 5 lines
arch/s390/include/asm/lowcore.h +1 -1
        /* SMP info area */
        __u32   cpu_nr;                         /* 0x0398 */
        __u32   softirq_pending;                /* 0x039c */
-       __u32   preempt_count;                  /* 0x03a0 */
+       __s32   preempt_count;                  /* 0x03a0 */

This change is less obvious. Do you still have the warning for that this hunk fixes?

I can't find it now, but there are multiple users that would cause this, like:

static inline void preempt_count_set(int pc)

{
        int old, new;

        do {
                old = READ_ONCE(S390_lowcore.preempt_count);
                new = (old & PREEMPT_NEED_RESCHED) |
                        (pc & ~PREEMPT_NEED_RESCHED);
        } while (__atomic_cmpxchg(&S390_lowcore.preempt_count,
                                  old, new) != old);
}

Arnd

Reviewed-by
#9 lore raw

Re: [PATCH v2 4/4] s390: fix clang -Wpointer-sign warnigns in boot code

Quoted 18 lines · Arnd Bergmann
Quoted 13 lines · Nick Desaulniers' via Clang Built Linux

arch/s390/include/asm/ebcdic.h extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */ · line 26

Quoted 9 lines
arch/s390/include/asm/ebcdic.h +1 -1
@@ -20,7 +20,7 @@ extern __u8 _ebc_tolower[256]; /* EBCDIC -> lowercase */
 extern __u8 _ebc_toupper[256]; /* EBCDIC -> uppercase */
 
 static inline void
-codepage_convert(const __u8 *codepage, volatile __u8 * addr, unsigned long nr)
+codepage_convert(const __u8 *codepage, volatile char* addr, unsigned long nr)
 {
        if (nr-- <= 0)
                return;

There are many call sites of ASCEBC which is defined in terms of this function. Do they all use char*? grep shows an explicit cast to unsigned char* in drivers/s390/char/tape_std.c for example.

Quoted 4 lines

Generally speaking, the kernel is full of Wpointer-sign warnings, that's why this warning is disabled in the top-level Makefile by default. My patch fixes the ones in the s390 boot code that is not built with those default flags, but I made no attempt to fix the rest of the kernel.

Right, sorry, I forgot about that. This patch looks good to me.

Quoted 5 lines

Fun fact: on most architectures, 'char' is signed, but on s390 and 32-bit arm it is unsigned. The compiler treats 'char', 'unsigned char' and 'signed char'
as three distinct types here for that reason.

I think I recall reading about that in:
https://www.amazon.com/ARM-System-Developers-Guide-Architecture/dp/1558608745
(I'll try to dig it up and post what the explanation was).

Signature · 2 lines
Thanks,
~Nick Desaulniers
#10 lore raw

Re: [PATCH v2 4/4] s390: fix clang -Wpointer-sign warnigns in boot code

In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

The arch/s390/boot directory is built with its own set of compiler options that does not include -Wno-pointer-sign like the rest of the kernel does, this causes a lot of harmess but correct warnings when building with clang.

For the atomics, we can add type casts to avoid the warnings, for everything else the easiest way is to slightly adapt the types to be more consistent.

Quoted 8 lines
---
 arch/s390/boot/ipl_parm.c       |  2 +-
 arch/s390/include/asm/bitops.h  | 12 ++++++------
 arch/s390/include/asm/ebcdic.h  |  2 +-
 arch/s390/include/asm/lowcore.h |  2 +-
 drivers/s390/char/sclp.h        |  4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)

Applied, with typo fix and a simple coding style issue. Thanks!

#11 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

llvm does does not understand -march=z9-109 and older target specifiers, so disable the respective Kconfig settings and the logic to make the boot code work on old systems when building with clang.

Part of the early boot code is normally compiled with -march=z900 for maximum compatibility. This also has to get changed with clang to the oldest supported ISA, which is -march=z10 here.

Quoted 5 lines
---
 arch/s390/Kconfig       |  6 ++++++
 arch/s390/boot/Makefile | 18 ++++++++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

Applied, thanks.