qemu/target/ppc
Nicholas Piggin fb802acdc8 ppc/spapr: Fix RTAS stopped state
This change takes the CPUPPCState 'quiesced' field added for powernv
hardware CPU core controls (used to stop and start cores), and extends
it to spapr to model the "RTAS stopped" state. This prevents the
schedulers attempting to run stopped CPUs unexpectedly, which can cause
hangs and possibly other unexpected behaviour.

The detail of the problematic situation is this:

A KVM spapr guest boots with all secondary CPUs defined to be in the
"RTAS stopped" state. In this state, the CPU is only responsive to the
start-cpu RTAS call. This behaviour is modeled in QEMU with the
start_powered_off feature, which sets ->halted on secondary CPUs at
boot. ->halted=true looks like an idle / sleep / power-save state which
typically is responsive to asynchronous interrupts, but spapr clears
wake-on-interrupt bits in the LPCR SPR. This more-or-less works.

Commit e8291ec16d ("target/ppc: fix timebase register reset state")
recently caused the decrementer to expire sooner at boot, causing a
decrementer exception on secondary CPUs in RTAS stopped state. This
was not a problem on TCG, but KVM limits how a guest can modify LPCR, in
particular it prevents the clearing of wake-on-interrupt bits, and so in
the course of CPU register synchronisation, the LPCR as set by spapr to
model the RTAS stopped state is overwritten with KVM's LPCR value, and
that then causes QEMU's interrupt code to notice the expired decrementer
exception, turn that into an interrupt, and set CPU_INTERRUPT_HARD.

That causes the CPU to be kicked, and the KVM vCPU thread to loop
calling kvm_cpu_exec(). kvm_cpu_exec() calls
kvm_arch_process_async_events(), which on ppc just returns ->halted.
This is still true, so it returns immediately with EXCP_HLT, and the
vCPU never goes to sleep because qemu_wait_io_event() sees
CPU_INTERRUPT_HARD is set. All this while the vCPU holds the bql.  This
causes the boot CPU to eventually lock up when it needs the bql.

So make 'quiesced' represent the "RTAS stopped" state, and have it
explicitly not respond to exceptions (interrupt conditions) rather than
rely on machine register state to model that state. This matches the
powernv quiesced state very well because it essentially turns off the
CPU core via a side-band control unit.

