Blame SOURCES/kvm-s390x-kvm-Handle-bpb-feature.patch

4a2fec
From 89628ec85c86fee920a518330759891dd0c01921 Mon Sep 17 00:00:00 2001
4a2fec
From: Thomas Huth <thuth@redhat.com>
4a2fec
Date: Tue, 23 Jan 2018 19:12:45 +0100
4a2fec
Subject: [PATCH 3/8] s390x/kvm: Handle bpb feature
4a2fec
4a2fec
RH-Author: Thomas Huth <thuth@redhat.com>
4a2fec
Message-id: <1516734766-12075-3-git-send-email-thuth@redhat.com>
4a2fec
Patchwork-id: 78701
4a2fec
O-Subject: [RHEL-7.5 qemu-kvm-ma PATCH 2/3] s390x/kvm: Handle bpb feature
4a2fec
Bugzilla: 1535606
4a2fec
RH-Acked-by: David Hildenbrand <david@redhat.com>
4a2fec
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
4a2fec
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
4a2fec
4a2fec
From: Christian Borntraeger <borntraeger@de.ibm.com>
4a2fec
4a2fec
We need to handle the bpb control on reset and migration. Normally
4a2fec
stfle.82 is transparent (and the normal guest part works without
4a2fec
hypervisor activity). To prevent any issues we require full
4a2fec
host kernel support for this feature.
4a2fec
4a2fec
Cc: qemu-stable@nongnu.org
4a2fec
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
4a2fec
Message-Id: <20180118085628.40798-3-borntraeger@de.ibm.com>
4a2fec
Reviewed-by: Thomas Huth <thuth@redhat.com>
4a2fec
Reviewed-by: David Hildenbrand <david@redhat.com>
4a2fec
[CH: 'Branch Prediction Blocking' -> 'Branch prediction blocking']
4a2fec
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
4a2fec
(cherry picked from commit b073c87517d4d348c7bac0f0b35e8e83e6354d82)
4a2fec
4a2fec
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
4a2fec
---
4a2fec
 target/s390x/cpu.c              |  1 +
4a2fec
 target/s390x/cpu.h              |  1 +
4a2fec
 target/s390x/cpu_features.c     |  1 +
4a2fec
 target/s390x/cpu_features_def.h |  1 +
4a2fec
 target/s390x/gen-features.c     |  1 +
4a2fec
 target/s390x/kvm.c              | 14 ++++++++++++++
4a2fec
 target/s390x/machine.c          | 17 +++++++++++++++++
4a2fec
 7 files changed, 36 insertions(+)
4a2fec
4a2fec
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
4a2fec
index 489bc25..8bd463c 100644
4a2fec
--- a/target/s390x/cpu.c
4a2fec
+++ b/target/s390x/cpu.c
4a2fec
@@ -78,6 +78,7 @@ static void s390_cpu_reset(CPUState *s)
4a2fec
     CPUS390XState *env = &cpu->env;
4a2fec
 
4a2fec
     env->pfault_token = -1UL;
4a2fec
+    env->bpbc = false;
4a2fec
     scc->parent_reset(s);
4a2fec
     cpu->env.sigp_order = 0;
4a2fec
     s390_cpu_set_state(CPU_STATE_STOPPED, cpu);
