From a5f9ecc49d63a905da6598900e0a0eeec1ef269d Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Wed, 25 Jul 2018 16:36:17 +0200 Subject: s390x/cpumodel: enum type S390FeatGroup now gets generated The enumeration type S390FeatGroup is now generated as well. This shall simplify the definition of new feature groups without the requirement to modify existing code. Signed-off-by: Michael Mueller Message-Id: <20180725143617.8731-1-mimu@linux.ibm.com> Acked-by: David Hildenbrand Acked-by: Christian Borntraeger Signed-off-by: Cornelia Huck --- target/s390x/cpu_features.c | 1 - target/s390x/cpu_features.h | 19 +------------------ target/s390x/gen-features.c | 18 +++++++++++++++++- 3 files changed, 18 insertions(+), 20 deletions(-) (limited to 'target') diff --git a/target/s390x/cpu_features.c b/target/s390x/cpu_features.c index 3b9e2745e9..d623db34a6 100644 --- a/target/s390x/cpu_features.c +++ b/target/s390x/cpu_features.c @@ -13,7 +13,6 @@ #include "qemu/osdep.h" #include "qemu/module.h" #include "cpu_features.h" -#include "gen-features.h" #define FEAT_INIT(_name, _type, _bit, _desc) \ { \ diff --git a/target/s390x/cpu_features.h b/target/s390x/cpu_features.h index 968b12fdfe..effe790271 100644 --- a/target/s390x/cpu_features.h +++ b/target/s390x/cpu_features.h @@ -16,6 +16,7 @@ #include "qemu/bitmap.h" #include "cpu_features_def.h" +#include "gen-features.h" /* CPU features are announced via different ways */ typedef enum { @@ -64,24 +65,6 @@ 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_MSA_EXT_6, - S390_FEAT_GROUP_MSA_EXT_7, - S390_FEAT_GROUP_MSA_EXT_8, - S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF, - S390_FEAT_GROUP_MAX, -} S390FeatGroup; - /* Definition of a CPU feature group */ typedef struct { const char *name; /* name exposed to the user */ diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c index 6626b6f565..2ca5ededb3 100644 --- a/target/s390x/gen-features.c +++ b/target/s390x/gen-features.c @@ -661,6 +661,7 @@ static CpuFeatDefSpec CpuFeatDef[] = { #define FEAT_GROUP_INITIALIZER(_name) \ { \ .name = "S390_FEAT_GROUP_LIST_" #_name, \ + .enum_name = "S390_FEAT_GROUP_" #_name, \ .bits = \ { .data = group_##_name, \ .len = ARRAY_SIZE(group_##_name) }, \ @@ -668,6 +669,7 @@ static CpuFeatDefSpec CpuFeatDef[] = { typedef struct { const char *name; + const char *enum_name; BitSpec bits; } FeatGroupDefSpec; @@ -678,7 +680,6 @@ static FeatGroupDefSpec FeatGroupDef[] = { FEAT_GROUP_INITIALIZER(PLO), FEAT_GROUP_INITIALIZER(TOD_CLOCK_STEERING), FEAT_GROUP_INITIALIZER(GEN13_PTFF), - FEAT_GROUP_INITIALIZER(MULTIPLE_EPOCH_PTFF), FEAT_GROUP_INITIALIZER(MSA), FEAT_GROUP_INITIALIZER(MSA_EXT_1), FEAT_GROUP_INITIALIZER(MSA_EXT_2), @@ -688,6 +689,7 @@ static FeatGroupDefSpec FeatGroupDef[] = { FEAT_GROUP_INITIALIZER(MSA_EXT_6), FEAT_GROUP_INITIALIZER(MSA_EXT_7), FEAT_GROUP_INITIALIZER(MSA_EXT_8), + FEAT_GROUP_INITIALIZER(MULTIPLE_EPOCH_PTFF), }; #define QEMU_FEAT_INITIALIZER(_name) \ @@ -810,6 +812,19 @@ static void print_feature_group_defs(void) } } +static void print_feature_group_enum_type(void) +{ + int i; + + printf("\n/* CPU feature group enum type */\n" + "typedef enum {\n"); + for (i = 0; i < ARRAY_SIZE(FeatGroupDef); i++) { + printf("\t%s,\n", FeatGroupDef[i].enum_name); + } + printf("\tS390_FEAT_GROUP_MAX,\n" + "} S390FeatGroup;\n"); +} + int main(int argc, char *argv[]) { printf("/*\n" @@ -826,6 +841,7 @@ int main(int argc, char *argv[]) print_feature_defs(); print_feature_group_defs(); print_qemu_feature_defs(); + print_feature_group_enum_type(); printf("\n#endif\n"); return 0; } -- cgit v1.2.3 From 36699ab480340b928f2e589d83a94e6786e1965b Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Mon, 23 Jul 2018 18:32:21 +0200 Subject: s390x: remove 's390-squash-mcss' option This option has been deprecated for two releases; remove it. Acked-by: Christian Borntraeger Reviewed-by: Thomas Huth Acked-by: Halil Pasic Signed-off-by: Cornelia Huck --- target/s390x/cpu.c | 10 ---------- target/s390x/cpu.h | 1 - 2 files changed, 11 deletions(-) (limited to 'target') diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 271c5ce652..8ed4823d6e 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -421,16 +421,6 @@ void s390_crypto_reset(void) } } -bool s390_get_squash_mcss(void) -{ - if (object_property_get_bool(OBJECT(qdev_get_machine()), "s390-squash-mcss", - NULL)) { - return true; - } - - return false; -} - void s390_enable_css_support(S390CPU *cpu) { if (kvm_enabled()) { diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 2c3dd2d189..86b66dfeac 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -713,7 +713,6 @@ static inline void s390_do_cpu_load_normal(CPUState *cs, run_on_cpu_data arg) /* cpu.c */ void s390_crypto_reset(void); -bool s390_get_squash_mcss(void); int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); -- cgit v1.2.3 From c61177881cbda50704207dd9fb4811659bbf913e Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Wed, 25 Jul 2018 11:12:33 +0200 Subject: s390x/cpumodel: Add "-cpu max" support The "max" CPU model behaves like "-cpu host" when KVM is enabled, and like a CPU with the maximum possible feature set when TCG is enabled. While the "host" model can not be used under TCG ("kvm_required"), the "max" model can and "Enables all features supported by the accelerator in the current host". So we can treat "host" just as a special case of "max" (like x86 does). It differs to the "qemu" CPU model under TCG such that compatibility handling will not be performed and that some experimental CPU features not yet part of the "qemu" model might be indicated. These are right now under TCG (see "qemu_MAX"): - stfle53 - msa5-base - zpci This will result right now in the following warning when starting QEMU TCG with the "max" model: "qemu-system-s390x: warning: 'msa5-base' requires 'kimd-sha-512'." The "qemu" model (used as default in QEMU under TCG) will continue to work without such warnings. The "max" model in the current form might be interesting for kvm-unit-tests (where we would e.g. now also test "msa5-base"). The "max" model is neither static nor migration safe (like the "host" model). It is independent of the machine but dependends on the accelerator. It can be used to detect the maximum CPU model also under TCG from upper layers without having to care about CPU model names for CPU model expansion. Signed-off-by: David Hildenbrand Message-Id: <20180725091233.3300-1-david@redhat.com> Reviewed-by: Eduardo Habkost [CH: minor wording changes] Signed-off-by: Cornelia Huck --- target/s390x/cpu_models.c | 82 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 25 deletions(-) (limited to 'target') diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index 604898a882..12e765ba1f 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -307,7 +307,10 @@ static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b) const char *name_a = object_class_get_name((ObjectClass *)a); const char *name_b = object_class_get_name((ObjectClass *)b); - /* move qemu and host to the top of the list, qemu first, host second */ + /* + * Move qemu, host and max to the top of the list, qemu first, host second, + * max third. + */ if (name_a[0] == 'q') { return -1; } else if (name_b[0] == 'q') { @@ -316,6 +319,10 @@ static gint s390_cpu_list_compare(gconstpointer a, gconstpointer b) return -1; } else if (name_b[0] == 'h') { return 1; + } else if (name_a[0] == 'm') { + return -1; + } else if (name_b[0] == 'm') { + return 1; } /* keep the same order we have in our table (sorted by release date) */ @@ -1077,27 +1084,6 @@ 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 - static S390CPUDef s390_qemu_cpu_def; static S390CPUModel s390_qemu_cpu_model; @@ -1136,6 +1122,31 @@ static void s390_qemu_cpu_model_initfn(Object *obj) memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model)); } +static void s390_max_cpu_model_initfn(Object *obj) +{ + const S390CPUModel *max_model; + S390CPU *cpu = S390_CPU(obj); + Error *local_err = NULL; + + if (kvm_enabled() && !kvm_s390_cpu_models_supported()) { + /* "max" and "host" always work, even without CPU model support */ + return; + } + + max_model = get_max_cpu_model(&local_err); + if (local_err) { + /* we expect errors only under KVM, when actually querying the kernel */ + g_assert(kvm_enabled()); + error_report_err(local_err); + /* fallback to unsupported CPU models */ + return; + } + + cpu->model = g_new(S390CPUModel, 1); + /* copy the CPU model so we can modify it */ + memcpy(cpu->model, max_model, sizeof(*cpu->model)); +} + static void s390_cpu_model_finalize(Object *obj) { S390CPU *cpu = S390_CPU(obj); @@ -1209,6 +1220,20 @@ static void s390_qemu_cpu_model_class_init(ObjectClass *oc, void *data) qemu_hw_version()); } +static void s390_max_cpu_model_class_init(ObjectClass *oc, void *data) +{ + S390CPUClass *xcc = S390_CPU_CLASS(oc); + + /* + * The "max" model is neither static nor migration safe. Under KVM + * it represents the "host" model. Under TCG it represents some kind of + * "qemu" CPU model without compat handling and maybe with some additional + * CPU features that are not yet unlocked in the "qemu" model. + */ + xcc->desc = + "Enables all features supported by the accelerator in the current host"; +} + /* Generate type name for a cpu model. Caller has to free the string. */ static char *s390_cpu_type_name(const char *model_name) { @@ -1239,12 +1264,18 @@ static const TypeInfo qemu_s390_cpu_type_info = { .class_init = s390_qemu_cpu_model_class_init, }; +static const TypeInfo max_s390_cpu_type_info = { + .name = S390_CPU_TYPE_NAME("max"), + .parent = TYPE_S390_CPU, + .instance_init = s390_max_cpu_model_initfn, + .instance_finalize = s390_cpu_model_finalize, + .class_init = s390_max_cpu_model_class_init, +}; + #ifdef CONFIG_KVM static const TypeInfo host_s390_cpu_type_info = { .name = S390_CPU_TYPE_NAME("host"), - .parent = TYPE_S390_CPU, - .instance_init = s390_host_cpu_model_initfn, - .instance_finalize = s390_cpu_model_finalize, + .parent = S390_CPU_TYPE_NAME("max"), .class_init = s390_host_cpu_model_class_init, }; #endif @@ -1326,6 +1357,7 @@ static void register_types(void) } type_register_static(&qemu_s390_cpu_type_info); + type_register_static(&max_s390_cpu_type_info); #ifdef CONFIG_KVM type_register_static(&host_s390_cpu_type_info); #endif -- cgit v1.2.3 From 27e84d4ebd25b981ab27cb590fe06d1b0fcd06d2 Mon Sep 17 00:00:00 2001 From: Christian Borntraeger Date: Tue, 31 Jul 2018 11:04:48 +0200 Subject: s390x/kvm: add etoken facility Provide the etoken facility. We need to handle cpu model, migration and clear reset. Signed-off-by: Christian Borntraeger Acked-by: Janosch Frank Message-Id: <20180731090448.36662-3-borntraeger@de.ibm.com> Reviewed-by: David Hildenbrand Signed-off-by: Cornelia Huck --- target/s390x/cpu.h | 3 +++ target/s390x/cpu_features.c | 3 ++- target/s390x/cpu_features_def.h | 3 ++- target/s390x/gen-features.c | 3 ++- target/s390x/kvm.c | 11 +++++++++++ target/s390x/machine.c | 20 +++++++++++++++++++- 6 files changed, 39 insertions(+), 4 deletions(-) (limited to 'target') diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 86b66dfeac..6f8861e554 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -2,6 +2,7 @@ * S/390 virtual CPU header * * Copyright (c) 2009 Ulrich Hecht + * Copyright IBM Corp. 2012, 2018 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -68,6 +69,8 @@ struct CPUS390XState { uint32_t aregs[16]; /* access registers */ uint8_t riccb[64]; /* runtime instrumentation control */ uint64_t gscb[4]; /* guarded storage control */ + uint64_t etoken; /* etoken */ + uint64_t etoken_extension; /* etoken extension */ /* Fields up to this point are not cleared by initial CPU reset */ struct {} start_initial_reset_fields; diff --git a/target/s390x/cpu_features.c b/target/s390x/cpu_features.c index d623db34a6..172fb18df7 100644 --- a/target/s390x/cpu_features.c +++ b/target/s390x/cpu_features.c @@ -1,7 +1,7 @@ /* * CPU features/facilities for s390x * - * Copyright 2016 IBM Corp. + * Copyright IBM Corp. 2016, 2018 * * Author(s): David Hildenbrand * @@ -105,6 +105,7 @@ static const S390FeatDef s390_features[] = { FEAT_INIT("irbm", S390_FEAT_TYPE_STFL, 145, "Insert-reference-bits-multiple facility"), FEAT_INIT("msa8-base", S390_FEAT_TYPE_STFL, 146, "Message-security-assist-extension-8 facility (excluding subfunctions)"), FEAT_INIT("cmmnt", S390_FEAT_TYPE_STFL, 147, "CMM: ESSA-enhancement (no translate) facility"), + FEAT_INIT("etoken", S390_FEAT_TYPE_STFL, 156, "Etoken facility"), /* SCLP SCCB Byte 80 - 98 (bit numbers relative to byte-80) */ FEAT_INIT("gsls", S390_FEAT_TYPE_SCLP_CONF_CHAR, 40, "SIE: Guest-storage-limit-suppression facility"), diff --git a/target/s390x/cpu_features_def.h b/target/s390x/cpu_features_def.h index 7c5915c7b2..ac2c947f30 100644 --- a/target/s390x/cpu_features_def.h +++ b/target/s390x/cpu_features_def.h @@ -1,7 +1,7 @@ /* * CPU features/facilities for s390 * - * Copyright 2016 IBM Corp. + * Copyright IBM Corp. 2016, 2018 * * Author(s): Michael Mueller * David Hildenbrand @@ -93,6 +93,7 @@ typedef enum { S390_FEAT_INSERT_REFERENCE_BITS_MULT, S390_FEAT_MSA_EXT_8, S390_FEAT_CMM_NT, + S390_FEAT_ETOKEN, /* Sclp Conf Char */ S390_FEAT_SIE_GSLS, diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c index 2ca5ededb3..384b61cd67 100644 --- a/target/s390x/gen-features.c +++ b/target/s390x/gen-features.c @@ -1,7 +1,7 @@ /* * S390 feature list generator * - * Copyright 2016 IBM Corp. + * Copyright IBM Corp. 2016, 2018 * * Author(s): Michael Mueller * David Hildenbrand @@ -471,6 +471,7 @@ static uint16_t full_GEN14_GA1[] = { S390_FEAT_GROUP_MSA_EXT_7, S390_FEAT_GROUP_MSA_EXT_8, S390_FEAT_CMM_NT, + S390_FEAT_ETOKEN, S390_FEAT_HPMA2, S390_FEAT_SIE_KSS, S390_FEAT_GROUP_MULTIPLE_EPOCH_PTFF, diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index d923cf4240..af83955e5f 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -493,6 +493,12 @@ int kvm_arch_put_registers(CPUState *cs, int level) cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_BPBC; } + if (can_sync_regs(cs, KVM_SYNC_ETOKEN)) { + cs->kvm_run->s.regs.etoken = env->etoken; + cs->kvm_run->s.regs.etoken_extension = env->etoken_extension; + cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_ETOKEN; + } + /* Finally the prefix */ if (can_sync_regs(cs, KVM_SYNC_PREFIX)) { cs->kvm_run->s.regs.prefix = env->psa; @@ -607,6 +613,11 @@ int kvm_arch_get_registers(CPUState *cs) env->bpbc = cs->kvm_run->s.regs.bpbc; } + if (can_sync_regs(cs, KVM_SYNC_ETOKEN)) { + env->etoken = cs->kvm_run->s.regs.etoken; + env->etoken_extension = cs->kvm_run->s.regs.etoken_extension; + } + /* pfault parameters */ if (can_sync_regs(cs, KVM_SYNC_PFAULT)) { env->pfault_token = cs->kvm_run->s.regs.pft; diff --git a/target/s390x/machine.c b/target/s390x/machine.c index bd3230d027..cb792aa103 100644 --- a/target/s390x/machine.c +++ b/target/s390x/machine.c @@ -1,7 +1,7 @@ /* * S390x machine definitions and functions * - * Copyright IBM Corp. 2014 + * Copyright IBM Corp. 2014, 2018 * * Authors: * Thomas Huth @@ -216,6 +216,23 @@ const VMStateDescription vmstate_bpbc = { } }; +static bool etoken_needed(void *opaque) +{ + return s390_has_feat(S390_FEAT_ETOKEN); +} + +const VMStateDescription vmstate_etoken = { + .name = "cpu/etoken", + .version_id = 1, + .minimum_version_id = 1, + .needed = etoken_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT64(env.etoken, S390CPU), + VMSTATE_UINT64(env.etoken_extension, S390CPU), + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_s390_cpu = { .name = "cpu", .post_load = cpu_post_load, @@ -251,6 +268,7 @@ const VMStateDescription vmstate_s390_cpu = { &vmstate_exval, &vmstate_gscb, &vmstate_bpbc, + &vmstate_etoken, NULL }, }; -- cgit v1.2.3 From 09c6c754804df4d997f84fd9c17d90c5b4ce948c Mon Sep 17 00:00:00 2001 From: Janosch Frank Date: Thu, 2 Aug 2018 08:02:01 +0100 Subject: s390x: Enable KVM huge page backing support QEMU has had huge page support for a longer time already, but KVM memory management under s390x needed some changes to work with huge backings. Now that we have support, let's enable it if requested and available. Otherwise we now properly tell the user if there is no support and back out instead of failing to run the VM later on. Signed-off-by: Janosch Frank Reviewed-by: David Hildenbrand Message-Id: <20180802070201.257406-1-frankja@linux.ibm.com> Reviewed-by: Thomas Huth Signed-off-by: Cornelia Huck --- target/s390x/kvm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'target') diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index af83955e5f..348e8cc546 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -34,6 +34,8 @@ #include "qapi/error.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/units.h" +#include "qemu/mmap-alloc.h" #include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "hw/hw.h" @@ -139,6 +141,7 @@ static int cap_mem_op; static int cap_s390_irq; static int cap_ri; static int cap_gs; +static int cap_hpage_1m; static int active_cmma; @@ -220,9 +223,9 @@ static void kvm_s390_enable_cmma(void) .attr = KVM_S390_VM_MEM_ENABLE_CMMA, }; - if (mem_path) { + if (cap_hpage_1m) { warn_report("CMM will not be enabled because it is not " - "compatible with hugetlbfs."); + "compatible with huge memory backings."); return; } rc = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr); @@ -281,10 +284,38 @@ void kvm_s390_crypto_reset(void) } } +static int kvm_s390_configure_mempath_backing(KVMState *s) +{ + size_t path_psize = qemu_mempath_getpagesize(mem_path); + + if (path_psize == 4 * KiB) { + return 0; + } + + if (path_psize != 1 * MiB) { + error_report("Memory backing with 2G pages was specified, " + "but KVM does not support this memory backing"); + return -EINVAL; + } + + if (kvm_vm_enable_cap(s, KVM_CAP_S390_HPAGE_1M, 0)) { + error_report("Memory backing with 1M pages was specified, " + "but KVM does not support this memory backing"); + return -EINVAL; + } + + cap_hpage_1m = 1; + return 0; +} + int kvm_arch_init(MachineState *ms, KVMState *s) { MachineClass *mc = MACHINE_GET_CLASS(ms); + if (mem_path && kvm_s390_configure_mempath_backing(s)) { + return -EINVAL; + } + mc->default_cpu_type = S390_CPU_TYPE_NAME("host"); cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF); -- cgit v1.2.3