Skip to contentSkip to conversation

s390x CPU models: exposing features

RFC In review David Hildenbrand 4 participants 53 messages Jun 21, 2016 – Jul 11, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

cover s390x CPU models: exposing features

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 fixed 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.

But, the fixed feature set is not really what we want to use as a default. It is just like a really minimum, stable base.

So we have
a) A "stable" 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". These are migration safe.
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. These models are not migration safe, e.g "z13" or "z10EC.2". The feature set can differ between QEMU versions.
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

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 a migration unsafe model looks like. Either falling back to a stable model or completely exposing all properties. We are interested in stable models.
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.

As we are aware that e.g. x86 has their own idea of a CPU model and their existing implementation in place, but are also looking into to ways to e.g. expand the "host" CPU model to a detailed representation, we designed the "expansion" interface to also allow that.

Comments are very welcome, but please always keep the restrictions and specialties in mind when suggesting some major design changes.

The header update will be replaced by a kvm-next header update as soon as the VSIE patches are upstream. The major KVM interface changes are already part of kvm-next.

The current state is available on git://github.com/cohuck/qemu on branch "cpumodel-s390x".

David Hildenbrand (26):
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
update linux headers (CPU model)
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              |   10 +
 linux-headers/asm-s390/kvm.h            |   40 ++
 qapi-schema.json                        |  184 ++++++
 qmp-commands.hx                         |   18 +
 qmp.c                                   |   22 +
 rules.mak                               |    1 +
 stubs/Makefile.objs                     |    3 +
 stubs/arch-query-cpu-model-baseline.c   |   13 +
 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                  |    5 +
 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               | 1055 +++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h               |  113 ++++
 target-s390x/gen-features.c             |  587 +++++++++++++++++
 target-s390x/helper.c                   |   29 +-
 target-s390x/kvm.c                      |  346 +++++++++-
 target-s390x/machine.c                  |   14 +-
 27 files changed, 3203 insertions(+), 66 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
Signature · 1 line
2.6.6
#1 lore raw

RFC 1/28 s390x/cpumodel: "host" and "qemu" as CPU subclasses

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. Bot models are not migration safe. They 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.

---
 hw/s390x/s390-virtio.c     |   6 +-
 target-s390x/Makefile.objs |   2 +-
 target-s390x/cpu-qom.h     |   3 +
 target-s390x/cpu.c         |  33 +++------
 target-s390x/cpu.h         |   2 +
 target-s390x/cpu_models.c  | 164 +++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/helper.c      |  29 +++++++-
 7 files changed, 211 insertions(+), 28 deletions(-)
 create mode 100644 target-s390x/cpu_models.c
hw/s390x/s390-virtio.c +5 -1
index 544c616..0a96347 100644
@@ -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);
target-s390x/Makefile.objs +1 -1
index dd62cbd..34bd693 100644
@@ -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
target-s390x/cpu-qom.h +3 -0
index 66b5d18..ae0be73 100644
@@ -45,6 +45,9 @@ typedef struct S390CPUClass {
     /*< private >*/
     CPUClass parent_class;
     /*< public >*/
+    bool kvm_required;
+    bool migration_safe;
+    const char *desc;
 
     int64_t next_cpu_id;
 
target-s390x/cpu.c +8 -25
index e43e2d6..44e53ec 100644
@@ -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,
 };
target-s390x/cpu.h +2 -0
index bd6b2e5..f1cb9a2 100644
@@ -632,6 +632,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) */
target-s390x/cpu_models.c new file +164 -0

164 lines not on this page · raw message

target-s390x/helper.c +28 -1
index 54a5177..2eaba9a 100644
@@ -70,7 +70,34 @@ void s390x_cpu_timer(void *opaque)
 
 S390CPU *cpu_s390x_create(const char *cpu_model, Error **errp)
 {
-    return S390_CPU(object_new(TYPE_S390_CPU));
+    char *name, *features;
+    CPUState *cpu;
+    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;
+    }
+    cpu = CPU(object_new(object_class_get_name(oc)));
+    cc = CPU_GET_CLASS(cpu);
+
+    cc->parse_features(cpu, features, errp);
+    if (*errp) {
+        object_unref(OBJECT(cpu));
+        g_free(name);
+        return NULL;
+    }
+    return S390_CPU(cpu);
 }
 
 S390CPU *s390x_new_cpu(const char *cpu_model, int64_t id, Error **errp)
Signature · 1 line
2.6.6
#2 lore raw

RFC 2/28 s390x/cpumodel: expose CPU class properties

In reply to David Hildenbrand

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

---
 target-s390x/cpu.c        |  1 +
 target-s390x/cpu.h        |  1 +
 target-s390x/cpu_models.c | 18 ++++++++++++++++++
 3 files changed, 20 insertions(+)
target-s390x/cpu.c +1 -0
index 44e53ec..d7d0b62 100644
@@ -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 = {
target-s390x/cpu.h +1 -0
index f1cb9a2..832da89 100644
@@ -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_class_register_props(ObjectClass *oc);
 void s390_realize_cpu_model(CPUState *cs, Error **errp);
 ObjectClass *s390_cpu_class_by_name(const char *name);
 
target-s390x/cpu_models.c +18 -0
index 08ed640..18638a9 100644
@@ -98,6 +98,24 @@ static void s390_cpu_model_finalize(Object *obj)
 {
 }
 
+static bool get_migratable(Object *obj, Error **errp)
+{
+    return S390_CPU_GET_CLASS(obj)->migration_safe;
+}
+
+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, "migratable", get_migratable, 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)
 {
Signature · 1 line
2.6.6
#3 lore raw

RFC 3/28 s390x/cpumodel: introduce CPU features

In reply to David Hildenbrand

From: Michael Mueller <[email protected]>

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.

[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
target-s390x/Makefile.objs +1 -1
index 34bd693..4266c87 100644
@@ -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
target-s390x/cpu_features.c new file +334 -0

334 lines not on this page · raw message

target-s390x/cpu_features.h new file +279 -0

279 lines not on this page · raw message

Signature · 1 line
2.6.6
#4 lore raw

RFC 4/28 s390x/cpumodel: generate CPU feature lists for CPU models

In reply to David Hildenbrand

From: Michael Mueller <[email protected]>

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.

[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
Makefile.target +1 -1
index 495b474..2ed5add 100644
@@ -215,7 +215,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
rules.mak +1 -0
index 72c5955..ce0a2a5 100644
@@ -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))
target-s390x/Makefile.objs +20 -0
index 4266c87..745d501 100644
@@ -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
target-s390x/gen-features.c new file +506 -0

506 lines not on this page · raw message

Signature · 1 line
2.6.6
#5 lore raw

RFC 5/28 s390x/cpumodel: generate CPU feature group lists

In reply to David Hildenbrand

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.

---
 target-s390x/gen-features.c | 80 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)
target-s390x/gen-features.c +80 -0
index 3a7c373..d4f4b29 100644
@@ -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;
 }
Signature · 1 line
2.6.6
#6 lore raw

RFC 6/28 s390x/cpumodel: introduce CPU feature group definitions

In reply to David Hildenbrand

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.

---
 target-s390x/cpu_features.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/cpu_features.h | 23 +++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
target-s390x/cpu_features.c +43 -1
index c78a189..6ec2bfc 100644
@@ -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];
+}
target-s390x/cpu_features.h +23 -0
index 485446c..e40a636 100644
@@ -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))
 
Signature · 1 line
2.6.6
#7 lore raw

