diff mbox series

[4/5] KVM: PPC: Book3S HV: Implement LPCR[AIL]=3 mode for injected interrupts

Message ID 20190520005659.18628-4-npiggin@gmail.com
State Changes Requested
Headers show
Series [1/5] KVM: PPC: Book3S: Define and use SRR1_MSR_BITS | expand

Commit Message

Nicholas Piggin May 20, 2019, 12:56 a.m. UTC
kvmppc_inject_interrupt does not implement LPCR[AIL]!=0 modes, which
can result in the guest receiving interrupts as if LPCR[AIL]=0
contrary to the ISA.

In practice, Linux guests cope with this deviation, but it should be
fixed.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/kvm/book3s_hv_builtin.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Paul Mackerras June 17, 2019, 1:48 a.m. UTC | #1
On Mon, May 20, 2019 at 10:56:58AM +1000, Nicholas Piggin wrote:
> kvmppc_inject_interrupt does not implement LPCR[AIL]!=0 modes, which
> can result in the guest receiving interrupts as if LPCR[AIL]=0
> contrary to the ISA.
> 
> In practice, Linux guests cope with this deviation, but it should be
> fixed.

Comment below...

> diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
> index 5ae7f8359368..2453a085da86 100644
> --- a/arch/powerpc/kvm/book3s_hv_builtin.c
> +++ b/arch/powerpc/kvm/book3s_hv_builtin.c
> @@ -797,6 +797,20 @@ void kvmppc_inject_interrupt_hv(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags)
>  		new_msr |= msr & MSR_TS_MASK;
>  #endif
>  
> +#ifdef CONFIG_PPC_BOOK3S_64

Why do we need this ifdef?  This file doesn't get compiled when
CONFIG_PPC_BOOK3S_64=n, right?

Paul.
diff mbox series

Patch

diff --git a/arch/powerpc/kvm/book3s_hv_builtin.c b/arch/powerpc/kvm/book3s_hv_builtin.c
index 5ae7f8359368..2453a085da86 100644
--- a/arch/powerpc/kvm/book3s_hv_builtin.c
+++ b/arch/powerpc/kvm/book3s_hv_builtin.c
@@ -797,6 +797,20 @@  void kvmppc_inject_interrupt_hv(struct kvm_vcpu *vcpu, int vec, u64 srr1_flags)
 		new_msr |= msr & MSR_TS_MASK;
 #endif
 
+#ifdef CONFIG_PPC_BOOK3S_64
+	/*
+	 * LPCR[AIL]=2 deliveries are not supported.
+	 * AIL does not apply to HMI, but it doesn't get delivered to guests.
+	 */
+	if (vec != BOOK3S_INTERRUPT_SYSTEM_RESET &&
+	    vec != BOOK3S_INTERRUPT_MACHINE_CHECK &&
+	    (vcpu->arch.vcore->lpcr & LPCR_AIL) == LPCR_AIL_3 &&
+	    (msr & (MSR_IR|MSR_DR)) == (MSR_IR|MSR_DR) ) {
+		new_msr |= MSR_IR | MSR_DR;
+		new_pc += 0xC000000000004000ULL;
+	}
+#endif
+
 	kvmppc_set_srr0(vcpu, pc);
 	kvmppc_set_srr1(vcpu, (msr & SRR1_MSR_BITS) | srr1_flags);
 	kvmppc_set_pc(vcpu, new_pc);