All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features
@ 2016-08-02 11:58 David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
                   ` (29 more replies)
  0 siblings, 30 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

After a very helpful discussion with Eduardo, we I did some changes to the
patch series, the most important ones being:
- All models except "host" will be "migration-safe" on s390x
- CPU model expansion now has only two types "full" and "static"
- The parameter "type" from CPU model baseline has been dropped
- "query-cpu-definitions" is extended by "static" and "migration-safe"
- Updated + clarified description of new QMP interfaces
Full list of changes can be found at the end of this length cover letter.

Latest version can be found on branch:
    github.com/cohuck/qemu cpumodel-s390x-v1

--------------------------------Concept------------------------------------

This is our second attempt to implement CPU models for s390x. We realized
that we also want to have features exposed via the CPU model. While doing
that we realized that we want to have a better interface for libvirt.

Unfortunately, CPU models on s390x are special and we have to take care of:
- A CPU like z13 looks differently in various environments (under different
  LPAR versions, under different z/VM versions, under different KVM
  versions, export regulation) - we have _a lot_ of feature variability.
- We still have certain features that are not published but might be
  implemented/introduced in the future. As they are a theoretical part
  of a CPU already, we have to find a way to model these future changes.
- We still have certain features that are already published, but not
  implemented. Implementation might be added in the future in KVM.
- We heavily rely on KVM to tell us which features it can actually
  virtualize - user space queries like "STFL(e)" give no guarantees.
- Certain "subfeatures" were introduced in one run. In practice, they are
  always around, but in theory, subfeatures could be dropped in the future.
- Just because two CPU models have the same features doesn't mean they
  are equal - some internal numbers might be different. E.g. we won't allow
  running a z13 under a zBC12 just by turning off features.
- We cannot blindly enable all possible features for a CPU generation,
  the IBC "Instruction Blocking Control" in KVM will try to block
  instructions introduced with certain features. So a CPU generation always
  has some maximum feature set that is guaranteed to work.

It all boils down to a specific released CPU to have.
a) A minimum feature set that we expect it to be have on every hypervisor.
b) A variable part that depends on the hypervisor and that could be
   extended in the future (adding not yet implemented features) that we
   always want to enable later on.
c) A variable part that we want to enable only if requested - nested
   virtualization ("vsie") and assists are one example.

As we want our users to always make use of most features, e.g. when using
the "z13" CPU model, we will have to update our CPU models between QEMU
releases, to include the latest feature additions we implemented/unlocked.
We're badically trying to be able at one point in the future to really look
like a maximum "z13" CPU in QEMU. However, that means that a "z13" CPU
looks differently on different QEMU versions. We will make sure using
compatibility machines, that migration stays safe.

However, if the feature set of a CPU model is bound to a compatibility
machine, how can it be of any help when used without a compatibility
machine? E.g. when indicating the host CPU model in "virsh capabilities",
simply saying "z13" is not really clear. Also when baselining and
comparing CPU models, we usually have no compatibility machine "context"
at hand. For this reason we introduce "static" CPU models, which will
never change, so everybody knows without a compatibility machine, what we
are talking about.

CPU definitions/models can be categorized:
1. migratable: all features _can_ be identified + properly migrated.
--> With migratable=off on x86, "host" cannot be migrated properly.
2. migration-safe: in combination with a QEMU machine, migration will work.
--> No CPU features are lost/added during migration
3. static: not bound to a QEMU machine - featureset will never* change.
--> Everybody knows which features are part of it, not affected by a compat
    machine. "virsh capabilities" can show this as "host" model.
*except for trivial bugfixes, especially on very old models nobody used in
production. Should be avoided.

We are currently planning to also support a "migratable=off" on s390x
for the "-cpu host" model, in order to enable all features, including not
recognized ones.

So we have on s390x:
a) A static CPU model for each released CPU that will never change and
   maps to the minimum feature set we expect to be around on all
   hypervisors. e.g. "z13-base" or "z10EC.2-base".
b) A "default" CPU model for each released CPU, that can change between
   QEMU versions and that will always include the features we expect to
   be around in our currently supported environments and will contain only
   features we expect to be stable. E.g. nested virtualization will not be
   contained in these models  for now. "z13" or "z10EC.2" are examples.
c) An internal "maximum" CPU model for each generation that tells us which
   features were supported as a maximum back when the hardware was
   released. This will not be exposed but used internally.

To not have to replicate all CPU model changes ("new default fetaures") in
libvirt, to not duplicate the logic about compatibility and the like,
our approach tries to keep all the QEMU logic in libvirt and provide
standardized interfaces for libvirt to e.g. baseline, compare. This
allows libvirt to not have to care about any model names or feature names,
it can just pass the data from interface to interface and report it to
the user.

Also, libvirt might want to know what the "host" model looks like and
convert a CPU model to a migration safe variant. For this reason, a QMP
command is added that can create a migration safe variant of a variable
CPU model, indicating only the delta changes done to a stable model.

So we have:
a) "query-cpu-model-expansion" - tell us what the "host" or another CPU
   model looks like. Either falling back to a static model or
   completely exposing all properties.
b) "query-cpu-model-comparison" - tell us how two CPU models compare,
    indicating which properties were responsible for the decision.
c) "query-cpu-model-baseline" - create a new model out of two models,
    taking a requested level of stability into account.

--------------------------------Libvirt usecase----------------------------

Testing for runability:
- Simply try to start QEMU with KVM, compat machine, CPU model
- Could be done using query-cpu-model-comparison in the future.

Identifying host model, e.g. "virsh capabilities"
- query-cpu-model-expansion on "host" with "-M none --enable-kvm"

<cpu mode='host-model'>:
- simply copy the identified host model

<cpu mode='host-passthrough'>:
- "-cpu host"

"virsh cpu-baseline":
- query-cpu-model-baseline on two models with "-M none"

"virsh cpu-compare":
- query-cpu-model-comparison on two models with "-M none"

There might be some cenarios where libvirt wants to convert another CPU
model to a static variant, this can be done using query-cpu-model-expansion

--------------------------------QMP examples------------------------------

Expanding "host" on z13.2 without nested virtualization support:
    { "execute":"query-cpu-model-expansion",
      "arguments":{
        "type":"static",
        "model":{
          "name":"host"
    }}}
    { "return":{
        "model":{
          "name":"z13.2-base",
          "props":{
            "aefsi":true,
            "msa5":true,
            "msa4":true,
            "msa3":true,
            "msa2":true,
            "msa1":true,
            "ri":true,
            "edat2":true,
            "edat1":true,
            "vx":true,
            "ipter":true,
            "esop":true,
            "ctx":true,
            "cmm":true,
            "tx":true
    }}}}

Expanding "host" on zEC12.2 without nested virtualization support:
    { "execute":"query-cpu-model-expansion",
      "arguments":{
        "type":"static",
        "model":{
          "name":"host"
    }}}
    { "return":{
        "model":{
          "name":"zEC12.2-base",
          "props":{
            "aefsi":true,
            "msa5":true,
            "msa4":true,
            "msa3":true,
            "msa2":true,
            "msa1":true,
            "ri":true,
            "edat2":true,
            "edat1":true,
            "ipter":true,
            "cei":true,
            "gpereh":true,
            "esop":true,
            "ib":true,
            "siif":true,
            "ibs":true,
            "sief2":true,
            "ctx":true,
            "64bscao":true,
            "cmm":true,
            "gsls":true,
            "tx":true
    }}}}

Comparing both models (dropping features for readability)
    { "execute":"query-cpu-model-comparison",
      "arguments":{
        "modela":{
          "name":"z13.2-base",
          "props":{ ... }
        },
        "modelb":{
          "name":"zEC12.2-base",
          "props":{ ... }
          }
    }}}
    {"return":{
        "result":"incompatible",
        "responsible-properties":[
          "cei",
          "ib",
          "siif",
          "gpereh",
          "sief2",
          "ibs",
          "64bscao",
          "gsls",
          "vx",
          "dfppc",
          "gen13e",
          "gen13ptff",
          "type"
        ]
    }}
Indicated are all z13 features + nested virtualization features. "type"
indicates that both models can never be made identical (as different
CPU generations).

Baselining both models (dropping features for readability)
    { "execute":"query-cpu-model-baseline",
      "arguments":{
        "modela":{
          "name":"z13.2-base",
          "props":{ ... }
        },
        "modelb":{
          "name":"zEC12.2-base",
          "props":{ ... }
    }}}}
    {
      "return":{
        "model":{
          "name":"zEC12.2-base",
          "props":{
            "aefsi":true,
            "msa5":true,
            "msa4":true,
            "msa3":true,
            "msa2":true,
            "msa1":true,
            "ri":true,
            "edat2":true,
            "edat1":true,
            "ipter":true,
            "esop":true,
            "ctx":true,
            "cmm":true,
            "tx":true
    }}}}
Which is in fact a zEC12.2 without nested virtualization.

--------------------------------Changes-----------------------------------

RFC -> Patch v1:
- Rebased to master, had to fixup qmp_visitor and CPU ceation stuff
- Changed function calls from (*fn)(...) to fn(...)
- Mark models not only as migration-safe but also as static
- Introduced "qmp: details about CPU definitions in query-cpu-definitions"
- Expose "static" as CPU class property
- All CPU models except "host" are now migration-safe (e.g. qemu and z13)
- Replaced linux-header update by a proper kvm/next update
- Removed baseline type parameter from "query-cpu-model-baseline" to KIS
- Renamed "stable" expansion to "static" (as stable sounds misleading)
- Removed "migratable" expansion type, can be done via "migratable=off"
- Heavily improved description of the new QMP interfaces
- Actually tested all QMP interfaces. Various bugfixes.

David Hildenbrand (27):
  qmp: details about CPU definitions in query-cpu-definitions
  s390x/cpumodel: "host" and "qemu" as CPU subclasses
  s390x/cpumodel: expose CPU class properties
  s390x/cpumodel: generate CPU feature group lists
  s390x/cpumodel: introduce CPU feature group definitions
  s390x/cpumodel: register defined CPU models as subclasses
  s390x/cpumodel: store the CPU model in the CPU instance
  s390x/cpumodel: expose features and feature groups as properties
  s390x/cpumodel: let the CPU model handle feature checks
  s390x/cpumodel: check and apply the CPU model
  s390x/sclp: factor out preparation of cpu entries
  s390x/sclp: introduce sclp feature blocks
  s390x/sclp: indicate sclp features
  s390x/sclp: propagate the ibc val(lowest and unblocked ibc)
  s390x/sclp: propagate the mha via sclp
  s390x/sclp: propagate hmfai
  linux-headers: update against kvm/next
  s390x/kvm: allow runtime-instrumentation for "none" machine
  s390x/kvm: implement CPU model support
  s390x/kvm: disable host model for existing compat machines
  s390x/kvm: let the CPU model control CMM(A)
  qmp: add QMP interface "query-cpu-model-expansion"
  qmp: add QMP interface "query-cpu-model-comparison"
  qmp: add QMP interface "query-cpu-model-baseline"
  s390x/cpumodel: implement QMP interface "query-cpu-model-expansion"
  s390x/cpumodel: implement QMP interface "query-cpu-model-comparison"
  s390x/cpumodel: implement QMP interface "query-cpu-model-baseline"

Michael Mueller (2):
  s390x/cpumodel: introduce CPU features
  s390x/cpumodel: generate CPU feature lists for CPU models

 Makefile.target                         |    2 +-
 hw/s390x/s390-virtio-ccw.c              |    5 +
 hw/s390x/s390-virtio.c                  |    6 +-
 hw/s390x/sclp.c                         |   35 +-
 include/hw/s390x/sclp.h                 |   17 +-
 include/sysemu/arch_init.h              |    9 +
 linux-headers/asm-arm64/kvm.h           |    2 +
 linux-headers/asm-s390/kvm.h            |   41 ++
 linux-headers/linux/kvm.h               |   12 +-
 qapi-schema.json                        |  200 +++++-
 qmp-commands.hx                         |   18 +
 qmp.c                                   |   21 +
 rules.mak                               |    1 +
 stubs/Makefile.objs                     |    3 +
 stubs/arch-query-cpu-model-baseline.c   |   12 +
 stubs/arch-query-cpu-model-comparison.c |   12 +
 stubs/arch-query-cpu-model-expansion.c  |   12 +
 target-s390x/Makefile.objs              |   22 +-
 target-s390x/cpu-qom.h                  |    6 +
 target-s390x/cpu.c                      |   35 +-
 target-s390x/cpu.h                      |    5 +
 target-s390x/cpu_features.c             |  376 +++++++++++
 target-s390x/cpu_features.h             |  302 +++++++++
 target-s390x/cpu_models.c               | 1083 +++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h               |  113 ++++
 target-s390x/gen-features.c             |  587 +++++++++++++++++
 target-s390x/helper.c                   |   33 +-
 target-s390x/kvm.c                      |  346 +++++++++-
 target-s390x/machine.c                  |   14 +-
 29 files changed, 3262 insertions(+), 68 deletions(-)
 create mode 100644 stubs/arch-query-cpu-model-baseline.c
 create mode 100644 stubs/arch-query-cpu-model-comparison.c
 create mode 100644 stubs/arch-query-cpu-model-expansion.c
 create mode 100644 target-s390x/cpu_features.c
 create mode 100644 target-s390x/cpu_features.h
 create mode 100644 target-s390x/cpu_models.c
 create mode 100644 target-s390x/cpu_models.h
 create mode 100644 target-s390x/gen-features.c

-- 
2.6.6

^ permalink raw reply	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 13:04   ` Eduardo Habkost
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 02/29] s390x/cpumodel: "host" and "qemu" as CPU subclasses David Hildenbrand
                   ` (28 subsequent siblings)
  29 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

It might be of interest for tooling whether a CPU definition can be safely
used when migrating, or if e.g. CPU features might get lost during
migration when migrationg from/to a different QEMU version or host, even if
the same compatibility machine is used.

Also, we want to know if a CPU definition is static and will never change.
Beause these definitions can then be used independantly of a compatibility
machine and will always have the same feature set, they can e.g. be used
to indicate the "host" model in libvirt later on.

Let's add optional return values to query-cpu-definitions, stating for
each returned CPU definition, if it is migration-safe and if it is static.

Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 qapi-schema.json | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 5658723..3f50c1d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3038,10 +3038,19 @@
 #
 # @name: the name of the CPU definition
 #
+# @migration-safe: #optional whether a CPU definition can be safely used for
+#                  migration in combination with a QEMU compatibility machine
+#                  when migrating between different QMU versions and hosts.
+#                  If not provided, information is not available.
+#
+# @static: #optional whether a CPU definition is static and will not change
+#          between QEMU versions / QEMU machines. A static model is always
+#          migration-safe. If not provided, information is not available.
+#
 # Since: 1.2.0
 ##
 { 'struct': 'CpuDefinitionInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*migration-safe' : 'bool', '*static' : 'bool' } }
 
 ##
 # @query-cpu-definitions:
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 02/29] s390x/cpumodel: "host" and "qemu" as CPU subclasses
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 03/29] s390x/cpumodel: expose CPU class properties David Hildenbrand
                   ` (27 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

This patch introduces two CPU models, "host" and "qemu".
"qemu" is used as default when running under TCG. "host" is used
as default when running under KVM. "host" cannot be used without KVM.
"host" is not migration-safe. They both inherit from the base s390x CPU,
which is turned into an abstract class.

This patch also changes CPU creation to take care of the passed CPU string
and reuses common code parse_features() function for that purpose. Unknown
CPU definitions are now reported. The "-cpu ?" and "query-cpu-definition"
commands are changed to list all CPU subclasses automatically, including
migration-safety and whether static.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio.c     |   6 +-
 target-s390x/Makefile.objs |   2 +-
 target-s390x/cpu-qom.h     |   4 +
 target-s390x/cpu.c         |  33 ++-------
 target-s390x/cpu.h         |   2 +
 target-s390x/cpu_models.c  | 178 +++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/helper.c      |  33 ++++++++-
 7 files changed, 230 insertions(+), 28 deletions(-)
 create mode 100644 target-s390x/cpu_models.c

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index 544c616..0a96347 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -101,7 +101,11 @@ void s390_init_cpus(MachineState *machine)
     gchar *name;
 
     if (machine->cpu_model == NULL) {
-        machine->cpu_model = "host";
+        if (kvm_enabled()) {
+            machine->cpu_model = "host";
+        } else {
+            machine->cpu_model = "qemu";
+        }
     }
 
     cpu_states = g_new0(S390CPU *, max_cpus);
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index dd62cbd..34bd693 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,5 +1,5 @@
 obj-y += translate.o helper.o cpu.o interrupt.o
 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
-obj-y += gdbstub.o
+obj-y += gdbstub.o cpu_models.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/target-s390x/cpu-qom.h b/target-s390x/cpu-qom.h
index 66b5d18..bb993d4 100644
--- a/target-s390x/cpu-qom.h
+++ b/target-s390x/cpu-qom.h
@@ -45,6 +45,10 @@ typedef struct S390CPUClass {
     /*< private >*/
     CPUClass parent_class;
     /*< public >*/
+    bool kvm_required;
+    bool is_static;
+    bool is_migration_safe;
+    const char *desc;
 
     int64_t next_cpu_id;
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index e43e2d6..44e53ec 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -44,30 +44,6 @@
 #define CR0_RESET       0xE0UL
 #define CR14_RESET      0xC2000000UL;
 
-/* generate CPU information for cpu -? */
-void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
-{
-#ifdef CONFIG_KVM
-    (*cpu_fprintf)(f, "s390 %16s\n", "host");
-#endif
-}
-
-#ifndef CONFIG_USER_ONLY
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
-{
-    CpuDefinitionInfoList *entry;
-    CpuDefinitionInfo *info;
-
-    info = g_malloc0(sizeof(*info));
-    info->name = g_strdup("host");
-
-    entry = g_malloc0(sizeof(*entry));
-    entry->value = info;
-
-    return entry;
-}
-#endif
-
 static void s390_cpu_set_pc(CPUState *cs, vaddr value)
 {
     S390CPU *cpu = S390_CPU(cs);
@@ -206,6 +182,12 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
     CPUS390XState *env = &cpu->env;
     Error *err = NULL;
 
+    /* the model has to be realized before qemu_init_vcpu() due to kvm */
+    s390_realize_cpu_model(cs, &err);
+    if (err) {
+        goto out;
+    }
+
 #if !defined(CONFIG_USER_ONLY)
     if (cpu->id >= max_cpus) {
         error_setg(&err, "Unable to add CPU: %" PRIi64
@@ -435,6 +417,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
     scc->cpu_reset = s390_cpu_reset;
     scc->initial_cpu_reset = s390_cpu_initial_reset;
     cc->reset = s390_cpu_full_reset;
+    cc->class_by_name = s390_cpu_class_by_name,
     cc->has_work = s390_cpu_has_work;
     cc->do_interrupt = s390_cpu_do_interrupt;
     cc->dump_state = s390_cpu_dump_state;
@@ -470,7 +453,7 @@ static const TypeInfo s390_cpu_type_info = {
     .instance_size = sizeof(S390CPU),
     .instance_init = s390_cpu_initfn,
     .instance_finalize = s390_cpu_finalize,
-    .abstract = false,
+    .abstract = true,
     .class_size = sizeof(S390CPUClass),
     .class_init = s390_cpu_class_init,
 };
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index c216bda..e34742e 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -631,6 +631,8 @@ extern void subsystem_reset(void);
 
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 #define cpu_list s390_cpu_list
+void s390_realize_cpu_model(CPUState *cs, Error **errp);
+ObjectClass *s390_cpu_class_by_name(const char *name);
 
 #define EXCP_EXT 1 /* external interrupt */
 #define EXCP_SVC 2 /* supervisor call (syscall) */
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
new file mode 100644
index 0000000..cff02b2
--- /dev/null
+++ b/target-s390x/cpu_models.c
@@ -0,0 +1,178 @@
+/*
+ * CPU models for s390x
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+#include "qapi/error.h"
+#ifndef CONFIG_USER_ONLY
+#include "sysemu/arch_init.h"
+#endif
+
+struct S390PrintCpuListInfo {
+    FILE *f;
+    fprintf_function print;
+};
+
+static void print_cpu_model_list(ObjectClass *klass, void *opaque)
+{
+    struct S390PrintCpuListInfo *info = opaque;
+    S390CPUClass *scc = S390_CPU_CLASS(klass);
+    char *name = g_strdup(object_class_get_name(klass));
+    const char *details = "";
+
+    if (scc->is_static) {
+        details = "(static, migration-safe)";
+    } else if (scc->is_migration_safe) {
+        details = "(migration-safe)";
+    }
+
+    /* strip off the -s390-cpu */
+    g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
+    (*info->print)(info->f, "s390 %-15s %-35s %s\n", name, scc->desc,
+                   details);
+    g_free(name);
+}
+
+void s390_cpu_list(FILE *f, fprintf_function print)
+{
+    struct S390PrintCpuListInfo info = {
+        f = f,
+        print = print,
+    };
+
+    object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);
+}
+
+#ifndef CONFIG_USER_ONLY
+static void create_cpu_model_list(ObjectClass *klass, void *opaque)
+{
+    CpuDefinitionInfoList **cpu_list = opaque;
+    CpuDefinitionInfoList *entry;
+    CpuDefinitionInfo *info;
+    char *name = g_strdup(object_class_get_name(klass));
+    S390CPUClass *scc = S390_CPU_CLASS(klass);
+
+    /* strip off the -s390-cpu */
+    g_strrstr(name, "-" TYPE_S390_CPU)[0] = 0;
+    info = g_malloc0(sizeof(*info));
+    info->name = name;
+    info->has_migration_safe = true;
+    info->migration_safe = scc->is_migration_safe;
+    info->has_q_static = true;
+    info->q_static = scc->is_static;
+
+
+    entry = g_malloc0(sizeof(*entry));
+    entry->value = info;
+    entry->next = *cpu_list;
+    *cpu_list = entry;
+}
+
+CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+{
+    CpuDefinitionInfoList *list = NULL;
+
+    object_class_foreach(create_cpu_model_list, TYPE_S390_CPU, false, &list);
+
+    return list;
+}
+#endif
+
+void s390_realize_cpu_model(CPUState *cs, Error **errp)
+{
+    S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
+
+    if (xcc->kvm_required && !kvm_enabled()) {
+        error_setg(errp, "CPU definition requires KVM");
+        return;
+    }
+}
+
+#ifdef CONFIG_KVM
+static void s390_host_cpu_model_initfn(Object *obj)
+{
+}
+#endif
+
+static void s390_qemu_cpu_model_initfn(Object *obj)
+{
+}
+
+static void s390_cpu_model_finalize(Object *obj)
+{
+}
+
+#ifdef CONFIG_KVM
+static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
+{
+    S390CPUClass *xcc = S390_CPU_CLASS(oc);
+
+    xcc->kvm_required = true;
+    xcc->desc = "KVM only: All recognized features";
+}
+#endif
+
+static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
+{
+    S390CPUClass *xcc = S390_CPU_CLASS(oc);
+
+    xcc->is_migration_safe = true;
+    xcc->desc = g_strdup_printf("QEMU Virtual CPU version %s",
+                                qemu_hw_version());
+}
+
+#define S390_CPU_TYPE_SUFFIX "-" TYPE_S390_CPU
+#define S390_CPU_TYPE_NAME(name) (name S390_CPU_TYPE_SUFFIX)
+
+/* Generate type name for a cpu model. Caller has to free the string. */
+static char *s390_cpu_type_name(const char *model_name)
+{
+    return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
+}
+
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+    char *typename = s390_cpu_type_name(name);
+    ObjectClass *oc;
+
+    oc = object_class_by_name(typename);
+    g_free(typename);
+    return oc;
+}
+
+static const TypeInfo qemu_s390_cpu_type_info = {
+    .name = S390_CPU_TYPE_NAME("qemu"),
+    .parent = TYPE_S390_CPU,
+    .instance_init = s390_qemu_cpu_model_initfn,
+    .instance_finalize = s390_cpu_model_finalize,
+    .class_init = s390_qemu_cpu_model_class_init,
+};
+
+#ifdef CONFIG_KVM
+static const TypeInfo host_s390_cpu_type_info = {
+    .name = S390_CPU_TYPE_NAME("host"),
+    .parent = TYPE_S390_CPU,
+    .instance_init = s390_host_cpu_model_initfn,
+    .instance_finalize = s390_cpu_model_finalize,
+    .class_init = s390_host_cpu_model_class_init,
+};
+#endif
+
+static void register_types(void)
+{
+    type_register_static(&qemu_s390_cpu_type_info);
+#ifdef CONFIG_KVM
+    type_register_static(&host_s390_cpu_type_info);
+#endif
+}
+
+type_init(register_types)
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index 54a5177..68bd2f9 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -70,7 +70,38 @@ void s390x_cpu_timer(void *opaque)
 
 S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp)
 {
-    return S390_CPU(object_new(TYPE_S390_CPU));
+    static bool features_parsed;
+    char *name, *features;
+    const char *typename;
+    ObjectClass *oc;
+    CPUClass *cc;
+
+    name = g_strdup(cpu_model);
+    features = strchr(name, ',');
+    if (features) {
+        features[0] = 0;
+        features++;
+    }
+
+    oc = cpu_class_by_name(TYPE_S390_CPU, name);
+    if (!oc) {
+        error_setg(errp, "Unknown CPU definition \'%s\'", name);
+        g_free(name);
+        return NULL;
+    }
+    typename = object_class_get_name(oc);
+
+    if (!features_parsed) {
+        features_parsed = true;
+        cc = CPU_CLASS(oc);
+        cc->parse_features(typename, features, errp);
+    }
+    g_free(name);
+
+    if (*errp) {
+        return NULL;
+    }
+    return S390_CPU(CPU(object_new(typename)));
 }
 
 S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp)
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 03/29] s390x/cpumodel: expose CPU class properties
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 02/29] s390x/cpumodel: "host" and "qemu" as CPU subclasses David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 04/29] s390x/cpumodel: introduce CPU features David Hildenbrand
                   ` (26 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's expose the description and migration safety and whether a definition
is static, as class properties, this can be helpful in the future.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu.c        |  1 +
 target-s390x/cpu.h        |  1 +
 target-s390x/cpu_models.c | 25 +++++++++++++++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 44e53ec..d7d0b62 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -445,6 +445,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
      * object_unref().
      */
     dc->cannot_destroy_with_object_finalize_yet = true;
+    s390_cpu_model_class_register_props(oc);
 }
 
 static const TypeInfo s390_cpu_type_info = {
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index e34742e..075bb37 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -631,6 +631,7 @@ extern void subsystem_reset(void);
 
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 #define cpu_list s390_cpu_list
+void s390_cpu_model_class_register_props(ObjectClass *oc);
 void s390_realize_cpu_model(CPUState *cs, Error **errp);
 ObjectClass *s390_cpu_class_by_name(const char *name);
 
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index cff02b2..c875719 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -111,6 +111,31 @@ static void s390_cpu_model_finalize(Object *obj)
 {
 }
 
+static bool get_is_migration_safe(Object *obj, Error **errp)
+{
+    return S390_CPU_GET_CLASS(obj)->is_migration_safe;
+}
+
+static bool get_is_static(Object *obj, Error **errp)
+{
+    return S390_CPU_GET_CLASS(obj)->is_static;
+}
+
+static char *get_description(Object *obj, Error **errp)
+{
+    return g_strdup(S390_CPU_GET_CLASS(obj)->desc);
+}
+
+void s390_cpu_model_class_register_props(ObjectClass *oc)
+{
+    object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe,
+                                   NULL, NULL);
+    object_class_property_add_bool(oc, "static", get_is_static,
+                                   NULL, NULL);
+    object_class_property_add_str(oc, "description", get_description, NULL,
+                                  NULL);
+}
+
 #ifdef CONFIG_KVM
 static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
 {
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 04/29] s390x/cpumodel: introduce CPU features
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (2 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 03/29] s390x/cpumodel: expose CPU class properties David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 05/29] s390x/cpumodel: generate CPU feature lists for CPU models David Hildenbrand
                   ` (25 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

From: Michael Mueller <mimu@linux.vnet.ibm.com>

The patch introduces s390x CPU features (most of them refered to as
facilities) along with their discription and some functions that will be
helpful when working with the features later on.

Please note that we don't introduce all known CPU features, only the
ones currently supported by KVM + QEMU. We don't want to enable later
on blindly any facilities, for which we don't know yet if we need QEMU
support to properly support them (e.g. migrate additional state when
active). We can update QEMU later on.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
[reworked to include non-stfle features, added definitions]
---
 target-s390x/Makefile.objs  |   2 +-
 target-s390x/cpu_features.c | 334 ++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/cpu_features.h | 279 ++++++++++++++++++++++++++++++++++++
 3 files changed, 614 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/cpu_features.c
 create mode 100644 target-s390x/cpu_features.h

diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 34bd693..4266c87 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,5 +1,5 @@
 obj-y += translate.o helper.o cpu.o interrupt.o
 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
-obj-y += gdbstub.o cpu_models.o
+obj-y += gdbstub.o cpu_models.o cpu_features.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
diff --git a/target-s390x/cpu_features.c b/target-s390x/cpu_features.c
new file mode 100644
index 0000000..5aa5981
--- /dev/null
+++ b/target-s390x/cpu_features.c
@@ -0,0 +1,334 @@
+/*
+ * CPU features/facilities for s390x
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu/osdep.h"
+#include "cpu_features.h"
+
+#define FEAT_INIT(_name, _type, _bit, _desc) \
+    {                                                \
+        .name = _name,                               \
+        .type = _type,                               \
+        .bit = _bit,                                 \
+        .desc = _desc,                               \
+    }
+
+/* indexed by feature number for easy lookup */
+static const S390FeatDef s390_features[] = {
+    FEAT_INIT("n3", S390_FEAT_TYPE_STFL, 0, "Instructions marked as n3"),
+    FEAT_INIT("z", S390_FEAT_TYPE_STFL, 1, "z/Architecture architectural mode"),
+    FEAT_INIT("dateh1", S390_FEAT_TYPE_STFL, 3, "DAT-enhancement facility 1"),
+    FEAT_INIT("idtes", S390_FEAT_TYPE_STFL, 4, "IDTE selective TLB segment-table clearing"),
+    FEAT_INIT("idter", S390_FEAT_TYPE_STFL, 5, "IDTE selective TLB region-table clearing"),
+    FEAT_INIT("asnlxr", S390_FEAT_TYPE_STFL, 6, "ASN-and-LX reuse facility"),
+    FEAT_INIT("stfle", S390_FEAT_TYPE_STFL, 7, "Store-facility-list-extended facility"),
+    FEAT_INIT("edat1", S390_FEAT_TYPE_STFL, 8, "Enhanced-DAT facility 1"),
+    FEAT_INIT("srs", S390_FEAT_TYPE_STFL, 9, "Sense-running-status facility"),
+    FEAT_INIT("csske", S390_FEAT_TYPE_STFL, 10, "Conditional-SSKE facility"),
+    FEAT_INIT("ctop", S390_FEAT_TYPE_STFL, 11, "Configuration-topology facility"),
+    FEAT_INIT("ipter", S390_FEAT_TYPE_STFL, 13, "IPTE-range facility"),
+    FEAT_INIT("nonqks", S390_FEAT_TYPE_STFL, 14, "Nonquiescing key-setting facility"),
+    FEAT_INIT("etf2", S390_FEAT_TYPE_STFL, 16, "Extended-translation facility 2"),
+    FEAT_INIT("msa-base", S390_FEAT_TYPE_STFL, 17, "Message-security-assist facility (excluding subfunctions)"),
+    FEAT_INIT("ldisp", S390_FEAT_TYPE_STFL, 18, "Long-displacement facility"),
+    FEAT_INIT("ldisphp", S390_FEAT_TYPE_STFL, 19, "Long-displacement facility has high performance"),
+    FEAT_INIT("hfpm", S390_FEAT_TYPE_STFL, 20, "HFP-multiply-add/subtract facility"),
+    FEAT_INIT("eimm", S390_FEAT_TYPE_STFL, 21, "Extended-immediate facility"),
+    FEAT_INIT("etf3", S390_FEAT_TYPE_STFL, 22, "Extended-translation facility 3"),
+    FEAT_INIT("hfpue", S390_FEAT_TYPE_STFL, 23, "HFP-unnormalized-extension facility"),
+    FEAT_INIT("etf2eh", S390_FEAT_TYPE_STFL, 24, "ETF2-enhancement facility"),
+    FEAT_INIT("stckf", S390_FEAT_TYPE_STFL, 25, "Store-clock-fast facility"),
+    FEAT_INIT("parseh", S390_FEAT_TYPE_STFL, 26, "Parsing-enhancement facility"),
+    FEAT_INIT("mvcos", S390_FEAT_TYPE_STFL, 27, "Move-with-optional-specification facility"),
+    FEAT_INIT("tods-base", S390_FEAT_TYPE_STFL, 28, "TOD-clock-steering facility (excluding subfunctions)"),
+    FEAT_INIT("etf3eh", S390_FEAT_TYPE_STFL, 30, "ETF3-enhancement facility"),
+    FEAT_INIT("ecput", S390_FEAT_TYPE_STFL, 31, "Extract-CPU-time facility"),
+    FEAT_INIT("csst", S390_FEAT_TYPE_STFL, 32, "Compare-and-swap-and-store facility"),
+    FEAT_INIT("csst2", S390_FEAT_TYPE_STFL, 33, "Compare-and-swap-and-store facility 2"),
+    FEAT_INIT("ginste", S390_FEAT_TYPE_STFL, 34, "General-instructions-extension facility"),
+    FEAT_INIT("exece", S390_FEAT_TYPE_STFL, 35, "Execute-extensions facility"),
+    FEAT_INIT("emon", S390_FEAT_TYPE_STFL, 36, "Enhanced-monitor facility"),
+    FEAT_INIT("fpe", S390_FEAT_TYPE_STFL, 37, "Floating-point extension facility"),
+    FEAT_INIT("spropg", S390_FEAT_TYPE_STFL, 40, "Set-program-parameters facility"),
+    FEAT_INIT("fpseh", S390_FEAT_TYPE_STFL, 41, "Floating-point-support-enhancement facilities"),
+    FEAT_INIT("dfp", S390_FEAT_TYPE_STFL, 42, "DFP (decimal-floating-point) facility"),
+    FEAT_INIT("dfphp", S390_FEAT_TYPE_STFL, 43, "DFP (decimal-floating-point) facility has high performance"),
+    FEAT_INIT("pfpo", S390_FEAT_TYPE_STFL, 44, "PFPO instruction"),
+    FEAT_INIT("gen11e", S390_FEAT_TYPE_STFL, 45, "Various facilities introduced with z196"),
+    FEAT_INIT("cmpsceh", S390_FEAT_TYPE_STFL, 47, "CMPSC-enhancement facility"),
+    FEAT_INIT("dfpzc", S390_FEAT_TYPE_STFL, 48, "Decimal-floating-point zoned-conversion facility"),
+    FEAT_INIT("gen12e", S390_FEAT_TYPE_STFL, 49, "Various facilites introduced with zEC12"),
+    FEAT_INIT("ctx", S390_FEAT_TYPE_STFL, 50, "Constrained transactional-execution facility"),
+    FEAT_INIT("ltlbc", S390_FEAT_TYPE_STFL, 51, "Local-TLB-clearing facility"),
+    FEAT_INIT("iacc2", S390_FEAT_TYPE_STFL, 52, "Interlocked-access facility 2"),
+    FEAT_INIT("gen13e", S390_FEAT_TYPE_STFL, 53, "Various facilities introduced with z13"),
+    FEAT_INIT("msa5-base", S390_FEAT_TYPE_STFL, 57, "Message-security-assist-extension-5 facility (excluding subfunctions)"),
+    FEAT_INIT("ri", S390_FEAT_TYPE_STFL, 64, "CPU runtime-instrumentation facility"),
+    FEAT_INIT("tx", S390_FEAT_TYPE_STFL, 73, "Transactional-execution facility"),
+    FEAT_INIT("sthyi", S390_FEAT_TYPE_STFL, 74, "Store-hypervisor-information facility"),
+    FEAT_INIT("aefsi", S390_FEAT_TYPE_STFL, 75, "Access-exception-fetch/store-indication facility"),
+    FEAT_INIT("msa3-base", S390_FEAT_TYPE_STFL, 76, "Message-security-assist-extension-3 facility (no subfunctions)"),
+    FEAT_INIT("msa4-base", S390_FEAT_TYPE_STFL, 77, "Message-security-assist-extension-4 facility"),
+    FEAT_INIT("edat2", S390_FEAT_TYPE_STFL, 78, "Enhanced-DAT facility 2"),
+    FEAT_INIT("dfppc", S390_FEAT_TYPE_STFL, 80, "Decimal-floating-point packed-conversion facility"),
+    FEAT_INIT("vx", S390_FEAT_TYPE_STFL, 129, "Vector facility"),
+    FEAT_INIT("scputm", S390_FEAT_TYPE_STFL, 142, "Store-CPU-counter-multiple facility"),
+
+    FEAT_INIT("gsls", S390_FEAT_TYPE_SCLP_CONF_CHAR, 40, "SIE: Guest-storage-limit-suppression facility"),
+    FEAT_INIT("esop", S390_FEAT_TYPE_SCLP_CONF_CHAR, 46, "Enhanced-suppression-on-protection facility"),
+
+    FEAT_INIT("64bscao", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 0, "SIE: 64-bit-SCAO facility"),
+    FEAT_INIT("cmma", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 1, "SIE: Collaborative-memory-management assist"),
+    FEAT_INIT("pfmfi", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 9, "SIE: PFMF interpretation facility"),
+    FEAT_INIT("ibs", S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT, 10, "SIE: Interlock-and-broadcast-suppression facility"),
+
+    FEAT_INIT("sief2", S390_FEAT_TYPE_SCLP_CPU, 4, "SIE: interception format 2 (Virtual SIE)"),
+    FEAT_INIT("skey", S390_FEAT_TYPE_SCLP_CPU, 5, "SIE: Storage-key facility"),
+    FEAT_INIT("gpereh", S390_FEAT_TYPE_SCLP_CPU, 10, "SIE: Guest-PER enhancement facility"),
+    FEAT_INIT("siif", S390_FEAT_TYPE_SCLP_CPU, 11, "SIE: Shared IPTE-interlock facility"),
+    FEAT_INIT("sigpif", S390_FEAT_TYPE_SCLP_CPU, 12, "SIE: SIGP interpretation facility"),
+    FEAT_INIT("ib", S390_FEAT_TYPE_SCLP_CPU, 42, "SIE: Intervention bypass facility"),
+    FEAT_INIT("cei", S390_FEAT_TYPE_SCLP_CPU, 43, "SIE: Conditional-external-interception facility"),
+
+    FEAT_INIT("dateh2", S390_FEAT_TYPE_MISC, 0, "DAT-enhancement facility 2"),
+    FEAT_INIT("cmm", S390_FEAT_TYPE_MISC, 0, "Collaborative-memory-management facility"),
+
+    FEAT_INIT("plo-cl", S390_FEAT_TYPE_PLO, 0, "PLO Compare and load (32 bit in general registers)"),
+    FEAT_INIT("plo-clg", S390_FEAT_TYPE_PLO, 1, "PLO Compare and load (64 bit in parameter list)"),
+    FEAT_INIT("plo-clgr", S390_FEAT_TYPE_PLO, 2, "PLO Compare and load (32 bit in general registers)"),
+    FEAT_INIT("plo-clx", S390_FEAT_TYPE_PLO, 3, "PLO Compare and load (128 bit in parameter list)"),
+    FEAT_INIT("plo-cs", S390_FEAT_TYPE_PLO, 4, "PLO Compare and swap (32 bit in general registers)"),
+    FEAT_INIT("plo-csg", S390_FEAT_TYPE_PLO, 5, "PLO Compare and swap (64 bit in parameter list)"),
+    FEAT_INIT("plo-csgr", S390_FEAT_TYPE_PLO, 6, "PLO Compare and swap (32 bit in general registers)"),
+    FEAT_INIT("plo-csx", S390_FEAT_TYPE_PLO, 7, "PLO Compare and swap (128 bit in parameter list)"),
+    FEAT_INIT("plo-dcs", S390_FEAT_TYPE_PLO, 8, "PLO Double compare and swap (32 bit in general registers)"),
+    FEAT_INIT("plo-dcsg", S390_FEAT_TYPE_PLO, 9, "PLO Double compare and swap (64 bit in parameter list)"),
+    FEAT_INIT("plo-dcsgr", S390_FEAT_TYPE_PLO, 10, "PLO Double compare and swap (32 bit in general registers)"),
+    FEAT_INIT("plo-dcsx", S390_FEAT_TYPE_PLO, 11, "PLO Double compare and swap (128 bit in parameter list)"),
+    FEAT_INIT("plo-csst", S390_FEAT_TYPE_PLO, 12, "PLO Compare and swap and store (32 bit in general registers)"),
+    FEAT_INIT("plo-csstg", S390_FEAT_TYPE_PLO, 13, "PLO Compare and swap and store (64 bit in parameter list)"),
+    FEAT_INIT("plo-csstgr", S390_FEAT_TYPE_PLO, 14, "PLO Compare and swap and store (32 bit in general registers)"),
+    FEAT_INIT("plo-csstx", S390_FEAT_TYPE_PLO, 15, "PLO Compare and swap and store (128 bit in parameter list)"),
+    FEAT_INIT("plo-csdst", S390_FEAT_TYPE_PLO, 16, "PLO Compare and swap and double store (32 bit in general registers)"),
+    FEAT_INIT("plo-csdstg", S390_FEAT_TYPE_PLO, 17, "PLO Compare and swap and double store (64 bit in parameter list)"),
+    FEAT_INIT("plo-csdstgr", S390_FEAT_TYPE_PLO, 18, "PLO Compare and swap and double store (32 bit in general registers)"),
+    FEAT_INIT("plo-csdstx", S390_FEAT_TYPE_PLO, 19, "PLO Compare and swap and double store (128 bit in parameter list)"),
+    FEAT_INIT("plo-cstst", S390_FEAT_TYPE_PLO, 20, "PLO Compare and swap and triple store (32 bit in general registers)"),
+    FEAT_INIT("plo-cststg", S390_FEAT_TYPE_PLO, 21, "PLO Compare and swap and triple store (64 bit in parameter list)"),
+    FEAT_INIT("plo-cststgr", S390_FEAT_TYPE_PLO, 22, "PLO Compare and swap and triple store (32 bit in general registers)"),
+    FEAT_INIT("plo-cststx", S390_FEAT_TYPE_PLO, 23, "PLO Compare and swap and triple store (128 bit in parameter list)"),
+
+    FEAT_INIT("ptff-qto", S390_FEAT_TYPE_PTFF, 1, "PTFF Query TOD Offset"),
+    FEAT_INIT("ptff-qsi", S390_FEAT_TYPE_PTFF, 2, "PTFF Query Steering Information"),
+    FEAT_INIT("ptff-qpc", S390_FEAT_TYPE_PTFF, 3, "PTFF Query Physical Clock"),
+    FEAT_INIT("ptff-qui", S390_FEAT_TYPE_PTFF, 4, "PTFF Query UTC Information"),
+    FEAT_INIT("ptff-qtou", S390_FEAT_TYPE_PTFF, 5, "PTFF Query TOD Offset User"),
+    FEAT_INIT("ptff-sto", S390_FEAT_TYPE_PTFF, 65, "PTFF Set TOD Offset"),
+    FEAT_INIT("ptff-stou", S390_FEAT_TYPE_PTFF, 69, "PTFF Set TOD Offset User"),
+
+    FEAT_INIT("kmac-dea", S390_FEAT_TYPE_KMAC, 1, "KMAC DEA"),
+    FEAT_INIT("kmac-tdea-128", S390_FEAT_TYPE_KMAC, 2, "KMAC TDEA-128"),
+    FEAT_INIT("kmac-tdea-192", S390_FEAT_TYPE_KMAC, 3, "KMAC TDEA-192"),
+    FEAT_INIT("kmac-edea", S390_FEAT_TYPE_KMAC, 9, "KMAC Encrypted-DEA"),
+    FEAT_INIT("kmac-etdea-128", S390_FEAT_TYPE_KMAC, 10, "KMAC Encrypted-TDEA-128"),
+    FEAT_INIT("kmac-etdea-192", S390_FEAT_TYPE_KMAC, 11, "KMAC Encrypted-TDEA-192"),
+    FEAT_INIT("kmac-aes-128", S390_FEAT_TYPE_KMAC, 18, "KMAC AES-128"),
+    FEAT_INIT("kmac-aes-192", S390_FEAT_TYPE_KMAC, 19, "KMAC AES-192"),
+    FEAT_INIT("kmac-aes-256", S390_FEAT_TYPE_KMAC, 20, "KMAC AES-256"),
+    FEAT_INIT("kmac-eaes-128", S390_FEAT_TYPE_KMAC, 26, "KMAC Encrypted-AES-128"),
+    FEAT_INIT("kmac-eaes-192", S390_FEAT_TYPE_KMAC, 27, "KMAC Encrypted-AES-192"),
+    FEAT_INIT("kmac-eaes-256", S390_FEAT_TYPE_KMAC, 28, "KMAC Encrypted-AES-256"),
+
+    FEAT_INIT("kmc-dea", S390_FEAT_TYPE_KMC, 1, "KMC DEA"),
+    FEAT_INIT("kmc-tdea-128", S390_FEAT_TYPE_KMC, 2, "KMC TDEA-128"),
+    FEAT_INIT("kmc-tdea-192", S390_FEAT_TYPE_KMC, 3, "KMC TDEA-192"),
+    FEAT_INIT("kmc-edea", S390_FEAT_TYPE_KMC, 9, "KMC Encrypted-DEA"),
+    FEAT_INIT("kmc-etdea-128", S390_FEAT_TYPE_KMC, 10, "KMC Encrypted-TDEA-128"),
+    FEAT_INIT("kmc-etdea-192", S390_FEAT_TYPE_KMC, 11, "KMC Encrypted-TDEA-192"),
+    FEAT_INIT("kmc-aes-128", S390_FEAT_TYPE_KMC, 18, "KMC AES-128"),
+    FEAT_INIT("kmc-aes-192", S390_FEAT_TYPE_KMC, 19, "KMC AES-192"),
+    FEAT_INIT("kmc-aes-256", S390_FEAT_TYPE_KMC, 20, "KMC AES-256"),
+    FEAT_INIT("kmc-eaes-128", S390_FEAT_TYPE_KMC, 26, "KMC Encrypted-AES-128"),
+    FEAT_INIT("kmc-eaes-192", S390_FEAT_TYPE_KMC, 27, "KMC Encrypted-AES-192"),
+    FEAT_INIT("kmc-eaes-256", S390_FEAT_TYPE_KMC, 28, "KMC Encrypted-AES-256"),
+    FEAT_INIT("kmc-prng", S390_FEAT_TYPE_KMC, 67, "KMC PRNG"),
+
+    FEAT_INIT("km-dea", S390_FEAT_TYPE_KM, 1, "KM DEA"),
+    FEAT_INIT("km-tdea-128", S390_FEAT_TYPE_KM, 2, "KM TDEA-128"),
+    FEAT_INIT("km-tdea-192", S390_FEAT_TYPE_KM, 3, "KM TDEA-192"),
+    FEAT_INIT("km-edea", S390_FEAT_TYPE_KM, 9, "KM Encrypted-DEA"),
+    FEAT_INIT("km-etdea-128", S390_FEAT_TYPE_KM, 10, "KM Encrypted-TDEA-128"),
+    FEAT_INIT("km-etdea-192", S390_FEAT_TYPE_KM, 11, "KM Encrypted-TDEA-192"),
+    FEAT_INIT("km-aes-128", S390_FEAT_TYPE_KM, 18, "KM AES-128"),
+    FEAT_INIT("km-aes-192", S390_FEAT_TYPE_KM, 19, "KM AES-192"),
+    FEAT_INIT("km-aes-256", S390_FEAT_TYPE_KM, 20, "KM AES-256"),
+    FEAT_INIT("km-eaes-128", S390_FEAT_TYPE_KM, 26, "KM Encrypted-AES-128"),
+    FEAT_INIT("km-eaes-192", S390_FEAT_TYPE_KM, 27, "KM Encrypted-AES-192"),
+    FEAT_INIT("km-eaes-256", S390_FEAT_TYPE_KM, 28, "KM Encrypted-AES-256"),
+    FEAT_INIT("km-xts-aes-128", S390_FEAT_TYPE_KM, 50, "KM XTS-AES-128"),
+    FEAT_INIT("km-xts-aes-256", S390_FEAT_TYPE_KM, 52, "KM XTS-AES-256"),
+    FEAT_INIT("km-xts-eaes-128", S390_FEAT_TYPE_KM, 58, "KM XTS-Encrypted-AES-128"),
+    FEAT_INIT("km-xts-eaes-256", S390_FEAT_TYPE_KM, 60, "KM XTS-Encrypted-AES-256"),
+
+    FEAT_INIT("kimd-sha-1", S390_FEAT_TYPE_KIMD, 1, "KIMD SHA-1"),
+    FEAT_INIT("kimd-sha-256", S390_FEAT_TYPE_KIMD, 2, "KIMD SHA-256"),
+    FEAT_INIT("kimd-sha-512", S390_FEAT_TYPE_KIMD, 3, "KIMD SHA-512"),
+    FEAT_INIT("kimd-ghash", S390_FEAT_TYPE_KIMD, 65, "KIMD GHASH"),
+    FEAT_INIT("klmd-sha-1", S390_FEAT_TYPE_KLMD, 1, "KLMD SHA-1"),
+    FEAT_INIT("klmd-sha-256", S390_FEAT_TYPE_KLMD, 2, "KLMD SHA-256"),
+    FEAT_INIT("klmd-sha-512", S390_FEAT_TYPE_KLMD, 3, "KLMD SHA-512"),
+
+    FEAT_INIT("pckmo-edea", S390_FEAT_TYPE_PCKMO, 1, "PCKMO Encrypted-DEA-Key"),
+    FEAT_INIT("pckmo-etdea-128", S390_FEAT_TYPE_PCKMO, 2, "PCKMO Encrypted-TDEA-128-Key"),
+    FEAT_INIT("pckmo-etdea-192", S390_FEAT_TYPE_PCKMO, 3, "PCKMO Encrypted-TDEA-192-Key"),
+    FEAT_INIT("pckmo-aes-128", S390_FEAT_TYPE_PCKMO, 18, "PCKMO Encrypted-AES-128-Key"),
+    FEAT_INIT("pckmo-aes-192", S390_FEAT_TYPE_PCKMO, 19, "PCKMO Encrypted-AES-192-Key"),
+    FEAT_INIT("pckmo-aes-256", S390_FEAT_TYPE_PCKMO, 20, "PCKMO Encrypted-AES-256-Key"),
+
+    FEAT_INIT("kmctr-dea", S390_FEAT_TYPE_KMCTR, 1, "KMCTR DEA"),
+    FEAT_INIT("kmctr-tdea-128", S390_FEAT_TYPE_KMCTR, 2, "KMCTR TDEA-128"),
+    FEAT_INIT("kmctr-tdea-192", S390_FEAT_TYPE_KMCTR, 3, "KMCTR TDEA-192"),
+    FEAT_INIT("kmctr-edea", S390_FEAT_TYPE_KMCTR, 9, "KMCTR Encrypted-DEA"),
+    FEAT_INIT("kmctr-etdea-128", S390_FEAT_TYPE_KMCTR, 10, "KMCTR Encrypted-TDEA-128"),
+    FEAT_INIT("kmctr-etdea-192", S390_FEAT_TYPE_KMCTR, 11, "KMCTR Encrypted-TDEA-192"),
+    FEAT_INIT("kmctr-aes-128", S390_FEAT_TYPE_KMCTR, 18, "KMCTR AES-128"),
+    FEAT_INIT("kmctr-aes-192", S390_FEAT_TYPE_KMCTR, 19, "KMCTR AES-192"),
+    FEAT_INIT("kmctr-aes-256", S390_FEAT_TYPE_KMCTR, 20, "KMCTR AES-256"),
+    FEAT_INIT("kmctr-eaes-128", S390_FEAT_TYPE_KMCTR, 26, "KMCTR Encrypted-AES-128"),
+    FEAT_INIT("kmctr-eaes-192", S390_FEAT_TYPE_KMCTR, 27, "KMCTR Encrypted-AES-192"),
+    FEAT_INIT("kmctr-eaes-256", S390_FEAT_TYPE_KMCTR, 28, "KMCTR Encrypted-AES-256"),
+
+    FEAT_INIT("kmf-dea", S390_FEAT_TYPE_KMF, 1, "KMF DEA"),
+    FEAT_INIT("kmf-tdea-128", S390_FEAT_TYPE_KMF, 2, "KMF TDEA-128"),
+    FEAT_INIT("kmf-tdea-192", S390_FEAT_TYPE_KMF, 3, "KMF TDEA-192"),
+    FEAT_INIT("kmf-edea", S390_FEAT_TYPE_KMF, 9, "KMF Encrypted-DEA"),
+    FEAT_INIT("kmf-etdea-128", S390_FEAT_TYPE_KMF, 10, "KMF Encrypted-TDEA-128"),
+    FEAT_INIT("kmf-etdea-192", S390_FEAT_TYPE_KMF, 11, "KMF Encrypted-TDEA-192"),
+    FEAT_INIT("kmf-aes-128", S390_FEAT_TYPE_KMF, 18, "KMF AES-128"),
+    FEAT_INIT("kmf-aes-192", S390_FEAT_TYPE_KMF, 19, "KMF AES-192"),
+    FEAT_INIT("kmf-aes-256", S390_FEAT_TYPE_KMF, 20, "KMF AES-256"),
+    FEAT_INIT("kmf-eaes-128", S390_FEAT_TYPE_KMF, 26, "KMF Encrypted-AES-128"),
+    FEAT_INIT("kmf-eaes-192", S390_FEAT_TYPE_KMF, 27, "KMF Encrypted-AES-192"),
+    FEAT_INIT("kmf-eaes-256", S390_FEAT_TYPE_KMF, 28, "KMF Encrypted-AES-256"),
+
+    FEAT_INIT("kmo-dea", S390_FEAT_TYPE_KMO, 1, "KMO DEA"),
+    FEAT_INIT("kmo-tdea-128", S390_FEAT_TYPE_KMO, 2, "KMO TDEA-128"),
+    FEAT_INIT("kmo-tdea-192", S390_FEAT_TYPE_KMO, 3, "KMO TDEA-192"),
+    FEAT_INIT("kmo-edea", S390_FEAT_TYPE_KMO, 9, "KMO Encrypted-DEA"),
+    FEAT_INIT("kmo-etdea-128", S390_FEAT_TYPE_KMO, 10, "KMO Encrypted-TDEA-128"),
+    FEAT_INIT("kmo-etdea-192", S390_FEAT_TYPE_KMO, 11, "KMO Encrypted-TDEA-192"),
+    FEAT_INIT("kmo-aes-128", S390_FEAT_TYPE_KMO, 18, "KMO AES-128"),
+    FEAT_INIT("kmo-aes-192", S390_FEAT_TYPE_KMO, 19, "KMO AES-192"),
+    FEAT_INIT("kmo-aes-256", S390_FEAT_TYPE_KMO, 20, "KMO AES-256"),
+    FEAT_INIT("kmo-eaes-128", S390_FEAT_TYPE_KMO, 26, "KMO Encrypted-AES-128"),
+    FEAT_INIT("kmo-eaes-192", S390_FEAT_TYPE_KMO, 27, "KMO Encrypted-AES-192"),
+    FEAT_INIT("kmo-eaes-256", S390_FEAT_TYPE_KMO, 28, "KMO Encrypted-AES-256"),
+
+    FEAT_INIT("pcc-cmac-dea", S390_FEAT_TYPE_PCC, 1, "PCC Compute-Last-Block-CMAC-Using-DEA"),
+    FEAT_INIT("pcc-cmac-tdea-128", S390_FEAT_TYPE_PCC, 2, "PCC Compute-Last-Block-CMAC-Using-TDEA-128"),
+    FEAT_INIT("pcc-cmac-tdea-192", S390_FEAT_TYPE_PCC, 3, "PCC Compute-Last-Block-CMAC-Using-TDEA-192"),
+    FEAT_INIT("pcc-cmac-edea", S390_FEAT_TYPE_PCC, 9, "PCC Compute-Last-Block-CMAC-Using-Encrypted-DEA"),
+    FEAT_INIT("pcc-cmac-etdea-128", S390_FEAT_TYPE_PCC, 10, "PCC Compute-Last-Block-CMAC-Using-Encrypted-TDEA-128"),
+    FEAT_INIT("pcc-cmac-etdea-192", S390_FEAT_TYPE_PCC, 11, "PCC Compute-Last-Block-CMAC-Using-EncryptedTDEA-192"),
+    FEAT_INIT("pcc-cmac-aes-128", S390_FEAT_TYPE_PCC, 18, "PCC Compute-Last-Block-CMAC-Using-AES-128"),
+    FEAT_INIT("pcc-cmac-aes-192", S390_FEAT_TYPE_PCC, 19, "PCC Compute-Last-Block-CMAC-Using-AES-192"),
+    FEAT_INIT("pcc-cmac-eaes-256", S390_FEAT_TYPE_PCC, 20, "PCC Compute-Last-Block-CMAC-Using-AES-256"),
+    FEAT_INIT("pcc-cmac-eaes-128", S390_FEAT_TYPE_PCC, 26, "PCC Compute-Last-Block-CMAC-Using-Encrypted-AES-128"),
+    FEAT_INIT("pcc-cmac-eaes-192", S390_FEAT_TYPE_PCC, 27, "PCC Compute-Last-Block-CMAC-Using-Encrypted-AES-192"),
+    FEAT_INIT("pcc-cmac-eaes-256", S390_FEAT_TYPE_PCC, 28, "PCC Compute-Last-Block-CMAC-Using-Encrypted-AES-256"),
+    FEAT_INIT("pcc-xts-aes-128", S390_FEAT_TYPE_PCC, 50, "PCC Compute-XTS-Parameter-Using-AES-128"),
+    FEAT_INIT("pcc-xts-aes-256", S390_FEAT_TYPE_PCC, 52, "PCC Compute-XTS-Parameter-Using-AES-256"),
+    FEAT_INIT("pcc-xts-eaes-128", S390_FEAT_TYPE_PCC, 58, "PCC Compute-XTS-Parameter-Using-Encrypted-AES-128"),
+    FEAT_INIT("pcc-xts-eaes-256", S390_FEAT_TYPE_PCC, 60, "PCC Compute-XTS-Parameter-Using-Encrypted-AES-256"),
+
+    FEAT_INIT("ppno-sha-512-drng", S390_FEAT_TYPE_PPNO, 3, "PPNO SHA-512-DRNG"),
+};
+
+const S390FeatDef *s390_feat_def(S390Feat feat)
+{
+    return &s390_features[feat];
+}
+
+S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit)
+{
+    S390Feat feat;
+
+    for (feat = 0; feat < ARRAY_SIZE(s390_features); feat++) {
+        if (s390_features[feat].type == type &&
+            s390_features[feat].bit == bit) {
+            return feat;
+        }
+    }
+    return S390_FEAT_MAX;
+}
+
+void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
+                          uint8_t *data)
+{
+    S390Feat feat;
+    int bit_nr;
+
+    if (type == S390_FEAT_TYPE_STFL && test_bit(S390_FEAT_ZARCH, features)) {
+        /* z/Architecture is always active if around */
+        data[0] |= 0x20;
+    }
+
+    feat = find_first_bit(features, S390_FEAT_MAX);
+    while (feat < S390_FEAT_MAX) {
+        if (s390_features[feat].type == type) {
+            bit_nr = s390_features[feat].bit;
+            /* big endian on uint8_t array */
+            data[bit_nr / 8] |= 0x80 >> (bit_nr % 8);
+        }
+        feat = find_next_bit(features, S390_FEAT_MAX, feat + 1);
+    }
+}
+
+void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
+                              uint8_t *data)
+{
+    int nr_bits, le_bit;
+
+    switch (type) {
+    case S390_FEAT_TYPE_STFL:
+       nr_bits = 2048;
+       break;
+    case S390_FEAT_TYPE_PLO:
+       nr_bits = 256;
+       break;
+    default:
+       /* all cpu subfunctions have 128 bit */
+       nr_bits = 128;
+    };
+
+    le_bit = find_first_bit((unsigned long *) data, nr_bits);
+    while (le_bit < nr_bits) {
+        /* convert the bit number to a big endian bit nr */
+        S390Feat feat = s390_feat_by_type_and_bit(type, BE_BIT_NR(le_bit));
+        /* ignore unknown bits */
+        if (feat < S390_FEAT_MAX) {
+            set_bit(feat, features);
+        }
+        le_bit = find_next_bit((unsigned long *) data, nr_bits, le_bit + 1);
+    }
+}
+
+void s390_feat_bitmap_to_ascii(const S390FeatBitmap bitmap, void *opaque,
+                               void (*fn)(const char *name, void *opaque))
+{
+    S390Feat feat;
+
+    feat = find_first_bit(bitmap, S390_FEAT_MAX);
+    while (feat < S390_FEAT_MAX) {
+        fn(s390_feat_def(feat)->name, opaque);
+        feat = find_next_bit(bitmap, S390_FEAT_MAX, feat + 1);
+    };
+}
diff --git a/target-s390x/cpu_features.h b/target-s390x/cpu_features.h
new file mode 100644
index 0000000..485446c
--- /dev/null
+++ b/target-s390x/cpu_features.h
@@ -0,0 +1,279 @@
+/*
+ * CPU features/facilities for s390
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com>
+ *            David Hildenbrand <dahi@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef TARGET_S390X_CPU_FEATURES_H
+#define TARGET_S390X_CPU_FEATURES_H
+
+#include "qemu/bitmap.h"
+
+typedef enum {
+    S390_FEAT_N3 = 0,
+    S390_FEAT_ZARCH,
+    S390_FEAT_DAT_ENH_1,
+    S390_FEAT_IDTE_SEGMENT,
+    S390_FEAT_IDTE_REGION,
+    S390_FEAT_ASN_LX_REUSE,
+    S390_FEAT_STFLE,
+    S390_FEAT_EDAT_1,
+    S390_FEAT_SENSE_RUNNING_STATUS,
+    S390_FEAT_CONDITIONAL_SSKE,
+    S390_FEAT_CONFIGURATION_TOPOLOGY,
+    S390_FEAT_IPTE_RANGE,
+    S390_FEAT_NONQ_KEY_SETTING,
+    S390_FEAT_EXTENDED_TRANSLATION_2,
+    S390_FEAT_MSA,
+    S390_FEAT_LONG_DISPLACEMENT,
+    S390_FEAT_LONG_DISPLACEMENT_FAST,
+    S390_FEAT_HFP_MADDSUB,
+    S390_FEAT_EXTENDED_IMMEDIATE,
+    S390_FEAT_EXTENDED_TRANSLATION_3,
+    S390_FEAT_HFP_UNNORMALIZED_EXT,
+    S390_FEAT_ETF2_ENH,
+    S390_FEAT_STORE_CLOCK_FAST,
+    S390_FEAT_PARSING_ENH,
+    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
+    S390_FEAT_TOD_CLOCK_STEERING,
+    S390_FEAT_ETF3_ENH,
+    S390_FEAT_EXTRACT_CPU_TIME,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
+    S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
+    S390_FEAT_EXECUTE_EXT,
+    S390_FEAT_ENHANCED_MONITOR,
+    S390_FEAT_FLOATING_POINT_EXT,
+    S390_FEAT_SET_PROGRAM_PARAMETERS,
+    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
+    S390_FEAT_DFP,
+    S390_FEAT_DFP_FAST,
+    S390_FEAT_PFPO,
+    S390_FEAT_GEN11_ENH,
+    S390_FEAT_CMPSC_ENH,
+    S390_FEAT_DFP_ZONED_CONVERSION,
+    S390_FEAT_GEN12_ENH,
+    S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
+    S390_FEAT_LOCAL_TLB_CLEARING,
+    S390_FEAT_INTERLOCKED_ACCESS_2,
+    S390_FEAT_GEN13_ENH,
+    S390_FEAT_MSA_EXT_5,
+    S390_FEAT_RUNTIME_INSTRUMENTATION,
+    S390_FEAT_TRANSACTIONAL_EXE,
+    S390_FEAT_STORE_HYPERVISOR_INFO,
+    S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
+    S390_FEAT_MSA_EXT_3,
+    S390_FEAT_MSA_EXT_4,
+    S390_FEAT_EDAT_2,
+    S390_FEAT_DFP_PACKED_CONVERSION,
+    S390_FEAT_VECTOR,
+    S390_FEAT_STORE_CPU_COUNTER_MULTI,
+    S390_FEAT_SIE_GSLS,
+    S390_FEAT_ESOP,
+    S390_FEAT_SIE_64BSCAO,
+    S390_FEAT_SIE_CMMA,
+    S390_FEAT_SIE_PFMFI,
+    S390_FEAT_SIE_IBS,
+    S390_FEAT_SIE_F2,
+    S390_FEAT_SIE_SKEY,
+    S390_FEAT_SIE_GPERE,
+    S390_FEAT_SIE_SIIF,
+    S390_FEAT_SIE_SIGPIF,
+    S390_FEAT_SIE_IB,
+    S390_FEAT_SIE_CEI,
+    S390_FEAT_DAT_ENH_2,
+    S390_FEAT_CMM,
+    S390_FEAT_PLO_CL,
+    S390_FEAT_PLO_CLG,
+    S390_FEAT_PLO_CLGR,
+    S390_FEAT_PLO_CLX,
+    S390_FEAT_PLO_CS,
+    S390_FEAT_PLO_CSG,
+    S390_FEAT_PLO_CSGR,
+    S390_FEAT_PLO_CSX,
+    S390_FEAT_PLO_DCS,
+    S390_FEAT_PLO_DCSG,
+    S390_FEAT_PLO_DCSGR,
+    S390_FEAT_PLO_DCSX,
+    S390_FEAT_PLO_CSST,
+    S390_FEAT_PLO_CSSTG,
+    S390_FEAT_PLO_CSSTGR,
+    S390_FEAT_PLO_CSSTX,
+    S390_FEAT_PLO_CSDST,
+    S390_FEAT_PLO_CSDSTG,
+    S390_FEAT_PLO_CSDSTGR,
+    S390_FEAT_PLO_CSDSTX,
+    S390_FEAT_PLO_CSTST,
+    S390_FEAT_PLO_CSTSTG,
+    S390_FEAT_PLO_CSTSTGR,
+    S390_FEAT_PLO_CSTSTX,
+    S390_FEAT_PTFF_QTO,
+    S390_FEAT_PTFF_QSI,
+    S390_FEAT_PTFF_QPT,
+    S390_FEAT_PTFF_QUI,
+    S390_FEAT_PTFF_QTOU,
+    S390_FEAT_PTFF_STO,
+    S390_FEAT_PTFF_STOU,
+    S390_FEAT_KMAC_DEA,
+    S390_FEAT_KMAC_TDEA_128,
+    S390_FEAT_KMAC_TDEA_192,
+    S390_FEAT_KMAC_EDEA,
+    S390_FEAT_KMAC_ETDEA_128,
+    S390_FEAT_KMAC_ETDEA_192,
+    S390_FEAT_KMAC_AES_128,
+    S390_FEAT_KMAC_AES_192,
+    S390_FEAT_KMAC_AES_256,
+    S390_FEAT_KMAC_EAES_128,
+    S390_FEAT_KMAC_EAES_192,
+    S390_FEAT_KMAC_EAES_256,
+    S390_FEAT_KMC_DEA,
+    S390_FEAT_KMC_TDEA_128,
+    S390_FEAT_KMC_TDEA_192,
+    S390_FEAT_KMC_EDEA,
+    S390_FEAT_KMC_ETDEA_128,
+    S390_FEAT_KMC_ETDEA_192,
+    S390_FEAT_KMC_AES_128,
+    S390_FEAT_KMC_AES_192,
+    S390_FEAT_KMC_AES_256,
+    S390_FEAT_KMC_EAES_128,
+    S390_FEAT_KMC_EAES_192,
+    S390_FEAT_KMC_EAES_256,
+    S390_FEAT_KMC_PRNG,
+    S390_FEAT_KM_DEA,
+    S390_FEAT_KM_TDEA_128,
+    S390_FEAT_KM_TDEA_192,
+    S390_FEAT_KM_EDEA,
+    S390_FEAT_KM_ETDEA_128,
+    S390_FEAT_KM_ETDEA_192,
+    S390_FEAT_KM_AES_128,
+    S390_FEAT_KM_AES_192,
+    S390_FEAT_KM_AES_256,
+    S390_FEAT_KM_EAES_128,
+    S390_FEAT_KM_EAES_192,
+    S390_FEAT_KM_EAES_256,
+    S390_FEAT_KM_XTS_AES_128,
+    S390_FEAT_KM_XTS_AES_256,
+    S390_FEAT_KM_XTS_EAES_128,
+    S390_FEAT_KM_XTS_EAES_256,
+    S390_FEAT_KIMD_SHA_1,
+    S390_FEAT_KIMD_SHA_256,
+    S390_FEAT_KIMD_SHA_512,
+    S390_FEAT_KIMD_GHASH,
+    S390_FEAT_KLMD_SHA_1,
+    S390_FEAT_KLMD_SHA_256,
+    S390_FEAT_KLMD_SHA_512,
+    S390_FEAT_PCKMO_EDEA,
+    S390_FEAT_PCKMO_ETDEA_128,
+    S390_FEAT_PCKMO_ETDEA_256,
+    S390_FEAT_PCKMO_AES_128,
+    S390_FEAT_PCKMO_AES_192,
+    S390_FEAT_PCKMO_AES_256,
+    S390_FEAT_KMCTR_DEA,
+    S390_FEAT_KMCTR_TDEA_128,
+    S390_FEAT_KMCTR_TDEA_192,
+    S390_FEAT_KMCTR_EDEA,
+    S390_FEAT_KMCTR_ETDEA_128,
+    S390_FEAT_KMCTR_ETDEA_192,
+    S390_FEAT_KMCTR_AES_128,
+    S390_FEAT_KMCTR_AES_192,
+    S390_FEAT_KMCTR_AES_256,
+    S390_FEAT_KMCTR_EAES_128,
+    S390_FEAT_KMCTR_EAES_192,
+    S390_FEAT_KMCTR_EAES_256,
+    S390_FEAT_KMF_DEA,
+    S390_FEAT_KMF_TDEA_128,
+    S390_FEAT_KMF_TDEA_192,
+    S390_FEAT_KMF_EDEA,
+    S390_FEAT_KMF_ETDEA_128,
+    S390_FEAT_KMF_ETDEA_192,
+    S390_FEAT_KMF_AES_128,
+    S390_FEAT_KMF_AES_192,
+    S390_FEAT_KMF_AES_256,
+    S390_FEAT_KMF_EAES_128,
+    S390_FEAT_KMF_EAES_192,
+    S390_FEAT_KMF_EAES_256,
+    S390_FEAT_KMO_DEA,
+    S390_FEAT_KMO_TDEA_128,
+    S390_FEAT_KMO_TDEA_192,
+    S390_FEAT_KMO_EDEA,
+    S390_FEAT_KMO_ETDEA_128,
+    S390_FEAT_KMO_ETDEA_192,
+    S390_FEAT_KMO_AES_128,
+    S390_FEAT_KMO_AES_192,
+    S390_FEAT_KMO_AES_256,
+    S390_FEAT_KMO_EAES_128,
+    S390_FEAT_KMO_EAES_192,
+    S390_FEAT_KMO_EAES_256,
+    S390_FEAT_PCC_CMAC_DEA,
+    S390_FEAT_PCC_CMAC_TDEA_128,
+    S390_FEAT_PCC_CMAC_TDEA_192,
+    S390_FEAT_PCC_CMAC_ETDEA_128,
+    S390_FEAT_PCC_CMAC_ETDEA_192,
+    S390_FEAT_PCC_CMAC_TDEA,
+    S390_FEAT_PCC_CMAC_AES_128,
+    S390_FEAT_PCC_CMAC_AES_192,
+    S390_FEAT_PCC_CMAC_AES_256,
+    S390_FEAT_PCC_CMAC_EAES_128,
+    S390_FEAT_PCC_CMAC_EAES_192,
+    S390_FEAT_PCC_CMAC_EAES_256,
+    S390_FEAT_PCC_XTS_AES_128,
+    S390_FEAT_PCC_XTS_AES_256,
+    S390_FEAT_PCC_XTS_EAES_128,
+    S390_FEAT_PCC_XTS_EAES_256,
+    S390_FEAT_PPNO_SHA_512_DRNG,
+    S390_FEAT_MAX,
+} S390Feat;
+
+/* CPU features are announced via different ways */
+typedef enum {
+    S390_FEAT_TYPE_STFL,
+    S390_FEAT_TYPE_SCLP_CONF_CHAR,
+    S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT,
+    S390_FEAT_TYPE_SCLP_CPU,
+    S390_FEAT_TYPE_MISC,
+    S390_FEAT_TYPE_PLO,
+    S390_FEAT_TYPE_PTFF,
+    S390_FEAT_TYPE_KMAC,
+    S390_FEAT_TYPE_KMC,
+    S390_FEAT_TYPE_KM,
+    S390_FEAT_TYPE_KIMD,
+    S390_FEAT_TYPE_KLMD,
+    S390_FEAT_TYPE_PCKMO,
+    S390_FEAT_TYPE_KMCTR,
+    S390_FEAT_TYPE_KMF,
+    S390_FEAT_TYPE_KMO,
+    S390_FEAT_TYPE_PCC,
+    S390_FEAT_TYPE_PPNO,
+} S390FeatType;
+
+/* Definition of a CPU feature */
+typedef struct {
+    const char *name;       /* name exposed to the user */
+    const char *desc;       /* description exposed to the user */
+    S390FeatType type;      /* feature type (way of indication)*/
+    int bit;                /* bit within the feature type area (fixed) */
+} S390FeatDef;
+
+/* use ordinary bitmap operations to work with features */
+typedef unsigned long S390FeatBitmap[BITS_TO_LONGS(S390_FEAT_MAX)];
+
+const S390FeatDef *s390_feat_def(S390Feat feat);
+S390Feat s390_feat_by_type_and_bit(S390FeatType type, int bit);
+void s390_fill_feat_block(const S390FeatBitmap features, S390FeatType type,
+                          uint8_t *data);
+void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
+                          uint8_t *data);
+void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque,
+                               void (*fn)(const char *name, void *opaque));
+
+#define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
+#define BE_BIT(BIT) (1ULL < BE_BIT_NR(BIT))
+
+#endif /* TARGET_S390X_CPU_FEATURES_H */
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 05/29] s390x/cpumodel: generate CPU feature lists for CPU models
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (3 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 04/29] s390x/cpumodel: introduce CPU features David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 06/29] s390x/cpumodel: generate CPU feature group lists David Hildenbrand
                   ` (24 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

From: Michael Mueller <mimu@linux.vnet.ibm.com>

This patch introduces the helper "gen-features" which allows to generate
feature list definitions at compile time. Its flexibility is better and the
error-proneness is lower when compared to static programming time added
statements.

The helper includes "target-s390x/cpu_features.h" to be able to use named
facility bits instead of numbers. The generated defines will be used for
the definition of CPU models.

We generate feature lists for each HW generation and GA for EC models. BC
models are always based on a EC version and have no separate definitions.

Base features: Features we expect to be always available in sane setups.
Migration safe - will never change. Can be seen as "minimum features
required for a CPU model".

Default features: Features we expect to be stable and around in latest
setups (e.g. having KVM support) - not migration safe.

Max features: All supported features that are theoretically allowed for a
CPU model. Exceeding these features could otherwise produce problems with
IBC (instruction blocking controls) in KVM.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
[generate base, default and models. renaming and cleanup]
---
 Makefile.target             |   2 +-
 rules.mak                   |   1 +
 target-s390x/Makefile.objs  |  20 ++
 target-s390x/gen-features.c | 506 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 528 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/gen-features.c

diff --git a/Makefile.target b/Makefile.target
index a440bcb..8c7a072 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -212,7 +212,7 @@ hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx $(SRC_PATH)/scripts/hxtool
 	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 
-clean:
+clean: clean-target
 	rm -f *.a *~ $(PROGS)
 	rm -f $(shell find . -name '*.[od]')
 	rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
diff --git a/rules.mak b/rules.mak
index 99cd0b3..55b0121 100644
--- a/rules.mak
+++ b/rules.mak
@@ -14,6 +14,7 @@ MAKEFLAGS += -rR
 %.cpp:
 %.m:
 %.mak:
+clean-target:
 
 # Flags for C++ compilation
 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 4266c87..745d501 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -3,3 +3,23 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o
 obj-y += gdbstub.o cpu_models.o cpu_features.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
+
+# build and run feature list generator
+feat-src = $(SRC_PATH)/target-$(TARGET_BASE_ARCH)/
+feat-dst = $(BUILD_DIR)/$(TARGET_DIR)
+ifneq ($(MAKECMDGOALS),clean)
+GENERATED_HEADERS += $(feat-dst)gen-features.h
+endif
+
+$(feat-dst)gen-features.h: $(feat-dst)gen-features.h-timestamp
+	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
+$(feat-dst)gen-features.h-timestamp: $(feat-dst)gen-features
+	$(call quiet-command,$< >$@,"  GEN   $(TARGET_DIR)gen-features.h")
+
+$(feat-dst)gen-features: $(feat-src)gen-features.c config-target.h
+	$(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(CFLAGS) -o $@ $<,"  CC    $(TARGET_DIR)gen-features")
+
+clean-target:
+	rm -f gen-features.h-timestamp
+	rm -f gen-features.h
+	rm -f gen-features
diff --git a/target-s390x/gen-features.c b/target-s390x/gen-features.c
new file mode 100644
index 0000000..3a7c373
--- /dev/null
+++ b/target-s390x/gen-features.c
@@ -0,0 +1,506 @@
+/*
+ * S390 feature list generator
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): Michael Mueller <mimu@linux.vnet.ibm.com>
+ *            David Hildenbrand <dahi@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "cpu_features.h"
+
+/***** BEGIN FEATURE DEFS *****/
+
+#define S390_FEAT_GROUP_PLO \
+    S390_FEAT_PLO_CL, \
+    S390_FEAT_PLO_CLG, \
+    S390_FEAT_PLO_CLGR, \
+    S390_FEAT_PLO_CLX, \
+    S390_FEAT_PLO_CS, \
+    S390_FEAT_PLO_CSG, \
+    S390_FEAT_PLO_CSGR, \
+    S390_FEAT_PLO_CSX, \
+    S390_FEAT_PLO_DCS, \
+    S390_FEAT_PLO_DCSG, \
+    S390_FEAT_PLO_DCSGR, \
+    S390_FEAT_PLO_DCSX, \
+    S390_FEAT_PLO_CSST, \
+    S390_FEAT_PLO_CSSTG, \
+    S390_FEAT_PLO_CSSTGR, \
+    S390_FEAT_PLO_CSSTX, \
+    S390_FEAT_PLO_CSDST, \
+    S390_FEAT_PLO_CSDSTG, \
+    S390_FEAT_PLO_CSDSTGR, \
+    S390_FEAT_PLO_CSDSTX, \
+    S390_FEAT_PLO_CSTST, \
+    S390_FEAT_PLO_CSTSTG, \
+    S390_FEAT_PLO_CSTSTGR, \
+    S390_FEAT_PLO_CSTSTX
+
+#define S390_FEAT_GROUP_TOD_CLOCK_STEERING \
+    S390_FEAT_TOD_CLOCK_STEERING, \
+    S390_FEAT_PTFF_QTO, \
+    S390_FEAT_PTFF_QSI, \
+    S390_FEAT_PTFF_QPT, \
+    S390_FEAT_PTFF_STO
+
+#define S390_FEAT_GROUP_GEN13_PTFF \
+    S390_FEAT_PTFF_QUI, \
+    S390_FEAT_PTFF_QTOU, \
+    S390_FEAT_PTFF_STOU
+
+#define S390_FEAT_GROUP_MSA \
+    S390_FEAT_MSA, \
+    S390_FEAT_KMAC_DEA, \
+    S390_FEAT_KMAC_TDEA_128, \
+    S390_FEAT_KMAC_TDEA_192, \
+    S390_FEAT_KMC_DEA, \
+    S390_FEAT_KMC_TDEA_128, \
+    S390_FEAT_KMC_TDEA_192, \
+    S390_FEAT_KM_DEA, \
+    S390_FEAT_KM_TDEA_128, \
+    S390_FEAT_KM_TDEA_192, \
+    S390_FEAT_KIMD_SHA_1, \
+    S390_FEAT_KLMD_SHA_1
+
+#define S390_FEAT_GROUP_MSA_EXT_1 \
+    S390_FEAT_KMC_AES_128, \
+    S390_FEAT_KM_AES_128, \
+    S390_FEAT_KIMD_SHA_256, \
+    S390_FEAT_KLMD_SHA_256
+
+#define S390_FEAT_GROUP_MSA_EXT_2 \
+    S390_FEAT_KMC_AES_192, \
+    S390_FEAT_KMC_AES_256, \
+    S390_FEAT_KMC_PRNG, \
+    S390_FEAT_KM_AES_192, \
+    S390_FEAT_KM_AES_256, \
+    S390_FEAT_KIMD_SHA_512, \
+    S390_FEAT_KLMD_SHA_512
+
+#define S390_FEAT_GROUP_MSA_EXT_3 \
+    S390_FEAT_MSA_EXT_3, \
+    S390_FEAT_KMAC_EDEA, \
+    S390_FEAT_KMAC_ETDEA_128, \
+    S390_FEAT_KMAC_ETDEA_192, \
+    S390_FEAT_KMC_EAES_128, \
+    S390_FEAT_KMC_EAES_192, \
+    S390_FEAT_KMC_EAES_256, \
+    S390_FEAT_KMC_EDEA, \
+    S390_FEAT_KMC_ETDEA_128, \
+    S390_FEAT_KMC_ETDEA_192, \
+    S390_FEAT_KM_EDEA, \
+    S390_FEAT_KM_ETDEA_128, \
+    S390_FEAT_KM_ETDEA_192, \
+    S390_FEAT_KM_EAES_128, \
+    S390_FEAT_KM_EAES_192, \
+    S390_FEAT_KM_EAES_256, \
+    S390_FEAT_PCKMO_EDEA, \
+    S390_FEAT_PCKMO_ETDEA_128, \
+    S390_FEAT_PCKMO_ETDEA_256, \
+    S390_FEAT_PCKMO_AES_128, \
+    S390_FEAT_PCKMO_AES_192, \
+    S390_FEAT_PCKMO_AES_256
+
+#define S390_FEAT_GROUP_MSA_EXT_4 \
+    S390_FEAT_MSA_EXT_4, \
+    S390_FEAT_KMAC_AES_128, \
+    S390_FEAT_KMAC_AES_192, \
+    S390_FEAT_KMAC_AES_256, \
+    S390_FEAT_KMAC_EAES_128, \
+    S390_FEAT_KMAC_EAES_192, \
+    S390_FEAT_KMAC_EAES_256, \
+    S390_FEAT_KM_XTS_AES_128, \
+    S390_FEAT_KM_XTS_AES_256, \
+    S390_FEAT_KM_XTS_EAES_128, \
+    S390_FEAT_KM_XTS_EAES_256, \
+    S390_FEAT_KIMD_GHASH, \
+    S390_FEAT_KMCTR_DEA, \
+    S390_FEAT_KMCTR_TDEA_128, \
+    S390_FEAT_KMCTR_TDEA_192, \
+    S390_FEAT_KMCTR_EDEA, \
+    S390_FEAT_KMCTR_ETDEA_128, \
+    S390_FEAT_KMCTR_ETDEA_192, \
+    S390_FEAT_KMCTR_AES_128, \
+    S390_FEAT_KMCTR_AES_192, \
+    S390_FEAT_KMCTR_AES_256, \
+    S390_FEAT_KMCTR_EAES_128, \
+    S390_FEAT_KMCTR_EAES_192, \
+    S390_FEAT_KMCTR_EAES_256, \
+    S390_FEAT_KMF_DEA, \
+    S390_FEAT_KMF_TDEA_128, \
+    S390_FEAT_KMF_TDEA_192, \
+    S390_FEAT_KMF_EDEA, \
+    S390_FEAT_KMF_ETDEA_128, \
+    S390_FEAT_KMF_ETDEA_192, \
+    S390_FEAT_KMF_AES_128, \
+    S390_FEAT_KMF_AES_192, \
+    S390_FEAT_KMF_AES_256, \
+    S390_FEAT_KMF_EAES_128, \
+    S390_FEAT_KMF_EAES_192, \
+    S390_FEAT_KMF_EAES_256, \
+    S390_FEAT_KMO_DEA, \
+    S390_FEAT_KMO_TDEA_128, \
+    S390_FEAT_KMO_TDEA_192, \
+    S390_FEAT_KMO_EDEA, \
+    S390_FEAT_KMO_ETDEA_128, \
+    S390_FEAT_KMO_ETDEA_192, \
+    S390_FEAT_KMO_AES_128, \
+    S390_FEAT_KMO_AES_192, \
+    S390_FEAT_KMO_AES_256, \
+    S390_FEAT_KMO_EAES_128, \
+    S390_FEAT_KMO_EAES_192, \
+    S390_FEAT_KMO_EAES_256, \
+    S390_FEAT_PCC_CMAC_DEA, \
+    S390_FEAT_PCC_CMAC_TDEA_128, \
+    S390_FEAT_PCC_CMAC_TDEA_192, \
+    S390_FEAT_PCC_CMAC_ETDEA_128, \
+    S390_FEAT_PCC_CMAC_ETDEA_192, \
+    S390_FEAT_PCC_CMAC_TDEA, \
+    S390_FEAT_PCC_CMAC_AES_128, \
+    S390_FEAT_PCC_CMAC_AES_192, \
+    S390_FEAT_PCC_CMAC_AES_256, \
+    S390_FEAT_PCC_CMAC_EAES_128, \
+    S390_FEAT_PCC_CMAC_EAES_192, \
+    S390_FEAT_PCC_CMAC_EAES_256, \
+    S390_FEAT_PCC_XTS_AES_128, \
+    S390_FEAT_PCC_XTS_AES_256, \
+    S390_FEAT_PCC_XTS_EAES_128, \
+    S390_FEAT_PCC_XTS_EAES_256
+
+#define S390_FEAT_GROUP_MSA_EXT_5 \
+    S390_FEAT_MSA_EXT_5, \
+    S390_FEAT_PPNO_SHA_512_DRNG
+
+/* base features in order of release */
+static uint16_t base_GEN7_GA1[] = {
+    S390_FEAT_GROUP_PLO,
+    S390_FEAT_N3,
+    S390_FEAT_ZARCH,
+};
+#define base_GEN7_GA2 EmptyFeat
+#define base_GEN7_GA3 EmptyFeat
+static uint16_t base_GEN8_GA1[] = {
+    S390_FEAT_DAT_ENH_1,
+    S390_FEAT_EXTENDED_TRANSLATION_2,
+    S390_FEAT_GROUP_MSA,
+    S390_FEAT_LONG_DISPLACEMENT,
+    S390_FEAT_LONG_DISPLACEMENT_FAST,
+    S390_FEAT_HFP_MADDSUB,
+};
+#define base_GEN8_GA2 EmptyFeat
+#define base_GEN8_GA3 EmptyFeat
+#define base_GEN8_GA4 EmptyFeat
+#define base_GEN8_GA5 EmptyFeat
+static uint16_t base_GEN9_GA1[] = {
+    S390_FEAT_IDTE_SEGMENT,
+    S390_FEAT_ASN_LX_REUSE,
+    S390_FEAT_STFLE,
+    S390_FEAT_SENSE_RUNNING_STATUS,
+    S390_FEAT_EXTENDED_IMMEDIATE,
+    S390_FEAT_EXTENDED_TRANSLATION_3,
+    S390_FEAT_HFP_UNNORMALIZED_EXT,
+    S390_FEAT_ETF2_ENH,
+    S390_FEAT_STORE_CLOCK_FAST,
+    S390_FEAT_GROUP_TOD_CLOCK_STEERING,
+    S390_FEAT_ETF3_ENH,
+    S390_FEAT_DAT_ENH_2,
+};
+#define base_GEN9_GA2 EmptyFeat
+#define base_GEN9_GA3 EmptyFeat
+static uint16_t base_GEN10_GA1[] = {
+    S390_FEAT_CONDITIONAL_SSKE,
+    S390_FEAT_PARSING_ENH,
+    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
+    S390_FEAT_EXTRACT_CPU_TIME,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
+    S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
+    S390_FEAT_EXECUTE_EXT,
+    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
+    S390_FEAT_DFP,
+    S390_FEAT_DFP_FAST,
+    S390_FEAT_PFPO,
+};
+#define base_GEN10_GA2 EmptyFeat
+#define base_GEN10_GA3 EmptyFeat
+static uint16_t base_GEN11_GA1[] = {
+    S390_FEAT_NONQ_KEY_SETTING,
+    S390_FEAT_ENHANCED_MONITOR,
+    S390_FEAT_FLOATING_POINT_EXT,
+    S390_FEAT_SET_PROGRAM_PARAMETERS,
+    S390_FEAT_GEN11_ENH,
+    S390_FEAT_CMPSC_ENH,
+    S390_FEAT_INTERLOCKED_ACCESS_2,
+};
+#define base_GEN11_GA2 EmptyFeat
+static uint16_t base_GEN12_GA1[] = {
+    S390_FEAT_DFP_ZONED_CONVERSION,
+    S390_FEAT_GEN12_ENH,
+    S390_FEAT_LOCAL_TLB_CLEARING,
+};
+#define base_GEN12_GA2 EmptyFeat
+static uint16_t base_GEN13_GA1[] = {
+    S390_FEAT_GEN13_ENH,
+    S390_FEAT_DFP_PACKED_CONVERSION,
+    S390_FEAT_GROUP_GEN13_PTFF,
+};
+#define base_GEN13_GA2 EmptyFeat
+
+/* full features differing to the base in order of release */
+static uint16_t full_GEN7_GA1[] = {
+    S390_FEAT_SIE_F2,
+    S390_FEAT_SIE_SKEY,
+    S390_FEAT_SIE_GPERE,
+    S390_FEAT_SIE_IB,
+    S390_FEAT_SIE_CEI,
+};
+static uint16_t full_GEN7_GA2[] = {
+    S390_FEAT_EXTENDED_TRANSLATION_2,
+};
+static uint16_t full_GEN7_GA3[] = {
+    S390_FEAT_LONG_DISPLACEMENT,
+    S390_FEAT_SIE_SIIF,
+};
+static uint16_t full_GEN8_GA1[] = {
+    S390_FEAT_SIE_GSLS,
+    S390_FEAT_SIE_64BSCAO,
+};
+#define full_GEN8_GA2 EmptyFeat
+static uint16_t full_GEN8_GA3[] = {
+    S390_FEAT_ASN_LX_REUSE,
+    S390_FEAT_EXTENDED_TRANSLATION_3,
+};
+#define full_GEN8_GA4 EmptyFeat
+#define full_GEN8_GA5 EmptyFeat
+static uint16_t full_GEN9_GA1[] = {
+    S390_FEAT_GROUP_MSA_EXT_1,
+    S390_FEAT_CMM,
+    S390_FEAT_SIE_CMMA,
+};
+static uint16_t full_GEN9_GA2[] = {
+    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
+    S390_FEAT_EXTRACT_CPU_TIME,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
+    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
+    S390_FEAT_DFP,
+};
+static uint16_t full_GEN9_GA3[] = {
+    S390_FEAT_CONDITIONAL_SSKE,
+    S390_FEAT_PFPO,
+};
+static uint16_t full_GEN10_GA1[] = {
+    S390_FEAT_EDAT_1,
+    S390_FEAT_CONFIGURATION_TOPOLOGY,
+    S390_FEAT_GROUP_MSA_EXT_2,
+    S390_FEAT_ESOP,
+    S390_FEAT_SIE_PFMFI,
+    S390_FEAT_SIE_SIGPIF,
+};
+static uint16_t full_GEN10_GA2[] = {
+    S390_FEAT_SET_PROGRAM_PARAMETERS,
+    S390_FEAT_SIE_IBS,
+};
+static uint16_t full_GEN10_GA3[] = {
+    S390_FEAT_GROUP_MSA_EXT_3,
+};
+static uint16_t full_GEN11_GA1[] = {
+    S390_FEAT_IPTE_RANGE,
+    S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
+    S390_FEAT_GROUP_MSA_EXT_4,
+};
+#define full_GEN11_GA2 EmptyFeat
+static uint16_t full_GEN12_GA1[] = {
+    S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
+    S390_FEAT_TRANSACTIONAL_EXE,
+    S390_FEAT_RUNTIME_INSTRUMENTATION,
+    S390_FEAT_EDAT_2,
+};
+static uint16_t full_GEN12_GA2[] = {
+    S390_FEAT_GROUP_MSA_EXT_5,
+};
+static uint16_t full_GEN13_GA1[] = {
+    S390_FEAT_VECTOR,
+    S390_FEAT_STORE_CPU_COUNTER_MULTI,
+};
+#define full_GEN13_GA2 EmptyFeat
+
+/* default features differing to the base in order of release */
+#define default_GEN7_GA1 EmptyFeat
+#define default_GEN7_GA2 EmptyFeat
+#define default_GEN7_GA3 EmptyFeat
+#define default_GEN8_GA1 EmptyFeat
+#define default_GEN8_GA2 EmptyFeat
+#define default_GEN8_GA3 EmptyFeat
+#define default_GEN8_GA4 EmptyFeat
+#define default_GEN8_GA5 EmptyFeat
+static uint16_t default_GEN9_GA1[] = {
+    S390_FEAT_GROUP_MSA_EXT_1,
+};
+#define default_GEN9_GA2 EmptyFeat
+#define default_GEN9_GA3 EmptyFeat
+static uint16_t default_GEN10_GA1[] = {
+    S390_FEAT_EDAT_1,
+    S390_FEAT_GROUP_MSA_EXT_2,
+};
+#define default_GEN10_GA2 EmptyFeat
+#define default_GEN10_GA3 EmptyFeat
+static uint16_t default_GEN11_GA1[] = {
+    S390_FEAT_GROUP_MSA_EXT_3,
+    S390_FEAT_IPTE_RANGE,
+    S390_FEAT_ACCESS_EXCEPTION_FS_INDICATION,
+    S390_FEAT_GROUP_MSA_EXT_4,
+};
+#define default_GEN11_GA2 EmptyFeat
+static uint16_t default_GEN12_GA1[] = {
+    S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE,
+    S390_FEAT_TRANSACTIONAL_EXE,
+    S390_FEAT_RUNTIME_INSTRUMENTATION,
+    S390_FEAT_EDAT_2,
+};
+#define default_GEN12_GA2 EmptyFeat
+static uint16_t default_GEN13_GA1[] = {
+    S390_FEAT_GROUP_MSA_EXT_5,
+    S390_FEAT_VECTOR,
+};
+#define default_GEN13_GA2 EmptyFeat
+
+/****** END FEATURE DEFS ******/
+
+#define _YEARS  "2016"
+#define _NAME_H "TARGET_S390X_GEN_FEATURES_H"
+
+#define CPU_FEAT_INITIALIZER(_name)                    \
+    {                                                  \
+        .name = "S390_FEAT_LIST_" #_name,              \
+        .base_bits =                                   \
+            { .data = base_##_name,                    \
+              .len = ARRAY_SIZE(base_##_name) },       \
+        .default_bits =                                \
+            { .data = default_##_name,                 \
+              .len = ARRAY_SIZE(default_##_name) },    \
+        .full_bits =                                   \
+            { .data = full_##_name,                    \
+              .len = ARRAY_SIZE(full_##_name) },       \
+    }
+
+typedef struct BitSpec {
+    uint16_t *data;
+    uint32_t len;
+} BitSpec;
+
+typedef struct {
+    const char *name;
+    BitSpec base_bits;
+    BitSpec default_bits;
+    BitSpec full_bits;
+} CpuFeatDefSpec;
+
+static uint16_t EmptyFeat[] = {};
+
+/*******************************
+ * processor GA series
+ *******************************/
+static CpuFeatDefSpec CpuFeatDef[] = {
+    CPU_FEAT_INITIALIZER(GEN7_GA1),
+    CPU_FEAT_INITIALIZER(GEN7_GA2),
+    CPU_FEAT_INITIALIZER(GEN7_GA3),
+    CPU_FEAT_INITIALIZER(GEN8_GA1),
+    CPU_FEAT_INITIALIZER(GEN8_GA2),
+    CPU_FEAT_INITIALIZER(GEN8_GA3),
+    CPU_FEAT_INITIALIZER(GEN8_GA4),
+    CPU_FEAT_INITIALIZER(GEN8_GA5),
+    CPU_FEAT_INITIALIZER(GEN9_GA1),
+    CPU_FEAT_INITIALIZER(GEN9_GA2),
+    CPU_FEAT_INITIALIZER(GEN9_GA3),
+    CPU_FEAT_INITIALIZER(GEN10_GA1),
+    CPU_FEAT_INITIALIZER(GEN10_GA2),
+    CPU_FEAT_INITIALIZER(GEN10_GA3),
+    CPU_FEAT_INITIALIZER(GEN11_GA1),
+    CPU_FEAT_INITIALIZER(GEN11_GA2),
+    CPU_FEAT_INITIALIZER(GEN12_GA1),
+    CPU_FEAT_INITIALIZER(GEN12_GA2),
+    CPU_FEAT_INITIALIZER(GEN13_GA1),
+    CPU_FEAT_INITIALIZER(GEN13_GA2),
+};
+
+static void set_bits(uint64_t list[], BitSpec bits)
+{
+    uint32_t i;
+
+    for (i = 0; i < bits.len; i++) {
+        list[bits.data[i] / 64] |= 1ULL << (bits.data[i] % 64);
+    }
+}
+
+static void print_feature_defs(void)
+{
+    uint64_t base_feat[S390_FEAT_MAX / 64 + 1] = {};
+    uint64_t default_feat[S390_FEAT_MAX / 64 + 1] = {};
+    uint64_t full_feat[S390_FEAT_MAX / 64 + 1] = {};
+    int i, j;
+
+    printf("\n/* CPU model feature list data */\n");
+
+    for (i = 0; i < ARRAY_SIZE(CpuFeatDef); i++) {
+        set_bits(base_feat, CpuFeatDef[i].base_bits);
+        /* add the base to the default features */
+        set_bits(default_feat, CpuFeatDef[i].base_bits);
+        set_bits(default_feat, CpuFeatDef[i].default_bits);
+        /* add the base to the full features */
+        set_bits(full_feat, CpuFeatDef[i].base_bits);
+        set_bits(full_feat, CpuFeatDef[i].full_bits);
+
+        printf("#define %s_BASE\t", CpuFeatDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(base_feat); j++) {
+            printf("0x%016"PRIx64"UL", base_feat[j]);
+            if (j < ARRAY_SIZE(base_feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+        printf("#define %s_DEFAULT\t", CpuFeatDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(default_feat); j++) {
+            printf("0x%016"PRIx64"UL", default_feat[j]);
+            if (j < ARRAY_SIZE(default_feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+        printf("#define %s_FULL\t\t", CpuFeatDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(full_feat); j++) {
+            printf("0x%016"PRIx64"UL", full_feat[j]);
+            if (j < ARRAY_SIZE(full_feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+    }
+}
+
+int main(int argc, char *argv[])
+{
+    printf("/*\n"
+           " * AUTOMATICALLY GENERATED, DO NOT MODIFY HERE, EDIT\n"
+           " * SOURCE FILE \"%s\" INSTEAD.\n"
+           " *\n"
+           " * Copyright %s IBM Corp.\n"
+           " *\n"
+           " * This work is licensed under the terms of the GNU GPL, "
+           "version 2 or (at\n * your option) any later version. See "
+           "the COPYING file in the top-level\n * directory.\n"
+           " */\n\n"
+           "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
+    print_feature_defs();
+    printf("\n#endif\n");
+    return 0;
+}
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 06/29] s390x/cpumodel: generate CPU feature group lists
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (4 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 05/29] s390x/cpumodel: generate CPU feature lists for CPU models David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 07/29] s390x/cpumodel: introduce CPU feature group definitions David Hildenbrand
                   ` (23 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Feature groups will be very helpful to reduce the amount of features
typically available in sane configurations. E.g. the MSA facilities
introduced loads of subfunctions, which could - in theory - go away
in the future, but we want to avoid reporting hundrets of features to
the user if usually all of them are in place.

Groups only contain features that were introduced in one shot, not just
random features. Therefore, groups can never change. This is an important
property regarding migration.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/gen-features.c | 80 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/target-s390x/gen-features.c b/target-s390x/gen-features.c
index 3a7c373..d4f4b29 100644
--- a/target-s390x/gen-features.c
+++ b/target-s390x/gen-features.c
@@ -178,6 +178,35 @@
     S390_FEAT_MSA_EXT_5, \
     S390_FEAT_PPNO_SHA_512_DRNG
 
+/* cpu feature groups */
+static uint16_t group_PLO[] = {
+    S390_FEAT_GROUP_PLO,
+};
+static uint16_t group_TOD_CLOCK_STEERING[] = {
+    S390_FEAT_GROUP_TOD_CLOCK_STEERING,
+};
+static uint16_t group_GEN13_PTFF[] = {
+    S390_FEAT_GROUP_GEN13_PTFF,
+};
+static uint16_t group_MSA[] = {
+    S390_FEAT_GROUP_MSA,
+};
+static uint16_t group_MSA_EXT_1[] = {
+    S390_FEAT_GROUP_MSA_EXT_1,
+};
+static uint16_t group_MSA_EXT_2[] = {
+    S390_FEAT_GROUP_MSA_EXT_2,
+};
+static uint16_t group_MSA_EXT_3[] = {
+    S390_FEAT_GROUP_MSA_EXT_3,
+};
+static uint16_t group_MSA_EXT_4[] = {
+    S390_FEAT_GROUP_MSA_EXT_4,
+};
+static uint16_t group_MSA_EXT_5[] = {
+    S390_FEAT_GROUP_MSA_EXT_5,
+};
+
 /* base features in order of release */
 static uint16_t base_GEN7_GA1[] = {
     S390_FEAT_GROUP_PLO,
@@ -430,6 +459,34 @@ static CpuFeatDefSpec CpuFeatDef[] = {
     CPU_FEAT_INITIALIZER(GEN13_GA2),
 };
 
+#define FEAT_GROUP_INITIALIZER(_name)                  \
+    {                                                  \
+        .name = "S390_FEAT_GROUP_LIST_" #_name,        \
+        .bits =                                        \
+            { .data = group_##_name,                   \
+              .len = ARRAY_SIZE(group_##_name) },      \
+    }
+
+typedef struct {
+    const char *name;
+    BitSpec bits;
+} FeatGroupDefSpec;
+
+/*******************************
+ * feature groups
+ *******************************/
+static FeatGroupDefSpec FeatGroupDef[] = {
+    FEAT_GROUP_INITIALIZER(PLO),
+    FEAT_GROUP_INITIALIZER(TOD_CLOCK_STEERING),
+    FEAT_GROUP_INITIALIZER(GEN13_PTFF),
+    FEAT_GROUP_INITIALIZER(MSA),
+    FEAT_GROUP_INITIALIZER(MSA_EXT_1),
+    FEAT_GROUP_INITIALIZER(MSA_EXT_2),
+    FEAT_GROUP_INITIALIZER(MSA_EXT_3),
+    FEAT_GROUP_INITIALIZER(MSA_EXT_4),
+    FEAT_GROUP_INITIALIZER(MSA_EXT_5),
+};
+
 static void set_bits(uint64_t list[], BitSpec bits)
 {
     uint32_t i;
@@ -487,6 +544,28 @@ static void print_feature_defs(void)
     }
 }
 
+static void print_feature_group_defs(void)
+{
+    int i, j;
+
+    printf("\n/* CPU feature group list data */\n");
+
+    for (i = 0; i < ARRAY_SIZE(FeatGroupDef); i++) {
+        uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
+
+        set_bits(feat, FeatGroupDef[i].bits);
+        printf("#define %s\t", FeatGroupDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(feat); j++) {
+            printf("0x%016"PRIx64"UL", feat[j]);
+            if (j < ARRAY_SIZE(feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+    }
+}
+
 int main(int argc, char *argv[])
 {
     printf("/*\n"
@@ -501,6 +580,7 @@ int main(int argc, char *argv[])
            " */\n\n"
            "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
     print_feature_defs();
+    print_feature_group_defs();
     printf("\n#endif\n");
     return 0;
 }
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 07/29] s390x/cpumodel: introduce CPU feature group definitions
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (5 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 06/29] s390x/cpumodel: generate CPU feature group lists David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 08/29] s390x/cpumodel: register defined CPU models as subclasses David Hildenbrand
                   ` (22 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's use the generated groups to create feature group representations for
the user. These groups can later be used to enable/disable multiple
features in one shot and will be used to reduce the amount of reported
features to the user if all subfeatures are in place.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu_features.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/cpu_features.h | 23 +++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/target-s390x/cpu_features.c b/target-s390x/cpu_features.c
index 5aa5981..a8ca9ca 100644
--- a/target-s390x/cpu_features.c
+++ b/target-s390x/cpu_features.c
@@ -12,6 +12,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu_features.h"
+#include "gen-features.h"
 
 #define FEAT_INIT(_name, _type, _bit, _desc) \
     {                                                \
@@ -321,14 +322,55 @@ void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
     }
 }
 
-void s390_feat_bitmap_to_ascii(const S390FeatBitmap bitmap, void *opaque,
+void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque,
                                void (*fn)(const char *name, void *opaque))
 {
+    S390FeatBitmap bitmap, tmp;
+    S390FeatGroup group;
     S390Feat feat;
 
+    bitmap_copy(bitmap, features, S390_FEAT_MAX);
+
+    /* process whole groups first */
+    for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
+        const S390FeatGroupDef *def = s390_feat_group_def(group);
+
+        bitmap_and(tmp, bitmap, def->feat, S390_FEAT_MAX);
+        if (bitmap_equal(tmp, def->feat, S390_FEAT_MAX)) {
+            bitmap_andnot(bitmap, bitmap, def->feat, S390_FEAT_MAX);
+            fn(def->name, opaque);
+        }
+    }
+
+    /* report leftovers as separate features */
     feat = find_first_bit(bitmap, S390_FEAT_MAX);
     while (feat < S390_FEAT_MAX) {
         fn(s390_feat_def(feat)->name, opaque);
         feat = find_next_bit(bitmap, S390_FEAT_MAX, feat + 1);
     };
 }
+
+#define FEAT_GROUP_INIT(_name, _group, _desc)        \
+    {                                                \
+        .name = _name,                               \
+        .desc = _desc,                               \
+        .feat = { S390_FEAT_GROUP_LIST_ ## _group }, \
+    }
+
+/* indexed by feature group number for easy lookup */
+static const S390FeatGroupDef s390_feature_groups[] = {
+    FEAT_GROUP_INIT("plo", PLO, "Perform-locked-operation facility"),
+    FEAT_GROUP_INIT("tods", TOD_CLOCK_STEERING, "Tod-clock-steering facility"),
+    FEAT_GROUP_INIT("gen13ptff", GEN13_PTFF, "PTFF enhancements introduced with z13"),
+    FEAT_GROUP_INIT("msa", MSA, "Message-security-assist facility"),
+    FEAT_GROUP_INIT("msa1", MSA_EXT_1, "Message-security-assist-extension 1 facility"),
+    FEAT_GROUP_INIT("msa2", MSA_EXT_2, "Message-security-assist-extension 2 facility"),
+    FEAT_GROUP_INIT("msa3", MSA_EXT_3, "Message-security-assist-extension 3 facility"),
+    FEAT_GROUP_INIT("msa4", MSA_EXT_4, "Message-security-assist-extension 4 facility"),
+    FEAT_GROUP_INIT("msa5", MSA_EXT_5, "Message-security-assist-extension 5 facility"),
+};
+
+const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group)
+{
+    return &s390_feature_groups[group];
+}
diff --git a/target-s390x/cpu_features.h b/target-s390x/cpu_features.h
index 485446c..e40a636 100644
--- a/target-s390x/cpu_features.h
+++ b/target-s390x/cpu_features.h
@@ -273,6 +273,29 @@ void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type,
 void s390_feat_bitmap_to_ascii(const S390FeatBitmap features, void *opaque,
                                void (*fn)(const char *name, void *opaque));
 
+/* static groups that will never change */
+typedef enum {
+    S390_FEAT_GROUP_PLO,
+    S390_FEAT_GROUP_TOD_CLOCK_STEERING,
+    S390_FEAT_GROUP_GEN13_PTFF_ENH,
+    S390_FEAT_GROUP_MSA,
+    S390_FEAT_GROUP_MSA_EXT_1,
+    S390_FEAT_GROUP_MSA_EXT_2,
+    S390_FEAT_GROUP_MSA_EXT_3,
+    S390_FEAT_GROUP_MSA_EXT_4,
+    S390_FEAT_GROUP_MSA_EXT_5,
+    S390_FEAT_GROUP_MAX,
+} S390FeatGroup;
+
+/* Definition of a CPU feature group */
+typedef struct {
+    const char *name;       /* name exposed to the user */
+    const char *desc;       /* description exposed to the user */
+    S390FeatBitmap feat;    /* features contained in the group */
+} S390FeatGroupDef;
+
+const S390FeatGroupDef *s390_feat_group_def(S390FeatGroup group);
+
 #define BE_BIT_NR(BIT) (BIT ^ (BITS_PER_LONG - 1))
 #define BE_BIT(BIT) (1ULL < BE_BIT_NR(BIT))
 
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 08/29] s390x/cpumodel: register defined CPU models as subclasses
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (6 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 07/29] s390x/cpumodel: introduce CPU feature group definitions David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 09/29] s390x/cpumodel: store the CPU model in the CPU instance David Hildenbrand
                   ` (21 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

This patch adds the CPU model definitions that are known on s390x -
like z900, zBC12 or z13. For each definition, introduce two CPU models:

1. Base model (e.g. z13-base): Minimum feature set we expect to be around
   on all z13 systems. These models are migration-safe and will never
   change.
2. Flexible models (e.g. z13): Models that can change between QEMU versions
   and will be extended over time as we implement further features that
   are already part of such a model in real hardware of certain
   configurations.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu-qom.h    |   2 +
 target-s390x/cpu_models.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h |  36 +++++++++++++++
 3 files changed, 151 insertions(+)
 create mode 100644 target-s390x/cpu_models.h

diff --git a/target-s390x/cpu-qom.h b/target-s390x/cpu-qom.h
index bb993d4..4e936e7 100644
--- a/target-s390x/cpu-qom.h
+++ b/target-s390x/cpu-qom.h
@@ -21,6 +21,7 @@
 #define QEMU_S390_CPU_QOM_H
 
 #include "qom/cpu.h"
+#include "cpu_models.h"
 
 #define TYPE_S390_CPU "s390-cpu"
 
@@ -45,6 +46,7 @@ typedef struct S390CPUClass {
     /*< private >*/
     CPUClass parent_class;
     /*< public >*/
+    const S390CPUDef *cpu_def;
     bool kvm_required;
     bool is_static;
     bool is_migration_safe;
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index c875719..2bd5048 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -12,11 +12,66 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "gen-features.h"
 #include "qapi/error.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
 
+#define CPUDEF_INIT(_type, _gen, _ec_ga, _mha_pow, _hmfai, _name, _desc) \
+    {                                                             \
+        .name = _name,                                            \
+        .type = _type,                                            \
+        .gen = _gen,                                              \
+        .ec_ga = _ec_ga,                                          \
+        .mha_pow = _mha_pow,                                      \
+        .hmfai = _hmfai,                                          \
+        .desc = _desc,                                            \
+        .base_feat = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _BASE },  \
+        .default_feat = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _DEFAULT },  \
+        .full_feat = { S390_FEAT_LIST_GEN ## _gen ## _GA ## _ec_ga ## _FULL },  \
+    }
+
+/*
+ * CPU definiton list in order of release. For now, base features of a
+ * following release are always a subset of base features of the previous
+ * release. Same is correct for the other feature sets.
+ * A BC release always follows the corresponding EC release.
+ */
+static const S390CPUDef s390_cpu_defs[] = {
+    CPUDEF_INIT(0x2064, 7, 1, 38, 0x00000000U, "z900", "IBM zSeries 900 GA1"),
+    CPUDEF_INIT(0x2064, 7, 2, 38, 0x00000000U, "z900.2", "IBM zSeries 900 GA2"),
+    CPUDEF_INIT(0x2064, 7, 3, 38, 0x00000000U, "z900.3", "IBM zSeries 900 GA3"),
+    CPUDEF_INIT(0x2066, 7, 3, 38, 0x00000000U, "z800", "IBM zSeries 800 GA1"),
+    CPUDEF_INIT(0x2084, 8, 1, 38, 0x00000000U, "z990", "IBM zSeries 990 GA1"),
+    CPUDEF_INIT(0x2084, 8, 2, 38, 0x00000000U, "z990.2", "IBM zSeries 990 GA2"),
+    CPUDEF_INIT(0x2084, 8, 3, 38, 0x00000000U, "z990.3", "IBM zSeries 990 GA3"),
+    CPUDEF_INIT(0x2086, 8, 3, 38, 0x00000000U, "z890", "IBM zSeries 880 GA1"),
+    CPUDEF_INIT(0x2084, 8, 4, 38, 0x00000000U, "z990.4", "IBM zSeries 990 GA4"),
+    CPUDEF_INIT(0x2086, 8, 4, 38, 0x00000000U, "z890.2", "IBM zSeries 880 GA2"),
+    CPUDEF_INIT(0x2084, 8, 5, 38, 0x00000000U, "z990.5", "IBM zSeries 990 GA5"),
+    CPUDEF_INIT(0x2086, 8, 5, 38, 0x00000000U, "z890.3", "IBM zSeries 880 GA3"),
+    CPUDEF_INIT(0x2094, 9, 1, 40, 0x00000000U, "z9EC", "IBM System z9 EC GA1"),
+    CPUDEF_INIT(0x2094, 9, 2, 40, 0x00000000U, "z9EC.2", "IBM System z9 EC GA2"),
+    CPUDEF_INIT(0x2096, 9, 2, 40, 0x00000000U, "z9BC", "IBM System z9 BC GA1"),
+    CPUDEF_INIT(0x2094, 9, 3, 40, 0x00000000U, "z9EC.3", "IBM System z9 EC GA3"),
+    CPUDEF_INIT(0x2096, 9, 3, 40, 0x00000000U, "z9BC.2", "IBM System z9 BC GA2"),
+    CPUDEF_INIT(0x2097, 10, 1, 43, 0x00000000U, "z10EC", "IBM System z10 EC GA1"),
+    CPUDEF_INIT(0x2097, 10, 2, 43, 0x00000000U, "z10EC.2", "IBM System z10 EC GA2"),
+    CPUDEF_INIT(0x2098, 10, 2, 43, 0x00000000U, "z10BC", "IBM System z10 BC GA1"),
+    CPUDEF_INIT(0x2097, 10, 3, 43, 0x00000000U, "z10EC.3", "IBM System z10 EC GA3"),
+    CPUDEF_INIT(0x2098, 10, 3, 43, 0x00000000U, "z10BC.2", "IBM System z10 BC GA2"),
+    CPUDEF_INIT(0x2817, 11, 1, 44, 0x08000000U, "z196", "IBM zEnterprise 196 GA1"),
+    CPUDEF_INIT(0x2817, 11, 2, 44, 0x08000000U, "z196.2", "IBM zEnterprise 196 GA2"),
+    CPUDEF_INIT(0x2818, 11, 2, 44, 0x08000000U, "z114", "IBM zEnterprise 114 GA1"),
+    CPUDEF_INIT(0x2827, 12, 1, 44, 0x08000000U, "zEC12", "IBM zEnterprise EC12 GA1"),
+    CPUDEF_INIT(0x2827, 12, 2, 44, 0x08000000U, "zEC12.2", "IBM zEnterprise EC12 GA2"),
+    CPUDEF_INIT(0x2828, 12, 2, 44, 0x08000000U, "zBC12", "IBM zEnterprise BC12 GA1"),
+    CPUDEF_INIT(0x2964, 13, 1, 47, 0x08000000U, "z13", "IBM z13 GA1"),
+    CPUDEF_INIT(0x2964, 13, 2, 47, 0x08000000U, "z13.2", "IBM z13 GA2"),
+    CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
+};
+
 struct S390PrintCpuListInfo {
     FILE *f;
     fprintf_function print;
@@ -97,6 +152,10 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
     }
 }
 
+static void s390_cpu_model_initfn(Object *obj)
+{
+}
+
 #ifdef CONFIG_KVM
 static void s390_host_cpu_model_initfn(Object *obj)
 {
@@ -146,6 +205,27 @@ static void s390_host_cpu_model_class_init(ObjectClass *oc, void *data)
 }
 #endif
 
+static void s390_base_cpu_model_class_init(ObjectClass *oc, void *data)
+{
+    S390CPUClass *xcc = S390_CPU_CLASS(oc);
+
+    /* all base models are migration safe */
+    xcc->cpu_def = (const S390CPUDef *) data;
+    xcc->is_migration_safe = true;
+    xcc->is_static = true;
+    xcc->desc = xcc->cpu_def->desc;
+}
+
+static void s390_cpu_model_class_init(ObjectClass *oc, void *data)
+{
+    S390CPUClass *xcc = S390_CPU_CLASS(oc);
+
+    /* model that can change between QEMU versions */
+    xcc->cpu_def = (const S390CPUDef *) data;
+    xcc->is_migration_safe = true;
+    xcc->desc = xcc->cpu_def->desc;
+}
+
 static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data)
 {
     S390CPUClass *xcc = S390_CPU_CLASS(oc);
@@ -164,6 +244,12 @@ static char *s390_cpu_type_name(const char *model_name)
     return g_strdup_printf(S390_CPU_TYPE_NAME("%s"), model_name);
 }
 
+/* Generate type name for a base cpu model. Caller has to free the string. */
+static char *s390_base_cpu_type_name(const char *model_name)
+{
+    return g_strdup_printf(S390_CPU_TYPE_NAME("%s-base"), model_name);
+}
+
 ObjectClass *s390_cpu_class_by_name(const char *name)
 {
     char *typename = s390_cpu_type_name(name);
@@ -194,6 +280,33 @@ static const TypeInfo host_s390_cpu_type_info = {
 
 static void register_types(void)
 {
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
+        char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
+        TypeInfo ti_base = {
+            .name = base_name,
+            .parent = TYPE_S390_CPU,
+            .instance_init = s390_cpu_model_initfn,
+            .instance_finalize = s390_cpu_model_finalize,
+            .class_init = s390_base_cpu_model_class_init,
+            .class_data = (void *) &s390_cpu_defs[i],
+        };
+        char *name = s390_cpu_type_name(s390_cpu_defs[i].name);
+        TypeInfo ti = {
+            .name = name,
+            .parent = TYPE_S390_CPU,
+            .instance_init = s390_cpu_model_initfn,
+            .instance_finalize = s390_cpu_model_finalize,
+            .class_init = s390_cpu_model_class_init,
+            .class_data = (void *) &s390_cpu_defs[i],
+        };
+
+        type_register_static(&ti_base);
+        type_register_static(&ti);
+        g_free(base_name);
+        g_free(name);
+    }
     type_register_static(&qemu_s390_cpu_type_info);
 #ifdef CONFIG_KVM
     type_register_static(&host_s390_cpu_type_info);
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
new file mode 100644
index 0000000..13f7217
--- /dev/null
+++ b/target-s390x/cpu_models.h
@@ -0,0 +1,36 @@
+/*
+ * CPU models for s390x
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): David Hildenbrand <dahi@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#ifndef TARGET_S390X_CPU_MODELS_H
+#define TARGET_S390X_CPU_MODELS_H
+
+#include "cpu_features.h"
+#include "qom/cpu.h"
+
+/* static CPU definition */
+typedef struct S390CPUDef {
+    const char *name;       /* name exposed to the user */
+    const char *desc;       /* description exposed to the user */
+    uint8_t gen;            /* hw generation identification */
+    uint16_t type;          /* cpu type identification */
+    uint8_t ec_ga;          /* EC GA version (on which also the BC is based) */
+    uint8_t mha_pow;        /* Maximum Host Adress Power, mha = 2^pow-1 */
+    uint32_t hmfai;         /* hypervisor-managed facilities */
+    /* base/min features, must never be changed between QEMU versions */
+    S390FeatBitmap base_feat;
+    /* deafault features, QEMU version specific */
+    S390FeatBitmap default_feat;
+    /* max allowed features, QEMU version specific */
+    S390FeatBitmap full_feat;
+} S390CPUDef;
+
+#endif /* TARGET_S390X_CPU_MODELS_H */
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 09/29] s390x/cpumodel: store the CPU model in the CPU instance
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (7 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 08/29] s390x/cpumodel: register defined CPU models as subclasses David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 10/29] s390x/cpumodel: expose features and feature groups as properties David Hildenbrand
                   ` (20 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

A CPU model consists of a CPU definition, to which delta changes are
applied - features added or removed (e.g. z13-base,vx=on). In addition,
certain properties (e.g. cpu id) can later on change during migration
but belong into the CPU model. This data will later be filled from the
host model in the KVM case.

Therefore, store the configured CPU model inside the CPU instance, so
we can later on perform delta changes using properties.

For the "qemu" model, we emulate in TCG a z900. "host" will be
uninitialized (cpu->model == NULL) unless we have CPU model support in KVM
later on. The other models are all initialized from their definitions.
Only the "host" model can have a cpu->model == NULL.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu.h        |  1 +
 target-s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
 target-s390x/cpu_models.h | 10 ++++++++++
 3 files changed, 37 insertions(+)

diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 075bb37..3b76654 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -188,6 +188,7 @@ struct S390CPU {
 
     CPUS390XState env;
     int64_t id;
+    S390CPUModel *model;
     /* needed for live migration */
     void *irqstate;
     uint32_t irqstate_saved_size;
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 2bd5048..bd88a9e 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -154,6 +154,21 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
 
 static void s390_cpu_model_initfn(Object *obj)
 {
+    S390CPU *cpu = S390_CPU(obj);
+    S390CPUClass *xcc = S390_CPU_GET_CLASS(cpu);
+
+    cpu->model = g_malloc0(sizeof(*cpu->model));
+    /* copy the model, so we can modify it */
+    cpu->model->def = xcc->cpu_def;
+    if (xcc->is_static) {
+        /* base model - features will never change */
+        bitmap_copy(cpu->model->features, cpu->model->def->base_feat,
+                    S390_FEAT_MAX);
+    } else {
+        /* latest model - features can change */
+        bitmap_copy(cpu->model->features,
+                    cpu->model->def->default_feat, S390_FEAT_MAX);
+    }
 }
 
 #ifdef CONFIG_KVM
@@ -164,10 +179,21 @@ static void s390_host_cpu_model_initfn(Object *obj)
 
 static void s390_qemu_cpu_model_initfn(Object *obj)
 {
+    S390CPU *cpu = S390_CPU(obj);
+
+    cpu->model = g_malloc0(sizeof(*cpu->model));
+    /* TCG emulates a z900 */
+    cpu->model->def = &s390_cpu_defs[0];
+    bitmap_copy(cpu->model->features, cpu->model->def->default_feat,
+                S390_FEAT_MAX);
 }
 
 static void s390_cpu_model_finalize(Object *obj)
 {
+    S390CPU *cpu = S390_CPU(obj);
+
+    g_free(cpu->model);
+    cpu->model = NULL;
 }
 
 static bool get_is_migration_safe(Object *obj, Error **errp)
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index 13f7217..244256b 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -33,4 +33,14 @@ typedef struct S390CPUDef {
     S390FeatBitmap full_feat;
 } S390CPUDef;
 
+/* CPU model based on a CPU definition */
+typedef struct S390CPUModel {
+    const S390CPUDef *def;
+    S390FeatBitmap features;
+    /* values copied from the "host" model, can change during migration */
+    uint16_t lowest_ibc;    /* lowest IBC that the hardware supports */
+    uint32_t cpu_id;        /* CPU id */
+    uint8_t cpu_ver;        /* CPU version, usually "ff" for kvm */
+} S390CPUModel;
+
 #endif /* TARGET_S390X_CPU_MODELS_H */
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 10/29] s390x/cpumodel: expose features and feature groups as properties
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (8 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 09/29] s390x/cpumodel: store the CPU model in the CPU instance David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 11/29] s390x/cpumodel: let the CPU model handle feature checks David Hildenbrand
                   ` (19 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's add all features and feature groups as properties to all CPU models.
If the "host" CPU model is unknown, we can neither query nor change
features. KVM will just continue to work like it did until now.

We will not allow to enable features that were not part of the original
CPU model, because that could collide with the IBC in KVM.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu.c        |   1 +
 target-s390x/cpu.h        |   1 +
 target-s390x/cpu_models.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index d7d0b62..2f3c8e2 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -291,6 +291,7 @@ static void s390_cpu_initfn(Object *obj)
     cs->exception_index = EXCP_HLT;
     object_property_add(OBJECT(cpu), "id", "int64_t", s390x_cpu_get_id,
                         s390x_cpu_set_id, NULL, NULL, NULL);
+    s390_cpu_model_register_props(obj);
 #if !defined(CONFIG_USER_ONLY)
     qemu_get_timedate(&tm, 0);
     env->tod_offset = TOD_UNIX_EPOCH +
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 3b76654..d03f0f1 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -632,6 +632,7 @@ extern void subsystem_reset(void);
 
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 #define cpu_list s390_cpu_list
+void s390_cpu_model_register_props(Object *obj);
 void s390_cpu_model_class_register_props(ObjectClass *oc);
 void s390_realize_cpu_model(CPUState *cs, Error **errp);
 ObjectClass *s390_cpu_class_by_name(const char *name);
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index bd88a9e..9532b46 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -14,6 +14,7 @@
 #include "cpu.h"
 #include "gen-features.h"
 #include "qapi/error.h"
+#include "qapi/visitor.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
@@ -103,8 +104,24 @@ void s390_cpu_list(FILE *f, fprintf_function print)
         f = f,
         print = print,
     };
+    S390FeatGroup group;
+    S390Feat feat;
 
     object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);
+
+    (*print)(f, "\nRecognized feature flags:\n");
+    for (feat = 0; feat < S390_FEAT_MAX; feat++) {
+        const S390FeatDef *def = s390_feat_def(feat);
+
+        (*print)(f, "%-20s %-50s\n", def->name, def->desc);
+    }
+
+    (*print)(f, "\nRecognized feature groups:\n");
+    for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
+        const S390FeatGroupDef *def = s390_feat_group_def(group);
+
+        (*print)(f, "%-20s %-50s\n", def->name, def->desc);
+    }
 }
 
 #ifndef CONFIG_USER_ONLY
@@ -152,6 +169,138 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
     }
 }
 
