KVM: PPC: BookE: Fix boot hang on preemptible kernels
Subsystems (3)
Shrikanth Hegde
reviewerv5 cover KVM: PPC: BookE: Fix boot hang on preemptible kernels
Christian Zigotzky had reported that preemptible kernels don't boot on his FSL Cyrus+ board. The board freezes on running either full/lazy preemption and has been an issue for a while now (years!).
https://lore.kernel.org/all/[email protected]/#t
More details in cover-letter of v2[1]
v4->v5:
- Removed fixes tag for patch 1 as backports could be complicated and added stable instead.
- Collected tags.
v3->v4:
- Modify hard_irq_disable for PPC32 to simply call local_irq_disable which does tracing/lockdep in addition to actually disabling the EE bit. (Ritesh Harjani)
- Modify the guest entry code to use the above (Ritesh Harjani)
- Collected tags. Thanks to Ritesh Harjani, Narayana Murty N.
v2->v3:
- Comment removal (Mukesh Kumar Chaurasiya)
- Add missing booke change (Sashiko)
- Collect tags (Thanks to Mukesh Kumar Chaurasiya, Christian Zigotzky)
v1->v2:
- Re-order to avoid preempt count dance (Narayana Murty N)
- Do only hard_irq_disable on PPC64 to avoid second warning. On PPC32 use local_irq_disable to acheive the same. (Ritesh Harjani)
v2: https://lore.kernel.org/all/[email protected]/#t [1]
v4: https://lore.kernel.org/all/[email protected]/
Apologies in case any nitpicks are missed.
I'm surviving on half a night's sleep these days.
As said in v2, remaining usecases of hard_irq_disable will be taken up later, which are in:arch/powerpc/kexec/core_64.carch/powerpc/kvm/book3s_hv.c arch/powerpc/platforms/85xx/smp.c
Shrikanth Hegde (3):
PPC32: Fix hard_irq_disable to follow tracing and lockdep state
KVM: PPC: BookE: Load FP and Altivec before enabling the interrupts
KVM: PPC: Hard disable interrupts before guest entry
arch/powerpc/include/asm/hw_irq.h | 2 +- arch/powerpc/kvm/booke.c | 4 +--- arch/powerpc/kvm/powerpc.c | 8 -------- 3 files changed, 2 insertions(+), 12 deletions(-)
Signature · 1 line
2.54.0
Shrikanth Hegde
reviewerPATCH v5 1/3 PPC32: Fix hard_irq_disable to follow tracing and lockdep state
On PPC32, the code for hard_irq_disable has diverged and it doesn't do lockdep/tracing anymore, leading to use of both local_irq_disable and hard_irq_disable on PPC32 to overcome those.
That is un-necessary, instead simply calling local_irq_disable is enough. It disables EE bit and does lockdep tracking.
Subsequent patch uses this API in KVM code to avoid the warnings. Wider use of it is possible, but it will be taken subsequently.
---
PS: New warnings would have started since commit 12013e3d4695 ("KVM: powerpc: Use generic xfer to guest work function") which added local_irq_disable for 32 bit. The proper fix may date back years ago. To avoid backport complications, keeping it backported till 7.2. So removed fixes tag and cc'ed stable.
Also, 32 bit shouldn't need hard_irq_disable. But that can only be taken up subsequently.
Also, below fix isn't needed anymore.
https://lore.kernel.org/linuxppc-dev/a14571be1897955f43d9994f0e093de3ada6ecde.1793447880.git.ritesh.list@gmail.com/
arch/powerpc/include/asm/hw_irq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/include/asm/hw_irq.h +1 -1
@@ -464,7 +464,7 @@ static inline bool arch_irqs_disabled(void)return arch_irqs_disabled_flags (arch_local_save_flags ()); } -#define hard_irq_disable () arch_local_irq_disable() +#define hard_irq_disable () local_irq_disable()static inline bool regs_irqs_disabled (struct pt_regs *regs) {
Signature · 1 line
2.54.0
Re: [PATCH v5 1/3] PPC32: Fix hard_irq_disable to follow tracing and lockdep state
Quoted 46 lines · Shrikanth Hegde
On PPC32, the code for
hard_irq_disablehas diverged and it doesn't do lockdep/tracing anymore, leading to use of bothlocal_irq_disableandhard_irq_disableon PPC32 to overcome those.That is un-necessary, instead simply calling
local_irq_disableis enough. It disables EE bit and does lockdep tracking.Subsequent patch uses this API in KVM code to avoid the warnings. Wider use of it is possible, but it will be taken subsequently.
Cc <[email protected]> # v7.2+Suggested-by Ritesh Harjani (IBM) <[email protected]>Reviewed-by Ritesh Harjani (IBM) <[email protected]>Signed-off-by Shrikanth Hegde <[email protected]>---
PS: New warnings would have started since commit12013e3d4695("KVM: powerpc: Use generic xfer to guest work function") which addedlocal_irq_disablefor 32 bit. The proper fix may date back years ago. To avoid backport complications, keeping it backported till 7.2. So removed fixes tag and cc'ed stable.Also, 32 bit shouldn't need
hard_irq_disable. But that can only be taken up subsequently.Also, below fix isn't needed anymore.
https://lore.kernel.org/linuxppc-dev/a14571be1897955f43d9994f0e093de3ada6ecde.1793447880.git.ritesh.list@gmail.com/arch/powerpc/include/asm/hw_irq.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/powerpc/include/asm/hw_irq.h +1
-1@@ -464,7 +464,7 @@ static inline bool arch_irqs_disabled(void)return arch_irqs_disabled_flags (arch_local_save_flags ()); } -#define hard_irq_disable () arch_local_irq_disable() +#define hard_irq_disable () local_irq_disable()static inline bool regs_irqs_disabled (struct pt_regs *regs) {Signature · 1 line
2.54.0
Cool, this makes things simple.
Shrikanth Hegde
reviewerPATCH v5 2/3 KVM: PPC: BookE: Load FP and Altivec before enabling the interrupts
In reply to Shrikanth HegdeChristian reported that booting preemptible kernel on FSL Cyrus+ board causes boot hang.
The logs pointed that system was busy in printing below warning.
WARNING: at .enable_kernel_fp+0x30/0x78, CPU#3: qemu-system-ppc/4884 Modules linked in: CPU: 3 UID: 1000 PID: 4884 Comm: qemu-system-ppc Not tainted 7.3.0-rc1-powerpc64-smp-preempt #1 PREEMPT NIP [c000000000003338] .enable_kernel_fp+0x30/0x78 LR [c00000000005de84] .kvmppc_load_guest_fp+0x30/0x80 Call Trace: [c000000085ca7700] [c00000000005de84] .kvmppc_load_guest_fp+0x30/0x80 [c000000085ca7780] [c00000000005f2a0] .kvmppc_handle_exit+0x5bc/0x5cc [c000000085ca7830] [c00000000006204c] .kvmppc_resume_host+0xb8/0x10c
Which is...
void enable_kernel_fp(void)
{
unsigned long cpumsr;
WARN_ON(preemptible());And...
Though irq's are hard disabled after kvmppc_prepare_to_enter, but kvmppc_fix_ee_before_entry enables the softmask's IRQ state. That causes the irqs_disabled to return false.
Hence leading to the warnings.
Fix it by re-ordering the code to load the FP and Altivec before enabling the softmask IRQ state.
--- arch/powerpc/kvm/booke.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/powerpc/kvm/booke.c +1 -2
@@ -1404,10 +1404,9 @@ int kvmppc_handle_exit(struct kvm_vcpu *vcpu, unsigned int exit_nr)if (s <=0 ) r = (s <<2 ) |RESUME_HOST | (r &RESUME_FLAG_NV );else { -/* interrupts now hard-disabled */ -kvmppc_fix_ee_before_entry ();kvmppc_load_guest_fp (vcpu);kvmppc_load_guest_altivec (vcpu); +kvmppc_fix_ee_before_entry (); } }
Signature · 1 line
2.54.0
Shrikanth Hegde
reviewerPATCH v5 3/3 KVM: PPC: Hard disable interrupts before guest entry
In reply to Shrikanth HegdeAfter applying preempt disable patch, i.e PATCH 2/3, Christian reported a subsequent warning stopping his board to boot properly.
WARNING: at .kvmppc_fix_ee_before_entry+0x10/0x28, CPU#0: qemu-system-ppc/4667 CPU: 0 UID: 1000 PID: 4667 Comm: qemu-system-ppc Tainted: G W 7.3.0-rc4-2-powerpc64-smp #1 PREEMPT Tainted: [W]=WARN Hardware name: varisys,CYRUS5040 e5500 0x80240012 CoreNet Generic NIP [c00000000005dc3c] .kvmppc_fix_ee_before_entry+0x10/0x28 LR [c00000000005f298] .kvmppc_handle_exit+0x5b4/0x5e8 Call Trace: [c000000086587780] [c00000000005ee10] .kvmppc_handle_exit+0x12c/0x5e8 (unreliable) [c000000086587830] [c000000000062068] .kvmppc_resume_host+0xb8/0x10c
It triggers below warning...
static inline void kvmppc_fix_ee_before_entry(void)
{
trace_hardirqs_on();
/*
* To avoid races, the caller must have gone directly from having
* interrupts fully-enabled to hard-disabled.
*/
WARN_ON(local_paca->irq_happened != PACA_IRQ_HARD_DIS);This happens since kvmppc_prepare_to_enter does first local_irq_disable followed by hard_irq_disable. This leaves a small window where interrupt may occur and it could set the irq pending bit in PACA.
That local_irq_disable was necessary for PPC32 to track the lockdep state etc. On PPC64 hard_irq_disable is good enough. There is no need to do both. With now hard_irq_disable, doing local_irq_disable for PPC32, just calling that is enough.
--- arch/powerpc/kvm/booke.c | 1 - arch/powerpc/kvm/powerpc.c | 8 -------- 2 files changed, 9 deletions(-)
arch/powerpc/kvm/booke.c +0 -1
@@ -722,7 +722,6 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)if (vcpu->arch.shared->msr &MSR_WE ) {local_irq_enable ();kvm_vcpu_halt (vcpu); -local_irq_disable ();hard_irq_disable ();kvmppc_set_exit_type (vcpu,EMULATED_MTMSRWE_EXITS );
arch/powerpc/kvm/powerpc.c +0 -8
@@ -81,12 +81,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)int r;WARN_ON (irqs_disabled ()); -/* -* local_irq_disable() first: on 32-bit, hard_irq_disable() alone is a -* raw MSR[EE] clear that bypasses the lockdep/irq-tracing state, and -* the xfer_to_guest_mode helpers assert IRQs are seen as disabled. -*/ -local_irq_disable ();hard_irq_disable ();while (true) {
@@ -101,7 +95,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)*/ local_irq_enable (); r =kvm_xfer_to_guest_mode_handle_work (vcpu); -local_irq_disable ();hard_irq_disable ();if (r) {/*
@@ -134,7 +127,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)local_irq_enable ();trace_kvm_check_requests (vcpu); r =kvmppc_core_check_requests (vcpu); -local_irq_disable ();hard_irq_disable ();if (r >0 )continue ;
Signature · 1 line
2.54.0
Quoted 8 lines · Shrikanth Hegde
Christian Zigotzky had reported that preemptible kernels don't boot on his FSL Cyrus+ board. The board freezes on running either full/lazy preemption and has been an issue for a while now (years!).
https://lore.kernel.org/all/[email protected]/#t
More details in cover-letter of v2[1][...]
Applied to powerpc/fixes.
[1/3] PPC32: Fix hard_irq_disable to follow tracing and lockdep state
https://git.kernel.org/powerpc/c/2672bdcc7857073722c4772831a24b14832ee88a [2/3] KVM: PPC: BookE: Load FP and Altivec before enabling the interrupts https://git.kernel.org/powerpc/c/cf2e6ef0a39e0682d22292f1b9e9cd865482e86d [3/3] KVM: PPC: Hard disable interrupts before guest entry https://git.kernel.org/powerpc/c/d0160f6470d1b8a4ce25d98bb8d1b0495a922d4f
cheers