qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 6/6] pseries: Allow KVM HV implementation of HPT resiz


From: David Gibson
Subject: [Qemu-devel] [RFC 6/6] pseries: Allow KVM HV implementation of HPT resizing to be used
Date: Mon, 21 Mar 2016 15:42:52 +1100

So far, qemu implements the PAPR Hash Page Table (HPT) resizing extension
with TCG or the KVM PR, since in both cases the guest's HPT is managed by
qemu.  For now we don't allow HPT resizing with KVM HV, since the HPT is
managed by the KVM host kernel in that case.

Instead of using a hack to detect KVM HV versus KVM PR, this patch uses
a special capability in newer kernels to directly see if HPT resizing is
supported by KVM.  The capability can advertise either qemu-managed HPT
resizing (KVM PR) or KVM-managed HPT resizing (KVM HV).

If the kernel doesn't advertise the capability at all, we fall back on the
old PR vs. HV test.

NOTE: This patch updates the linux-headers tree with the define for the
new capability.  Since the corresponding kernel changes aren't yet upstream
this is a temporary hack to be replaced by a proper headers update before
merge.

Signed-off-by: David Gibson <address@hidden>
---
 linux-headers/linux/kvm.h |  1 +
 target-ppc/kvm.c          | 49 +++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 4a56b9e..96c5cfb 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -856,6 +856,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_IOEVENTFD_ANY_LENGTH 122
 #define KVM_CAP_HYPERV_SYNIC 123
 #define KVM_CAP_S390_RI 124
+#define KVM_CAP_SPAPR_RESIZE_HPT 128
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 562e9fa..0e1c487 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -2576,16 +2576,53 @@ int kvmppc_enable_hwrng(void)
 
 void kvmppc_check_papr_resize_hpt(Error **errp)
 {
+    int cap_resize_hpt;
+    int rc;
+
     if (!kvm_enabled()) {
         return;
     }
 
-    /* TODO: Check specific capabilities for HPT resize aware host kernels */
+    cap_resize_hpt = kvm_vm_check_extension(kvm_state,
+                                            KVM_CAP_SPAPR_RESIZE_HPT);
 
-    /* Fall back to checking if we have PR or HV KVM */
-    if (!kvm_vm_check_extension(kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
-        error_setg(errp, "Hash page table resizing not available with HV KVM");
-    }
+    switch (cap_resize_hpt) {
+    case 0:
+        /* Fall back to checking if we have PR or HV KVM */
+        if (!kvm_vm_check_extension(kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+            error_setg(errp,
+                       "Hash page table resizing not available with HV KVM");
+        }
+        /* PR KVM, we should be ok */
+        return;
 
-    /* PR KVM, we should be ok */
+    case 1:
+        /* Resizing only allowed with a qemu managed HPT */
+        if (kvm_vm_check_extension(kvm_state, KVM_CAP_PPC_ALLOC_HTAB)) {
+            error_setg(errp,
+                       "Hash page table resizing not available with kernel 
managed HPT");
+        }
+        /* qemu managed HPT, we should be ok */
+        return;
+
+    case 2:
+        /* HPT resize allowed with kernel managed HPT too */
+        rc = kvmppc_enable_hcall(kvm_state, KVMPPC_H_RESIZE_HPT_PREPARE);
+        if (rc < 0) {
+            error_setg_errno(errp, -rc,
+                             "Unable to enable H_RESIZE_HPT_PREPARE 
hypercall");
+            return;
+        }
+        rc = kvmppc_enable_hcall(kvm_state, KVMPPC_H_RESIZE_HPT_COMMIT);
+        if (rc < 0) {
+            error_setg_errno(errp, -rc,
+                             "Unable to enable H_RESIZE_HPT_COMMIT hypercall");
+        }
+        return;
+
+    default:
+        error_setg(errp, "Unknown KVM_CAP_SPAPR_RESIZE_HPT value %d",
+                   cap_resize_hpt);
+        return;
+    }
 }
-- 
2.5.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]