+static void get_feature(Object *obj, Visitor *v, const char *name,
+                        void *opaque, Error **errp)
+{
+    S390Feat feat = (S390Feat) opaque;
+    S390CPU *cpu = S390_CPU(obj);
+    bool value;
+
+    if (!cpu->model) {
+        error_setg(errp, "Details about the host CPU model are not available, "
+                         "features cannot be queried.");
+        return;
+    }
+
+    value = test_bit(feat, cpu->model->features);
+    visit_type_bool(v, name, &value, errp);
+}
+
+static void set_feature(Object *obj, Visitor *v, const char *name,
+                        void *opaque, Error **errp)
+{
+    S390Feat feat = (S390Feat) opaque;
+    DeviceState *dev = DEVICE(obj);
+    S390CPU *cpu = S390_CPU(obj);
+    bool value;
+
+    if (dev->realized) {
+        error_setg(errp, "Attempt to set property '%s' on '%s' after "
+                   "it was realized", name, object_get_typename(obj));
+        return;
+    } else if (!cpu->model) {
+        error_setg(errp, "Details about the host CPU model are not available, "
+                         "features cannot be changed.");
+        return;
+    }
+
+    visit_type_bool(v, name, &value, errp);
+    if (*errp) {
+        return;
+    }
+    if (value) {
+        if (!test_bit(feat, cpu->model->def->full_feat)) {
+            error_setg(errp, "Feature '%s' is not available for CPU model '%s',"
+                       " it was introduced with later models.",
+                       name, cpu->model->def->name);
+            return;
+        }
+        set_bit(feat, cpu->model->features);
+    } else {
+        clear_bit(feat, cpu->model->features);
+    }
+}
+
+static void get_feature_group(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp)
+{
+    S390FeatGroup group = (S390FeatGroup) opaque;
+    const S390FeatGroupDef *def = s390_feat_group_def(group);
+    S390CPU *cpu = S390_CPU(obj);
+    S390FeatBitmap tmp;
+    bool value;
+
+    if (!cpu->model) {
+        error_setg(errp, "Details about the host CPU model are not available, "
+                         "features cannot be queried.");
+        return;
+    }
+
+    /* a group is enabled if all features are enabled */
+    bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX);
+    value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX);
+    visit_type_bool(v, name, &value, errp);
+}
+
+static void set_feature_group(Object *obj, Visitor *v, const char *name,
+                              void *opaque, Error **errp)
+{
+    S390FeatGroup group = (S390FeatGroup) opaque;
+    const S390FeatGroupDef *def = s390_feat_group_def(group);
+    DeviceState *dev = DEVICE(obj);
+    S390CPU *cpu = S390_CPU(obj);
+    bool value;
+
+    if (dev->realized) {
+        error_setg(errp, "Attempt to set property '%s' on '%s' after "
+                   "it was realized", name, object_get_typename(obj));
+        return;
+    } else if (!cpu->model) {
+        error_setg(errp, "Details about the host CPU model are not available, "
+                         "features cannot be changed.");
+        return;
+    }
+
+    visit_type_bool(v, name, &value, errp);
+    if (*errp) {
+        return;
+    }
+    if (value) {
+        /* groups are added in one shot, so an intersect is sufficient */
+        if (!bitmap_intersects(def->feat, cpu->model->def->full_feat,
+                               S390_FEAT_MAX)) {
+            error_setg(errp, "Group '%s' is not available for CPU model '%s',"
+                       " it was introduced with later models.",
+                       name, cpu->model->def->name);
+            return;
+        }
+        bitmap_or(cpu->model->features, cpu->model->features, def->feat,
+                  S390_FEAT_MAX);
+    } else {
+        bitmap_andnot(cpu->model->features, cpu->model->features, def->feat,
+                      S390_FEAT_MAX);
+    }
+}
+
+void s390_cpu_model_register_props(Object *obj)
+{
+    S390FeatGroup group;
+    S390Feat feat;
+
+    for (feat = 0; feat < S390_FEAT_MAX; feat++) {
+        const S390FeatDef *def = s390_feat_def(feat);
+        object_property_add(obj, def->name, "bool", get_feature,
+                            set_feature, NULL, (void *) feat, NULL);
+        object_property_set_description(obj, def->name, def->desc , NULL);
+    }
+    for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
+        const S390FeatGroupDef *def = s390_feat_group_def(group);
+        object_property_add(obj, def->name, "bool", get_feature_group,
+                            set_feature_group, NULL, (void *) group, NULL);
+        object_property_set_description(obj, def->name, def->desc , NULL);
+    }
+}
+
 static void s390_cpu_model_initfn(Object *obj)
 {
     S390CPU *cpu = S390_CPU(obj);
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 11/29] s390x/cpumodel: let the CPU model handle feature checks
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (9 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 10/29] s390x/cpumodel: expose features and feature groups as properties David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 12/29] s390x/cpumodel: check and apply the CPU model David Hildenbrand
                   ` (18 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

If we have certain features enabled, we have to migrate additional state
(e.g. vector registers or runtime-instrumentation registers). Let the
CPU model control that unless we have no "host" CPU model in the KVM
case. This will later on be the case for compatibility machines, so
migration from QEMU versions without the CPU model will still work.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu_models.c | 24 ++++++++++++++++++++++++
 target-s390x/cpu_models.h |  2 ++
 target-s390x/machine.c    | 14 ++------------
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 9532b46..b698b80 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -73,6 +73,30 @@ static const S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+bool s390_has_feat(S390Feat feat)
+{
+    static S390CPU *cpu;
+
+    if (!cpu) {
+        cpu = S390_CPU(qemu_get_cpu(0));
+    }
+
+    if (!cpu || !cpu->model) {
+#ifdef CONFIG_KVM
+        if (kvm_enabled()) {
+            if (feat == S390_FEAT_VECTOR) {
+                return kvm_check_extension(kvm_state, KVM_CAP_S390_VECTOR_REGISTERS);
+            }
+            if (feat == S390_FEAT_RUNTIME_INSTRUMENTATION) {
+                return kvm_s390_get_ri();
+            }
+        }
+#endif
+        return 0;
+    }
+    return test_bit(feat, cpu->model->features);
+}
+
 struct S390PrintCpuListInfo {
     FILE *f;
     fprintf_function print;
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index 244256b..fe988cc 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -43,4 +43,6 @@ typedef struct S390CPUModel {
     uint8_t cpu_ver;        /* CPU version, usually "ff" for kvm */
 } S390CPUModel;
 
+bool s390_has_feat(S390Feat feat);
+
 #endif /* TARGET_S390X_CPU_MODELS_H */
diff --git a/target-s390x/machine.c b/target-s390x/machine.c
index aa39e5d..edc3a47 100644
--- a/target-s390x/machine.c
+++ b/target-s390x/machine.c
@@ -78,12 +78,7 @@ static const VMStateDescription vmstate_fpu = {
 
 static bool vregs_needed(void *opaque)
 {
-#ifdef CONFIG_KVM
-    if (kvm_enabled()) {
-        return kvm_check_extension(kvm_state, KVM_CAP_S390_VECTOR_REGISTERS);
-    }
-#endif
-    return 0;
+    return s390_has_feat(S390_FEAT_VECTOR);
 }
 
 static const VMStateDescription vmstate_vregs = {
@@ -147,12 +142,7 @@ static const VMStateDescription vmstate_vregs = {
 
 static bool riccb_needed(void *opaque)
 {
-#ifdef CONFIG_KVM
-    if (kvm_enabled()) {
-        return kvm_s390_get_ri();
-    }
-#endif
-    return 0;
+    return s390_has_feat(S390_FEAT_RUNTIME_INSTRUMENTATION);
 }
 
 const VMStateDescription vmstate_riccb = {
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 12/29] s390x/cpumodel: check and apply the CPU model
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (10 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 11/29] s390x/cpumodel: let the CPU model handle feature checks David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 13/29] s390x/sclp: factor out preparation of cpu entries David Hildenbrand
                   ` (17 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

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>
---
 target-s390x/cpu_models.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 154 insertions(+)

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index b698b80..3fe85fa 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,167 @@ 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_1 },
+        { S390_FEAT_IDTE_SEGMENT, S390_FEAT_DAT_ENH_1 },
+        { S390_FEAT_IDTE_REGION, S390_FEAT_DAT_ENH_1 },
+        { S390_FEAT_IDTE_REGION, S390_FEAT_IDTE_SEGMENT },
+        { S390_FEAT_LOCAL_TLB_CLEARING, S390_FEAT_DAT_ENH_1},
+        { S390_FEAT_LONG_DISPLACEMENT_FAST, S390_FEAT_LONG_DISPLACEMENT },
+        { S390_FEAT_DFP_FAST, S390_FEAT_DFP },
+        { S390_FEAT_TRANSACTIONAL_EXE, S390_FEAT_GEN12_ENH },
+        { S390_FEAT_CONSTRAINT_TRANSACTIONAL_EXE, S390_FEAT_TRANSACTIONAL_EXE },
+        { S390_FEAT_EDAT_2, S390_FEAT_EDAT_1},
+        { 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_1 },
+    };
+    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.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 13/29] s390x/sclp: factor out preparation of cpu entries
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (11 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 12/29] s390x/cpumodel: check and apply the CPU model David Hildenbrand
@ 2016-08-02 11:58 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 14/29] s390x/sclp: introduce sclp feature blocks David Hildenbrand
                   ` (16 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's factor out the common code of "read cpu info" and "read scp
info". This will make the introduction of new cpu entry fields easier.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/sclp.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index fca37f5..15d7114 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -29,6 +29,16 @@ static inline SCLPDevice *get_sclp_device(void)
     return SCLP(object_resolve_path_type("", TYPE_SCLP, NULL));
 }
 
+static void prepare_cpu_entries(SCLPDevice *sclp, CPUEntry *entry, int count)
+{
+    int i;
+
+    for (i = 0; i < count; i++) {
+        entry[i].address = i;
+        entry[i].type = 0;
+    }
+}
+
 /* Provide information about the configuration, CPUs and storage */
 static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
 {
@@ -37,7 +47,6 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     sclpMemoryHotplugDev *mhd = get_sclp_memory_hotplug_dev();
     CPUState *cpu;
     int cpu_count = 0;
-    int i = 0;
     int rnsize, rnmax;
     int slots = MIN(machine->ram_slots, s390_get_memslot_count(kvm_state));
 
@@ -50,10 +59,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries));
     read_info->highest_cpu = cpu_to_be16(max_cpus);
 
-    for (i = 0; i < cpu_count; i++) {
-        read_info->entries[i].address = i;
-        read_info->entries[i].type = 0;
-    }
+    prepare_cpu_entries(sclp, read_info->entries, cpu_count);
 
     read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
                                         SCLP_HAS_PCI_RECONFIG);
@@ -304,7 +310,6 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB *sccb)
     ReadCpuInfo *cpu_info = (ReadCpuInfo *) sccb;
     CPUState *cpu;
     int cpu_count = 0;
-    int i = 0;
 
     CPU_FOREACH(cpu) {
         cpu_count++;
@@ -318,10 +323,7 @@ static void sclp_read_cpu_info(SCLPDevice *sclp, SCCB *sccb)
     cpu_info->offset_standby = cpu_to_be16(cpu_info->offset_configured
         + cpu_info->nr_configured*sizeof(CPUEntry));
 
-    for (i = 0; i < cpu_count; i++) {
-        cpu_info->entries[i].address = i;
-        cpu_info->entries[i].type = 0;
-    }
+    prepare_cpu_entries(sclp, cpu_info->entries, cpu_count);
 
     sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_READ_COMPLETION);
 }
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 14/29] s390x/sclp: introduce sclp feature blocks
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (12 preceding siblings ...)
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 13/29] s390x/sclp: factor out preparation of cpu entries David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features David Hildenbrand
                   ` (15 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

The sclp "read cpu info" and "read scp info" commands can include
features for the cpu info and configuration characteristics (extended),
decribing some advanced features available in the configuration.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 include/hw/s390x/sclp.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index ba28d1d..30a40ea 100644
--- a/include/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
@@ -98,11 +98,14 @@ typedef struct SCCBHeader {
 } QEMU_PACKED SCCBHeader;
 
 #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
+#define SCCB_CPU_FEATURE_LEN 6
 
 /* CPU information */
 typedef struct CPUEntry {
     uint8_t address;
-    uint8_t reserved0[13];
+    uint8_t reserved0;
+    uint8_t features[SCCB_CPU_FEATURE_LEN];
+    uint8_t reserved2[6];
     uint8_t type;
     uint8_t reserved1;
 } QEMU_PACKED CPUEntry;
@@ -118,10 +121,13 @@ typedef struct ReadInfo {
     uint8_t  loadparm[8];               /* 24-31 */
     uint8_t  _reserved3[48 - 32];       /* 32-47 */
     uint64_t facilities;                /* 48-55 */
-    uint8_t  _reserved0[100 - 56];
+    uint8_t  _reserved0[80 - 56];       /* 56-79 */
+    uint8_t  conf_char[96 - 80];        /* 80-95 */
+    uint8_t  _reserved4[100 - 96];      /* 96-99 */
     uint32_t rnsize2;
     uint64_t rnmax2;
-    uint8_t  _reserved4[120-112];       /* 112-119 */
+    uint8_t  _reserved6[116 - 112];     /* 112-115 */
+    uint8_t  conf_char_ext[120 - 116];   /* 116-119 */
     uint16_t highest_cpu;
     uint8_t  _reserved5[128 - 122];     /* 122-127 */
     struct CPUEntry entries[0];
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (13 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 14/29] s390x/sclp: introduce sclp feature blocks David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 12:31   ` Thomas Huth
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 16/29] s390x/sclp: propagate the ibc val(lowest and unblocked ibc) David Hildenbrand
                   ` (14 subsequent siblings)
  29 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

We have three different blocks in the SCLP read-SCP information response
that indicate sclp features. Let's prepare propagation.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/sclp.c           |  9 +++++++++
 target-s390x/cpu_models.c | 14 ++++++++++++++
 target-s390x/cpu_models.h |  1 +
 3 files changed, 24 insertions(+)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 15d7114..3c126ee 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -31,11 +31,14 @@ static inline SCLPDevice *get_sclp_device(void)
 
 static void prepare_cpu_entries(SCLPDevice *sclp, CPUEntry *entry, int count)
 {
+    uint8_t features[SCCB_CPU_FEATURE_LEN] = { 0 };
     int i;
 
+    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CPU, features);
     for (i = 0; i < count; i++) {
         entry[i].address = i;
         entry[i].type = 0;
+        memcpy(entry[i].features, features, sizeof(entry[i].features));
     }
 }
 
@@ -59,6 +62,12 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries));
     read_info->highest_cpu = cpu_to_be16(max_cpus);
 