There are still issues with QEMU and KVM idea of LPCR diverging and that
is quite ugly and fragile that should be fixed. spapr should synchronize
its LPCR properly with KVM, and not try to use values that KVM does not
support.

Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
Tested-by: Misbah Anjum N <misanjum@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
2025-03-20 14:48:17 +10:00
..
translate target/ppc: Fix lxvx/stxvx facility check 2024-09-22 06:55:21 +02:00
arch_dump.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
compat.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
cpu-models.c target/ppc: Add Power11 DD2.0 processor 2024-11-04 09:12:42 +10:00
cpu-models.h target/ppc: Add Power11 DD2.0 processor 2024-11-04 09:12:42 +10:00
cpu-param.h target/*: Remove TARGET_LONG_BITS from cpu-param.h 2025-02-08 12:41:33 -08:00
cpu-qom.h target/ppc: Use GDBFeature for dynamic XML 2024-02-28 09:09:25 +00:00
cpu.c ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
cpu.h ppc/spapr: Fix RTAS stopped state 2025-03-20 14:48:17 +10:00
cpu_init.c target/ppc: Wire up BookE ATB registers for e500 family 2025-03-11 22:43:32 +10:00
cpu_init.h target/ppc: Add Power11 DD2.0 processor 2024-11-04 09:12:42 +10:00
dfp_helper.c target/ppc: replace assert(0) with g_assert_not_reached() 2024-09-24 13:53:35 +02:00
excp_helper.c ppc/spapr: Fix RTAS stopped state 2025-03-20 14:48:17 +10:00
fpu_helper.c target/ppc: Use env->fp_status in helper_compute_fprf functions 2024-12-11 15:31:03 +00:00
gdbstub.c target/ppc: Fix GDB register indexing on secondary CPUs 2024-03-30 18:50:24 +10:00
helper.h ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
helper_regs.c exec: Declare tlb_flush*() in 'exec/cputlb.h' 2025-03-08 07:56:14 -08:00
helper_regs.h target/ppc: Fix PMU hflags calculation 2023-06-10 10:19:24 -03:00
insn32.decode target/ppc: Move VSX fp compare insns to decodetree. 2024-07-26 09:51:33 +10:00
insn64.decode target/ppc: Implemented [pm]xvbf16ger2* 2022-05-26 17:11:33 -03:00
int_helper.c target/ppc: Move VMX integer add/sub saturate insns to decodetree. 2024-07-26 09:51:33 +10:00
internal.h target/ppc: Make powerpc_excp() prototype public 2025-03-11 22:43:31 +10:00
Kconfig ppc: switch boards to "default y" 2024-05-03 15:47:47 +02:00
kvm.c ppc: spapr: Enable 2nd DAWR on Power10 pSeries machine 2025-03-11 22:43:32 +10:00
kvm_ppc.h ppc: spapr: Enable 2nd DAWR on Power10 pSeries machine 2025-03-11 22:43:32 +10:00
machine.c ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
mem_helper.c target/ppc: Move VSX vector with length storage access insns to decodetree. 2024-07-26 09:51:33 +10:00
meson.build target/ppc: Move TCG specific exception handlers to tcg-excp_helper.c 2025-03-11 22:43:31 +10:00
misc_helper.c ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
mmu-book3s-v3.c target/ppc/mmu-radix64: Remove externally unused parts from header 2024-07-26 09:51:34 +10:00
mmu-book3s-v3.h target/ppc: Remove includes from mmu-book3s-v3.h 2024-07-26 09:51:34 +10:00
mmu-booke.c target/ppc: Move out BookE and related MMU functions from mmu_common.c 2024-05-24 09:43:13 +10:00
mmu-booke.h target/ppc: Move out BookE and related MMU functions from mmu_common.c 2024-05-24 09:43:13 +10:00
mmu-books.h target/ppc: introduce mmu-books.h 2021-07-09 10:38:19 +10:00
mmu-hash32.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
mmu-hash32.h target/ppc/mmu-hash32.c: Move get_pteg_offset32() to the header 2024-07-26 09:51:34 +10:00
mmu-hash64.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
mmu-hash64.h target/ppc: Unexport some functions from mmu-book3s-v3.h 2024-07-26 09:51:34 +10:00
mmu-radix64.c target/ppc: Avoid warning message for zero process table entries 2025-03-11 22:43:32 +10:00
mmu-radix64.h target/ppc/mmu-radix64: Remove externally unused parts from header 2024-07-26 09:51:34 +10:00
mmu_common.c include: Rename sysemu/ -> system/ 2024-12-20 17:44:56 +01:00
mmu_helper.c exec: Declare tlb_set_page() in 'exec/cputlb.h' 2025-03-08 07:56:14 -08:00
power8-pmu-regs.c.inc target/ppc: Add new hflags to support BHRB 2024-05-24 08:57:50 +10:00
power8-pmu.c target/ppc: Add recording of taken branches to BHRB 2024-05-24 09:33:06 +10:00
power8-pmu.h target/ppc: Add recording of taken branches to BHRB 2024-05-24 09:33:06 +10:00
ppc-qmp-cmds.c target/ppc: Prefer fast cpu_env() over slower CPU QOM cast macro 2024-03-12 12:04:24 +01:00
spr_common.h ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
tcg-excp_helper.c ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
tcg-stub.c hw/ppc/spapr_hcall: Allow elision of softmmu_resize_hpt_prep 2024-02-23 23:24:42 +10:00
timebase_helper.c ppc/pnv: Add POWER10 ChipTOD quirk for big-core 2024-07-26 09:21:06 +10:00
trace-events target/ppc: Improve KVM hypercall trace 2022-04-20 18:00:30 -03:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
translate.c ppc: Enable 2nd DAWR support on Power10 PowerNV machine 2025-03-11 22:43:32 +10:00
user_only_helper.c target/ppc: Prefer fast cpu_env() over slower CPU QOM cast macro 2024-03-12 12:04:24 +01:00