All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: peter.maydell@linaro.org
Cc: borntraeger@de.ibm.com, agraf@suse.de, jfrei@linux.vnet.ibm.com,
	qemu-devel@nongnu.org,
	David Hildenbrand <dahi@linux.vnet.ibm.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>
Subject: [Qemu-devel] [PULL 21/38] s390x/cpumodel: check and apply the CPU model
Date: Tue,  6 Sep 2016 09:46:53 +0200	[thread overview]
Message-ID: <20160906074710.13495-22-cornelia.huck@de.ibm.com> (raw)
In-Reply-To: <20160906074710.13495-1-cornelia.huck@de.ibm.com>

From: David Hildenbrand <dahi@linux.vnet.ibm.com>

We have to test if a configured CPU model is runnable in the current
configuration, and if not report why that is the case. This is done by
comparing it to the maximum supported model (host for KVM or z900 for TCG).
Also, we want to do some base sanity checking for a configured CPU model.

We'll cache the maximum model and the applied model (for performance
reasons and because KVM can only be configured before any VCPU is created).

For unavailable "host" model, we have to make sure that we inform KVM,
so it can do some compatibility stuff (enable CMMA later on to be precise).

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Message-Id: <20160905085244.99980-13-dahi@linux.vnet.ibm.com>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 target-s390x/cpu_models.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 153 insertions(+)

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index d44dab2..2401282 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -15,6 +15,7 @@
 #include "gen-features.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
+#include "qemu/error-report.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
@@ -183,14 +184,166 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
 }
 #endif
 
