| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * SMP support for pSeries machines. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 5 | 6 | * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Plus various changes from other IBM teams... |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or |
|---|
| 10 | | - * modify it under the terms of the GNU General Public License |
|---|
| 11 | | - * as published by the Free Software Foundation; either version |
|---|
| 12 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| 15 | 11 | |
|---|
| .. | .. |
|---|
| 24 | 20 | #include <linux/err.h> |
|---|
| 25 | 21 | #include <linux/device.h> |
|---|
| 26 | 22 | #include <linux/cpu.h> |
|---|
| 23 | +#include <linux/pgtable.h> |
|---|
| 27 | 24 | |
|---|
| 28 | 25 | #include <asm/ptrace.h> |
|---|
| 29 | 26 | #include <linux/atomic.h> |
|---|
| 30 | 27 | #include <asm/irq.h> |
|---|
| 31 | 28 | #include <asm/page.h> |
|---|
| 32 | | -#include <asm/pgtable.h> |
|---|
| 33 | 29 | #include <asm/io.h> |
|---|
| 34 | 30 | #include <asm/prom.h> |
|---|
| 35 | 31 | #include <asm/smp.h> |
|---|
| .. | .. |
|---|
| 45 | 41 | #include <asm/dbell.h> |
|---|
| 46 | 42 | #include <asm/plpar_wrappers.h> |
|---|
| 47 | 43 | #include <asm/code-patching.h> |
|---|
| 44 | +#include <asm/svm.h> |
|---|
| 45 | +#include <asm/kvm_guest.h> |
|---|
| 48 | 46 | |
|---|
| 49 | 47 | #include "pseries.h" |
|---|
| 50 | | -#include "offline_states.h" |
|---|
| 51 | | - |
|---|
| 52 | 48 | |
|---|
| 53 | 49 | /* |
|---|
| 54 | 50 | * The Primary thread of each non-boot processor was started from the OF client |
|---|
| .. | .. |
|---|
| 109 | 105 | return 1; |
|---|
| 110 | 106 | } |
|---|
| 111 | 107 | |
|---|
| 112 | | - /* Fixup atomic count: it exited inside IRQ handler. */ |
|---|
| 113 | | - task_thread_info(paca_ptrs[lcpu]->__current)->preempt_count = 0; |
|---|
| 114 | | -#ifdef CONFIG_HOTPLUG_CPU |
|---|
| 115 | | - if (get_cpu_current_state(lcpu) == CPU_STATE_INACTIVE) |
|---|
| 116 | | - goto out; |
|---|
| 117 | | -#endif |
|---|
| 118 | 108 | /* |
|---|
| 119 | 109 | * If the RTAS start-cpu token does not exist then presume the |
|---|
| 120 | 110 | * cpu is already spinning. |
|---|
| .. | .. |
|---|
| 129 | 119 | return 0; |
|---|
| 130 | 120 | } |
|---|
| 131 | 121 | |
|---|
| 132 | | -#ifdef CONFIG_HOTPLUG_CPU |
|---|
| 133 | | -out: |
|---|
| 134 | | -#endif |
|---|
| 135 | 122 | return 1; |
|---|
| 136 | 123 | } |
|---|
| 137 | 124 | |
|---|
| .. | .. |
|---|
| 146 | 133 | vpa_init(cpu); |
|---|
| 147 | 134 | |
|---|
| 148 | 135 | cpumask_clear_cpu(cpu, of_spin_mask); |
|---|
| 149 | | -#ifdef CONFIG_HOTPLUG_CPU |
|---|
| 150 | | - set_cpu_current_state(cpu, CPU_STATE_ONLINE); |
|---|
| 151 | | - set_default_offline_state(cpu); |
|---|
| 152 | | -#endif |
|---|
| 153 | 136 | } |
|---|
| 154 | 137 | |
|---|
| 155 | 138 | static int smp_pSeries_kick_cpu(int nr) |
|---|
| .. | .. |
|---|
| 166 | 149 | * the processor will continue on to secondary_start |
|---|
| 167 | 150 | */ |
|---|
| 168 | 151 | paca_ptrs[nr]->cpu_start = 1; |
|---|
| 169 | | -#ifdef CONFIG_HOTPLUG_CPU |
|---|
| 170 | | - set_preferred_offline_state(nr, CPU_STATE_ONLINE); |
|---|
| 171 | | - |
|---|
| 172 | | - if (get_cpu_current_state(nr) == CPU_STATE_INACTIVE) { |
|---|
| 173 | | - long rc; |
|---|
| 174 | | - unsigned long hcpuid; |
|---|
| 175 | | - |
|---|
| 176 | | - hcpuid = get_hard_smp_processor_id(nr); |
|---|
| 177 | | - rc = plpar_hcall_norets(H_PROD, hcpuid); |
|---|
| 178 | | - if (rc != H_SUCCESS) |
|---|
| 179 | | - printk(KERN_ERR "Error: Prod to wake up processor %d " |
|---|
| 180 | | - "Ret= %ld\n", nr, rc); |
|---|
| 181 | | - } |
|---|
| 182 | | -#endif |
|---|
| 183 | 152 | |
|---|
| 184 | 153 | return 0; |
|---|
| 185 | 154 | } |
|---|
| .. | .. |
|---|
| 191 | 160 | return 0; |
|---|
| 192 | 161 | } |
|---|
| 193 | 162 | |
|---|
| 194 | | -static void smp_pseries_cause_ipi(int cpu) |
|---|
| 163 | +/* Cause IPI as setup by the interrupt controller (xics or xive) */ |
|---|
| 164 | +static void (*ic_cause_ipi)(int cpu) __ro_after_init; |
|---|
| 165 | + |
|---|
| 166 | +/* Use msgsndp doorbells target is a sibling, else use interrupt controller */ |
|---|
| 167 | +static void dbell_or_ic_cause_ipi(int cpu) |
|---|
| 195 | 168 | { |
|---|
| 196 | | - /* POWER9 should not use this handler */ |
|---|
| 197 | 169 | if (doorbell_try_core_ipi(cpu)) |
|---|
| 198 | 170 | return; |
|---|
| 199 | 171 | |
|---|
| 200 | | - icp_ops->cause_ipi(cpu); |
|---|
| 172 | + ic_cause_ipi(cpu); |
|---|
| 201 | 173 | } |
|---|
| 202 | 174 | |
|---|
| 203 | 175 | static int pseries_cause_nmi_ipi(int cpu) |
|---|
| .. | .. |
|---|
| 221 | 193 | return 0; |
|---|
| 222 | 194 | } |
|---|
| 223 | 195 | |
|---|
| 224 | | -static __init void pSeries_smp_probe_xics(void) |
|---|
| 225 | | -{ |
|---|
| 226 | | - xics_smp_probe(); |
|---|
| 227 | | - |
|---|
| 228 | | - if (cpu_has_feature(CPU_FTR_DBELL)) |
|---|
| 229 | | - smp_ops->cause_ipi = smp_pseries_cause_ipi; |
|---|
| 230 | | - else |
|---|
| 231 | | - smp_ops->cause_ipi = icp_ops->cause_ipi; |
|---|
| 232 | | -} |
|---|
| 233 | | - |
|---|
| 234 | 196 | static __init void pSeries_smp_probe(void) |
|---|
| 235 | 197 | { |
|---|
| 236 | 198 | if (xive_enabled()) |
|---|
| 237 | | - /* |
|---|
| 238 | | - * Don't use P9 doorbells when XIVE is enabled. IPIs |
|---|
| 239 | | - * using MMIOs should be faster |
|---|
| 240 | | - */ |
|---|
| 241 | 199 | xive_smp_probe(); |
|---|
| 242 | 200 | else |
|---|
| 243 | | - pSeries_smp_probe_xics(); |
|---|
| 201 | + xics_smp_probe(); |
|---|
| 202 | + |
|---|
| 203 | + /* No doorbell facility, must use the interrupt controller for IPIs */ |
|---|
| 204 | + if (!cpu_has_feature(CPU_FTR_DBELL)) |
|---|
| 205 | + return; |
|---|
| 206 | + |
|---|
| 207 | + /* Doorbells can only be used for IPIs between SMT siblings */ |
|---|
| 208 | + if (!cpu_has_feature(CPU_FTR_SMT)) |
|---|
| 209 | + return; |
|---|
| 210 | + |
|---|
| 211 | + check_kvm_guest(); |
|---|
| 212 | + |
|---|
| 213 | + if (is_kvm_guest()) { |
|---|
| 214 | + /* |
|---|
| 215 | + * KVM emulates doorbells by disabling FSCR[MSGP] so msgsndp |
|---|
| 216 | + * faults to the hypervisor which then reads the instruction |
|---|
| 217 | + * from guest memory, which tends to be slower than using XIVE. |
|---|
| 218 | + */ |
|---|
| 219 | + if (xive_enabled()) |
|---|
| 220 | + return; |
|---|
| 221 | + |
|---|
| 222 | + /* |
|---|
| 223 | + * XICS hcalls aren't as fast, so we can use msgsndp (which |
|---|
| 224 | + * also helps exercise KVM emulation), however KVM can't |
|---|
| 225 | + * emulate secure guests because it can't read the instruction |
|---|
| 226 | + * out of their memory. |
|---|
| 227 | + */ |
|---|
| 228 | + if (is_secure_guest()) |
|---|
| 229 | + return; |
|---|
| 230 | + } |
|---|
| 231 | + |
|---|
| 232 | + /* |
|---|
| 233 | + * Under PowerVM, FSCR[MSGP] is enabled as guest vCPU siblings are |
|---|
| 234 | + * gang scheduled on the same physical core, so doorbells are always |
|---|
| 235 | + * faster than the interrupt controller, and they can be used by |
|---|
| 236 | + * secure guests. |
|---|
| 237 | + */ |
|---|
| 238 | + |
|---|
| 239 | + ic_cause_ipi = smp_ops->cause_ipi; |
|---|
| 240 | + smp_ops->cause_ipi = dbell_or_ic_cause_ipi; |
|---|
| 244 | 241 | } |
|---|
| 245 | 242 | |
|---|
| 246 | 243 | static struct smp_ops_t pseries_smp_ops = { |
|---|