linux/arch
Jordan Niethe 1f3e93d881 powerpc/64: Set up a kernel stack for secondaries before cpu_restore()
[ Upstream commit 3c0b976bf2 ]

Currently in generic_secondary_smp_init(), cur_cpu_spec->cpu_restore()
is called before a stack has been set up in r1. This was previously fine
as the cpu_restore() functions were implemented in assembly and did not
use a stack. However commit 5a61ef74f2 ("powerpc/64s: Support new
device tree binding for discovering CPU features") used
__restore_cpu_cpufeatures() as the cpu_restore() function for a
device-tree features based cputable entry. This is a C function and
hence uses a stack in r1.

generic_secondary_smp_init() is entered on the secondary cpus via the
primary cpu using the OPAL call opal_start_cpu(). In OPAL, each hardware
thread has its own stack. The OPAL call is ran in the primary's hardware
thread. During the call, a job is scheduled on a secondary cpu that will
start executing at the address of generic_secondary_smp_init().  Hence
the value that will be left in r1 when the secondary cpu enters the
kernel is part of that secondary cpu's individual OPAL stack. This means
that __restore_cpu_cpufeatures() will write to that OPAL stack. This is
not horribly bad as each hardware thread has its own stack and the call
that enters the kernel from OPAL never returns, but it is still wrong
and should be corrected.

Create the temp kernel stack before calling cpu_restore().

As noted by mpe, for a kexec boot, the secondary CPUs are released from
the spin loop at address 0x60 by smp_release_cpus() and then jump to
generic_secondary_smp_init(). The call to smp_release_cpus() is in
setup_arch(), and it comes before the call to emergency_stack_init().
emergency_stack_init() allocates an emergency stack in the PACA for each
CPU.  This address in the PACA is what is used to set up the temp kernel
stack in generic_secondary_smp_init(). Move releasing the secondary CPUs
to after the PACAs have been allocated an emergency stack, otherwise the
PACA stack pointer will contain garbage and hence the temp kernel stack
created from it will be broken.

Fixes: 5a61ef74f2 ("powerpc/64s: Support new device tree binding for discovering CPU features")
Signed-off-by: Jordan Niethe <jniethe5@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201014072837.24539-1-jniethe5@gmail.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-12-30 11:25:51 +01:00
..
alpha alpha: fix annotation of io{read,write}{16,32}be() 2020-08-26 10:31:02 +02:00
arc ARC: stack unwinding: don't assume non-current task is sleeping 2020-12-30 11:25:38 +01:00
arm ARM: p2v: fix handling of LPAE translation in BE mode 2020-12-30 11:25:50 +01:00
arm64 arm64: syscall: exit userspace before unmasking exceptions 2020-12-30 11:25:46 +01:00
c6x
h8300
hexagon hexagon: define ioremap_uc 2020-05-10 10:30:11 +02:00
ia64 ia64: fix build error with !COREDUMP 2020-11-05 11:08:52 +01:00
m68k m68k: q40: Fix info-leak in rtc_ioctl 2020-10-01 13:14:24 +02:00
microblaze microblaze: Prevent the overflow of the start 2020-02-24 08:34:53 +01:00
mips MIPS: Alchemy: Fix memleak in alchemy_clk_setup_cpu 2020-11-24 13:27:22 +01:00
nds32 nds32: Fix the items of hwcap_str ordering issue. 2019-12-13 08:51:35 +01:00
nios2 nios2: ksyms: Add missing symbol exports 2020-01-27 14:50:30 +01:00
openrisc openrisc: Fix cache API compile issue when not inlining 2020-09-23 12:10:58 +02:00
parisc parisc: Implement __smp_store_release and __smp_load_acquire barriers 2020-08-19 08:15:07 +02:00
powerpc powerpc/64: Set up a kernel stack for secondaries before cpu_restore() 2020-12-30 11:25:51 +01:00
riscv riscv: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO 2020-11-05 11:08:41 +01:00
s390 s390/cpum_sf.c: fix file permission for cpum_sfb_size 2020-11-24 13:27:26 +01:00
sh sh: landisk: Add missing initialization of sh_io_port_base 2020-08-21 11:05:39 +02:00
sparc sparc64: remove mm_cpumask clearing to fix kthread_use_mm race 2020-11-05 11:08:38 +01:00
um um: change sigio_spinlock to a mutex 2020-11-05 11:08:39 +01:00
unicore32
x86 x86/apic: Fix x2apic enablement without interrupt remapping 2020-12-30 11:25:50 +01:00
xtensa xtensa: uaccess: Add missing __user to strncpy_from_user() prototype 2020-12-02 08:48:10 +01:00
.gitignore
Kconfig mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race 2020-11-05 11:08:38 +01:00