+    /* Configuration Characteristic (Extension) */
+    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR,
+                         read_info->conf_char);
+    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT,
+                         read_info->conf_char_ext);
+
     prepare_cpu_entries(sclp, read_info->entries, cpu_count);
 
     read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 3fe85fa..641aad0 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -74,6 +74,20 @@ static const S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+void s390_get_feat_block(S390FeatType type, uint8_t *data)
+{
+    static S390CPU *cpu;
+
+    if (!cpu) {
+        cpu = S390_CPU(qemu_get_cpu(0));
+    }
+
+    if (!cpu || !cpu->model) {
+        return;
+    }
+    return s390_fill_feat_block(cpu->model->features, type, data);
+}
+
 bool s390_has_feat(S390Feat feat)
 {
     static S390CPU *cpu;
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index fe988cc..04c47c6 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -43,6 +43,7 @@ typedef struct S390CPUModel {
     uint8_t cpu_ver;        /* CPU version, usually "ff" for kvm */
 } S390CPUModel;
 
+void s390_get_feat_block(S390FeatType type, uint8_t *data);
 bool s390_has_feat(S390Feat feat);
 
 #endif /* TARGET_S390X_CPU_MODELS_H */
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 16/29] s390x/sclp: propagate the ibc val(lowest and unblocked ibc)
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (14 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 17/29] s390x/sclp: propagate the mha via sclp David Hildenbrand
                   ` (13 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

If we have a lowest ibc, we can indicate the ibc to the guest.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/sclp.c           |  2 ++
 include/hw/s390x/sclp.h   |  3 ++-
 target-s390x/cpu_models.c | 21 +++++++++++++++++++++
 target-s390x/cpu_models.h | 12 ++++++++++++
 4 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 3c126ee..52f8bb9 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -62,6 +62,8 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
     read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries));
     read_info->highest_cpu = cpu_to_be16(max_cpus);
 
+    read_info->ibc_val = cpu_to_be32(s390_get_ibc_val());
+
     /* Configuration Characteristic (Extension) */
     s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR,
                          read_info->conf_char);
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index 30a40ea..664be9b 100644
--- a/include/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
@@ -121,7 +121,8 @@ typedef struct ReadInfo {
     uint8_t  loadparm[8];               /* 24-31 */
     uint8_t  _reserved3[48 - 32];       /* 32-47 */
     uint64_t facilities;                /* 48-55 */
-    uint8_t  _reserved0[80 - 56];       /* 56-79 */
+    uint8_t  _reserved0[76 - 56];       /* 56-75 */
+    uint32_t ibc_val;
     uint8_t  conf_char[96 - 80];        /* 80-95 */
     uint8_t  _reserved4[100 - 96];      /* 96-99 */
     uint32_t rnsize2;
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 641aad0..51ce3d8 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -74,6 +74,27 @@ static const S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+uint32_t s390_get_ibc_val(void)
+{
+    uint16_t unblocked_ibc, lowest_ibc;
+    static S390CPU *cpu;
+
+    if (!cpu) {
+        cpu = S390_CPU(qemu_get_cpu(0));
+    }
+
+    if (!cpu || !cpu->model) {
+        return 0;
+    }
+    unblocked_ibc = s390_ibc_from_cpu_model(cpu->model);
+    lowest_ibc = cpu->model->lowest_ibc;
+    /* the lowest_ibc always has to be <= unblocked_ibc */
+    if (!lowest_ibc || lowest_ibc > unblocked_ibc) {
+        return 0;
+    }
+    return ((uint32_t) lowest_ibc << 16) | unblocked_ibc;
+}
+
 void s390_get_feat_block(S390FeatType type, uint8_t *data)
 {
     static S390CPU *cpu;
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index 04c47c6..bbb85ac 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -43,6 +43,18 @@ typedef struct S390CPUModel {
     uint8_t cpu_ver;        /* CPU version, usually "ff" for kvm */
 } S390CPUModel;
 
+#define S390_GEN_Z10 0xa
+
+uint32_t s390_get_ibc_val(void);
+static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
+{
+    uint16_t ibc = 0;
+
+    if (model->def->gen >= S390_GEN_Z10) {
+        ibc = ((model->def->gen - S390_GEN_Z10) << 4) + model->def->ec_ga;
+    }
+    return ibc;
+}
 void s390_get_feat_block(S390FeatType type, uint8_t *data);
 bool s390_has_feat(S390Feat feat);
 
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 17/29] s390x/sclp: propagate the mha via sclp
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (15 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 16/29] s390x/sclp: propagate the ibc val(lowest and unblocked ibc) David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 18/29] s390x/sclp: propagate hmfai David Hildenbrand
                   ` (12 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

The mha is provided in the CPU model, so get any CPU and extract the value.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/sclp.c           |  1 +
 include/hw/s390x/sclp.h   |  3 ++-
 target-s390x/cpu_models.c | 14 ++++++++++++++
 target-s390x/cpu_models.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 52f8bb9..5ffcf51 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -105,6 +105,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
 
         read_info->facilities |= cpu_to_be64(SCLP_FC_ASSIGN_ATTACH_READ_STOR);
     }
