Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/kexec: Enable SMT before waking offline CPUs

If SMT is disabled or a partial SMT state is enabled, when a new kernel
image is loaded for kexec, on reboot the following warning is observed:

kexec: Waking offline cpu 228.
WARNING: CPU: 0 PID: 9062 at arch/powerpc/kexec/core_64.c:223 kexec_prepare_cpus+0x1b0/0x1bc
[snip]
NIP kexec_prepare_cpus+0x1b0/0x1bc
LR kexec_prepare_cpus+0x1a0/0x1bc
Call Trace:
kexec_prepare_cpus+0x1a0/0x1bc (unreliable)
default_machine_kexec+0x160/0x19c
machine_kexec+0x80/0x88
kernel_kexec+0xd0/0x118
__do_sys_reboot+0x210/0x2c4
system_call_exception+0x124/0x320
system_call_vectored_common+0x15c/0x2ec

This occurs as add_cpu() fails due to cpu_bootable() returning false for
CPUs that fail the cpu_smt_thread_allowed() check or non primary
threads if SMT is disabled.

Fix the issue by enabling SMT and resetting the number of SMT threads to
the number of threads per core, before attempting to wake up all present
CPUs.

Fixes: 38253464bc82 ("cpu/SMT: Create topology_smt_thread_allowed()")
Reported-by: Sachin P Bappalige <sachinpb@linux.ibm.com>
Cc: stable@vger.kernel.org # v6.6+
Reviewed-by: Srikar Dronamraju <srikar@linux.ibm.com>
Signed-off-by: Nysal Jan K.A. <nysal@linux.ibm.com>
Tested-by: Samir M <samir@linux.ibm.com>
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com>
Link: https://patch.msgid.link/20251028105516.26258-1-nysal@linux.ibm.com

authored by

Nysal Jan K.A. and committed by
Madhavan Srinivasan
c2296a1e 9448598b

+19
+19
arch/powerpc/kexec/core_64.c
··· 202 202 mb(); 203 203 } 204 204 205 + 206 + /* 207 + * The add_cpu() call in wake_offline_cpus() can fail as cpu_bootable() 208 + * returns false for CPUs that fail the cpu_smt_thread_allowed() check 209 + * or non primary threads if SMT is disabled. Re-enable SMT and set the 210 + * number of SMT threads to threads per core. 211 + */ 212 + static void kexec_smt_reenable(void) 213 + { 214 + #if defined(CONFIG_SMP) && defined(CONFIG_HOTPLUG_SMT) 215 + lock_device_hotplug(); 216 + cpu_smt_num_threads = threads_per_core; 217 + cpu_smt_control = CPU_SMT_ENABLED; 218 + unlock_device_hotplug(); 219 + #endif 220 + } 221 + 205 222 /* 206 223 * We need to make sure each present CPU is online. The next kernel will scan 207 224 * the device tree and assume primary threads are online and query secondary ··· 232 215 static void wake_offline_cpus(void) 233 216 { 234 217 int cpu = 0; 218 + 219 + kexec_smt_reenable(); 235 220 236 221 for_each_present_cpu(cpu) { 237 222 if (!cpu_online(cpu)) {