Blame SOURCES/kvm-target-ppc-kvm-Add-cap_ppc_safe_-cache-bounds_check-.patch

9bac43
From e8388e92e3bb6dbdd69ada6d7939e06e15875eeb Mon Sep 17 00:00:00 2001
9bac43
From: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
Date: Tue, 13 Feb 2018 04:12:23 +0100
9bac43
Subject: [PATCH 06/15] target/ppc/kvm: Add
9bac43
 cap_ppc_safe_[cache/bounds_check/indirect_branch]
9bac43
9bac43
RH-Author: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
Message-id: <1518495150-24134-3-git-send-email-sursingh@redhat.com>
9bac43
Patchwork-id: 78984
9bac43
O-Subject: [RHEL7.5 qemu-kvm-rhev PATCH 2/9] target/ppc/kvm: Add cap_ppc_safe_[cache/bounds_check/indirect_branch]
9bac43
Bugzilla: 1532050
9bac43
RH-Acked-by: David Gibson <dgibson@redhat.com>
9bac43
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9bac43
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9bac43
9bac43
From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
9bac43
9bac43
Add three new kvm capabilities used to represent the level of host support
9bac43
for three corresponding workarounds.
9bac43
9bac43
Host support for each of the capabilities is queried through the
9bac43
new ioctl KVM_PPC_GET_CPU_CHAR which returns four uint64 quantities. The
9bac43
first two, character and behaviour, represent the available
9bac43
characteristics of the cpu and the behaviour of the cpu respectively.
9bac43
The second two, c_mask and b_mask, represent the mask of known bits for
9bac43
the character and beheviour dwords respectively.
9bac43
9bac43
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
9bac43
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
[dwg: Correct some compile errors due to name change in final kernel
9bac43
 patch version]
9bac43
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
9bac43
(cherry picked from commit 8acc2ae5e91681ceda3ff4cf946ebf163f6012e9)
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
9bac43
Conflicts:
9bac43
	target/ppc/kvm.c
9bac43
9bac43
Minor massage required due to lack of commit downstream:
9bac43
2e9c10eb (ppc: spapr: use generic cpu_model parsing)
9bac43
9bac43
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1532050
9bac43
9bac43
Signed-off-by: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
---
9bac43
 include/hw/ppc/spapr.h | 12 +++++++++++
9bac43
 target/ppc/kvm.c       | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
9bac43
 target/ppc/kvm_ppc.h   | 18 ++++++++++++++++
9bac43
 3 files changed, 88 insertions(+)
9bac43
9bac43
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
9bac43
index 7156a70..6090f3d 100644
9bac43
--- a/include/hw/ppc/spapr.h
9bac43
+++ b/include/hw/ppc/spapr.h
9bac43
@@ -297,6 +297,18 @@ struct sPAPRMachineState {
9bac43
 #define H_DABRX_KERNEL     (1ULL<<(63-62))
9bac43
 #define H_DABRX_USER       (1ULL<<(63-63))
9bac43
 
9bac43
+/* Values for KVM_PPC_GET_CPU_CHAR & H_GET_CPU_CHARACTERISTICS */
9bac43
+#define H_CPU_CHAR_SPEC_BAR_ORI31               PPC_BIT(0)
9bac43
+#define H_CPU_CHAR_BCCTRL_SERIALISED            PPC_BIT(1)
9bac43
+#define H_CPU_CHAR_L1D_FLUSH_ORI30              PPC_BIT(2)
9bac43
+#define H_CPU_CHAR_L1D_FLUSH_TRIG2              PPC_BIT(3)
9bac43
+#define H_CPU_CHAR_L1D_THREAD_PRIV              PPC_BIT(4)
9bac43
+#define H_CPU_CHAR_HON_BRANCH_HINTS             PPC_BIT(5)
9bac43
+#define H_CPU_CHAR_THR_RECONF_TRIG              PPC_BIT(6)
9bac43
+#define H_CPU_BEHAV_FAVOUR_SECURITY             PPC_BIT(0)
9bac43
+#define H_CPU_BEHAV_L1D_FLUSH_PR                PPC_BIT(1)
9bac43
+#define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR           PPC_BIT(2)
9bac43
+
9bac43
 /* Each control block has to be on a 4K boundary */
9bac43
 #define H_CB_ALIGNMENT     4096
9bac43
 
9bac43
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
9bac43
index ce7e2ec..7a7bc3b 100644
9bac43
--- a/target/ppc/kvm.c
9bac43
+++ b/target/ppc/kvm.c
9bac43
@@ -92,6 +92,9 @@ static int cap_mmu_radix;
9bac43
 static int cap_mmu_hash_v3;
9bac43
 static int cap_resize_hpt;
9bac43
 static int cap_ppc_pvr_compat;
9bac43
+static int cap_ppc_safe_cache;
9bac43
+static int cap_ppc_safe_bounds_check;
9bac43
+static int cap_ppc_safe_indirect_branch;
9bac43
 
9bac43
 static uint32_t debug_inst_opcode;
9bac43
 
9bac43
@@ -124,6 +127,7 @@ static bool kvmppc_is_pr(KVMState *ks)
9bac43
 }
9bac43
 
9bac43
 static int kvm_ppc_register_host_cpu_type(void);
9bac43
+static void kvmppc_get_cpu_characteristics(KVMState *s);
9bac43
 
9bac43
 int kvm_arch_init(MachineState *ms, KVMState *s)