+    read_info->mha_pow = s390_get_mha_pow();
 
     rnsize = 1 << (sclp->increment_size - 20);
     if (rnsize <= 128) {
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index 664be9b..dab3c0f 100644
--- a/include/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
@@ -124,7 +124,8 @@ typedef struct ReadInfo {
     uint8_t  _reserved0[76 - 56];       /* 56-75 */
     uint32_t ibc_val;
     uint8_t  conf_char[96 - 80];        /* 80-95 */
-    uint8_t  _reserved4[100 - 96];      /* 96-99 */
+    uint8_t  _reserved4[99 - 96];       /* 96-98 */
+    uint8_t mha_pow;
     uint32_t rnsize2;
     uint64_t rnmax2;
     uint8_t  _reserved6[116 - 112];     /* 112-115 */
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 51ce3d8..2363027 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -74,6 +74,20 @@ static const S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+uint8_t s390_get_mha_pow(void)
+{
+    static S390CPU *cpu;
+
+    if (!cpu) {
+        cpu = S390_CPU(qemu_get_cpu(0));
+    }
+
+    if (!cpu || !cpu->model) {
+        return 0;
+    }
+    return cpu->model->def->mha_pow;
+}
+
 uint32_t s390_get_ibc_val(void)
 {
     uint16_t unblocked_ibc, lowest_ibc;
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index bbb85ac..ee019b4 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -45,6 +45,7 @@ typedef struct S390CPUModel {
 
 #define S390_GEN_Z10 0xa
 
+uint8_t s390_get_mha_pow(void);
 uint32_t s390_get_ibc_val(void);
 static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
 {
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 18/29] s390x/sclp: propagate hmfai
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (16 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 17/29] s390x/sclp: propagate the mha via sclp David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 19/29] linux-headers: update against kvm/next David Hildenbrand
                   ` (11 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

hmfai is provided on CPU models >= z196. Let's propagate it properly.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/sclp.c           |  1 +
 include/hw/s390x/sclp.h   |  3 ++-
 target-s390x/cpu_models.c | 14 ++++++++++++++
 target-s390x/cpu_models.h |  1 +
 4 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
index 5ffcf51..883592c 100644
--- a/hw/s390x/sclp.c
+++ b/hw/s390x/sclp.c
@@ -106,6 +106,7 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
         read_info->facilities |= cpu_to_be64(SCLP_FC_ASSIGN_ATTACH_READ_STOR);
     }
     read_info->mha_pow = s390_get_mha_pow();
+    read_info->hmfai = cpu_to_be32(s390_get_hmfai());
 
     rnsize = 1 << (sclp->increment_size - 20);
     if (rnsize <= 128) {
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
index dab3c0f..3008a51 100644
--- a/include/hw/s390x/sclp.h
+++ b/include/hw/s390x/sclp.h
@@ -131,7 +131,8 @@ typedef struct ReadInfo {
     uint8_t  _reserved6[116 - 112];     /* 112-115 */
     uint8_t  conf_char_ext[120 - 116];   /* 116-119 */
     uint16_t highest_cpu;
-    uint8_t  _reserved5[128 - 122];     /* 122-127 */
+    uint8_t  _reserved5[124 - 122];     /* 122-123 */
+    uint32_t hmfai;
     struct CPUEntry entries[0];
 } QEMU_PACKED ReadInfo;
 
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 2363027..9115731 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -74,6 +74,20 @@ static const S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
 };
 
+uint32_t s390_get_hmfai(void)
+{
+    static S390CPU *cpu;
+
+    if (!cpu) {
+        cpu = S390_CPU(qemu_get_cpu(0));
+    }
+
+    if (!cpu || !cpu->model) {
+        return 0;
+    }
+    return cpu->model->def->hmfai;
+}
+
 uint8_t s390_get_mha_pow(void)
 {
     static S390CPU *cpu;
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index ee019b4..986f7cb 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -45,6 +45,7 @@ typedef struct S390CPUModel {
 
 #define S390_GEN_Z10 0xa
 
+uint32_t s390_get_hmfai(void);
 uint8_t s390_get_mha_pow(void);
 uint32_t s390_get_ibc_val(void);
 static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 19/29] linux-headers: update against kvm/next
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (17 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 18/29] s390x/sclp: propagate hmfai David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 20/29] s390x/kvm: allow runtime-instrumentation for "none" machine David Hildenbrand
                   ` (10 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Update against 601045bff745 ("Merge branch 'kvm-ppc-next'...").

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 linux-headers/asm-arm64/kvm.h |  2 ++
 linux-headers/asm-s390/kvm.h  | 41 +++++++++++++++++++++++++++++++++++++++++
 linux-headers/linux/kvm.h     | 12 +++++++++++-
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/linux-headers/asm-arm64/kvm.h b/linux-headers/asm-arm64/kvm.h
index 7d82d1f..fd5a276 100644
--- a/linux-headers/asm-arm64/kvm.h
+++ b/linux-headers/asm-arm64/kvm.h
@@ -87,9 +87,11 @@ struct kvm_regs {
 /* Supported VGICv3 address types  */
 #define KVM_VGIC_V3_ADDR_TYPE_DIST	2
 #define KVM_VGIC_V3_ADDR_TYPE_REDIST	3
+#define KVM_VGIC_ITS_ADDR_TYPE		4
 
 #define KVM_VGIC_V3_DIST_SIZE		SZ_64K
 #define KVM_VGIC_V3_REDIST_SIZE		(2 * SZ_64K)
+#define KVM_VGIC_V3_ITS_SIZE		(2 * SZ_64K)
 
 #define KVM_ARM_VCPU_POWER_OFF		0 /* CPU is started in OFF state */
 #define KVM_ARM_VCPU_EL1_32BIT		1 /* CPU running a 32bit VM */
diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index 09ae5dc..ac63ca6 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -93,6 +93,47 @@ struct kvm_s390_vm_cpu_machine {
 	__u64 fac_list[256];
 };
 
+#define KVM_S390_VM_CPU_PROCESSOR_FEAT	2
+#define KVM_S390_VM_CPU_MACHINE_FEAT	3
+
+#define KVM_S390_VM_CPU_FEAT_NR_BITS	1024
+#define KVM_S390_VM_CPU_FEAT_ESOP	0
+#define KVM_S390_VM_CPU_FEAT_SIEF2	1
+#define KVM_S390_VM_CPU_FEAT_64BSCAO	2
+#define KVM_S390_VM_CPU_FEAT_SIIF	3
+#define KVM_S390_VM_CPU_FEAT_GPERE	4
+#define KVM_S390_VM_CPU_FEAT_GSLS	5
+#define KVM_S390_VM_CPU_FEAT_IB		6
+#define KVM_S390_VM_CPU_FEAT_CEI	7
+#define KVM_S390_VM_CPU_FEAT_IBS	8
+#define KVM_S390_VM_CPU_FEAT_SKEY	9
+#define KVM_S390_VM_CPU_FEAT_CMMA	10
+#define KVM_S390_VM_CPU_FEAT_PFMFI	11
+#define KVM_S390_VM_CPU_FEAT_SIGPIF	12
+struct kvm_s390_vm_cpu_feat {
+	__u64 feat[16];
+};
+
+#define KVM_S390_VM_CPU_PROCESSOR_SUBFUNC	4
+#define KVM_S390_VM_CPU_MACHINE_SUBFUNC		5
+/* for "test bit" instructions MSB 0 bit ordering, for "query" raw blocks */
+struct kvm_s390_vm_cpu_subfunc {
+	__u8 plo[32];		/* always */
+	__u8 ptff[16];		/* with TOD-clock steering */
+	__u8 kmac[16];		/* with MSA */
+	__u8 kmc[16];		/* with MSA */
+	__u8 km[16];		/* with MSA */
+	__u8 kimd[16];		/* with MSA */
+	__u8 klmd[16];		/* with MSA */
+	__u8 pckmo[16];		/* with MSA3 */
+	__u8 kmctr[16];		/* with MSA4 */
+	__u8 kmf[16];		/* with MSA4 */
+	__u8 kmo[16];		/* with MSA4 */
+	__u8 pcc[16];		/* with MSA4 */
+	__u8 ppno[16];		/* with MSA5 */
+	__u8 reserved[1824];
+};
+
 /* kvm attributes for crypto */
 #define KVM_S390_VM_CRYPTO_ENABLE_AES_KW	0
 #define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW	1
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index e60e21b..bf91e47 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -866,6 +866,9 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_ARM_PMU_V3 126
 #define KVM_CAP_VCPU_ATTRIBUTES 127
 #define KVM_CAP_MAX_VCPU_ID 128
+#define KVM_CAP_X2APIC_API 129
+#define KVM_CAP_S390_USER_INSTR0 130
+#define KVM_CAP_MSI_DEVID 131
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -1024,12 +1027,14 @@ struct kvm_one_reg {
 	__u64 addr;
 };
 
+#define KVM_MSI_VALID_DEVID	(1U << 0)
 struct kvm_msi {
 	__u32 address_lo;
 	__u32 address_hi;
 	__u32 data;
 	__u32 flags;
-	__u8  pad[16];
+	__u32 devid;
+	__u8  pad[12];
 };
 
 struct kvm_arm_device_addr {
@@ -1074,6 +1079,8 @@ enum kvm_device_type {
 #define KVM_DEV_TYPE_FLIC		KVM_DEV_TYPE_FLIC
 	KVM_DEV_TYPE_ARM_VGIC_V3,
 #define KVM_DEV_TYPE_ARM_VGIC_V3	KVM_DEV_TYPE_ARM_VGIC_V3
+	KVM_DEV_TYPE_ARM_VGIC_ITS,
+#define KVM_DEV_TYPE_ARM_VGIC_ITS	KVM_DEV_TYPE_ARM_VGIC_ITS
 	KVM_DEV_TYPE_MAX,
 };
 
@@ -1313,4 +1320,7 @@ struct kvm_assigned_msix_entry {
 	__u16 padding[3];
 };
 
+#define KVM_X2APIC_API_USE_32BIT_IDS            (1ULL << 0)
+#define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK  (1ULL << 1)
+
 #endif /* __LINUX_KVM_H */
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 20/29] s390x/kvm: allow runtime-instrumentation for "none" machine
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (18 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 19/29] linux-headers: update against kvm/next David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 21/29] s390x/kvm: implement CPU model support David Hildenbrand
                   ` (9 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

To be able to query the correct host model for the "none" machine,
let's allow runtime-instrumentation for that machine.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 hw/s390x/s390-virtio-ccw.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 91d9cef..f7dd2c8 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -249,6 +249,11 @@ bool ri_allowed(void)
 
             return s390mc->ri_allowed;
         }
+        /*
+         * Make sure the "none" machine can have ri, otherwise it won't * be
+         * unlocked in KVM and therefore the host CPU model might be wrong.
+         */
+        return true;
     }
     return 0;
 }
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 21/29] s390x/kvm: implement CPU model support
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (19 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 20/29] s390x/kvm: allow runtime-instrumentation for "none" machine David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 22/29] s390x/kvm: disable host model for existing compat machines David Hildenbrand
                   ` (8 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's implement our two hooks so we can support CPU models.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/cpu_models.c |  75 +++++++++++-
 target-s390x/cpu_models.h |  50 ++++++++
 target-s390x/kvm.c        | 295 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 417 insertions(+), 3 deletions(-)

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 9115731..b2d722b 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -161,6 +161,61 @@ bool s390_has_feat(S390Feat feat)
     return test_bit(feat, cpu->model->features);
 }
 
+uint8_t s390_get_gen_for_cpu_type(uint16_t type)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
+        if (s390_cpu_defs[i].type == type) {
+            return s390_cpu_defs[i].gen;
+        }
+    }
+    return 0;
+}
+
+const S390CPUDef *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                                    S390FeatBitmap features)
+{
+    const S390CPUDef *last_compatible = NULL;
+    int i;
+
+    if (!gen) {
+        ec_ga = 0;
+    }
+    if (!gen && type) {
+        gen = s390_get_gen_for_cpu_type(type);
+    }
+
+    for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
+        const S390CPUDef *def = &s390_cpu_defs[i];
+        S390FeatBitmap missing;
+
+        /* don't even try newer generations if we know the generation */
+        if (gen) {
+            if (def->gen > gen) {
+                break;
+            } else if (def->gen == gen && ec_ga && def->ec_ga > ec_ga) {
+                break;
+            }
+        }
+
+        if (features) {
+            /* see if the model satisfies the minimum features */
+            bitmap_andnot(missing, def->base_feat, features, S390_FEAT_MAX);
+            if (!bitmap_empty(missing, S390_FEAT_MAX)) {
+                break;
+            }
+        }
+
+        /* stop the search if we found the exact model */
+        if (def->type == type && def->ec_ga == ec_ga) {
+            return def;
+        }
+        last_compatible = def;
+    }
+    return last_compatible;
+}
+
 struct S390PrintCpuListInfo {
     FILE *f;
     fprintf_function print;
@@ -325,7 +380,7 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
     }
 
     if (kvm_enabled()) {
-        error_setg(errp, "KVM does not support CPU models.");
+        kvm_s390_get_host_cpu_model(&max_model, errp);
     } else {
         /* TCG enulates a z900 */
         max_model.def = &s390_cpu_defs[0];
@@ -358,8 +413,7 @@ static inline void apply_cpu_model(const S390CPUModel *model, Error **errp)
     }
 
     if (kvm_enabled()) {
-        /* FIXME KVM */
-        error_setg(errp, "KVM doesn't support CPU models.");
+        kvm_s390_apply_cpu_model(model, errp);
     } else if (model) {
         /* FIXME TCG - use data for stdip/stfl */
     }
