Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * SMP initialisation and IPI support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Based on arch/arm/kernel/smp.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (C) 2012 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/arm_sdei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/sched/hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/profile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/irqchip/arm-gic-v3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/clockchips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/irq_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <asm/alternative.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <asm/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <asm/cputype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <asm/cpu_ops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <asm/daifflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <asm/kvm_mmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <asm/numa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <asm/smp_plat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <asm/virt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <trace/events/ipi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #undef CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <trace/hooks/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) EXPORT_PER_CPU_SYMBOL(cpu_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_raise);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66)  * as from 2.5, kernels no longer have an init_tasks structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * so we need some other way of telling a new secondary core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * where to place its SVC stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) struct secondary_data secondary_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) /* Number of CPUs which aren't online, but looping in kernel text. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static int cpus_stuck_in_kernel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) enum ipi_msg_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	IPI_RESCHEDULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	IPI_CALL_FUNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	IPI_CPU_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	IPI_CPU_CRASH_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	IPI_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	IPI_IRQ_WORK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	IPI_WAKEUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	NR_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static int ipi_irq_base __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static int nr_ipi __read_mostly = NR_IPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static struct irq_desc *ipi_desc[NR_IPI] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static void ipi_setup(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) static void ipi_teardown(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static int op_cpu_kill(unsigned int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static inline int op_cpu_kill(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103)  * Boot a secondary CPU, and assign it the specified idle task.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104)  * This also gives us the initial stack to use for this CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static int boot_secondary(unsigned int cpu, struct task_struct *idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	const struct cpu_operations *ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	if (ops->cpu_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		return ops->cpu_boot(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static DECLARE_COMPLETION(cpu_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) int __cpu_up(unsigned int cpu, struct task_struct *idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	long status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	 * We need to tell the secondary core where to find its stack and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	 * page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	secondary_data.task = idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	secondary_data.stack = task_stack_page(idle) + THREAD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	update_cpu_boot_status(CPU_MMU_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	__flush_dcache_area(&secondary_data, sizeof(secondary_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	/* Now bring the CPU into our world */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	ret = boot_secondary(cpu, idle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	 * CPU was successfully started, wait for it to come online or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	 * time out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	wait_for_completion_timeout(&cpu_running,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 				    msecs_to_jiffies(5000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	if (cpu_online(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	pr_crit("CPU%u: failed to come online\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	secondary_data.task = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	secondary_data.stack = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	__flush_dcache_area(&secondary_data, sizeof(secondary_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	status = READ_ONCE(secondary_data.status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 	if (status == CPU_MMU_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 		status = READ_ONCE(__early_cpu_boot_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	switch (status & CPU_BOOT_STATUS_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		pr_err("CPU%u: failed in unknown state : 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		       cpu, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 		cpus_stuck_in_kernel++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	case CPU_KILL_ME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		if (!op_cpu_kill(cpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 			pr_crit("CPU%u: died during early boot\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 		pr_crit("CPU%u: may not have shut down cleanly\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	case CPU_STUCK_IN_KERNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		pr_crit("CPU%u: is stuck in kernel\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 		if (status & CPU_STUCK_REASON_52_BIT_VA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 			pr_crit("CPU%u: does not support 52-bit VAs\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 		if (status & CPU_STUCK_REASON_NO_GRAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 			pr_crit("CPU%u: does not support %luK granule\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 				cpu, PAGE_SIZE / SZ_1K);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 		cpus_stuck_in_kernel++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	case CPU_PANIC_KERNEL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		panic("CPU%u detected unsupported configuration\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) static void init_gic_priority_masking(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	u32 cpuflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	if (WARN_ON(!gic_enable_sre()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	cpuflags = read_sysreg(daif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	WARN_ON(!(cpuflags & PSR_I_BIT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	gic_write_pmr(GIC_PRIO_IRQON | GIC_PRIO_PSR_I_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201)  * This is the secondary CPU boot entry.  We're using this CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202)  * idle thread stack, but a set of temporary page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) asmlinkage notrace void secondary_start_kernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	u64 mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	struct mm_struct *mm = &init_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	const struct cpu_operations *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	cpu = task_cpu(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	set_my_cpu_offset(per_cpu_offset(cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	 * All kernel threads share the same mm context; grab a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	 * reference and switch to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	mmgrab(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	current->active_mm = mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	 * TTBR0 is only used for the identity mapping at this stage. Make it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 	 * point to zero page to avoid speculatively fetching new entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	cpu_uninstall_idmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	if (system_uses_irq_prio_masking())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		init_gic_priority_masking();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	rcu_cpu_starting(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	trace_hardirqs_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	 * If the system has established the capabilities, make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	 * this CPU ticks all of those. If it doesn't, the CPU will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	 * fail to come online.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	check_local_cpu_capabilities();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	if (ops->cpu_postboot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		ops->cpu_postboot();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	 * Log the CPU info before it is marked online and might get read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	cpuinfo_store_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	 * Enable GIC and timers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	notify_cpu_starting(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	ipi_setup(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	store_cpu_topology(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	numa_add_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	 * OK, now it's safe to let the boot CPU continue.  Wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	 * the CPU migration code to notice that the CPU is online
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	 * before we continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	pr_info("CPU%u: Booted secondary processor 0x%010lx [0x%08x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 					 cpu, (unsigned long)mpidr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 					 read_cpuid_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	update_cpu_boot_status(CPU_BOOT_SUCCESS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	set_cpu_online(cpu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	complete(&cpu_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	local_daif_restore(DAIF_PROCCTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	 * OK, it's off to the idle thread for us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) static int op_cpu_disable(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	const struct cpu_operations *ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	 * If we don't have a cpu_die method, abort before we reach the point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	 * of no return. CPU0 may not have an cpu_ops, so test for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	if (!ops || !ops->cpu_die)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 		return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	 * We may need to abort a hot unplug for some other mechanism-specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	 * reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	if (ops->cpu_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		return ops->cpu_disable(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302)  * __cpu_disable runs on the processor to be shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) int __cpu_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	ret = op_cpu_disable(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	remove_cpu_topology(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 	numa_remove_cpu(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	 * Take this CPU offline.  Once we clear this, we can't return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	 * and we must not schedule until we're ready to give up the cpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	set_cpu_online(cpu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	ipi_teardown(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	 * OK - migrate IRQs away from this CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	irq_migrate_all_off_this_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) static int op_cpu_kill(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	const struct cpu_operations *ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	 * If we have no means of synchronising with the dying CPU, then assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	 * that it is really dead. We can only wait for an arbitrary length of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 * time and hope that it's dead, so let's skip the wait and just hope.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	if (!ops->cpu_kill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	return ops->cpu_kill(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347)  * called on the thread which is asking for a CPU to be shutdown -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348)  * waits until shutdown has completed, or it is timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) void __cpu_die(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	if (!cpu_wait_death(cpu, 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		pr_crit("CPU%u: cpu didn't die\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	pr_debug("CPU%u: shutdown\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	 * Now that the dying CPU is beyond the point of no return w.r.t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	 * in-kernel synchronisation, try to get the firwmare to help us to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	 * verify that it has really left the kernel before we consider
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	 * clobbering anything it might still be using.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	err = op_cpu_kill(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		pr_warn("CPU%d may not have shut down cleanly: %d\n", cpu, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  * Called from the idle thread for the CPU which has been shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) void cpu_die(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	const struct cpu_operations *ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	idle_task_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	local_daif_mask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	/* Tell __cpu_die() that this CPU is now safe to dispose of */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	(void)cpu_report_death();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	 * Actually shutdown the CPU. This must never fail. The specific hotplug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	 * mechanism must perform all required cache maintenance to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	 * no dirty lines are lost in the process of shutting down the CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	ops->cpu_die(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) static void __cpu_try_die(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	const struct cpu_operations *ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	if (ops && ops->cpu_die)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		ops->cpu_die(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  * Kill the calling secondary CPU, early in bringup before it is turned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * online.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) void cpu_die_early(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	pr_crit("CPU%d: will not boot\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	/* Mark this CPU absent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	set_cpu_present(cpu, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	rcu_report_dead(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	if (IS_ENABLED(CONFIG_HOTPLUG_CPU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 		update_cpu_boot_status(CPU_KILL_ME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		__cpu_try_die(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	update_cpu_boot_status(CPU_STUCK_IN_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	cpu_park_loop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) static void __init hyp_mode_check(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	if (is_hyp_mode_available())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		pr_info("CPU: All CPU(s) started at EL2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	else if (is_hyp_mode_mismatched())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		WARN_TAINT(1, TAINT_CPU_OUT_OF_SPEC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			   "CPU: CPUs started in inconsistent modes");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		pr_info("CPU: All CPU(s) started at EL1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	if (IS_ENABLED(CONFIG_KVM) && !is_kernel_in_hyp_mode()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		kvm_compute_layout();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		kvm_apply_hyp_relocations();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) void __init smp_cpus_done(unsigned int max_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	setup_cpu_features();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	hyp_mode_check();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	apply_alternatives_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	mark_linear_text_alias_ro();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) void __init smp_prepare_boot_cpu(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	cpuinfo_store_boot_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	 * We now know enough about the boot CPU to apply the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	 * alternatives that cannot wait until interrupt handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	 * and/or scheduling is enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	apply_boot_alternatives();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	/* Conditionally switch to GIC PMR for interrupt masking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (system_uses_irq_prio_masking())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		init_gic_priority_masking();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	kasan_init_hw_tags();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) static u64 __init of_get_cpu_mpidr(struct device_node *dn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	const __be32 *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	u64 hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	 * A cpu node with missing "reg" property is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	 * considered invalid to build a cpu_logical_map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	 * entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	cell = of_get_property(dn, "reg", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	if (!cell) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 		pr_err("%pOF: missing reg property\n", dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		return INVALID_HWID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	hwid = of_read_number(cell, of_n_addr_cells(dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	 * Non affinity bits must be set to 0 in the DT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	if (hwid & ~MPIDR_HWID_BITMASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		pr_err("%pOF: invalid reg property\n", dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		return INVALID_HWID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	return hwid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503)  * Duplicate MPIDRs are a recipe for disaster. Scan all initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504)  * entries and check for duplicates. If any is found just ignore the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  * cpu. cpu_logical_map was initialized to INVALID_HWID to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  * matching valid MPIDR values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) static bool __init is_mpidr_duplicate(unsigned int cpu, u64 hwid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	for (i = 1; (i < cpu) && (i < NR_CPUS); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		if (cpu_logical_map(i) == hwid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  * Initialize cpu operations for a logical cpu and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520)  * set it in the possible mask on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) static int __init smp_cpu_setup(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	const struct cpu_operations *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	if (init_cpu_ops(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	if (ops->cpu_init(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	set_cpu_possible(cpu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) static bool bootcpu_valid __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) static unsigned int cpu_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) #ifdef CONFIG_ACPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) static struct acpi_madt_generic_interrupt cpu_madt_gicc[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) struct acpi_madt_generic_interrupt *acpi_cpu_get_madt_gicc(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	return &cpu_madt_gicc[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550)  * acpi_map_gic_cpu_interface - parse processor MADT entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  * Carry out sanity checks on MADT processor entry and initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553)  * cpu_logical_map on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) static void __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	u64 hwid = processor->arm_mpidr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	if (!(processor->flags & ACPI_MADT_ENABLED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	if (hwid & ~MPIDR_HWID_BITMASK || hwid == INVALID_HWID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 		pr_err("skipping CPU entry with invalid MPIDR 0x%llx\n", hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	if (is_mpidr_duplicate(cpu_count, hwid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		pr_err("duplicate CPU MPIDR 0x%llx in MADT\n", hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	/* Check if GICC structure of boot CPU is available in the MADT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	if (cpu_logical_map(0) == hwid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		if (bootcpu_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			pr_err("duplicate boot CPU MPIDR: 0x%llx in MADT\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			       hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		bootcpu_valid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		cpu_madt_gicc[0] = *processor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	if (cpu_count >= NR_CPUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	/* map the logical cpu id to cpu MPIDR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	set_cpu_logical_map(cpu_count, hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	cpu_madt_gicc[cpu_count] = *processor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	 * Set-up the ACPI parking protocol cpu entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	 * while initializing the cpu_logical_map to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	 * avoid parsing MADT entries multiple times for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	 * nothing (ie a valid cpu_logical_map entry should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	 * contain a valid parking protocol data set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	 * initialize the cpu if the parking protocol is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	 * the only available enable method).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	acpi_set_mailbox_entry(cpu_count, processor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	cpu_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) static int __init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) acpi_parse_gic_cpu_interface(union acpi_subtable_headers *header,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			     const unsigned long end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	struct acpi_madt_generic_interrupt *processor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	processor = (struct acpi_madt_generic_interrupt *)header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	if (BAD_MADT_GICC_ENTRY(processor, end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	acpi_table_print_madt_entry(&header->common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	acpi_map_gic_cpu_interface(processor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) static void __init acpi_parse_and_init_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	 * do a walk of MADT to determine how many CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	 * we have including disabled CPUs, and get information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	 * we need for SMP init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 				      acpi_parse_gic_cpu_interface, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	 * In ACPI, SMP and CPU NUMA information is provided in separate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	 * static tables, namely the MADT and the SRAT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	 * Thus, it is simpler to first create the cpu logical map through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	 * an MADT walk and then map the logical cpus to their node ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	 * as separate steps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	acpi_map_cpus_to_nodes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	for (i = 0; i < nr_cpu_ids; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		early_map_cpu_to_node(i, acpi_numa_get_nid(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) #define acpi_parse_and_init_cpus(...)	do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656)  * Enumerate the possible CPU set from the device tree and build the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657)  * cpu logical map array containing MPIDR values related to logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658)  * cpus. Assumes that cpu_logical_map(0) has already been initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) static void __init of_parse_and_init_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	struct device_node *dn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 	for_each_of_cpu_node(dn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		u64 hwid = of_get_cpu_mpidr(dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		if (hwid == INVALID_HWID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		if (is_mpidr_duplicate(cpu_count, hwid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			pr_err("%pOF: duplicate cpu reg properties in the DT\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 				dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		 * The numbering scheme requires that the boot CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		 * must be assigned logical id 0. Record it so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		 * the logical map built from DT is validated and can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 		 * be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		if (hwid == cpu_logical_map(0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			if (bootcpu_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 				pr_err("%pOF: duplicate boot cpu reg property in DT\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 					dn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 			bootcpu_valid = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 			early_map_cpu_to_node(0, of_node_to_nid(dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			 * cpu_logical_map has already been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			 * initialized and the boot cpu doesn't need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			 * the enable-method so continue without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			 * incrementing cpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		if (cpu_count >= NR_CPUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		pr_debug("cpu logical map 0x%llx\n", hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		set_cpu_logical_map(cpu_count, hwid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		early_map_cpu_to_node(cpu_count, of_node_to_nid(dn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		cpu_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714)  * Enumerate the possible CPU set from the device tree or ACPI and build the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715)  * cpu logical map array containing MPIDR values related to logical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)  * cpus. Assumes that cpu_logical_map(0) has already been initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) void __init smp_init_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		of_parse_and_init_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		acpi_parse_and_init_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	if (cpu_count > nr_cpu_ids)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 		pr_warn("Number of cores (%d) exceeds configured maximum of %u - clipping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			cpu_count, nr_cpu_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (!bootcpu_valid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	 * We need to set the cpu_logical_map entries before enabling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 	 * the cpus so that cpu processor description entries (DT cpu nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	 * and ACPI MADT entries) can be retrieved by matching the cpu hwid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	 * with entries in cpu_logical_map while initializing the cpus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	 * If the cpu set-up fails, invalidate the cpu_logical_map entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	for (i = 1; i < nr_cpu_ids; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		if (cpu_logical_map(i) != INVALID_HWID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			if (smp_cpu_setup(i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 				set_cpu_logical_map(i, INVALID_HWID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) void __init smp_prepare_cpus(unsigned int max_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	const struct cpu_operations *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	unsigned int this_cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	init_cpu_topology();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	this_cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	store_cpu_topology(this_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	numa_store_cpu_info(this_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	numa_add_cpu(this_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	 * If UP is mandated by "nosmp" (which implies "maxcpus=0"), don't set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	 * secondary CPUs present.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	if (max_cpus == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	 * Initialise the present map (which describes the set of CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	 * actually populated at the present time) and release the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	 * secondaries from the bootloader.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		per_cpu(cpu_number, cpu) = cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 		if (cpu == smp_processor_id())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		ops = get_cpu_ops(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 		if (!ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		err = ops->cpu_prepare(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		set_cpu_present(cpu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		numa_store_cpu_info(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) static const char *ipi_types[NR_IPI] __tracepoint_string = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) #define S(x,s)	[x] = s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	S(IPI_RESCHEDULE, "Rescheduling interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	S(IPI_CALL_FUNC, "Function call interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	S(IPI_CPU_STOP, "CPU stop interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	S(IPI_CPU_CRASH_STOP, "CPU stop (for crash dump) interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	S(IPI_TIMER, "Timer broadcast interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	S(IPI_IRQ_WORK, "IRQ work interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	S(IPI_WAKEUP, "CPU wake-up interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) static void smp_cross_call(const struct cpumask *target, unsigned int ipinr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) unsigned long irq_err_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) int arch_show_interrupts(struct seq_file *p, int prec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	unsigned int cpu, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	for (i = 0; i < NR_IPI; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		unsigned int irq = irq_desc_get_irq(ipi_desc[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			   prec >= 4 ? " " : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		for_each_online_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			seq_printf(p, "%10u ", kstat_irqs_cpu(irq, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		seq_printf(p, "      %s\n", ipi_types[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 	seq_printf(p, "%*s: %10lu\n", prec, "Err", irq_err_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) void arch_send_call_function_ipi_mask(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	smp_cross_call(mask, IPI_CALL_FUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) void arch_send_call_function_single_ipi(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	smp_cross_call(mask, IPI_WAKEUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) #ifdef CONFIG_IRQ_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) void arch_irq_work_raise(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) static void local_cpu_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	if (system_state <= SYSTEM_RUNNING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		pr_crit("CPU%u: stopping\n", smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	set_cpu_online(smp_processor_id(), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	local_daif_mask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	sdei_mask_local_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	cpu_park_loop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867)  * We need to implement panic_smp_self_stop() for parallel panic() calls, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868)  * that cpu_online_mask gets correctly updated and smp_send_stop() can skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869)  * CPUs that have already stopped themselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) void panic_smp_self_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	local_cpu_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) static atomic_t waiting_for_crash_ipi = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) static void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	crash_save_cpu(regs, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 	atomic_dec(&waiting_for_crash_ipi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	sdei_mask_local_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	if (IS_ENABLED(CONFIG_HOTPLUG_CPU))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		__cpu_try_die(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	/* just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	cpu_park_loop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899)  * Main handler for inter-processor interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) static void do_handle_IPI(int ipinr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	if ((unsigned)ipinr < NR_IPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		trace_ipi_entry_rcuidle(ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	switch (ipinr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	case IPI_RESCHEDULE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		scheduler_ipi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	case IPI_CALL_FUNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		generic_smp_call_function_interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	case IPI_CPU_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		trace_android_vh_ipi_stop_rcuidle(get_irq_regs());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		local_cpu_stop();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	case IPI_CPU_CRASH_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		if (IS_ENABLED(CONFIG_KEXEC_CORE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 			ipi_cpu_crash_stop(cpu, get_irq_regs());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 			unreachable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	case IPI_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		tick_receive_broadcast();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) #ifdef CONFIG_IRQ_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	case IPI_IRQ_WORK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		irq_work_run();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	case IPI_WAKEUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 		WARN_ONCE(!acpi_parking_protocol_valid(cpu),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 			  "CPU%u: Wake-up IPI outside the ACPI parking protocol\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			  cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if ((unsigned)ipinr < NR_IPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		trace_ipi_exit_rcuidle(ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) static irqreturn_t ipi_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	do_handle_IPI(irq - ipi_irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	trace_ipi_raise(target, ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	__ipi_send_mask(ipi_desc[ipinr], target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) static void ipi_setup(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	if (WARN_ON_ONCE(!ipi_irq_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	for (i = 0; i < nr_ipi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 		enable_percpu_irq(ipi_irq_base + i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) static void ipi_teardown(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	if (WARN_ON_ONCE(!ipi_irq_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	for (i = 0; i < nr_ipi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		disable_percpu_irq(ipi_irq_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) void __init set_smp_ipi_range(int ipi_base, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	WARN_ON(n < NR_IPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	nr_ipi = min(n, NR_IPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	for (i = 0; i < nr_ipi; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 		err = request_percpu_irq(ipi_base + i, ipi_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 					 "IPI", &cpu_number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		WARN_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		ipi_desc[i] = irq_to_desc(ipi_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		irq_set_status_flags(ipi_base + i, IRQ_HIDDEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		/* The recheduling IPI is special... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		if (i == IPI_RESCHEDULE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 			__irq_modify_status(ipi_base + i, 0, IRQ_RAW, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	ipi_irq_base = ipi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	/* Setup the boot CPU immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	ipi_setup(smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) void smp_send_reschedule(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) void tick_broadcast(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	smp_cross_call(mask, IPI_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)  * The number of CPUs online, not counting this CPU (which may not be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037)  * fully online and so not counted in num_online_cpus()).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) static inline unsigned int num_other_online_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	unsigned int this_cpu_online = cpu_online(smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	return num_online_cpus() - this_cpu_online;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) void smp_send_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	if (num_other_online_cpus()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 		cpumask_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		cpumask_copy(&mask, cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		cpumask_clear_cpu(smp_processor_id(), &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 		if (system_state <= SYSTEM_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 			pr_crit("SMP: stopping secondary CPUs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		smp_cross_call(&mask, IPI_CPU_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	/* Wait up to one second for other CPUs to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	timeout = USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	while (num_other_online_cpus() && timeout--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	if (num_other_online_cpus())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		pr_warn("SMP: failed to stop secondary CPUs %*pbl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 			cpumask_pr_args(cpu_online_mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	sdei_mask_local_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) void crash_smp_send_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	static int cpus_stopped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	cpumask_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	 * This function can be called twice in panic path, but obviously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	 * we execute this only once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (cpus_stopped)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 	cpus_stopped = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	 * If this cpu is the only one alive at this point in time, online or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	 * not, there are no stop messages to be sent around, so just back out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	if (num_other_online_cpus() == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		sdei_mask_local_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	cpumask_copy(&mask, cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	cpumask_clear_cpu(smp_processor_id(), &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	atomic_set(&waiting_for_crash_ipi, num_other_online_cpus());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	pr_crit("SMP: stopping secondary CPUs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	smp_cross_call(&mask, IPI_CPU_CRASH_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	/* Wait up to one second for other CPUs to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	timeout = USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	while ((atomic_read(&waiting_for_crash_ipi) > 0) && timeout--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	if (atomic_read(&waiting_for_crash_ipi) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		pr_warn("SMP: failed to stop secondary CPUs %*pbl\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			cpumask_pr_args(&mask));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	sdei_mask_local_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) bool smp_crash_stop_failed(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	return (atomic_read(&waiting_for_crash_ipi) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  * not supported here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int setup_profiling_timer(unsigned int multiplier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) static bool have_cpu_die(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	int any_cpu = raw_smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	const struct cpu_operations *ops = get_cpu_ops(any_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	if (ops && ops->cpu_die)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) bool cpus_are_stuck_in_kernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	bool smp_spin_tables = (num_possible_cpus() > 1 && !have_cpu_die());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	return !!cpus_stuck_in_kernel || smp_spin_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) int nr_ipi_get(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	return nr_ipi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) EXPORT_SYMBOL_GPL(nr_ipi_get);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) struct irq_desc **ipi_desc_get(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	return ipi_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) EXPORT_SYMBOL_GPL(ipi_desc_get);