Re: [Qemu-devel] [RFC 06/28] s390x/cpumodel: introduce CPU feature group definitions

Quoted 36 lines · David Hildenbrand

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.

---
 target-s390x/cpu_features.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/cpu_features.h | 23 +++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
target-s390x/cpu_features.c +4 -1
index c78a189..6ec2bfc 100644
@@ -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;
 

target-s390x/cpu_features.c void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, · line 341

Quoted 10 lines
target-s390x/cpu_features.c +10 -0
+    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);

Maybe simply write

               fn(dev->name, opaque);

instead?

Thomas

#8 lore raw

Re: [Qemu-devel] [RFC 06/28] s390x/cpumodel: introduce CPU feature group definitions

Quoted 49 lines · David Hildenbrand
Quoted 36 lines

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.

---
 target-s390x/cpu_features.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/cpu_features.h | 23 +++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
target-s390x/cpu_features.c +4 -1
index c78a189..6ec2bfc 100644
@@ -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;
 

target-s390x/cpu_features.c void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, · line 341

Quoted 10 lines
target-s390x/cpu_features.c +10 -0
+    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);  

Maybe simply write

Quoted 2 lines
               fn(dev->name, opaque);

instead?

Will that work? As fn is a pointer I am not a 100% sure. If so, I'll change it!

Thanks!

David

#9 lore raw

Re: [Qemu-devel] [RFC 06/28] s390x/cpumodel: introduce CPU feature group definitions

Quoted 52 lines · David Hildenbrand
Quoted 49 lines · David Hildenbrand
Quoted 36 lines

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.

---
 target-s390x/cpu_features.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/cpu_features.h | 23 +++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)
target-s390x/cpu_features.c +4 -1
index c78a189..6ec2bfc 100644
@@ -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;
 

target-s390x/cpu_features.c void s390_add_from_feat_block(S390FeatBitmap features, S390FeatType type, · line 341

Quoted 10 lines
target-s390x/cpu_features.c +10 -0
+    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);  

Maybe simply write

Quoted 2 lines
               fn(dev->name, opaque);

instead?

Quoted 1 line

Will that work? As fn is a pointer I am not a 100% sure. If so, I'll change it!

Both are 100% equivalent. Actually, the expression denoting the function to be called has to be a function pointer, but (*fn) happens to be magically converted back to a function pointer because the spec says so.

Signature · 1 line
Eduardo
#10 lore raw

RFC 7/28 s390x/cpumodel: register defined CPU models as subclasses

In reply to David Hildenbrand

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 save 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.

---
 target-s390x/cpu-qom.h    |   2 +
 target-s390x/cpu_models.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h |  36 +++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 target-s390x/cpu_models.h
target-s390x/cpu-qom.h +2 -0
index ae0be73..d619cbd 100644
@@ -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 migration_safe;
     const char *desc;
target-s390x/cpu_models.c +111 -0

146 lines not on this page · raw message

target-s390x/cpu_models.h new file +36 -0
new file mode 100644
index 0000000..13f7217
@@ -0,0 +1,36 @@
+/*
+ * CPU models for s390x
+ *
+ * Copyright 2016 IBM Corp.
+ *
+ * Author(s): David Hildenbrand <[email protected]>
+ *
+ * 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 */
Signature · 1 line
2.6.6
#11 lore raw

RFC 8/28 s390x/cpumodel: store the CPU model in the CPU instance

In reply to David Hildenbrand

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.

---
 target-s390x/cpu.h        |  1 +
 target-s390x/cpu_models.c | 26 ++++++++++++++++++++++++++
 target-s390x/cpu_models.h | 10 ++++++++++
 3 files changed, 37 insertions(+)
target-s390x/cpu.h +1 -0
index 832da89..ec60b3b 100644
@@ -187,6 +187,7 @@ struct S390CPU {
 
     CPUS390XState env;
     int64_t id;
+    S390CPUModel *model;
     /* needed for live migration */
     void *irqstate;
     uint32_t irqstate_saved_size;
target-s390x/cpu_models.c +26 -0
index 50b395a..d54b795 100644
@@ -141,6 +141,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->migration_safe) {
+        /* base model - features will mever 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
@@ -151,10 +166,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_migratable(Object *obj, Error **errp)
target-s390x/cpu_models.h +10 -0
index 13f7217..244256b 100644
@@ -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 */
Signature · 1 line
2.6.6
#12 lore raw

RFC 9/28 s390x/cpumodel: expose features and feature groups as properties

In reply to David Hildenbrand

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.

---
 target-s390x/cpu.c        |   1 +
 target-s390x/cpu.h        |   1 +
 target-s390x/cpu_models.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+)
target-s390x/cpu.c +1 -0
index d7d0b62..2f3c8e2 100644
@@ -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 +
target-s390x/cpu.h +1 -0
index ec60b3b..47a1861 100644
@@ -633,6 +633,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);
target-s390x/cpu_models.c +149 -0

169 lines not on this page · raw message

Signature · 1 line
2.6.6
#13 lore raw

RFC 10/28 s390x/cpumodel: let the CPU model handle feature checks

In reply to David Hildenbrand

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.

---
 target-s390x/cpu_models.c | 24 ++++++++++++++++++++++++
 target-s390x/cpu_models.h |  2 ++
 target-s390x/machine.c    | 14 ++------------
 3 files changed, 28 insertions(+), 12 deletions(-)
target-s390x/cpu_models.c +24 -0
index 93e63cb..7e3f544 100644
@@ -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;
target-s390x/cpu_models.h +2 -0
index 244256b..fe988cc 100644
@@ -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 */
target-s390x/machine.c +2 -12
index aa39e5d..edc3a47 100644
@@ -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 = {
Signature · 1 line
2.6.6
#14 lore raw

RFC 11/28 s390x/cpumodel: check and apply the CPU model

In reply to David Hildenbrand

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).

---
 target-s390x/cpu_models.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 154 insertions(+)
target-s390x/cpu_models.c +154 -0
index 7e3f544..e7bcea9 100644
@@ -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
@@ -170,14 +171,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,
Signature · 1 line
2.6.6
#15 lore raw

RFC 12/28 s390x/sclp: factor out preparation of cpu entries

In reply to David Hildenbrand

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.

---
 hw/s390x/sclp.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
hw/s390x/sclp.c +12 -10
index fca37f5..15d7114 100644
@@ -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);
 }
Signature · 1 line
2.6.6
#16 lore raw

RFC 13/28 s390x/sclp: introduce sclp feature blocks

In reply to David Hildenbrand

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.

---
 include/hw/s390x/sclp.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
include/hw/s390x/sclp.h +9 -3
index b0c71b5..743abd4 100644
@@ -97,11 +97,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;
@@ -117,10 +120,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];
Signature · 1 line
2.6.6
#17 lore raw

RFC 14/28 s390x/sclp: indicate sclp features

In reply to David Hildenbrand

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

---
 hw/s390x/sclp.c           |  9 +++++++++
 target-s390x/cpu_models.c | 14 ++++++++++++++
 target-s390x/cpu_models.h |  1 +
 3 files changed, 24 insertions(+)
hw/s390x/sclp.c +9 -0
index 15d7114..3c126ee 100644
@@ -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 |
target-s390x/cpu_models.c +14 -0
index e7bcea9..571ceaa 100644
@@ -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;
target-s390x/cpu_models.h +1 -0
index fe988cc..04c47c6 100644
@@ -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 */
Signature · 1 line
2.6.6
#18 lore raw

