[PATCH] ARC: avoid unwanted gcc optimizations in atomic operations
From: Pavel Kozlov Notify a compiler about write operations and prevent unwanted optimizations. Add the "memory" clobber to the clobber list. An obvious problem with unwanted compiler optimizations appeared after the cpumask optimization commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"). After this commit the SMP kernels for ARC no longer loads because of failed assert in the percpu allocator initialization routine: percpu: BUG: failure at mm/percpu.c:2981/pcpu_build_alloc_info()! The write operation performed by the scond instruction in the atomic inline asm code is not properly passed to the compiler. The compiler cannot correctly optimize a nested loop that runs through the cpumask in the pcpu_build_alloc_info() function. Add the "memory" clobber to fix this. Link: https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/135 Cc: # v6.3+ Signed-off-by: Pavel Kozlov --- arch/arc/include/asm/atomic-llsc.h| 6 +++--- arch/arc/include/asm/atomic64-arcv2.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/arc/include/asm/atomic-llsc.h b/arch/arc/include/asm/atomic-llsc.h index 1b0ffaeee16d..5258cb81a16b 100644 --- a/arch/arc/include/asm/atomic-llsc.h +++ b/arch/arc/include/asm/atomic-llsc.h @@ -18,7 +18,7 @@ static inline void arch_atomic_##op(int i, atomic_t *v) \ : [val] "=&r" (val) /* Early clobber to prevent reg reuse */ \ : [ctr] "r" (&v->counter), /* Not "m": llock only supports reg direct addr mode */ \ [i] "ir"(i) \ - : "cc");\ + : "cc", "memory"); \ } \ #define ATOMIC_OP_RETURN(op, asm_op) \ @@ -34,7 +34,7 @@ static inline int arch_atomic_##op##_return_relaxed(int i, atomic_t *v) \ : [val] "=&r" (val) \ : [ctr] "r" (&v->counter), \ [i] "ir"(i) \ - : "cc");\ + : "cc", "memory"); \ \ return val; \ } @@ -56,7 +56,7 @@ static inline int arch_atomic_fetch_##op##_relaxed(int i, atomic_t *v)\ [orig] "=&r" (orig) \ : [ctr] "r" (&v->counter), \ [i] "ir"(i) \ - : "cc");\ + : "cc", "memory"); \ \ return orig;\ } diff --git a/arch/arc/include/asm/atomic64-arcv2.h b/arch/arc/include/asm/atomic64-arcv2.h index 6b6db981967a..9b5791b85471 100644 --- a/arch/arc/include/asm/atomic64-arcv2.h +++ b/arch/arc/include/asm/atomic64-arcv2.h @@ -60,7 +60,7 @@ static inline void arch_atomic64_##op(s64 a, atomic64_t *v) \ " bnz 1b \n" \ : "=&r"(val)\ : "r"(&v->counter), "ir"(a) \ - : "cc");\ + : "cc", "memory"); \ } \ #define ATOMIC64_OP_RETURN(op, op1, op2) \ @@ -77,7 +77,7 @@ static inline s64 arch_atomic64_##op##_return_relaxed(s64 a, atomic64_t *v) \ " bnz 1b \n" \ : [val] "=&r"(val) \ : "r"(&v->counter), "ir"(a) \ - : "cc");/* memory clobber comes from smp_mb() */\ + : "cc", "memory"); \ \ return val; \ } @@ -99,7 +99,7 @@ static inline s64 arch_atomic64_fetch_##op##_relaxed(s64 a, atomic64_t *v)\ " bnz 1b \n" \ : "=&r"(orig), "=&r"(val) \ : "r"(&v->counter), "ir"(a) \ - : "cc");/* memory clobber comes from
Re: [PATCH] ARC: avoid unwanted gcc optimizations in atomic operations
On 8/15/23 08:11, pavel.koz...@synopsys.com wrote: From: Pavel Kozlov Notify a compiler about write operations and prevent unwanted optimizations. Add the "memory" clobber to the clobber list. An obvious problem with unwanted compiler optimizations appeared after the cpumask optimization commit 596ff4a09b89 ("cpumask: re-introduce constant-sized cpumask optimizations"). After this commit the SMP kernels for ARC no longer loads because of failed assert in the percpu allocator initialization routine: percpu: BUG: failure at mm/percpu.c:2981/pcpu_build_alloc_info()! The write operation performed by the scond instruction in the atomic inline asm code is not properly passed to the compiler. The compiler cannot correctly optimize a nested loop that runs through the cpumask in the pcpu_build_alloc_info() function. Add the "memory" clobber to fix this. Link:https://github.com/foss-for-synopsys-dwc-arc-processors/linux/issues/135 Cc: # v6.3+ Signed-off-by: Pavel Kozlov Acked-by: Vineet Gupta Fixes: b64be6836993c431e ("ARC: atomics: implement relaxed variants") Before that commit, atomic ops could elide memory clobber because the trailing smp_mb() did that anyways. However after that commit, the smp_mb() was optional for relaxed variants and thus needs clobber. ___ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc
Re: {standard input}:1727: Error: operand out of range (-132 is not between -128 and 127)
On Tue, Aug 15, 2023 at 07:34:04AM +, Liu, Yujie wrote: > Hi Paul, > > On Fri, 2023-08-11 at 08:41 -0700, Paul E. McKenney wrote: > > On Fri, Aug 11, 2023 at 01:02:12PM +0800, kernel test robot wrote: > > > tree: > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master > > > head: 25aa0bebba72b318e71fe205bfd1236550cc9534 > > > commit: a6889becb05394255c80b62103677e3b095726a9 refscale: Add tests > > > using SLAB_TYPESAFE_BY_RCU > > > date: 7 months ago > > > config: arc-randconfig-r006-20230811 > > > (https://download.01.org/0day-ci/archive/20230811/202308111233.rbf5c0jd-...@intel.com/config) > > > compiler: arceb-elf-gcc (GCC) 12.3.0 > > > reproduce: > > > (https://download.01.org/0day-ci/archive/20230811/202308111233.rbf5c0jd-...@intel.com/reproduce) > > > > > > If you fix the issue in a separate patch/commit (i.e. not just a new > > > version of > > > the same patch/commit), kindly add following tags > > > > Reported-by: kernel test robot > > > > Closes: > > > > https://lore.kernel.org/oe-kbuild-all/202308111233.rbf5c0jd-...@intel.com/ > > > > > > All errors (new ones prefixed by >>): > > > > > > {standard input}: Assembler messages: > > > > > {standard input}:1727: Error: operand out of range (-132 is not > > > > > between -128 and 127) > > > > I am not seeing any inline assembly in that patch, so I have to suspect > > a bug in arch code or the compiler backend for arc. > > > > Or is there something that I am missing here? > > We looked into this case a little bit. The assembler error popped up > when building kernel/rcu/refscale.o > > $make W=1 --keep-going CROSS_COMPILE=arceb-elf- ARCH=arc kernel/rcu/refscale.o > ... > CC [M] kernel/rcu/refscale.o > {standard input}: Assembler messages: > {standard input}:1727: Error: operand out of range (-132 is not between -128 > and 127) > make[3]: *** [scripts/Makefile.build:252: kernel/rcu/refscale.o] Error 1 > make[2]: *** [scripts/Makefile.build:504: kernel/rcu] Error 2 > make[2]: Target 'kernel/rcu/refscale.o' not remade because of errors. > make[1]: *** [scripts/Makefile.build:504: kernel] Error 2 > make[1]: Target 'kernel/rcu/refscale.o' not remade because of errors. > make: *** [Makefile:2008: .] Error 2 > make: Target 'kernel/rcu/refscale.o' not remade because of errors. > > We did some assembly and disassembly tricks: > > 1721 .L334: > 1722 ld_sr0,[r14,52] ;15 > 1723 brgt r0, r19, @.L335 > 1724 ld_sr0,[r13,120];15 > 1725 breq_s r0, 0, @.L337 > 1726 jl [r17] > 1727 brne_s r0, 0, @.L337<--- > 1728 mov_s r2,20 ;3 > 1729 mov_s r1,0;3 > 1730 mov_s r0,sp ;4 > 1731 jl [r20] > 1732 mov_s r1,0;3 > 1733 mov_s r0,sp ;4 > 1734 jl @init_wait_entry > 1735 .align 2 > > This assembly instruction at line 1727 points to the code in main_func, > but main_func is not touched by commit a6889becb053. > > d6e: 860dld_sr0,[r14,0x34] > d70: 0b59 a002 brlt.nt r19,r0,-168 ;cc8 > return arch_atomic_read(v); > d74: 851eld_sr0,[r13,0x78] > wait_event(main_wq, > d76: e842breq_s r0,0,-124 ;cf8 > d78: 2022 0440 jl [r17] > d7c: e8bebrne_s r0,0,124;df8 ><-- > d7e: da14mov_s r2,0x14 > d80: 702cmov_s r1,0 > d82: 4083mov_s r0,sp > d84: 2022 0500 jl [r20] > d88: 702cmov_s r1,0 > d8a: 4083mov_s r0,sp > d8c: 2022 0f80 jl 0 > > We also tried on the parent commit 3c6496c86e48. It builds fine without > that assembler error, and corresponding disassembly is: > > afe: 860dld_sr0,[r14,0x34] > b00: 0b5d a002 brlt.nt r19,r0,-164 ;a5c > return arch_atomic_read(v); > b04: 8518ld_sr0,[r13,0x60] > wait_event(main_wq, > b06: e844breq_s r0,0,-120 ;a8c > b08: 2022 0440 jl [r17] > b0c: e8c0brne_s r0,0,-128 ;a8c ><-- > b0e: da14mov_s r2,0x14 > b10: 702cmov_s r1,0 > b12: 4083mov_s r0,sp > b14: 2022 0500 jl [r20] > b18: 702cmov_s r1,0 > b1a: 4083mov_s r0,sp > b1c: 2022 0f80 jl 0 > b24: 724cmov_s r2,2 > b26: 4183mov_s r1,sp > b28: 40c3 mov_s r0,0 > b2e: 2022 0f80 jl 0 > > > We are also not sure if this is a bug in arch code or compiler side. > Here we provide above info for your referen
Re: {standard input}:1727: Error: operand out of range (-132 is not between -128 and 127)
+CC Alexey and Claudiu On 8/15/23 09:35, Paul E. McKenney wrote: On Tue, Aug 15, 2023 at 07:34:04AM +, Liu, Yujie wrote: Hi Paul, On Fri, 2023-08-11 at 08:41 -0700, Paul E. McKenney wrote: On Fri, Aug 11, 2023 at 01:02:12PM +0800, kernel test robot wrote: tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 25aa0bebba72b318e71fe205bfd1236550cc9534 commit: a6889becb05394255c80b62103677e3b095726a9 refscale: Add tests using SLAB_TYPESAFE_BY_RCU date: 7 months ago config: arc-randconfig-r006-20230811 (https://download.01.org/0day-ci/archive/20230811/202308111233.rbf5c0jd-...@intel.com/config) compiler: arceb-elf-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230811/202308111233.rbf5c0jd-...@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202308111233.rbf5c0jd-...@intel.com/ All errors (new ones prefixed by >>): {standard input}: Assembler messages: {standard input}:1727: Error: operand out of range (-132 is not between -128 and 127) I am not seeing any inline assembly in that patch, so I have to suspect a bug in arch code or the compiler backend for arc. Or is there something that I am missing here? We looked into this case a little bit. The assembler error popped up when building kernel/rcu/refscale.o $make W=1 --keep-going CROSS_COMPILE=arceb-elf- ARCH=arc kernel/rcu/refscale.o ... CC [M] kernel/rcu/refscale.o {standard input}: Assembler messages: {standard input}:1727: Error: operand out of range (-132 is not between -128 and 127) make[3]: *** [scripts/Makefile.build:252: kernel/rcu/refscale.o] Error 1 make[2]: *** [scripts/Makefile.build:504: kernel/rcu] Error 2 make[2]: Target 'kernel/rcu/refscale.o' not remade because of errors. make[1]: *** [scripts/Makefile.build:504: kernel] Error 2 make[1]: Target 'kernel/rcu/refscale.o' not remade because of errors. make: *** [Makefile:2008: .] Error 2 make: Target 'kernel/rcu/refscale.o' not remade because of errors. We did some assembly and disassembly tricks: 1721 .L334: 1722 ld_sr0,[r14,52] ;15 1723 brgt r0, r19, @.L335 1724 ld_sr0,[r13,120];15 1725 breq_s r0, 0, @.L337 1726 jl [r17] 1727 brne_s r0, 0, @.L337<--- 1728 mov_s r2,20 ;3 1729 mov_s r1,0;3 1730 mov_s r0,sp ;4 1731 jl [r20] 1732 mov_s r1,0;3 1733 mov_s r0,sp ;4 1734 jl @init_wait_entry 1735 .align 2 This assembly instruction at line 1727 points to the code in main_func, but main_func is not touched by commit a6889becb053. d6e: 860dld_sr0,[r14,0x34] d70: 0b59 a002 brlt.nt r19,r0,-168 ;cc8 return arch_atomic_read(v); d74: 851eld_sr0,[r13,0x78] wait_event(main_wq, d76: e842breq_s r0,0,-124 ;cf8 d78: 2022 0440 jl [r17] d7c: e8bebrne_s r0,0,124;df8 <-- d7e: da14mov_s r2,0x14 d80: 702cmov_s r1,0 d82: 4083mov_s r0,sp d84: 2022 0500 jl [r20] d88: 702cmov_s r1,0 d8a: 4083mov_s r0,sp d8c: 2022 0f80 jl 0 We also tried on the parent commit 3c6496c86e48. It builds fine without that assembler error, and corresponding disassembly is: afe: 860dld_sr0,[r14,0x34] b00: 0b5d a002 brlt.nt r19,r0,-164 ;a5c return arch_atomic_read(v); b04: 8518ld_sr0,[r13,0x60] wait_event(main_wq, b06: e844breq_s r0,0,-120 ;a8c b08: 2022 0440 jl [r17] b0c: e8c0brne_s r0,0,-128 ;a8c <-- b0e: da14mov_s r2,0x14 b10: 702cmov_s r1,0 b12: 4083mov_s r0,sp b14: 2022 0500 jl [r20] b18: 702cmov_s r1,0 b1a: 4083mov_s r0,sp b1c: 2022 0f80 jl 0 b24: 724cmov_s r2,2 b26: 4183mov_s r1,sp b28: 40c3 mov_s r0,0 b2e: 2022 0f80 jl 0 We are also not sure if this is a bug in arch code or compiler side. Here we provide above info for your reference. Thank you for looking into this and getting back to me. I added the ARC maintainer and list on CC. Thanx, Paul ___ linux-snps-arc mailin
[PATCH] treewide: drop CONFIG_EMBEDDED
There is only one Kconfig user of CONFIG_EMBEDDED and it can be switched to EXPERT or "if !ARCH_MULTIPLATFORM" (suggested by Arnd). Signed-off-by: Randy Dunlap Cc: Russell King Cc: linux-arm-ker...@lists.infradead.org Cc: Arnd Bergmann Cc: Jason A. Donenfeld Cc: wiregu...@lists.zx2c4.com Cc: linux-a...@vger.kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: Vineet Gupta Cc: Brian Cain Cc: linux-hexa...@vger.kernel.org Cc: Greg Ungerer Cc: Geert Uytterhoeven Cc: linux-m...@lists.linux-m68k.org Cc: Michal Simek Cc: Thomas Bogendoerfer Cc: Dinh Nguyen Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: linux-openr...@vger.kernel.org Cc: linux-m...@vger.kernel.org Cc: Michael Ellerman Cc: Nicholas Piggin Cc: Christophe Leroy Cc: linuxppc-...@lists.ozlabs.org Cc: linux-ri...@lists.infradead.org Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: Yoshinori Sato Cc: Rich Felker Cc: John Paul Adrian Glaubitz Cc: linux...@vger.kernel.org Cc: Max Filippov Cc: Josh Triplett Cc: Masahiro Yamada Cc: linux-kbu...@vger.kernel.org Cc: Andrew Morton --- arch/arc/configs/axs101_defconfig|2 +- arch/arc/configs/axs103_defconfig|2 +- arch/arc/configs/axs103_smp_defconfig|2 +- arch/arc/configs/haps_hs_smp_defconfig |2 +- arch/arc/configs/hsdk_defconfig |2 +- arch/arc/configs/nsim_700_defconfig |2 +- arch/arc/configs/nsimosci_defconfig |2 +- arch/arc/configs/nsimosci_hs_defconfig |2 +- arch/arc/configs/tb10x_defconfig |2 +- arch/arc/configs/vdk_hs38_defconfig |2 +- arch/arc/configs/vdk_hs38_smp_defconfig |2 +- arch/arm/Kconfig |2 +- arch/arm/configs/aspeed_g4_defconfig |2 +- arch/arm/configs/aspeed_g5_defconfig |2 +- arch/arm/configs/at91_dt_defconfig |2 +- arch/arm/configs/axm55xx_defconfig |2 +- arch/arm/configs/bcm2835_defconfig |2 +- arch/arm/configs/clps711x_defconfig |2 +- arch/arm/configs/keystone_defconfig |2 +- arch/arm/configs/lpc18xx_defconfig |2 +- arch/arm/configs/lpc32xx_defconfig |2 +- arch/arm/configs/milbeaut_m10v_defconfig |2 +- arch/arm/configs/moxart_defconfig|2 +- arch/arm/configs/multi_v4t_defconfig |2 +- arch/arm/configs/multi_v7_defconfig |2 +- arch/arm/configs/pxa_defconfig |2 +- arch/arm/configs/qcom_defconfig |2 +- arch/arm/configs/sama5_defconfig |2 +- arch/arm/configs/sama7_defconfig |2 +- arch/arm/configs/socfpga_defconfig |2 +- arch/arm/configs/stm32_defconfig |2 +- arch/arm/configs/tegra_defconfig |2 +- arch/arm/configs/vf610m4_defconfig |2 +- arch/hexagon/configs/comet_defconfig |2 +- arch/m68k/configs/amcore_defconfig |2 +- arch/m68k/configs/m5475evb_defconfig |2 +- arch/m68k/configs/stmark2_defconfig |2 +- arch/microblaze/configs/mmu_defconfig|2 +- arch/mips/configs/ath25_defconfig|2 +- arch/mips/configs/ath79_defconfig|2 +- arch/mips/configs/bcm47xx_defconfig |2 +- arch/mips/configs/ci20_defconfig |2 +- arch/mips/configs/cu1000-neo_defconfig |2 +- arch/mips/configs/cu1830-neo_defconfig |2 +- arch/mips/configs/db1xxx_defconfig |2 +- arch/mips/configs/gcw0_defconfig |2 +- arch/mips/configs/generic_defconfig |2 +- arch/mips/configs/loongson2k_defconfig |2 +- arch/mips/configs/loongson3_defconfig|2 +- arch/mips/configs/malta_qemu_32r6_defconfig |2 +- arch/mips/configs/maltaaprp_defconfig|2 +- arch/mips/configs/maltasmvp_defconfig|2 +- arch/mips/configs/maltasmvp_eva_defconfig|2 +- arch/mips/configs/maltaup_defconfig |2 +- arch/mips/configs/omega2p_defconfig |2 +- arch/mips/configs/pic32mzda_defconfig|2 +- arch/mips/configs/qi_lb60_defconfig |2 +- arch/mips/configs/rs90_defconfig |2 +- arch/mips/configs/rt305x_defconfig |2 +- arch/mips/configs/vocore2_defconfig |2 +- arch/mips/configs/xway_defconfig |2 +