From: David Hildenbrand <dahi@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: ehabkost@redhat.com, jdenemar@redhat.com, imammedo@redhat.com,
cornelia.huck@de.ibm.com, borntraeger@de.ibm.com,
fiuczy@linux.vnet.ibm.com, mimu@linux.vnet.ibm.com
Subject: [Qemu-devel] [Patch v2 10/29] s390x/cpumodel: expose features and feature groups as properties
Date: Mon, 8 Aug 2016 17:32:39 +0200 [thread overview]
Message-ID: <1470670378-53732-11-git-send-email-dahi@linux.vnet.ibm.com> (raw)
In-Reply-To: <1470670378-53732-1-git-send-email-dahi@linux.vnet.ibm.com>
Let's add all features and feature groups as properties to all CPU models.
If the "host" CPU model is unknown, we can neither query nor change
features. KVM will just continue to work like it did until now.
We will not allow to enable features that were not part of the original
CPU model, because that could collide with the IBC in KVM.
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
---
target-s390x/cpu.c | 1 +
target-s390x/cpu.h | 1 +
target-s390x/cpu_models.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 151 insertions(+)
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index d7d0b62..2f3c8e2 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -291,6 +291,7 @@ static void s390_cpu_initfn(Object *obj)
cs->exception_index = EXCP_HLT;
object_property_add(OBJECT(cpu), "id", "int64_t", s390x_cpu_get_id,
s390x_cpu_set_id, NULL, NULL, NULL);
+ s390_cpu_model_register_props(obj);
#if !defined(CONFIG_USER_ONLY)
qemu_get_timedate(&tm, 0);
env->tod_offset = TOD_UNIX_EPOCH +
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index 3b76654..d03f0f1 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -632,6 +632,7 @@ extern void subsystem_reset(void);
void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
#define cpu_list s390_cpu_list
+void s390_cpu_model_register_props(Object *obj);
void s390_cpu_model_class_register_props(ObjectClass *oc);
void s390_realize_cpu_model(CPUState *cs, Error **errp);
ObjectClass *s390_cpu_class_by_name(const char *name);
diff --git a/target-s390x/cpu_models.c b/target-s390x/cpu_models.c
index f707a4b..5f218c2 100644
--- a/target-s390x/cpu_models.c
+++ b/target-s390x/cpu_models.c
@@ -14,6 +14,7 @@
#include "cpu.h"
#include "gen-features.h"
#include "qapi/error.h"
+#include "qapi/visitor.h"
#ifndef CONFIG_USER_ONLY
#include "sysemu/arch_init.h"
#endif
@@ -103,8 +104,24 @@ void s390_cpu_list(FILE *f, fprintf_function print)
f = f,
print = print,
};
+ S390FeatGroup group;
+ S390Feat feat;
object_class_foreach(print_cpu_model_list, TYPE_S390_CPU, false, &info);
+
+ (*print)(f, "\nRecognized feature flags:\n");
+ for (feat = 0; feat < S390_FEAT_MAX; feat++) {
+ const S390FeatDef *def = s390_feat_def(feat);
+
+ (*print)(f, "%-20s %-50s\n", def->name, def->desc);
+ }
+
+ (*print)(f, "\nRecognized feature groups:\n");
+ for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
+ const S390FeatGroupDef *def = s390_feat_group_def(group);
+
+ (*print)(f, "%-20s %-50s\n", def->name, def->desc);
+ }
}
#ifndef CONFIG_USER_ONLY
@@ -151,6 +168,138 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp)
}
}
+static void get_feature(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ S390Feat feat = (S390Feat) opaque;
+ S390CPU *cpu = S390_CPU(obj);
+ bool value;
+
+ if (!cpu->model) {
+ error_setg(errp, "Details about the host CPU model are not available, "
+ "features cannot be queried.");
+ return;
+ }
+
+ value = test_bit(feat, cpu->model->features);
+ visit_type_bool(v, name, &value, errp);
+}
+
+static void set_feature(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ S390Feat feat = (S390Feat) opaque;
+ DeviceState *dev = DEVICE(obj);
+ S390CPU *cpu = S390_CPU(obj);
+ bool value;
+
+ if (dev->realized) {
+ error_setg(errp, "Attempt to set property '%s' on '%s' after "
+ "it was realized", name, object_get_typename(obj));
+ return;
+ } else if (!cpu->model) {
+ error_setg(errp, "Details about the host CPU model are not available, "
+ "features cannot be changed.");
+ return;
+ }
+
+ visit_type_bool(v, name, &value, errp);
+ if (*errp) {
+ return;
+ }
+ if (value) {
+ if (!test_bit(feat, cpu->model->def->full_feat)) {
+ error_setg(errp, "Feature '%s' is not available for CPU model '%s',"
+ " it was introduced with later models.",
+ name, cpu->model->def->name);
+ return;
+ }
+ set_bit(feat, cpu->model->features);
+ } else {
+ clear_bit(feat, cpu->model->features);
+ }
+}
+
+static void get_feature_group(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ S390FeatGroup group = (S390FeatGroup) opaque;
+ const S390FeatGroupDef *def = s390_feat_group_def(group);
+ S390CPU *cpu = S390_CPU(obj);
+ S390FeatBitmap tmp;
+ bool value;
+
+ if (!cpu->model) {
+ error_setg(errp, "Details about the host CPU model are not available, "
+ "features cannot be queried.");
+ return;
+ }
+
+ /* a group is enabled if all features are enabled */
+ bitmap_and(tmp, cpu->model->features, def->feat, S390_FEAT_MAX);
+ value = bitmap_equal(tmp, def->feat, S390_FEAT_MAX);
+ visit_type_bool(v, name, &value, errp);
+}
+
+static void set_feature_group(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ S390FeatGroup group = (S390FeatGroup) opaque;
+ const S390FeatGroupDef *def = s390_feat_group_def(group);
+ DeviceState *dev = DEVICE(obj);
+ S390CPU *cpu = S390_CPU(obj);
+ bool value;
+
+ if (dev->realized) {
+ error_setg(errp, "Attempt to set property '%s' on '%s' after "
+ "it was realized", name, object_get_typename(obj));
+ return;
+ } else if (!cpu->model) {
+ error_setg(errp, "Details about the host CPU model are not available, "
+ "features cannot be changed.");
+ return;
+ }
+
+ visit_type_bool(v, name, &value, errp);
+ if (*errp) {
+ return;
+ }
+ if (value) {
+ /* groups are added in one shot, so an intersect is sufficient */
+ if (!bitmap_intersects(def->feat, cpu->model->def->full_feat,
+ S390_FEAT_MAX)) {
+ error_setg(errp, "Group '%s' is not available for CPU model '%s',"
+ " it was introduced with later models.",
+ name, cpu->model->def->name);
+ return;
+ }
+ bitmap_or(cpu->model->features, cpu->model->features, def->feat,
+ S390_FEAT_MAX);
+ } else {
+ bitmap_andnot(cpu->model->features, cpu->model->features, def->feat,
+ S390_FEAT_MAX);
+ }
+}
+
+void s390_cpu_model_register_props(Object *obj)
+{
+ S390FeatGroup group;
+ S390Feat feat;
+
+ for (feat = 0; feat < S390_FEAT_MAX; feat++) {
+ const S390FeatDef *def = s390_feat_def(feat);
+ object_property_add(obj, def->name, "bool", get_feature,
+ set_feature, NULL, (void *) feat, NULL);
+ object_property_set_description(obj, def->name, def->desc , NULL);
+ }
+ for (group = 0; group < S390_FEAT_GROUP_MAX; group++) {
+ const S390FeatGroupDef *def = s390_feat_group_def(group);
+ object_property_add(obj, def->name, "bool", get_feature_group,
+ set_feature_group, NULL, (void *) group, NULL);
+ object_property_set_description(obj, def->name, def->desc , NULL);
+ }
+}
+
static void s390_cpu_model_initfn(Object *obj)
{
S390CPU *cpu = S390_CPU(obj);
--
2.6.6
next prev parent reply other threads:[~2016-08-08 15:33 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-08 15:32 [Qemu-devel] [Patch v2 00/29] s390x CPU models: exposing features David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 01/29] qmp: details about CPU definitions in query-cpu-definitions David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 02/29] s390x/cpumodel: "host" and "qemu" as CPU subclasses David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 03/29] s390x/cpumodel: expose CPU class properties David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 04/29] s390x/cpumodel: introduce CPU features David Hildenbrand
2016-08-16 14:36 ` Christian Borntraeger
2016-08-16 14:42 ` David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 05/29] s390x/cpumodel: generate CPU feature lists for CPU models David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 06/29] s390x/cpumodel: generate CPU feature group lists David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 07/29] s390x/cpumodel: introduce CPU feature group definitions David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 08/29] s390x/cpumodel: register defined CPU models as subclasses David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 09/29] s390x/cpumodel: store the CPU model in the CPU instance David Hildenbrand
2016-08-08 15:32 ` David Hildenbrand [this message]
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 11/29] s390x/cpumodel: let the CPU model handle feature checks David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 12/29] s390x/cpumodel: check and apply the CPU model David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 13/29] s390x/sclp: factor out preparation of cpu entries David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 14/29] s390x/sclp: introduce sclp feature blocks David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 15/29] s390x/sclp: indicate sclp features David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 16/29] s390x/sclp: propagate the ibc val(lowest and unblocked ibc) David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 17/29] s390x/sclp: propagate the mha via sclp David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 18/29] s390x/sclp: propagate hmfai David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 19/29] linux-headers: update against kvm/next David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 20/29] s390x/kvm: allow runtime-instrumentation for "none" machine David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 21/29] s390x/kvm: implement CPU model support David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 22/29] s390x/kvm: disable host model for existing compat machines David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 23/29] s390x/kvm: let the CPU model control CMM(A) David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 24/29] qmp: add QMP interface "query-cpu-model-expansion" David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 25/29] qmp: add QMP interface "query-cpu-model-comparison" David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 26/29] qmp: add QMP interface "query-cpu-model-baseline" David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 27/29] s390x/cpumodel: implement QMP interface "query-cpu-model-expansion" David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 28/29] s390x/cpumodel: implement QMP interface "query-cpu-model-comparison" David Hildenbrand
2016-08-08 15:32 ` [Qemu-devel] [Patch v2 29/29] s390x/cpumodel: implement QMP interface "query-cpu-model-baseline" David Hildenbrand
2016-08-08 16:45 ` [Qemu-devel] [Patch v2 00/29] s390x CPU models: exposing features no-reply
[not found] ` <201608081645.u78GKFHE092220@mx0b-001b2d01.pphosted.com>
2016-08-08 17:02 ` Cornelia Huck
2016-08-08 17:14 ` David Hildenbrand
[not found] ` <201608081645.u78GjISN026387@int-mx10.intmail.prod.int.phx2.redhat.com>
2016-08-08 17:27 ` Eduardo Habkost
2016-08-09 1:08 ` Fam Zheng
2016-08-15 14:00 ` David Hildenbrand
2016-08-15 14:03 ` Christian Borntraeger
2016-08-15 14:49 ` Cornelia Huck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470670378-53732-11-git-send-email-dahi@linux.vnet.ibm.com \
--to=dahi@linux.vnet.ibm.com \
--cc=borntraeger@de.ibm.com \
--cc=cornelia.huck@de.ibm.com \
--cc=ehabkost@redhat.com \
--cc=fiuczy@linux.vnet.ibm.com \
--cc=imammedo@redhat.com \
--cc=jdenemar@redhat.com \
--cc=mimu@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).