KVM: PPC: Book3S HV: check for XIVE device before executing the XICS hcalls
Subsystems (2)
PATCH 1/1 KVM: PPC: Book3S HV: check for XIVE device before executing the XICS hcalls
When QEMU is started with the option kernel_irqchip=òff, the kvm XICS hcalls are being used even though a kvm XICS device has not been created on the host, resulting quickly in a failure and a broken guest.
The test checking if there is a XIVE device in the VM before executing the XICS hcalls is missing from the recent XICS-over-XIVE glue.
--- arch/powerpc/kvm/book3s_xive_template.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
arch/powerpc/kvm/book3s_xive_template.c +19 -0
@@ -276,11 +276,15 @@ static u32 GLUE(X_PFX,scan_interrupts)(struct kvmppc_xive_vcpu *xc,X_STATIC unsigned long GLUE (X_PFX ,h_xirr )(struct kvm_vcpu *vcpu) {struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu; +struct kvmppc_xive *xive = vcpu->kvm->arch.xive;u8 old_cppr;u32 hirq;pr_devel ("H_XIRR\n" ); +if (!xive) +return H_TOO_HARD ; + xc->GLUE (X_STAT_PFX ,h_xirr)++;/* First collect pending bits from HW */
@@ -335,11 +339,15 @@ X_STATIC unsigned long GLUE(X_PFX,h_xirr)(struct kvm_vcpu *vcpu)X_STATIC unsigned long GLUE (X_PFX ,h_ipoll )(struct kvm_vcpu *vcpu,unsigned long server) {struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu; +struct kvmppc_xive *xive = vcpu->kvm->arch.xive;u8 pending = xc->pending;u32 hirq;pr_devel ("H_IPOLL(server=%ld)\n" , server); +if (!xive) +return H_TOO_HARD ; + xc->GLUE (X_STAT_PFX ,h_ipoll)++;/* Grab the target VCPU if not the current one */
@@ -388,8 +396,12 @@ static void GLUE(X_PFX,push_pending_to_hw)(struct kvmppc_xive_vcpu *xc) X_STATIC int GLUE(X_PFX,h_cppr)(struct kvm_vcpu *vcpu, unsigned long cppr) {struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu; +struct kvmppc_xive *xive = vcpu->kvm->arch.xive;u8 old_cppr; +if (!xive) +return H_TOO_HARD ; +pr_devel ("H_CPPR(cppr=%ld)\n" , cppr); xc->GLUE (X_STAT_PFX ,h_cppr)++;
@@ -435,6 +447,9 @@ X_STATIC int GLUE(X_PFX,h_eoi)(struct kvm_vcpu *vcpu, unsigned long xirr)u16 src;int rc =0 ; +if (!xive) +return H_TOO_HARD ; +pr_devel ("H_EOI(xirr=%08lx)\n" , xirr); xc->GLUE (X_STAT_PFX ,h_eoi)++;
@@ -532,9 +547,13 @@ X_STATIC int GLUE(X_PFX,h_ipi)(struct kvm_vcpu *vcpu, unsigned long server, unsigned long mfrr) {struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu; +struct kvmppc_xive *xive = vcpu->kvm->arch.xive;pr_devel ("H_IPI(server=%08lx,mfrr=%ld)\n" , server, mfrr); +if (!xive) +return H_TOO_HARD ; + xc->GLUE (X_STAT_PFX ,h_ipi)++;/* Find target */
Signature · 1 line
2.13.6
Quoted 9 lines · Cédric Le Goater
When QEMU is started with the option kernel_irqchip=òff, the kvm XICS hcalls are being used even though a kvm XICS device has not been created on the host, resulting quickly in a failure and a broken guest.
The test checking if there is a XIVE device in the VM before executing the XICS hcalls is missing from the recent XICS-over-XIVE glue.
Signed-off-by Cédric Le Goater <[email protected]>
I think this is fixing the same bug that commit 00bb6ae50062 ("KVM:
PPC: Book3S HV: Don't call real-mode XICS hypercall handlers if not enabled", 2017-10-26) addresses.
Do you think this patch is needed in addition to 00bb6ae50062?
Paul.
Quoted 9 lines · Paul Mackerras
Quoted 8 lines · Cédric Le Goater
When QEMU is started with the option kernel_irqchip=òff, the kvm XICS hcalls are being used even though a kvm XICS device has not been created on the host, resulting quickly in a failure and a broken guest.
The test checking if there is a XIVE device in the VM before executing the XICS hcalls is missing from the recent XICS-over-XIVE glue.
Quoted 7 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>I think this is fixing the same bug that commit
00bb6ae50062("KVM:
PPC: Book3S HV: Don't call real-mode XICS hypercall handlers if not enabled", 2017-10-26) addresses.Do you think this patch is needed in addition to
00bb6ae50062?
No. I think 00bb6ae50062 is fine.
It is a bit redundant for P8 systems because the XICS device availability in the VM is already tested in the xics_rm_h_* hcalls with :
struct kvmppc_xics *xics = vcpu->kvm->arch.xics; if (!xics || !xics->real_mode) return H_TOO_HARD;
But, as the XICS-over-XIVE glue also assigns the VCPU 'arch.irq_type' field to KVMPPC_IRQ_XICS, we can use the macro kvmppc_xics_enabled() for both backend in the top level hcalls.
Letting each backend decide whether H_TOO_HARD should be returned might be more precise. I think we will clarify that when XIVE exploitation mode support is added to KVM.
Thanks,
C.