@@ -564,6 +618,21 @@ static void s390_cpu_model_initfn(Object *obj)
 #ifdef CONFIG_KVM
 static void s390_host_cpu_model_initfn(Object *obj)
 {
+    S390CPU *cpu = S390_CPU(obj);
+    Error *err = NULL;
+
+    if (!kvm_enabled() || !kvm_s390_cpu_models_supported()) {
+        return;
+    }
+
+    cpu->model = g_malloc0(sizeof(*cpu->model));
+    kvm_s390_get_host_cpu_model(cpu->model, &err);
+    if (err) {
+        error_report_err(err);
+        g_free(cpu->model);
+        /* fallback to unsupported cpu models */
+        cpu->model = NULL;
+    }
 }
 #endif
 
diff --git a/target-s390x/cpu_models.h b/target-s390x/cpu_models.h
index 986f7cb..a1ee3d6 100644
--- a/target-s390x/cpu_models.h
+++ b/target-s390x/cpu_models.h
@@ -43,7 +43,25 @@ typedef struct S390CPUModel {
     uint8_t cpu_ver;        /* CPU version, usually "ff" for kvm */
 } S390CPUModel;
 
+/*
+ * CPU ID
+ *
+ * bits 0-7: Zeroes (ff for kvm)
+ * bits 8-31: CPU ID (serial number)
+ * bits 32-48: Machine type
+ * bits 48-63: Zeroes
+ */
+#define cpuid_type(x)     (((x) >> 16) & 0xffff)
+#define cpuid_id(x)       (((x) >> 32) & 0xffffff)
+#define cpuid_ver(x)      (((x) >> 56) & 0xff)
+
+#define lowest_ibc(x)     (((uint32_t)(x) >> 16) & 0xfff)
+#define unblocked_ibc(x)  ((uint32_t)(x) & 0xfff)
+#define has_ibc(x)        (lowest_ibc(x) != 0)
+
 #define S390_GEN_Z10 0xa
+#define ibc_gen(x)        (x == 0 ? 0 : ((x >> 4) + S390_GEN_Z10))
+#define ibc_ec_ga(x)      (x & 0xf)
 
 uint32_t s390_get_hmfai(void);
 uint8_t s390_get_mha_pow(void);
@@ -59,5 +77,37 @@ static inline uint16_t s390_ibc_from_cpu_model(const S390CPUModel *model)
 }
 void s390_get_feat_block(S390FeatType type, uint8_t *data);
 bool s390_has_feat(S390Feat feat);
+uint8_t s390_get_gen_for_cpu_type(uint16_t type);
+static inline bool s390_known_cpu_type(uint16_t type)
+{
+    return s390_get_gen_for_cpu_type(type) != 0;
+}
+static inline uint64_t s390_cpuid_from_cpu_model(const S390CPUModel *model)
+{
+    return ((uint64_t)model->cpu_ver << 56) |
+           ((uint64_t)model->cpu_id << 32) |
+           ((uint64_t)model->def->type << 16);
+}
+S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                                    S390FeatBitmap features);
+
+#ifdef CONFIG_KVM
+bool kvm_s390_cpu_models_supported(void);
+void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp);
+void kvm_s390_apply_cpu_model(const S390CPUModel *model,  Error **errp);
+#else
+static inline void kvm_s390_get_host_cpu_model(S390CPUModel *model,
+                                               Error **errp)
+{
+}
+static inline void kvm_s390_apply_cpu_model(const S390CPUModel *model,
+                                            Error **errp)
+{
+}
+static inline bool kvm_s390_cpu_models_supported(void)
+{
+    return false;
+}
+#endif
 
 #endif /* TARGET_S390X_CPU_MODELS_H */
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 80ac621..edebc6d 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -2282,3 +2282,298 @@ int kvm_arch_msi_data_to_gsi(uint32_t data)
 {
     abort();
 }
+
+static inline int test_bit_inv(long nr, const unsigned long *addr)
+{
+    return test_bit(BE_BIT_NR(nr), addr);
+}
+
+static inline void set_bit_inv(long nr, unsigned long *addr)
+{
+    set_bit(BE_BIT_NR(nr), addr);
+}
+
+static int query_cpu_subfunc(S390FeatBitmap features)
+{
+    struct kvm_s390_vm_cpu_subfunc prop;
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_MACHINE_SUBFUNC,
+        .addr = (uint64_t) &prop,
+    };
+    int rc;
+
+    rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc) {
+        return  rc;
+    }
+
+    /*
+     * We're going to add all subfunctions now, if the corresponding feature
+     * is available that unlocks the query functions.
+     */
+    s390_add_from_feat_block(features, S390_FEAT_TYPE_PLO, prop.plo);
+    if (test_bit(S390_FEAT_TOD_CLOCK_STEERING, features)) {
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_PTFF, prop.ptff);
+    }
+    if (test_bit(S390_FEAT_MSA, features)) {
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KMAC, prop.kmac);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KMC, prop.kmc);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KM, prop.km);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KIMD, prop.kimd);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KLMD, prop.klmd);
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_3, features)) {
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_PCKMO, prop.pckmo);
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_4, features)) {
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KMCTR, prop.kmctr);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KMF, prop.kmf);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_KMO, prop.kmo);
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_PCC, prop.pcc);
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_5, features)) {
+        s390_add_from_feat_block(features, S390_FEAT_TYPE_PPNO, prop.ppno);
+    }
+    return 0;
+}
+
+static int configure_cpu_subfunc(const S390FeatBitmap features)
+{
+    struct kvm_s390_vm_cpu_subfunc prop = {};
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_PROCESSOR_SUBFUNC,
+        .addr = (uint64_t) &prop,
+    };
+
+    if (!kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                           KVM_S390_VM_CPU_PROCESSOR_SUBFUNC)) {
+        /* hardware support might be missing, IBC will handle most of this */
+        return 0;
+    }
+
+    s390_fill_feat_block(features, S390_FEAT_TYPE_PLO, prop.plo);
+    if (test_bit(S390_FEAT_TOD_CLOCK_STEERING, features)) {
+        s390_fill_feat_block(features, S390_FEAT_TYPE_PTFF, prop.ptff);
+        prop.ptff[0] |= 0x80; /* query is always available */
+    }
+    if (test_bit(S390_FEAT_MSA, features)) {
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KMAC, prop.kmac);
+        prop.kmac[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KMC, prop.kmc);
+        prop.kmc[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KM, prop.km);
+        prop.km[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KIMD, prop.kimd);
+        prop.kimd[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KLMD, prop.klmd);
+        prop.klmd[0] |= 0x80; /* query is always available */
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_3, features)) {
+        s390_fill_feat_block(features, S390_FEAT_TYPE_PCKMO, prop.pckmo);
+        prop.pckmo[0] |= 0x80; /* query is always available */
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_4, features)) {
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KMCTR, prop.kmctr);
+        prop.kmctr[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KMF, prop.kmf);
+        prop.kmf[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_KMO, prop.kmo);
+        prop.kmo[0] |= 0x80; /* query is always available */
+        s390_fill_feat_block(features, S390_FEAT_TYPE_PCC, prop.pcc);
+        prop.pcc[0] |= 0x80; /* query is always available */
+    }
+    if (test_bit(S390_FEAT_MSA_EXT_5, features)) {
+        s390_fill_feat_block(features, S390_FEAT_TYPE_PPNO, prop.ppno);
+        prop.ppno[0] |= 0x80; /* query is always available */
+    }
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
+static int kvm_to_feat[][2] = {
+    { KVM_S390_VM_CPU_FEAT_ESOP, S390_FEAT_ESOP },
+    { KVM_S390_VM_CPU_FEAT_SIEF2, S390_FEAT_SIE_F2 },
+    { KVM_S390_VM_CPU_FEAT_64BSCAO , S390_FEAT_SIE_64BSCAO },
+    { KVM_S390_VM_CPU_FEAT_SIIF, S390_FEAT_SIE_SIIF },
+    { KVM_S390_VM_CPU_FEAT_GPERE, S390_FEAT_SIE_GPERE },
+    { KVM_S390_VM_CPU_FEAT_GSLS, S390_FEAT_SIE_GSLS },
+    { KVM_S390_VM_CPU_FEAT_IB, S390_FEAT_SIE_IB },
+    { KVM_S390_VM_CPU_FEAT_CEI, S390_FEAT_SIE_CEI },
+    { KVM_S390_VM_CPU_FEAT_IBS, S390_FEAT_SIE_IBS },
+    { KVM_S390_VM_CPU_FEAT_SKEY, S390_FEAT_SIE_SKEY },
+    { KVM_S390_VM_CPU_FEAT_CMMA, S390_FEAT_SIE_CMMA },
+    { KVM_S390_VM_CPU_FEAT_PFMFI, S390_FEAT_SIE_PFMFI},
+    { KVM_S390_VM_CPU_FEAT_SIGPIF, S390_FEAT_SIE_SIGPIF},
+};
+
+static int query_cpu_feat(S390FeatBitmap features)
+{
+    struct kvm_s390_vm_cpu_feat prop;
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_MACHINE_FEAT,
+        .addr = (uint64_t) &prop,
+    };
+    int rc;
+    int i;
+
+    rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc) {
+        return  rc;
+    }
+
+    for (i = 0; i < ARRAY_SIZE(kvm_to_feat); i++) {
+        if (test_bit_inv(kvm_to_feat[i][0], (unsigned long *)prop.feat)) {
+            set_bit(kvm_to_feat[i][1], features);
+        }
+    }
+    return 0;
+}
+
+static int configure_cpu_feat(const S390FeatBitmap features)
+{
+    struct kvm_s390_vm_cpu_feat prop = {};
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_PROCESSOR_FEAT,
+        .addr = (uint64_t) &prop,
+    };
+    int i;
+
+    for (i = 0; i < ARRAY_SIZE(kvm_to_feat); i++) {
+        if (test_bit(kvm_to_feat[i][1], features)) {
+            set_bit_inv(kvm_to_feat[i][0], (unsigned long *)prop.feat);
+        }
+    }
+    return kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+}
+
+bool kvm_s390_cpu_models_supported(void)
+{
+    return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                             KVM_S390_VM_CPU_MACHINE) &&
+           kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                             KVM_S390_VM_CPU_PROCESSOR) &&
+           kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                             KVM_S390_VM_CPU_MACHINE_FEAT) &&
+           kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                             KVM_S390_VM_CPU_PROCESSOR_FEAT) &&
+           kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
+                             KVM_S390_VM_CPU_MACHINE_SUBFUNC);
+}
+
+void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
+{
+    struct kvm_s390_vm_cpu_machine prop = {};
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_MACHINE,
+        .addr = (uint64_t) &prop,
+    };
+    uint16_t unblocked_ibc = 0, cpu_type = 0;
+    int rc;
+
+    memset(model, 0, sizeof(*model));
+
+    if (!kvm_s390_cpu_models_supported()) {
+        error_setg(errp, "KVM doesn't support CPU models");
+        return;
+    }
+
+    /* query the basic cpu model properties */
+    rc = kvm_vm_ioctl(kvm_state, KVM_GET_DEVICE_ATTR, &attr);
+    if (rc) {
+        error_setg(errp, "KVM: Error querying host CPU model: %d", rc);
+        return;
+    }
+
+    cpu_type = cpuid_type(prop.cpuid);
+    if (has_ibc(prop.ibc)) {
+        model->lowest_ibc = lowest_ibc(prop.ibc);
+        unblocked_ibc = unblocked_ibc(prop.ibc);
+    }
+    model->cpu_id = cpuid_id(prop.cpuid);
+    model->cpu_ver = 0xff;
+
+    /* get supported cpu features indicated via STFL(E) */
+    s390_add_from_feat_block(model->features, S390_FEAT_TYPE_STFL,
+                             (uint8_t *) prop.fac_mask);
+    /* dat-enhancement facility 2 has no bit but was introduced with stfle */
+    if (test_bit(S390_FEAT_STFLE, model->features)) {
+        set_bit(S390_FEAT_DAT_ENH_2, model->features);
+    }
+    /* get supported cpu features indicated e.g. via SCLP */
+    rc = query_cpu_feat(model->features);
+    if (rc) {
+        error_setg(errp, "KVM: Error querying CPU features: %d", rc);
+        return;
+    }
+    /* get supported cpu subfunctions indicated via query / test bit */
+    rc = query_cpu_subfunc(model->features);
+    if (rc) {
+        error_setg(errp, "KVM: Error querying CPU subfunctions: %d", rc);
+        return;
+    }
+
+    if (s390_known_cpu_type(cpu_type)) {
+        /* we want the exact model, even if some features are missing */
+        model->def = s390_find_cpu_def(cpu_type, ibc_gen(unblocked_ibc),
+                                       ibc_ec_ga(unblocked_ibc), NULL);
+    } else {
+        /* model unknown, e.g. too new - search using features */
+        model->def = s390_find_cpu_def(0, ibc_gen(unblocked_ibc),
+                                       ibc_ec_ga(unblocked_ibc),
+                                       model->features);
+    }
+    if (!model->def) {
+        error_setg(errp, "KVM: host CPU model could not be identified");
+        return;
+    }
+    /* strip of features that are not part of the maximum model */
+    bitmap_and(model->features, model->features, model->def->full_feat,
+               S390_FEAT_MAX);
+}
+
+void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
+{
+    struct kvm_s390_vm_cpu_processor prop  = {
+        .fac_list = { 0 },
+    };
+    struct kvm_device_attr attr = {
+        .group = KVM_S390_VM_CPU_MODEL,
+        .attr = KVM_S390_VM_CPU_PROCESSOR,
+        .addr = (uint64_t) &prop,
+    };
+    int rc;
+
+    if (!model) {
+        return;
+    }
+    if (!kvm_s390_cpu_models_supported()) {
+        error_setg(errp, "KVM doesn't support CPU models");
+        return;
+    }
+    prop.cpuid = s390_cpuid_from_cpu_model(model);
+    prop.ibc = s390_ibc_from_cpu_model(model);
+    /* configure cpu features indicated via STFL(e) */
+    s390_fill_feat_block(model->features, S390_FEAT_TYPE_STFL,
+                         (uint8_t *) prop.fac_list);
+    rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+    if (rc) {
+        error_setg(errp, "KVM: Error configuring the CPU model: %d", rc);
+        return;
+    }
+    /* configure cpu features indicated e.g. via SCLP */
+    rc = configure_cpu_feat(model->features);
+    if (rc) {
+        error_setg(errp, "KVM: Error configuring CPU features: %d", rc);
+        return;
+    }
+    /* configure cpu subfunctions indicated via query / test bit */
+    rc = configure_cpu_subfunc(model->features);
+    if (rc) {
+        error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
+        return;
+    }
+}
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 22/29] s390x/kvm: disable host model for existing compat machines
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (20 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 21/29] s390x/kvm: implement CPU model support David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 23/29] s390x/kvm: let the CPU model control CMM(A) David Hildenbrand
                   ` (7 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Compatibility machines that touch runtime-instrumentation should not
be used with the CPU model. Otherwise the host model will look different,
depending on the QEMU machine QEMU has been started with.

So let's simply disable the host model for existing compatibility machines
that all disable ri.

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

diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index edebc6d..4020328 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -2451,6 +2451,10 @@ static int configure_cpu_feat(const S390FeatBitmap features)
 
 bool kvm_s390_cpu_models_supported(void)
 {
+    if (!ri_allowed()) {
+        /* compatibility machines interfere with the cpu model */
+        return false;
+    }
     return kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
                              KVM_S390_VM_CPU_MACHINE) &&
            kvm_vm_check_attr(kvm_state, KVM_S390_VM_CPU_MODEL,
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 23/29] s390x/kvm: let the CPU model control CMM(A)
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (21 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 22/29] s390x/kvm: disable host model for existing compat machines David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion" David Hildenbrand
                   ` (6 subsequent siblings)
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Starting with recent kernels, if the cmma attributes are available, we
actually have hardware support. Enabling CMMA then means providing the
guest VCPU with CMM, therefore enabling its CMM facility.

Let's not blindly enable CMM anymore but let's control it using CPU models.
For disabled CPU models, CMMA will continue to always get enabled.

Also enable it in the applicable default models.

Please note that CMM doesn't work with hugetlbfs, therefore we will
warn the user and keep it disabled. Migrating from/to a hugetlbfs
configuration works, as it will be disabled on both sides.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 target-s390x/gen-features.c |  1 +
 target-s390x/kvm.c          | 47 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/target-s390x/gen-features.c b/target-s390x/gen-features.c
index d4f4b29..52d46dc 100644
--- a/target-s390x/gen-features.c
+++ b/target-s390x/gen-features.c
@@ -371,6 +371,7 @@ static uint16_t full_GEN13_GA1[] = {
 #define default_GEN8_GA5 EmptyFeat
 static uint16_t default_GEN9_GA1[] = {
     S390_FEAT_GROUP_MSA_EXT_1,
+    S390_FEAT_CMM,
 };
 #define default_GEN9_GA2 EmptyFeat
 #define default_GEN9_GA3 EmptyFeat
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 4020328..a089c03 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -174,6 +174,18 @@ int kvm_s390_set_mem_limit(KVMState *s, uint64_t new_limit, uint64_t *hw_limit)
     return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
 }
 
+static bool kvm_s390_cmma_available(void)
+{
+    static bool initialized, value;
+
+    if (!initialized) {
+        initialized = true;
+        value = kvm_vm_check_mem_attr(kvm_state, KVM_S390_VM_MEM_ENABLE_CMMA) &&
+                kvm_vm_check_mem_attr(kvm_state, KVM_S390_VM_MEM_CLR_CMMA);
+    }
+    return value;
+}
+
 void kvm_s390_cmma_reset(void)
 {
     int rc;
@@ -182,11 +194,15 @@ void kvm_s390_cmma_reset(void)
         .attr = KVM_S390_VM_MEM_CLR_CMMA,
     };
 
+    if (!mem_path || !kvm_s390_cmma_available()) {
+        return;
+    }
+
     rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
     trace_kvm_clear_cmma(rc);
 }
 
-static void kvm_s390_enable_cmma(KVMState *s)
+static void kvm_s390_enable_cmma(void)
 {
     int rc;
     struct kvm_device_attr attr = {
@@ -194,12 +210,7 @@ static void kvm_s390_enable_cmma(KVMState *s)
         .attr = KVM_S390_VM_MEM_ENABLE_CMMA,
     };
 
-    if (!kvm_vm_check_mem_attr(s, KVM_S390_VM_MEM_ENABLE_CMMA) ||
-        !kvm_vm_check_mem_attr(s, KVM_S390_VM_MEM_CLR_CMMA)) {
-        return;
-    }
-
-    rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr);
+    rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
     trace_kvm_enable_cmma(rc);
 }
 
@@ -259,10 +270,6 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
     cap_mem_op = kvm_check_extension(s, KVM_CAP_S390_MEM_OP);
     cap_s390_irq = kvm_check_extension(s, KVM_CAP_S390_INJECT_IRQ);
 
-    if (!mem_path) {
-        kvm_s390_enable_cmma(s);
-    }
-
     if (!kvm_check_extension(s, KVM_CAP_S390_GMAP)
         || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
         phys_mem_set_alloc(legacy_s390_alloc);
@@ -2520,6 +2527,11 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)
         return;
     }
 
+    /* with cpu model support, CMM is only indicated if really available */
+    if (kvm_s390_cmma_available()) {
+        set_bit(S390_FEAT_CMM, model->features);
+    }
+
     if (s390_known_cpu_type(cpu_type)) {
         /* we want the exact model, even if some features are missing */
         model->def = s390_find_cpu_def(cpu_type, ibc_gen(unblocked_ibc),
@@ -2552,6 +2564,10 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
     int rc;
 
     if (!model) {
+        /* compatibility handling if cpu models are disabled */
+        if (kvm_s390_cmma_available() && !mem_path) {
+            kvm_s390_enable_cmma();
+        }
         return;
     }
     if (!kvm_s390_cpu_models_supported()) {
@@ -2580,4 +2596,13 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)
         error_setg(errp, "KVM: Error configuring CPU subfunctions: %d", rc);
         return;
     }
+    /* enable CMM via CMMA - disable on hugetlbfs */
+    if (test_bit(S390_FEAT_CMM, model->features)) {
+        if (mem_path) {
+            error_report("Warning: CMM will not be enabled because it is not "
+                         "compatible to hugetlbfs.");
+        } else {
+            kvm_s390_enable_cmma();
+        }
+    }
 }
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (22 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 23/29] s390x/kvm: let the CPU model control CMM(A) David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 13:45   ` Eduardo Habkost
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
                   ` (5 subsequent siblings)
  29 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's provide a standardized interface to expand CPU models, like the
host model. This interface can be used by tooling to get details about a
specific CPU model, e.g. the "host" model.

To take care of all architectures, two detail levels for an expansion
are introduced. Certain architectures might not support all detail levels.
While "full" will expand and indicate all relevant properties/features
of a CPU model, "static" expands to a static base CPU model, that will
never change between QEMU versions and therefore have the same features
when used under different compatibility machines.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 include/sysemu/arch_init.h             |  3 ++
 qapi-schema.json                       | 86 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx                        |  6 +++
 qmp.c                                  |  7 +++
 stubs/Makefile.objs                    |  1 +
 stubs/arch-query-cpu-model-expansion.c | 12 +++++
 6 files changed, 115 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-expansion.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index d690dfa..37b2e86 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -35,5 +35,8 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