+static void check_consistency(const S390CPUModel *model)
+{
+    static int dep[][2] = {
+        { S390_FEAT_IPTE_RANGE, S390_FEAT_DAT_ENH },
+        { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH },
+        { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH },
+        { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT },
+        { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH},
+        { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT },
+        { S390_FEAT_DFP_FAST, S390_FEAT_DFP },
+        { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_STFLE_49 },
+        { S390_FEAT_EDAT_2, S390_FEAT_EDAT},
+        { S390_FEAT_MSA_EXT_5, S390_FEAT_KIMD_SHA_512 },
+        { S390_FEAT_MSA_EXT_5, S390_FEAT_KLMD_SHA_512 },
+        { S390_FEAT_MSA_EXT_4, S390_FEAT_MSA_EXT_3 },
+        { S390_FEAT_SIE_CMMA, S390_FEAT_CMM },
+        { S390_FEAT_SIE_CMMA, S390_FEAT_SIE_GSLS },
+        { S390_FEAT_SIE_PFMFI, S390_FEAT_EDAT },
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(dep); i++) {
+        if (test_bit(dep[i][0], model->features) &&
+            !test_bit(dep[i][1], model->features)) {
+            error_report("Warning: \'%s\' requires \'%s\'.",
+                         s390_feat_def(dep[i][0])->name,
+                         s390_feat_def(dep[i][1])->name);
+        }
+    }
+}
+
+static void error_prepend_missing_feat(const char *name, void *opaque)
+{
+    error_prepend((Error **) opaque, "%s ", name);
+}
+
+static void check_compatibility(const S390CPUModel *max_model,
+                                const S390CPUModel *model, Error **errp)
+{
+    S390FeatBitmap missing;
+
+    if (model->def->gen > max_model->def->gen) {
+        error_setg(errp, "Selected CPU generation is too new. Maximum "
+                   "supported model in the configuration: \'%s\'",
+                   max_model->def->name);
+        return;
+    } else if (model->def->gen == max_model->def->gen &&
+               model->def->ec_ga > max_model->def->ec_ga) {
+        error_setg(errp, "Selected CPU GA level is too new. Maximum "
+                   "supported model in the configuration: \'%s\'",
+                   max_model->def->name);
+        return;
+    }
+
+    /* detect the missing features to properly report them */
+    bitmap_andnot(missing, model->features, max_model->features, S390_FEAT_MAX);
+    if (bitmap_empty(missing, S390_FEAT_MAX)) {
+        return;
+    }
+
+    error_setg(errp, " ");
+    s390_feat_bitmap_to_ascii(missing, errp, error_prepend_missing_feat);
+    error_prepend(errp, "Some features requested in the CPU model are not "
+                  "available in the configuration: ");
+}
+
+static S390CPUModel *get_max_cpu_model(Error **errp)
+{
+#ifndef CONFIG_USER_ONLY
+    static S390CPUModel max_model;
+    static bool cached;
+
+    if (cached) {
+        return &max_model;
+    }
+
+    if (kvm_enabled()) {
+        error_setg(errp, "KVM does not support CPU models.");
+    } else {
+        /* TCG enulates a z900 */
+        max_model.def = &s390_cpu_defs[0];
+        bitmap_copy(max_model.features, max_model.def->default_feat,
+                    S390_FEAT_MAX);
+    }
+    if (!*errp) {
+        cached = true;
+        return &max_model;
+    }
+#endif
+    return NULL;
+}
+
+static inline void apply_cpu_model(const S390CPUModel *model, Error **errp)
+{
+#ifndef CONFIG_USER_ONLY
+    static S390CPUModel applied_model;
+    static bool applied;
+
+    /*
+     * We have the same model for all VCPUs. KVM can only be configured before
+     * any VCPUs are defined in KVM.
+     */
+    if (applied) {
+        if (model && memcmp(&applied_model, model, sizeof(S390CPUModel))) {
+            error_setg(errp, "Mixed CPU models are not supported on s390x.");
+        }
+        return;
+    }
+
+    if (kvm_enabled()) {
+        /* FIXME KVM */
+        error_setg(errp, "KVM doesn't support CPU models.");
+    } else if (model) {
+        /* FIXME TCG - use data for stdip/stfl */
+    }
+
+    if (!*errp) {
+        applied = true;
+        if (model) {
+            applied_model = *model;
+        }
+    }
+#endif
+}
+
 void s390_realize_cpu_model(CPUState *cs, Error **errp)
 {
     S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
+    S390CPU *cpu = S390_CPU(cs);
+    const S390CPUModel *max_model;
 
     if (xcc->kvm_required && !kvm_enabled()) {
         error_setg(errp, "CPU definition requires KVM");
         return;
     }
+
+    if (!cpu->model) {
+        /* no host model support -> perform compatibility stuff */
+        apply_cpu_model(NULL, errp);
+        return;
+    }
+
+    max_model = get_max_cpu_model(errp);
+    if (*errp) {
+        error_prepend(errp, "CPU models are not available: ");
+        return;
+    }
+
+    /* copy over properties that can vary */
+    cpu->model->lowest_ibc = max_model->lowest_ibc;
+    cpu->model->cpu_id = max_model->cpu_id;
+    cpu->model->cpu_ver = max_model->cpu_ver;
+
+    check_consistency(cpu->model);
+    check_compatibility(max_model, cpu->model, errp);
+    if (*errp) {
+        return;
+    }
+
+    apply_cpu_model(cpu->model, errp);
 }
 
 static void get_feature(Object *obj, Visitor *v, const char *name,
-- 
2.9.3

  parent reply	other threads:[~2016-09-06  7:47 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-06  7:46 [Qemu-devel] [PULL 00/38] First set of s390x patches for 2.8 Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 01/38] s390x: add compat machine " Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 02/38] s390x/pci: return directly if create zpci failed Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 03/38] s390x/pci: assert zpci always existing Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 04/38] s390/sclp: cache the sclp device Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 05/38] s390x: wrap flic savevm calls into vmstate Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 06/38] s390x/ioinst: advertise fcs facility Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 07/38] s390x/css: handle cssid 255 correctly Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 08/38] linux-headers: update Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 09/38] s390x/kvm: 2 byte software breakpoint support Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 10/38] qmp: details about CPU definitions in query-cpu-definitions Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 11/38] s390x/cpumodel: "host" and "qemu" as CPU subclasses Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 12/38] s390x/cpumodel: expose CPU class properties Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 13/38] s390x/cpumodel: introduce CPU features Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 14/38] s390x/cpumodel: generate CPU feature lists for CPU models Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 15/38] s390x/cpumodel: generate CPU feature group lists Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 16/38] s390x/cpumodel: introduce CPU feature group definitions Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 17/38] s390x/cpumodel: register defined CPU models as subclasses Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 18/38] s390x/cpumodel: store the CPU model in the CPU instance Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 19/38] s390x/cpumodel: expose features and feature groups as properties Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 20/38] s390x/cpumodel: let the CPU model handle feature checks Cornelia Huck
2016-09-06  7:46 ` Cornelia Huck [this message]
2016-09-06  7:46 ` [Qemu-devel] [PULL 22/38] s390x/sclp: factor out preparation of cpu entries Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 23/38] s390x/sclp: introduce sclp feature blocks Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 24/38] s390x/sclp: indicate sclp features Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 25/38] s390x/sclp: propagate the ibc val (lowest and unblocked ibc) Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 26/38] s390x/sclp: propagate the mha via sclp Cornelia Huck
2016-09-06  7:46 ` [Qemu-devel] [PULL 27/38] s390x/sclp: propagate hmfai Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 28/38] s390x/kvm: allow runtime-instrumentation for "none" machine Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 29/38] s390x/kvm: implement CPU model support Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 30/38] s390x/kvm: disable host model for problematic compat machines Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 31/38] s390x/kvm: let the CPU model control CMM(A) Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 32/38] s390x/kvm: don't enable key wrapping if msa3 is disabled Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 33/38] qmp: add QMP interface "query-cpu-model-expansion" Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 34/38] qmp: add QMP interface "query-cpu-model-comparison" Cornelia Huck
2016-09-08 14:12   ` Eric Blake
2016-09-09  7:39     ` Christian Borntraeger
2016-09-06  7:47 ` [Qemu-devel] [PULL 35/38] qmp: add QMP interface "query-cpu-model-baseline" Cornelia Huck
2016-09-08 14:15   ` Eric Blake
2016-09-06  7:47 ` [Qemu-devel] [PULL 36/38] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 37/38] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison" Cornelia Huck
2016-09-06  7:47 ` [Qemu-devel] [PULL 38/38] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline" Cornelia Huck
2016-09-06  8:48 ` [Qemu-devel] [PULL 00/38] First set of s390x patches for 2.8 no-reply
2016-09-06 14:32 ` Peter Maydell
2016-09-06 14:49   ` Cornelia Huck
2016-09-06 15:04     ` Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160906074710.13495-22-cornelia.huck@de.ibm.com \
    --to=cornelia.huck@de.ibm.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=dahi@linux.vnet.ibm.com \
    --cc=jfrei@linux.vnet.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.