OSDN Git Service

KVM: PPC: Book3S HV: Set LPCR[HDICE] before writing HDEC
authorPaul Mackerras <paulus@ozlabs.org>
Thu, 3 Sep 2020 07:55:40 +0000 (17:55 +1000)
committerPaul Mackerras <paulus@ozlabs.org>
Thu, 17 Sep 2020 01:38:17 +0000 (11:38 +1000)
commit35dfb43c243b28658ef757a2b9c6454f99cfc43c
tree5134339e412f8f1e425cf6c0312e3513bfbad571
parent05e6295dc7de859c9d56334805485c4d20bebf25
KVM: PPC: Book3S HV: Set LPCR[HDICE] before writing HDEC

POWER8 and POWER9 machines have a hardware deviation where generation
of a hypervisor decrementer exception is suppressed if the HDICE bit
in the LPCR register is 0 at the time when the HDEC register
decrements from 0 to -1.  When entering a guest, KVM first writes the
HDEC register with the time until it wants the CPU to exit the guest,
and then writes the LPCR with the guest value, which includes
HDICE = 1.  If HDEC decrements from 0 to -1 during the interval
between those two events, it is possible that we can enter the guest
with HDEC already negative but no HDEC exception pending, meaning that
no HDEC interrupt will occur while the CPU is in the guest, or at
least not until HDEC wraps around.  Thus it is possible for the CPU to
keep executing in the guest for a long time; up to about 4 seconds on
POWER8, or about 4.46 years on POWER9 (except that the host kernel
hard lockup detector will fire first).

To fix this, we set the LPCR[HDICE] bit before writing HDEC on guest
entry.

Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_hv_interrupts.S