4a2fec
diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
4a2fec
index 29fdd5d..ce1f933 100644
4a2fec
--- a/target/s390x/cpu.h
4a2fec
+++ b/target/s390x/cpu.h
4a2fec
@@ -96,6 +96,7 @@ typedef struct CPUS390XState {
4a2fec
 
4a2fec
     uint32_t fpc;          /* floating-point control register */
4a2fec
     uint32_t cc_op;
4a2fec
+    bool bpbc;             /* branch prediction blocking */
4a2fec
 
4a2fec
     float_status fpu_status; /* passed to softfloat lib */
4a2fec
 
4a2fec
diff --git a/target/s390x/cpu_features.c b/target/s390x/cpu_features.c
4a2fec
index 1d3a036..d39efb0 100644
4a2fec
--- a/target/s390x/cpu_features.c
4a2fec
+++ b/target/s390x/cpu_features.c
4a2fec
@@ -89,6 +89,7 @@ static const S390FeatDef s390_features[] = {
4a2fec
     FEAT_INIT("msa4-base", S390_FEAT_TYPE_STFL, 77, "Message-security-assist-extension-4 facility (excluding subfunctions)"),
4a2fec
     FEAT_INIT("edat2", S390_FEAT_TYPE_STFL, 78, "Enhanced-DAT facility 2"),
4a2fec
     FEAT_INIT("dfppc", S390_FEAT_TYPE_STFL, 80, "Decimal-floating-point packed-conversion facility"),
4a2fec
+    FEAT_INIT("bpb", S390_FEAT_TYPE_STFL, 82, "Branch prediction blocking"),
4a2fec
     FEAT_INIT("vx", S390_FEAT_TYPE_STFL, 129, "Vector facility"),
4a2fec
     FEAT_INIT("iep", S390_FEAT_TYPE_STFL, 130, "Instruction-execution-protection facility"),
4a2fec
     FEAT_INIT("sea_esop2", S390_FEAT_TYPE_STFL, 131, "Side-effect-access facility and Enhanced-suppression-on-protection facility 2"),
4a2fec
diff --git a/target/s390x/cpu_features_def.h b/target/s390x/cpu_features_def.h
4a2fec
index 4b6d4e9..4487cfd 100644
4a2fec
--- a/target/s390x/cpu_features_def.h
4a2fec
+++ b/target/s390x/cpu_features_def.h
4a2fec
@@ -80,6 +80,7 @@ typedef enum {
4a2fec
     S390_FEAT_MSA_EXT_4,
4a2fec
     S390_FEAT_EDAT_2,
4a2fec
     S390_FEAT_DFP_PACKED_CONVERSION,
4a2fec
+    S390_FEAT_BPB,
4a2fec
     S390_FEAT_VECTOR,
4a2fec
     S390_FEAT_INSTRUCTION_EXEC_PROT,
4a2fec
     S390_FEAT_SIDE_EFFECT_ACCESS_ESOP2,
4a2fec
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
4a2fec
index 68e6c31..13a6291 100644
4a2fec
--- a/target/s390x/gen-features.c
4a2fec
+++ b/target/s390x/gen-features.c
4a2fec
@@ -352,6 +352,7 @@ static uint16_t base_GEN14_GA1[] = {
4a2fec
  * support these features yet.
4a2fec
  */
4a2fec
 static uint16_t full_GEN7_GA1[] = {
4a2fec
+    S390_FEAT_BPB,
4a2fec
     S390_FEAT_SIE_F2,
4a2fec
     S390_FEAT_SIE_SKEY,
4a2fec
     S390_FEAT_SIE_GPERE,
4a2fec
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
4a2fec
index 3589e6e..871f441 100644
4a2fec
--- a/target/s390x/kvm.c
4a2fec
+++ b/target/s390x/kvm.c
4a2fec
@@ -488,6 +488,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)
4a2fec
         cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_GSCB;
4a2fec
     }
4a2fec
 
4a2fec
+    if (can_sync_regs(cs, KVM_SYNC_BPBC)) {
4a2fec
+        cs->kvm_run->s.regs.bpbc = env->bpbc;
4a2fec
+        cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_BPBC;
4a2fec
+    }
4a2fec
+
4a2fec
     /* Finally the prefix */
4a2fec
     if (can_sync_regs(cs, KVM_SYNC_PREFIX)) {
4a2fec
         cs->kvm_run->s.regs.prefix = env->psa;
4a2fec
@@ -598,6 +603,10 @@ int kvm_arch_get_registers(CPUState *cs)
4a2fec
         memcpy(env->gscb, cs->kvm_run->s.regs.gscb, 32);
4a2fec
     }
4a2fec
 
4a2fec
+    if (can_sync_regs(cs, KVM_SYNC_BPBC)) {
4a2fec
+        env->bpbc = cs->kvm_run->s.regs.bpbc;
4a2fec
+    }
4a2fec
+
4a2fec
     /* pfault parameters */
4a2fec
     if (can_sync_regs(cs, KVM_SYNC_PFAULT)) {
4a2fec
         env->pfault_token = cs->kvm_run->s.regs.pft;
4a2fec
@@ -2666,6 +2675,11 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
4a2fec
         clear_bit(S390_FEAT_CMM_NT, model->features);
4a2fec
     }
4a2fec
 
4a2fec
+    /* bpb needs kernel support for migration, VSIE and reset */
4a2fec
+    if (!kvm_check_extension(kvm_state, KVM_CAP_S390_BPB)) {
4a2fec
+        clear_bit(S390_FEAT_BPB, model->features);
4a2fec
+    }
4a2fec
+
4a2fec
     /* We emulate a zPCI bus and AEN, therefore we don't need HW support */
4a2fec
     set_bit(S390_FEAT_ZPCI, model->features);
4a2fec
     set_bit(S390_FEAT_ADAPTER_EVENT_NOTIFICATION, model->features);
4a2fec
diff --git a/target/s390x/machine.c b/target/s390x/machine.c
4a2fec
index 2dcadfd..f24088b 100644
4a2fec
--- a/target/s390x/machine.c
4a2fec
+++ b/target/s390x/machine.c
4a2fec
@@ -190,6 +190,22 @@ const VMStateDescription vmstate_gscb = {
4a2fec
         }
4a2fec
 };
4a2fec
 
4a2fec
+static bool bpbc_needed(void *opaque)
4a2fec
+{
4a2fec
+    return s390_has_feat(S390_FEAT_BPB);
4a2fec
+}
4a2fec
+
4a2fec
+const VMStateDescription vmstate_bpbc = {
4a2fec
+    .name = "cpu/bpbc",
4a2fec
+    .version_id = 1,
4a2fec
+    .minimum_version_id = 1,
4a2fec
+    .needed = bpbc_needed,
4a2fec
+    .fields = (VMStateField[]) {
4a2fec
+        VMSTATE_BOOL(env.bpbc, S390CPU),
4a2fec
+        VMSTATE_END_OF_LIST()
4a2fec
+    }
4a2fec
+};
4a2fec
+
4a2fec
 const VMStateDescription vmstate_s390_cpu = {
4a2fec
     .name = "cpu",
4a2fec
     .post_load = cpu_post_load,
4a2fec
@@ -224,6 +240,7 @@ const VMStateDescription vmstate_s390_cpu = {
4a2fec
         &vmstate_riccb,
4a2fec
         &vmstate_exval,
4a2fec
         &vmstate_gscb,
4a2fec
+        &vmstate_bpbc,
4a2fec
         NULL
4a2fec
     },
4a2fec
 };
4a2fec
-- 
4a2fec
1.8.3.1
4a2fec