KVM: PPC: Book3S HV: Introduce new capability for 2nd DAWR
authorRavi Bangoria <ravi.bangoria@linux.ibm.com>
Wed, 16 Dec 2020 10:42:19 +0000 (16:12 +0530)
committerPaul Mackerras <paulus@ozlabs.org>
Wed, 10 Feb 2021 03:31:08 +0000 (14:31 +1100)
Introduce KVM_CAP_PPC_DAWR1 which can be used by QEMU to query whether
KVM supports 2nd DAWR or not. The capability is by default disabled
even when the underlying CPU supports 2nd DAWR. QEMU needs to check
and enable it manually to use the feature.

Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Documentation/virt/kvm/api.rst
arch/powerpc/include/asm/kvm_ppc.h
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/powerpc.c
include/uapi/linux/kvm.h
tools/include/uapi/linux/kvm.h

index a783a8da818bd3f3bcbce4b1c12113a765dc6b95..45fd862ac128a2ccfdfc9006c44ec6fb1998dea6 100644 (file)
@@ -6215,6 +6215,16 @@ the bus lock vm exit can be preempted by a higher priority VM exit, the exit
 notifications to userspace can be KVM_EXIT_BUS_LOCK or other reasons.
 KVM_RUN_BUS_LOCK flag is used to distinguish between them.
 
+7.22 KVM_CAP_PPC_DAWR1
+----------------------
+
+:Architectures: ppc
+:Parameters: none
+:Returns: 0 on success, -EINVAL when CPU doesn't support 2nd DAWR
+
+This capability can be used to check / enable 2nd DAWR feature provided
+by POWER10 processor.
+
 8. Other capabilities.
 ======================
 
index 0a056c64c317b7f61edacb313ea025ea1c3addef..13c39d24dda563fa7083c674ccbc8e12f191a21a 100644 (file)
@@ -314,6 +314,7 @@ struct kvmppc_ops {
                              int size);
        int (*enable_svm)(struct kvm *kvm);
        int (*svm_off)(struct kvm *kvm);
+       int (*enable_dawr1)(struct kvm *kvm);
 };
 
 extern struct kvmppc_ops *kvmppc_hv_ops;
index b37bddfead1be59c0e331f8350cf610f707d2dc2..dffbfd1ab47b1dfff3d54ad1a2879893e5ea057b 100644 (file)
@@ -5642,6 +5642,17 @@ out:
        return ret;
 }
 
+static int kvmhv_enable_dawr1(struct kvm *kvm)
+{
+       if (!cpu_has_feature(CPU_FTR_DAWR1))
+               return -ENODEV;
+
+       /* kvm == NULL means the caller is testing if the capability exists */
+       if (kvm)
+               kvm->arch.dawr1_enabled = true;
+       return 0;
+}
+
 static struct kvmppc_ops kvm_ops_hv = {
        .get_sregs = kvm_arch_vcpu_ioctl_get_sregs_hv,
        .set_sregs = kvm_arch_vcpu_ioctl_set_sregs_hv,
@@ -5685,6 +5696,7 @@ static struct kvmppc_ops kvm_ops_hv = {
        .store_to_eaddr = kvmhv_store_to_eaddr,
        .enable_svm = kvmhv_enable_svm,
        .svm_off = kvmhv_svm_off,
+       .enable_dawr1 = kvmhv_enable_dawr1,
 };
 
 static int kvm_init_subcore_bitmap(void)
index cf52d26f49cd7cb628dfe8bc8fd3de6e1b5805bb..5914c32d9ef3d3c6ae49a681921b92290c5222f2 100644 (file)
@@ -678,6 +678,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
                r = hv_enabled && kvmppc_hv_ops->enable_svm &&
                        !kvmppc_hv_ops->enable_svm(NULL);
                break;
+       case KVM_CAP_PPC_DAWR1:
+               r = !!(hv_enabled && kvmppc_hv_ops->enable_dawr1 &&
+                      !kvmppc_hv_ops->enable_dawr1(NULL));
+               break;
 #endif
        default:
                r = 0;
@@ -2187,6 +2191,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
                        break;
                r = kvm->arch.kvm_ops->enable_svm(kvm);
                break;
+       case KVM_CAP_PPC_DAWR1:
+               r = -EINVAL;
+               if (!is_kvmppc_hv_enabled(kvm) || !kvm->arch.kvm_ops->enable_dawr1)
+                       break;
+               r = kvm->arch.kvm_ops->enable_dawr1(kvm);
+               break;
 #endif
        default:
                r = -EINVAL;
index 63f8f6e956487cbd297297eff8b13678e7ed43b5..8b281f722e5bd8f098a384dd9f00c5115ad497d7 100644 (file)
@@ -1077,6 +1077,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_SYS_HYPERV_CPUID 191
 #define KVM_CAP_DIRTY_LOG_RING 192
 #define KVM_CAP_X86_BUS_LOCK_EXIT 193
+#define KVM_CAP_PPC_DAWR1 194
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
index 886802b8ffba3617f64b47f7f6f452335fdfa23e..9c284a9c3ac5d6f0bb2ad89b12df2202c8d76c31 100644 (file)
@@ -1056,6 +1056,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_ENFORCE_PV_FEATURE_CPUID 190
 #define KVM_CAP_SYS_HYPERV_CPUID 191
 #define KVM_CAP_DIRTY_LOG_RING 192
+#define KVM_CAP_PPC_DAWR1 194
 
 #ifdef KVM_CAP_IRQ_ROUTING