+                                                      CpuModelInfo *mode,
+                                                      Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 3f50c1d..43f7969 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3063,6 +3063,92 @@
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model.
+#
+# A CPU model consists of the name of a CPU definition, to which
+# delta changes are applied (e.g. features added/removed). Most magic values
+# that an architecture might require should be hidden behind the name.
+# However, if required, architectures can expose relevant properties.
+#
+# @name: the name of the CPU definition the model is based on
+# @props: #optional a dictionary of properties to be applied
+#
+# Since: 2.8.0
+##
+{ 'struct': 'CpuModelInfo',
+  'data': { 'name': 'str',
+            '*props': 'any' } }
+
+##
+# @CpuModelExpansionType
+#
+# An enumeration of CPU model expansion types.
+#
+# @static: Expand to a static CPU model, a combination of a static base
+#          model name and property delta changes. As the static base model will
+#          never change, the expanded CPU model will be the same, independant of
+#          QEMU version or compatibility machines. Therefore, the resulting
+#          model can be used by tooling without having to specify a
+#          compatibility machine - e.g. when displaying the "host" model.
+#          All static CPU models are migration-safe.
+#
+# @full: Expand all properties. The produced model is not guaranteed to be
+#        migration-safe, but allows tooling to get an insight and work with
+#        model details.
+#
+# Since: 2.8.0
+##
+{ 'enum': 'CpuModelExpansionType',
+  'data': [ 'static', 'full' ] }
+
+
+##
+# @CpuModelExpansionInfo
+#
+# The result of a cpu model expansion.
+#
+# @model: the expanded CpuModelInfo.
+#
+# Since: 2.8.0
+##
+{ 'struct': 'CpuModelExpansionInfo',
+  'data': { 'model': 'CpuModelInfo' } }
+
+
+##
+# @query-cpu-model-expansion:
+#
+# Expands the given CPU model to different granularities, allowing tooling
+# to get an understanding what a specific CPU model looks like in QEMU
+# under a certain QEMU machine.
+#
+# Expanding CPU models is in general independant of the accelerator, except
+# for models like "host" that explicitly rely on an accelerator and can
+# vary in different configurations. This interface can therefore also be used
+# to query the "host" CPU model.
+#
+# Note: This interface should not be used when global properties of CPU classes
+#       are changed (e.g. via "-cpu ...").
+#
+# s390x supports expanding of all CPU models with all expansion types. Other
+# architectures are not supported yet.
+#
+# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU models is
+#          not supported, if the model cannot be expanded, if the model contains
+#          an unknown CPU definition name, unknown properties or properties
+#          with a wrong type. Also returns an error if an expansion type is
+#          not supported.
+#
+# Since: 2.8.0
+##
+{ 'command': 'query-cpu-model-expansion',
+  'data': { 'type': 'CpuModelExpansionType',
+            'model': 'CpuModelInfo' },
+  'returns': 'CpuModelExpansionInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index c8d360a..7ed9528 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3942,6 +3942,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model-expansion",
+        .args_type  = "type:s,model:q",
+        .mhandler.cmd_new = qmp_marshal_query_cpu_model_expansion,
+    },
+
+    {
         .name       = "query-target",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_query_target,
diff --git a/qmp.c b/qmp.c
index b6d531e..29fbfb8 100644
--- a/qmp.c
+++ b/qmp.c
@@ -607,6 +607,13 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
     return arch_query_cpu_definitions(errp);
 }
 
+CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
+                                                     CpuModelInfo *model,
+                                                     Error **errp)
+{
+    return arch_query_cpu_model_expansion(type, model, errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
                     bool has_skipauth, bool skipauth, bool has_tls, bool tls,
                     Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 55edd15..4929842 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,4 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-model-expansion.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
diff --git a/stubs/arch-query-cpu-model-expansion.c b/stubs/arch-query-cpu-model-expansion.c
new file mode 100644
index 0000000..ae7cf55
--- /dev/null
+++ b/stubs/arch-query-cpu-model-expansion.c
@@ -0,0 +1,12 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
+                                                      CpuModelInfo *mode,
+                                                      Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (23 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion" David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 14:45   ` Eduardo Habkost
  2016-08-04  7:34   ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline" David Hildenbrand
                   ` (4 subsequent siblings)
  29 siblings, 2 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's provide a standardized interface to compare two CPU models.

query-cpu-model-compare takes two models and returns what it knows about
their compability under a certain QEMU machine QEMU has been started with.

If modelA is a subset of modelB or if both are identical, modelA will run
in the same configuration as modelB. If modelA is however a superset of
modelB or if both are incompatible, one can try to create a compatible one
by "baselining" both models (follow up patch).

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 include/sysemu/arch_init.h              |  3 ++
 qapi-schema.json                        | 65 +++++++++++++++++++++++++++++++++
 qmp-commands.hx                         |  6 +++
 qmp.c                                   |  7 ++++
 stubs/Makefile.objs                     |  1 +
 stubs/arch-query-cpu-model-comparison.c | 12 ++++++
 6 files changed, 94 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-comparison.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 37b2e86..96d47c0 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -38,5 +38,8 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
 CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
                                                       CpuModelInfo *mode,
                                                       Error **errp);
+CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela,
+                                                     CpuModelInfo *modelb,
+                                                     Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 43f7969..1f8f8ec 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3149,6 +3149,71 @@
             'model': 'CpuModelInfo' },
   'returns': 'CpuModelExpansionInfo' }
 
+##
+# @CpuModelCompareResult:
+#
+# An enumeration of CPU model comparation results.
+#
+# @incompatible: both model definition are incompatible
+#
+# @identical: model A == model B
+#
+# @superset: model A > model B
+#
+# @subset: model A < model B
+#
+# Since: 2.8.0
+##
+{ 'enum': 'CpuModelCompareResult',
+  'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }
+
+##
+# @CpuModelCompareInfo
+#
+# The result of a CPU model comparison.
+#
+# @result: The result of the compare operation.
+# @responsible-properties: List of properties that led to the comparison result
+#                          not being identical.
+#
+# @responsible-properties is a list of QOM property names that led to
+# both CPUs not being detected as identical. For identical models, this
+# list is empty.
+# If a QOM property is read-only, that means there's no known way to make the
+# CPU models identical. If the special property name "type" is included, the
+# models are by definition not identical and cannot be made identical.
+#
+# Since: 2.8.0
+##
+{ 'struct': 'CpuModelCompareInfo',
+  'data': {'result': 'CpuModelCompareResult',
+           'responsible-properties': ['str']
+          }
+}
+
+##
+# @query-cpu-model-comparison:
+#
+# Compares two CPU models, returning how they compare under a specific QEMU
+# machine.
+#
+# Note: This interface should not be used when global properties of CPU classes
+#       are changed (e.g. via "-cpu ...").
+#
+# s390x supports comparing of all CPU models. Other architectures are not
+# supported yet.
+#
+# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU models is
+#          not supported, if a model cannot be used, if a model contains
+#          an unknown cpu definition name, unknown properties or properties
+#          with wrong types.
+#
+# Since: 2.8.0
+##
+{ 'command': 'query-cpu-model-comparison',
+  'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
+  'returns': 'CpuModelCompareInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7ed9528..0af2098 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3948,6 +3948,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model-comparison",
+        .args_type  = "modela:q,modelb:q",
+        .mhandler.cmd_new = qmp_marshal_query_cpu_model_comparison,
+    },
+
+    {
         .name       = "query-target",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_query_target,
diff --git a/qmp.c b/qmp.c
index 29fbfb8..f551019 100644
--- a/qmp.c
+++ b/qmp.c
@@ -614,6 +614,13 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
     return arch_query_cpu_model_expansion(type, model, errp);
 }
 
+CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
+                                                    CpuModelInfo *modelb,
+                                                    Error **errp)
+{
+    return arch_query_cpu_model_comparison(modela, modelb, errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
                     bool has_skipauth, bool skipauth, bool has_tls, bool tls,
                     Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 4929842..da768f0 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,5 +1,6 @@
 stub-obj-y += arch-query-cpu-def.o
 stub-obj-y += arch-query-cpu-model-expansion.o
+stub-obj-y += arch-query-cpu-model-comparison.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
diff --git a/stubs/arch-query-cpu-model-comparison.c b/stubs/arch-query-cpu-model-comparison.c
new file mode 100644
index 0000000..d5486ae
--- /dev/null
+++ b/stubs/arch-query-cpu-model-comparison.c
@@ -0,0 +1,12 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela,
+                                                     CpuModelInfo *modelb,
+                                                     Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (24 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-04  7:32   ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" David Hildenbrand
                   ` (3 subsequent siblings)
  29 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's provide a standardized interface to baseline two CPU models, to
create a third, compatible one.

The returned CPU model is a static CPU model, so it will never change
between QEMU machines.

Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
 include/sysemu/arch_init.h            |  3 +++
 qapi-schema.json                      | 38 +++++++++++++++++++++++++++++++++++
 qmp-commands.hx                       |  6 ++++++
 qmp.c                                 |  7 +++++++
 stubs/Makefile.objs                   |  1 +
 stubs/arch-query-cpu-model-baseline.c | 12 +++++++++++
 6 files changed, 67 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-baseline.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 96d47c0..1c9dad1 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -41,5 +41,8 @@ CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type
 CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela,
                                                      CpuModelInfo *modelb,
                                                      Error **errp);
+CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela,
+                                                    CpuModelInfo *modelb,
+                                                    Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 1f8f8ec..4e21a86 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3214,6 +3214,44 @@
   'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
   'returns': 'CpuModelCompareInfo' }
 
+##
+# @CpuModelBaselineInfo
+#
+# The result of a CPU model baseline.
+#
+# @model: the baselined CpuModelInfo.
+#
+# Since: 2.8.0
+##
+{ 'struct': 'CpuModelBaselineInfo',
+  'data': { 'model': 'CpuModelInfo' } }
+
+##
+# @query-cpu-model-baseline:
+#
+# Baseline two CPU models, creating a compatible third model. The created
+# model will always be a static, migration-safe CPU model (see "static"
+# CPU model expansion for details). The QEMU machine QEMU has been started
+# with affects the result if CPU definitions are used that are not static.
+#
+# Note: This interface should not be used when global properties of CPU classes
+#       are changed (e.g. via "-cpu ...").
+#
+# s390x supports baselining of all CPU models. Other architectures are not
+# supported yet.
+#
+# Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU models is
+#          not supported, if a model cannot be used, if a model contains
+#          an unknown cpu definition name, unknown properties or properties
+#          with wrong types.
+#
+# Since: 2.8.0
+##
+{ 'command': 'query-cpu-model-baseline',
+  'data': { 'modela': 'CpuModelInfo',
+            'modelb': 'CpuModelInfo' },
+  'returns': 'CpuModelBaselineInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 0af2098..8abccb9 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3954,6 +3954,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model-baseline",
+        .args_type  = "modela:q,modelb:q",
+        .mhandler.cmd_new = qmp_marshal_query_cpu_model_baseline,
+    },
+
+    {
         .name       = "query-target",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_query_target,
diff --git a/qmp.c b/qmp.c
index f551019..dea8f81 100644
--- a/qmp.c
+++ b/qmp.c
@@ -621,6 +621,13 @@ CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
     return arch_query_cpu_model_comparison(modela, modelb, errp);
 }
 
+CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *modela,
+                                                   CpuModelInfo *modelb,
+                                                   Error **errp)
+{
+    return arch_query_cpu_model_baseline(modela, modelb, errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
                     bool has_skipauth, bool skipauth, bool has_tls, bool tls,
                     Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index da768f0..c5850e8 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,6 +1,7 @@
 stub-obj-y += arch-query-cpu-def.o
 stub-obj-y += arch-query-cpu-model-expansion.o
 stub-obj-y += arch-query-cpu-model-comparison.o
+stub-obj-y += arch-query-cpu-model-baseline.o
 stub-obj-y += bdrv-next-monitor-owned.o
 stub-obj-y += blk-commit-all.o
 stub-obj-y += blockdev-close-all-bdrv-states.o
diff --git a/stubs/arch-query-cpu-model-baseline.c b/stubs/arch-query-cpu-model-baseline.c
new file mode 100644
index 0000000..094ec13
--- /dev/null
+++ b/stubs/arch-query-cpu-model-baseline.c
@@ -0,0 +1,12 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *modela,
+                                                    CpuModelInfo *modelb,
+                                                    Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (25 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline" David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 14:22   ` Eduardo Habkost
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 28/29] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison" David Hildenbrand
                   ` (2 subsequent siblings)
  29 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

In order to expand CPU models, we create temporary cpus that handle the
feature/group parsing.

When converting the data structure back, we always fall back to the
static base CPU model, which is by definition migration-safe.

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

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index b2d722b..6353b8c 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -16,6 +16,9 @@
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qemu/error-report.h"
+#include "qapi/qmp/qerror.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp/qbool.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
@@ -300,6 +303,146 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
 
     return list;
 }
+
+static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
+                                Error **errp)
+{
+    const QDict *qdict = NULL;
+    const QDictEntry *e;
+    Visitor *visitor;
+    ObjectClass *oc;
+    S390CPU *cpu;
+    Object *obj;
+
+    if (info->props) {
+        qdict = qobject_to_qdict(info->props);
+        if (!qdict) {
+            error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict");
+            return;
+        }
+    }
+
+    oc = cpu_class_by_name(TYPE_S390_CPU, info->name);
+    if (!oc) {
+        error_setg(errp, "The CPU definition \'%s\' is unknown.", info->name);
+        return;
+    }
+    if (S390_CPU_CLASS(oc)->kvm_required && !kvm_enabled()) {
+        error_setg(errp, "The CPU definition '%s' requires KVM", info->name);
+        return;
+    }
+    obj = object_new(object_class_get_name(oc));
+    cpu = S390_CPU(obj);
+
+    if (!cpu->model) {
+        error_setg(errp, "Details about the host CPU model are not available, "
+                         "it cannot be used.");
+        object_unref(obj);
+        return;
+    }
+
+    if (qdict) {
+        visitor = qmp_input_visitor_new(info->props, true);
+        visit_start_struct(visitor, NULL, NULL, 0, errp);
+        if (*errp) {
+            object_unref(obj);
+            return;
+        }
+        for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+            object_property_set(obj, visitor, e->key, errp);
+            if (*errp) {
+                break;
+            }
+        }
+        if (!*errp) {
+            visit_check_struct(visitor, errp);
+        }
+        visit_end_struct(visitor, NULL);
+        visit_free(visitor);
+        if (*errp) {
+            object_unref(obj);
+            return;
+        }
+    }
+
+    /* copy the model and throw the cpu away */
+    memcpy(model, cpu->model, sizeof(*model));
+    object_unref(obj);
+}
+
+static void qdict_add_disabled_feat(const char *name, void *opaque)
+{
+    qdict_put((QDict *) opaque, name, qbool_from_bool(false));
+}
+
+static void qdict_add_enabled_feat(const char *name, void *opaque)
+{
+    qdict_put((QDict *) opaque, name, qbool_from_bool(true));
+}
+
+/* convert S390CPUDef into a static CpuModelInfo */
+static void cpu_info_from_model(CpuModelInfo *info, const S390CPUModel *model,
+                                bool delta_changes)
+{
+    QDict *qdict = qdict_new();
+    S390FeatBitmap bitmap;
+
+    /* always fallback to the static base model */
+    info->name = g_strdup_printf("%s-base", model->def->name);
+
+    if (delta_changes) {
+        /* features deleted from the base feature set */
+        bitmap_andnot(bitmap, model->def->base_feat, model->features,
+                      S390_FEAT_MAX);
+        if (!bitmap_empty(bitmap, S390_FEAT_MAX)) {
+            s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat);
+        }
+
+        /* features added to the base feature set */
+        bitmap_andnot(bitmap, model->features, model->def->base_feat,
+                      S390_FEAT_MAX);
+        if (!bitmap_empty(bitmap, S390_FEAT_MAX)) {
+            s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_enabled_feat);
+        }
+    } else {
+        /* expand all features */
+        s390_feat_bitmap_to_ascii(model->features, qdict, qdict_add_enabled_feat);
+        bitmap_complement(bitmap, model->features, S390_FEAT_MAX);
+        s390_feat_bitmap_to_ascii(bitmap, qdict, qdict_add_disabled_feat);
+    }
+
+    if (!qdict_size(qdict)) {
+        QDECREF(qdict);
+    } else {
+        info->props = QOBJECT(qdict);
+        info->has_props = true;
+    }
+}
+
+CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
+                                                      CpuModelInfo *model,
+                                                      Error **errp)
+{
+    CpuModelExpansionInfo *expansion_info = NULL;
+    S390CPUModel s390_model;
+    bool delta_changes = false;
+
+    /* convert it to our internal representation */
+    cpu_model_from_info(&s390_model, model, errp);
+    if (*errp) {
+        return NULL;
+    }
+
+    if (type == CPU_MODEL_EXPANSION_TYPE_STATIC) {
+        delta_changes = true;
+    }
+
+    /* convert it back to a static representation */
+    expansion_info = g_malloc0(sizeof(*expansion_info));
+    expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
+    cpu_info_from_model(expansion_info->model, &s390_model, delta_changes);
+    return expansion_info;
+}
 #endif
 
 static void check_consistency(const S390CPUModel *model)
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 28/29] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (26 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 29/29] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline" David Hildenbrand
  2016-08-02 17:28 ` [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features Eduardo Habkost
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's implement that interface by reusing our convertion code
implemented for expansion.

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

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 6353b8c..22feebe 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -443,6 +443,90 @@ CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type
     cpu_info_from_model(expansion_info->model, &s390_model, delta_changes);
     return expansion_info;
 }
+
+static void list_add_feat(const char *name, void *opaque)
+{
+    strList **last = (strList **) opaque;
+    strList *entry;
+
+    entry = g_malloc0(sizeof(*entry));
+    entry->value = g_strdup(name);
+    entry->next = *last;
+    *last = entry;
+}
+
+CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
+                                                     CpuModelInfo *infob,
+                                                     Error **errp)
+{
+    CpuModelCompareResult feat_result, gen_result;
+    CpuModelCompareInfo *compare_info;
+    S390FeatBitmap missing, added;
+    S390CPUModel modela, modelb;
+
+    /* convert both models to our internal representation */
+    cpu_model_from_info(&modela, infoa, errp);
+    if (*errp) {
+        return NULL;
+    }
+    cpu_model_from_info(&modelb, infob, errp);
+    if (*errp) {
+        return NULL;
+    }
+    compare_info = g_malloc0(sizeof(*compare_info));
+
+    /* check the cpu generation and ga level */
+    if (modela.def->gen == modelb.def->gen) {
+        if (modela.def->ec_ga == modelb.def->ec_ga) {
+            /* ec and corresponding bc are identical */
+            gen_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL;
+        } else if (modela.def->ec_ga < modelb.def->ec_ga) {
+            gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
+        } else {
+            gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
+        }
+    } else if (modela.def->gen < modelb.def->gen) {
+        gen_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
+    } else {
+        gen_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
+    }
+    if (gen_result != CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
+        /* both models cannot be made identical */
+        list_add_feat("type", &compare_info->responsible_properties);
+    }
+
+    /* check the feature set */
+    if (bitmap_equal(modela.features, modelb.features, S390_FEAT_MAX)) {
+        feat_result = CPU_MODEL_COMPARE_RESULT_IDENTICAL;
+    } else {
+        bitmap_andnot(missing, modela.features, modelb.features, S390_FEAT_MAX);
+        s390_feat_bitmap_to_ascii(missing,
+                                  &compare_info->responsible_properties,
+                                  list_add_feat);
+        bitmap_andnot(added, modelb.features, modela.features, S390_FEAT_MAX);
+        s390_feat_bitmap_to_ascii(added, &compare_info->responsible_properties,
+                                  list_add_feat);
+        if (bitmap_empty(missing, S390_FEAT_MAX)) {
+            feat_result = CPU_MODEL_COMPARE_RESULT_SUBSET;
+        } else if (bitmap_empty(added, S390_FEAT_MAX)) {
+            feat_result = CPU_MODEL_COMPARE_RESULT_SUPERSET;
+        } else {
+            feat_result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE;
+        }
+    }
+
+    /* combine the results */
+    if (gen_result == feat_result) {
+        compare_info->result = gen_result;
+    } else if (feat_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
+        compare_info->result = gen_result;
+    } else if (gen_result == CPU_MODEL_COMPARE_RESULT_IDENTICAL) {
+        compare_info->result = feat_result;
+    } else {
+        compare_info->result = CPU_MODEL_COMPARE_RESULT_INCOMPATIBLE;
+    }
+    return compare_info;
+}
 #endif
 
 static void check_consistency(const S390CPUModel *model)
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* [Qemu-devel] [Patch v1 29/29] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline"
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (27 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 28/29] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison" David Hildenbrand
@ 2016-08-02 11:59 ` David Hildenbrand
  2016-08-02 17:28 ` [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features Eduardo Habkost
  29 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 11:59 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

Let's implement that interface by reusing our conversion code and
lookup code for CPU definitions.

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

diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index 22feebe..476bb76 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -527,6 +527,61 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
     }
     return compare_info;
 }
+
+CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelInfo *infoa,
+                                                    CpuModelInfo *infob,
+                                                    Error **errp)
+{
+    CpuModelBaselineInfo *baseline_info;
+    S390CPUModel modela, modelb, model;
+    uint16_t cpu_type;
+    uint8_t max_gen_ga;
+    uint8_t max_gen;
+
+    /* convert both models to our internal representation */
+    cpu_model_from_info(&modela, infoa, errp);
+    if (*errp) {
+        return NULL;
+    }
+
+    cpu_model_from_info(&modelb, infob, errp);
+    if (*errp) {
+        return NULL;
+    }
+
+    /* features both models support */
+    bitmap_and(model.features, modela.features, modelb.features, S390_FEAT_MAX);
+
+    /* detect the maximum model not regarding features */
+    if (modela.def->gen == modelb.def->gen) {
+        if (modela.def->type == modelb.def->type) {
+            cpu_type = modela.def->type;
+        } else {
+            cpu_type = 0;
+        }
+        max_gen = modela.def->gen;
+        max_gen_ga = MIN(modela.def->ec_ga, modelb.def->ec_ga);
+    } else if (modela.def->gen > modelb.def->gen) {
+        cpu_type = modelb.def->type;
+        max_gen = modelb.def->gen;
+        max_gen_ga = modelb.def->ec_ga;
+    } else {
+        cpu_type = modela.def->type;
+        max_gen = modela.def->gen;
+        max_gen_ga = modela.def->ec_ga;
+    }
+
+    model.def = s390_find_cpu_def(cpu_type, max_gen, max_gen_ga,
+                                  model.features);
+    /* strip off features not part of the max model */
+    bitmap_and(model.features, model.features, model.def->full_feat,
+               S390_FEAT_MAX);
+
+    baseline_info = g_malloc0(sizeof(*baseline_info));
+    baseline_info->model = g_malloc0(sizeof(*baseline_info->model));
+    cpu_info_from_model(baseline_info->model, &model, true);
+    return baseline_info;
+}
 #endif
 
 static void check_consistency(const S390CPUModel *model)
-- 
2.6.6

^ permalink raw reply related	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features David Hildenbrand
@ 2016-08-02 12:31   ` Thomas Huth
  2016-08-02 13:00     ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Thomas Huth @ 2016-08-02 12:31 UTC (permalink / raw)
  To: David Hildenbrand, qemu-devel
  Cc: ehabkost, borntraeger, fiuczy, cornelia.huck, imammedo, jdenemar, mimu

On 02.08.2016 13:59, David Hildenbrand wrote:
> We have three different blocks in the SCLP read-SCP information response
> that indicate sclp features. Let's prepare propagation.
> 
> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> ---
>  hw/s390x/sclp.c           |  9 +++++++++
>  target-s390x/cpu_models.c | 14 ++++++++++++++
>  target-s390x/cpu_models.h |  1 +
>  3 files changed, 24 insertions(+)
> 
> diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
> index 15d7114..3c126ee 100644
> --- a/hw/s390x/sclp.c
> +++ b/hw/s390x/sclp.c
> @@ -31,11 +31,14 @@ static inline SCLPDevice *get_sclp_device(void)
>  
>  static void prepare_cpu_entries(SCLPDevice *sclp, CPUEntry *entry, int count)
>  {
> +    uint8_t features[SCCB_CPU_FEATURE_LEN] = { 0 };
>      int i;
>  
> +    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CPU, features);
>      for (i = 0; i < count; i++) {
>          entry[i].address = i;
>          entry[i].type = 0;
> +        memcpy(entry[i].features, features, sizeof(entry[i].features));
>      }
>  }
>  
> @@ -59,6 +62,12 @@ static void read_SCP_info(SCLPDevice *sclp, SCCB *sccb)
>      read_info->offset_cpu = cpu_to_be16(offsetof(ReadInfo, entries));
>      read_info->highest_cpu = cpu_to_be16(max_cpus);
>  
> +    /* Configuration Characteristic (Extension) */
> +    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR,
> +                         read_info->conf_char);
> +    s390_get_feat_block(S390_FEAT_TYPE_SCLP_CONF_CHAR_EXT,
> +                         read_info->conf_char_ext);
> +
>      prepare_cpu_entries(sclp, read_info->entries, cpu_count);
>  
>      read_info->facilities = cpu_to_be64(SCLP_HAS_CPU_INFO |
> diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
> index 3fe85fa..641aad0 100644
> --- a/target-s390x/cpu_models.c
> +++ b/target-s390x/cpu_models.c
> @@ -74,6 +74,20 @@ static const S390CPUDef s390_cpu_defs[] = {
>      CPUDEF_INIT(0x2965, 13, 2, 47, 0x08000000U, "z13s", "IBM z13s GA1"),
>  };
>  
> +void s390_get_feat_block(S390FeatType type, uint8_t *data)
> +{
> +    static S390CPU *cpu;
> +
> +    if (!cpu) {
> +        cpu = S390_CPU(qemu_get_cpu(0));
> +    }
> +
> +    if (!cpu || !cpu->model) {
> +        return;
> +    }
> +    return s390_fill_feat_block(cpu->model->features, type, data);

IMHO it's somewhat strange to write "return something()" in a function
that has been declared as "void". I know GCC does not reject this, but
anyway, I'd suggest to simply remove the "return" keyword here.

 Thomas

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features
  2016-08-02 12:31   ` Thomas Huth
@ 2016-08-02 13:00     ` David Hildenbrand
  0 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 13:00 UTC (permalink / raw)
  To: Thomas Huth
  Cc: qemu-devel, ehabkost, borntraeger, fiuczy, cornelia.huck,
	imammedo, jdenemar, mimu


> > +void s390_get_feat_block(S390FeatType type, uint8_t *data)
> > +{
> > +    static S390CPU *cpu;
> > +
> > +    if (!cpu) {
> > +        cpu = S390_CPU(qemu_get_cpu(0));
> > +    }
> > +
> > +    if (!cpu || !cpu->model) {
> > +        return;
> > +    }
> > +    return s390_fill_feat_block(cpu->model->features, type, data);  
> 
> IMHO it's somewhat strange to write "return something()" in a function
> that has been declared as "void". I know GCC does not reject this, but
> anyway, I'd suggest to simply remove the "return" keyword here.
> 
>  Thomas

Yes, that looks like a leftover, thanks Thomas!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 11:58 ` [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
@ 2016-08-02 13:04   ` Eduardo Habkost
  2016-08-02 13:23     ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 13:04 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 01:58:47PM +0200, David Hildenbrand wrote:
> It might be of interest for tooling whether a CPU definition can be safely
> used when migrating, or if e.g. CPU features might get lost during
> migration when migrationg from/to a different QEMU version or host, even if
> the same compatibility machine is used.
> 
> Also, we want to know if a CPU definition is static and will never change.
> Beause these definitions can then be used independantly of a compatibility
> machine and will always have the same feature set, they can e.g. be used
> to indicate the "host" model in libvirt later on.
> 
> Let's add optional return values to query-cpu-definitions, stating for
> each returned CPU definition, if it is migration-safe and if it is static.
> 
> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> ---
>  qapi-schema.json | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 5658723..3f50c1d 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3038,10 +3038,19 @@
>  #
>  # @name: the name of the CPU definition
>  #
> +# @migration-safe: #optional whether a CPU definition can be safely used for
> +#                  migration in combination with a QEMU compatibility machine
> +#                  when migrating between different QMU versions and hosts.
> +#                  If not provided, information is not available.

I would be more explicit about migration between different hosts.
I suggest "between different QEMU versions and between hosts with
different sets of (hardware or software) capabilities".

Maybe we should make the "if not provided" case clearer. Maybe
"if not provided, information is not available and caller should
not assume the CPU model is migration-safe". We know that
existing libvirt x86 code assumes all CPU models (except "host")
are migration-safe, but it's better to advise people to not try
to make any assumptions in new code.

Later, we need to document somewhere that the "migratable"
property in "host" does not mean "migration-safe" (at least in
x86), because migration of "host" is safe only if the host
(software and hardware) capabilities are exactly the same.

For reference: in x86, all CPU models except "host" are
migration-safe.

> +#
> +# @static: #optional whether a CPU definition is static and will not change
> +#          between QEMU versions / QEMU machines. A static model is always
> +#          migration-safe. If not provided, information is not available.

I assume static models don't change depending on the
machine-type, either. If that's case, we should document that.

I believe in this case we don't need to make it optional: just
make the field always present and set it to "false" by default.

> +#
>  # Since: 1.2.0
>  ##
>  { 'struct': 'CpuDefinitionInfo',
> -  'data': { 'name': 'str' } }
> +  'data': { 'name': 'str', '*migration-safe' : 'bool', '*static' : 'bool' } }
>  
>  ##
>  # @query-cpu-definitions:
> -- 
> 2.6.6
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 13:04   ` Eduardo Habkost
@ 2016-08-02 13:23     ` David Hildenbrand
  2016-08-02 14:00       ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 13:23 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu


> >  # @name: the name of the CPU definition
> >  #
> > +# @migration-safe: #optional whether a CPU definition can be safely used for
> > +#                  migration in combination with a QEMU compatibility machine
> > +#                  when migrating between different QMU versions and hosts.
> > +#                  If not provided, information is not available.  
> 
> I would be more explicit about migration between different hosts.
> I suggest "between different QEMU versions and between hosts with
> different sets of (hardware or software) capabilities".

Sounds good to me.

> 
> Maybe we should make the "if not provided" case clearer. Maybe
> "if not provided, information is not available and caller should
> not assume the CPU model is migration-safe". We know that
> existing libvirt x86 code assumes all CPU models (except "host")
> are migration-safe, but it's better to advise people to not try
> to make any assumptions in new code.

Also sounds good to me.

> 
> Later, we need to document somewhere that the "migratable"
> property in "host" does not mean "migration-safe" (at least in
> x86), because migration of "host" is safe only if the host
> (software and hardware) capabilities are exactly the same.
> 

Right, this will be a special case, also once we have that for s390x.

> For reference: in x86, all CPU models except "host" are
> migration-safe.

Yes, that was my conclusion and that's also why I turned all s390x models
(except host) into migration-safe models. Makes a lot of things easier to
handle.

> 
> > +#
> > +# @static: #optional whether a CPU definition is static and will not change
> > +#          between QEMU versions / QEMU machines. A static model is always
> > +#          migration-safe. If not provided, information is not available.  
> 
> I assume static models don't change depending on the
> machine-type, either. If that's case, we should document that.

That's what I meant with "QEMU machines", should that be "QEMU machine types"
instead?

> 
> I believe in this case we don't need to make it optional: just
> make the field always present and set it to "false" by default.

That is true for x86, do you know about the other architectures (arm, ppc)?
I'd like to avoid returning false information here for other architectures.

Thanks Eduardo!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion"
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion" David Hildenbrand
@ 2016-08-02 13:45   ` Eduardo Habkost
  2016-08-02 15:04     ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 13:45 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 01:59:10PM +0200, David Hildenbrand wrote:
> Let's provide a standardized interface to expand CPU models, like the
> host model. This interface can be used by tooling to get details about a
> specific CPU model, e.g. the "host" model.
> 
> To take care of all architectures, two detail levels for an expansion
> are introduced. Certain architectures might not support all detail levels.
> While "full" will expand and indicate all relevant properties/features
> of a CPU model, "static" expands to a static base CPU model, that will
> never change between QEMU versions and therefore have the same features
> when used under different compatibility machines.
> 
> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> ---
>  include/sysemu/arch_init.h             |  3 ++
>  qapi-schema.json                       | 86 ++++++++++++++++++++++++++++++++++
>  qmp-commands.hx                        |  6 +++
>  qmp.c                                  |  7 +++
>  stubs/Makefile.objs                    |  1 +
>  stubs/arch-query-cpu-model-expansion.c | 12 +++++
>  6 files changed, 115 insertions(+)
>  create mode 100644 stubs/arch-query-cpu-model-expansion.c
> 
> diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
> index d690dfa..37b2e86 100644
> --- a/include/sysemu/arch_init.h
> +++ b/include/sysemu/arch_init.h
> @@ -35,5 +35,8 @@ int kvm_available(void);
>  int xen_available(void);
>  
>  CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
> +CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
> +                                                      CpuModelInfo *mode,
> +                                                      Error **errp);
>  
>  #endif
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 3f50c1d..43f7969 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3063,6 +3063,92 @@
>  ##
>  { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
>  
> +##
> +# @CpuModelInfo:
> +#
> +# Virtual CPU model.
> +#
> +# A CPU model consists of the name of a CPU definition, to which
> +# delta changes are applied (e.g. features added/removed). Most magic values
> +# that an architecture might require should be hidden behind the name.
> +# However, if required, architectures can expose relevant properties.
> +#
> +# @name: the name of the CPU definition the model is based on
> +# @props: #optional a dictionary of properties to be applied

Should we make it explicit that we are talking about QOM
properties?

> +#
> +# Since: 2.8.0
> +##
> +{ 'struct': 'CpuModelInfo',
> +  'data': { 'name': 'str',
> +            '*props': 'any' } }
> +
> +##
> +# @CpuModelExpansionType
> +#
> +# An enumeration of CPU model expansion types.
> +#
> +# @static: Expand to a static CPU model, a combination of a static base
> +#          model name and property delta changes. As the static base model will
> +#          never change, the expanded CPU model will be the same, independant of
> +#          QEMU version or compatibility machines. Therefore, the resulting

We could be more explicit about the guarantees: "independent of
QEMU version, machine type, machine options, and accelerator
options".

> +#          model can be used by tooling without having to specify a
> +#          compatibility machine - e.g. when displaying the "host" model.
> +#          All static CPU models are migration-safe.

This is cool. Unfortunately we are not going to support it in x86
very soon because we don't have any static CPU models.

> +#
> +# @full: Expand all properties. The produced model is not guaranteed to be
> +#        migration-safe, but allows tooling to get an insight and work with
> +#        model details.

I wonder if we really need to document it broadly as "not
guaranteed to be migration-safe". The returned data will be
migration-safe (but not static) if the CPU model being expanded
is migration-safe, won't it?

Also: I wonder what should be the return value for "name" when
expansion type is "full" and we don't have any static CPU models
(like on x86). e.g. returning:
  { name: "host", props: { foo: "on", bar: "on", ... }
would make the interface not directly usable for the expansion of
<cpu mode="host-model">. Maybe that means we have to add at least
one static CPU model to x86, too?

> +#
> +# Since: 2.8.0
> +##
> +{ 'enum': 'CpuModelExpansionType',
> +  'data': [ 'static', 'full' ] }
> +
> +
> +##
> +# @CpuModelExpansionInfo
> +#
> +# The result of a cpu model expansion.
> +#
> +# @model: the expanded CpuModelInfo.
> +#
> +# Since: 2.8.0
> +##
> +{ 'struct': 'CpuModelExpansionInfo',
> +  'data': { 'model': 'CpuModelInfo' } }

I like it that the input and output of query-cpu-model-expansion
is in the same format (CpuModelInfo).

> +
> +
> +##
> +# @query-cpu-model-expansion:
> +#
> +# Expands the given CPU model to different granularities, allowing tooling
> +# to get an understanding what a specific CPU model looks like in QEMU
> +# under a certain QEMU machine.

Maybe "expands a given CPU model (or a combination of CPU model +
additional options) to different granularities".

> +#
> +# Expanding CPU models is in general independant of the accelerator, except
> +# for models like "host" that explicitly rely on an accelerator and can
> +# vary in different configurations.

Unfortunately this is not true in x86. Documenting it this way
might give people the wrong expectations.

Specific guarantees from arch-specific code could be documented
somewhere, but: where?

Maybe arch-specific guarantees should actually become
query-cpu-definitions fields (like we have "static" and
"migration-safe" today). If people are really interested in
accelerator-independent data, we need


> This interface can therefore also be used
> +# to query the "host" CPU model.
> +#
> +# Note: This interface should not be used when global properties of CPU classes
> +#       are changed (e.g. via "-cpu ...").

We could simply enumerate all cases that could affect the return
value. e.g.:

# The data returned by this command may be affected by:
#
# * QEMU version: CPU models may look different depending on the
#   QEMU version. (Except for CPU models reported as "static"
#   in query-cpu-definitions.)
# * machine-type: CPU model expansion may look different depending
#   on the machine-type. (Except for CPU models reported as "static"
#   in query-cpu-definitions.)
# * machine options (including accelerator): in some
#   architectures, CPU models may look different depending on
#   machine and accelerator options. (Except for CPU models
#   reported as "static" in query-cpu-definitions.)
# * "-cpu" arguments and global properties: arguments to the -cpu
#    option and global properties may affect expansion of CPU
#    models. Using query-cpu-model-expansion while using "-cpu"
#    or global properties is not advised.


> +#
> +# s390x supports expanding of all CPU models with all expansion types. Other
> +# architectures are not supported yet.

I think this paragraph is likely to get obsolete very soon (as
people may forget to update it when implementing the new
interface on other architectures). Also, the paragraph is not
true until patch 27/29 is applied.

Maybe write it as "Some architectures may not support all
expansion types".

Patch 27/29 could add "s390x supports both 'static' and 'full'
expansion types". I wouldn't document it as "supports all
expansion types" because CpuModelExpansionType may be extended in
the future.

> +#
> +# Returns: a CpuModelExpansionInfo. Returns an error if expanding CPU models is
> +#          not supported, if the model cannot be expanded, if the model contains
> +#          an unknown CPU definition name, unknown properties or properties
> +#          with a wrong type. Also returns an error if an expansion type is
> +#          not supported.
> +#
> +# Since: 2.8.0
> +##
> +{ 'command': 'query-cpu-model-expansion',
> +  'data': { 'type': 'CpuModelExpansionType',
> +            'model': 'CpuModelInfo' },
> +  'returns': 'CpuModelExpansionInfo' }
> +
>  # @AddfdInfo:
>  #
>  # Information about a file descriptor that was added to an fd set.
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index c8d360a..7ed9528 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3942,6 +3942,12 @@ EQMP
>      },
>  
>      {
> +        .name       = "query-cpu-model-expansion",
> +        .args_type  = "type:s,model:q",
> +        .mhandler.cmd_new = qmp_marshal_query_cpu_model_expansion,
> +    },
> +
> +    {
>          .name       = "query-target",
>          .args_type  = "",
>          .mhandler.cmd_new = qmp_marshal_query_target,
> diff --git a/qmp.c b/qmp.c
> index b6d531e..29fbfb8 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -607,6 +607,13 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
>      return arch_query_cpu_definitions(errp);
>  }
>  
> +CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
> +                                                     CpuModelInfo *model,
> +                                                     Error **errp)
> +{
> +    return arch_query_cpu_model_expansion(type, model, errp);
> +}
> +
>  void qmp_add_client(const char *protocol, const char *fdname,
>                      bool has_skipauth, bool skipauth, bool has_tls, bool tls,
>                      Error **errp)
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 55edd15..4929842 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -1,4 +1,5 @@
>  stub-obj-y += arch-query-cpu-def.o
> +stub-obj-y += arch-query-cpu-model-expansion.o
>  stub-obj-y += bdrv-next-monitor-owned.o
>  stub-obj-y += blk-commit-all.o
>  stub-obj-y += blockdev-close-all-bdrv-states.o
> diff --git a/stubs/arch-query-cpu-model-expansion.c b/stubs/arch-query-cpu-model-expansion.c
> new file mode 100644
> index 0000000..ae7cf55
> --- /dev/null
> +++ b/stubs/arch-query-cpu-model-expansion.c
> @@ -0,0 +1,12 @@
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "sysemu/arch_init.h"
> +#include "qapi/qmp/qerror.h"
> +
> +CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
> +                                                      CpuModelInfo *mode,
> +                                                      Error **errp)
> +{
> +    error_setg(errp, QERR_UNSUPPORTED);
> +    return NULL;
> +}
> -- 
> 2.6.6
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 13:23     ` David Hildenbrand
@ 2016-08-02 14:00       ` Eduardo Habkost
  2016-08-02 14:27         ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 14:00 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 03:23:30PM +0200, David Hildenbrand wrote:
[...]
> > > +#
> > > +# @static: #optional whether a CPU definition is static and will not change
> > > +#          between QEMU versions / QEMU machines. A static model is always
> > > +#          migration-safe. If not provided, information is not available.  
> > 
> > I assume static models don't change depending on the
> > machine-type, either. If that's case, we should document that.
> 
> That's what I meant with "QEMU machines", should that be "QEMU machine types"
> instead?

Sorry, I was reading it too quickly. You did document it. :)

We could extend it to mention the other guarantees (just like my
previous suggestion for CpuModelExpansionType::static): "will not
change depending on QEMU version, machine type, machine options,
and accelerator options".

> 
> > 
> > I believe in this case we don't need to make it optional: just
> > make the field always present and set it to "false" by default.
> 
> That is true for x86, do you know about the other architectures (arm, ppc)?
> I'd like to avoid returning false information here for other architectures.

As being "static" is not a fact about the existing code, but just
a guarantee about what the developers are going to do in the
future, static=false just means that the developers didn't make
any promises yet (so I don't think it would ever be false
information).

In other words, I believe we can safely assume a CPU model is not
guaranteed to be static unless the maintainers decided to
explicitly document it as static (and change the data returned by
query-cpu-definitions).

(I am assuming that changing it from "false" to "true" in a new
QEMU version won't be a problem for anybody.)

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion"
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" David Hildenbrand
@ 2016-08-02 14:22   ` Eduardo Habkost
  2016-08-02 14:28     ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 14:22 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 01:59:13PM +0200, David Hildenbrand wrote:
[...]
> +CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
> +                                                      CpuModelInfo *model,
> +                                                      Error **errp)
> +{
> +    CpuModelExpansionInfo *expansion_info = NULL;
> +    S390CPUModel s390_model;
> +    bool delta_changes = false;
> +
> +    /* convert it to our internal representation */
> +    cpu_model_from_info(&s390_model, model, errp);
> +    if (*errp) {
> +        return NULL;
> +    }
> +
> +    if (type == CPU_MODEL_EXPANSION_TYPE_STATIC) {
> +        delta_changes = true;
> +    }

This assumes the only valid values for type will always be
"static" and "full". I would check explicitly for
CPU_MODEL_EXPANSION_TYPE_STATIC and CPU_MODEL_EXPANSION_TYPE_FULL
and return an error otherwise, just in case CpuModelExpansionType
is extended to include other expansion modes in the future.

> +
> +    /* convert it back to a static representation */
> +    expansion_info = g_malloc0(sizeof(*expansion_info));
> +    expansion_info->model = g_malloc0(sizeof(*expansion_info->model));
> +    cpu_info_from_model(expansion_info->model, &s390_model, delta_changes);
> +    return expansion_info;
> +}
>  #endif
>  
>  static void check_consistency(const S390CPUModel *model)
> -- 
> 2.6.6
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 14:00       ` Eduardo Habkost
@ 2016-08-02 14:27         ` David Hildenbrand
  2016-08-02 14:49           ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 14:27 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

> On Tue, Aug 02, 2016 at 03:23:30PM +0200, David Hildenbrand wrote:
> [...]
> > > > +#
> > > > +# @static: #optional whether a CPU definition is static and will not change
> > > > +#          between QEMU versions / QEMU machines. A static model is always
> > > > +#          migration-safe. If not provided, information is not available.    
> > > 
> > > I assume static models don't change depending on the
> > > machine-type, either. If that's case, we should document that.  
> > 
> > That's what I meant with "QEMU machines", should that be "QEMU machine types"
> > instead?  
> 
> Sorry, I was reading it too quickly. You did document it. :)
> 
> We could extend it to mention the other guarantees (just like my
> previous suggestion for CpuModelExpansionType::static): "will not
> change depending on QEMU version, machine type, machine options,
> and accelerator options".

Sounds good to me!

> 
> >   
> > > 
> > > I believe in this case we don't need to make it optional: just
> > > make the field always present and set it to "false" by default.  
> > 
> > That is true for x86, do you know about the other architectures (arm, ppc)?
> > I'd like to avoid returning false information here for other architectures.  
> 
> As being "static" is not a fact about the existing code, but just
> a guarantee about what the developers are going to do in the
> future, static=false just means that the developers didn't make
> any promises yet (so I don't think it would ever be false
> information).
> 
> In other words, I believe we can safely assume a CPU model is not
> guaranteed to be static unless the maintainers decided to
> explicitly document it as static (and change the data returned by
> query-cpu-definitions).
> 
> (I am assuming that changing it from "false" to "true" in a new
> QEMU version won't be a problem for anybody.)
> 

Hmm, if "static" means, the model will never be changed, but it was changed in
the past, this sounds somewhat strange. I would rather say then "information
is not available" == no guarantee.

But if nobody else sees a problem with that, I can just set it to stable=false
on all other architectures.

Thanks!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion"
  2016-08-02 14:22   ` Eduardo Habkost
@ 2016-08-02 14:28     ` David Hildenbrand
  0 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 14:28 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

> On Tue, Aug 02, 2016 at 01:59:13PM +0200, David Hildenbrand wrote:
> [...]
> > +CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
> > +                                                      CpuModelInfo *model,
> > +                                                      Error **errp)
> > +{
> > +    CpuModelExpansionInfo *expansion_info = NULL;
> > +    S390CPUModel s390_model;
> > +    bool delta_changes = false;
> > +
> > +    /* convert it to our internal representation */
> > +    cpu_model_from_info(&s390_model, model, errp);
> > +    if (*errp) {
> > +        return NULL;
> > +    }
> > +
> > +    if (type == CPU_MODEL_EXPANSION_TYPE_STATIC) {
> > +        delta_changes = true;
> > +    }  
> 
> This assumes the only valid values for type will always be
> "static" and "full". I would check explicitly for
> CPU_MODEL_EXPANSION_TYPE_STATIC and CPU_MODEL_EXPANSION_TYPE_FULL
> and return an error otherwise, just in case CpuModelExpansionType
> is extended to include other expansion modes in the future.

I actually also had that in mind :) Will add that check!

Thanks!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
@ 2016-08-02 14:45   ` Eduardo Habkost
  2016-08-02 15:15     ` David Hildenbrand
  2016-08-04  7:34   ` David Hildenbrand
  1 sibling, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 14:45 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 01:59:11PM +0200, David Hildenbrand wrote:
> Let's provide a standardized interface to compare two CPU models.
> 
> query-cpu-model-compare takes two models and returns what it knows about
> their compability under a certain QEMU machine QEMU has been started with.
> 
> If modelA is a subset of modelB or if both are identical, modelA will run
> in the same configuration as modelB. If modelA is however a superset of
> modelB or if both are incompatible, one can try to create a compatible one
> by "baselining" both models (follow up patch).
> 
> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
> ---
>  include/sysemu/arch_init.h              |  3 ++
>  qapi-schema.json                        | 65 +++++++++++++++++++++++++++++++++
>  qmp-commands.hx                         |  6 +++
>  qmp.c                                   |  7 ++++
>  stubs/Makefile.objs                     |  1 +
>  stubs/arch-query-cpu-model-comparison.c | 12 ++++++
>  6 files changed, 94 insertions(+)
>  create mode 100644 stubs/arch-query-cpu-model-comparison.c
> 
> diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
> index 37b2e86..96d47c0 100644
> --- a/include/sysemu/arch_init.h
> +++ b/include/sysemu/arch_init.h
> @@ -38,5 +38,8 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
>  CpuModelExpansionInfo *arch_query_cpu_model_expansion(CpuModelExpansionType type,
>                                                        CpuModelInfo *mode,
>                                                        Error **errp);
> +CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela,
> +                                                     CpuModelInfo *modelb,
> +                                                     Error **errp);
>  
>  #endif
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 43f7969..1f8f8ec 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3149,6 +3149,71 @@
>              'model': 'CpuModelInfo' },
>    'returns': 'CpuModelExpansionInfo' }
>  
> +##
> +# @CpuModelCompareResult:
> +#
> +# An enumeration of CPU model comparation results.
> +#
> +# @incompatible: both model definition are incompatible
> +#
> +# @identical: model A == model B
> +#
> +# @superset: model A > model B
> +#
> +# @subset: model A < model B

We need to clarify what superset/subset, ">" and "<" really mean.

> +#
> +# Since: 2.8.0
> +##
> +{ 'enum': 'CpuModelCompareResult',
> +  'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }

I assume implementations are free to return "incompatible" if
they still don't have any extra logic to expand CPU models and
check for supersets/subsets. If that's the case, see my
suggestion below for a generic comparison function.

> +
> +##
> +# @CpuModelCompareInfo
> +#
> +# The result of a CPU model comparison.
> +#
> +# @result: The result of the compare operation.
> +# @responsible-properties: List of properties that led to the comparison result
> +#                          not being identical.
> +#
> +# @responsible-properties is a list of QOM property names that led to
> +# both CPUs not being detected as identical. For identical models, this
> +# list is empty.
> +# If a QOM property is read-only, that means there's no known way to make the
> +# CPU models identical. If the special property name "type" is included, the
> +# models are by definition not identical and cannot be made identical.
> +#
> +# Since: 2.8.0
> +##
> +{ 'struct': 'CpuModelCompareInfo',
> +  'data': {'result': 'CpuModelCompareResult',
> +           'responsible-properties': ['str']
> +          }
> +}
> +
> +##
> +# @query-cpu-model-comparison:
> +#
> +# Compares two CPU models, returning how they compare under a specific QEMU
> +# machine.
> +#
> +# Note: This interface should not be used when global properties of CPU classes
> +#       are changed (e.g. via "-cpu ...").
> +#
> +# s390x supports comparing of all CPU models.

This statement is not true until patch 28/29 is applied.

> Other architectures are not
> +# supported yet.

What if we provide a generic comparison function that does like
the following pseudocode:

def basic_comparison(modela, modelb):
  if modela.name == modelb.name:
    if modela.props == modelb.props:
      return "identical", []
    else:
      #XXX: maybe add some extra logic to check if
      # modela.props is a subset or superset of modelb.props?
      return "incompatible", set(modela.props.keys(), modelb.props.keys())
  else:
    return "incompatible", ["type"]

def full_comparison(modela, modelb):
  r,p = basic_comparison(modela, modelb)
  if r == "incompatible":
    try:
      modela = expand_cpu_model(modela, "full")
      modelb = expand_cpu_model(modelb, "full")
    except:
      # in case "full" expansion mode is not supported
      return r,p
    return basic_comparison(modela, modelb)


> +#
> +# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU models is
> +#          not supported, if a model cannot be used, if a model contains
> +#          an unknown cpu definition name, unknown properties or properties
> +#          with wrong types.
> +#
> +# Since: 2.8.0
> +##
> +{ 'command': 'query-cpu-model-comparison',
> +  'data': { 'modela': 'CpuModelInfo', 'modelb': 'CpuModelInfo' },
> +  'returns': 'CpuModelCompareInfo' }
> +
>  # @AddfdInfo:
>  #
>  # Information about a file descriptor that was added to an fd set.
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 7ed9528..0af2098 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -3948,6 +3948,12 @@ EQMP
>      },
>  
>      {
> +        .name       = "query-cpu-model-comparison",
> +        .args_type  = "modela:q,modelb:q",
> +        .mhandler.cmd_new = qmp_marshal_query_cpu_model_comparison,
> +    },
> +
> +    {
>          .name       = "query-target",
>          .args_type  = "",
>          .mhandler.cmd_new = qmp_marshal_query_target,
> diff --git a/qmp.c b/qmp.c
> index 29fbfb8..f551019 100644
> --- a/qmp.c
> +++ b/qmp.c
> @@ -614,6 +614,13 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuModelExpansionType type,
>      return arch_query_cpu_model_expansion(type, model, errp);
>  }
>  
> +CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
> +                                                    CpuModelInfo *modelb,
> +                                                    Error **errp)
> +{
> +    return arch_query_cpu_model_comparison(modela, modelb, errp);
> +}
> +
>  void qmp_add_client(const char *protocol, const char *fdname,
>                      bool has_skipauth, bool skipauth, bool has_tls, bool tls,
>                      Error **errp)
> diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
> index 4929842..da768f0 100644
> --- a/stubs/Makefile.objs
> +++ b/stubs/Makefile.objs
> @@ -1,5 +1,6 @@
>  stub-obj-y += arch-query-cpu-def.o
>  stub-obj-y += arch-query-cpu-model-expansion.o
> +stub-obj-y += arch-query-cpu-model-comparison.o
>  stub-obj-y += bdrv-next-monitor-owned.o
>  stub-obj-y += blk-commit-all.o
>  stub-obj-y += blockdev-close-all-bdrv-states.o
> diff --git a/stubs/arch-query-cpu-model-comparison.c b/stubs/arch-query-cpu-model-comparison.c
> new file mode 100644
> index 0000000..d5486ae
> --- /dev/null
> +++ b/stubs/arch-query-cpu-model-comparison.c
> @@ -0,0 +1,12 @@
> +#include "qemu/osdep.h"
> +#include "qemu-common.h"
> +#include "sysemu/arch_init.h"
> +#include "qapi/qmp/qerror.h"
> +
> +CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *modela,
> +                                                     CpuModelInfo *modelb,
> +                                                     Error **errp)
> +{
> +    error_setg(errp, QERR_UNSUPPORTED);
> +    return NULL;
> +}
> -- 
> 2.6.6
> 

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 14:27         ` David Hildenbrand
@ 2016-08-02 14:49           ` Eduardo Habkost
  2016-08-02 14:53             ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 14:49 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 04:27:55PM +0200, David Hildenbrand wrote:
[...]
> > > > 
> > > > I believe in this case we don't need to make it optional: just
> > > > make the field always present and set it to "false" by default.  
> > > 
> > > That is true for x86, do you know about the other architectures (arm, ppc)?
> > > I'd like to avoid returning false information here for other architectures.  
> > 
> > As being "static" is not a fact about the existing code, but just
> > a guarantee about what the developers are going to do in the
> > future, static=false just means that the developers didn't make
> > any promises yet (so I don't think it would ever be false
> > information).
> > 
> > In other words, I believe we can safely assume a CPU model is not
> > guaranteed to be static unless the maintainers decided to
> > explicitly document it as static (and change the data returned by
> > query-cpu-definitions).
> > 
> > (I am assuming that changing it from "false" to "true" in a new
> > QEMU version won't be a problem for anybody.)
> > 
> 
> Hmm, if "static" means, the model will never be changed, but it was changed in
> the past, this sounds somewhat strange. I would rather say then "information
> is not available" == no guarantee.

If the CPU model really changed in the past, I think it must be
always set to "false".

But if it never changed in the past and we never made an explicit
decision about future guarantees, we can set it to "false" today,
and change it to "true" later (after we made a decision).

> 
> But if nobody else sees a problem with that, I can just set it to stable=false
> on all other architectures.

I think it's OK, as long we set it to "true" only if it never
changed in the past.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions
  2016-08-02 14:49           ` Eduardo Habkost
@ 2016-08-02 14:53             ` David Hildenbrand
  0 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 14:53 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

> On Tue, Aug 02, 2016 at 04:27:55PM +0200, David Hildenbrand wrote:
> [...]
> > > > > 
> > > > > I believe in this case we don't need to make it optional: just
> > > > > make the field always present and set it to "false" by default.    
> > > > 
> > > > That is true for x86, do you know about the other architectures (arm, ppc)?
> > > > I'd like to avoid returning false information here for other architectures.    
> > > 
> > > As being "static" is not a fact about the existing code, but just
> > > a guarantee about what the developers are going to do in the
> > > future, static=false just means that the developers didn't make
> > > any promises yet (so I don't think it would ever be false
> > > information).
> > > 
> > > In other words, I believe we can safely assume a CPU model is not
> > > guaranteed to be static unless the maintainers decided to
> > > explicitly document it as static (and change the data returned by
> > > query-cpu-definitions).
> > > 
> > > (I am assuming that changing it from "false" to "true" in a new
> > > QEMU version won't be a problem for anybody.)
> > >   
> > 
> > Hmm, if "static" means, the model will never be changed, but it was changed in
> > the past, this sounds somewhat strange. I would rather say then "information
> > is not available" == no guarantee.  
> 
> If the CPU model really changed in the past, I think it must be
> always set to "false".
> 
> But if it never changed in the past and we never made an explicit
> decision about future guarantees, we can set it to "false" today,
> and change it to "true" later (after we made a decision).
> 
> > 
> > But if nobody else sees a problem with that, I can just set it to stable=false
> > on all other architectures.  
> 
> I think it's OK, as long we set it to "true" only if it never
> changed in the past.
> 

That indeed is okay. So I'll change that for arm,ppc and x86 (static=false for
all returned definitions).

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion"
  2016-08-02 13:45   ` Eduardo Habkost
@ 2016-08-02 15:04     ` David Hildenbrand
  2016-08-02 15:38       ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 15:04 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu


> > +# A CPU model consists of the name of a CPU definition, to which
> > +# delta changes are applied (e.g. features added/removed). Most magic values
> > +# that an architecture might require should be hidden behind the name.
> > +# However, if required, architectures can expose relevant properties.
> > +#
> > +# @name: the name of the CPU definition the model is based on
> > +# @props: #optional a dictionary of properties to be applied  
> 
> Should we make it explicit that we are talking about QOM
> properties?

Yes makes sense.

> 
> > +#
> > +# Since: 2.8.0
> > +##
> > +{ 'struct': 'CpuModelInfo',
> > +  'data': { 'name': 'str',
> > +            '*props': 'any' } }
> > +
> > +##
> > +# @CpuModelExpansionType
> > +#
> > +# An enumeration of CPU model expansion types.
> > +#
> > +# @static: Expand to a static CPU model, a combination of a static base
> > +#          model name and property delta changes. As the static base model will
> > +#          never change, the expanded CPU model will be the same, independant of
> > +#          QEMU version or compatibility machines. Therefore, the resulting  
> 
> We could be more explicit about the guarantees: "independent of
> QEMU version, machine type, machine options, and accelerator
> options".

agreed.

> 
> > +#          model can be used by tooling without having to specify a
> > +#          compatibility machine - e.g. when displaying the "host" model.
> > +#          All static CPU models are migration-safe.  
> 
> This is cool. Unfortunately we are not going to support it in x86
> very soon because we don't have any static CPU models.

Well, it's all about finding a minimum set of features that one can work with.
I assume e.g. a Phenom also always has a minimum set of features?

> 
> > +#
> > +# @full: Expand all properties. The produced model is not guaranteed to be
> > +#        migration-safe, but allows tooling to get an insight and work with
> > +#        model details.  
> 
> I wonder if we really need to document it broadly as "not
> guaranteed to be migration-safe". The returned data will be
> migration-safe (but not static) if the CPU model being expanded
> is migration-safe, won't it?

Actually I don't think so.
Imagine expanding host: featA=true, featB=false

Now, if going to another QEMU version, there might be featC known.
So -host,featA=on,featB=off will implicitly enable featC and is therefore
not be migration-safe. You would have to disable featC for compatibility
machines on the host model. Is something like that done? I don't think so
(and at least s390x won't do it right now).

But, I can simply get rid of that remark.

> 
> Also: I wonder what should be the return value for "name" when
> expansion type is "full" and we don't have any static CPU models
> (like on x86). e.g. returning:
>   { name: "host", props: { foo: "on", bar: "on", ... }
> would make the interface not directly usable for the expansion of
> <cpu mode="host-model">. Maybe that means we have to add at least
> one static CPU model to x86, too?

I'd simply copy the name then. That's what I had in mind.
(actually I don't do it on s390x because it's easier to just rely
on the output of our conversion function).

> > +
> > +
> > +##
> > +# @query-cpu-model-expansion:
> > +#
> > +# Expands the given CPU model to different granularities, allowing tooling
> > +# to get an understanding what a specific CPU model looks like in QEMU
> > +# under a certain QEMU machine.  
> 
> Maybe "expands a given CPU model (or a combination of CPU model +
> additional options) to different granularities".
> 
> > +#
> > +# Expanding CPU models is in general independant of the accelerator, except
> > +# for models like "host" that explicitly rely on an accelerator and can
> > +# vary in different configurations.  
> 
> Unfortunately this is not true in x86. Documenting it this way
> might give people the wrong expectations.
> 
> Specific guarantees from arch-specific code could be documented
> somewhere, but: where?
> 
> Maybe arch-specific guarantees should actually become
> query-cpu-definitions fields (like we have "static" and
> "migration-safe" today). If people are really interested in
> accelerator-independent data, we need

Okay, so this could be extended later than.

> 
> 
> > This interface can therefore also be used
> > +# to query the "host" CPU model.
> > +#
> > +# Note: This interface should not be used when global properties of CPU classes
> > +#       are changed (e.g. via "-cpu ...").  
> 
> We could simply enumerate all cases that could affect the return
> value. e.g.:
> 
> # The data returned by this command may be affected by:
> #
> # * QEMU version: CPU models may look different depending on the
> #   QEMU version. (Except for CPU models reported as "static"
> #   in query-cpu-definitions.)
> # * machine-type: CPU model expansion may look different depending
> #   on the machine-type. (Except for CPU models reported as "static"
> #   in query-cpu-definitions.)
> # * machine options (including accelerator): in some
> #   architectures, CPU models may look different depending on
> #   machine and accelerator options. (Except for CPU models
> #   reported as "static" in query-cpu-definitions.)
> # * "-cpu" arguments and global properties: arguments to the -cpu
> #    option and global properties may affect expansion of CPU
> #    models. Using query-cpu-model-expansion while using "-cpu"
> #    or global properties is not advised.
> 

Yes, that's better.

> 
> > +#
> > +# s390x supports expanding of all CPU models with all expansion types. Other
> > +# architectures are not supported yet.  
> 
> I think this paragraph is likely to get obsolete very soon (as
> people may forget to update it when implementing the new
> interface on other architectures). Also, the paragraph is not
> true until patch 27/29 is applied.
> 
> Maybe write it as "Some architectures may not support all
> expansion types".

Agreed. And most likely x86 won't support expanding all CPU models I assume?

> 
> Patch 27/29 could add "s390x supports both 'static' and 'full'
> expansion types". I wouldn't document it as "supports all
> expansion types" because CpuModelExpansionType may be extended in
> the future.

Agreed.


Thanks!


David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 14:45   ` Eduardo Habkost
@ 2016-08-02 15:15     ` David Hildenbrand
  2016-08-02 15:47       ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 15:15 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu


> > +# @CpuModelCompareResult:
> > +#
> > +# An enumeration of CPU model comparation results.
> > +#
> > +# @incompatible: both model definition are incompatible
> > +#
> > +# @identical: model A == model B
> > +#
> > +# @superset: model A > model B
> > +#
> > +# @subset: model A < model B  
> 
> We need to clarify what superset/subset, ">" and "<" really mean.
> 

I think this is "feature subset" on the one hand and "earlier generation"
on the other hand - at least for s390x. But it boils down to runnability I
think: (< and > are actually quite misleading)

# @incompatible: both model definition are incompatible. A host which
#                can run model A can't run model B and the other way around.
#
# @identical: model A == model B. A host which can run model A can run
#             model B and the other way around.
#
# @superset: A host which can run model A can run model B, but not the
#            other way around.
#
# @subset: A host which can run model B can run model A, but not the
#          other way around.

> > +#
> > +# Since: 2.8.0
> > +##
> > +{ 'enum': 'CpuModelCompareResult',
> > +  'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }  
> 
> I assume implementations are free to return "incompatible" if
> they still don't have any extra logic to expand CPU models and
> check for supersets/subsets. If that's the case, see my
> suggestion below for a generic comparison function.

incompatible basically means, you have to baseline to create a runnable CPU
model. Could be done, but see my last comment.

> 
> > +
> > +##
> > +# @CpuModelCompareInfo
> > +#
> > +# The result of a CPU model comparison.
> > +#
> > +# @result: The result of the compare operation.
> > +# @responsible-properties: List of properties that led to the comparison result
> > +#                          not being identical.
> > +#
> > +# @responsible-properties is a list of QOM property names that led to
> > +# both CPUs not being detected as identical. For identical models, this
> > +# list is empty.
> > +# If a QOM property is read-only, that means there's no known way to make the
> > +# CPU models identical. If the special property name "type" is included, the
> > +# models are by definition not identical and cannot be made identical.
> > +#
> > +# Since: 2.8.0
> > +##
> > +{ 'struct': 'CpuModelCompareInfo',
> > +  'data': {'result': 'CpuModelCompareResult',
> > +           'responsible-properties': ['str']
> > +          }
> > +}
> > +
> > +##
> > +# @query-cpu-model-comparison:
> > +#
> > +# Compares two CPU models, returning how they compare under a specific QEMU
> > +# machine.
> > +#
> > +# Note: This interface should not be used when global properties of CPU classes
> > +#       are changed (e.g. via "-cpu ...").
> > +#
> > +# s390x supports comparing of all CPU models.  
> 
> This statement is not true until patch 28/29 is applied.

Yes, will move it (also for the baseline patch),

> 
> > Other architectures are not
> > +# supported yet.  
> 
> What if we provide a generic comparison function that does like
> the following pseudocode:
> 
> def basic_comparison(modela, modelb):
>   if modela.name == modelb.name:
>     if modela.props == modelb.props:
>       return "identical", []
>     else:
>       #XXX: maybe add some extra logic to check if
>       # modela.props is a subset or superset of modelb.props?
>       return "incompatible", set(modela.props.keys(), modelb.props.keys())
>   else:
>     return "incompatible", ["type"]
> 
> def full_comparison(modela, modelb):
>   r,p = basic_comparison(modela, modelb)
>   if r == "incompatible":
>     try:
>       modela = expand_cpu_model(modela, "full")
>       modelb = expand_cpu_model(modelb, "full")
>     except:
>       # in case "full" expansion mode is not supported
>       return r,p
>     return basic_comparison(modela, modelb)
> 

While I agree that that would be nice to have, it doesn't fit for s390x right
now: The result on s390x does not rely on features/name only, but internal data
we don't want to expose.

e.g. z13.2 and z13s are considered identically.

z13 is a subset of z13.2, although they have exactly the same
features/properties (right now). It basically has to do with internal data
(e.g. address bus sizes for hamax as an example)

(that's where we indictate "type" under "responsible-properties" - they can
never be made identically, you have to baseline).

Thanks a lot!!!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion"
  2016-08-02 15:04     ` David Hildenbrand
@ 2016-08-02 15:38       ` Eduardo Habkost
  2016-08-03  7:02         ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 15:38 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 05:04:05PM +0200, David Hildenbrand wrote:
[...]
> > 
> > > +#          model can be used by tooling without having to specify a
> > > +#          compatibility machine - e.g. when displaying the "host" model.
> > > +#          All static CPU models are migration-safe.  
> > 
> > This is cool. Unfortunately we are not going to support it in x86
> > very soon because we don't have any static CPU models.
> 
> Well, it's all about finding a minimum set of features that one can work with.
> I assume e.g. a Phenom also always has a minimum set of features?

We could have a very minimal CPU model that is static in x86,
yes. We just need to find out "how minimal" we can really make
it.

> 
> > 
> > > +#
> > > +# @full: Expand all properties. The produced model is not guaranteed to be
> > > +#        migration-safe, but allows tooling to get an insight and work with
> > > +#        model details.  
> > 
> > I wonder if we really need to document it broadly as "not
> > guaranteed to be migration-safe". The returned data will be
> > migration-safe (but not static) if the CPU model being expanded
> > is migration-safe, won't it?
> 
> Actually I don't think so.
> Imagine expanding host: featA=true, featB=false

In this case, "host" is not migration-safe, so the results will
not be migration-safe.

> 
> Now, if going to another QEMU version, there might be featC known.
> So -host,featA=on,featB=off will implicitly enable featC and is therefore
> not be migration-safe. You would have to disable featC for compatibility
> machines on the host model. Is something like that done? I don't think so
> (and at least s390x won't do it right now).
> 
> But, I can simply get rid of that remark.

I think we can keep it, and change it later if knowing about
migration-safety of "full" is deemed important. Being explicit
about guarantees we do _not_ give (yet) doesn't hurt, even if we
change the docs later to be explicit about extra guarantees we
didn't document before.

> 
> > 
> > Also: I wonder what should be the return value for "name" when
> > expansion type is "full" and we don't have any static CPU models
> > (like on x86). e.g. returning:
> >   { name: "host", props: { foo: "on", bar: "on", ... }
> > would make the interface not directly usable for the expansion of
> > <cpu mode="host-model">. Maybe that means we have to add at least
> > one static CPU model to x86, too?
> 
> I'd simply copy the name then. That's what I had in mind.
> (actually I don't do it on s390x because it's easier to just rely
> on the output of our conversion function).

Copying the name should work for the first version. It would be
less useful for <cpu model="host-model">, but we can improve it
later.

> 
[...]
> > > +#
> > > +# Expanding CPU models is in general independant of the accelerator, except
> > > +# for models like "host" that explicitly rely on an accelerator and can
> > > +# vary in different configurations.  
> > 
> > Unfortunately this is not true in x86. Documenting it this way
> > might give people the wrong expectations.
> > 
> > Specific guarantees from arch-specific code could be documented
> > somewhere, but: where?
> > 
> > Maybe arch-specific guarantees should actually become
> > query-cpu-definitions fields (like we have "static" and
> > "migration-safe" today). If people are really interested in
> > accelerator-independent data, we need

Oops, forgot to finish this paragraph:

If people are really interested in accelerator-independent data,
we could add an additional query-cpu-definitions field stating
that. (But I doubt we will need it)

> 
> Okay, so this could be extended later than.
[...]
> > 
> > > +#
> > > +# s390x supports expanding of all CPU models with all expansion types. Other
> > > +# architectures are not supported yet.  
> > 
> > I think this paragraph is likely to get obsolete very soon (as
> > people may forget to update it when implementing the new
> > interface on other architectures). Also, the paragraph is not
> > true until patch 27/29 is applied.
> > 
> > Maybe write it as "Some architectures may not support all
> > expansion types".
> 
> Agreed. And most likely x86 won't support expanding all CPU models I assume?

It will probably support expanding all CPU models in the same way
(when using "full").

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 15:15     ` David Hildenbrand
@ 2016-08-02 15:47       ` Eduardo Habkost
  2016-08-03  7:09         ` David Hildenbrand
  0 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 15:47 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 05:15:54PM +0200, David Hildenbrand wrote:
> > > +# @CpuModelCompareResult:
> > > +#
> > > +# An enumeration of CPU model comparation results.
> > > +#
> > > +# @incompatible: both model definition are incompatible
> > > +#
> > > +# @identical: model A == model B
> > > +#
> > > +# @superset: model A > model B
> > > +#
> > > +# @subset: model A < model B  
> > 
> > We need to clarify what superset/subset, ">" and "<" really mean.
> > 
> 
> I think this is "feature subset" on the one hand and "earlier generation"
> on the other hand - at least for s390x. But it boils down to runnability I
> think: (< and > are actually quite misleading)

It sounds like we need to clarify what are the use cases and
requirements, to find out how to document the exact meaning of
"superset" and "subset".

I assume this is closely related to the semantics of
query-cpu-model-baseline (which I didn't review yet). In other
words: "superset" and "subset" means you can save a
query-cpu-model-baseline call because you already know modela or
modelb can be used as baseline, already. Is that correct?

In this case, I will get back to this while reviewing and
discussing query-cpu-model-baseline.

> 
> # @incompatible: both model definition are incompatible. A host which
> #                can run model A can't run model B and the other way around.
> #
> # @identical: model A == model B. A host which can run model A can run
> #             model B and the other way around.
> #
> # @superset: A host which can run model A can run model B, but not the
> #            other way around.
> #
> # @subset: A host which can run model B can run model A, but not the
> #          other way around.
> 
> > > +#
> > > +# Since: 2.8.0
> > > +##
> > > +{ 'enum': 'CpuModelCompareResult',
> > > +  'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }  
> > 
> > I assume implementations are free to return "incompatible" if
> > they still don't have any extra logic to expand CPU models and
> > check for supersets/subsets. If that's the case, see my
> > suggestion below for a generic comparison function.
> 
> incompatible basically means, you have to baseline to create a runnable CPU
> model. Could be done, but see my last comment.
> 
> > 
> > > +
> > > +##
> > > +# @CpuModelCompareInfo
> > > +#
> > > +# The result of a CPU model comparison.
> > > +#
> > > +# @result: The result of the compare operation.
> > > +# @responsible-properties: List of properties that led to the comparison result
> > > +#                          not being identical.
> > > +#
> > > +# @responsible-properties is a list of QOM property names that led to
> > > +# both CPUs not being detected as identical. For identical models, this
> > > +# list is empty.
> > > +# If a QOM property is read-only, that means there's no known way to make the
> > > +# CPU models identical. If the special property name "type" is included, the
> > > +# models are by definition not identical and cannot be made identical.
> > > +#
> > > +# Since: 2.8.0
> > > +##
> > > +{ 'struct': 'CpuModelCompareInfo',
> > > +  'data': {'result': 'CpuModelCompareResult',
> > > +           'responsible-properties': ['str']
> > > +          }
> > > +}
> > > +
> > > +##
> > > +# @query-cpu-model-comparison:
> > > +#
> > > +# Compares two CPU models, returning how they compare under a specific QEMU
> > > +# machine.
> > > +#
> > > +# Note: This interface should not be used when global properties of CPU classes
> > > +#       are changed (e.g. via "-cpu ...").
> > > +#
> > > +# s390x supports comparing of all CPU models.  
> > 
> > This statement is not true until patch 28/29 is applied.
> 
> Yes, will move it (also for the baseline patch),
> 
> > 
> > > Other architectures are not
> > > +# supported yet.  
> > 
> > What if we provide a generic comparison function that does like
> > the following pseudocode:
> > 
> > def basic_comparison(modela, modelb):
> >   if modela.name == modelb.name:
> >     if modela.props == modelb.props:
> >       return "identical", []
> >     else:
> >       #XXX: maybe add some extra logic to check if
> >       # modela.props is a subset or superset of modelb.props?
> >       return "incompatible", set(modela.props.keys(), modelb.props.keys())
> >   else:
> >     return "incompatible", ["type"]
> > 
> > def full_comparison(modela, modelb):
> >   r,p = basic_comparison(modela, modelb)
> >   if r == "incompatible":
> >     try:
> >       modela = expand_cpu_model(modela, "full")
> >       modelb = expand_cpu_model(modelb, "full")
> >     except:
> >       # in case "full" expansion mode is not supported
> >       return r,p
> >     return basic_comparison(modela, modelb)
> > 
> 
> While I agree that that would be nice to have, it doesn't fit for s390x right
> now: The result on s390x does not rely on features/name only, but internal data
> we don't want to expose.
> 
> e.g. z13.2 and z13s are considered identically.
> 
> z13 is a subset of z13.2, although they have exactly the same
> features/properties (right now). It basically has to do with internal data
> (e.g. address bus sizes for hamax as an example)
> 
> (that's where we indictate "type" under "responsible-properties" - they can
> never be made identically, you have to baseline).

Right, I don't mean it to be enough for all architectures, but as
a basic implementation that is minimally useful when there's no
arch-specific comparison function.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features
  2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
                   ` (28 preceding siblings ...)
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 29/29] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline" David Hildenbrand
@ 2016-08-02 17:28 ` Eduardo Habkost
  2016-08-02 18:12   ` David Hildenbrand
  29 siblings, 1 reply; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 17:28 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 01:58:46PM +0200, David Hildenbrand wrote:
[...]
> So we have:
> a) "query-cpu-model-expansion" - tell us what the "host" or another CPU
>    model looks like. Either falling back to a static model or
>    completely exposing all properties.

The query-cpu-model-expansion interface looks good to me. I just
had a few comments about the interface documentation.

> b) "query-cpu-model-comparison" - tell us how two CPU models compare,
>     indicating which properties were responsible for the decision.
> c) "query-cpu-model-baseline" - create a new model out of two models,
>     taking a requested level of stability into account.

I miss a clearer specifiction of what are the actual requirements
and use cases of query-cpu-model-baseline. Is it related to
runnability? If so, how exactly?

Related to that (as mentioned in my reply to patch 25/29), I
would like a clearer definintion of what "superset" and "subset"
mean exactly, in query-cpu-model-comparison. Likewise, I would
like to understand the requirements and use cases that make
"superset" and "subset" useful.

> 
> --------------------------------Libvirt usecase----------------------------
> 
> Testing for runability:
> - Simply try to start QEMU with KVM, compat machine, CPU model
> - Could be done using query-cpu-model-comparison in the future.
> 
> Identifying host model, e.g. "virsh capabilities"
> - query-cpu-model-expansion on "host" with "-M none --enable-kvm"
> 
> <cpu mode='host-model'>:
> - simply copy the identified host model

AFAICS, this will work out of the box only if
  query-cpu-model-expansion {name: "host"}
return a static CPU model name in return.model.name.

> 
> <cpu mode='host-passthrough'>:
> - "-cpu host"
> 
> "virsh cpu-baseline":
> - query-cpu-model-baseline on two models with "-M none"
> 
> "virsh cpu-compare":
> - query-cpu-model-comparison on two models with "-M none"
> 
> There might be some cenarios where libvirt wants to convert another CPU
> model to a static variant, this can be done using query-cpu-model-expansion
> 
[...]

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features
  2016-08-02 17:28 ` [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features Eduardo Habkost
@ 2016-08-02 18:12   ` David Hildenbrand
  2016-08-02 20:14     ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-02 18:12 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

> On Tue, Aug 02, 2016 at 01:58:46PM +0200, David Hildenbrand wrote:
> [...]
> > So we have:
> > a) "query-cpu-model-expansion" - tell us what the "host" or another CPU
> >    model looks like. Either falling back to a static model or
> >    completely exposing all properties.  
> 
> The query-cpu-model-expansion interface looks good to me. I just
> had a few comments about the interface documentation.
> 
> > b) "query-cpu-model-comparison" - tell us how two CPU models compare,
> >     indicating which properties were responsible for the decision.
> > c) "query-cpu-model-baseline" - create a new model out of two models,
> >     taking a requested level of stability into account.  
> 
> I miss a clearer specifiction of what are the actual requirements
> and use cases of query-cpu-model-baseline. Is it related to
> runnability? If so, how exactly?

