Skip to contentSkip to conversation

ppc/kvm: Always allow transactional memory on POWER8 KVM-HV

PATCH Applied Thomas Huth 2 participants 5 messages Sep 29, 2016

lore
Share & tools
lore
#0 lore raw

cover ppc/kvm: Always allow transactional memory on POWER8 KVM-HV

KVM-HV also supports transactional memory on POWER8 with older kernels that do not support the KVM_CAP_PPC_HTM extension yet. The first patch introduces a proper function for checking whether we're running on KVM-PR or KVM-HV, which is then used in the second patch to check that we're running on POWER8 with KVM-HV, so we can allow TM there, too.

Thomas Huth (2):
target-ppc/kvm: Add a wrapper function to check for KVM-PR target-ppc/kvm: Enable transactional memory on POWER8 with KVM-HV, too

 hw/ppc/spapr.c   |  2 +-
 target-ppc/kvm.c | 32 +++++++++++++++++++++-----------
 2 files changed, 22 insertions(+), 12 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 target-ppc/kvm: Add a wrapper function to check for KVM-PR

It makes more sense if we have a proper function to check for KVM-PR than to check for the GET_PVINFO extension all over the place.

---
 target-ppc/kvm.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
target-ppc/kvm.c +13 -10
index e9a9faf..dca50bc 100644
@@ -102,6 +102,13 @@ static void kvm_kick_cpu(void *opaque)
     qemu_cpu_kick(CPU(cpu));
 }
 
+/* Check whether we are running with KVM-PR (instead of KVM-HV) */
+static bool kvmppc_is_pr(KVMState *ks)
+{
+    /* Assume KVM-PR if the GET_PVINFO capability is available */
+    return kvm_check_extension(ks, KVM_CAP_PPC_GET_PVINFO) != 0;
+}
+
 static int kvm_ppc_register_host_cpu_type(void);
 
 int kvm_arch_init(MachineState *ms, KVMState *s)
@@ -223,10 +230,9 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu,
      *
      * For that to work we make a few assumptions:
      *
-     * - If KVM_CAP_PPC_GET_PVINFO is supported we are running "PR"
-     *   KVM which only supports 4K and 16M pages, but supports them
-     *   regardless of the backing store characteritics. We also don't
-     *   support 1T segments.
+     * - Check whether we are running "PR" KVM which only supports 4K
+     *   and 16M pages, but supports them regardless of the backing
+     *   store characteritics. We also don't support 1T segments.
      *
      *   This is safe as if HV KVM ever supports that capability or PR
      *   KVM grows supports for more page/segment sizes, those versions
@@ -241,7 +247,7 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu,
      *   implements KVM_CAP_PPC_GET_SMMU_INFO and thus doesn't hit
      *   this fallback.
      */