RFC 15/28 s390x/sclp: propagate the ibc val(lowest and unblocked ibc)

In reply to David Hildenbrand

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

---
 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(-)
hw/s390x/sclp.c +2 -0
index 3c126ee..52f8bb9 100644
@@ -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);
include/hw/s390x/sclp.h +2 -1
index 743abd4..4580134 100644
@@ -120,7 +120,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;
target-s390x/cpu_models.c +21 -0
index 571ceaa..d58b931 100644
@@ -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;
target-s390x/cpu_models.h +12 -0
index 04c47c6..bbb85ac 100644
@@ -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);
 
Signature · 1 line
2.6.6
#19 lore raw

RFC 16/28 s390x/sclp: propagate the mha via sclp

In reply to David Hildenbrand

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

---
 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(-)
hw/s390x/sclp.c +1 -0
index 52f8bb9..5ffcf51 100644
@@ -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) {
include/hw/s390x/sclp.h +2 -1
index 4580134..7a610cd 100644
@@ -123,7 +123,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 */
target-s390x/cpu_models.c +14 -0
index d58b931..edfbb60 100644
@@ -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;
target-s390x/cpu_models.h +1 -0
index bbb85ac..ee019b4 100644
@@ -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)
 {
Signature · 1 line
2.6.6
#20 lore raw

RFC 17/28 s390x/sclp: propagate hmfai

In reply to David Hildenbrand

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

---
 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(-)
hw/s390x/sclp.c +1 -0
index 5ffcf51..883592c 100644
@@ -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) {
include/hw/s390x/sclp.h +2 -1
index 7a610cd..004cb13 100644
@@ -130,7 +130,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;
 
target-s390x/cpu_models.c +14 -0
index edfbb60..32d9a09 100644
@@ -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;
target-s390x/cpu_models.h +1 -0
index ee019b4..986f7cb 100644
@@ -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)
Signature · 1 line
2.6.6
#21 lore raw

RFC 18/28 update linux headers (CPU model)

In reply to David Hildenbrand

Update linux headers to include the new cpu model attributes

---
 linux-headers/asm-s390/kvm.h | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
linux-headers/asm-s390/kvm.h +40 -0
index 09ae5dc..dd4f22e 100644
@@ -93,6 +93,46 @@ 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
+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
Signature · 1 line
2.6.6
#22 lore raw

RFC 19/28 s390x/kvm: allow runtime-instrumentation for "none" machine

In reply to David Hildenbrand

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

---
 hw/s390x/s390-virtio-ccw.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/s390x/s390-virtio-ccw.c +5 -0
index 52f079a..704b5b5 100644
@@ -248,6 +248,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;
 }
Signature · 1 line
2.6.6
#23 lore raw

RFC 20/28 s390x/kvm: implement CPU model support

In reply to David Hildenbrand

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

---
 target-s390x/cpu_models.c |  75 +++++++++++-
 target-s390x/cpu_models.h |  50 ++++++++
 target-s390x/kvm.c        | 295 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 417 insertions(+), 3 deletions(-)
target-s390x/cpu_models.c +72 -3
index 32d9a09..b8ae601 100644
@@ -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;
@@ -312,7 +367,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];
@@ -345,8 +400,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 */
     }
@@ -551,6 +605,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
 
target-s390x/cpu_models.h +50 -0

62 lines not on this page · raw message

target-s390x/kvm.c +295 -0

298 lines not on this page · raw message

Signature · 1 line
2.6.6
#24 lore raw

RFC 21/28 s390x/kvm: disable host model for existing compat machines

In reply to David Hildenbrand

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.

---
 target-s390x/kvm.c | 4 ++++
 1 file changed, 4 insertions(+)
target-s390x/kvm.c +4 -0
index 6002cf9..a4f5762 100644
@@ -2440,6 +2440,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,
Signature · 1 line
2.6.6
#25 lore raw

RFC 22/28 s390x/kvm: let the CPU model control CMM(A)

In reply to David Hildenbrand

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.

---
 target-s390x/gen-features.c |  1 +
 target-s390x/kvm.c          | 47 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 37 insertions(+), 11 deletions(-)
target-s390x/gen-features.c +1 -0
index d4f4b29..52d46dc 100644
@@ -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
target-s390x/kvm.c +36 -11

91 lines not on this page · raw message

Signature · 1 line
2.6.6
#26 lore raw

RFC 23/28 qmp: add QMP interface "query-cpu-model-expansion"

In reply to David Hildenbrand

Let's provide a standardized interface to expand CPU models, like the host model.

To take care of all architectures, different detail levels for an expansion are introduced. Certain architectures might not support all detail levels.

When the host CPU model is to be expanded, at least the accelerator QEMU has been started with affects the result. Some architectures might decide to take the QEMU machine also into account.

E.g. for s390x, the host CPU model will only depend on the accelerator.

The result of "stable" will be a migration safe CPU model, that will produce the same guest ABI on other QEMU versions. This interface is very helpful when CPU models are to be updated between QEMU versions. The updated model can then simply be expanded to a migration safe representation.

---
 include/sysemu/arch_init.h             |  3 ++
 qapi-schema.json                       | 81 ++++++++++++++++++++++++++++++++++
 qmp-commands.hx                        |  6 +++
 qmp.c                                  |  7 +++
 stubs/Makefile.objs                    |  1 +
 stubs/arch-query-cpu-model-expansion.c | 12 +++++
 6 files changed, 110 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-expansion.c
include/sysemu/arch_init.h +3 -0
index d690dfa..37b2e86 100644
@@ -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
qapi-schema.json +81 -0

87 lines not on this page · raw message

qmp-commands.hx +6 -0
index b444c20..b279fc5 100644
@@ -3930,6 +3930,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model-expansion",
+        .args_type  = "model:q",
+        .mhandler.cmd_new = qmp_marshal_query_cpu_model_expansion,
+    },
+
+    {
         .name       = "query-target",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_query_target,
qmp.c +7 -0
index 7df6543..c54f0a0 100644
@@ -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)
stubs/Makefile.objs +1 -0
index 4b258a6..83915f5 100644
@@ -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
stubs/arch-query-cpu-model-expansion.c new file +12 -0
new file mode 100644
index 0000000..ae7cf55
@@ -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;
+}
Signature · 1 line
2.6.6
#27 lore raw

RFC 24/28 qmp: add QMP interface "query-cpu-model-comparison"

In reply to David Hildenbrand

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.

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).

The host CPU model has the same semantics as for "query-cpu-model-expansion".

---
 include/sysemu/arch_init.h              |  3 ++
 qapi-schema.json                        | 59 +++++++++++++++++++++++++++++++++
 qmp-commands.hx                         |  6 ++++
 qmp.c                                   |  7 ++++
 stubs/Makefile.objs                     |  1 +
 stubs/arch-query-cpu-model-comparison.c | 12 +++++++
 6 files changed, 88 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-comparison.c
include/sysemu/arch_init.h +3 -0
index 37b2e86..96d47c0 100644
@@ -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
qapi-schema.json +59 -0

65 lines not on this page · raw message

qmp-commands.hx +6 -0
index b279fc5..4ee7937 100644
@@ -3936,6 +3936,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,
qmp.c +7 -0
index c54f0a0..afa8c77 100644
@@ -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)
stubs/Makefile.objs +1 -0
index 83915f5..b831dbc 100644
@@ -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
stubs/arch-query-cpu-model-comparison.c new file +12 -0
new file mode 100644
index 0000000..d5486ae
@@ -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;
+}
Signature · 1 line
2.6.6
#28 lore raw

