core/cpu: Initialize all cpu thread areas to avoid invalid memory access.
core/cpu: Initialize all cpu thread areas to avoid invalid memory access.

Starting from p10 hostboot will no longer clear all the system memory except
its own space. OPAL uses the memory at SKIBOOT_BASE + SKIBOOT_SIZE for cpu
stack with pir as index. With hostboot no longer clearing memory this region
may hold junk contents. Currently opal initialize cpu stack memory only for
cpu pir that is found on the device-tree. For the rest, the cpu thread
contents are uninitialized. This sometime causes for_each_cpu* macros to
return cpu thread for pir/cpu which isn't present on the system. The
for_each_cpu* macros iterate over cpu stacks using pir as index and returns
cpu thread pointer if state != cpu_state_no_cpu. For cpus that are not found
on device-tree the state may hold junk value leading OPAL to access invalid
cpu thread area. This further leads to accessing pointers with junk values
causing machine check (MCE) during OPAL init code. Fix this by Initializing
all the cpu thread areas upto cpu_max_pir.

[  182.049714372,3] ***********************************************
[  182.049878580,3] Fatal MCE at 0000000030039738   .init_trace_buffers+0x21c  MSR 9000000000201002
[  182.049943811,3] Cause: load real address error
[  182.049968681,3] Effective address: 0x480113a4791c4a50
[  182.050000736,3] CFAR : 00000000300395b8 MSR  : 9000000000201002
[  182.050035376,3] SRR0 : 0000000030039738 SRR1 : 9000000000201002
[  182.050072878,3] HSRR0: 0000000030020024 HSRR1: 9000000000001000
[  182.050117303,3] DSISR: 00000040         DAR  : 480113a4791c4a50
[  182.050149054,3] LR   : 0000000030039744 CTR  : 0000000000000000
[  182.050182991,3] CR   : 42000224         XER  : 00000000
[  182.050217262,3] GPR00: 000000003003962c GPR16: 0000000032d50000
[  182.050255746,3] GPR01: 0000000032d53a50 GPR17: 0000000030003198
[  182.050288081,3] GPR02: 000000003014cb00 GPR18: 0000000000000000
[  182.050331474,3] GPR03: 0000000031c50000 GPR19: 0000000000000000
[  182.050371934,3] GPR04: 0000000000000000 GPR20: 0000000000000000
[  182.050416212,3] GPR05: ffffffffffffffff GPR21: 0000000000000001
[  182.050454130,3] GPR06: 0000000000000005 GPR22: 00000000300f74eb
[  182.050488053,3] GPR07: 0000000000000028 GPR23: 00000000000fffd8
[  182.050522774,3] GPR08: 000000000000067f GPR24: 00000000000fff40
[  182.050566878,3] GPR09: 480113a4791c4a18 GPR25: 0000000000000070
[  182.050601524,3] GPR10: 00000000078b0353 GPR26: 00000000300f7527
[  182.050640345,3] GPR11: 0000000000000000 GPR27: 00000000300f7516
[  182.050680816,3] GPR12: 0000000042000222 GPR28: 000000003acd0000
[  182.050724099,3] GPR13: 000000000025a908 GPR29: 000000003acd0000
[  182.050759728,3] GPR14: 0000000000000000 GPR30: 0000000000000000
[  182.050790430,3] GPR15: 0000000000000000 GPR31: 00000000301f0038
CPU 0228 Backtrace:
 S: 0000000032d53d60 R: 000000003003962c   .init_trace_buffers+0x110
 S: 0000000032d53e30 R: 0000000030022f84   .main_cpu_entry+0x550
 S: 0000000032d53f00 R: 00000000300031f8   not_fused+0x11c

Signed-off-by: Mahesh Salgaonkar <6a890e1065a1d4e8df9dcf1d9a2c9c740bbcf8aa@linux.ibm.com>
Signed-off-by: Nicholas Piggin <24829078df5003d9dd1dd871ca2aeb0b1cf95ef4@gmail.com>
[Folded Nick's patch to that added mark_all_secondary_cpus_absent() - Vasant]
Signed-off-by: Vasant Hegde <a6d753843573f7bfed5075c1e875b0be8007a0ab@linux.vnet.ibm.com>

qemu/skiboot,legoater/skiboot,qemu/skiboot,shenki/skiboot,open-power/skiboot,qemu/skiboot,open-power/skiboot,shenki/skiboot,shenki/skiboot,open-power/skiboot,legoater/skiboot,shenki/skiboot,qemu/skiboot,legoater/skiboot,qemu/skiboot,open-power/skiboot,legoater/skiboot,legoater/skiboot,shenki/skiboot,open-power/skiboot