2019-05-27 13:55:01 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2011-09-20 00:44:52 +07:00
|
|
|
/*
|
|
|
|
* SMP support for PowerNV machines.
|
|
|
|
*
|
|
|
|
* Copyright 2011 IBM Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/sched.h>
|
2017-02-09 00:51:36 +07:00
|
|
|
#include <linux/sched/hotplug.h>
|
2011-09-20 00:44:52 +07:00
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/paca.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/firmware.h>
|
|
|
|
#include <asm/vdso_datapage.h>
|
|
|
|
#include <asm/cputhreads.h>
|
|
|
|
#include <asm/xics.h>
|
2017-04-05 14:54:50 +07:00
|
|
|
#include <asm/xive.h>
|
2011-09-20 00:44:57 +07:00
|
|
|
#include <asm/opal.h>
|
2014-04-11 17:31:48 +07:00
|
|
|
#include <asm/runlatch.h>
|
2014-03-11 07:54:06 +07:00
|
|
|
#include <asm/code-patching.h>
|
2014-06-11 12:59:28 +07:00
|
|
|
#include <asm/dbell.h>
|
2015-03-19 15:29:01 +07:00
|
|
|
#include <asm/kvm_ppc.h>
|
|
|
|
#include <asm/ppc-opcode.h>
|
2017-03-22 22:04:14 +07:00
|
|
|
#include <asm/cpuidle.h>
|
2017-12-15 15:14:55 +07:00
|
|
|
#include <asm/kexec.h>
|
|
|
|
#include <asm/reg.h>
|
2019-02-12 07:58:29 +07:00
|
|
|
#include <asm/powernv.h>
|
2011-09-20 00:44:52 +07:00
|
|
|
|
|
|
|
#include "powernv.h"
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <asm/udbg.h>
|
|
|
|
#define DBG(fmt...) udbg_printf(fmt)
|
|
|
|
#else
|
|
|
|
#define DBG(fmt...)
|
|
|
|
#endif
|
|
|
|
|
2013-06-25 02:30:09 +07:00
|
|
|
static void pnv_smp_setup_cpu(int cpu)
|
2011-09-20 00:44:52 +07:00
|
|
|
{
|
2017-09-15 12:25:48 +07:00
|
|
|
/*
|
|
|
|
* P9 workaround for CI vector load (see traps.c),
|
|
|
|
* enable the corresponding HMI interrupt
|
|
|
|
*/
|
|
|
|
if (pvr_version_is(PVR_POWER9))
|
|
|
|
mtspr(SPRN_HMEER, mfspr(SPRN_HMEER) | PPC_BIT(17));
|
|
|
|
|
2017-04-05 14:54:50 +07:00
|
|
|
if (xive_enabled())
|
|
|
|
xive_smp_setup_cpu();
|
|
|
|
else if (cpu != boot_cpuid)
|
2011-09-20 00:44:52 +07:00
|
|
|
xics_setup_cpu();
|
|
|
|
}
|
|
|
|
|
2014-08-20 05:55:18 +07:00
|
|
|
static int pnv_smp_kick_cpu(int nr)
|
2011-09-20 00:44:57 +07:00
|
|
|
{
|
2017-07-04 11:22:46 +07:00
|
|
|
unsigned int pcpu;
|
2014-03-11 07:54:06 +07:00
|
|
|
unsigned long start_here =
|
|
|
|
__pa(ppc_function_entry(generic_secondary_smp_init));
|
2011-09-20 00:44:57 +07:00
|
|
|
long rc;
|
2015-12-09 13:18:20 +07:00
|
|
|
uint8_t status;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2017-06-27 14:00:06 +07:00
|
|
|
if (nr < 0 || nr >= nr_cpu_ids)
|
2017-06-27 14:00:05 +07:00
|
|
|
return -EINVAL;
|
2011-09-20 00:44:57 +07:00
|
|
|
|
2017-07-04 11:22:46 +07:00
|
|
|
pcpu = get_hard_smp_processor_id(nr);
|
2013-05-14 12:12:31 +07:00
|
|
|
/*
|
2015-12-09 13:18:20 +07:00
|
|
|
* If we already started or OPAL is not supported, we just
|
2013-05-14 12:12:31 +07:00
|
|
|
* kick the CPU via the PACA
|
2011-09-20 00:44:57 +07:00
|
|
|
*/
|
2018-02-13 22:08:12 +07:00
|
|
|
if (paca_ptrs[nr]->cpu_start || !firmware_has_feature(FW_FEATURE_OPAL))
|
2013-05-14 12:12:31 +07:00
|
|
|
goto kick;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, the CPU can either be spinning on the way in
|
|
|
|
* from kexec or be inside OPAL waiting to be started for the
|
|
|
|
* first time. OPAL v3 allows us to query OPAL to know if it
|
|
|
|
* has the CPUs, so we do that
|
|
|
|
*/
|
2015-12-09 13:18:20 +07:00
|
|
|
rc = opal_query_cpu_status(pcpu, &status);
|
|
|
|
if (rc != OPAL_SUCCESS) {
|
|
|
|
pr_warn("OPAL Error %ld querying CPU %d state\n", rc, nr);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2013-05-14 12:12:31 +07:00
|
|
|
|
2015-12-09 13:18:20 +07:00
|
|
|
/*
|
|
|
|
* Already started, just kick it, probably coming from
|
|
|
|
* kexec and spinning
|
|
|
|
*/
|
|
|
|
if (status == OPAL_THREAD_STARTED)
|
|
|
|
goto kick;
|
2013-05-14 12:12:31 +07:00
|
|
|
|
2015-12-09 13:18:20 +07:00
|
|
|
/*
|
|
|
|
* Available/inactive, let's kick it
|
|
|
|
*/
|
|
|
|
if (status == OPAL_THREAD_INACTIVE) {
|
|
|
|
pr_devel("OPAL: Starting CPU %d (HW 0x%x)...\n", nr, pcpu);
|
|
|
|
rc = opal_start_cpu(pcpu, start_here);
|
|
|
|
if (rc != OPAL_SUCCESS) {
|
|
|
|
pr_warn("OPAL Error %ld starting CPU %d\n", rc, nr);
|
2013-05-14 12:12:31 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
2015-12-09 13:18:20 +07:00
|
|
|
* An unavailable CPU (or any other unknown status)
|
|
|
|
* shouldn't be started. It should also
|
|
|
|
* not be in the possible map but currently it can
|
|
|
|
* happen
|
2013-05-14 12:12:31 +07:00
|
|
|
*/
|
2015-12-09 13:18:20 +07:00
|
|
|
pr_devel("OPAL: CPU %d (HW 0x%x) is unavailable"
|
|
|
|
" (status %d)...\n", nr, pcpu, status);
|
|
|
|
return -ENODEV;
|
2011-09-20 00:44:57 +07:00
|
|
|
}
|
2015-12-09 13:18:20 +07:00
|
|
|
|
|
|
|
kick:
|
2011-09-20 00:44:57 +07:00
|
|
|
return smp_generic_kick_cpu(nr);
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
|
|
|
|
static int pnv_smp_cpu_disable(void)
|
|
|
|
{
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
/* This is identical to pSeries... might consolidate by
|
|
|
|
* moving migrate_irqs_away to a ppc_md with default to
|
|
|
|
* the generic fixup_irqs. --BenH.
|
|
|
|
*/
|
|
|
|
set_cpu_online(cpu, false);
|
|
|
|
vdso_data->processorCount--;
|
|
|
|
if (cpu == boot_cpuid)
|
|
|
|
boot_cpuid = cpumask_any(cpu_online_mask);
|
2017-04-05 14:54:50 +07:00
|
|
|
if (xive_enabled())
|
|
|
|
xive_smp_disable_cpu();
|
|
|
|
else
|
|
|
|
xics_migrate_irqs_away();
|
2011-09-20 00:44:54 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pnv_smp_cpu_kill_self(void)
|
|
|
|
{
|
|
|
|
unsigned int cpu;
|
2015-03-19 15:29:01 +07:00
|
|
|
unsigned long srr1, wmask;
|
2019-02-12 07:58:29 +07:00
|
|
|
u64 lpcr_val;
|
2011-09-20 00:44:54 +07:00
|
|
|
|
|
|
|
/* Standard hot unplug procedure */
|
2017-06-13 20:05:46 +07:00
|
|
|
/*
|
|
|
|
* This hard disables local interurpts, ensuring we have no lazy
|
|
|
|
* irqs pending.
|
|
|
|
*/
|
|
|
|
WARN_ON(irqs_disabled());
|
|
|
|
hard_irq_disable();
|
|
|
|
WARN_ON(lazy_irq_pending());
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
idle_task_exit();
|
|
|
|
current->active_mm = NULL; /* for sanity */
|
|
|
|
cpu = smp_processor_id();
|
|
|
|
DBG("CPU%d offline\n", cpu);
|
|
|
|
generic_set_cpu_dead(cpu);
|
|
|
|
smp_wmb();
|
|
|
|
|
2015-03-19 15:29:01 +07:00
|
|
|
wmask = SRR1_WAKEMASK;
|
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S))
|
|
|
|
wmask = SRR1_WAKEMASK_P8;
|
|
|
|
|
2019-02-12 07:58:29 +07:00
|
|
|
/*
|
|
|
|
* We don't want to take decrementer interrupts while we are
|
|
|
|
* offline, so clear LPCR:PECE1. We keep PECE2 (and
|
|
|
|
* LPCR_PECE_HVEE on P9) enabled so as to let IPIs in.
|
|
|
|
*
|
|
|
|
* If the CPU gets woken up by a special wakeup, ensure that
|
|
|
|
* the SLW engine sets LPCR with decrementer bit cleared, else
|
|
|
|
* the CPU will come back to the kernel due to a spurious
|
|
|
|
* wakeup.
|
|
|
|
*/
|
|
|
|
lpcr_val = mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1;
|
|
|
|
pnv_program_cpu_hotplug_lpcr(cpu, lpcr_val);
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
while (!generic_check_cpu_restart(cpu)) {
|
powerpc/powernv: Handle irq_happened flag correctly in off-line loop
This fixes a bug where it is possible for an off-line CPU to fail to go
into a low-power state (nap/sleep/winkle), and to become unresponsive to
requests from the KVM subsystem to wake up and run a VCPU. What can
happen is that a maskable interrupt of some kind (external, decrementer,
hypervisor doorbell, or HMI) after we have called local_irq_disable() at
the beginning of pnv_smp_cpu_kill_self() and before interrupts are
hard-disabled inside power7_nap/sleep/winkle(). In this situation, the
pending event is marked in the irq_happened flag in the PACA. This
pending event prevents power7_nap/sleep/winkle from going to the
requested low-power state; instead they return immediately. We don't
deal with any of these pending event flags in the off-line loop in
pnv_smp_cpu_kill_self() because power7_nap et al. return 0 in this case,
so we will have srr1 == 0, and none of the processing to clear
interrupts or doorbells will be done.
Usually, the most obvious symptom of this is that a KVM guest will fail
with a console message saying "KVM: couldn't grab cpu N".
This fixes the problem by making sure we handle the irq_happened flags
properly. First, we hard-disable before the off-line loop. Once we have
hard-disabled, the irq_happened flags can't change underneath us. We
unconditionally clear the DEC and HMI flags: there is no processing of
timer interrupts while off-line, and the necessary HMI processing is all
done in lower-level code. We leave the EE and DBELL flags alone for the
first iteration of the loop, so that we won't fail to respond to a
split-core request that came in just before hard-disabling. Within the
loop, we handle external interrupts if the EE bit is set in irq_happened
as well as if the low-power state was interrupted by an external
interrupt. (We don't need to do the msgclr for a pending doorbell in
irq_happened, because doorbells are edge-triggered and don't remain
pending in hardware.) Then we clear both the EE and DBELL flags, and
once clear, they cannot be set again (until this CPU comes online again,
that is).
This also fixes the debug check to not be done when we just ran a KVM
guest or when the sleep didn't happen because of a pending event in
irq_happened.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-10-21 12:06:24 +07:00
|
|
|
/*
|
|
|
|
* Clear IPI flag, since we don't handle IPIs while
|
|
|
|
* offline, except for those when changing micro-threading
|
|
|
|
* mode, which are handled explicitly below, and those
|
|
|
|
* for coming online, which are handled via
|
|
|
|
* generic_check_cpu_restart() calls.
|
|
|
|
*/
|
|
|
|
kvmppc_set_host_ipi(cpu, 0);
|
2014-12-10 01:56:53 +07:00
|
|
|
|
2017-03-22 22:04:14 +07:00
|
|
|
srr1 = pnv_cpu_offline(cpu);
|
2014-05-23 15:15:30 +07:00
|
|
|
|
2017-06-13 20:05:46 +07:00
|
|
|
WARN_ON(lazy_irq_pending());
|
|
|
|
|
powerpc/powernv: Return to cpu offline loop when finished in KVM guest
When a secondary hardware thread has finished running a KVM guest, we
currently put that thread into nap mode using a nap instruction in
the KVM code. This changes the code so that instead of doing a nap
instruction directly, we instead cause the call to power7_nap() that
put the thread into nap mode to return. The reason for doing this is
to avoid having the KVM code having to know what low-power mode to
put the thread into.
In the case of a secondary thread used to run a KVM guest, the thread
will be offline from the point of view of the host kernel, and the
relevant power7_nap() call is the one in pnv_smp_cpu_disable().
In this case we don't want to clear pending IPIs in the offline loop
in that function, since that might cause us to miss the wakeup for
the next time the thread needs to run a guest. To tell whether or
not to clear the interrupt, we use the SRR1 value returned from
power7_nap(), and check if it indicates an external interrupt. We
arrange that the return from power7_nap() when we have finished running
a guest returns 0, so pending interrupts don't get flushed in that
case.
Note that it is important a secondary thread that has finished
executing in the guest, or that didn't have a guest to run, should
not return to power7_nap's caller while the kvm_hstate.hwthread_req
flag in the PACA is non-zero, because the return from power7_nap
will reenable the MMU, and the MMU might still be in guest context.
In this situation we spin at low priority in real mode waiting for
hwthread_req to become zero.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2014-12-03 10:48:40 +07:00
|
|
|
/*
|
|
|
|
* If the SRR1 value indicates that we woke up due to
|
|
|
|
* an external interrupt, then clear the interrupt.
|
|
|
|
* We clear the interrupt before checking for the
|
|
|
|
* reason, so as to avoid a race where we wake up for
|
|
|
|
* some other reason, find nothing and clear the interrupt
|
|
|
|
* just as some other cpu is sending us an interrupt.
|
|
|
|
* If we returned from power7_nap as a result of
|
|
|
|
* having finished executing in a KVM guest, then srr1
|
|
|
|
* contains 0.
|
|
|
|
*/
|
powerpc/powernv: Handle irq_happened flag correctly in off-line loop
This fixes a bug where it is possible for an off-line CPU to fail to go
into a low-power state (nap/sleep/winkle), and to become unresponsive to
requests from the KVM subsystem to wake up and run a VCPU. What can
happen is that a maskable interrupt of some kind (external, decrementer,
hypervisor doorbell, or HMI) after we have called local_irq_disable() at
the beginning of pnv_smp_cpu_kill_self() and before interrupts are
hard-disabled inside power7_nap/sleep/winkle(). In this situation, the
pending event is marked in the irq_happened flag in the PACA. This
pending event prevents power7_nap/sleep/winkle from going to the
requested low-power state; instead they return immediately. We don't
deal with any of these pending event flags in the off-line loop in
pnv_smp_cpu_kill_self() because power7_nap et al. return 0 in this case,
so we will have srr1 == 0, and none of the processing to clear
interrupts or doorbells will be done.
Usually, the most obvious symptom of this is that a KVM guest will fail
with a console message saying "KVM: couldn't grab cpu N".
This fixes the problem by making sure we handle the irq_happened flags
properly. First, we hard-disable before the off-line loop. Once we have
hard-disabled, the irq_happened flags can't change underneath us. We
unconditionally clear the DEC and HMI flags: there is no processing of
timer interrupts while off-line, and the necessary HMI processing is all
done in lower-level code. We leave the EE and DBELL flags alone for the
first iteration of the loop, so that we won't fail to respond to a
split-core request that came in just before hard-disabling. Within the
loop, we handle external interrupts if the EE bit is set in irq_happened
as well as if the low-power state was interrupted by an external
interrupt. (We don't need to do the msgclr for a pending doorbell in
irq_happened, because doorbells are edge-triggered and don't remain
pending in hardware.) Then we clear both the EE and DBELL flags, and
once clear, they cannot be set again (until this CPU comes online again,
that is).
This also fixes the debug check to not be done when we just ran a KVM
guest or when the sleep didn't happen because of a pending event in
irq_happened.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-10-21 12:06:24 +07:00
|
|
|
if (((srr1 & wmask) == SRR1_WAKEEE) ||
|
2017-06-13 20:05:46 +07:00
|
|
|
((srr1 & wmask) == SRR1_WAKEHVI)) {
|
2017-04-05 14:54:50 +07:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300)) {
|
|
|
|
if (xive_enabled())
|
|
|
|
xive_flush_interrupt();
|
|
|
|
else
|
|
|
|
icp_opal_flush_interrupt();
|
|
|
|
} else
|
2017-02-07 07:35:31 +07:00
|
|
|
icp_native_flush_interrupt();
|
2015-03-19 15:29:01 +07:00
|
|
|
} else if ((srr1 & wmask) == SRR1_WAKEHDBELL) {
|
|
|
|
unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
|
|
|
|
asm volatile(PPC_MSGCLR(%0) : : "r" (msg));
|
2017-12-15 15:14:55 +07:00
|
|
|
} else if ((srr1 & wmask) == SRR1_WAKERESET) {
|
|
|
|
irq_set_pending_from_srr1(srr1);
|
|
|
|
/* Does not return */
|
powerpc/powernv: Return to cpu offline loop when finished in KVM guest
When a secondary hardware thread has finished running a KVM guest, we
currently put that thread into nap mode using a nap instruction in
the KVM code. This changes the code so that instead of doing a nap
instruction directly, we instead cause the call to power7_nap() that
put the thread into nap mode to return. The reason for doing this is
to avoid having the KVM code having to know what low-power mode to
put the thread into.
In the case of a secondary thread used to run a KVM guest, the thread
will be offline from the point of view of the host kernel, and the
relevant power7_nap() call is the one in pnv_smp_cpu_disable().
In this case we don't want to clear pending IPIs in the offline loop
in that function, since that might cause us to miss the wakeup for
the next time the thread needs to run a guest. To tell whether or
not to clear the interrupt, we use the SRR1 value returned from
power7_nap(), and check if it indicates an external interrupt. We
arrange that the return from power7_nap() when we have finished running
a guest returns 0, so pending interrupts don't get flushed in that
case.
Note that it is important a secondary thread that has finished
executing in the guest, or that didn't have a guest to run, should
not return to power7_nap's caller while the kvm_hstate.hwthread_req
flag in the PACA is non-zero, because the return from power7_nap
will reenable the MMU, and the MMU might still be in guest context.
In this situation we spin at low priority in real mode waiting for
hwthread_req to become zero.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2014-12-03 10:48:40 +07:00
|
|
|
}
|
2017-12-15 15:14:55 +07:00
|
|
|
|
powerpc/powernv: Handle irq_happened flag correctly in off-line loop
This fixes a bug where it is possible for an off-line CPU to fail to go
into a low-power state (nap/sleep/winkle), and to become unresponsive to
requests from the KVM subsystem to wake up and run a VCPU. What can
happen is that a maskable interrupt of some kind (external, decrementer,
hypervisor doorbell, or HMI) after we have called local_irq_disable() at
the beginning of pnv_smp_cpu_kill_self() and before interrupts are
hard-disabled inside power7_nap/sleep/winkle(). In this situation, the
pending event is marked in the irq_happened flag in the PACA. This
pending event prevents power7_nap/sleep/winkle from going to the
requested low-power state; instead they return immediately. We don't
deal with any of these pending event flags in the off-line loop in
pnv_smp_cpu_kill_self() because power7_nap et al. return 0 in this case,
so we will have srr1 == 0, and none of the processing to clear
interrupts or doorbells will be done.
Usually, the most obvious symptom of this is that a KVM guest will fail
with a console message saying "KVM: couldn't grab cpu N".
This fixes the problem by making sure we handle the irq_happened flags
properly. First, we hard-disable before the off-line loop. Once we have
hard-disabled, the irq_happened flags can't change underneath us. We
unconditionally clear the DEC and HMI flags: there is no processing of
timer interrupts while off-line, and the necessary HMI processing is all
done in lower-level code. We leave the EE and DBELL flags alone for the
first iteration of the loop, so that we won't fail to respond to a
split-core request that came in just before hard-disabling. Within the
loop, we handle external interrupts if the EE bit is set in irq_happened
as well as if the low-power state was interrupted by an external
interrupt. (We don't need to do the msgclr for a pending doorbell in
irq_happened, because doorbells are edge-triggered and don't remain
pending in hardware.) Then we clear both the EE and DBELL flags, and
once clear, they cannot be set again (until this CPU comes online again,
that is).
This also fixes the debug check to not be done when we just ran a KVM
guest or when the sleep didn't happen because of a pending event in
irq_happened.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-10-21 12:06:24 +07:00
|
|
|
smp_mb();
|
2014-05-23 15:15:30 +07:00
|
|
|
|
2017-12-15 15:14:55 +07:00
|
|
|
/*
|
|
|
|
* For kdump kernels, we process the ipi and jump to
|
|
|
|
* crash_ipi_callback
|
|
|
|
*/
|
|
|
|
if (kdump_in_progress()) {
|
|
|
|
/*
|
|
|
|
* If we got to this point, we've not used
|
|
|
|
* NMI's, otherwise we would have gone
|
|
|
|
* via the SRR1_WAKERESET path. We are
|
|
|
|
* using regular IPI's for waking up offline
|
|
|
|
* threads.
|
|
|
|
*/
|
|
|
|
struct pt_regs regs;
|
|
|
|
|
|
|
|
ppc_save_regs(®s);
|
|
|
|
crash_ipi_callback(®s);
|
|
|
|
/* Does not return */
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:15:30 +07:00
|
|
|
if (cpu_core_split_required())
|
|
|
|
continue;
|
|
|
|
|
powerpc/powernv: Handle irq_happened flag correctly in off-line loop
This fixes a bug where it is possible for an off-line CPU to fail to go
into a low-power state (nap/sleep/winkle), and to become unresponsive to
requests from the KVM subsystem to wake up and run a VCPU. What can
happen is that a maskable interrupt of some kind (external, decrementer,
hypervisor doorbell, or HMI) after we have called local_irq_disable() at
the beginning of pnv_smp_cpu_kill_self() and before interrupts are
hard-disabled inside power7_nap/sleep/winkle(). In this situation, the
pending event is marked in the irq_happened flag in the PACA. This
pending event prevents power7_nap/sleep/winkle from going to the
requested low-power state; instead they return immediately. We don't
deal with any of these pending event flags in the off-line loop in
pnv_smp_cpu_kill_self() because power7_nap et al. return 0 in this case,
so we will have srr1 == 0, and none of the processing to clear
interrupts or doorbells will be done.
Usually, the most obvious symptom of this is that a KVM guest will fail
with a console message saying "KVM: couldn't grab cpu N".
This fixes the problem by making sure we handle the irq_happened flags
properly. First, we hard-disable before the off-line loop. Once we have
hard-disabled, the irq_happened flags can't change underneath us. We
unconditionally clear the DEC and HMI flags: there is no processing of
timer interrupts while off-line, and the necessary HMI processing is all
done in lower-level code. We leave the EE and DBELL flags alone for the
first iteration of the loop, so that we won't fail to respond to a
split-core request that came in just before hard-disabling. Within the
loop, we handle external interrupts if the EE bit is set in irq_happened
as well as if the low-power state was interrupted by an external
interrupt. (We don't need to do the msgclr for a pending doorbell in
irq_happened, because doorbells are edge-triggered and don't remain
pending in hardware.) Then we clear both the EE and DBELL flags, and
once clear, they cannot be set again (until this CPU comes online again,
that is).
This also fixes the debug check to not be done when we just ran a KVM
guest or when the sleep didn't happen because of a pending event in
irq_happened.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2015-10-21 12:06:24 +07:00
|
|
|
if (srr1 && !generic_check_cpu_restart(cpu))
|
2017-06-13 20:05:46 +07:00
|
|
|
DBG("CPU%d Unexpected exit while offline srr1=%lx!\n",
|
|
|
|
cpu, srr1);
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
}
|
2017-02-07 07:35:31 +07:00
|
|
|
|
2019-02-12 07:58:29 +07:00
|
|
|
/*
|
|
|
|
* Re-enable decrementer interrupts in LPCR.
|
|
|
|
*
|
|
|
|
* Further, we want stop states to be woken up by decrementer
|
|
|
|
* for non-hotplug cases. So program the LPCR via stop api as
|
|
|
|
* well.
|
|
|
|
*/
|
|
|
|
lpcr_val = mfspr(SPRN_LPCR) | (u64)LPCR_PECE1;
|
|
|
|
pnv_program_cpu_hotplug_lpcr(cpu, lpcr_val);
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
DBG("CPU%d coming online...\n", cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
|
|
|
|
2014-12-12 18:37:40 +07:00
|
|
|
static int pnv_cpu_bootable(unsigned int nr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Starting with POWER8, the subcore logic relies on all threads of a
|
|
|
|
* core being booted so that they can participate in split mode
|
|
|
|
* switches. So on those machines we ignore the smt_enabled_at_boot
|
|
|
|
* setting (smt-enabled on the kernel command line).
|
|
|
|
*/
|
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_207S))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return smp_generic_cpu_bootable(nr);
|
|
|
|
}
|
|
|
|
|
2017-04-05 14:54:50 +07:00
|
|
|
static int pnv_smp_prepare_cpu(int cpu)
|
|
|
|
{
|
|
|
|
if (xive_enabled())
|
|
|
|
return xive_smp_prepare_cpu(cpu);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-26 14:32:38 +07:00
|
|
|
/* Cause IPI as setup by the interrupt controller (xics or xive) */
|
|
|
|
static void (*ic_cause_ipi)(int cpu);
|
|
|
|
|
2017-04-13 17:16:21 +07:00
|
|
|
static void pnv_cause_ipi(int cpu)
|
|
|
|
{
|
|
|
|
if (doorbell_try_core_ipi(cpu))
|
|
|
|
return;
|
|
|
|
|
2017-04-26 14:32:38 +07:00
|
|
|
ic_cause_ipi(cpu);
|
2017-04-13 17:16:21 +07:00
|
|
|
}
|
|
|
|
|
2017-04-05 14:54:50 +07:00
|
|
|
static void __init pnv_smp_probe(void)
|
|
|
|
{
|
|
|
|
if (xive_enabled())
|
|
|
|
xive_smp_probe();
|
|
|
|
else
|
|
|
|
xics_smp_probe();
|
2017-04-13 17:16:21 +07:00
|
|
|
|
2017-04-13 17:16:24 +07:00
|
|
|
if (cpu_has_feature(CPU_FTR_DBELL)) {
|
2017-04-26 14:32:38 +07:00
|
|
|
ic_cause_ipi = smp_ops->cause_ipi;
|
|
|
|
WARN_ON(!ic_cause_ipi);
|
|
|
|
|
2018-07-05 15:47:00 +07:00
|
|
|
if (cpu_has_feature(CPU_FTR_ARCH_300))
|
|
|
|
smp_ops->cause_ipi = doorbell_global_ipi;
|
|
|
|
else
|
2017-04-13 17:16:24 +07:00
|
|
|
smp_ops->cause_ipi = pnv_cause_ipi;
|
2017-04-13 17:16:21 +07:00
|
|
|
}
|
2017-04-05 14:54:50 +07:00
|
|
|
}
|
|
|
|
|
2017-09-29 10:29:42 +07:00
|
|
|
static int pnv_system_reset_exception(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
if (smp_handle_nmi_ipi(regs))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pnv_cause_nmi_ipi(int cpu)
|
|
|
|
{
|
|
|
|
int64_t rc;
|
|
|
|
|
|
|
|
if (cpu >= 0) {
|
2018-05-10 19:21:48 +07:00
|
|
|
int h = get_hard_smp_processor_id(cpu);
|
|
|
|
|
|
|
|
if (opal_check_token(OPAL_QUIESCE))
|
|
|
|
opal_quiesce(QUIESCE_HOLD, h);
|
|
|
|
|
|
|
|
rc = opal_signal_system_reset(h);
|
|
|
|
|
|
|
|
if (opal_check_token(OPAL_QUIESCE))
|
|
|
|
opal_quiesce(QUIESCE_RESUME, h);
|
|
|
|
|
2017-09-29 10:29:42 +07:00
|
|
|
if (rc != OPAL_SUCCESS)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else if (cpu == NMI_IPI_ALL_OTHERS) {
|
|
|
|
bool success = true;
|
|
|
|
int c;
|
|
|
|
|
2018-05-10 19:21:48 +07:00
|
|
|
if (opal_check_token(OPAL_QUIESCE))
|
|
|
|
opal_quiesce(QUIESCE_HOLD, -1);
|
2017-09-29 10:29:42 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not use broadcasts (yet), because it's not clear
|
|
|
|
* exactly what semantics Linux wants or the firmware should
|
|
|
|
* provide.
|
|
|
|
*/
|
|
|
|
for_each_online_cpu(c) {
|
|
|
|
if (c == smp_processor_id())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
rc = opal_signal_system_reset(
|
|
|
|
get_hard_smp_processor_id(c));
|
|
|
|
if (rc != OPAL_SUCCESS)
|
|
|
|
success = false;
|
|
|
|
}
|
2018-05-10 19:21:48 +07:00
|
|
|
|
|
|
|
if (opal_check_token(OPAL_QUIESCE))
|
|
|
|
opal_quiesce(QUIESCE_RESUME, -1);
|
|
|
|
|
2017-09-29 10:29:42 +07:00
|
|
|
if (success)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Caller will fall back to doorbells, which may pick
|
|
|
|
* up the remainders.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-20 00:44:52 +07:00
|
|
|
static struct smp_ops_t pnv_smp_ops = {
|
2017-04-13 17:16:21 +07:00
|
|
|
.message_pass = NULL, /* Use smp_muxed_ipi_message_pass */
|
|
|
|
.cause_ipi = NULL, /* Filled at runtime by pnv_smp_probe() */
|
2016-12-20 01:30:09 +07:00
|
|
|
.cause_nmi_ipi = NULL,
|
2017-04-05 14:54:50 +07:00
|
|
|
.probe = pnv_smp_probe,
|
|
|
|
.prepare_cpu = pnv_smp_prepare_cpu,
|
2011-09-20 00:44:57 +07:00
|
|
|
.kick_cpu = pnv_smp_kick_cpu,
|
2011-09-20 00:44:52 +07:00
|
|
|
.setup_cpu = pnv_smp_setup_cpu,
|
2014-12-12 18:37:40 +07:00
|
|
|
.cpu_bootable = pnv_cpu_bootable,
|
2011-09-20 00:44:54 +07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
.cpu_disable = pnv_smp_cpu_disable,
|
|
|
|
.cpu_die = generic_cpu_die,
|
|
|
|
#endif /* CONFIG_HOTPLUG_CPU */
|
2011-09-20 00:44:52 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* This is called very early during platform setup_arch */
|
|
|
|
void __init pnv_smp_init(void)
|
|
|
|
{
|
2017-09-29 10:29:42 +07:00
|
|
|
if (opal_check_token(OPAL_SIGNAL_SYSTEM_RESET)) {
|
|
|
|
ppc_md.system_reset_exception = pnv_system_reset_exception;
|
|
|
|
pnv_smp_ops.cause_nmi_ipi = pnv_cause_nmi_ipi;
|
|
|
|
}
|
2011-09-20 00:44:52 +07:00
|
|
|
smp_ops = &pnv_smp_ops;
|
|
|
|
|
2011-09-20 00:44:54 +07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
|
|
|
ppc_md.cpu_die = pnv_smp_cpu_kill_self;
|
2017-12-15 15:14:55 +07:00
|
|
|
#ifdef CONFIG_KEXEC_CORE
|
|
|
|
crash_wake_offline = 1;
|
|
|
|
#endif
|
2011-09-20 00:44:54 +07:00
|
|
|
#endif
|
2011-09-20 00:44:52 +07:00
|
|
|
}
|