RFC 25/28 qmp: add QMP interface "query-cpu-model-baseline"

In reply to David Hildenbrand

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

For now, we allow two baseline modes. "stable" tries to create a better tested model, e.g. by minimizing CPU definition changes. "maximum" rather tries to get the maxmimum possible model, e.g. by maximizing features.

The host CPU model has the same semantics as for "query-cpu-model-expansion".

---
 include/sysemu/arch_init.h            |  4 ++++
 qapi-schema.json                      | 44 +++++++++++++++++++++++++++++++++++
 qmp-commands.hx                       |  6 +++++
 qmp.c                                 |  8 +++++++
 stubs/Makefile.objs                   |  1 +
 stubs/arch-query-cpu-model-baseline.c | 13 +++++++++++
 6 files changed, 76 insertions(+)
 create mode 100644 stubs/arch-query-cpu-model-baseline.c
include/sysemu/arch_init.h +4 -0
index 96d47c0..1b35e90 100644
@@ -41,5 +41,9 @@ 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(CpuModelBaselineType type,
+                                                    CpuModelInfo *modela,
+                                                    CpuModelInfo *modelb,
+                                                    Error **errp);
 
 #endif
qapi-schema.json +44 -0

50 lines not on this page · raw message

qmp-commands.hx +6 -0
index 4ee7937..42b3853 100644
@@ -3942,6 +3942,12 @@ EQMP
     },
 
     {
+        .name       = "query-cpu-model-baseline",
+        .args_type  = "type:s,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,
qmp.c +8 -0
index afa8c77..6e5437f 100644
@@ -621,6 +621,14 @@ CpuModelCompareInfo *qmp_query_cpu_model_comparison(CpuModelInfo *modela,
     return arch_query_cpu_model_comparison(modela, modelb, errp);
 }
 
+CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelBaselineType type,
+                                                   CpuModelInfo *modela,
+                                                   CpuModelInfo *modelb,
+                                                   Error **errp)
+{
+    return arch_query_cpu_model_baseline(type, 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)
stubs/Makefile.objs +1 -0
index b831dbc..56bddd8 100644
@@ -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
stubs/arch-query-cpu-model-baseline.c new file +13 -0
new file mode 100644
index 0000000..407d323
@@ -0,0 +1,13 @@
+#include "qemu/osdep.h"
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelBaselineType type,
+                                                    CpuModelInfo *modela,
+                                                    CpuModelInfo *modelb,
+                                                    Error **errp)
+{
+    error_setg(errp, QERR_UNSUPPORTED);
+    return NULL;
+}
Signature · 1 line
2.6.6
#29 lore raw

RFC 26/28 s390x/cpumodel: implement QMP interface "query-cpu-model-expansion"

In reply to David Hildenbrand

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 base cpu model, which is by definition migration safe.

---
 target-s390x/cpu_models.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 132 insertions(+)
target-s390x/cpu_models.c +132 -0
index b8ae601..988b9d7 100644
@@ -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
@@ -287,6 +290,135 @@ 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;
+    QmpInputVisitor *qiv;
+    const QDictEntry *e;
+    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) {
+        qiv = qmp_input_visitor_new(info->props, true);
+        for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
+            object_property_set(obj, qmp_input_get_visitor(qiv), e->key, errp);
+            if (*errp) {
+                qmp_input_visitor_cleanup(qiv);
+                object_unref(obj);
+                return;
+            }
+        }
+        qmp_input_visitor_cleanup(qiv);
+    }
+
+    /* 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 migration safe 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 stable 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(model->features, 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_STABLE) {
+        delta_changes = true;
+    }
+
+    /* convert it back to a migration safe version */
+    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)
Signature · 1 line
2.6.6
#30 lore raw

RFC 27/28 s390x/cpumodel: implement QMP interface "query-cpu-model-comparison"

In reply to David Hildenbrand

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

---
 target-s390x/cpu_models.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
target-s390x/cpu_models.c +84 -0
index 988b9d7..75d808b 100644
@@ -419,6 +419,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)
Signature · 1 line
2.6.6
#31 lore raw

RFC 28/28 s390x/cpumodel: implement QMP interface "query-cpu-model-baseline"

In reply to David Hildenbrand

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

---
 target-s390x/cpu_models.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
target-s390x/cpu_models.c +61 -0
index 75d808b..56b945d 100644
@@ -503,6 +503,67 @@ CpuModelCompareInfo *arch_query_cpu_model_comparison(CpuModelInfo *infoa,
     }
     return compare_info;
 }
+
+CpuModelBaselineInfo *arch_query_cpu_model_baseline(CpuModelBaselineType type,
+                                                    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);
+    /* make sure we don't exceed full features of that vcpu */
+    if (type == CPU_MODEL_BASELINE_TYPE_STABLE) {
+        bitmap_and(model.features, model.features, model.def->default_feat,
+                   S390_FEAT_MAX);
+    } else {
+        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)
Signature · 1 line
2.6.6
#32 lore raw
In reply to David Hildenbrand

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:
<cpu match='exact'>
<model fallback='forbid'>Westmere</model> <feature policy='require' name='aes'/>
</cpu>
2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

How exactly would this be done using the new commands?

Quoted 157 lines

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 fixed 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.

But, the fixed feature set is not really what we want to use as a default. It is just like a really minimum, stable base.

So we have
a) A "stable" 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". These are migration safe.
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. These models are not migration safe, e.g "z13" or "z10EC.2". The feature set can differ between QEMU versions.
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

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 a migration unsafe model looks like. Either falling back to a stable model or completely exposing all properties. We are interested in stable models.
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.

As we are aware that e.g. x86 has their own idea of a CPU model and their existing implementation in place, but are also looking into to ways to e.g. expand the "host" CPU model to a detailed representation, we designed the "expansion" interface to also allow that.

Comments are very welcome, but please always keep the restrictions and specialties in mind when suggesting some major design changes.

The header update will be replaced by a kvm-next header update as soon as the VSIE patches are upstream. The major KVM interface changes are already part of kvm-next.

The current state is available on git://github.com/cohuck/qemu on branch "cpumodel-s390x".

David Hildenbrand (26):
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
update linux headers (CPU model)
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              |   10 +
 linux-headers/asm-s390/kvm.h            |   40 ++
 qapi-schema.json                        |  184 ++++++
 qmp-commands.hx                         |   18 +
 qmp.c                                   |   22 +
 rules.mak                               |    1 +
 stubs/Makefile.objs                     |    3 +
 stubs/arch-query-cpu-model-baseline.c   |   13 +
 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                  |    5 +
 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               | 1055 +++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h               |  113 ++++
 target-s390x/gen-features.c             |  587 +++++++++++++++++
 target-s390x/helper.c                   |   29 +-
 target-s390x/kvm.c                      |  346 +++++++++-
 target-s390x/machine.c                  |   14 +-
 27 files changed, 3203 insertions(+), 66 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
Signature · 1 line
2.6.6
Signature · 1 line
Eduardo
#33 lore raw
Quoted 17 lines

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>
Quoted 6 lines

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

How exactly would this be done using the new commands?

Hi Eduardo,

thanks for having a look - highly appreciated that you actually map this to libvirt requirements!

That would map to a compare operation between "host" and "Westmere,aes=on".

Host could at that point already be expanded by libvirt. Doesn't matter at that point.

If the result is "identica"l or "superset", it is runnable. If the result is "subset" or "incompatible", details about the responsible properties is indicated. (I actually took that idea from your patch for indicating runnability).