9bac43
 {
9bac43
@@ -150,6 +154,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
9bac43
     cap_mmu_radix = kvm_vm_check_extension(s, KVM_CAP_PPC_MMU_RADIX);
9bac43
     cap_mmu_hash_v3 = kvm_vm_check_extension(s, KVM_CAP_PPC_MMU_HASH_V3);
9bac43
     cap_resize_hpt = kvm_vm_check_extension(s, KVM_CAP_SPAPR_RESIZE_HPT);
9bac43
+    kvmppc_get_cpu_characteristics(s);
9bac43
     /*
9bac43
      * Note: setting it to false because there is not such capability
9bac43
      * in KVM at this moment.
9bac43
@@ -2473,6 +2478,59 @@ bool kvmppc_has_cap_mmu_hash_v3(void)
9bac43
     return cap_mmu_hash_v3;
9bac43
 }
9bac43
 
9bac43
+static void kvmppc_get_cpu_characteristics(KVMState *s)
9bac43
+{
9bac43
+    struct kvm_ppc_cpu_char c;
9bac43
+    int ret;
9bac43
+
9bac43
+    /* Assume broken */
9bac43
+    cap_ppc_safe_cache = 0;
9bac43
+    cap_ppc_safe_bounds_check = 0;
9bac43
+    cap_ppc_safe_indirect_branch = 0;
9bac43
+
9bac43
+    ret = kvm_vm_check_extension(s, KVM_CAP_PPC_GET_CPU_CHAR);
9bac43
+    if (!ret) {
9bac43
+        return;
9bac43
+    }
9bac43
+    ret = kvm_vm_ioctl(s, KVM_PPC_GET_CPU_CHAR, &c);
9bac43
+    if (ret < 0) {
9bac43
+        return;
9bac43
+    }
9bac43
+    /* Parse and set cap_ppc_safe_cache */
9bac43
+    if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_L1D_FLUSH_PR) {
9bac43
+        cap_ppc_safe_cache = 2;
9bac43
+    } else if ((c.character & c.character_mask & H_CPU_CHAR_L1D_THREAD_PRIV) &&
9bac43
+               (c.character & c.character_mask
9bac43
+                & (H_CPU_CHAR_L1D_FLUSH_ORI30 | H_CPU_CHAR_L1D_FLUSH_TRIG2))) {
9bac43
+        cap_ppc_safe_cache = 1;
9bac43
+    }
9bac43
+    /* Parse and set cap_ppc_safe_bounds_check */
9bac43
+    if (~c.behaviour & c.behaviour_mask & H_CPU_BEHAV_BNDS_CHK_SPEC_BAR) {
9bac43
+        cap_ppc_safe_bounds_check = 2;
9bac43
+    } else if (c.character & c.character_mask & H_CPU_CHAR_SPEC_BAR_ORI31) {
9bac43
+        cap_ppc_safe_bounds_check = 1;
9bac43
+    }
9bac43
+    /* Parse and set cap_ppc_safe_indirect_branch */
9bac43
+    if (c.character & H_CPU_CHAR_BCCTRL_SERIALISED) {
9bac43
+        cap_ppc_safe_indirect_branch = 2;
9bac43
+    }
9bac43
+}
9bac43
+
9bac43
+int kvmppc_get_cap_safe_cache(void)
9bac43
+{
9bac43
+    return cap_ppc_safe_cache;
9bac43
+}
9bac43
+
9bac43
+int kvmppc_get_cap_safe_bounds_check(void)
9bac43
+{
9bac43
+    return cap_ppc_safe_bounds_check;
9bac43
+}
9bac43
+
9bac43
+int kvmppc_get_cap_safe_indirect_branch(void)
9bac43
+{
9bac43
+    return cap_ppc_safe_indirect_branch;
9bac43
+}
9bac43
+
9bac43
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void)
9bac43
 {
9bac43
     uint32_t host_pvr = mfpvr();
9bac43
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
9bac43
index e6711fc..9da92a9 100644
9bac43
--- a/target/ppc/kvm_ppc.h
9bac43
+++ b/target/ppc/kvm_ppc.h
9bac43
@@ -62,6 +62,9 @@ bool kvmppc_has_cap_fixup_hcalls(void);
9bac43
 bool kvmppc_has_cap_htm(void);
9bac43
 bool kvmppc_has_cap_mmu_radix(void);
9bac43
 bool kvmppc_has_cap_mmu_hash_v3(void);
9bac43
+int kvmppc_get_cap_safe_cache(void);
9bac43
+int kvmppc_get_cap_safe_bounds_check(void);
9bac43
+int kvmppc_get_cap_safe_indirect_branch(void);
9bac43
 int kvmppc_enable_hwrng(void);
9bac43
 int kvmppc_put_books_sregs(PowerPCCPU *cpu);
9bac43
 PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void);
9bac43
@@ -299,6 +302,21 @@ static inline bool kvmppc_has_cap_mmu_hash_v3(void)
9bac43
     return false;
9bac43
 }
9bac43
 
9bac43
+static inline int kvmppc_get_cap_safe_cache(void)
9bac43
+{
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
+static inline int kvmppc_get_cap_safe_bounds_check(void)
9bac43
+{
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
+static inline int kvmppc_get_cap_safe_indirect_branch(void)
9bac43
+{
9bac43
+    return 0;
9bac43
+}
9bac43
+
9bac43
 static inline int kvmppc_enable_hwrng(void)
9bac43
 {
9bac43
     return -1;
9bac43
-- 
9bac43
1.8.3.1
9bac43