qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: paulus@samba.org, aik@ozlabs.ru
Cc: agraf@suse.de, David Gibson <david@gibson.dropbear.id.au>,
	qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	bharata@linux.vnet.ibm.com
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	[thread overview]
Message-ID: <1458535372-6757-7-git-send-email-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <1458535372-6757-1-git-send-email-david@gibson.dropbear.id.au>

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 <david@gibson.dropbear.id.au>
---
 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

      parent reply	other threads:[~2016-03-21  4:41 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-21  4:42 [Qemu-devel] [RFC 0/6] PAPR HPT resizing (qemu host side) David Gibson
2016-03-21  4:42 ` [Qemu-devel] [RFC 1/6] pseries: Stubs for HPT resizing David Gibson
2016-03-21  4:42 ` [Qemu-devel] [RFC 2/6] pseries: Implement " David Gibson
2016-03-21  4:42 ` [Qemu-devel] [RFC 3/6] pseries: Enable HPT resizing for 2.6 David Gibson
2016-03-21  4:42 ` [Qemu-devel] [RFC 4/6] pseries: Use smaller default hash page tables when guest can resize David Gibson
2016-03-21  4:42 ` [Qemu-devel] [RFC 5/6] pseries: Allow HPT resizing on PR KVM David Gibson
2016-03-21  4:42 ` David Gibson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458535372-6757-7-git-send-email-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=bharata@linux.vnet.ibm.com \
    --cc=paulus@samba.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).