Thanks!

David

#34 lore raw
Quoted 31 lines · David Hildenbrand
Quoted 17 lines

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>
Quoted 6 lines

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

How exactly would this be done using the new commands?

Hi Eduardo,

thanks for having a look - highly appreciated that you actually map this to libvirt requirements!

That would map to a compare operation between "host" and "Westmere,aes=on".

Quoted 7 lines

Host could at that point already be expanded by libvirt. Doesn't matter at that point.

If the result is "identica"l or "superset", it is runnable. If the result is "subset" or "incompatible", details about the responsible properties is indicated. (I actually took that idea from your patch for indicating runnability).

So, I have two worries about the proposal:

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

If we don't mind adding multiple new QMP commands in this series, I don't see why not having a separate "query-host-cpu" command so the semantics of each command are very clear. Then query-cpu-definitions/query-cpu-model-expansion would be about "what you really get when using -cpu <model>", and "query-host-cpu" would be about "what this hosts supports running".

2) Requiring a running QEMU instance to run
query-cpu-model-comparison

With my previous query-host-cpu proposal, the task of comparing the configuration requested by the user with host capabilities can be done directly by libvirt. This way, no extra QEMU instance needs to be run before starting a VM.

In my example above, if query-cpu-model-comparison were not required, libvirt could run "query-cpu-expansion model=host" or "query-host-cpu" once at boot, and just check if "Westmere" is runnable and "aes" is present in the host data. With query-cpu-model-comparison, QEMU needs to be run one more time before starting a VM.

I don't know if requiring running a new QEMU instance just to check if a CPU config is runnable would be acceptable for libvirt. I will let the libvirt people answer that.

I still like the query-cpu-model-comparison proposal, because it would allow us to extend the data returned by query-cpu-model-expansion without requiring libvirt changes. It may be the best log-term option, but probably only after we add a mechanism to allow the VM to be configured after running a few QMP commands, without re-running QEMU.

Signature · 1 line
Eduardo
#35 lore raw
Quoted 49 lines · Eduardo Habkost
Quoted 31 lines · David Hildenbrand
Quoted 17 lines

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>
Quoted 6 lines

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

How exactly would this be done using the new commands?

Hi Eduardo,

thanks for having a look - highly appreciated that you actually map this to libvirt requirements!

That would map to a compare operation between "host" and "Westmere,aes=on".

Quoted 7 lines

Host could at that point already be expanded by libvirt. Doesn't matter at that point.

If the result is "identica"l or "superset", it is runnable. If the result is "subset" or "incompatible", details about the responsible properties is indicated. (I actually took that idea from your patch for indicating runnability).

So, I have two worries about the proposal:

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

Quoted 6 lines

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

Quoted 7 lines

2) Requiring a running QEMU instance to run
query-cpu-model-comparison

With my previous query-host-cpu proposal, the task of comparing the configuration requested by the user with host capabilities can be done directly by libvirt. This way, no extra QEMU instance needs to be run before starting a VM.

I think we can just easily get around this by not comparing a guest CPU to host (except for the explicit virConnectCompareCPU, which is not very useful in its current form anyway).

Jirka

#36 lore raw

On Tue, Jun 21, 2016 at 11:09:49PM +0200, Jiri Denemark wrote:
[...]

Quoted 13 lines
Quoted 6 lines

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

Quoted 6 lines

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

Quoted 3 lines

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

In that case, I think it makes sense to just extend query-cpu-definitions or use "query-cpu-model-expansion model=host" instead of a query-host-cpu command.

Probably query-cpu-model-expansion is better than just extending query-cpu-definitions, because it would allow the expansion of extra CPU options, like "host,migratable=off".

Signature · 1 line
Eduardo
#37 lore raw
Quoted 19 lines · Eduardo Habkost

On Tue, Jun 21, 2016 at 11:09:49PM +0200, Jiri Denemark wrote:
[...]

Quoted 13 lines
Quoted 6 lines

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

Quoted 6 lines

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

Quoted 3 lines

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

Quoted 7 lines

In that case, I think it makes sense to just extend query-cpu-definitions or use "query-cpu-model-expansion model=host" instead of a query-host-cpu command.

Probably query-cpu-model-expansion is better than just extending query-cpu-definitions, because it would allow the expansion of extra CPU options, like "host,migratable=off".

Yeah, this would be even better.

Jirka

#38 lore raw
Quoted 24 lines · Eduardo Habkost
Quoted 23 lines · Jiri Denemark

[...]

Quoted 13 lines
Quoted 6 lines

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

Quoted 6 lines

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

Quoted 3 lines

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

In that case, I think it makes sense to just extend query-cpu-definitions or use "query-cpu-model-expansion model=host" instead of a query-host-cpu command.

Quoted 8 lines
Quoted 3 lines

Probably query-cpu-model-expansion is better than just extending query-cpu-definitions, because it would allow the expansion of extra CPU options, like "host,migratable=off".

Yeah, this would be even better.

Jirka

Please be aware that we don't have anything like that on s390x, but I prepared for that requirement by being able to tell query-cpu-model-expansion how to expand (full, migratable, stable). Actually full and migratable looks the same on s390x.

The plan for us is to rely on "stable" most of the time, full and migratable might be what you're looking for.

David

#39 lore raw
In reply to Jiri Denemark
Quoted 57 lines · Eduardo Habkost
Quoted 49 lines · David Hildenbrand
Quoted 31 lines
Quoted 17 lines

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>
Quoted 6 lines

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

How exactly would this be done using the new commands?

Hi Eduardo,

thanks for having a look - highly appreciated that you actually map this to libvirt requirements!

That would map to a compare operation between "host" and "Westmere,aes=on".

Quoted 7 lines

Host could at that point already be expanded by libvirt. Doesn't matter at that point.

If the result is "identica"l or "superset", it is runnable. If the result is "subset" or "incompatible", details about the responsible properties is indicated. (I actually took that idea from your patch for indicating runnability).

So, I have two worries about the proposal:

1) "query-cpu-model-expansion model=host" vs "query-host-cpu":

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

Quoted 6 lines

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

Quoted 3 lines

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

That's also what I had in mind first. Let me explain why they are not the same on s390x and why it is problematic (actually both types are not the same!):

1. Certain CPU features are only valid for LPAR guests, they can't be virtualized for KVM guests (remember that we always have at least one level of virtualization on s390x). So we will never be able to provide these features to a KVM guest, therefore we will never be able to completely mimic the real host model.

2. We have a whole lot of unpublished features. We would have to include them in the "real host model", but we can't. For the "host" model, this is not a problem, because we simply don't virtualize them. But the "real host model" would then vary between say QEMZ versions, which looks really strage, because in essance, QEMU/KVM looks like the wrong interface to query for a "real host model".

3. We don't have the kernel interfaces in place to query the "real host model". We can only query what we are able to virtualize. And that is indeed different compared to what I said previously.

And as I can't see any use case for s390x, we most probably will never be able to support the interface you are suggesting here. Which is fine, if it makes sense for x86.

Quoted 4 lines
Quoted 4 lines

2) Requiring a running QEMU instance to run
query-cpu-model-comparison

Quoted 8 lines
Quoted 4 lines

With my previous query-host-cpu proposal, the task of comparing the configuration requested by the user with host capabilities can be done directly by libvirt. This way, no extra QEMU instance needs to be run before starting a VM.