-    if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+    if (kvmppc_is_pr(cs->kvm_state)) {
         /* No flags */
         info->flags = 0;
         info->slb_size = 64;
@@ -2270,11 +2276,8 @@ int kvmppc_reset_htab(int shift_hint)
 
     /* We have a kernel that predates the htab reset calls.  For PR
      * KVM, we need to allocate the htab ourselves, for an HV KVM of
-     * this era, it has allocated a 16MB fixed size hash table
-     * already.  Kernels of this era have the GET_PVINFO capability
-     * only on PR, so we use this hack to determine the right
-     * answer */
-    if (kvm_check_extension(kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+     * this era, it has allocated a 16MB fixed size hash table already. */
+    if (kvmppc_is_pr(kvm_state)) {
         /* PR - tell caller to allocate htab */
         return 0;
     } else {
Signature · 1 line
1.8.3.1
Applied
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] target-ppc/kvm: Add a wrapper function to check for KVM-PR

Quoted 5 lines · Thomas Huth

It makes more sense if we have a proper function to check for KVM-PR than to check for the GET_PVINFO extension all over the place.

Applied to ppc-for-2.8. I expanded your comment to say this should only be used for fallback tests, though.

Quoted 59 lines
---
 target-ppc/kvm.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
target-ppc/kvm.c +13 -10
index e9a9faf..dca50bc 100644
@@ -102,6 +102,13 @@ static void kvm_kick_cpu(void *opaque)
     qemu_cpu_kick(CPU(cpu));
 }
 
+/* Check whether we are running with KVM-PR (instead of KVM-HV) */
+static bool kvmppc_is_pr(KVMState *ks)
+{
+    /* Assume KVM-PR if the GET_PVINFO capability is available */
+    return kvm_check_extension(ks, KVM_CAP_PPC_GET_PVINFO) != 0;
+}
+
 static int kvm_ppc_register_host_cpu_type(void);
 
 int kvm_arch_init(MachineState *ms, KVMState *s)
@@ -223,10 +230,9 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu,
      *
      * For that to work we make a few assumptions:
      *
-     * - If KVM_CAP_PPC_GET_PVINFO is supported we are running "PR"
-     *   KVM which only supports 4K and 16M pages, but supports them
-     *   regardless of the backing store characteritics. We also don't
-     *   support 1T segments.
+     * - Check whether we are running "PR" KVM which only supports 4K
+     *   and 16M pages, but supports them regardless of the backing
+     *   store characteritics. We also don't support 1T segments.
      *
      *   This is safe as if HV KVM ever supports that capability or PR
      *   KVM grows supports for more page/segment sizes, those versions
@@ -241,7 +247,7 @@ static void kvm_get_fallback_smmu_info(PowerPCCPU *cpu,
      *   implements KVM_CAP_PPC_GET_SMMU_INFO and thus doesn't hit
      *   this fallback.
      */
-    if (kvm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+    if (kvmppc_is_pr(cs->kvm_state)) {
         /* No flags */
         info->flags = 0;
         info->slb_size = 64;
@@ -2270,11 +2276,8 @@ int kvmppc_reset_htab(int shift_hint)
 
     /* We have a kernel that predates the htab reset calls.  For PR
      * KVM, we need to allocate the htab ourselves, for an HV KVM of
-     * this era, it has allocated a 16MB fixed size hash table
-     * already.  Kernels of this era have the GET_PVINFO capability
-     * only on PR, so we use this hack to determine the right
-     * answer */
-    if (kvm_check_extension(kvm_state, KVM_CAP_PPC_GET_PVINFO)) {
+     * this era, it has allocated a 16MB fixed size hash table already. */
+    if (kvmppc_is_pr(kvm_state)) {
         /* PR - tell caller to allocate htab */
         return 0;
     } else {
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

PATCH 2/2 target-ppc/kvm: Enable transactional memory on POWER8 with KVM-HV, too

In reply to Thomas Huth

Transactional memory is also supported on POWER8 KVM-HV if the KVM_CAP_PPC_HTM is not available in the kernel yet, so add a hack to allow TM here, too.

---
 hw/ppc/spapr.c   | 2 +-
 target-ppc/kvm.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +1 -1
index fc37145..2f4e818 100644
@@ -584,7 +584,7 @@ static void spapr_populate_pa_features(CPUPPCState *env, void *fdt, int offset)
          */
         pa_features[3] |= 0x20;
     }
-    if (kvmppc_has_cap_htm()) {
+    if (kvmppc_has_cap_htm() && pa_size > 24) {
         pa_features[24] |= 0x80;    /* Transactional memory support */
     }
 
target-ppc/kvm.c +8 -1
index dca50bc..e990cb7 100644
@@ -567,11 +567,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
 
     idle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, kvm_kick_cpu, cpu);
 
-    /* Some targets support access to KVM's guest TLB. */
     switch (cenv->mmu_model) {
     case POWERPC_MMU_BOOKE206:
+        /* This target supports access to KVM's guest TLB */
         ret = kvm_booke206_tlb_init(cpu);
         break;
+    case POWERPC_MMU_2_07:
+        if (!cap_htm && !kvmppc_is_pr(cs->kvm_state)) {
+            /* KVM-HV has transactional memory on POWER8 also without the
+             * KVM_CAP_PPC_HTM extension, so enable it here instead. */
+            cap_htm = true;
+        }
+        break;
     default:
         break;
     }
Signature · 1 line
1.8.3.1
Applied
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-ppc/kvm: Enable transactional memory on POWER8 with KVM-HV, too

Quoted 5 lines · Thomas Huth

Transactional memory is also supported on POWER8 KVM-HV if the KVM_CAP_PPC_HTM is not available in the kernel yet, so add a hack to allow TM here, too.

Applied to ppc-for-2.8.

Quoted 10 lines
---
 hw/ppc/spapr.c   | 2 +-
 target-ppc/kvm.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +0 -0
index fc37145..2f4e818 100644

hw/ppc/spapr.c static void spapr_populate_pa_features(CPUPPCState *env, void *fdt, int offset) · line 587

Quoted 5 lines
hw/ppc/spapr.c +1 -1
@@ -584,7 +584,7 @@ static void spapr_populate_pa_features(CPUPPCState *env, void *fdt, int offset)
          */
         pa_features[3] |= 0x20;
     }
-    if (kvmppc_has_cap_htm()) {
+    if (kvmppc_has_cap_htm() && pa_size > 24) {

It looks like this is an unrelated fix to the original TM test. I'll fold it into the original patch.

Quoted 27 lines
hw/ppc/spapr.c +0 -0
         pa_features[24] |= 0x80;    /* Transactional memory support */
     }
 
target-ppc/kvm.c +8 -1
index dca50bc..e990cb7 100644
@@ -567,11 +567,18 @@ int kvm_arch_init_vcpu(CPUState *cs)
 
     idle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, kvm_kick_cpu, cpu);
 
-    /* Some targets support access to KVM's guest TLB. */
     switch (cenv->mmu_model) {
     case POWERPC_MMU_BOOKE206:
+        /* This target supports access to KVM's guest TLB */
         ret = kvm_booke206_tlb_init(cpu);
         break;
+    case POWERPC_MMU_2_07:
+        if (!cap_htm && !kvmppc_is_pr(cs->kvm_state)) {
+            /* KVM-HV has transactional memory on POWER8 also without the
+             * KVM_CAP_PPC_HTM extension, so enable it here instead. */
+            cap_htm = true;
+        }
+        break;
     default:
         break;
     }
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson