linux-stable/arch
Michael Ellerman af4cff0dd6 powerpc/uaccess: Fix build errors seen with GCC 13/14
commit 2d43cc701b upstream.

Building ppc64le_defconfig with GCC 14 fails with assembler errors:

    CC      fs/readdir.o
  /tmp/ccdQn0mD.s: Assembler messages:
  /tmp/ccdQn0mD.s:212: Error: operand out of domain (18 is not a multiple of 4)
  /tmp/ccdQn0mD.s:226: Error: operand out of domain (18 is not a multiple of 4)
  ... [6 lines]
  /tmp/ccdQn0mD.s:1699: Error: operand out of domain (18 is not a multiple of 4)

A snippet of the asm shows:

  # ../fs/readdir.c:210:         unsafe_copy_dirent_name(dirent->d_name, name, namlen, efault_end);
         ld 9,0(29)       # MEM[(u64 *)name_38(D) + _88 * 1], MEM[(u64 *)name_38(D) + _88 * 1]
  # 210 "../fs/readdir.c" 1
         1:      std 9,18(8)     # put_user       # *__pus_addr_52, MEM[(u64 *)name_38(D) + _88 * 1]

The 'std' instruction requires a 4-byte aligned displacement because
it is a DS-form instruction, and as the assembler says, 18 is not a
multiple of 4.

A similar error is seen with GCC 13 and CONFIG_UBSAN_SIGNED_WRAP=y.

The fix is to change the constraint on the memory operand to put_user(),
from "m" which is a general memory reference to "YZ".

The "Z" constraint is documented in the GCC manual PowerPC machine
constraints, and specifies a "memory operand accessed with indexed or
indirect addressing". "Y" is not documented in the manual but specifies
a "memory operand for a DS-form instruction". Using both allows the
compiler to generate a DS-form "std" or X-form "stdx" as appropriate.

The change has to be conditional on CONFIG_PPC_KERNEL_PREFIXED because
the "Y" constraint does not guarantee 4-byte alignment when prefixed
instructions are enabled.

Unfortunately clang doesn't support the "Y" constraint so that has to be
behind an ifdef.

Although the build error is only seen with GCC 13/14, that appears
to just be luck. The constraint has been incorrect since it was first
added.

Fixes: c20beffeec ("powerpc/uaccess: Use flexible addressing with __put_user()/__get_user()")
Cc: stable@vger.kernel.org # v5.10+
Suggested-by: Kewen Lin <linkw@gcc.gnu.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240529123029.146953-1-mpe@ellerman.id.au
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-06-21 14:38:26 +02:00
..
alpha rtc: Add support for configuring the UIP timeout for RTC reads 2024-01-31 16:18:56 -08:00
arc ARC: [plat-hsdk]: Remove misplaced interrupt-cells property 2024-05-02 16:32:33 +02:00
arm ARM: dts: samsung: exynos4412-origen: fix keypad no-autorepeat 2024-06-16 13:47:45 +02:00
arm64 KVM: arm64: AArch32: Fix spurious trapping of conditional instructions 2024-06-16 13:47:38 +02:00
csky work around gcc bugs with 'asm goto' with outputs 2024-02-23 09:24:47 +01:00
hexagon hexagon: vmlinux.lds.S: handle attributes section 2024-04-03 15:28:55 +02:00
ia64 cpu-hotplug: Provide prototypes for arch CPU registration 2023-10-11 14:27:37 +02:00
loongarch LoongArch: Override higher address bits in JUMP_VIRT_ADDR 2024-06-16 13:47:39 +02:00
m68k m68k: mac: Fix reboot hang on Mac IIci 2024-06-12 11:11:51 +02:00
microblaze microblaze: Remove early printk call from cpuinfo-static.c 2024-06-12 11:12:23 +02:00
mips MIPS: scall: Save thread_info.syscall unconditionally on entry 2024-05-17 12:02:15 +02:00
nios2 mm: Introduce flush_cache_vmap_early() 2024-02-16 19:10:52 +01:00
openrisc openrisc: traps: Don't send signals to kernel mode threads 2024-06-12 11:11:42 +02:00
parisc parisc: Define sigset_t in parisc uapi header 2024-06-16 13:47:45 +02:00
powerpc powerpc/uaccess: Fix build errors seen with GCC 13/14 2024-06-21 14:38:26 +02:00
riscv RISC-V: KVM: Fix incorrect reg_subtype labels in kvm_riscv_vcpu_set_reg_isa_ext function 2024-06-21 14:38:14 +02:00
s390 s390/cpacf: Make use of invalid opcode produce a link error 2024-06-16 13:47:46 +02:00
sh Revert "sh: Handle calling csum_partial with misaligned data" 2024-06-12 11:11:48 +02:00
sparc sparc: move struct termio to asm/termios.h 2024-06-16 13:47:44 +02:00
um um: Fix the declaration of kasan_map_memory 2024-06-12 11:12:42 +02:00
x86 KVM: SEV-ES: Delegate LBR virtualization to the processor 2024-06-21 14:38:15 +02:00
xtensa xtensa: fix MAKE_PC_FROM_RA second argument 2024-05-17 12:02:32 +02:00
.gitignore
Kconfig cpu: Re-enable CPU mitigations by default for !X86 architectures 2024-05-02 16:32:44 +02:00