I think we can just easily get around this by not comparing a guest CPU to host (except for the explicit virConnectCompareCPU, which is not very useful in its current form anyway).

If there is some flexible way around that, great. But I think we (s390x) could life without this additional query.

So your first concern is valid, and if you really need this information, you should probably really create a new interface. Your second concern should not be trivial for now. We don't want to optimize for total speed at that point.

David

#40 lore raw
Quoted 33 lines · David Hildenbrand
Quoted 13 lines · Eduardo Habkost
Quoted 11 lines · David Hildenbrand

I still don't think we want to set in stone that "the result the guest sees when using -cpu host" is always the same as "what the host supports running".

For example: let's assume a given architecture have two features (A and B) that are both supported by the host but can never be enabled together. For actual "-cpu host" usage, QEMU would have to choose between enabling A and B. For querying host capabilities, we still want to let management software know that either A or B are supported.

Quoted 3 lines

What libvirt is really interested in is the guest CPU which would be used with -cpu host. This is actually what I thought query-host-cpu was all about. Perhaps because there's no difference for x86.

That's also what I had in mind first. Let me explain why they are not the same on s390x and why it is problematic (actually both types are not the same!):

1. Certain CPU features are only valid for LPAR guests, they can't be virtualized for KVM guests (remember that we always have at least one level of virtualization on s390x). So we will never be able to provide these features to a KVM guest, therefore we will never be able to completely mimic the real host model.

2. We have a whole lot of unpublished features. We would have to include them in the "real host model", but we can't. For the "host" model, this is not a problem, because we simply don't virtualize them. But the "real host model" would then vary between say QEMZ versions, which looks really strage, because in essance, QEMU/KVM looks like the wrong interface to query for a "real host model".

Quoted 7 lines

3. We don't have the kernel interfaces in place to query the "real host model". We can only query what we are able to virtualize. And that is indeed different compared to what I said previously.

And as I can't see any use case for s390x, we most probably will never be able to support the interface you are suggesting here. Which is fine, if it makes sense for x86.

Well, as I said I always thought about query-host-cpu as a way to get the CPU configuration QEMU would provide with -cpu host. Thanks to this discussion I realized its semantics is different and thus what I really need is actually the command you suggested, i.e., query-cpu-model-expansion.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

2) Requiring a running QEMU instance to run
query-cpu-model-comparison

With my previous query-host-cpu proposal, the task of comparing the configuration requested by the user with host capabilities can be done directly by libvirt. This way, no extra QEMU instance needs to be run before starting a VM.

Quoted 6 lines
Quoted 3 lines

I think we can just easily get around this by not comparing a guest CPU to host (except for the explicit virConnectCompareCPU, which is not very useful in its current form anyway).

If there is some flexible way around that, great. But I think we (s390x) could life without this additional query.

So if I understand correctly, you say you don't need the API to compare guest CPU to host CPU, right? If so, that's exactly what I said too.

Jirka

#41 lore raw
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines

2) Requiring a running QEMU instance to run
query-cpu-model-comparison

With my previous query-host-cpu proposal, the task of comparing the configuration requested by the user with host capabilities can be done directly by libvirt. This way, no extra QEMU instance needs to be run before starting a VM.

I think we can just easily get around this by not comparing a guest CPU to host (except for the explicit virConnectCompareCPU, which is not very useful in its current form anyway).

Quoted 6 lines
Quoted 2 lines

If there is some flexible way around that, great. But I think we (s390x) could life without this additional query.

So if I understand correctly, you say you don't need the API to compare guest CPU to host CPU, right? If so, that's exactly what I said too.

I think the coffee didn't do its work already :) . I wanted to write that we can _with_ this additional query. Meaning the involved overhead would be ok - in my opinion for s390x.

What we could do to avoid one compare operation would be:

a) Expand the host model
b) Expand the target model (because on s390x we could have migration unsafe model)
c) Work with the runnability information returned via query-cpu-definitions

But as we have to do b) either way on s390x, we can directly do a compare operation. (which makes implementation a lot simpler, because libvirt then doesn't have to deal with any feature/model names).

David

#42 lore raw
Quoted 6 lines · David Hildenbrand

I think the coffee didn't do its work already :) . I wanted to write that we can _with_ this additional query. Meaning the involved overhead would be ok - in my opinion for s390x.

What we could do to avoid one compare operation would be:

Quoted 8 lines

a) Expand the host model
b) Expand the target model (because on s390x we could have migration unsafe model)
c) Work with the runnability information returned via query-cpu-definitions

But as we have to do b) either way on s390x, we can directly do a compare operation. (which makes implementation a lot simpler, because libvirt then doesn't have to deal with any feature/model names).

But why do you even need to do any comparison? Isn't it possible to let QEMU do it when a domain starts? The thing is we should avoid doing completely different things on each architecture.

Jirka

#43 lore raw
Quoted 12 lines · David Hildenbrand
Quoted 11 lines

I think the coffee didn't do its work already :) . I wanted to write that we can _with_ this additional query. Meaning the involved overhead would be ok - in my opinion for s390x.

What we could do to avoid one compare operation would be:

a) Expand the host model
b) Expand the target model (because on s390x we could have migration unsafe model)
c) Work with the runnability information returned via query-cpu-definitions

Quoted 8 lines
Quoted 3 lines

But as we have to do b) either way on s390x, we can directly do a compare operation. (which makes implementation a lot simpler, because libvirt then doesn't have to deal with any feature/model names).

But why do you even need to do any comparison? Isn't it possible to let QEMU do it when a domain starts? The thing is we should avoid doing completely different things on each architecture.

Sure, QEMU will of course double check when starting the guest! So trying to start and failing is of course an option! So no check is needed if that is acceptable.

David

#44 lore raw
Quoted 16 lines · David Hildenbrand
Quoted 16 lines · David Hildenbrand
Quoted 14 lines

I think the coffee didn't do its work already :) . I wanted to write that we can _with_ this additional query. Meaning the involved overhead would be ok - in my opinion for s390x.

What we could do to avoid one compare operation would be:

a) Expand the host model
b) Expand the target model (because on s390x we could have migration unsafe model)
c) Work with the runnability information returned via query-cpu-definitions

But as we have to do b) either way on s390x, we can directly do a compare operation. (which makes implementation a lot simpler, because libvirt then doesn't have to deal with any feature/model names).

Quoted 8 lines
Quoted 4 lines

But why do you even need to do any comparison? Isn't it possible to let QEMU do it when a domain starts? The thing is we should avoid doing completely different things on each architecture.

Sure, QEMU will of course double check when starting the guest! So trying to start and failing is of course an option! So no check is needed if that is acceptable.

Yeah, I think it's the safest and easiest option now.

Jirka

#45 lore raw
Quoted 22 lines · David Hildenbrand
Quoted 21 lines
Quoted 20 lines · David Hildenbrand
Quoted 6 lines

I think the coffee didn't do its work already :) . I wanted to write that we can _with_ this additional query. Meaning the involved overhead would be ok - in my opinion for s390x.

What we could do to avoid one compare operation would be:

Quoted 8 lines

a) Expand the host model
b) Expand the target model (because on s390x we could have migration unsafe model)
c) Work with the runnability information returned via query-cpu-definitions

