qemu-ppc
[Top][All Lists]
Advanced

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

[Qemu-ppc] [PATCH 3/4] ppc/spapr-caps: Convert cap-ibs to custom spapr-c


From: Suraj Jitindar Singh
Subject: [Qemu-ppc] [PATCH 3/4] ppc/spapr-caps: Convert cap-ibs to custom spapr-cap
Date: Thu, 1 Mar 2018 15:45:02 +1100

Convert cap-ibs (indirect branch speculation) to a custom spapr-cap
type.

Signed-off-by: Suraj Jitindar Singh <address@hidden>
---
 hw/ppc/spapr_caps.c    | 23 +++++++++++++++--------
 hw/ppc/spapr_hcall.c   |  5 ++++-
 include/hw/ppc/spapr.h |  1 +
 target/ppc/kvm.c       |  6 +++++-
 4 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
index 449e30bae0..3ef8266191 100644
--- a/hw/ppc/spapr_caps.c
+++ b/hw/ppc/spapr_caps.c
@@ -270,16 +270,22 @@ static void cap_safe_bounds_check_apply(sPAPRMachineState 
*spapr, uint8_t val,
     }
 }
 
+sPAPRCapPossible cap_ibs_possible = {
+    .num = 3,
+    .vals = {"broken", "fixed-u2k", "fixed-u2u"},
+    .help = "broken - no protection, fixed-u2k - kernel protection, fixed-u2u 
- kernel and user to user protection",
+};
+
 static void cap_safe_indirect_branch_apply(sPAPRMachineState *spapr,
                                            uint8_t val, Error **errp)
 {
-    if (val == SPAPR_CAP_WORKAROUND) { /* Can only be Broken or Fixed */
-        error_setg(errp, "Requested safe indirect branch capability level 
\"workaround\" not valid, try cap-ibs=fixed");
-    } else if (tcg_enabled() && val) {
+    uint8_t kvm_val = kvmppc_get_cap_safe_indirect_branch();
+
+    if (tcg_enabled() && val) {
         /* TODO - for now only allow broken for TCG */
         error_setg(errp, "Requested safe indirect branch capability level not 
supported by tcg, try a different value for cap-ibs");
-    } else if (kvm_enabled() && (val > kvmppc_get_cap_safe_indirect_branch())) 
{
-        error_setg(errp, "Requested safe indirect branch capability level not 
supported by kvm, try a different value for cap-ibs");
+    } else if (kvm_enabled() && val && (val != kvm_val)) {
+        error_setg(errp, "Requested safe indirect branch capability level not 
supported by kvm, try cap-ibs=%s", cap_ibs_possible.vals[kvm_val]);
     }
 }
 
@@ -333,11 +339,12 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = {
     },
     [SPAPR_CAP_IBS] = {
         .name = "ibs",
-        .description = "Indirect Branch Serialisation (broken, fixed)",
+        .description = "Indirect Branch Speculation (help, broken, fixed-u2k, 
fixed-u2u)",
         .index = SPAPR_CAP_IBS,
-        .get = spapr_cap_get_tristate,
-        .set = spapr_cap_set_tristate,
+        .get = spapr_cap_get_string,
+        .set = spapr_cap_set_string,
         .type = "string",
+        .possible = &cap_ibs_possible,
         .apply = cap_safe_indirect_branch_apply,
     },
 };
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index 1986560480..791a04c79c 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1705,7 +1705,10 @@ static target_ulong h_get_cpu_characteristics(PowerPCCPU 
*cpu,
     }
 
     switch (safe_indirect_branch) {
-    case SPAPR_CAP_FIXED:
+    case 2:
+        characteristics |= H_CPU_CHAR_CACHE_COUNT_DIS;
+        break;
+    case 1:
         characteristics |= H_CPU_CHAR_BCCTRL_SERIALISED;
         break;
     default: /* broken */
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
index 36942b378d..9e60ab42cb 100644
--- a/include/hw/ppc/spapr.h
+++ b/include/hw/ppc/spapr.h
@@ -313,6 +313,7 @@ struct sPAPRMachineState {
 #define H_CPU_CHAR_L1D_THREAD_PRIV              PPC_BIT(4)
 #define H_CPU_CHAR_HON_BRANCH_HINTS             PPC_BIT(5)
 #define H_CPU_CHAR_THR_RECONF_TRIG              PPC_BIT(6)
+#define H_CPU_CHAR_CACHE_COUNT_DIS              PPC_BIT(7)
 #define H_CPU_BEHAV_FAVOUR_SECURITY             PPC_BIT(0)
 #define H_CPU_BEHAV_L1D_FLUSH_PR                PPC_BIT(1)
 #define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR           PPC_BIT(2)
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
index 2c183f61e2..b75cba82f1 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -2494,8 +2494,12 @@ static void kvmppc_get_cpu_characteristics(KVMState *s)
         cap_ppc_safe_bounds_check = 1;
     }
     /* Parse and set cap_ppc_safe_indirect_branch */
-    if (c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED) {
+    if (c.character & c.character_mask & H_CPU_CHAR_CACHE_COUNT_DIS) {
+        /* Kernel and user to user protection */
         cap_ppc_safe_indirect_branch = 2;
+    } else if (c.character & c.character_mask & H_CPU_CHAR_BCCTRL_SERIALISED) {
+        /* Kernel protection */
+        cap_ppc_safe_indirect_branch = 1;
     }
 }
 
-- 
2.13.6




reply via email to

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