Blame SOURCES/kvm-target-ppc-spapr-Add-H-Call-H_GET_CPU_CHARACTERISTIC.patch

9bac43
From d47dcee27b473fd94b4afdb21433d735ff9e51cd Mon Sep 17 00:00:00 2001
9bac43
From: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
Date: Tue, 13 Feb 2018 04:12:29 +0100
9bac43
Subject: [PATCH 12/15] target/ppc/spapr: Add H-Call H_GET_CPU_CHARACTERISTICS
9bac43
9bac43
RH-Author: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
Message-id: <1518495150-24134-9-git-send-email-sursingh@redhat.com>
9bac43
Patchwork-id: 78986
9bac43
O-Subject: [RHEL7.5 qemu-kvm-rhev PATCH 8/9] target/ppc/spapr: Add H-Call H_GET_CPU_CHARACTERISTICS
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
The new H-Call H_GET_CPU_CHARACTERISTICS is used by the guest to query
9bac43
behaviours and available characteristics of the cpu.
9bac43
9bac43
Implement the handler for this new H-Call which formulates its response
9bac43
based on the setting of the spapr_caps cap-cfpc, cap-sbbc and cap-ibs.
9bac43
9bac43
Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
9bac43
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
9bac43
(cherry picked from commit c59704b254734182c3202e0c261589ea2ccf485e)
9bac43
9bac43
Conflicts: none
9bac43
9bac43
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1532050
9bac43
9bac43
Signed-off-by: Suraj Jitindar Singh <sursingh@redhat.com>
9bac43
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9bac43
---
9bac43
 hw/ppc/spapr_hcall.c   | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++
9bac43
 include/hw/ppc/spapr.h |  1 +
9bac43
 2 files changed, 59 insertions(+)
9bac43
9bac43
diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
9bac43
index 217358d..21247cd 100644
9bac43
--- a/hw/ppc/spapr_hcall.c
9bac43
+++ b/hw/ppc/spapr_hcall.c
9bac43
@@ -1629,6 +1629,60 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
9bac43
     return H_SUCCESS;
9bac43
 }
9bac43
 
9bac43
+static target_ulong h_get_cpu_characteristics(PowerPCCPU *cpu,
9bac43
+                                              sPAPRMachineState *spapr,
9bac43
+                                              target_ulong opcode,
9bac43
+                                              target_ulong *args)
9bac43
+{
9bac43
+    uint64_t characteristics = H_CPU_CHAR_HON_BRANCH_HINTS &
9bac43
+                               ~H_CPU_CHAR_THR_RECONF_TRIG;
9bac43
+    uint64_t behaviour = H_CPU_BEHAV_FAVOUR_SECURITY;
9bac43
+    uint8_t safe_cache = spapr_get_cap(spapr, SPAPR_CAP_CFPC);
9bac43
+    uint8_t safe_bounds_check = spapr_get_cap(spapr, SPAPR_CAP_SBBC);
9bac43
+    uint8_t safe_indirect_branch = spapr_get_cap(spapr, SPAPR_CAP_IBS);
9bac43
+
9bac43
+    switch (safe_cache) {
9bac43
+    case SPAPR_CAP_WORKAROUND:
9bac43
+        characteristics |= H_CPU_CHAR_L1D_FLUSH_ORI30;
9bac43
+        characteristics |= H_CPU_CHAR_L1D_FLUSH_TRIG2;
9bac43
+        characteristics |= H_CPU_CHAR_L1D_THREAD_PRIV;
9bac43
+        behaviour |= H_CPU_BEHAV_L1D_FLUSH_PR;
9bac43
+        break;
9bac43
+    case SPAPR_CAP_FIXED:
9bac43
+        break;
9bac43
+    default: /* broken */
9bac43
+        assert(safe_cache == SPAPR_CAP_BROKEN);
9bac43
+        behaviour |= H_CPU_BEHAV_L1D_FLUSH_PR;
9bac43
+        break;
9bac43
+    }
9bac43
+
9bac43
+    switch (safe_bounds_check) {
9bac43
+    case SPAPR_CAP_WORKAROUND:
9bac43
+        characteristics |= H_CPU_CHAR_SPEC_BAR_ORI31;
9bac43
+        behaviour |= H_CPU_BEHAV_BNDS_CHK_SPEC_BAR;
9bac43
+        break;
9bac43
+    case SPAPR_CAP_FIXED:
9bac43
+        break;
9bac43
+    default: /* broken */
9bac43
+        assert(safe_bounds_check == SPAPR_CAP_BROKEN);
9bac43
+        behaviour |= H_CPU_BEHAV_BNDS_CHK_SPEC_BAR;
9bac43
+        break;
9bac43
+    }
9bac43
+
9bac43
+    switch (safe_indirect_branch) {
9bac43
+    case SPAPR_CAP_FIXED:
9bac43
+        characteristics |= H_CPU_CHAR_BCCTRL_SERIALISED;
9bac43
+    default: /* broken */
9bac43
+        assert(safe_indirect_branch == SPAPR_CAP_BROKEN);
9bac43
+        break;
9bac43
+    }
9bac43
+
9bac43
+    args[0] = characteristics;
9bac43
+    args[1] = behaviour;
9bac43
+
9bac43
+    return H_SUCCESS;
9bac43
+}
9bac43
+
9bac43
 static spapr_hcall_fn papr_hypercall_table[(MAX_HCALL_OPCODE / 4) + 1];
9bac43
 static spapr_hcall_fn kvmppc_hypercall_table[KVMPPC_HCALL_MAX - KVMPPC_HCALL_BASE + 1];
9bac43
 
9bac43
@@ -1708,6 +1762,10 @@ static void hypercall_register_types(void)
9bac43
     spapr_register_hypercall(H_INVALIDATE_PID, h_invalidate_pid);
9bac43
     spapr_register_hypercall(H_REGISTER_PROC_TBL, h_register_process_table);
9bac43
 
9bac43
+    /* hcall-get-cpu-characteristics */
9bac43
+    spapr_register_hypercall(H_GET_CPU_CHARACTERISTICS,
9bac43
+                             h_get_cpu_characteristics);
9bac43
+
9bac43
     /* "debugger" hcalls (also used by SLOF). Note: We do -not- differenciate
9bac43
      * here between the "CI" and the "CACHE" variants, they will use whatever
9bac43
      * mapping attributes qemu is using. When using KVM, the kernel will
9bac43
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
9bac43
index f7f01f3..375b2ba 100644
9bac43
--- a/include/hw/ppc/spapr.h
9bac43
+++ b/include/hw/ppc/spapr.h
9bac43
@@ -406,6 +406,7 @@ struct sPAPRMachineState {
9bac43
 #define H_GET_HCA_INFO          0x1B8
9bac43
 #define H_GET_PERF_COUNT        0x1BC
9bac43
 #define H_MANAGE_TRACE          0x1C0
9bac43
+#define H_GET_CPU_CHARACTERISTICS 0x1C8
9bac43
 #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
9bac43
 #define H_QUERY_INT_STATE       0x1E4
9bac43
 #define H_POLL_PENDING          0x1D8
9bac43
-- 
9bac43
1.8.3.1
9bac43