But as we have to do b) either way on s390x, we can directly do a compare operation. (which makes implementation a lot simpler, because libvirt then doesn't have to deal with any feature/model names).

But why do you even need to do any comparison? Isn't it possible to let QEMU do it when a domain starts? The thing is we should avoid doing completely different things on each architecture.

Quoted 8 lines
Quoted 3 lines

Sure, QEMU will of course double check when starting the guest! So trying to start and failing is of course an option! So no check is needed if that is acceptable.

Yeah, I think it's the safest and easiest option now.

Jirka

Alright then, this RFC already handles that properly, so that seems to be solved. The question now is if you guys see a fundamental problem in the way we want to handle CPU models.

Especially
a) Having flexible, not migration safe CPU models that can be expanded to migration safe models (using the expansion interface).

b) Letting QEMU carry out the task of comparing and baselining to be used for e.g. for "virsh cpu-baseline" or "virsh cpu-compare".

c) Indicating the host model as the expansion of "-cpu host", e.g. for "virsh capabilities" (which says "host" for now for us).

Also, it will be good to know if the "expansion" interface with parameters "full" or "migratable" is really helpful to you or if I should drop that and you will come up with an own "query-host-cpu".

We are also planning to implement the "query-cpu-definitions" runnability information in the future, because as you said, it might be a good way to quickly indicate runnable CPU models. But we are most likely not going to use it for e.g. comparing or baselining or detection of runnability of a more complex cpu model (having a lot of feature changes).

Thanks!

David

#46 lore raw
In reply to Eduardo Habkost
Quoted 13 lines · Eduardo Habkost

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

Quoted 8 lines
   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

While this is what libvirt currently does, I don't think it's necessary to keep doing that... see below.

Quoted 7 lines
Quoted 7 lines

a) "query-cpu-model-expansion" - tell us what the "host" or a migration unsafe model looks like. Either falling back to a stable model or completely exposing all properties. We are interested in stable models.
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.

This looks like it copies current libvirt APIs, which I think is not a very good idea. Both CPU compare and baseline APIs in libvirt will need to be changed (or rather new APIs with similar functionality added) to become useful. I think we should first focus on making guest CPU configuration work the way it should work. For that I think we need some higher level commands.

Let me sum up what libvirt is doing (or will be doing) with guest CPUs... Libvirt supports three guest CPU configuration modes:

- host-passthrough -- this is easy, it's just asking for "-cpu host" and no fancy commands are required.

- host-model -- for this we need to know what CPU configuration we need to ask for to get as close to the host CPU as possible while being able to ask for the exact same CPU on a different host (after migration). And we need to be able to ask for this at probing time (when libvirtd starts rather than when starting a new domain) using "-machine none,accel=kvm:tcg", that is without actually creating any guest CPU. This is what Eduardo's query-host-cpu QMP command is useful for. In x86 world we could just query the guest CPU after running QEMU with "-cpu host", but that's unusable with "-machine none", which is why another way of getting this info is needed.

- custom -- the XML specifies an exact guest CPU configuration. We don't really need to know if that exact CPU is runnable on the current host in advance, we can just try to start the domain, check if the guest CPU matches what we asked for, and we may kill QEMU if the CPU does not meet the specification. Of course, higher level management wants to know a set of host where it can run a given domain for scheduling purposes, but since they logically want to avoid tons of different CPU configs, they would just stick the CPU models predefined by QEMU. Thus giving them a way of checking what CPU models can be run on a given host with a given QEMU (using the unavailable features stuff for query-cpu-definitions usable with "-machine none") should be enough and it's even better than having to ask for every single CPU model, which is what they need to do now.

There are configuration options which are somewhere between host-model and custom, but they don't bring more requirements in addition to what both of them needs.

This was basically all about starting a new domain. When the domain successfully starts, we need to make sure the guest CPU does not change during save/restore or migration to another host. To achieve this, we need the same checking we need for custom mode, i.e., whether the guest CPU we got is what we asked for. In addition to this, we need a way to ask QEMU what the guest CPU looks like so that we can store it in the domain XML and ask for it during migration.

I think all of this should be pretty much architecture agnostic. Of course the actual data would be quite different fro each architecture, but I believe the entry points could fit all. Or did I miss anything?

Jirka

#47 lore raw
Quoted 34 lines · Eduardo Habkost
Quoted 13 lines

(CCing libvirt people)

Quoted 3 lines · David Hildenbrand

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.

Before getting into the details, I would like to clarify how the following could be accomplished using the new commands:

Example:

1) User configures libvirt with:

Quoted 8 lines
   <cpu match='exact'>
       <model fallback='forbid'>Westmere</model>
       <feature policy='require' name='aes'/>
   </cpu>

2) libvirt will translate that to:
"-cpu Westmere,+aes" or "-cpu Westmere,aes=on"
3) libvirt wants to know if "-cpu Westmere,aes=on" is usable in the current host, before trying to start the VM.

While this is what libvirt currently does, I don't think it's necessary to keep doing that... see below.

Quoted 7 lines
Quoted 7 lines

a) "query-cpu-model-expansion" - tell us what the "host" or a migration unsafe model looks like. Either falling back to a stable model or completely exposing all properties. We are interested in stable models.
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.

Quoted 6 lines

This looks like it copies current libvirt APIs, which I think is not a very good idea. Both CPU compare and baseline APIs in libvirt will need to be changed (or rather new APIs with similar functionality added) to become useful. I think we should first focus on making guest CPU configuration work the way it should work. For that I think we need some higher level commands.

Hi Jiri,

thanks for your reply!

Please be aware that we (s390x) have no libvirt cpu model support in place. We are coming up with a solution that solves our problems, but instead of tagging all interfaces with "s390x" we want interfaces that everybody might use.

I understand that x86 has some very advanced libvirt CPU model magic in place. You can still stick to what you have right now. It doesn't work for us.

So we provide 3 basic functions (baseline, compare, expand) that can easily by added for s390x into the CPU model. So I don't see a problem introducing these operations in libvirt - it just works without any magic and knowledge about features and models in libvirt.

In the end it keeps the CPU model where it belongs (QEMU) and allows us to just fit in fine into the libvirt CPU model world that was heavily inspired by x86 (an I can tell you, that is a very challenging task).

But - of course - we have to do some additional queries on a QEMU instance. I don't think that this is a problem (at least not for s390x).

Quoted 3 lines

Let me sum up what libvirt is doing (or will be doing) with guest CPUs... Libvirt supports three guest CPU configuration modes:

One important thing to mention here is that all of these was inspired by x86. Some stuff doesn't even make sense on s390x ("mimic the real host"), as it would even in practice never be possible. See my reply to Eduards patchset I'll post later.

We want to focus on the real use cases and I think they are
- Making sure models ("Guest API") doesn't change during migration
- Allowing the user to use a certain CPU model
- Baselining/Comparing/Using the -cpu host model

Quoted 3 lines

- host-passthrough -- this is easy, it's just asking for "-cpu host" and no fancy commands are required.

This should map to expanding the host model in our case.

Quoted 11 lines

- host-model -- for this we need to know what CPU configuration we need to ask for to get as close to the host CPU as possible while being able to ask for the exact same CPU on a different host (after migration). And we need to be able to ask for this at probing time (when libvirtd starts rather than when starting a new domain) using "-machine none,accel=kvm:tcg", that is without actually creating any guest CPU. This is what Eduardo's query-host-cpu QMP command is useful for. In x86 world we could just query the guest CPU after running QEMU with "-cpu host", but that's unusable with "-machine none", which is why another way of getting this info is needed.

Again, we will be relying on "-cpu host" here, because the real host model will never be possible to be fordwarded on s390x. And what's the use case anyway? Does not make sense on s390x as far as I can tell.

We want to know what we are able to virtualize, not build up some strange model that won't even be able to run.

