KVM: PPC: Book3S HV: Add new capability to control MCE behaviour
authorAravinda Prasad <aravinda@linux.vnet.ibm.com>
Thu, 11 May 2017 11:02:48 +0000 (16:32 +0530)
committerPaul Mackerras <paulus@ozlabs.org>
Wed, 21 Jun 2017 03:37:08 +0000 (13:37 +1000)
This introduces a new KVM capability to control how KVM behaves
on machine check exception (MCE) in HV KVM guests.

If this capability has not been enabled, KVM redirects machine check
exceptions to guest's 0x200 vector, if the address in error belongs to
the guest. With this capability enabled, KVM will cause a guest exit
with the exit reason indicating an NMI.

The new capability is required to avoid problems if a new kernel/KVM
is used with an old QEMU, running a guest that doesn't issue
"ibm,nmi-register".  As old QEMU does not understand the NMI exit
type, it treats it as a fatal error.  However, the guest could have
handled the machine check error if the exception was delivered to
guest's 0x200 interrupt vector instead of NMI exit in case of old
QEMU.

[paulus@ozlabs.org - Reworded the commit message to be clearer,
 enable only on HV KVM.]

Signed-off-by: Aravinda Prasad <aravinda@linux.vnet.ibm.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Documentation/virtual/kvm/api.txt
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kernel/asm-offsets.c
arch/powerpc/kvm/powerpc.c
include/uapi/linux/kvm.h

index 68b66b538d2d1fc47aea7a42cb182a6c9b5b8511..1531a3cd548fa57e47c9138bae0d4d68b13d5c98 100644 (file)
@@ -4011,6 +4011,17 @@ vsmt_mode being returned when the KVM_CAP_PPC_SMT capability is
 subsequently queried for the VM.  This capability is only supported by
 HV KVM, and can only be set before any VCPUs have been created.
 
+7.12 KVM_CAP_PPC_FWNMI
+
+Architectures: ppc
+Parameters: none
+
+With this capability a machine check exception in the guest address
+space will cause KVM to exit the guest with NMI exit reason. This
+enables QEMU to build error log and branch to guest kernel registered
+machine check handling routine. Without this capability KVM will
+branch to guests' 0x200 interrupt vector.
+
 8. Other capabilities.
 ----------------------
 
index 683c3c82ce9c3d2ab00916515a69ccce8294eaf5..05866391f406d2ac6d5b172aeae3bc40360b9507 100644 (file)
@@ -287,6 +287,7 @@ struct kvm_arch {
        cpumask_t need_tlb_flush;
        cpumask_t cpu_in_guest;
        u8 radix;
+       u8 fwnmi_enabled;
        pgd_t *pgtable;
        u64 process_table;
        struct dentry *debugfs_dir;
index 293fbdf96e7d6084aec772a3383d3d833e700621..ae8e89e0d0836274b07377ed8668332d83f648e1 100644 (file)
@@ -485,6 +485,7 @@ int main(void)
        OFFSET(KVM_ENABLED_HCALLS, kvm, arch.enabled_hcalls);
        OFFSET(KVM_VRMA_SLB_V, kvm, arch.vrma_slb_v);
        OFFSET(KVM_RADIX, kvm, arch.radix);
+       OFFSET(KVM_FWNMI, kvm, arch.fwnmi_enabled);
        OFFSET(VCPU_DSISR, kvm_vcpu, arch.shregs.dsisr);
        OFFSET(VCPU_DAR, kvm_vcpu, arch.shregs.dar);
        OFFSET(VCPU_VPA, kvm_vcpu, arch.vpa.pinned_addr);
index 8208c2b95a93ebcec71e9c1761c6c41fb3ff5460..ccaa7a407c15c42d8dffe7c32ad4603079647062 100644 (file)
@@ -623,6 +623,11 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
                /* Disable this on POWER9 until code handles new HPTE format */
                r = !!hv_enabled && !cpu_has_feature(CPU_FTR_ARCH_300);
                break;
+#endif
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+       case KVM_CAP_PPC_FWNMI:
+               r = hv_enabled;
+               break;
 #endif
        case KVM_CAP_PPC_HTM:
                r = cpu_has_feature(CPU_FTR_TM_COMP) &&
@@ -1543,6 +1548,15 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
                break;
        }
 #endif /* CONFIG_KVM_XICS */
+#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
+       case KVM_CAP_PPC_FWNMI:
+               r = -EINVAL;
+               if (!is_kvmppc_hv_enabled(vcpu->kvm))
+                       break;
+               r = 0;
+               vcpu->kvm->arch.fwnmi_enabled = true;
+               break;
+#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
        default:
                r = -EINVAL;
                break;
index 577429a95ad887ca98dd31d7f54b0a6a6da8b7db..89bc145b40515f5c320c3018183d01faeabc21bc 100644 (file)
@@ -895,6 +895,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_SPAPR_TCE_VFIO 142
 #define KVM_CAP_X86_GUEST_MWAIT 143
 #define KVM_CAP_ARM_USER_IRQ 144
+#define KVM_CAP_PPC_FWNMI 145
 
 #ifdef KVM_CAP_IRQ_ROUTING