cpu-baseline and cpu-compare are only needed to make
- "virsh cpu-compare"
- "virsh cpu-baseline" work
(see libvirt usecases below)

These commands are needed to find/test runnability of a CPU model for
a cluster in bigger installations by tooling.

As libvirt won't have details about s390x models, we have to provide
an interface so it can carry out these tasks.

> 
> Related to that (as mentioned in my reply to patch 25/29), I
> would like a clearer definintion of what "superset" and "subset"
> mean exactly, in query-cpu-model-comparison. Likewise, I would
> like to understand the requirements and use cases that make
> "superset" and "subset" useful.

I took these definitions from libvirt directly.

Example: core2duo against my sandybridge
$ virsh cpu-compare test.xml
Host CPU is a superset of CPU described in test.xml

Usually, you do a "virsh cpu-compare" against your host cpu model. Chances
that the result is identical are very low. So depending on which
one is the first model, you get superset or subset.

So
if A is a subset of B, A will run where B runs
if A is a superset of B, B will run where A runs

That means, if "cpu-compare" (against your host!) returns "identical" or
"superset", you're good to go. If they are "incompatible" or "subset",
you will have to use cpu-baseline to create a compatible model.

Does that answer your question?

> 
> > 
> > --------------------------------Libvirt usecase----------------------------
> > 
> > Testing for runability:
> > - Simply try to start QEMU with KVM, compat machine, CPU model
> > - Could be done using query-cpu-model-comparison in the future.
> > 
> > Identifying host model, e.g. "virsh capabilities"
> > - query-cpu-model-expansion on "host" with "-M none --enable-kvm"
> > 
> > <cpu mode='host-model'>:
> > - simply copy the identified host model  
> 
> AFAICS, this will work out of the box only if
>   query-cpu-model-expansion {name: "host"}
> return a static CPU model name in return.model.name.


Yes, that was also my impression.

Thanks again!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features
  2016-08-02 18:12   ` David Hildenbrand
@ 2016-08-02 20:14     ` Eduardo Habkost
  0 siblings, 0 replies; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-02 20:14 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Tue, Aug 02, 2016 at 08:12:34PM +0200, David Hildenbrand wrote:
> > On Tue, Aug 02, 2016 at 01:58:46PM +0200, David Hildenbrand wrote:
> > [...]
> > > So we have:
> > > a) "query-cpu-model-expansion" - tell us what the "host" or another CPU
> > >    model looks like. Either falling back to a static model or
> > >    completely exposing all properties.  
> > 
> > The query-cpu-model-expansion interface looks good to me. I just
> > had a few comments about the interface documentation.
> > 
> > > b) "query-cpu-model-comparison" - tell us how two CPU models compare,
> > >     indicating which properties were responsible for the decision.
> > > c) "query-cpu-model-baseline" - create a new model out of two models,
> > >     taking a requested level of stability into account.  
> > 
> > I miss a clearer specifiction of what are the actual requirements
> > and use cases of query-cpu-model-baseline. Is it related to
> > runnability? If so, how exactly?
> 
> cpu-baseline and cpu-compare are only needed to make
> - "virsh cpu-compare"
> - "virsh cpu-baseline" work
> (see libvirt usecases below)
> 
> These commands are needed to find/test runnability of a CPU model for
> a cluster in bigger installations by tooling.
> 
> As libvirt won't have details about s390x models, we have to provide
> an interface so it can carry out these tasks.
> 
> > 
> > Related to that (as mentioned in my reply to patch 25/29), I
> > would like a clearer definintion of what "superset" and "subset"
> > mean exactly, in query-cpu-model-comparison. Likewise, I would
> > like to understand the requirements and use cases that make
> > "superset" and "subset" useful.
> 
> I took these definitions from libvirt directly.
> 
> Example: core2duo against my sandybridge
> $ virsh cpu-compare test.xml
> Host CPU is a superset of CPU described in test.xml
> 
> Usually, you do a "virsh cpu-compare" against your host cpu model. Chances
> that the result is identical are very low. So depending on which
> one is the first model, you get superset or subset.
> 
> So
> if A is a subset of B, A will run where B runs
> if A is a superset of B, B will run where A runs
> 
> That means, if "cpu-compare" (against your host!) returns "identical" or
> "superset", you're good to go. If they are "incompatible" or "subset",
> you will have to use cpu-baseline to create a compatible model.
> 
> Does that answer your question?

It does, thanks! We need this to be clearly specified in the QMP
command documentation.

Proably the "if A is a superset of B, [...]" rule is enough to
unambigiously specify the semantics, while the rest of your
explanation is useful to explain when/how exactly the command is
useful.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion"
  2016-08-02 15:38       ` Eduardo Habkost
@ 2016-08-03  7:02         ` David Hildenbrand
  0 siblings, 0 replies; 56+ messages in thread
From: David Hildenbrand @ 2016-08-03  7:02 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

> On Tue, Aug 02, 2016 at 05:04:05PM +0200, David Hildenbrand wrote:
> [...]
> > >   
> > > > +#          model can be used by tooling without having to specify a
> > > > +#          compatibility machine - e.g. when displaying the "host" model.
> > > > +#          All static CPU models are migration-safe.    
> > > 
> > > This is cool. Unfortunately we are not going to support it in x86
> > > very soon because we don't have any static CPU models.  
> > 
> > Well, it's all about finding a minimum set of features that one can work with.
> > I assume e.g. a Phenom also always has a minimum set of features?  
> 
> We could have a very minimal CPU model that is static in x86,
> yes. We just need to find out "how minimal" we can really make
> it.

Right. Basically, on s390x we have two types of features
1) hypervisor managed
2) non-hypervisor managed

Meaning the hypervisor can blindly forward 2), but needs special implementation
for 1). This implies that old releases of an hypervisor will only show 2) but
not 1).

We can therefore move all 2) that are made public (~99%) into the minimum model
+ some very old 1) that are always expected to be around nowadays.

Actually going below the minimum model is possible on s390x, could just happen
that e.g. Linux will not boot anymore.

But the question is, if static CPU models for x86 are really needed. I assume
you only make veeeery little changes to these models, so showing them
without a compatibility machine should almost always give the same result. And
that's the main difference to s390x. The other one is obviously that we have
much more feature variance, depending under which hypervisor (LPAR/KVM/z/VM)
and version we're running.

> 
> >   
> > >   
> > > > +#
> > > > +# @full: Expand all properties. The produced model is not guaranteed to be
> > > > +#        migration-safe, but allows tooling to get an insight and work with
> > > > +#        model details.    
> > > 
> > > I wonder if we really need to document it broadly as "not
> > > guaranteed to be migration-safe". The returned data will be
> > > migration-safe (but not static) if the CPU model being expanded
> > > is migration-safe, won't it?  
> > 
> > Actually I don't think so.
> > Imagine expanding host: featA=true, featB=false  
> 
> In this case, "host" is not migration-safe, so the results will
> not be migration-safe.

Yes, so I'll keep this remark for now.

> > > > +#
> > > > +# s390x supports expanding of all CPU models with all expansion types. Other
> > > > +# architectures are not supported yet.    
> > > 
> > > I think this paragraph is likely to get obsolete very soon (as
> > > people may forget to update it when implementing the new
> > > interface on other architectures). Also, the paragraph is not
> > > true until patch 27/29 is applied.
> > > 
> > > Maybe write it as "Some architectures may not support all
> > > expansion types".  
> > 
> > Agreed. And most likely x86 won't support expanding all CPU models I assume?  
> 
> It will probably support expanding all CPU models in the same way
> (when using "full").
> 

Cool! Thanks!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 15:47       ` Eduardo Habkost
@ 2016-08-03  7:09         ` David Hildenbrand
  2016-08-03 17:39           ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-03  7:09 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu


> > >   
> > 
> > I think this is "feature subset" on the one hand and "earlier generation"
> > on the other hand - at least for s390x. But it boils down to runnability I
> > think: (< and > are actually quite misleading)  
> 
> It sounds like we need to clarify what are the use cases and
> requirements, to find out how to document the exact meaning of
> "superset" and "subset".
> 
> I assume this is closely related to the semantics of
> query-cpu-model-baseline (which I didn't review yet). In other
> words: "superset" and "subset" means you can save a
> query-cpu-model-baseline call because you already know modela or
> modelb can be used as baseline, already. Is that correct?

Depends on the order of parameters. But I think this was clarified to my reply
in the cover letter. Will improve the overall explanation of
query-cpu-model-comparison

> 
> In this case, I will get back to this while reviewing and
> discussing query-cpu-model-baseline.

That sure makes sense, they go hand-in-hand, especially for the two commands
"virsh cpu-baseline" and "virsh cpu-compare". It's all about testing/detecting
runnable CPU models for different environments.

[...]
> > > > Other architectures are not
> > > > +# supported yet.    
> > > 
> > > What if we provide a generic comparison function that does like
> > > the following pseudocode:
> > > 
> > > def basic_comparison(modela, modelb):
> > >   if modela.name == modelb.name:
> > >     if modela.props == modelb.props:
> > >       return "identical", []
> > >     else:
> > >       #XXX: maybe add some extra logic to check if
> > >       # modela.props is a subset or superset of modelb.props?
> > >       return "incompatible", set(modela.props.keys(), modelb.props.keys())
> > >   else:
> > >     return "incompatible", ["type"]
> > > 
> > > def full_comparison(modela, modelb):
> > >   r,p = basic_comparison(modela, modelb)
> > >   if r == "incompatible":
> > >     try:
> > >       modela = expand_cpu_model(modela, "full")
> > >       modelb = expand_cpu_model(modelb, "full")
> > >     except:
> > >       # in case "full" expansion mode is not supported
> > >       return r,p
> > >     return basic_comparison(modela, modelb)
> > >   
> > 
> > While I agree that that would be nice to have, it doesn't fit for s390x right
> > now: The result on s390x does not rely on features/name only, but internal data
> > we don't want to expose.
> > 
> > e.g. z13.2 and z13s are considered identically.
> > 
> > z13 is a subset of z13.2, although they have exactly the same
> > features/properties (right now). It basically has to do with internal data
> > (e.g. address bus sizes for hamax as an example)
> > 
> > (that's where we indictate "type" under "responsible-properties" - they can
> > never be made identically, you have to baseline).  
> 
> Right, I don't mean it to be enough for all architectures, but as
> a basic implementation that is minimally useful when there's no
> arch-specific comparison function.

Then the question would be: Is it better to have a wrong result than any result?
As it doesn't work on s390x, there could also be a problem with other
architectures.

Especially when comparing against "host", the name after expansion would give
no identication about runnability. And only living with
"incompatible" and "identical" might also not really be enough.

While this could make sense, I'd suggest postponing such a basic comapare
function until other architectures support the basics (expanding to full) and
then see if this basic function would work for them (maybe x86 is a good
candidate once the expanded name would not be "host" anymore).

Thanks Eduardo!

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-03  7:09         ` David Hildenbrand
@ 2016-08-03 17:39           ` Eduardo Habkost
  0 siblings, 0 replies; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-03 17:39 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, jdenemar, imammedo, cornelia.huck, borntraeger, fiuczy, mimu

On Wed, Aug 03, 2016 at 09:09:25AM +0200, David Hildenbrand wrote:
[...]
> > > > > Other architectures are not
> > > > > +# supported yet.    
> > > > 
> > > > What if we provide a generic comparison function that does like
> > > > the following pseudocode:
> > > > 
> > > > def basic_comparison(modela, modelb):
> > > >   if modela.name == modelb.name:
> > > >     if modela.props == modelb.props:
> > > >       return "identical", []
> > > >     else:
> > > >       #XXX: maybe add some extra logic to check if
> > > >       # modela.props is a subset or superset of modelb.props?
> > > >       return "incompatible", set(modela.props.keys(), modelb.props.keys())
> > > >   else:
> > > >     return "incompatible", ["type"]
> > > > 
> > > > def full_comparison(modela, modelb):
> > > >   r,p = basic_comparison(modela, modelb)
> > > >   if r == "incompatible":
> > > >     try:
> > > >       modela = expand_cpu_model(modela, "full")
> > > >       modelb = expand_cpu_model(modelb, "full")
> > > >     except:
> > > >       # in case "full" expansion mode is not supported
> > > >       return r,p
> > > >     return basic_comparison(modela, modelb)
> > > >   
> > > 
> > > While I agree that that would be nice to have, it doesn't fit for s390x right
> > > now: The result on s390x does not rely on features/name only, but internal data
> > > we don't want to expose.
> > > 
> > > e.g. z13.2 and z13s are considered identically.
> > > 
> > > z13 is a subset of z13.2, although they have exactly the same
> > > features/properties (right now). It basically has to do with internal data
> > > (e.g. address bus sizes for hamax as an example)
> > > 
> > > (that's where we indictate "type" under "responsible-properties" - they can
> > > never be made identically, you have to baseline).  
> > 
> > Right, I don't mean it to be enough for all architectures, but as
> > a basic implementation that is minimally useful when there's no
> > arch-specific comparison function.
> 
> Then the question would be: Is it better to have a wrong result than any result?
> As it doesn't work on s390x, there could also be a problem with other
> architectures.
> 
> Especially when comparing against "host", the name after expansion would give
> no identication about runnability. And only living with
> "incompatible" and "identical" might also not really be enough.
> 
> While this could make sense, I'd suggest postponing such a basic comapare
> function until other architectures support the basics (expanding to full) and
> then see if this basic function would work for them (maybe x86 is a good
> candidate once the expanded name would not be "host" anymore).

Agreed. After we have a x86 implementation, we can look into
implementing a generic comparison function (but make it opt-in,
instead of enabling it for all architectures at once).

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline"
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline" David Hildenbrand
@ 2016-08-04  7:32   ` David Hildenbrand
  2016-08-04 14:36     ` Eduardo Habkost
  0 siblings, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-04  7:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, borntraeger, fiuczy, cornelia.huck, imammedo, jdenemar, mimu


> +##
> +# @query-cpu-model-baseline:
> +#
> +# Baseline two CPU models, creating a compatible third model. The created
> +# model will always be a static, migration-safe CPU model (see "static"
> +# CPU model expansion for details). The QEMU machine QEMU has been started
> +# with affects the result if CPU definitions are used that are not static.
> +#
> +# Note: This interface should not be used when global properties of CPU classes
> +#       are changed (e.g. via "-cpu ...").
> +#
> +# s390x supports baselining of all CPU models. Other architectures are not
> +# supported yet.
> +#
> +# Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU models is
> +#          not supported, if a model cannot be used, if a model contains
> +#          an unknown cpu definition name, unknown properties or properties
> +#          with wrong types.
> +#
> +# Since: 2.8.0
> +##


This comment is now:

##                                                                                  
# @query-cpu-model-baseline:                                                        
#                                                                                   
# Baseline two CPU models, creating a compatible third model. The created           
# model will always be a static, migration-safe CPU model (see "static"             
# CPU model expansion for details).                                                 
#                                                                                   
# This interface can be used by tooling to create a compatible CPU model out    
# two CPU models. The created CPU model will be identical to or a subset of     
# both CPU models when comparing them. Therefore, the created CPU model is          
# guaranteed to run where the given CPU models run.                                 
#                                                                                   
# The result returned by this command may be affected by:                           
#                                                                                   
# * QEMU version: CPU models may look different depending on the QEMU version.  
#   (Except for CPU models reported as "static" in query-cpu-definitions.)          
# * machine-type: CPU model  may look different depending on the machine-type.  
#   (Except for CPU models reported as "static" in query-cpu-definitions.)          
# * machine options (including accelerator): in some architectures, CPU models  
#   may look different depending on machine and accelerator options. (Except for
#   CPU models reported as "static" in query-cpu-definitions.)                      
# * "-cpu" arguments and global properties: arguments to the -cpu option and    
#   global properties may affect expansion of CPU models. Using                     
#   query-cpu-model-expansion while using these is not advised.                     
#                                                                                   
# Some architectures may not support baselining CPU models. s390x supports          
# baselining CPU models.                                                            
#                                                                                   
# Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU models is 
#          not supported, if a model cannot be used, if a model contains            
#          an unknown cpu definition name, unknown properties or properties     
#          with wrong types.                                                        
#                                                                                   
# Since: 2.8.0                                                                      
##      

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-02 11:59 ` [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
  2016-08-02 14:45   ` Eduardo Habkost
@ 2016-08-04  7:34   ` David Hildenbrand
  2016-08-04 14:36     ` Eduardo Habkost
  1 sibling, 1 reply; 56+ messages in thread
From: David Hildenbrand @ 2016-08-04  7:34 UTC (permalink / raw)
  To: qemu-devel
  Cc: ehabkost, borntraeger, fiuczy, cornelia.huck, imammedo, jdenemar, mimu


> +##
> +# @CpuModelCompareResult:
> +#
> +# An enumeration of CPU model comparation results.
> +#
> +# @incompatible: both model definition are incompatible
> +#
> +# @identical: model A == model B
> +#
> +# @superset: model A > model B
> +#
> +# @subset: model A < model B
> +#
> +# Since: 2.8.0
> +##

This comment is now:

##                                                                              
# @CpuModelCompareResult:                                                       
#                                                                               
# An enumeration of CPU model comparation results. The result is usually        
# calcualted using e.g. at CPU features or CPU generations.                     
#                                                                               
# @incompatible: If model A is incompatible to model B, model A is not          
#                guaranteed to run where model B runs and the other way around. 
#                                                                               
# @identical: If model A is identical to model B, model A is guaranteed to run  
#             where model B runs and the other way around.                      
#                                                                               
# @superset: If model A is a superset of model B, model B is guaranteed to run  
#            where model A runs. There are no guarantees about the other way.   
#                                                                               
# @subset: If model A is a subset of model B, model A is guaranteed to run      
#          where model B runs. There are no guarantees about the other way.     
#                                                                               
# Since: 2.8.0                                                                  
##

Think it's all about guarantees.

> +{ 'enum': 'CpuModelCompareResult',
> +  'data': [ 'incompatible', 'identical', 'superset', 'subset' ] }
> +
> +##
> +# @CpuModelCompareInfo
> +#
> +# The result of a CPU model comparison.
> +#
> +# @result: The result of the compare operation.
> +# @responsible-properties: List of properties that led to the comparison result
> +#                          not being identical.
> +#
> +# @responsible-properties is a list of QOM property names that led to
> +# both CPUs not being detected as identical. For identical models, this
> +# list is empty.
> +# If a QOM property is read-only, that means there's no known way to make the
> +# CPU models identical. If the special property name "type" is included, the
> +# models are by definition not identical and cannot be made identical.
> +#
> +# Since: 2.8.0
> +##
> +{ 'struct': 'CpuModelCompareInfo',
> +  'data': {'result': 'CpuModelCompareResult',
> +           'responsible-properties': ['str']
> +          }
> +}
> +
> +##
> +# @query-cpu-model-comparison:
> +#
> +# Compares two CPU models, returning how they compare under a specific QEMU
> +# machine.
> +#
> +# Note: This interface should not be used when global properties of CPU classes
> +#       are changed (e.g. via "-cpu ...").
> +#
> +# s390x supports comparing of all CPU models. Other architectures are not
> +# supported yet.
> +#
> +# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU models is
> +#          not supported, if a model cannot be used, if a model contains
> +#          an unknown cpu definition name, unknown properties or properties
> +#          with wrong types.
> +#
> +# Since: 2.8.0
> +##

This comment is now:

##                                                                              
# @query-cpu-model-comparison:                                                  
#                                                                               
# Compares two CPU models, returning how they compare in a specific             
# configuration. The results indicates how both models compare regarding        
# runnability. This result can be used by tooling to make decisions if a        
# certain CPU model will run in a certain configuration or if a compatible      
# CPU model has to be created by baselining.                                    
#                                                                               
# Usually, a CPU model is compared against the maximum possible CPU model       
# of a ceratin configuration (e.g. the "host" model for KVM). If that CPU       
# model is identical or a subset, it will run in that configuration.            
#                                                                               
# The result returned by this command may be affected by:                       
#                                                                               
# * QEMU version: CPU models may look different depending on the QEMU version.  
#   (Except for CPU models reported as "static" in query-cpu-definitions.)      
# * machine-type: CPU model  may look different depending on the machine-type.  
#   (Except for CPU models reported as "static" in query-cpu-definitions.)      
# * machine options (including accelerator): in some architectures, CPU models  
#   may look different depending on machine and accelerator options. (Except for
#   CPU models reported as "static" in query-cpu-definitions.)                  
# * "-cpu" arguments and global properties: arguments to the -cpu option and    
#   global properties may affect expansion of CPU models. Using                 
#   query-cpu-model-expansion while using these is not advised.                 
#                                                                               
# Some architectures may not support comparing CPU models. s390x supports       
# comparing CPU models.                                                         
#                                                                               
# Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU models is  
#          not supported, if a model cannot be used, if a model contains        
#          an unknown cpu definition name, unknown properties or properties     
#          with wrong types.                                                    
#                                                                               
# Since: 2.8.0                                                                  
##  

(excluding the remark about s390x in this patch)

David

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline"
  2016-08-04  7:32   ` David Hildenbrand
@ 2016-08-04 14:36     ` Eduardo Habkost
  0 siblings, 0 replies; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-04 14:36 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, borntraeger, fiuczy, cornelia.huck, imammedo, jdenemar, mimu

On Thu, Aug 04, 2016 at 09:32:22AM +0200, David Hildenbrand wrote:
> ##                                                                                  
> # @query-cpu-model-baseline:                                                        
> #                                                                                   
> # Baseline two CPU models, creating a compatible third model. The created           
> # model will always be a static, migration-safe CPU model (see "static"             
> # CPU model expansion for details).                                                 
> #                                                                                   
> # This interface can be used by tooling to create a compatible CPU model out    
> # two CPU models. The created CPU model will be identical to or a subset of     
> # both CPU models when comparing them. Therefore, the created CPU model is          
> # guaranteed to run where the given CPU models run.                                 
> #                                                                                   
> # The result returned by this command may be affected by:                           
> #                                                                                   
> # * QEMU version: CPU models may look different depending on the QEMU version.  
> #   (Except for CPU models reported as "static" in query-cpu-definitions.)          
> # * machine-type: CPU model  may look different depending on the machine-type.  
> #   (Except for CPU models reported as "static" in query-cpu-definitions.)          
> # * machine options (including accelerator): in some architectures, CPU models  
> #   may look different depending on machine and accelerator options. (Except for
> #   CPU models reported as "static" in query-cpu-definitions.)                      
> # * "-cpu" arguments and global properties: arguments to the -cpu option and    
> #   global properties may affect expansion of CPU models. Using                     
> #   query-cpu-model-expansion while using these is not advised.                     
> #                                                                                   
> # Some architectures may not support baselining CPU models. s390x supports          
> # baselining CPU models.                                                            
> #                                                                                   
> # Returns: a CpuModelBaselineInfo. Returns an error if baselining CPU models is 
> #          not supported, if a model cannot be used, if a model contains            
> #          an unknown cpu definition name, unknown properties or properties     
> #          with wrong types.                                                        
> #                                                                                   
> # Since: 2.8.0                                                                      
> ##      

Looks very clear to me, now. Thanks!

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

* Re: [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison"
  2016-08-04  7:34   ` David Hildenbrand
@ 2016-08-04 14:36     ` Eduardo Habkost
  0 siblings, 0 replies; 56+ messages in thread
From: Eduardo Habkost @ 2016-08-04 14:36 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-devel, borntraeger, fiuczy, cornelia.huck, imammedo, jdenemar, mimu

On Thu, Aug 04, 2016 at 09:34:16AM +0200, David Hildenbrand wrote:
> ##                                                                              
> # @CpuModelCompareResult:                                                       
> #                                                                               
> # An enumeration of CPU model comparation results. The result is usually        
> # calcualted using e.g. at CPU features or CPU generations.                     
> #                                                                               
> # @incompatible: If model A is incompatible to model B, model A is not          
> #                guaranteed to run where model B runs and the other way around. 
> #                                                                               
> # @identical: If model A is identical to model B, model A is guaranteed to run  
> #             where model B runs and the other way around.                      
> #                                                                               
> # @superset: If model A is a superset of model B, model B is guaranteed to run  
> #            where model A runs. There are no guarantees about the other way.   
> #                                                                               
> # @subset: If model A is a subset of model B, model A is guaranteed to run      
> #          where model B runs. There are no guarantees about the other way.     
> #                                                                               
> # Since: 2.8.0                                                                  
> ##
> 
> Think it's all about guarantees.
> 
[...]
> This comment is now:
> 
> ##                                                                              
> # @query-cpu-model-comparison:                                                  
> #                                                                               
> # Compares two CPU models, returning how they compare in a specific             
> # configuration. The results indicates how both models compare regarding        
> # runnability. This result can be used by tooling to make decisions if a        
> # certain CPU model will run in a certain configuration or if a compatible      
> # CPU model has to be created by baselining.                                    
> #                                                                               
> # Usually, a CPU model is compared against the maximum possible CPU model       
> # of a ceratin configuration (e.g. the "host" model for KVM). If that CPU       
> # model is identical or a subset, it will run in that configuration.            
> #                                                                               
> # The result returned by this command may be affected by:                       
> #                                                                               
> # * QEMU version: CPU models may look different depending on the QEMU version.  
> #   (Except for CPU models reported as "static" in query-cpu-definitions.)      
> # * machine-type: CPU model  may look different depending on the machine-type.  
> #   (Except for CPU models reported as "static" in query-cpu-definitions.)      
> # * machine options (including accelerator): in some architectures, CPU models  
> #   may look different depending on machine and accelerator options. (Except for
> #   CPU models reported as "static" in query-cpu-definitions.)                  
> # * "-cpu" arguments and global properties: arguments to the -cpu option and    
> #   global properties may affect expansion of CPU models. Using                 
> #   query-cpu-model-expansion while using these is not advised.                 
> #                                                                               
> # Some architectures may not support comparing CPU models. s390x supports       
> # comparing CPU models.                                                         
> #                                                                               
> # Returns: a CpuModelBaselineInfo. Returns an error if comparing CPU models is  
> #          not supported, if a model cannot be used, if a model contains        
> #          an unknown cpu definition name, unknown properties or properties     
> #          with wrong types.                                                    
> #                                                                               
> # Since: 2.8.0                                                                  
> ##  
> 
> (excluding the remark about s390x in this patch)

Both look very clear to me. Thanks!

-- 
Eduardo

^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2016-08-04 14:36 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-02 11:58 [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
2016-08-02 13:04   ` Eduardo Habkost
2016-08-02 13:23     ` David Hildenbrand
2016-08-02 14:00       ` Eduardo Habkost
2016-08-02 14:27         ` David Hildenbrand
2016-08-02 14:49           ` Eduardo Habkost
2016-08-02 14:53             ` David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 02/29] s390x/cpumodel: "host" and "qemu" as CPU subclasses David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 03/29] s390x/cpumodel: expose CPU class properties David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 04/29] s390x/cpumodel: introduce CPU features David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 05/29] s390x/cpumodel: generate CPU feature lists for CPU models David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 06/29] s390x/cpumodel: generate CPU feature group lists David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 07/29] s390x/cpumodel: introduce CPU feature group definitions David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 08/29] s390x/cpumodel: register defined CPU models as subclasses David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 09/29] s390x/cpumodel: store the CPU model in the CPU instance David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 10/29] s390x/cpumodel: expose features and feature groups as properties David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 11/29] s390x/cpumodel: let the CPU model handle feature checks David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 12/29] s390x/cpumodel: check and apply the CPU model David Hildenbrand
2016-08-02 11:58 ` [Qemu-devel] [Patch v1 13/29] s390x/sclp: factor out preparation of cpu entries David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 14/29] s390x/sclp: introduce sclp feature blocks David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 15/29] s390x/sclp: indicate sclp features David Hildenbrand
2016-08-02 12:31   ` Thomas Huth
2016-08-02 13:00     ` David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 16/29] s390x/sclp: propagate the ibc val(lowest and unblocked ibc) David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 17/29] s390x/sclp: propagate the mha via sclp David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 18/29] s390x/sclp: propagate hmfai David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 19/29] linux-headers: update against kvm/next David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 20/29] s390x/kvm: allow runtime-instrumentation for "none" machine David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 21/29] s390x/kvm: implement CPU model support David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 22/29] s390x/kvm: disable host model for existing compat machines David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 23/29] s390x/kvm: let the CPU model control CMM(A) David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 24/29] qmp: add QMP interface "query-cpu-model-expansion" David Hildenbrand
2016-08-02 13:45   ` Eduardo Habkost
2016-08-02 15:04     ` David Hildenbrand
2016-08-02 15:38       ` Eduardo Habkost
2016-08-03  7:02         ` David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
2016-08-02 14:45   ` Eduardo Habkost
2016-08-02 15:15     ` David Hildenbrand
2016-08-02 15:47       ` Eduardo Habkost
2016-08-03  7:09         ` David Hildenbrand
2016-08-03 17:39           ` Eduardo Habkost
2016-08-04  7:34   ` David Hildenbrand
2016-08-04 14:36     ` Eduardo Habkost
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 26/29] qmp: add QMP interface "query-cpu-model-baseline" David Hildenbrand
2016-08-04  7:32   ` David Hildenbrand
2016-08-04 14:36     ` Eduardo Habkost
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" David Hildenbrand
2016-08-02 14:22   ` Eduardo Habkost
2016-08-02 14:28     ` David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 28/29] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison" David Hildenbrand
2016-08-02 11:59 ` [Qemu-devel] [Patch v1 29/29] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline" David Hildenbrand
2016-08-02 17:28 ` [Qemu-devel] [Patch v1 00/29] s390x CPU models: exposing features Eduardo Habkost
2016-08-02 18:12   ` David Hildenbrand
2016-08-02 20:14     ` Eduardo Habkost

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.