Quoted 14 lines

- custom -- the XML specifies an exact guest CPU configuration. We don't really need to know if that exact CPU is runnable on the current host in advance, we can just try to start the domain, check if the guest CPU matches what we asked for, and we may kill QEMU if the CPU does not meet the specification. Of course, higher level management wants to know a set of host where it can run a given domain for scheduling purposes, but since they logically want to avoid tons of different CPU configs, they would just stick the CPU models predefined by QEMU. Thus giving them a way of checking what CPU models can be run on a given host with a given QEMU (using the unavailable features stuff for query-cpu-definitions usable with "-machine none") should be enough and it's even better than having to ask for every single CPU model, which is what they need to do now.

Which is simply necessary when having to care about a lot of feature variability. Please keep the requirements in our cover letter in place.

It's not that simple when
a) having to update the "flexible" models over time (e.g. adding stuff to "z13")
b) nobody really using the "stable" models like "z13-base", but interested in "z13" + feature changes

I agree that CPU models defined in QEMU are the place to go - which is why we keep our default here.

And also keep in mind that I think your extension to query-cpu-definitions to detect runability makes total sense, it is just not enough for us having to care about changable "default" models.

Let's say we report a "z13" via that interface as runnable? It doesn't mean a thing because that model could look different on e.g. another QEMU version we're migrating to. To check the real deal, we have to expand that model and then verify if it is runnable. In essence, runnability information contained in query-cpu-definitions only makes sense for migration-safe models.

Of course, that could somehow be done using the "expansion" interface only in combination with "query-cpu-definitions". But it doesn't solve the other problems we're dealing with and just introduces some unnecessary complexity (for us!).

Quoted 5 lines

There are configuration options which are somewhere between host-model and custom, but they don't bring more requirements in addition to what both of them needs.

Quoted 7 lines

This was basically all about starting a new domain. When the domain successfully starts, we need to make sure the guest CPU does not change during save/restore or migration to another host. To achieve this, we need the same checking we need for custom mode, i.e., whether the guest CPU we got is what we asked for. In addition to this, we need a way to ask QEMU what the guest CPU looks like so that we can store it in the domain XML and ask for it during migration.

Exactly, that's where our "expansion" interface comes into play.

If the user asks for a "z13", we will expand it to a "z13-base,feata=on,featb=on" ...

So we can guarantee that we are always dealing with a migration safe variant.

Quoted 5 lines

I think all of this should be pretty much architecture agnostic. Of course the actual data would be quite different fro each architecture, but I believe the entry points could fit all. Or did I miss anything?

These are also the use cases I looked into, with the addition of being able to baseline and compare CPU models (including the "host" model).

Thanks again for having a look!

David

#48 lore raw
In reply to Jiri Denemark

On Tue, Jun 21, 2016 at 10:56:28PM +0200, Jiri Denemark wrote:
[...]

Quoted 6 lines

Let me sum up what libvirt is doing (or will be doing) with guest CPUs... Libvirt supports three guest CPU configuration modes:

- host-passthrough -- this is easy, it's just asking for "-cpu host" and no fancy commands are required.

Quoted 10 lines

- host-model -- for this we need to know what CPU configuration we need to ask for to get as close to the host CPU as possible while being able to ask for the exact same CPU on a different host (after migration). And we need to be able to ask for this at probing time (when libvirtd starts rather than when starting a new domain) using "-machine none,accel=kvm:tcg", that is without actually creating any guest CPU. This is what Eduardo's query-host-cpu QMP command is useful for. In x86 world we could just query the guest CPU after running QEMU with "-cpu host", but that's unusable with "-machine none", which is why another way of getting this info is needed.

Question: KVM supports x2apic (and enables it by default) on any host CPU, because it is all emulated by KVM. Should "host-model" include x2apic on all hosts, or only when the host CPU has it? ("-cpu host" does include it).

Including x2apic sounds more useful, but it doesn't match the "get as close to the host CPU as possible" part of your description.

Signature · 1 line
Eduardo
#49 lore raw
Quoted 10 lines

Question: KVM supports x2apic (and enables it by default) on any host CPU, because it is all emulated by KVM. Should "host-model" include x2apic on all hosts, or only when the host CPU has it? ("-cpu host" does include it).

Including x2apic sounds more useful, but it doesn't match the "get as close to the host CPU as possible" part of your description.

From a s390x point of view, our "host" model is about indicating the maximum possible configuration we are able to virtualize, not strictly limiting it only to the real host features.

We also have a feature called "sthyi", emulated by KVM, which might not be around for the real "host". We will include that in "host", because otherwise things seem to get really complicated with no obvious benefit (to me :) ).

Not sure how you want to handle that.

David

#50 lore raw
In reply to David Hildenbrand

Are there any further comments, especially on patches 23-25, introducing new QOM interfaces?

Also, if anybody is planning to look into this, please speak up :)

Otherwise it might make sense to put this onto the next KVM call agenda.

David

Quoted 157 lines

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 fixed 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.

But, the fixed feature set is not really what we want to use as a default. It is just like a really minimum, stable base.

So we have
a) A "stable" 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". These are migration safe.
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. These models are not migration safe, e.g "z13" or "z10EC.2". The feature set can differ between QEMU versions.
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

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 a migration unsafe model looks like. Either falling back to a stable model or completely exposing all properties. We are interested in stable models.
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.

As we are aware that e.g. x86 has their own idea of a CPU model and their existing implementation in place, but are also looking into to ways to e.g. expand the "host" CPU model to a detailed representation, we designed the "expansion" interface to also allow that.

Comments are very welcome, but please always keep the restrictions and specialties in mind when suggesting some major design changes.

The header update will be replaced by a kvm-next header update as soon as the VSIE patches are upstream. The major KVM interface changes are already part of kvm-next.

The current state is available on git://github.com/cohuck/qemu on branch "cpumodel-s390x".

David Hildenbrand (26):
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
update linux headers (CPU model)
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              |   10 +
 linux-headers/asm-s390/kvm.h            |   40 ++
 qapi-schema.json                        |  184 ++++++
 qmp-commands.hx                         |   18 +
 qmp.c                                   |   22 +
 rules.mak                               |    1 +
 stubs/Makefile.objs                     |    3 +
 stubs/arch-query-cpu-model-baseline.c   |   13 +
 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                  |    5 +
 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               | 1055 +++++++++++++++++++++++++++++++
 target-s390x/cpu_models.h               |  113 ++++
 target-s390x/gen-features.c             |  587 +++++++++++++++++
 target-s390x/helper.c                   |   29 +-
 target-s390x/kvm.c                      |  346 +++++++++-
 target-s390x/machine.c                  |   14 +-
 27 files changed, 3203 insertions(+), 66 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
#51 lore raw
Quoted 5 lines · David Hildenbrand

Are there any further comments, especially on patches 23-25, introducing new QOM interfaces?

Also, if anybody is planning to look into this, please speak up :)

I am still planning to look at this (I didn't look at the interfaces and code yet), especially the query-cpu-model-expansion command.

Signature · 1 line
Eduardo
#52 lore raw
In reply to David Hildenbrand
Quoted 2 lines

Are there any further comments, especially on patches 23-25, introducing new QOM interfaces?

Ping, can somebody please have a look, especially on patches 23-25? We really want to know if we can proceed with this CPU model approach.

David

Quoted 6 lines

Also, if anybody is planning to look into this, please speak up :)

Otherwise it might make sense to put this onto the next KVM call agenda.

David