Re: [Qemu-devel] [PATCH v5 11/17] target-s390x: Add KVM VM attribute interface for S390 CPU models

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 14:19:13 +0200
Cornelia Huck  wrote:

> > > >> Would it make sense to do the cast here  
> > > > 
> > > > cpu_model_get/set() is used to handle both attributes,
> > > > KVM_S390_VM_CPU_MACHINE and KVM_S390_VM_CPU_PROCESSOR.
> > > > Both require a different type in the signature, (S390ProcessorProps*)
> > > > and (S390MachineProps*). Adding both as parameters seems to be odd
> > > > and would require additionally logic in the function.
> > > > Thus I think doing the cast outside is just the right thing to do.  
> > > 
> > > So what about a void pointer then as parameter?
> > > I prefer a pointer for qemu process memory over uint64_t as part of the 
> > > function interface. This makes it somewhat clearer that this is an
> > > address within QEMU. Both ways will certainly work, though.  
> > 
> > The interface calls are:
> > 
> > int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
> > int kvm_s390_get_processor_props(S390ProcessorProps *prop)
> > 
> > cpu_model_get/set() are just static helpers.  
> 
> So this makes them internal calls...
> 
> >   
> > > 
> > > Conny, I guess you will pick up the patches. Any preference?  
> 
> ...and I'd prefer using a void pointer for them.

Ok, I will make void pointers then to emphasize their address characteristics.

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 11/17] target-s390x: Add KVM VM attribute interface for S390 CPU models

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 12:52:54 +0200
Christian Borntraeger  wrote:

> Am 27.04.2015 um 11:43 schrieb Michael Mueller:
> > On Mon, 27 Apr 2015 10:15:47 +0200
> > Christian Borntraeger  wrote:
> > 
> >> Am 13.04.2015 um 15:56 schrieb Michael Mueller:
> >> [...]
> >>> +static int cpu_model_get(KVMState *s, uint64_t attr, uint64_t addr)
> >>> +{
> >>> +int rc = -ENOSYS;
> >>> +struct kvm_device_attr dev_attr = {
> >>> +.group = KVM_S390_VM_CPU_MODEL,
> >>> +.attr = attr,
> >>> +.addr = addr,
> >>
> >> Would it make sense to do the cast here
> > 
> > cpu_model_get/set() is used to handle both attributes,
> > KVM_S390_VM_CPU_MACHINE and KVM_S390_VM_CPU_PROCESSOR.
> > Both require a different type in the signature, (S390ProcessorProps*)
> > and (S390MachineProps*). Adding both as parameters seems to be odd
> > and would require additionally logic in the function.
> > Thus I think doing the cast outside is just the right thing to do.
> 
> So what about a void pointer then as parameter?
> I prefer a pointer for qemu process memory over uint64_t as part of the 
> function interface. This makes it somewhat clearer that this is an
> address within QEMU. Both ways will certainly work, though.

The interface calls are:

int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
int kvm_s390_get_processor_props(S390ProcessorProps *prop)

cpu_model_get/set() are just static helpers.

> 
> Conny, I guess you will pick up the patches. Any preference?
> 
> Christian

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 06/17] target-s390x: Introduce S390 CPU facilities

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 12:14:19 +0200
Christian Borntraeger  wrote:

> +/* z/VM-specific, see: SC24-6179-05 page 953) */
> +FAC_STHYI   = 74,

picked

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 10:11:29 +0200
Christian Borntraeger  wrote:

> > This patch implements the QMP command 'query-cpu-definitions' in the S390
> > context. The command returns a list of cpu definitions in the current host
> > context. A runnable and migratable cpu model has the related attributes
> > set to true. The order attribute is used to bring the listed cpu definitions
> > in a release order.  
> 
> Can you add some explanation why we need the fallback code (e.g. something
> along the line, when querying no KVM guest is available and to query the
> capabilities we have to open a dummy VM bla bla)

Maybe something like that:

The returned values for attributes like runnable depend on the machine type 
QEMU is running on.
The function kvm_s390_get_machine_props() is used to determine that. If QEMU 
was started for
accelerator KVM, a KVMstate is established and machine properties are retrieved 
by
cpu_model_get(). In case no KVMstate was established, e.g. during QEMU startup 
in daemonized mode
with the default accelerator TCG, a fallback routine named 
get_machine_props_fallback() is used
to retrieve the KVM machine properties. It first creates a temporary VM, 
performs the required
ioctls and finally destroys the VM again.

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 11/17] target-s390x: Add KVM VM attribute interface for S390 CPU models

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 10:15:47 +0200
Christian Borntraeger  wrote:

> Am 13.04.2015 um 15:56 schrieb Michael Mueller:
> [...]
> > +static int cpu_model_get(KVMState *s, uint64_t attr, uint64_t addr)
> > +{
> > +int rc = -ENOSYS;
> > +struct kvm_device_attr dev_attr = {
> > +.group = KVM_S390_VM_CPU_MODEL,
> > +.attr = attr,
> > +.addr = addr,
> 
> Would it make sense to do the cast here

cpu_model_get/set() is used to handle both attributes,
KVM_S390_VM_CPU_MACHINE and KVM_S390_VM_CPU_PROCESSOR.
Both require a different type in the signature, (S390ProcessorProps*)
and (S390MachineProps*). Adding both as parameters seems to be odd
and would require additionally logic in the function.
Thus I think doing the cast outside is just the right thing to do.

Michael

> > +};
> > +
> > +if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
> > +rc = kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &dev_attr);
> > +}
> > +
> > +return rc;
> > +}
> > +
> > +static int cpu_model_set(KVMState *s, uint64_t attr, uint64_t addr)
> > +{
> > +int rc = -ENOSYS;
> > +struct kvm_device_attr dev_attr = {
> > +.group = KVM_S390_VM_CPU_MODEL,
> > +.attr = attr,
> > +.addr = addr,
> 
> ...and here...
> 
> > +};
> > +
> > +if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
> > +rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &dev_attr);
> > +}
> > +
> > +return rc;
> > +}
> > +
> > +static int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
> > +{
> > +int rc = -EFAULT;
> > +
> > +if (s) {
> > +rc = cpu_model_get(s, KVM_S390_VM_CPU_MACHINE, (uint64_t) prop);
> 
> and pass S390MachineProps as 3rd parameter?
> 
> 
> > +int kvm_s390_get_processor_props(S390ProcessorProps *prop)
> > +{
> > +int rc;
> > +
> > +rc = cpu_model_get(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) 
> > prop);
> 
> dito
> > +trace_kvm_get_processor_props(rc, prop->cpuid, prop->ibc);
> > +return rc;
> > +}
> > +
> > +int kvm_s390_set_processor_props(S390ProcessorProps *prop)
> > +{
> > +int rc;
> > +
> > +rc = cpu_model_set(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) 
> > prop);
> 
> dito

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 09/17] target-s390x: Define S390 CPU model specific facility lists

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 10:11:40 +0200
Christian Borntraeger  wrote:

> Am 13.04.2015 um 15:56 schrieb Michael Mueller:
> > --- a/target-s390x/cpu-models.c
> > +++ b/target-s390x/cpu-models.c
> 
> > @@ -76,3 +87,4 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM 
> > zEnterprise EC12 GA1")
> >  S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
> >  S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
> >  S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
> > +
> 
> Blank line at end of file, git am also complains:
> 
> Applying: target-s390x: Define S390 CPU model specific facility lists
> /home/cborntra/REPOS/qemu/.git/rebase-apply/patch:54: new blank line at EOF.
> +
> warning: 1 line adds whitespace errors.

I will address this here and in the next patch, checkpatch does not seem to 
catch that.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 06/17] target-s390x: Introduce S390 CPU facilities

2015-04-27 Thread Michael Mueller
On Mon, 27 Apr 2015 10:11:37 +0200
Christian Borntraeger  wrote:

> Am 13.04.2015 um 15:56 schrieb Michael Mueller:
> [...]
> > +FAC_TRANSACTIONAL_EXE   = 73,
> > +/*
> > + * The store-hypervisor-information facility #74 is
> > + * z/VM related and when added to be handled by QEMU
> > + * when hosted on LPAR. (see: SC24-6179-05 page 953)
> > + */
> 
> I find this sentence hard to read.
> 

I would not mind to fully skip it then.

> 
> > +FAC_ACCESS_EXCEPTION_FS_INDICATION  = 75,
> [...]

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 06/17] target-s390x: Introduce S390 CPU facilities

2015-04-13 Thread Michael Mueller
The patch introduces S390 CPU facility bit numbers and names
as well as the architectural facility size limit in bytes.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-facilities.h | 86 +++
 1 file changed, 86 insertions(+)
 create mode 100644 target-s390x/cpu-facilities.h

diff --git a/target-s390x/cpu-facilities.h b/target-s390x/cpu-facilities.h
new file mode 100644
index 000..db1f064
--- /dev/null
+++ b/target-s390x/cpu-facilities.h
@@ -0,0 +1,86 @@
+/*
+ * CPU facilities for s390
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * 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_FACILITIES_H
+#define TARGET_S390X_CPU_FACILITIES_H
+
+/* architectural size of facilities is 2KB */
+#define FAC_LIST_ARCH_S390_SIZE_UINT8 (1<<11)
+
+/* CPU facility bits */
+typedef enum {
+FAC_N3  = 0,
+FAC_ZARCH   = 1,
+FAC_ZARCH_ACTIVE= 2,
+FAC_DAT_ENH = 3,
+FAC_ASN_LX_REUSE= 6,
+FAC_STFLE   = 7,
+FAC_ENHANCED_DAT_1  = 8,
+FAC_SENSE_RUNNING_STATUS= 9,
+FAC_CONDITIONAL_SSKE= 10,
+FAC_CONFIGURATION_TOPOLOGY  = 11,
+FAC_IPTE_RANGE  = 13,
+FAC_NONQ_KEY_SETTING= 14,
+FAC_EXTENDED_TRANSLATION_2  = 16,
+FAC_MESSAGE_SECURITY_ASSIST = 17,
+FAC_LONG_DISPLACEMENT   = 18,
+FAC_LONG_DISPLACEMENT_FAST  = 19,
+FAC_HFP_MADDSUB = 20,
+FAC_EXTENDED_IMMEDIATE  = 21,
+FAC_EXTENDED_TRANSLATION_3  = 22,
+FAC_HFP_UNNORMALIZED_EXT= 23,
+FAC_ETF2_ENH= 24,
+FAC_STORE_CLOCK_FAST= 25,
+FAC_PARSING_ENH = 26,
+FAC_MOVE_WITH_OPTIONAL_SPEC = 27,
+FAC_TOD_CLOCK_STEERING  = 28,
+FAC_ETF3_ENH= 30,
+FAC_EXTRACT_CPU_TIME= 31,
+FAC_COMPARE_AND_SWAP_AND_STORE  = 32,
+FAC_COMPARE_AND_SWAP_AND_STORE_2= 33,
+FAC_GENERAL_INSTRUCTIONS_EXT= 34,
+FAC_EXECUTE_EXT = 35,
+FAC_ENHANCED_MONITOR= 36,
+FAC_FLOATING_POINT_EXT  = 37,
+FAC_LOAD_PROGRAM_PARAMETERS = 40,
+FAC_FLOATING_POINT_SUPPPORT_ENH = 41,
+FAC_DFP = 42,
+FAC_DFP_FAST= 43,
+FAC_PFPO= 44,
+FAC_MULTI_45= 45,
+FAC_CMPSC_ENH   = 47,
+FAC_DFP_ZONED_CONVERSION= 48,
+FAC_MULTI_49= 49,
+FAC_CONSTRAINT_TRANSACTIONAL_EXE= 50,
+FAC_LOCAL_TLB_CLEARING  = 51,
+FAC_INTERLOCKED_ACCESS_2= 52,
+FAC_LOAD_STORE_ON_COND_2= 53,
+FAC_MESSAGE_SECURITY_ASSIST_5   = 57,
+FAC_RESET_REFERENCE_BITS_MULTIPLE   = 66,
+FAC_CPU_MEASUREMENT_COUNTER = 67,
+FAC_CPU_MEASUREMENT_SAMPLING= 68,
+FAC_TRANSACTIONAL_EXE   = 73,
+/*
+ * The store-hypervisor-information facility #74 is
+ * z/VM related and when added to be handled by QEMU
+ * when hosted on LPAR. (see: SC24-6179-05 page 953)
+ */
+FAC_ACCESS_EXCEPTION_FS_INDICATION  = 75,
+FAC_MESSAGE_SECURITY_ASSIST_3   = 76,
+FAC_MESSAGE_SECURITY_ASSIST_4   = 77,
+FAC_ENHANCED_DAT_2  = 78,
+FAC_DFP_PACKED_CONVERSION   = 80,
+FAC_VECTOR  = 129,
+FAC_STORE_CPU_COUNTER_MULTI = 142,
+} S390Facility;
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 08/17] target-s390x: Introduce S390 CPU models

2015-04-13 Thread Michael Mueller
This patch implements the static part of the S390 CPU class definitions.
It defines S390 CPU models by means of virtual CPU ids (enum) which contain
information on the CPU generation, the machine class, the GA number and
the machine type. The CPU id is used to instantiate a CPU class per CPU
model.

Furthermore it extends S390CPUClass by model related properties.

Signed-off-by: Michael Mueller 
---
 target-s390x/Makefile.objs |  1 +
 target-s390x/cpu-models.c  | 78 ++
 target-s390x/cpu-models.h  | 72 ++
 target-s390x/cpu-qom.h | 49 +
 target-s390x/cpu.c |  2 ++
 5 files changed, 202 insertions(+)
 create mode 100644 target-s390x/cpu-models.c
 create mode 100644 target-s390x/cpu-models.h

diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 997dda4..97c4177 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,6 +1,7 @@
 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 += cpu-models.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
 
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
new file mode 100644
index 000..147e221
--- /dev/null
+++ b/target-s390x/cpu-models.c
@@ -0,0 +1,78 @@
+/*
+ * CPU models for s390
+ *
+ * Copyright 2014,2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu-common.h"
+#include "cpu-models.h"
+
+#define S390_PROC_DEF(_name, _cpu_id, _desc)\
+static void \
+glue(_cpu_id, _cpu_class_init)  \
+(ObjectClass *oc, void *data)   \
+{   \
+DeviceClass *dc = DEVICE_CLASS(oc); \
+S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+\
+cc->is_migration_safe = true;   \
+cc->mach.ga = cpu_ga(_cpu_id);  \
+cc->mach.class  = cpu_class(_cpu_id);   \
+cc->mach.order  = cpu_order(_cpu_id);   \
+cc->proc.gen= cpu_generation(_cpu_id);  \
+cc->proc.ver= S390_DEF_VERSION; \
+cc->proc.id = S390_DEF_ID;  \
+cc->proc.type   = cpu_type(_cpu_id);\
+cc->proc.ibc= S390_DEF_IBC; \
+dc->desc= _desc;\
+}   \
+static const TypeInfo   \
+glue(_cpu_id, _cpu_type_info) = {   \
+.name   = _name "-" TYPE_S390_CPU,  \
+.parent = TYPE_S390_CPU,\
+.class_init = glue(_cpu_id, _cpu_class_init),   \
+};  \
+static void \
+glue(_cpu_id, _cpu_register_types)(void)\
+{   \
+type_register_static(   \
+&glue(_cpu_id, _cpu_type_info));\
+}   \
+type_init(glue(_cpu_id, _cpu_register_types))
+
+/* define S390 CPU model classes */
+S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
+S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
+S390_PROC_DEF("2064-ga3", CPU_S390_2064_GA3, "IBM zSeries 900 GA3")
+S390_PROC_DEF("2066-ga1", CPU_S390_2066_GA1, "IBM zSeries 800 GA1")
+S390_PROC_DEF("2084-ga1", CPU_S390_2084_GA1, "IBM zSeries 990 GA1")
+S390_PROC_DEF("2084-ga2", CPU_S390_2084_GA2, "IBM zSeries 990 GA2")
+S390_PROC_DEF("2084-ga3", CPU_S390_2084_GA3, "IBM zSeries 990 GA3")
+S390_PROC_DEF("2084-ga4", CPU_S390_2084_GA4, "IBM zSeries 990 GA4")
+S390_PROC_DEF("2084-ga5&quo

[PATCH v5 02/17] Add accelerator id and model name to CPUState

2015-04-13 Thread Michael Mueller
The patch defines ids per accelerator and adds the accel_id and
the model_name to the CPUState. The accel_id is initialized by
common code, the model name needs to be initialized by target
specific code.

Signed-off-by: Michael Mueller 
---
 include/qom/cpu.h |  5 +
 qapi-schema.json  |  9 +
 qom/cpu.c | 14 ++
 3 files changed, 28 insertions(+)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 9dafb48..4ffc050 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -236,6 +236,8 @@ struct kvm_run;
  * @mem_io_pc: Host Program Counter at which the memory was accessed.
  * @mem_io_vaddr: Target virtual address at which the memory was accessed.
  * @kvm_fd: vCPU file descriptor for KVM.
+ * @accel_id: accelerator id of this CPU.
+ * @model_name: model name of this CPU
  *
  * State of one CPU core or thread.
  */
@@ -313,6 +315,9 @@ struct CPUState {
(absolute value) offset as small as possible.  This reduces code
size, especially for hosts without large memory offsets.  */
 volatile sig_atomic_t tcg_exit_req;
+
+AccelId accel_id;
+char *model_name;
 };
 
 QTAILQ_HEAD(CPUTailQ, CPUState);
diff --git a/qapi-schema.json b/qapi-schema.json
index ac9594d..540e520 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2515,6 +2515,15 @@
 ##
 { 'command': 'query-machines', 'returns': ['MachineInfo'] }
 
+# @AccelId
+#
+# Defines accelerator ids
+#
+# Since: 2.4
+##
+{ 'enum': 'AccelId',
+  'data': ['qtest', 'tcg', 'kvm', 'xen'] }
+
 ##
 # @CpuDefinitionInfo:
 #
diff --git a/qom/cpu.c b/qom/cpu.c
index 108bfa2..457afc7 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const char 
*cpu_model)
 goto out;
 }
 
+if (tcg_enabled()) {
+cpu->accel_id = ACCEL_ID_TCG;
+} else if (kvm_enabled()) {
+cpu->accel_id = ACCEL_ID_KVM;
+}
+#ifdef CONFIG_XEN
+else if (xen_enabled()) {
+cpu->accel_id = ACCEL_ID_XEN;
+}
+#endif
+else {
+cpu->accel_id = ACCEL_ID_QTEST;
+}
+
 object_property_set_bool(OBJECT(cpu), true, "realized", &err);
 
 out:
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 01/17] Introduce stub routine cpu_desc_avail

2015-04-13 Thread Michael Mueller
This patch introduces the function cpu_desc_avail() which returns by
default true if not architecture specific implemented. Its intention
is to indicate if the cpu model description is available for display
by list_cpus(). This change allows cpu model descriptions to become
dynamically created by evaluating the runtime context instead of
putting static cpu model information at display.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 include/qemu-common.h  | 2 ++
 stubs/Makefile.objs| 1 +
 stubs/cpu-desc-avail.c | 6 ++
 vl.c   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 stubs/cpu-desc-avail.c

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 1b5cffb..386750f 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -484,4 +484,6 @@ int parse_debug_env(const char *name, int max, int initial);
 
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
+bool cpu_desc_avail(void);
+
 #endif
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 8beff4c..dce9cd2 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -39,3 +39,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += cpu-desc-avail.o
diff --git a/stubs/cpu-desc-avail.c b/stubs/cpu-desc-avail.c
new file mode 100644
index 000..0cd594e
--- /dev/null
+++ b/stubs/cpu-desc-avail.c
@@ -0,0 +1,6 @@
+#include "qemu-common.h"
+
+bool cpu_desc_avail(void)
+{
+return true;
+}
diff --git a/vl.c b/vl.c
index 74c2681..c552561 100644
--- a/vl.c
+++ b/vl.c
@@ -3820,7 +3820,7 @@ int main(int argc, char **argv, char **envp)
  */
 cpudef_init();
 
-if (cpu_model && is_help_option(cpu_model)) {
+if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
 list_cpus(stdout, &fprintf, cpu_model);
 exit(0);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 09/17] target-s390x: Define S390 CPU model specific facility lists

2015-04-13 Thread Michael Mueller
This patch defines S390 CPU facilities and their presence at the
different CPU model levels. Beside defining a base which facilities
have to be requested per CPU model, these sets are associated to the
defined CPU classes and used to calculate the list of supported
CPU models in context of the current hosting machine model.

The also defined qemu side facility mask allows to implement and enable
facilities in QEMU land.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 12 
 target-s390x/cpu-models.h |  8 
 target-s390x/cpu.c|  1 +
 3 files changed, 21 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 147e221..6cc121b 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -12,6 +12,7 @@
 
 #include "qemu-common.h"
 #include "cpu-models.h"
+#include "gen-facilities.h"
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -20,6 +21,10 @@
 {   \
 DeviceClass *dc = DEVICE_CLASS(oc); \
 S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+uint64_t nbits = FAC_LIST_CPU_S390_SIZE_UINT1;  \
+uint64_t fac_list[FAC_LIST_CPU_S390_SIZE_UINT64] = {\
+glue(FAC_LIST_, _cpu_id)\
+};  \
 \
 cc->is_migration_safe = true;   \
 cc->mach.ga = cpu_ga(_cpu_id);  \
@@ -30,6 +35,7 @@
 cc->proc.id = S390_DEF_ID;  \
 cc->proc.type   = cpu_type(_cpu_id);\
 cc->proc.ibc= S390_DEF_IBC; \
+bitmap_copy(cc->proc.fac_list, fac_list, nbits);\
 dc->desc= _desc;\
 }   \
 static const TypeInfo   \
@@ -46,6 +52,11 @@
 }   \
 type_init(glue(_cpu_id, _cpu_register_types))
 
+/* facilities implemented by qemu */
+uint64_t qemu_s390_fac_list_mask[FAC_LIST_CPU_S390_SIZE_UINT64] = {
+FAC_LIST_CPU_S390_MASK_QEMU
+};
+
 /* define S390 CPU model classes */
 S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
 S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
@@ -76,3 +87,4 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM zEnterprise 
EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index b02c38b..948af10 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -13,6 +13,14 @@
 #ifndef TARGET_S390X_CPU_MODELS_H
 #define TARGET_S390X_CPU_MODELS_H
 
+#include "cpu-facilities.h"
+#include "gen-facilities.h"
+
+#define FAC_LIST_ARCH_S390_SIZE_UINT1 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 * BITS_PER_BYTE)
+#define FAC_LIST_ARCH_S390_SIZE_UINT64 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 / sizeof(uint64_t))
+
 #define S390_EC 0x1
 #define S390_BC 0x2
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 8f49813..9232a97 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "hw/hw.h"
 #include "trace.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 07/17] target-s390x: Generate facility defines per S390 CPU model

2015-04-13 Thread Michael Mueller
This patch introduces the helper "gen-facilities" which allows to generate
facility list definitions and masks 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-facilities.h" to be able to use named
facility bits instead of numbers. Its output will be feed back into the
cpu model related header file "target-s390x/cpu-models.h" by including
gen-facilities.h to implement model related data structures.

The following defines/symbols are expected to be provided by the cpu-facilities
header file:

FAC_LIST_ARCH_S390_SIZE_UINT8
FAC_N3
FAC_ZARCH
FAC_ZARCH_ACTIVE
...

The defines provided by gen-facilities follow the following schema:

FAC_LIST_CPU_S390_SIZE_UINT1 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT8 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT64 %PRIu32
FAC_LIST_CPU_S390_MASK_QEMU 0x%016PRIx64,0x%016PRIx64,...
FAC_LIST_CPU_S390__GA 0x%016PRIx64,0x%016PRIx64,...

Signed-off-by: Michael Mueller 
---
 Makefile.target   |   2 +-
 rules.mak |   1 +
 target-s390x/Makefile.objs|  20 ++
 target-s390x/gen-facilities.c | 417 ++
 4 files changed, 439 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/gen-facilities.c

diff --git a/Makefile.target b/Makefile.target
index 2262d89..58cfc1b 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -190,7 +190,7 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN  
 $(TARGET_DIR)$@")
 
-clean:
+clean: clean-target
rm -f *.a *~ $(PROGS)
rm -f $(shell find . -name '*.[od]')
rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
diff --git a/rules.mak b/rules.mak
index 3a05627..43cf05c 100644
--- a/rules.mak
+++ b/rules.mak
@@ -12,6 +12,7 @@ MAKEFLAGS += -rR
 %.cpp:
 %.m:
 %.mak:
+clean-target:
 
 # Flags for C++ compilation
 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index dd62cbd..997dda4 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -3,3 +3,23 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o 
misc_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
+
+# build and run facility generator
+#
+fac = gen-facilities
+fac-src = $(SRC_PATH)/target-$(TARGET_BASE_ARCH)
+fac-dst = $(BUILD_DIR)/$(TARGET_DIR)
+
+ifneq ($(MAKECMDGOALS),clean)
+GENERATED_HEADERS += $(fac-dst)$(fac).h
+endif
+
+$(fac-dst)$(fac).h: $(fac-dst)$(fac)
+   $(call quiet-command,$< >$@,"  GEN   $(TARGET_DIR)$(fac).h")
+
+$(fac-dst)$(fac): $(fac-src)/$(fac).c $(fac-src)/cpu-facilities.h
+   $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(CFLAGS) -o 
$@ $<,"  CC$(TARGET_DIR)$(fac)")
+
+clean-target:
+   rm -f $(fac).h
+   rm -f $(fac)
diff --git a/target-s390x/gen-facilities.c b/target-s390x/gen-facilities.c
new file mode 100644
index 000..f4f4c57
--- /dev/null
+++ b/target-s390x/gen-facilities.c
@@ -0,0 +1,417 @@
+/*
+ * S390 facility list/mask generator
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "cpu-facilities.h"
+
+/* BEGIN FACILITY DEFS */
+
+/***
+ * CMOS G7 processors
+ ***/
+
+/* 2064-GA1 */
+static uint16_t set_2064_GA1[] = {
+FAC_N3,
+FAC_ZARCH,
+FAC_ZARCH_ACTIVE,
+};
+#define clear_2064_GA1 EmptyFacs
+
+/* 2064-GA2 */
+static uint16_t set_2064_GA2[] = {
+FAC_EXTENDED_TRANSLATION_2,
+};
+#define clear_2064_GA2 EmptyFacs
+
+/* 2064-GA3 */
+#define set_2064_GA3 EmptyFacs
+#define clear_2064_GA3 EmptyFacs
+
+/* 2066-GA1 */
+#define set_2066_GA1 EmptyFacs
+#define clear_2066_GA1 EmptyFacs
+
+/***
+ * CMOS G8 processors
+ ***/
+
+/* 2084-GA1 */
+static uint16_t set_2084_GA1[] = {
+FAC_DAT_ENH,
+FAC_MESSAGE_SECURITY_ASSIST,
+FAC_LONG_DISPLACEMENT,
+FAC_LONG_DISPLACEMENT_FAST,
+FAC_HFP_MADDSUB,
+};
+#define clear_2084_GA1 EmptyFacs
+
+/* 2084-GA2 */
+static uint16_t set_2084_GA2[] = {
+4,
+};
+#define clear_2084_GA2 EmptyFacs
+
+/* 2084-GA3 */
+static uint16_t set_2084_GA3[] = {
+FAC_ASN_LX_REUSE,
+FAC_EXTENDED_TRANSLATION_3,
+};
+#define clear_2084_GA3 EmptyFacs
+
+/* 2084-

[PATCH v5 05/17] Add optional parameters to QMP command query-cpu-definitions

2015-04-13 Thread Michael Mueller
The patch adds optional parameters to the QMP command query-cpu-definitions.
Thus the signature of routine arch_query_cpu_definitions needs to be changed
for the stub function and all target implementations:

target-arm
target-i386
target-ppc
target-s390

Signed-off-by: Michael Mueller 
---
 include/sysemu/arch_init.h  |  7 +--
 qapi-schema.json| 28 +---
 qmp-commands.hx |  2 +-
 qmp.c   | 11 ---
 stubs/arch-query-cpu-def.c  |  6 +-
 target-arm/helper.c |  6 +-
 target-i386/cpu.c   |  6 +-
 target-ppc/translate_init.c |  6 +-
 target-s390x/cpu.c  |  6 +-
 9 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 54b36c1..0d4bf51 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -36,6 +36,9 @@ void audio_init(void);
 int kvm_available(void);
 int xen_available(void);
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
-
+CpuDefinitionInfoList *arch_query_cpu_definitions(bool has_machine,
+  const char *machine,
+  bool has_accel,
+  AccelId accel,
+  Error **errp);
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 215a7bc..285b2d3 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2536,21 +2536,43 @@
 #
 # @name: the name of the CPU definition
 #
+# @default: #optional true if cpu model is the default,
+#   omitted if false (since 2.4)
+#
+# @runnable: #optional true if cpu model is runnable,
+#omitted if false (since 2.4)
+#
+# @live-migration-safe: #optional true if cpu model represents a
+#   cpu model that is safely migratable
+#   omitted if false (since 2.4)
+#
+# @order: #optional order criterion
+#
 # Since: 1.2.0
 ##
 { 'type': 'CpuDefinitionInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool',
+'*live-migration-safe': 'bool', '*order': 'int' } }
 
 ##
 # @query-cpu-definitions:
 #
-# Return a list of supported virtual CPU definitions
+# Return a list of supported virtual CPU definitions. In context with the
+# optional parameters @machine and @accel the returned list contains
+# also information if the respective cpu definition is runnable or the
+# default to be used.
+#
+# @machine: #optional machine type (since 2.4)
+#
+# @accel: #optional accelerator id (since 2.4)
 #
 # Returns: a list of CpuDefInfo
 #
 # Since: 1.2.0
 ##
-{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
+{ 'command': 'query-cpu-definitions',
+  'data': { '*machine': 'str', '*accel': 'AccelId' },
+  'returns': ['CpuDefinitionInfo'] }
 
 # @AddfdInfo:
 #
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 3a42ad0..6592e2c 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3412,7 +3412,7 @@ EQMP
 
 {
 .name   = "query-cpu-definitions",
-.args_type  = "",
+.args_type  = "machine:s?,accel:s?",
 .mhandler.cmd_new = qmp_marshal_input_query_cpu_definitions,
 },
 
diff --git a/qmp.c b/qmp.c
index e6c7050..16a24d1 100644
--- a/qmp.c
+++ b/qmp.c
@@ -567,9 +567,14 @@ DevicePropertyInfoList *qmp_device_list_properties(const 
char *typename,
 return prop_list;
 }
 
-CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
-{
-return arch_query_cpu_definitions(errp);
+CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine,
+ const char *machine,
+ bool has_accel,
+ AccelId accel,
+ Error **errp)
+{
+return arch_query_cpu_definitions(has_machine, machine,
+  has_accel, accel, errp);
 }
 
 void qmp_add_client(const char *protocol, const char *fdname,
diff --git a/stubs/arch-query-cpu-def.c b/stubs/arch-query-cpu-def.c
index 22e0b43..6f8904e 100644
--- a/stubs/arch-query-cpu-def.c
+++ b/stubs/arch-query-cpu-def.c
@@ -2,7 +2,11 @@
 #include "sysemu/arch_init.h"
 #include "qapi/qmp/qerror.h"
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *arch_query_cpu_definitions(bool has_machine,
+  const char *machine,
+   

[PATCH v5 11/17] target-s390x: Add KVM VM attribute interface for S390 CPU models

2015-04-13 Thread Michael Mueller
The patch implements routines to set and retrieve processor configuration
data and to retrieve machine configuration data. The machine related data
is used together with the CPU model facility lists to determine the list of
supported CPU models of this host. The above mentioned routines have QEMU
trace point instrumentation.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.h | 36 -
 target-s390x/kvm.c| 79 +++
 trace-events  |  3 ++
 3 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 35dde5a..efa255e 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -43,11 +43,45 @@ typedef struct S390CPUAlias {
 char *model;
 } S390CPUAlias;
 
-extern GSList *s390_cpu_aliases;
+typedef struct S390ProcessorProps {
+uint64_t cpuid;
+uint16_t ibc;
+uint8_t  pad[6];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390ProcessorProps;
+
+typedef struct S390MachineProps {
+uint64_t cpuid;
+uint32_t ibc;
+uint8_t  pad[4];
+uint64_t fac_mask[FAC_LIST_ARCH_S390_SIZE_UINT64];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390MachineProps;
 
 ObjectClass *s390_cpu_class_by_name(const char *name);
 int set_s390_cpu_alias(const char *name, const char *model);
 
+#ifdef CONFIG_KVM
+int kvm_s390_get_processor_props(S390ProcessorProps *prop);
+int kvm_s390_set_processor_props(S390ProcessorProps *prop);
+bool kvm_s390_cpu_classes_initialized(void);
+#else
+static inline int kvm_s390_get_processor_props(S390ProcessorProps *prop)
+{
+return -ENOSYS;
+}
+static inline int kvm_s390_set_processor_props(S390ProcessorProps *prop)
+{
+return -ENOSYS;
+}
+static inline bool kvm_s390_cpu_classes_initialized(void)
+{
+return false;
+}
+#endif
+
+extern GSList *s390_cpu_aliases;
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b48c643..42f01a8 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -44,6 +44,7 @@
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "cpu-models.h"
 
 /* #define DEBUG_KVM */
 
@@ -122,6 +123,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 
 static int cap_sync_regs;
 static int cap_async_pf;
+static bool cpu_classes_initialized;
 
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
@@ -242,6 +244,59 @@ static void kvm_s390_init_crypto(void)
 kvm_s390_init_dea_kw();
 }
 
+static int cpu_model_get(KVMState *s, uint64_t attr, uint64_t addr)
+{
+int rc = -ENOSYS;
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
+rc = kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &dev_attr);
+}
+
+return rc;
+}
+
+static int cpu_model_set(KVMState *s, uint64_t attr, uint64_t addr)
+{
+int rc = -ENOSYS;
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
+rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &dev_attr);
+}
+
+return rc;
+}
+
+static int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
+{
+int rc = -EFAULT;
+
+if (s) {
+rc = cpu_model_get(s, KVM_S390_VM_CPU_MACHINE, (uint64_t) prop);
+}
+trace_kvm_get_machine_props(rc, prop->cpuid, prop->ibc);
+
+return rc;
+}
+
+static void kvm_setup_cpu_classes(KVMState *s)
+{
+S390MachineProps mach;
+
+if (!kvm_s390_get_machine_props(s, &mach)) {
+cpu_classes_initialized = false;
+}
+}
+
 int kvm_arch_init(MachineState *ms, KVMState *s)
 {
 cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
@@ -255,6 +310,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
 }
 
 kvm_vm_enable_cap(s, KVM_CAP_S390_USER_SIGP, 0);
+kvm_setup_cpu_classes(s);
 
 return 0;
 }
@@ -1940,3 +1996,26 @@ int kvm_arch_fixup_msi_route(struct 
kvm_irq_routing_entry *route,
 route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id;
 return 0;
 }
+
+int kvm_s390_get_processor_props(S390ProcessorProps *prop)
+{
+int rc;
+
+rc = cpu_model_get(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop);
+trace_kvm_get_processor_props(rc, prop->cpuid, prop->ibc);
+return rc;
+}
+
+int kvm_s390_set_processor_props(S390ProcessorProps *prop)
+{
+int rc;
+
+rc = cpu_model_set(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop);
+trace_kvm_set_processor_props(rc);
+return rc;
+}
+
+bool kvm_s390_cpu_classes_initialized(void)
+{
+return cpu_classes_initialized;
+}
diff --git a/trace-

[PATCH v5 17/17] target-s390x: Enable S390 CPU model usage

2015-04-13 Thread Michael Mueller
This patch enables QEMU to instantiate S390 CPUs with CPU model types.

Signed-off-by: Michael Mueller 
---
 hw/s390x/s390-virtio.c | 12 +++-
 target-s390x/helper.c  |  9 ++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index bdb5388..8fda717 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -32,6 +32,7 @@
 #include "hw/virtio/virtio.h"
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
+#include "sysemu/cpus.h"
 #include "exec/address-spaces.h"
 
 #include "hw/s390x/s390-virtio-bus.h"
@@ -157,7 +158,12 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 int i;
 
 if (cpu_model == NULL) {
-cpu_model = "host";
+cpu_model = "none";
+}
+
+if (is_help_option(cpu_model)) {
+list_cpus(stdout, &fprintf, cpu_model);
+exit(0);
 }
 
 ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
@@ -167,6 +173,10 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 CPUState *cs;
 
 cpu = cpu_s390x_init(cpu_model);
+if (cpu == NULL) {
+fprintf(stderr, "Unable to find CPU definition\n");
+exit(1);
+}
 cs = CPU(cpu);
 
 ipi_states[i] = cpu;
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index f1060c2..29dabe2 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -22,6 +22,7 @@
 #include "exec/gdbstub.h"
 #include "qemu/timer.h"
 #include "exec/cpu_ldst.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/sysemu.h"
 #endif
@@ -66,13 +67,7 @@ void s390x_cpu_timer(void *opaque)
 
 S390CPU *cpu_s390x_init(const char *cpu_model)
 {
-S390CPU *cpu;
-
-cpu = S390_CPU(object_new(TYPE_S390_CPU));
-
-object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
-return cpu;
+return S390_CPU(cpu_generic_init(TYPE_S390_CPU, cpu_model));
 }
 
 #if defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 15/17] target-s390x: Extend arch specific QMP command query-cpu-definitions

2015-04-13 Thread Michael Mueller
This patch implements the QMP command 'query-cpu-definitions' in the S390
context. The command returns a list of cpu definitions in the current host
context. A runnable and migratable cpu model has the related attributes
set to true. The order attribute is used to bring the listed cpu definitions
in a release order.

request:
  {"execute": "query-cpu-definitions",
  "arguments": { "accel": "kvm",
 "machine": "s390-ccw-virtio" }
  }

answer:
  {"return": [ { "order": 3345, "name": "2964-ga1",
 "live-migration-safe": true },
   { "name": "zBC12", "runnable": true },
   { "name": "2828", "runnable": true },
   ...
   { "name": "host", "runnable": true },
   ...
   { "order": 3090, "name": "2827-ga2", "runnable": true,
 "live-migration-safe": true, "is-default": true },
   ...
   { "name": "none", "runnable": true } ]
  }

The request arguments are optional and if omitted lead to different answers.
Eventually only the CPU model none gets returned as runnable and as default

   ...
   { "name": "none", "runnable": true, "is-default": true }

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c |  15 ++
 target-s390x/cpu-models.h |   7 +++
 target-s390x/cpu.c| 126 +++---
 target-s390x/kvm.c|  49 +-
 4 files changed, 189 insertions(+), 8 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index fa74a8a..b696897 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -208,6 +208,21 @@ int set_s390_cpu_alias(const char *name, const char *model)
 return 0;
 }
 
+/* compare order of two cpu classes for descending sort */
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return 1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return -1;
+}
+return 0;
+}
+
 /* return machine class for specific machine type */
 static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
 {
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index c24550b..76673f4 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -87,6 +87,7 @@ void s390_setup_cpu_classes(S390AccelMode mode, 
S390MachineProps *prop,
 uint64_t *fac_list_mask);
 void s390_setup_cpu_aliases(void);
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b);
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b);
 void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 uint64_t *s390_fac_list_mask_by_machine(const char *name);
@@ -94,10 +95,16 @@ uint64_t *s390_current_fac_list_mask(void);
 void s390_cpu_model_init(S390CPUClass *cc);
 
 #ifdef CONFIG_KVM
+int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop);
 int kvm_s390_get_processor_props(S390ProcessorProps *prop);
 int kvm_s390_set_processor_props(S390ProcessorProps *prop);
 bool kvm_s390_cpu_classes_initialized(void);
 #else
+static inline int kvm_s390_get_machine_props(KVMState *s,
+ S390MachineProps *prop)
+{
+return -ENOSYS;
+}
 static inline int kvm_s390_get_processor_props(S390ProcessorProps *prop)
 {
 return -ENOSYS;
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 771acbd..a006b93 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -30,7 +30,10 @@
 #include "hw/hw.h"
 #include "trace.h"
 #include "cpu-models.h"
+#include "sysemu/accel.h"
+#include "qapi/qmp/qerror.h"
 #ifndef CONFIG_USER_ONLY
+#include "hw/boards.h"
 #include "sysemu/arch_init.h"
 #endif
 
@@ -61,22 +64,131 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 }
 
 #ifndef CONFIG_USER_ONLY
+static CpuDefinitionInfoList *qmp_query_cpu_definition_host(void)
+{
+CpuDefinitionInfoList *host = NULL;
+CpuDefinitionInfo *info;
+
+info = g_try_new0(CpuDefinitionInfo, 1);
+if (!info) {
+goto out;
+}
+info->name = g_strdup("host");
+
+host = g_try_new0(CpuDefinitionInfoList, 1);
+if (!host) {
+g_free(info->name);
+g_free(info);
+goto out

[PATCH v5 13/17] target-s390x: Prepare accelerator during S390 CPU object realization

2015-04-13 Thread Michael Mueller
This patch implements routine s390_cpu_model_init(). It is called by the
realize function during instantiation of an CPU object. Its task is to
initialize the current accelerator with the properties of the selected
processor model.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 30 ++
 target-s390x/cpu-models.h |  4 
 target-s390x/cpu.c|  1 +
 3 files changed, 35 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 07039c0..fa74a8a 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -670,3 +670,33 @@ uint64_t *s390_current_fac_list_mask(void)
 return s390_fac_list_mask_by_machine(mc->name);
 }
 #endif
+
+/**
+ * s390_cpu_model_init:
+ * @cc: S390 CPU class
+ *
+ * This function intitializes the current accelerator with processor
+ * related properties.
+ *
+ * Since: 2.4
+ */
+void s390_cpu_model_init(S390CPUClass *cc)
+{
+S390ProcessorProps proc = {
+.cpuid = cpuid(cc->proc),
+.ibc = cc->proc.ibc,
+};
+
+/* none cpu model case */
+if (!proc.cpuid) {
+return;
+}
+
+bitmap_zero(proc.fac_list, FAC_LIST_ARCH_S390_SIZE_UINT1);
+bitmap_copy(proc.fac_list, cc->fac_list[ACCEL_CURRENT],
+FAC_LIST_CPU_S390_SIZE_UINT1);
+
+if (kvm_enabled()) {
+kvm_s390_set_processor_props(&proc);
+}
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 00454d3..c24550b 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -45,6 +45,9 @@
 #define type_cpuid(x) ((uint64_t)((x) & 0x) << 16)
 #define id_cpuid(x)   ((uint64_t)((x) & 0xff) << 32)
 #define ver_cpuid(x)  ((uint64_t)((x) & 0xff) << 56)
+#define cpuid(x)  (ver_cpuid(x.ver) |  \
+   id_cpuid(x.id) |\
+   type_cpuid(x.type))
 
 #define oldest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff)
 #define newest_ibc(x) ((uint32_t)(x) & 0xfff)
@@ -88,6 +91,7 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 uint64_t *s390_fac_list_mask_by_machine(const char *name);
 uint64_t *s390_current_fac_list_mask(void);
+void s390_cpu_model_init(S390CPUClass *cc);
 
 #ifdef CONFIG_KVM
 int kvm_s390_get_processor_props(S390ProcessorProps *prop);
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index cbab627..65dee3e 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -184,6 +184,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error 
**errp)
 CPUState *cs = CPU(dev);
 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
 
+s390_cpu_model_init(scc);
 s390_cpu_gdb_init(cs);
 qemu_init_vcpu(cs);
 #if !defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 16/17] target-s390x: Introduce S390 CPU facility test routine

2015-04-13 Thread Michael Mueller
The patch introduces routine s390_facility_test() which allows to
verify if a specific facility bit is set.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 29 +
 target-s390x/cpu-models.h |  1 +
 2 files changed, 30 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index b696897..f218dde 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -715,3 +715,32 @@ void s390_cpu_model_init(S390CPUClass *cc)
 kvm_s390_set_processor_props(&proc);
 }
 }
+
+static inline int test_facility(uint64_t *fac_list, uint16_t nr)
+{
+uint16_t word = nr / BITS_PER_LONG;
+uint16_t be_bit = (BITS_PER_LONG - 1) - (nr % BITS_PER_LONG);
+
+return (nr < FAC_LIST_CPU_S390_SIZE_UINT1) ?
+(fac_list[word] >> be_bit) & __UINT64_C(1) : 0;
+}
+
+/**
+ * s390_test_facility:
+ * @nr: facility bit number to test
+ * @cc: cpu class to test
+ *
+ * The functions tests if the cpu facility identified by bit @nr is available
+ * to the cpu class @cc.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.4
+ */
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr)
+{
+if (!cc) {
+return false;
+}
+return test_facility(cc->fac_list[ACCEL_CURRENT], nr) ? true : false;
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 76673f4..23242aa 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -93,6 +93,7 @@ bool s390_cpu_classes_initialized(void);
 uint64_t *s390_fac_list_mask_by_machine(const char *name);
 uint64_t *s390_current_fac_list_mask(void);
 void s390_cpu_model_init(S390CPUClass *cc);
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr);
 
 #ifdef CONFIG_KVM
 int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop);
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 10/17] target-s390x: Add S390 CPU model alias definition routines

2015-04-13 Thread Michael Mueller
This patch implements the infrastructure to dynamically add
CPU model aliases.

Signed-off-by: Michael Mueller 
Reviewed-by: Cornelia Huck 
---
 target-s390x/cpu-models.c | 82 +++
 target-s390x/cpu-models.h | 13 
 target-s390x/cpu.c|  1 +
 3 files changed, 96 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 6cc121b..28251f9 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -88,3 +88,85 @@ S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM 
zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
 
+GSList *s390_cpu_aliases;
+
+static gint s390_cpu_compare_name(gconstpointer a, gconstpointer b)
+{
+char *aname = strdup_cpu_name((S390CPUClass *) a);
+gint rc;
+
+rc = strcasecmp(aname, (char *) b);
+free(aname);
+
+return rc;
+}
+
+/**
+ * s390_cpu_class_by_name:
+ * @name: a cpu model or alias name
+ *
+ * The function searches for the requested cpu model name or an alias
+ * cpu model name and returns the associated object class.
+ *
+ * Returns: reference to object class on success or %NULL elsewise.
+ *
+ * Since: 2.4
+ */
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+GSList *list, *item;
+ObjectClass *ret = NULL;
+S390CPUAlias *alias;
+
+for (item = s390_cpu_aliases; item != NULL; item = item->next) {
+alias = (S390CPUAlias *) item->data;
+if (strcmp(alias->name, name) == 0) {
+return s390_cpu_class_by_name(alias->model);
+}
+}
+list = object_class_get_list(TYPE_S390_CPU, false);
+item = g_slist_find_custom(list, name, s390_cpu_compare_name);
+if (item) {
+ret = OBJECT_CLASS(item->data);
+}
+g_slist_free(list);
+return ret;
+}
+
+/**
+ * set_s390_cpu_alias:
+ * @name: the cpu alias name
+ * @model: the cpu model name
+ *
+ * The function registers the alias @name for an existing cpu @model.
+ *
+ * Returns: %0 in case of success
+ *  -%EINVAL if name or model is %NULL or both are idential
+ *   or model is not a valid cpu model
+ *  -%ENOMEM if internal memory allocation fails
+ *
+ * Since: 2.4
+ */
+int set_s390_cpu_alias(const char *name, const char *model)
+{
+S390CPUAlias *alias;
+
+if (!name || !model) {
+return -EINVAL;
+}
+if (!strcmp(name, model)) {
+return -EINVAL;
+}
+if (!s390_cpu_class_by_name(model)) {
+return -EINVAL;
+}
+alias = g_try_malloc0(sizeof(S390CPUAlias));
+if (!alias) {
+return -ENOMEM;
+}
+alias->name = g_strdup(name);
+alias->model = g_strdup(model);
+s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+return 0;
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 948af10..35dde5a 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -36,6 +36,19 @@
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
 /*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+char *name;
+char *model;
+} S390CPUAlias;
+
+extern GSList *s390_cpu_aliases;
+
+ObjectClass *s390_cpu_class_by_name(const char *name);
+int set_s390_cpu_alias(const char *name, const char *model);
+
+/*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
  * bits 10-11 : machine class 0=unknown 1=EC 2=BC
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 9232a97..c081885 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -314,6 +314,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
 #endif
 scc->cpu_reset = s390_cpu_reset;
 scc->initial_cpu_reset = s390_cpu_initial_reset;
+cc->class_by_name = s390_cpu_class_by_name;
 cc->reset = s390_cpu_full_reset;
 cc->has_work = s390_cpu_has_work;
 cc->do_interrupt = s390_cpu_do_interrupt;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 14/17] target-s390x: Initialize S390 CPU model name in CPUState

2015-04-13 Thread Michael Mueller
The cpu model name now gets initialized during CPU instance
initialization.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 65dee3e..771acbd 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -207,6 +207,7 @@ static void s390_cpu_initfn(Object *obj)
 struct tm tm;
 #endif
 
+cs->model_name = strdup_cpu_name(S390_CPU_GET_CLASS(cs));
 cs->env_ptr = env;
 cpu_exec_init(env);
 #if !defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 12/17] target-s390x: Add S390 CPU class initialization routines

2015-04-13 Thread Michael Mueller
This patch provides routines to dynamically update the previously defined
S390 CPU classes in the current host context. The main function performing
this process is s390_setup_cpu_classes(). It takes the current host context
and a facility list mask as parameter to setup the classes accordingly. It
basically performs the following sub-tasks:

- Update of CPU classes with accelerator specific host and QEMU properties
- Mark adequate CPU class as default CPU class to be used for CPU model 'host'
- Invalidate CPU classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common CPU model names
- Set CPU model alias 'host' to default CPU class

Forthermore the patch provides the following routines:

- cpu_desc_avail(), s390 specific stub indicating that list_cpus() can run
- s390_setup_cpu_aliases(), adds cu model aliases
- s390_cpu_classes_initialized(), test if CPU classes have been initialized
- s390_fac_list_mask_by_machine(), returns facility list mask by machine
- s390_current_fac_list_mask(), returns facility list mask of current machine

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 500 ++
 target-s390x/cpu-models.h |  29 +++
 target-s390x/cpu.c|  17 +-
 target-s390x/kvm.c|   5 +-
 4 files changed, 549 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 28251f9..07039c0 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -13,6 +13,11 @@
 #include "qemu-common.h"
 #include "cpu-models.h"
 #include "gen-facilities.h"
+#include "qemu/error-report.h"
+#ifndef CONFIG_USER_ONLY
+#include "exec/cpu-common.h"
+#include "hw/boards.h"
+#endif
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -88,8 +93,41 @@ S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM 
zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
 
+/* some types for calls to g_list_foreach() with parameters */
+typedef struct ParmBoolShortShort {
+bool valid;
+unsigned short type;
+union {
+unsigned short class;
+unsigned short gen;
+unsigned short ga;
+};
+} ParmBoolShortShort;
+
+typedef struct ParmAddrAddrModeMask {
+S390MachineProps *prop;
+S390CPUClass *host_cc;
+S390AccelMode mode;
+uint64_t *mask;
+} ParmAddrAddrModeMask;
+
 GSList *s390_cpu_aliases;
 
+/* compare order of two cpu classes for ascending sort */
+gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return -1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return 1;
+}
+return 0;
+}
+
 static gint s390_cpu_compare_name(gconstpointer a, gconstpointer b)
 {
 char *aname = strdup_cpu_name((S390CPUClass *) a);
@@ -170,3 +208,465 @@ int set_s390_cpu_alias(const char *name, const char 
*model)
 return 0;
 }
 
+/* return machine class for specific machine type */
+static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShort *parm = user_data;
+
+if (parm->valid || is_cpu_class_none(cc) || parm->type != cc->proc.type) {
+return;
+}
+
+parm->class = cc->mach.class;
+parm->valid = true;
+}
+
+/* return machine class by machine type */
+static unsigned short machine_class(unsigned short type, void *user_data)
+{
+GSList *list = object_class_get_list(TYPE_S390_CPU, false);
+ParmBoolShortShort parm_class, *parm = user_data;
+
+if (parm->type != type) {
+parm->class = 0;
+}
+if (!parm->class) {
+parm_class.type = type;
+parm_class.class = 0;
+parm_class.valid = false;
+g_slist_foreach(list, (GFunc) s390_machine_class_test_cpu_class,
+&parm_class);
+g_slist_free(list);
+if (parm_class.valid) {
+parm->class = parm_class.class;
+}
+}
+parm->type = type;
+
+return parm->class;
+}
+
+/* return CMOS generation for specific machine type */
+static void s390_machine_class_test_cpu_gen(gpointer data, gpointer user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShort *parm = user_data;
+
+if (parm->valid) {
+return;
+}
+
+if (parm->type == cc-&g

[PATCH v5 03/17] Extend QMP command query-cpus to return accelerator id and model name

2015-04-13 Thread Michael Mueller
The QMP command query-cpus now additionally displays a model name and
the backing accelerator. Both are omitted if the model name is not
initialized.

  request:
{ "execute" : "query-cpus" }

  answer:
{ { "current": true,
"CPU": 0,
"model": "2827-ga2",
"halted": false,
"accel": "kvm",
"thread_id": 31917
  }, ... }

Signed-off-by: Michael Mueller 
---
 cpus.c   | 4 
 qapi-schema.json | 7 ++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/cpus.c b/cpus.c
index e6dcae3..00f33b9 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1436,6 +1436,10 @@ CpuInfoList *qmp_query_cpus(Error **errp)
 info->value->current = (cpu == first_cpu);
 info->value->halted = cpu->halted;
 info->value->thread_id = cpu->thread_id;
+info->value->model = g_strdup(cpu->model_name);
+info->value->accel = cpu->accel_id;
+info->value->has_model = info->value->has_accel =
+info->value->model != NULL;
 #if defined(TARGET_I386)
 info->value->has_pc = true;
 info->value->pc = env->eip + env->segs[R_CS].base;
diff --git a/qapi-schema.json b/qapi-schema.json
index 540e520..215a7bc 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -616,6 +616,10 @@
 #
 # @thread_id: ID of the underlying host thread
 #
+# @accel: #optional accelerator id (since 2.4)
+#
+# @model: #optional cpu model name (since 2.4)
+#
 # Since: 0.14.0
 #
 # Notes: @halted is a transient state that changes frequently.  By the time the
@@ -623,7 +627,8 @@
 ##
 { 'type': 'CpuInfo',
   'data': {'CPU': 'int', 'current': 'bool', 'halted': 'bool', '*pc': 'int',
-   '*nip': 'int', '*npc': 'int', '*PC': 'int', 'thread_id': 'int'} }
+   '*nip': 'int', '*npc': 'int', '*PC': 'int', 'thread_id': 'int',
+   '*accel': 'AccelId', '*model': 'str'} }
 
 ##
 # @query-cpus:
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 04/17] Extend HMP command info cpus to display accelerator id and model name

2015-04-13 Thread Michael Mueller
The HMP command info cpus now displays the CPU model name and the
backing accelerator if part of the CPUState.

(qemu) info cpus
* CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679

Signed-off-by: Michael Mueller 
---
 hmp.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/hmp.c b/hmp.c
index f31ae27..70238332 100644
--- a/hmp.c
+++ b/hmp.c
@@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
 monitor_printf(mon, " (halted)");
 }
 
+if (cpu->value->has_model) {
+monitor_printf(mon, " model=%s", cpu->value->model);
+}
+if (cpu->value->has_accel) {
+monitor_printf(mon, " accel=%s", 
AccelId_lookup[cpu->value->accel]);
+}
+
 monitor_printf(mon, " thread_id=%" PRId64 "\n", cpu->value->thread_id);
 }
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 00/17] s390x cpu model implementation

2015-04-13 Thread Michael Mueller
lerator field now mandatory for "query-cpu-model" (13/16)
- sorted list related comment to "query-cpu-definitions" dropped in
  commit message (13/16)
- comment for AccelCpuInfo type updated (13/16)
- routine s390_facility_test() factored out (15/16)

v1-v2:
- QEMU-side facility list mask introduced: this allows to enable guest
  facilities that are handled by instruction interception handlers
  implemented on qemu side. Similar to the facilities enabled by means
  of the KVM side facility list mask which are handled by kvm/kernel.
- Concept of soft facilities has been dropped
- Result type of QMP command query-cpu-definitions extended to hold
  additional information beside the cpu model name including which
  cpu model is runnable in current accelerator and machine context.

Michael Mueller (17):
  Introduce stub routine cpu_desc_avail
  Add accelerator id and model name to CPUState
  Extend QMP command query-cpus to return accelerator id and model name
  Extend HMP command info cpus to display accelerator id and model name
  Add optional parameters to QMP command query-cpu-definitions
  target-s390x: Introduce S390 CPU facilities
  target-s390x: Generate facility defines per S390 CPU model
  target-s390x: Introduce S390 CPU models
  target-s390x: Define S390 CPU model specific facility lists
  target-s390x: Add S390 CPU model alias definition routines
  target-s390x: Add KVM VM attribute interface for S390 CPU models
  target-s390x: Add S390 CPU class initialization routines
  target-s390x: Prepare accelerator during S390 CPU object realization
  target-s390x: Initialize S390 CPU model name in CPUState
  target-s390x: Extend arch specific QMP command query-cpu-definitions
  target-s390x: Introduce S390 CPU facility test routine
  target-s390x: Enable S390 CPU model usage

 Makefile.target   |   2 +-
 cpus.c|   4 +
 hmp.c |   7 +
 hw/s390x/s390-virtio.c|  12 +-
 include/qemu-common.h |   2 +
 include/qom/cpu.h |   5 +
 include/sysemu/arch_init.h|   7 +-
 qapi-schema.json  |  44 ++-
 qmp-commands.hx   |   2 +-
 qmp.c |  11 +-
 qom/cpu.c |  14 +
 rules.mak |   1 +
 stubs/Makefile.objs   |   1 +
 stubs/arch-query-cpu-def.c|   6 +-
 stubs/cpu-desc-avail.c|   6 +
 target-arm/helper.c   |   6 +-
 target-i386/cpu.c |   6 +-
 target-ppc/translate_init.c   |   6 +-
 target-s390x/Makefile.objs|  21 ++
 target-s390x/cpu-facilities.h |  86 +
 target-s390x/cpu-models.c | 746 ++
 target-s390x/cpu-models.h | 168 ++
 target-s390x/cpu-qom.h|  49 +++
 target-s390x/cpu.c| 149 -
 target-s390x/gen-facilities.c | 417 +++
 target-s390x/helper.c |   9 +-
 target-s390x/kvm.c| 129 
 trace-events  |   3 +
 vl.c  |   2 +-
 29 files changed, 1891 insertions(+), 30 deletions(-)
 create mode 100644 stubs/cpu-desc-avail.c
 create mode 100644 target-s390x/cpu-facilities.h
 create mode 100644 target-s390x/cpu-models.c
 create mode 100644 target-s390x/cpu-models.h
 create mode 100644 target-s390x/gen-facilities.c

-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-04-02 Thread Michael Mueller
On Wed, 1 Apr 2015 20:05:24 -0300
Eduardo Habkost  wrote:

> > > 
> > > If you don't want to encode that knowledge in libvirt or other
> > > management software for s390, it looks like you need something like a
> > > "stable-abi-safe" field on CpuDefinitionInfo?  
> > 
> > Exactly that fulfills the "name" field for s390 already in my view.
> > 
> > And cpu model "none" just means that QEMU does not manage the cpu model. 
> > That's also
> > the reason why I initially returned an empty "[]" model and not "none". 
> > This somewhat
> > convinces me to go back to this approach...  
> 
> I understand the reasons for your approach and it seems to work for
> s390, but the only problem I see is that you are adding an additional
> (undocumented?) s390-specific constraint to the semantics of
> query-cpu-models: that the model name will appear on the list only if it
> can be safely migratable. This may prevent us from unifying CPU model
> code into generic code later.

I agree that an aliases is something different compared with the CPU model none 
as
there is a CPU class representing it. And thus, when implicitly or explicitly 
selected,
shall be presented in the CPU definition list as well. If I would set 
"runnable" to
false as it now (bad), it would be sorted out by the "considered for migration" 
test but it
would be misleading as it is always runnable. Though an additional field like 
"migrate-able"
could express that characteristic.

> 
> But if we add a simple stable-abi-safe field to the list (even if s390
> set it to to true for all models and omit aliases and "none" in this
> first version), we will have clearer semantics that can still be
> honoured by other architectures (and by generic code) later.

To be honest I currently don't right get the idea that you follow with that
stable-abi-save field... But eventually yes (I wrote this before the section 
above)

The stable-abi-save field means: "Take me into account for whatever kind of
CPU model related comparison you perform between two running QEMU instances as I
represent a well defined aspect.

Thus CPU model none will be { "name": "none", "runnable: true, 
"stable-abi-save": false } and
the aliases can be represented as { "name": , "runnable": , 
"stable-abi-save":
false } in the s390 case, right?

Michael


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-04-01 Thread Michael Mueller
On Wed, 1 Apr 2015 21:05:31 +0200
Michael Mueller  wrote:

> And cpu model "none" just means that QEMU does not manage the cpu model. 
> That's also
> the reason why I initially returned an empty "[]" model and not "none". This 
> somewhat
> convinces me to go back to this approach...

And for query-cpus that can be represented as a non-existent model field:

[{"current":true,"CPU":0,"halted":false,"thread_id":39110}, ...]

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-04-01 Thread Michael Mueller
On Wed, 1 Apr 2015 13:59:05 -0300
Eduardo Habkost  wrote:

> > Not directly invalid as "-cpu none" will be the same as omitting the -cpu 
> > option.
> > KVM will setup the vcpu properties withou any QEMU control to whatever the 
> > hosting
> > machine and the kvm kernel code offers. That will allow to run QEMU against 
> > a KVM
> > version that is not aware of the s390 cpu model ioctls.  
> 
> It looks like we have conflicting expectations about
> query-cpu-definitions, it seems: on the one hand, if "-cpu none" is
> valid I believe it should appear on the query-cpu-definitions return
> value; on the other hand, it is not (always?) migration-safe, so just
> comparing the source query-cpus data with the target
> query-cpu-definitions data wouldn't be enough to ensure live-migration
> safety.

There are other cases as well where the value given with -cpu is *not* part
of the cpu definition list and that is aliases:

[mimu@p57lp59 (master-cpu-model) qemu]$ ./s390x-softmmu/qemu-system-s390x 
-machine
s390-ccw,accel=kvm -cpu ?
s390 2064-ga1   IBM zSeries 900 GA1
s390 2064-ga2   IBM zSeries 900 GA2
s390 2064-ga3   IBM zSeries 900 GA3
s390 2064   (alias for 2064-ga3)
s390 z900   (alias for 2064-ga3)
...
s390 z10(alias for 2097-ga3)
s390 z10-ec (alias for 2097-ga3)
s390 2098-ga1   IBM System z10 BC GA1
s390 2098-ga2   IBM System z10 BC GA2
s390 2098   (alias for 2098-ga2)
s390 z10-bc (alias for 2098-ga2)
s390 2817-ga1   IBM zEnterprise 196 GA1
s390 2817-ga2   IBM zEnterprise 196 GA2
s390 2817   (alias for 2817-ga2)
s390 z196   (alias for 2817-ga2)
s390 2818-ga1   IBM zEnterprise 114 GA1
s390 2818   (alias for 2818-ga1)
s390 z114   (alias for 2818-ga1)
s390 2827-ga1   IBM zEnterprise EC12 GA1
s390 2827-ga2   IBM zEnterprise EC12 GA2
s390 2827   (alias for 2827-ga2)
s390 zEC12  (alias for 2827-ga2)
s390 host   (alias for 2827-ga2)
s390 2828-ga1   IBM zEnterprise BC12 GA1
s390 2828   (alias for 2828-ga1)
s390 zBC12  (alias for 2828-ga1)

As you can see "host" is in s390x case always an alias and also all other 
aliases
are normalized to their real cpu models in the cpu-definitions list.

> 
> On x86, we have a similar problem with "-cpu host", that changes
> depending on the host hardware and host kernel. We solve this problem by
> making libvirt code aware of the set of valid CPU models, and libvirt
> has special cases for "-cpu host".

"-cpu host" is not a special case for s390, it will return ("2827-ga2", "kvm") 
as
cpu model or whatever model the hosting system implements.

> 
> If you don't want to encode that knowledge in libvirt or other
> management software for s390, it looks like you need something like a
> "stable-abi-safe" field on CpuDefinitionInfo?

Exactly that fulfills the "name" field for s390 already in my view.

And cpu model "none" just means that QEMU does not manage the cpu model. That's 
also
the reason why I initially returned an empty "[]" model and not "none". This 
somewhat
convinces me to go back to this approach...

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-04-01 Thread Michael Mueller
On Wed, 1 Apr 2015 10:01:13 -0300
Eduardo Habkost  wrote:

> On Tue, Mar 31, 2015 at 10:09:09PM +0200, Michael Mueller wrote:
> > On Tue, 31 Mar 2015 15:35:26 -0300
> > Eduardo Habkost  wrote:
> > 
> > > On Mon, Mar 30, 2015 at 04:28:24PM +0200, Michael Mueller wrote:
> > > > This patch implements a new QMP request named 'query-cpu-model'.
> > > > It returns the cpu model of cpu 0 and its backing accelerator.
> > > > 
> > > > request:
> > > >   {"execute" : "query-cpu-model" }
> > > > 
> > > > answer:
> > > >   {"return" : {"name": "2827-ga2", "accel": "kvm" }}
> > > > 
> > > > Alias names are resolved to their respective machine type and GA names
> > > > already during cpu instantiation. Thus, also a cpu model like 'host'
> > > > which is implemented as alias will return its normalized cpu model name.
> > > > 
> > > > Furthermore the patch implements the following function:
> > > > 
> > > > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > > > 
> > > > Signed-off-by: Michael Mueller 
> > > > ---
> > > [...]
> > > > +static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > > > +{
> > > > +return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > > > +}
> > > 
> > > How exactly is this information going to be used by clients? If getting
> > > the correct type and ga values is important for them, maybe you could
> > > add them as integer fields, instead of requiring clients to parse the
> > > CPU model name?
> > 
> > The consumer don't need to parse the name, it is just important for them to 
> > have
> > distinctive names that correlate with the names returned by 
> > query-cpu-definitions.
> > Once the name of an active guest is known, e.g. ("2827-ga2", "kvm") a 
> > potential
> > migration target can be verified, i.e. its query-cpu-definitions answer for 
> > "kvm"
> > has to contain "2827-ga2" with the attribute runnable set to true. With 
> > that mechanism
> > also the largest common denominator can be calculated. That model will be 
> > used then.
> 
> Understood. So the point is to really have a name that can be found at
> query-cpu-definitions. Makes sense.
> 
> (BTW, if you reused strdup_s390_cpu_name() inside
> s390_cpu_compare_class_name() too, you would automatically ensure that
> query-cpus, query-cpu-definitions and s390_cpu_class_by_name() will
> always agree with each other).

I have to verify but it seems to make sense from reading... I will do that if 
it works. :-)

> 
> > 
> > I also changed the above mentioned routine to map the cpu model none case:
> > 
> > static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > {
> > if (cpuid(cc->proc)) {
> > return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > } else {
> > return g_strdup("none");
> > }
> > }
> 
> What about:
> 
>   static const char *s390_cpu_name(S390CPUClass *cc)
>   {
>   return cc->model_name;
>   }
> 
> And then you can just set cc->model_name=_name inside S390_PROC_DEF (and
> set it to "none" inside s390_cpu_class_init()).
> 

Wouldn't that store redundant information... but it would at least shift the 
work into the
initialization phase and do the format just once per model.

> I wonder if this class->model_name conversion could be made generic
> inside the CPU class. We already have a CPU::class_by_name() method, so
> it makes sense to have the opposite function too.
> 
> (But I wouldn't mind making this s390-specific first, and converted
> later to generic code if appropriate).

ok

> 
> > 
> > This implicitly will fail a comparison for cpu model ("none", "kvm") as 
> > that will
> > never be part of the query-cpu-definitions answer.
> 
> I am not sure I follow. If ("none", "kvm") is never in the list, is
> "-cpu none -machine accel=kvm" always an invalid use case?

Not directly invalid as "-cpu none" will be the same as omitting the -cpu 
option.
KVM will setup the vcpu properties withou any QEMU control to whatever the 
hosting
machine and the kvm kernel code offers. That will allow to run QEMU against a 
KVM
version that is not aware of the s390 cpu model ioctls.

> 
> (I don't understand completely the meaning of "-cpu none" yet. How does
> the CPU look like for the guest in this case? Is it possible to
> live-migrate when using -cpu none?)

And yes, that does not make sense in a migration context. The answer on 
query-cpu-model
(or query-cpus) will be ("none", "kvm") and that will never match a runnable 
model.
The guest cpu will be derived from the hosting system and the kvm kernel as it 
is currently
without the cpu model interface. 

I hope I made it better to understand now...

Michael

> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 12/15] Add optional parameters to QMP command query-cpu-definitions

2015-03-31 Thread Michael Mueller
On Tue, 31 Mar 2015 16:46:56 -0300
Eduardo Habkost  wrote:

> On Mon, Mar 30, 2015 at 04:28:25PM +0200, Michael Mueller wrote:
> [...]
> >  ##
> >  # @query-cpu-definitions:
> >  #
> >  # Return a list of supported virtual CPU definitions
> >  #
> > +# @machine: #optional machine type (since 2.4)
> > +#
> > +# @accel: #optional accelerator id (since 2.4)
> > +#
> >  # Returns: a list of CpuDefInfo
> >  #
> >  # Since: 1.2.0
> >  ##
> > -{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
> > +{ 'command': 'query-cpu-definitions',
> > +  'data': { '*machine': 'str', '*accel': 'AccelId' },
> > +  'returns': ['CpuDefinitionInfo'] }
> 
> What happens if the new parameters are provided to an old QEMU version
> that doesn't accept them? It looks like we need an introspection
> mechanism or a new command name.

Yep, as Eric mentions:

[mimu@p57lp59 (master) qemu]$ sudo virsh qemu-monitor-command zhyp027 '{ 
"execute":
"query-cpu-definitions", "arguments": { "accel": "kvm", "machine":
"s390-ccw-virtio" } }'

{"id":"libvirt-13","error":{"class":"GenericError","desc":"Invalid parameter 
'accel'"}}



> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-03-31 Thread Michael Mueller
On Tue, 31 Mar 2015 15:35:26 -0300
Eduardo Habkost  wrote:

> On Mon, Mar 30, 2015 at 04:28:24PM +0200, Michael Mueller wrote:
> > This patch implements a new QMP request named 'query-cpu-model'.
> > It returns the cpu model of cpu 0 and its backing accelerator.
> > 
> > request:
> >   {"execute" : "query-cpu-model" }
> > 
> > answer:
> >   {"return" : {"name": "2827-ga2", "accel": "kvm" }}
> > 
> > Alias names are resolved to their respective machine type and GA names
> > already during cpu instantiation. Thus, also a cpu model like 'host'
> > which is implemented as alias will return its normalized cpu model name.
> > 
> > Furthermore the patch implements the following function:
> > 
> > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> [...]
> > +static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > +{
> > +return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > +}
> 
> How exactly is this information going to be used by clients? If getting
> the correct type and ga values is important for them, maybe you could
> add them as integer fields, instead of requiring clients to parse the
> CPU model name?

The consumer don't need to parse the name, it is just important for them to have
distinctive names that correlate with the names returned by 
query-cpu-definitions.
Once the name of an active guest is known, e.g. ("2827-ga2", "kvm") a potential
migration target can be verified, i.e. its query-cpu-definitions answer for 
"kvm"
has to contain "2827-ga2" with the attribute runnable set to true. With that 
mechanism
also the largest common denominator can be calculated. That model will be used 
then.

I also changed the above mentioned routine to map the cpu model none case:

static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
{
if (cpuid(cc->proc)) {
return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
} else {
return g_strdup("none");
}
}

This implicitly will fail a comparison for cpu model ("none", "kvm") as that 
will
never be part of the query-cpu-definitions answer.

I actually applied a couple of your suggestions like:

- test for NULL skipped after strdup_s390_cpu_name()
- strdup_s390_cpu_name() now also handles none cpu model case
- omit runnable and is-default field from query-cpu-definitions
  answer when they are false
- global variable cpu_models_used dropped
- function s390_cpu_models_used() dropped
- routine query-cpu-definitions has a single code path now

Only the integration of the ACCEL_ID with the cpu state in cpu_generic_init() 
and
the change for the query-cpus implementation is under construction. I hope to 
resend
the patches by tomorrow evening.

Thanks,
Michael 

> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-03-31 Thread Michael Mueller
On Mon, 30 Mar 2015 17:17:21 -0300
Eduardo Habkost  wrote:

> On Mon, Mar 30, 2015 at 04:28:24PM +0200, Michael Mueller wrote:
> > This patch implements a new QMP request named 'query-cpu-model'.
> > It returns the cpu model of cpu 0 and its backing accelerator.
> > 
> > request:
> >   {"execute" : "query-cpu-model" }
> > 
> > answer:
> >   {"return" : {"name": "2827-ga2", "accel": "kvm" }}
> 
> If you are returning information about an existing CPU, why not just
> extend the output of "query-cpus"?
> 
> (Existing qmp_query_cpus() calls cpu_synchronize_state(), which may be
> undesired. But in this case we could add an optional parameter to
> disable the return of data that requires stopping the VCPU).

Will the cpu_cpu_syncronize_state() really hurt in real life? query-cpus will 
be called only once
a while...

I will prepare the extension of query-cpus as an option but initially without 
the optional
parameter.

> 
> > 
> > Alias names are resolved to their respective machine type and GA names
> > already during cpu instantiation. Thus, also a cpu model like 'host'
> > which is implemented as alias will return its normalized cpu model name.
> > 
> > Furthermore the patch implements the following function:
> > 
> > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > 
> > Signed-off-by: Michael Mueller 
> [...]
> 

Thanks,
Michael


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 10/15] target-s390x: Prepare accelerator during cpu object realization

2015-03-31 Thread Michael Mueller
On Mon, 30 Mar 2015 16:33:51 -0300
Eduardo Habkost  wrote:

> On Mon, Mar 30, 2015 at 04:28:23PM +0200, Michael Mueller wrote:
> > This patch implements routine s390_cpu_model_init(). It is called by the
> > realize function during instantiation of an cpu object. Its task is to
> > initialize the current accelerator with the properties of the selected
> > processor model.
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> >  target-s390x/cpu-models.c | 37 +
> >  target-s390x/cpu-models.h |  4 
> >  target-s390x/cpu.c|  1 +
> >  3 files changed, 42 insertions(+)
> > 
> > diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
> > index 8a877d3..ba873ea 100644
> > --- a/target-s390x/cpu-models.c
> > +++ b/target-s390x/cpu-models.c
> > @@ -111,6 +111,7 @@ typedef struct ParmAddrAddrModeMask {
> >  } ParmAddrAddrModeMask;
> >  
> >  static GSList *s390_cpu_aliases;
> > +static bool cpu_models_used;
> >  
> >  /* compare order of two cpu classes for ascending sort */
> >  gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
> > @@ -670,3 +671,39 @@ uint64_t *s390_current_fac_list_mask(void)
> >  return s390_fac_list_mask_by_machine(mc->name);
> >  }
> >  #endif
> > +
> > +/**
> > + * s390_cpu_model_init:
> > + * @cc: S390 CPU class
> > + *
> > + * This function intitializes the current accelerator with processor
> > + * related properties.
> > + *
> > + * Since: 2.4
> > + */
> > +void s390_cpu_model_init(S390CPUClass *cc)
> > +{
> > +S390ProcessorProps proc;
> > +
> > +/* none cpu model case */
> > +if (!strcmp(object_class_get_name(OBJECT_CLASS(cc)), TYPE_S390_CPU)) {
> > +return;
> > +}
> 
> Instead of checking the class name, can't you just check a S390CPUClass
> field that may indicate that s390_cpu_model_init() doesn't need to do
> anything for the class? Maybe (cpuid(cc->proc) == 0)?

That will work as well but excludes cpuid 0 from being a valid cpu id.

> 
> 
> > +
> > +/* accelerator already prepared */
> > +if (cpu_models_used) {
> > +return;
> > +}
> 
> I'm still trying to understand the need for this global. But I will ask
> for more details in the following patches that actually use
> s390_cpu_models_used()?

I'm currently using the variable to avoid multiple calls to 
kvm_s390_set_processor_props() as it
sets the processor properties for all vcpus. I will not hurt to call it twice 
or more often, it
is just not required and just consumes cpu cycles.

> 
> > +
> > +proc.cpuid = cpuid(cc->proc);
> > +proc.ibc = cc->proc.ibc;
> > +bitmap_zero(proc.fac_list, FAC_LIST_ARCH_S390_SIZE_UINT1);
> > +bitmap_copy(proc.fac_list, cc->fac_list[ACCEL_CURRENT],
> > +FAC_LIST_CPU_S390_SIZE_UINT1);
> > +
> > +if (kvm_enabled()) {
> > +if (!kvm_s390_set_processor_props(&proc)) {
> > +cpu_models_used = true;
> > +}
> > +}
> > +}
> > diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
> > index 9562088..fe3997f 100644
> > --- a/target-s390x/cpu-models.h
> > +++ b/target-s390x/cpu-models.h
> > @@ -45,6 +45,9 @@
> >  #define type_cpuid(x) ((uint64_t)((x) & 0x) << 16)
> >  #define id_cpuid(x)   ((uint64_t)((x) & 0xff) << 32)
> >  #define ver_cpuid(x)  ((uint64_t)((x) & 0xff) << 56)
> > +#define cpuid(x)  (ver_cpuid(x.ver) |  \
> > +   id_cpuid(x.id) |\
> > +   type_cpuid(x.type))
> >  
> >  #define oldest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff)
> >  #define newest_ibc(x) ((uint32_t)(x) & 0xfff)
> > @@ -108,6 +111,7 @@ void s390_cpu_list_entry(gpointer data, gpointer 
> > user_data);
> >  bool s390_cpu_classes_initialized(void);
> >  uint64_t *s390_fac_list_mask_by_machine(const char *name);
> >  uint64_t *s390_current_fac_list_mask(void);
> > +void s390_cpu_model_init(S390CPUClass *cc);
> >  
> >  extern uint64_t qemu_s390_fac_list_mask[];
> >  
> > diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
> > index c33f05e..829945d 100644
> > --- a/target-s390x/cpu.c
> > +++ b/target-s390x/cpu.c
> > @@ -180,6 +180,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error 
> > **errp)
> >  CPUState *cs = CPU(dev);
> >  S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
> >  
> > +s390_cpu_model_init(scc);
> >  s390_cpu_gdb_init(cs);
> >  qemu_init_vcpu(cs);
> >  #if !defined(CONFIG_USER_ONLY)
> > -- 
> > 1.8.3.1
> > 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-03-31 Thread Michael Mueller
On Mon, 30 Mar 2015 16:50:20 -0300
Eduardo Habkost  wrote:

Hello Eduardo,

> On Mon, Mar 30, 2015 at 04:28:24PM +0200, Michael Mueller wrote:
> [...]
> > diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
> > index 829945d..1698b52 100644
> > --- a/target-s390x/cpu.c
> > +++ b/target-s390x/cpu.c
> > @@ -37,6 +37,11 @@
> >  #define CR0_RESET   0xE0UL
> >  #define CR14_RESET  0xC200UL;
> >  
> > +static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
> > +{
> > +return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
> > +}
> > +
> >  /* generate CPU information for cpu -? */
> >  void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
> >  {
> > @@ -74,6 +79,30 @@ CpuDefinitionInfoList *arch_query_cpu_definitions(Error 
> > **errp)
> >  
> >  return entry;
> >  }
> > +
> > +CpuModelInfo *arch_query_cpu_model(Error **errp)
> > +{
> > +CpuModelInfo *info;
> > +S390CPUClass *cc;
> > +
> > +if (!s390_cpu_models_used()) {
> > +return NULL;
> > +}
> 
> First question is: why you don't want to just return
>   { name: "none", accel: ...  }
> when TYPE_S390_CPU ("-cpu none") is used?

That's a good idea, indeed! CPU model "none" is used as well in case option 
-cpu is omitted.

> 
> Now, assuming that you really want to return NULL if -cpu none is used,
> why don't you just ask for the first CPU (like you already do below) and
> check if it is a named CPU model, instead of adding a new global? e.g.:
> 
> static bool s390_cpu_class_is_model(S390CPUClass *cc)
> {
> return cpuid(cc->proc) != 0;
> }
> 
> CpuModelInfo *arch_query_cpu_model(Error **errp)
> {
> S390CPUClass *cc;
> S390CPUClass *cc;
> 
> cc = S390_CPU_GET_CLASS(s390_cpu_addr2state(0));
> if (!s390_cpu_class_is_model(cc)) {
> return NULL;
> }
> [...]
> }
> 
> 
> > +info = g_try_new0(CpuModelInfo, 1);
> > +if (!info) {
> > +return NULL;
> > +}
> > +cc = S390_CPU_GET_CLASS(s390_cpu_addr2state(0));
> > +info->name = strdup_s390_cpu_name(cc);
> 
> I don't think the current version of strdup_s390_cpu_name() can ever
> return NULL. Do you expect it to return NULL in the future?

No I do not expect this. I will drop the NULL test.

> 
> > +if (!info->name) {
> > +g_free(info);
> > +return NULL;
> > +}
> > +if (kvm_enabled()) {
> > +info->accel = ACCEL_ID_KVM;
> 
> This could be a CPUState field, added automatically by
> cpu_generic_init() using current_machine->accel.

I will add a CPUState field and see how it works out...

> 
> > +}
> > +return info;
> > +}
> >  #endif
> >  
> >  static void s390_cpu_set_pc(CPUState *cs, vaddr value)
> > -- 
> > 1.8.3.1
> > 
> 

Thanks a lot,
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-03-31 Thread Michael Mueller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Mon, 30 Mar 2015 14:19:27 -0600
Eric Blake  wrote:

> On 03/30/2015 08:28 AM, Michael Mueller wrote:
> > This patch implements a new QMP request named 'query-cpu-model'.
> > It returns the cpu model of cpu 0 and its backing accelerator.
> > 
> > request:
> >   {"execute" : "query-cpu-model" }
> > 
> > answer:
> >   {"return" : {"name": "2827-ga2", "accel": "kvm" }}
> > 
> > Alias names are resolved to their respective machine type and GA names
> > already during cpu instantiation. Thus, also a cpu model like 'host'
> > which is implemented as alias will return its normalized cpu model name.
> > 
> > Furthermore the patch implements the following function:
> > 
> > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> 
> > +++ b/qapi-schema.json
> > @@ -2516,6 +2516,16 @@
> >  { 'command': 'query-machines', 'returns': ['MachineInfo'] }
> >  
> >  ##
> > +# @AccelId
> > +#
> > +# Defines accelerator ids
> > +#
> > +# Since: 2.4
> > +##
> > +{ 'enum': 'AccelId',
> > +  'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
> 
> Unusual spacing (0 spaces after '[' but 2 spaces before closing ']'?),
> but not necessarily wrong.
> 
> 
> > +##
> > +# @CpuModelInfo:
> > +#
> > +# Virtual CPU model definition.
> > +#
> > +# @name: the name of the CPU model definition
> > +#
> > +# @accel: AccelId (name) of this cpu models accelerator
> 
> s/models/model's/
> 
> 

Will fix both findings...

Thanks,
Michael
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJVGlM7AAoJELPcPLQSJsKQV1IP/07cv8CB1ggyWFq7pCjo/x4G
A6sjzPziW9sZdrcaMsDb2Px62ddyx+4KymnzzdjKTrKGePZGOBQNd0xwCeIDanw9
Z+hVBG8vzqPiwBM25xKUMYl+NDC7SPeqv6YSFelEBAcbsZGtNb9CBqycjbc8AWtj
Qy8PiLlbPQLxUiFIvnTYe3umW60CtnfUoAiRXs3wQyBkWsUZ7HI7/Rsm8wRIq0tE
HX52/xuD79rQvgqeJi+2zxHyB+WGv0GrvOzIB22d93peMOrdXyQj9GYM6R4Fj7pT
XASifUzztLYlUqNh6MRYmrUaLbsV12ERUKitcd1Cw7l8T7tpIh/NpaOhrm8VosVh
P1Wm9UWha1MfF/rW/u/3sW/82Pv+eQ54a9XYd4H4tD3PFMMmIbZK/9D69BpyxtSZ
45fe4jiKO87bryMtaYPH9oAc8VOmOR9EI94p4q/GK8swaYQ5DGNAPiFlWlfmgg4B
VGXmiHE0VeJOH5dh5+wT/5gjZu3ZmUQNtqhT09rfG0jvMZVUFT0qr5vXQtYXW4Gj
DbK3uir15ovHYBErfun11vs15tUoy4PT3OMsmgelgQl1FQG8T7FD9asj72m3vLUh
UVvRj1KduWET4b4W5SBgzLlMdRyTAcXRPKuDCcSCtqfxE4+jsAp3+mYbLpB2y5Aw
Qjklt025kmr0A7pNrL4d
=ZBtF
-END PGP SIGNATURE-
N‹§²æìr¸›yúèšØb²X¬¶Ç§vØ^–)Þº{.nÇ+‰·¤¾h§¶›¡Ü¨}©ž²Æ 
zÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ߢf

Re: [Qemu-devel] [PATCH v4 12/15] Add optional parameters to QMP command query-cpu-definitions

2015-03-31 Thread Michael Mueller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Mon, 30 Mar 2015 14:28:01 -0600
Eric Blake  wrote:

> On 03/30/2015 08:28 AM, Michael Mueller wrote:
> > The patch adds optional parameters to the QMP command query-cpu-definitions.
> > Thus the signature of routine arch_query_cpu_definitions needs to be changed
> > for the stub function and all target implementations:
> > 
> > target-arm
> > target-i386
> > target-ppc
> > target-s390
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> 
> > +++ b/qapi-schema.json
> > @@ -2532,21 +2532,31 @@
> >  #
> >  # @name: the name of the CPU definition
> >  #
> > +# @default: #optional defines if cpu model is the default (since 2.4)
> 
> Reads poorly.  How about:
> 
> # @default: #optional true if cpu model is the default, omitted if false
> (since 2.4)

Yep, will change

> 
> 
> > +#
> > +# @runnable: #optional defines if cpu model is runnable (since 2.4)
> 
> Similarly:
> 
> # @runnable: #optional true if cpu model is runnable, omitted if false
> (since 2.4)

here as well

> 
> > +#
> >  # Since: 1.2.0
> >  ##
> >  { 'type': 'CpuDefinitionInfo',
> > -  'data': { 'name': 'str' } }
> > +  'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool' } }
> >  
> >  ##
> >  # @query-cpu-definitions:
> >  #
> >  # Return a list of supported virtual CPU definitions
> >  #
> > +# @machine: #optional machine type (since 2.4)
> > +#
> > +# @accel: #optional accelerator id (since 2.4)
> 
> Maybe mention that these two fields are for filtering results.

I will add a comment as it is more than filtering, it is execution context 
information that allows
to determine if a cpu model is runnable.

Thanks a lot,
Michael

> 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJVGk/gAAoJELPcPLQSJsKQ9qcQAJiURTXS+NZO/kmKfP1aH18s
RC/bhXyV6gVmfsvZ1X7S0cH5eO4Z7AfpNNT73Mw0lYDIXei+94/Mdby4AplF7S8q
RoPVu9KxWXV6oM1nigEMvExt5n6BxIM3+/xvKt1Rkef4cx8qIRju+rCLNekmBd3E
yJtSs3Oasft8LoG+4ZPEv26jC7uvHa04bp1nZslXhgUmbUJZzRtArRohp0JA0kfl
BIzpFSKJEvGB/xwyj4bvfC4NQJ9nMtel6BhO04oxHgQNXmpaJK4vN5h7wi6PG2ac
I7mKhC/nNFPUXvQUGQ91itWH/ir1fyim4Rjhtd2Pvpq19waEg2M+dHp2YKAqg1xd
YrHpAQA/6MLqlBqrsqYzVS/LHz7juXP3u/sX5azdbZY8LPynAXqnSwqiNinvk2bA
sc3NG/JwZnbtASFrjJEpmrudS29IXuNNycISzGwrL06pwgmrFaJkpyzD6gOkJfnh
UByIMqTYskk3yP8G8K4n6775al0Zx8v39E7En+dQozEnVa/SxA5YdjJMVPOZiEt4
O/szkqCr5kcQHZJ/x42Sz0YFZ5QIidhMkX6jEqeak7q0Ow0awXgreuxXEmPYu6lG
5wHo6WP1h6tdogQnJGnyFXC5kWzp2iBYxVDP86/4aKLGyZViNPS1XDSjhd9NH4X/
9IPbCIOJYwpZF9l5GeG/
=JAwu
-END PGP SIGNATURE-


Re: [PATCH v4 07/15] target-s390x: Update linux-headers/asm-s390/kvm.h

2015-03-31 Thread Michael Mueller
On Mon, 30 Mar 2015 21:36:22 +0200
Christian Borntraeger  wrote:

> Am 30.03.2015 um 16:28 schrieb Michael Mueller:
> > Signed-off-by: Michael Mueller 
> > ---
> >  linux-headers/asm-s390/kvm.h | 18 +-
> >  1 file changed, 9 insertions(+), 9 deletions(-)
> > 
> 
> Looks like a leftover. Drop that patch and rename ibc_range to ibc in the 
> other patch.

Will drop the patch and stay with the current name used upstream already.
> 
> 
> > diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
> > index c5a93eb..bfe6925 100644
> > --- a/linux-headers/asm-s390/kvm.h
> > +++ b/linux-headers/asm-s390/kvm.h
> > @@ -70,8 +70,14 @@ struct kvm_s390_io_adapter_req {
> >  #define KVM_S390_VM_TOD_LOW0
> >  #define KVM_S390_VM_TOD_HIGH   1
> > 
> > +/* kvm attributes for crypto */
> > +#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW   0
> > +#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW   1
> > +#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW  2
> > +#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW  3
> > +
> >  /* kvm attributes for KVM_S390_VM_CPU_MODEL */
> > -/* processor related attributes are r/w */
> > +/* kvm S390 processor related attributes are r/w */
> >  #define KVM_S390_VM_CPU_PROCESSOR  0
> >  struct kvm_s390_vm_cpu_processor {
> > __u64 cpuid;
> > @@ -80,22 +86,16 @@ struct kvm_s390_vm_cpu_processor {
> > __u64 fac_list[256];
> >  };
> > 
> > -/* machine related attributes are r/o */
> > +/* kvm S390 machine related attributes are r/o */
> >  #define KVM_S390_VM_CPU_MACHINE1
> >  struct kvm_s390_vm_cpu_machine {
> > __u64 cpuid;
> > -   __u32 ibc;
> > +   __u32 ibc_range;
> > __u8  pad[4];
> > __u64 fac_mask[256];
> > __u64 fac_list[256];
> >  };
> > 
> > -/* kvm attributes for crypto */
> > -#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW   0
> > -#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW   1
> > -#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW  2
> > -#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW  3
> > -
> >  /* for KVM_GET_REGS and KVM_SET_REGS */
> >  struct kvm_regs {
> > /* general purpose regs for s390 */
> > 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/15] target-s390x: Update linux-headers/asm-s390/kvm.h

2015-03-30 Thread Michael Mueller
Signed-off-by: Michael Mueller 
---
 linux-headers/asm-s390/kvm.h | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index c5a93eb..bfe6925 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -70,8 +70,14 @@ struct kvm_s390_io_adapter_req {
 #define KVM_S390_VM_TOD_LOW0
 #define KVM_S390_VM_TOD_HIGH   1
 
+/* kvm attributes for crypto */
+#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW   0
+#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW   1
+#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW  2
+#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW  3
+
 /* kvm attributes for KVM_S390_VM_CPU_MODEL */
-/* processor related attributes are r/w */
+/* kvm S390 processor related attributes are r/w */
 #define KVM_S390_VM_CPU_PROCESSOR  0
 struct kvm_s390_vm_cpu_processor {
__u64 cpuid;
@@ -80,22 +86,16 @@ struct kvm_s390_vm_cpu_processor {
__u64 fac_list[256];
 };
 
-/* machine related attributes are r/o */
+/* kvm S390 machine related attributes are r/o */
 #define KVM_S390_VM_CPU_MACHINE1
 struct kvm_s390_vm_cpu_machine {
__u64 cpuid;
-   __u32 ibc;
+   __u32 ibc_range;
__u8  pad[4];
__u64 fac_mask[256];
__u64 fac_list[256];
 };
 
-/* kvm attributes for crypto */
-#define KVM_S390_VM_CRYPTO_ENABLE_AES_KW   0
-#define KVM_S390_VM_CRYPTO_ENABLE_DEA_KW   1
-#define KVM_S390_VM_CRYPTO_DISABLE_AES_KW  2
-#define KVM_S390_VM_CRYPTO_DISABLE_DEA_KW  3
-
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
/* general purpose regs for s390 */
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 05/15] target-s390x: Define cpu model specific facility lists

2015-03-30 Thread Michael Mueller
This patch defines S390 cpu facilities and their presence at the
different cpu model levels. Beside defining a base which facilities
have to be requested per cpu model, these sets are associated to the
defined cpu classes and used to calculate the list of supported
cpu models in context of the current hosting machine model.

The also defined qemu side facility mask allows to implement and enable
facilities in QEMU land.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 12 
 target-s390x/cpu-models.h |  8 
 target-s390x/cpu.c|  1 +
 3 files changed, 21 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 908e8eb..028e3de 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -12,6 +12,7 @@
 
 #include "qemu-common.h"
 #include "cpu-models.h"
+#include "gen-facilities.h"
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -20,6 +21,10 @@
 {   \
 DeviceClass *dc = DEVICE_CLASS(oc); \
 S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+uint64_t nbits = FAC_LIST_CPU_S390_SIZE_UINT1;  \
+uint64_t fac_list[FAC_LIST_CPU_S390_SIZE_UINT64] = {\
+glue(FAC_LIST_, _cpu_id)\
+};  \
 \
 cc->mach.ga= cpu_ga(_cpu_id);   \
 cc->mach.class = cpu_class(_cpu_id);\
@@ -29,6 +34,7 @@
 cc->proc.id= S390_DEF_ID;   \
 cc->proc.type  = cpu_type(_cpu_id); \
 cc->proc.ibc   = S390_DEF_IBC;  \
+bitmap_copy(cc->proc.fac_list, fac_list, nbits);\
 dc->desc   = _desc; \
 }   \
 static const TypeInfo   \
@@ -45,6 +51,11 @@
 }   \
 type_init(glue(_cpu_id, _cpu_register_types))
 
+/* facilities implemented by qemu */
+uint64_t qemu_s390_fac_list_mask[FAC_LIST_CPU_S390_SIZE_UINT64] = {
+FAC_LIST_CPU_S390_MASK_QEMU
+};
+
 /* define S390 CPU model classes */
 S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
 S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
@@ -75,3 +86,4 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM zEnterprise 
EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index b02c38b..948af10 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -13,6 +13,14 @@
 #ifndef TARGET_S390X_CPU_MODELS_H
 #define TARGET_S390X_CPU_MODELS_H
 
+#include "cpu-facilities.h"
+#include "gen-facilities.h"
+
+#define FAC_LIST_ARCH_S390_SIZE_UINT1 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 * BITS_PER_BYTE)
+#define FAC_LIST_ARCH_S390_SIZE_UINT64 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 / sizeof(uint64_t))
+
 #define S390_EC 0x1
 #define S390_BC 0x2
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index e0537fa..0db62c2 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "hw/hw.h"
 #include "trace.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 02/15] target-s390x: Introduce cpu facilities

2015-03-30 Thread Michael Mueller
The patch introduces S390 CPU facility bit numbers and names
as well as the architectural facility size limit in bytes.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-facilities.h | 86 +++
 1 file changed, 86 insertions(+)
 create mode 100644 target-s390x/cpu-facilities.h

diff --git a/target-s390x/cpu-facilities.h b/target-s390x/cpu-facilities.h
new file mode 100644
index 000..db1f064
--- /dev/null
+++ b/target-s390x/cpu-facilities.h
@@ -0,0 +1,86 @@
+/*
+ * CPU facilities for s390
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * 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_FACILITIES_H
+#define TARGET_S390X_CPU_FACILITIES_H
+
+/* architectural size of facilities is 2KB */
+#define FAC_LIST_ARCH_S390_SIZE_UINT8 (1<<11)
+
+/* CPU facility bits */
+typedef enum {
+FAC_N3  = 0,
+FAC_ZARCH   = 1,
+FAC_ZARCH_ACTIVE= 2,
+FAC_DAT_ENH = 3,
+FAC_ASN_LX_REUSE= 6,
+FAC_STFLE   = 7,
+FAC_ENHANCED_DAT_1  = 8,
+FAC_SENSE_RUNNING_STATUS= 9,
+FAC_CONDITIONAL_SSKE= 10,
+FAC_CONFIGURATION_TOPOLOGY  = 11,
+FAC_IPTE_RANGE  = 13,
+FAC_NONQ_KEY_SETTING= 14,
+FAC_EXTENDED_TRANSLATION_2  = 16,
+FAC_MESSAGE_SECURITY_ASSIST = 17,
+FAC_LONG_DISPLACEMENT   = 18,
+FAC_LONG_DISPLACEMENT_FAST  = 19,
+FAC_HFP_MADDSUB = 20,
+FAC_EXTENDED_IMMEDIATE  = 21,
+FAC_EXTENDED_TRANSLATION_3  = 22,
+FAC_HFP_UNNORMALIZED_EXT= 23,
+FAC_ETF2_ENH= 24,
+FAC_STORE_CLOCK_FAST= 25,
+FAC_PARSING_ENH = 26,
+FAC_MOVE_WITH_OPTIONAL_SPEC = 27,
+FAC_TOD_CLOCK_STEERING  = 28,
+FAC_ETF3_ENH= 30,
+FAC_EXTRACT_CPU_TIME= 31,
+FAC_COMPARE_AND_SWAP_AND_STORE  = 32,
+FAC_COMPARE_AND_SWAP_AND_STORE_2= 33,
+FAC_GENERAL_INSTRUCTIONS_EXT= 34,
+FAC_EXECUTE_EXT = 35,
+FAC_ENHANCED_MONITOR= 36,
+FAC_FLOATING_POINT_EXT  = 37,
+FAC_LOAD_PROGRAM_PARAMETERS = 40,
+FAC_FLOATING_POINT_SUPPPORT_ENH = 41,
+FAC_DFP = 42,
+FAC_DFP_FAST= 43,
+FAC_PFPO= 44,
+FAC_MULTI_45= 45,
+FAC_CMPSC_ENH   = 47,
+FAC_DFP_ZONED_CONVERSION= 48,
+FAC_MULTI_49= 49,
+FAC_CONSTRAINT_TRANSACTIONAL_EXE= 50,
+FAC_LOCAL_TLB_CLEARING  = 51,
+FAC_INTERLOCKED_ACCESS_2= 52,
+FAC_LOAD_STORE_ON_COND_2= 53,
+FAC_MESSAGE_SECURITY_ASSIST_5   = 57,
+FAC_RESET_REFERENCE_BITS_MULTIPLE   = 66,
+FAC_CPU_MEASUREMENT_COUNTER = 67,
+FAC_CPU_MEASUREMENT_SAMPLING= 68,
+FAC_TRANSACTIONAL_EXE   = 73,
+/*
+ * The store-hypervisor-information facility #74 is
+ * z/VM related and when added to be handled by QEMU
+ * when hosted on LPAR. (see: SC24-6179-05 page 953)
+ */
+FAC_ACCESS_EXCEPTION_FS_INDICATION  = 75,
+FAC_MESSAGE_SECURITY_ASSIST_3   = 76,
+FAC_MESSAGE_SECURITY_ASSIST_4   = 77,
+FAC_ENHANCED_DAT_2  = 78,
+FAC_DFP_PACKED_CONVERSION   = 80,
+FAC_VECTOR  = 129,
+FAC_STORE_CPU_COUNTER_MULTI = 142,
+} S390Facility;
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 04/15] target-s390x: Introduce cpu models

2015-03-30 Thread Michael Mueller
This patch implements the static part of the s390 cpu class definitions.
It defines s390 cpu models by means of virtual cpu ids (enum) which contain
information on the cpu generation, the machine class, the GA number and
the machine type. The cpu id is used to instantiate a cpu class per cpu
model.

Furthermore it extends the existing S390CPUClass by model related properties.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 target-s390x/Makefile.objs |  1 +
 target-s390x/cpu-models.c  | 77 ++
 target-s390x/cpu-models.h  | 72 +++
 target-s390x/cpu-qom.h | 36 ++
 4 files changed, 186 insertions(+)
 create mode 100644 target-s390x/cpu-models.c
 create mode 100644 target-s390x/cpu-models.h

diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 997dda4..97c4177 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,6 +1,7 @@
 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 += cpu-models.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
 
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
new file mode 100644
index 000..908e8eb
--- /dev/null
+++ b/target-s390x/cpu-models.c
@@ -0,0 +1,77 @@
+/*
+ * CPU models for s390
+ *
+ * Copyright 2014,2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu-common.h"
+#include "cpu-models.h"
+
+#define S390_PROC_DEF(_name, _cpu_id, _desc)\
+static void \
+glue(_cpu_id, _cpu_class_init)  \
+(ObjectClass *oc, void *data)   \
+{   \
+DeviceClass *dc = DEVICE_CLASS(oc); \
+S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+\
+cc->mach.ga= cpu_ga(_cpu_id);   \
+cc->mach.class = cpu_class(_cpu_id);\
+cc->mach.order = cpu_order(_cpu_id);\
+cc->proc.gen   = cpu_generation(_cpu_id);   \
+cc->proc.ver   = S390_DEF_VERSION;  \
+cc->proc.id= S390_DEF_ID;   \
+cc->proc.type  = cpu_type(_cpu_id); \
+cc->proc.ibc   = S390_DEF_IBC;  \
+dc->desc   = _desc; \
+}   \
+static const TypeInfo   \
+glue(_cpu_id, _cpu_type_info) = {   \
+.name   = _name "-" TYPE_S390_CPU,  \
+.parent = TYPE_S390_CPU,\
+.class_init = glue(_cpu_id, _cpu_class_init),   \
+};  \
+static void \
+glue(_cpu_id, _cpu_register_types)(void)\
+{   \
+type_register_static(   \
+&glue(_cpu_id, _cpu_type_info));\
+}   \
+type_init(glue(_cpu_id, _cpu_register_types))
+
+/* define S390 CPU model classes */
+S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
+S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
+S390_PROC_DEF("2064-ga3", CPU_S390_2064_GA3, "IBM zSeries 900 GA3")
+S390_PROC_DEF("2066-ga1", CPU_S390_2066_GA1, "IBM zSeries 800 GA1")
+S390_PROC_DEF("2084-ga1", CPU_S390_2084_GA1, "IBM zSeries 990 GA1")
+S390_PROC_DEF("2084-ga2", CPU_S390_2084_GA2, "IBM zSeries 990 GA2")
+S390_PROC_DEF("2084-ga3", CPU_S390_2084_GA3, "IBM zSeries 990 GA3")
+S390_PROC_DEF("2084-ga4", CPU_S390_2084_GA4, "IBM zSeries 990 GA4")
+S390_PROC_DEF("2084-ga5", CPU_S390_2084_GA5, "IBM zSeries 990 GA5")
+S390_PROC_DEF("20

[PATCH v4 08/15] target-s390x: Add KVM VM attribute interface for cpu models

2015-03-30 Thread Michael Mueller
The patch implements routines to set and retrieve processor configuration
data and to retrieve machine configuration data. The machine related data
is used together with the cpu model facility lists to determine the list of
supported cpu models of this host. The above mentioned routines have QEMU
trace point instrumentation.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.h | 34 
 target-s390x/kvm.c| 79 +++
 trace-events  |  3 ++
 3 files changed, 116 insertions(+)

diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 562464f..3b75236 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -46,6 +46,40 @@ typedef struct S390CPUAlias {
 char *model;
 } S390CPUAlias;
 
+typedef struct S390ProcessorProps {
+uint64_t cpuid;
+uint16_t ibc;
+uint8_t  pad[6];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390ProcessorProps;
+
+typedef struct S390MachineProps {
+uint64_t cpuid;
+uint32_t ibc_range;
+uint8_t  pad[4];
+uint64_t fac_list_mask[FAC_LIST_ARCH_S390_SIZE_UINT64];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390MachineProps;
+
+#ifdef CONFIG_KVM
+int kvm_s390_get_processor_props(S390ProcessorProps *prop);
+int kvm_s390_set_processor_props(S390ProcessorProps *prop);
+bool kvm_s390_cpu_classes_initialized(void);
+#else
+static inline int kvm_s390_get_processor_props(S390ProcessorProps *prop)
+{
+return -ENOSYS;
+}
+static inline int kvm_s390_set_processor_props(S390ProcessorProps *prop)
+{
+return -ENOSYS;
+}
+static inline bool kvm_s390_cpu_classes_initialized(void)
+{
+return false;
+}
+#endif
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index b48c643..bde4aaa 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -44,6 +44,7 @@
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "cpu-models.h"
 
 /* #define DEBUG_KVM */
 
@@ -122,6 +123,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 
 static int cap_sync_regs;
 static int cap_async_pf;
+static bool cpu_classes_initialized;
 
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
@@ -242,6 +244,59 @@ static void kvm_s390_init_crypto(void)
 kvm_s390_init_dea_kw();
 }
 
+static int cpu_model_get(KVMState *s, uint64_t attr, uint64_t addr)
+{
+int rc = -ENOSYS;
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
+rc = kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &dev_attr);
+}
+
+return rc;
+}
+
+static int cpu_model_set(KVMState *s, uint64_t attr, uint64_t addr)
+{
+int rc = -ENOSYS;
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+if (kvm_vm_check_attr(s, dev_attr.group, dev_attr.attr)) {
+rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &dev_attr);
+}
+
+return rc;
+}
+
+static int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
+{
+int rc = -EFAULT;
+
+if (s) {
+rc = cpu_model_get(s, KVM_S390_VM_CPU_MACHINE, (uint64_t) prop);
+}
+trace_kvm_get_machine_props(rc, prop->cpuid, prop->ibc_range);
+
+return rc;
+}
+
+static void kvm_setup_cpu_classes(KVMState *s)
+{
+S390MachineProps mach;
+
+if (!kvm_s390_get_machine_props(s, &mach)) {
+cpu_classes_initialized = false;
+}
+}
+
 int kvm_arch_init(MachineState *ms, KVMState *s)
 {
 cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
@@ -255,6 +310,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
 }
 
 kvm_vm_enable_cap(s, KVM_CAP_S390_USER_SIGP, 0);
+kvm_setup_cpu_classes(s);
 
 return 0;
 }
@@ -1940,3 +1996,26 @@ int kvm_arch_fixup_msi_route(struct 
kvm_irq_routing_entry *route,
 route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id;
 return 0;
 }
+
+int kvm_s390_get_processor_props(S390ProcessorProps *prop)
+{
+int rc;
+
+rc = cpu_model_get(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop);
+trace_kvm_get_processor_props(rc, prop->cpuid, prop->ibc);
+return rc;
+}
+
+int kvm_s390_set_processor_props(S390ProcessorProps *prop)
+{
+int rc;
+
+rc = cpu_model_set(kvm_state, KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop);
+trace_kvm_set_processor_props(rc);
+return rc;
+}
+
+bool kvm_s390_cpu_classes_initialized(void)
+{
+return cpu_classes_initialized;
+}
diff --git a/trace-events b/trace-events
index 30eba92..2f1d734 100644
--- a/trace-events
+++ b/trace-events
@@ -1582,6 +1582,9 @@ kvm_enable_cmma(int rc) "CMMA: enabling with result code 
%d"
 kvm_c

[PATCH v4 10/15] target-s390x: Prepare accelerator during cpu object realization

2015-03-30 Thread Michael Mueller
This patch implements routine s390_cpu_model_init(). It is called by the
realize function during instantiation of an cpu object. Its task is to
initialize the current accelerator with the properties of the selected
processor model.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 37 +
 target-s390x/cpu-models.h |  4 
 target-s390x/cpu.c|  1 +
 3 files changed, 42 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 8a877d3..ba873ea 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -111,6 +111,7 @@ typedef struct ParmAddrAddrModeMask {
 } ParmAddrAddrModeMask;
 
 static GSList *s390_cpu_aliases;
+static bool cpu_models_used;
 
 /* compare order of two cpu classes for ascending sort */
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
@@ -670,3 +671,39 @@ uint64_t *s390_current_fac_list_mask(void)
 return s390_fac_list_mask_by_machine(mc->name);
 }
 #endif
+
+/**
+ * s390_cpu_model_init:
+ * @cc: S390 CPU class
+ *
+ * This function intitializes the current accelerator with processor
+ * related properties.
+ *
+ * Since: 2.4
+ */
+void s390_cpu_model_init(S390CPUClass *cc)
+{
+S390ProcessorProps proc;
+
+/* none cpu model case */
+if (!strcmp(object_class_get_name(OBJECT_CLASS(cc)), TYPE_S390_CPU)) {
+return;
+}
+
+/* accelerator already prepared */
+if (cpu_models_used) {
+return;
+}
+
+proc.cpuid = cpuid(cc->proc);
+proc.ibc = cc->proc.ibc;
+bitmap_zero(proc.fac_list, FAC_LIST_ARCH_S390_SIZE_UINT1);
+bitmap_copy(proc.fac_list, cc->fac_list[ACCEL_CURRENT],
+FAC_LIST_CPU_S390_SIZE_UINT1);
+
+if (kvm_enabled()) {
+if (!kvm_s390_set_processor_props(&proc)) {
+cpu_models_used = true;
+}
+}
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 9562088..fe3997f 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -45,6 +45,9 @@
 #define type_cpuid(x) ((uint64_t)((x) & 0x) << 16)
 #define id_cpuid(x)   ((uint64_t)((x) & 0xff) << 32)
 #define ver_cpuid(x)  ((uint64_t)((x) & 0xff) << 56)
+#define cpuid(x)  (ver_cpuid(x.ver) |  \
+   id_cpuid(x.id) |\
+   type_cpuid(x.type))
 
 #define oldest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff)
 #define newest_ibc(x) ((uint32_t)(x) & 0xfff)
@@ -108,6 +111,7 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 uint64_t *s390_fac_list_mask_by_machine(const char *name);
 uint64_t *s390_current_fac_list_mask(void);
+void s390_cpu_model_init(S390CPUClass *cc);
 
 extern uint64_t qemu_s390_fac_list_mask[];
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index c33f05e..829945d 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -180,6 +180,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error 
**errp)
 CPUState *cs = CPU(dev);
 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
 
+s390_cpu_model_init(scc);
 s390_cpu_gdb_init(cs);
 qemu_init_vcpu(cs);
 #if !defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 14/15] target-s390x: Introduce facility test routine

2015-03-30 Thread Michael Mueller
The patch introduces routine s390_facility_test() which allows to
verify a specific facility bit is set.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 29 +
 target-s390x/cpu-models.h |  1 +
 2 files changed, 30 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index aba44dd..a9f7372 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -736,3 +736,32 @@ bool s390_cpu_models_used(void)
 {
 return cpu_models_used;
 }
+
+static inline int test_facility(uint64_t *fac_list, uint16_t nr)
+{
+uint16_t word = nr / BITS_PER_LONG;
+uint16_t be_bit = (BITS_PER_LONG - 1) - (nr % BITS_PER_LONG);
+
+return (nr < FAC_LIST_CPU_S390_SIZE_UINT1) ?
+(fac_list[word] >> be_bit) & __UINT64_C(1) : 0;
+}
+
+/**
+ * s390_test_facility:
+ * @nr: facility bit number to test
+ * @cc: cpu class to test
+ *
+ * The functions tests if the cpu facility identified by bit @nr is available
+ * to the cpu class @cc.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.4
+ */
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr)
+{
+if (!cc) {
+return false;
+}
+return test_facility(cc->fac_list[ACCEL_CURRENT], nr) ? true : false;
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 4734c58..eb0476f 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -120,6 +120,7 @@ uint64_t *s390_fac_list_mask_by_machine(const char *name);
 uint64_t *s390_current_fac_list_mask(void);
 void s390_cpu_model_init(S390CPUClass *cc);
 bool s390_cpu_models_used(void);
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr);
 
 extern uint64_t qemu_s390_fac_list_mask[];
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 09/15] target-s390x: Add cpu class initialization routines

2015-03-30 Thread Michael Mueller
This patch provides routines to dynamically update the previously defined
S390 cpu classes in the current host context. The main function performing
this process is s390_setup_cpu_classes(). It takes the current host context
and a facility list mask as parameter to setup the classes accordingly. It
basically performs the following sub-tasks:

- Update of cpu classes with accelerator specific host and QEMU properties
- Mark adequate cpu class as default cpu class to be used for cpu model 'host'
- Invalidate cpu classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common cpu model names
- Set cpu model alias 'host' to default cpu class

Forthermore the patch provides the following routines:

- cpu_desc_avail(), s390 specific stub indicating that list_cpus() can run
- s390_setup_cpu_aliases(), adds cu model aliases
- s390_cpu_classes_initialized(), test if cpu classes have been initialized
- s390_fac_list_mask_by_machine(), returns facility list mask by machine
- s390_current_fac_list_mask(), returns facility list mask of current machine

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 494 ++
 target-s390x/cpu-models.h |  31 +++
 target-s390x/cpu.c|  17 +-
 target-s390x/kvm.c|   5 +-
 4 files changed, 545 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index f792066..8a877d3 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -13,6 +13,11 @@
 #include "qemu-common.h"
 #include "cpu-models.h"
 #include "gen-facilities.h"
+#include "qemu/error-report.h"
+#ifndef CONFIG_USER_ONLY
+#include "exec/cpu-common.h"
+#include "hw/boards.h"
+#endif
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -87,8 +92,41 @@ S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM 
zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
 
+/* some types for calls to g_list_foreach() with parameters */
+typedef struct ParmBoolShortShort {
+bool valid;
+unsigned short type;
+union {
+unsigned short class;
+unsigned short gen;
+unsigned short ga;
+};
+} ParmBoolShortShort;
+
+typedef struct ParmAddrAddrModeMask {
+S390MachineProps *prop;
+S390CPUClass *host_cc;
+S390AccelMode mode;
+uint64_t *mask;
+} ParmAddrAddrModeMask;
+
 static GSList *s390_cpu_aliases;
 
+/* compare order of two cpu classes for ascending sort */
+gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return -1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return 1;
+}
+return 0;
+}
+
 static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
 {
 const char *aname = object_class_get_name((ObjectClass *) a);
@@ -176,3 +214,459 @@ int set_s390_cpu_alias(const char *name, const char 
*model)
 return 0;
 }
 
+/* return machine class for specific machine type */
+static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShort *parm = user_data;
+
+if (parm->valid || !cc->proc.type || parm->type != cc->proc.type) {
+return;
+}
+
+parm->class = cc->mach.class;
+parm->valid = true;
+}
+
+/* return machine class by machine type */
+static unsigned short machine_class(unsigned short type, void *user_data)
+{
+GSList *list = object_class_get_list(TYPE_S390_CPU, false);
+ParmBoolShortShort parm_class, *parm = user_data;
+
+if (parm->type != type) {
+parm->class = 0;
+}
+if (!parm->class) {
+parm_class.type = type;
+parm_class.class = 0;
+parm_class.valid = false;
+g_slist_foreach(list, (GFunc) s390_machine_class_test_cpu_class,
+&parm_class);
+g_slist_free(list);
+if (parm_class.valid) {
+parm->class = parm_class.class;
+}
+}
+parm->type = type;
+
+return parm->class;
+}
+
+/* return CMOS generation for specific machine type */
+static void s390_machine_class_test_cpu_gen(gpointer data, gpointer user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShort *parm = user_data;
+
+if (parm->valid) {
+return;
+}
+
+if (parm->type

[PATCH v4 06/15] target-s390x: Add cpu model alias definition routines

2015-03-30 Thread Michael Mueller
This patch implements the infrastructure to dynamically add cpu
model aliases.

Signed-off-by: Michael Mueller 
Reviewed-by: Cornelia Huck 
---
 target-s390x/cpu-models.c | 89 +++
 target-s390x/cpu-models.h | 11 ++
 target-s390x/cpu.c|  1 +
 3 files changed, 101 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 028e3de..f792066 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -87,3 +87,92 @@ S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM 
zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 S390_PROC_DEF("2964-ga1", CPU_S390_2964_GA1, "IBM z13 GA1")
 
+static GSList *s390_cpu_aliases;
+
+static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
+{
+const char *aname = object_class_get_name((ObjectClass *) a);
+const char *bname = b;
+int blen;
+
+if (!strcmp(bname, "none") &&
+!strcmp(aname, TYPE_S390_CPU)) {
+return 0;
+}
+blen = strlen(bname);
+if (!strncasecmp(bname, aname, blen) &&
+!strcmp(aname + blen, "-" TYPE_S390_CPU)) {
+return 0;
+}
+return -1;
+}
+
+/**
+ * s390_cpu_class_by_name:
+ * @name: a cpu model or alias name
+ *
+ * The function searches for the requested cpu model name or an alias
+ * cpu model name and returns the associated object class.
+ *
+ * Returns: reference to object class on success or %NULL elsewise.
+ *
+ * Since: 2.4
+ */
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+GSList *list, *item;
+ObjectClass *ret = NULL;
+S390CPUAlias *alias;
+
+for (item = s390_cpu_aliases; item != NULL; item = item->next) {
+alias = (S390CPUAlias *) item->data;
+if (strcmp(alias->name, name) == 0) {
+return s390_cpu_class_by_name(alias->model);
+}
+}
+list = object_class_get_list(TYPE_S390_CPU, false);
+item = g_slist_find_custom(list, name, s390_cpu_compare_class_name);
+if (item) {
+ret = OBJECT_CLASS(item->data);
+}
+g_slist_free(list);
+return ret;
+}
+
+/**
+ * set_s390_cpu_alias:
+ * @name: the cpu alias name
+ * @model: the cpu model name
+ *
+ * The function registers the alias @name for an existing cpu @model.
+ *
+ * Returns: %0 in case of success
+ *  -%EINVAL if name or model is %NULL or both are idential
+ *   or model is not a valid cpu model
+ *  -%ENOMEM if internal memory allocation fails
+ *
+ * Since: 2.4
+ */
+int set_s390_cpu_alias(const char *name, const char *model)
+{
+S390CPUAlias *alias;
+
+if (!name || !model) {
+return -EINVAL;
+}
+if (!strcmp(name, model)) {
+return -EINVAL;
+}
+if (!s390_cpu_class_by_name(model)) {
+return -EINVAL;
+}
+alias = g_try_malloc0(sizeof(S390CPUAlias));
+if (!alias) {
+return -ENOMEM;
+}
+alias->name = g_strdup(name);
+alias->model = g_strdup(model);
+s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+return 0;
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 948af10..562464f 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -35,6 +35,17 @@
 #define cpu_class(x)  (((x) >> 20) & 0x3)
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
+ObjectClass *s390_cpu_class_by_name(const char *name);
+int set_s390_cpu_alias(const char *name, const char *model);
+
+/*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+char *name;
+char *model;
+} S390CPUAlias;
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 0db62c2..2b78e6a 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -310,6 +310,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
 #endif
 scc->cpu_reset = s390_cpu_reset;
 scc->initial_cpu_reset = s390_cpu_initial_reset;
+cc->class_by_name = s390_cpu_class_by_name;
 cc->reset = s390_cpu_full_reset;
 cc->has_work = s390_cpu_has_work;
 cc->do_interrupt = s390_cpu_do_interrupt;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 12/15] Add optional parameters to QMP command query-cpu-definitions

2015-03-30 Thread Michael Mueller
The patch adds optional parameters to the QMP command query-cpu-definitions.
Thus the signature of routine arch_query_cpu_definitions needs to be changed
for the stub function and all target implementations:

target-arm
target-i386
target-ppc
target-s390

Signed-off-by: Michael Mueller 
---
 include/sysemu/arch_init.h  |  6 +-
 qapi-schema.json| 14 --
 qmp-commands.hx |  2 +-
 qmp.c   | 11 ---
 stubs/arch-query-cpu-def.c  |  6 +-
 target-arm/helper.c |  6 +-
 target-i386/cpu.c   |  6 +-
 target-ppc/translate_init.c |  6 +-
 target-s390x/cpu.c  |  6 +-
 9 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 86344a2..ab48c35 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -36,7 +36,11 @@ void audio_init(void);
 int kvm_available(void);
 int xen_available(void);
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuDefinitionInfoList *arch_query_cpu_definitions(bool has_machine,
+  const char *machine,
+  bool has_accel,
+  AccelId accel,
+  Error **errp);
 CpuModelInfo *arch_query_cpu_model(Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 14d294f..61a145d 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2532,21 +2532,31 @@
 #
 # @name: the name of the CPU definition
 #
+# @default: #optional defines if cpu model is the default (since 2.4)
+#
+# @runnable: #optional defines if cpu model is runnable (since 2.4)
+#
 # Since: 1.2.0
 ##
 { 'type': 'CpuDefinitionInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*is-default': 'bool', '*runnable': 'bool' } }
 
 ##
 # @query-cpu-definitions:
 #
 # Return a list of supported virtual CPU definitions
 #
+# @machine: #optional machine type (since 2.4)
+#
+# @accel: #optional accelerator id (since 2.4)
+#
 # Returns: a list of CpuDefInfo
 #
 # Since: 1.2.0
 ##
-{ 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
+{ 'command': 'query-cpu-definitions',
+  'data': { '*machine': 'str', '*accel': 'AccelId' },
+  'returns': ['CpuDefinitionInfo'] }
 
 ##
 # @CpuModelInfo:
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 8fe577f..ed86773d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3412,7 +3412,7 @@ EQMP
 
 {
 .name   = "query-cpu-definitions",
-.args_type  = "",
+.args_type  = "machine:s?,accel:s?",
 .mhandler.cmd_new = qmp_marshal_input_query_cpu_definitions,
 },
 
diff --git a/qmp.c b/qmp.c
index ad63803..ad52fb3 100644
--- a/qmp.c
+++ b/qmp.c
@@ -567,9 +567,14 @@ DevicePropertyInfoList *qmp_device_list_properties(const 
char *typename,
 return prop_list;
 }
 
-CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)
-{
-return arch_query_cpu_definitions(errp);
+CpuDefinitionInfoList *qmp_query_cpu_definitions(bool has_machine,
+ const char *machine,
+ bool has_accel,
+ AccelId accel,
+ Error **errp)
+{
+return arch_query_cpu_definitions(has_machine, machine,
+  has_accel, accel, errp);
 }
 
 CpuModelInfo *qmp_query_cpu_model(Error **errp)
diff --git a/stubs/arch-query-cpu-def.c b/stubs/arch-query-cpu-def.c
index 22e0b43..6f8904e 100644
--- a/stubs/arch-query-cpu-def.c
+++ b/stubs/arch-query-cpu-def.c
@@ -2,7 +2,11 @@
 #include "sysemu/arch_init.h"
 #include "qapi/qmp/qerror.h"
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *arch_query_cpu_definitions(bool has_machine,
+  const char *machine,
+  bool has_accel,
+  AccelId accel,
+  Error **errp)
 {
 error_set(errp, QERR_UNSUPPORTED);
 return NULL;
diff --git a/target-arm/helper.c b/target-arm/helper.c
index 10886c5..d56d47a 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -3535,7 +3535,11 @@ static void arm_cpu_add_definition(gpointer data, 
gpointer user_data)
 *cpu_list = entry;
 }
 
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+CpuDefinitionInfoList *arch_query_cp

[PATCH v4 15/15] target-s390x: Enable cpu model usage

2015-03-30 Thread Michael Mueller
This patch enables QEMU to instantiate S390 CPUs with cpu model types.

Signed-off-by: Michael Mueller 
---
 hw/s390x/s390-virtio.c | 12 +++-
 target-s390x/helper.c  |  9 ++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index bdb5388..8fda717 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -32,6 +32,7 @@
 #include "hw/virtio/virtio.h"
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
+#include "sysemu/cpus.h"
 #include "exec/address-spaces.h"
 
 #include "hw/s390x/s390-virtio-bus.h"
@@ -157,7 +158,12 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 int i;
 
 if (cpu_model == NULL) {
-cpu_model = "host";
+cpu_model = "none";
+}
+
+if (is_help_option(cpu_model)) {
+list_cpus(stdout, &fprintf, cpu_model);
+exit(0);
 }
 
 ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
@@ -167,6 +173,10 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 CPUState *cs;
 
 cpu = cpu_s390x_init(cpu_model);
+if (cpu == NULL) {
+fprintf(stderr, "Unable to find CPU definition\n");
+exit(1);
+}
 cs = CPU(cpu);
 
 ipi_states[i] = cpu;
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index f1060c2..29dabe2 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -22,6 +22,7 @@
 #include "exec/gdbstub.h"
 #include "qemu/timer.h"
 #include "exec/cpu_ldst.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/sysemu.h"
 #endif
@@ -66,13 +67,7 @@ void s390x_cpu_timer(void *opaque)
 
 S390CPU *cpu_s390x_init(const char *cpu_model)
 {
-S390CPU *cpu;
-
-cpu = S390_CPU(object_new(TYPE_S390_CPU));
-
-object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
-return cpu;
+return S390_CPU(cpu_generic_init(TYPE_S390_CPU, cpu_model));
 }
 
 #if defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 13/15] target-s390x: Extend QMP command query-cpu-definitions

2015-03-30 Thread Michael Mueller
This patch implements the QMP command 'query-cpu-definitions' in the S390
context. The command returns a list of cpu model names in the current host
context. A consumer may successfully request each listed cpu model as long
for a given accelerator and machine this model is runnable.

request:
  {"execute": "query-cpu-definitions",
  "arguments": { "accel": "kvm",
 "machine": "s390-ccw-virtio" }
  }

answer:
  {"return": [ {"name":"2964-ga1","runnable":false,"is-default":false},
   {"name":"2828-ga1","runnable":true,"is-default":false},
   {"name":"2827-ga2","runnable":true,"is-default":true},
   {"name":"2827-ga1","runnable":true,"is-default":false},
       ...
   {"name":"2064-ga1","runnable":true,"is-default":false} ]
  }

The request arguments are optional and if omitted only the cpu model names
are returned without the runnable or is-default attributes.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c |  15 ++
 target-s390x/cpu-models.h |   7 +++
 target-s390x/cpu.c| 114 +++---
 target-s390x/kvm.c|  49 +++-
 4 files changed, 177 insertions(+), 8 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 187d110..aba44dd 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -215,6 +215,21 @@ int set_s390_cpu_alias(const char *name, const char *model)
 return 0;
 }
 
+/* compare order of two cpu classes for descending sort */
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return 1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return -1;
+}
+return 0;
+}
+
 /* return machine class for specific machine type */
 static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
 {
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 67f0519..4734c58 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -85,10 +85,16 @@ typedef struct S390MachineProps {
 } S390MachineProps;
 
 #ifdef CONFIG_KVM
+int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop);
 int kvm_s390_get_processor_props(S390ProcessorProps *prop);
 int kvm_s390_set_processor_props(S390ProcessorProps *prop);
 bool kvm_s390_cpu_classes_initialized(void);
 #else
+static inline int kvm_s390_get_machine_props(KVMState *s,
+ S390MachineProps *prop)
+{
+return -ENOSYS;
+}
 static inline int kvm_s390_get_processor_props(S390ProcessorProps *prop)
 {
 return -ENOSYS;
@@ -107,6 +113,7 @@ void s390_setup_cpu_classes(S390AccelMode mode, 
S390MachineProps *prop,
 uint64_t *fac_list_mask);
 void s390_setup_cpu_aliases(void);
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b);
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b);
 void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 uint64_t *s390_fac_list_mask_by_machine(const char *name);
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 615173f..0ccacb7 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -30,13 +30,21 @@
 #include "hw/hw.h"
 #include "trace.h"
 #include "cpu-models.h"
+#include "sysemu/accel.h"
+#include "qapi/qmp/qerror.h"
 #ifndef CONFIG_USER_ONLY
+#include "hw/boards.h"
 #include "sysemu/arch_init.h"
 #endif
 
 #define CR0_RESET   0xE0UL
 #define CR14_RESET  0xC200UL;
 
+typedef struct CpuDefParm {
+CpuDefinitionInfoList *list;
+bool showFullEntry;
+} CpuDefParm;
+
 static inline char *strdup_s390_cpu_name(S390CPUClass *cc)
 {
 return g_strdup_printf("%04x-ga%u", cc->proc.type, cc->mach.ga);
@@ -66,22 +74,114 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 }
 
 #ifndef CONFIG_USER_ONLY
+static CpuDefinitionInfoList *qmp_query_cpu_definition_host(void)
+{
+CpuDefinitionInfoList *host = NULL;
+CpuDefinitionInfo *info;
+
+info = g_try_new0(CpuDefinitionInfo, 1);
+if (!info) {
+goto out;
+}
+info->name = g_strdup("host");
+
+host = g_try_new0(CpuDefinitionInfoList, 1);
+if (!host) {
+g_free(info->name);
+g_free(info);
+goto out;
+}
+host->value = inf

[PATCH v4 11/15] target-s390x: New QMP command query-cpu-model

2015-03-30 Thread Michael Mueller
This patch implements a new QMP request named 'query-cpu-model'.
It returns the cpu model of cpu 0 and its backing accelerator.

request:
  {"execute" : "query-cpu-model" }

answer:
  {"return" : {"name": "2827-ga2", "accel": "kvm" }}

Alias names are resolved to their respective machine type and GA names
already during cpu instantiation. Thus, also a cpu model like 'host'
which is implemented as alias will return its normalized cpu model name.

Furthermore the patch implements the following function:

- s390_cpu_models_used(), returns true if S390 cpu models are in use

Signed-off-by: Michael Mueller 
---
 include/sysemu/arch_init.h |  1 +
 qapi-schema.json   | 35 +++
 qmp-commands.hx|  6 ++
 qmp.c  |  5 +
 stubs/Makefile.objs|  1 +
 stubs/arch-query-cpu-mod.c |  9 +
 target-s390x/cpu-models.c  | 14 ++
 target-s390x/cpu-models.h  |  1 +
 target-s390x/cpu.c | 29 +
 9 files changed, 101 insertions(+)
 create mode 100644 stubs/arch-query-cpu-mod.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 54b36c1..86344a2 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -37,5 +37,6 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelInfo *arch_query_cpu_model(Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index ac9594d..14d294f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2516,6 +2516,16 @@
 { 'command': 'query-machines', 'returns': ['MachineInfo'] }
 
 ##
+# @AccelId
+#
+# Defines accelerator ids
+#
+# Since: 2.4
+##
+{ 'enum': 'AccelId',
+  'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
+
+##
 # @CpuDefinitionInfo:
 #
 # Virtual CPU definition.
@@ -2538,6 +2548,31 @@
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# @accel: AccelId (name) of this cpu models accelerator
+#
+# Since: 2.4
+##
+{ 'type': 'CpuModelInfo',
+  'data': { 'name': 'str', 'accel': 'AccelId' } }
+
+##
+# @query-cpu-model:
+#
+# Return the current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 2.4
+##
+{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 3a42ad0..8fe577f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3417,6 +3417,12 @@ EQMP
 },
 
 {
+.name   = "query-cpu-model",
+.args_type  = "",
+.mhandler.cmd_new = qmp_marshal_input_query_cpu_model,
+},
+
+{
 .name   = "query-target",
 .args_type  = "",
 .mhandler.cmd_new = qmp_marshal_input_query_target,
diff --git a/qmp.c b/qmp.c
index c479e77..ad63803 100644
--- a/qmp.c
+++ b/qmp.c
@@ -572,6 +572,11 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error 
**errp)
 return arch_query_cpu_definitions(errp);
 }
 
+CpuModelInfo *qmp_query_cpu_model(Error **errp)
+{
+return arch_query_cpu_model(errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
 Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index dce9cd2..ca70d5d 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,4 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-mod.o
 stub-obj-y += bdrv-commit-all.o
 stub-obj-y += chr-baum-init.o
 stub-obj-y += chr-msmouse.o
diff --git a/stubs/arch-query-cpu-mod.c b/stubs/arch-query-cpu-mod.c
new file mode 100644
index 000..90ebd08
--- /dev/null
+++ b/stubs/arch-query-cpu-mod.c
@@ -0,0 +1,9 @@
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+error_set(errp, QERR_UNSUPPORTED);
+return NULL;
+}
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index ba873ea..187d110 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -707,3 +707,17 @@ void s390_cpu_model_init(S390CPUClass *cc)
 }
 }
 }
+
+/**
+ * s390_cpu_models_used:
+ *
+ * This function indicates if cpus with model properties are in use.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.4
+ */
+bool s390_cpu_models_use

[PATCH v4 03/15] target-s390x: Generate facility defines per cpu model

2015-03-30 Thread Michael Mueller
This patch introduces the helper "gen-facilities" which allows to generate
facility list definitions and masks 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-facilities.h" to be able to use named
facility bits instead of numbers. Its output will be feed back into the
cpu model related header file "target-s390x/cpu-models.h" by including
"target-s390x/gen-facilities.h" to implement model related data structures.

The following defines/symbols are expected to be provided by the cpu-facilities
header file:

FAC_LIST_ARCH_S390_SIZE_UINT8
FAC_N3
FAC_ZARCH
FAC_ZARCH_ACTIVE
...

The defines provided by gen-facilities follow the following schema:

FAC_LIST_CPU_S390_SIZE_UINT1 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT8 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT64 %PRIu32
FAC_LIST_CPU_S390_MASK_QEMU 0x%016PRIx64,0x%016PRIx64,...
FAC_LIST_CPU_S390__GA 0x%016PRIx64,0x%016PRIx64,...

fix: target-s390/Makefile.obj

private build dir now supported, but make clean still has an issue:

[mimu@p57lp59 (bb/mimu/devel-cpu-model-v6+) qemu]$ make clean
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h 
gen-op-arm.h
...
for d in s390x-softmmu s390x-linux-user pc-bios/s390-ccw; do \
if test -d $d; then make -C $d clean || exit 1; fi; \
rm -f $d/qemu-options.def; \
done
make[1]: Entering directory `/home/mimu/REPO/qemu/foobuild/s390x-softmmu'
  CCgen-facilities
cc1: error: -I/usr/include/pixman-1: No such file or directory [-Werror]
cc1: all warnings being treated as errors
make[1]: *** [/gen-facilities] Error 1
make[1]: Leaving directory `/home/mimu/REPO/qemu/foobuild/s390x-softmmu'
make: *** [clean] Error 1

Signed-off-by: Michael Mueller 
---
 Makefile.target   |   2 +-
 rules.mak |   1 +
 target-s390x/Makefile.objs|  20 ++
 target-s390x/gen-facilities.c | 417 ++
 4 files changed, 439 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/gen-facilities.c

diff --git a/Makefile.target b/Makefile.target
index 2262d89..58cfc1b 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -190,7 +190,7 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN  
 $(TARGET_DIR)$@")
 
-clean:
+clean: clean-target
rm -f *.a *~ $(PROGS)
rm -f $(shell find . -name '*.[od]')
rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
diff --git a/rules.mak b/rules.mak
index 3a05627..43cf05c 100644
--- a/rules.mak
+++ b/rules.mak
@@ -12,6 +12,7 @@ MAKEFLAGS += -rR
 %.cpp:
 %.m:
 %.mak:
+clean-target:
 
 # Flags for C++ compilation
 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index dd62cbd..997dda4 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -3,3 +3,23 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o 
misc_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
+
+# build and run facility generator
+#
+fac = gen-facilities
+fac-src = $(SRC_PATH)/target-$(TARGET_BASE_ARCH)
+fac-dst = $(BUILD_DIR)/$(TARGET_DIR)
+
+ifneq ($(MAKECMDGOALS),clean)
+GENERATED_HEADERS += $(fac-dst)$(fac).h
+endif
+
+$(fac-dst)$(fac).h: $(fac-dst)$(fac)
+   $(call quiet-command,$< >$@,"  GEN   $(TARGET_DIR)$(fac).h")
+
+$(fac-dst)$(fac): $(fac-src)/$(fac).c $(fac-src)/cpu-facilities.h
+   $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(CFLAGS) -o 
$@ $<,"  CC$(TARGET_DIR)$(fac)")
+
+clean-target:
+   rm -f $(fac).h
+   rm -f $(fac)
diff --git a/target-s390x/gen-facilities.c b/target-s390x/gen-facilities.c
new file mode 100644
index 000..f4f4c57
--- /dev/null
+++ b/target-s390x/gen-facilities.c
@@ -0,0 +1,417 @@
+/*
+ * S390 facility list/mask generator
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "cpu-facilities.h"
+
+/* BEGIN FACILITY DEFS */
+
+/***
+ * CMOS G7 processors
+ ***/
+
+/* 2064-GA1 */
+static uint16_t set_2064_GA1[] = {
+FAC_N3,
+FAC_ZARCH,
+FAC_ZARCH_ACTIVE,
+};
+#define clear_2064_GA1 EmptyFacs
+
+/* 2064-GA2 */
+static uint16_t set_2064_GA2[] = {
+FAC_EX

[PATCH v4 01/15] Introduce stub routine cpu_desc_avail

2015-03-30 Thread Michael Mueller
This patch introduces the function cpu_desc_avail() which returns by
default true if not architecture specific implemented. Its intention
is to indicate if the cpu model description is available for display
by list_cpus(). This change allows cpu model descriptions to become
dynamically created by evaluating the runtime context instead of
putting static cpu model information at display.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 include/qemu-common.h  | 2 ++
 stubs/Makefile.objs| 1 +
 stubs/cpu-desc-avail.c | 6 ++
 vl.c   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 stubs/cpu-desc-avail.c

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 1b5cffb..386750f 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -484,4 +484,6 @@ int parse_debug_env(const char *name, int max, int initial);
 
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
+bool cpu_desc_avail(void);
+
 #endif
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 8beff4c..dce9cd2 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -39,3 +39,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += cpu-desc-avail.o
diff --git a/stubs/cpu-desc-avail.c b/stubs/cpu-desc-avail.c
new file mode 100644
index 000..0cd594e
--- /dev/null
+++ b/stubs/cpu-desc-avail.c
@@ -0,0 +1,6 @@
+#include "qemu-common.h"
+
+bool cpu_desc_avail(void)
+{
+return true;
+}
diff --git a/vl.c b/vl.c
index 74c2681..c552561 100644
--- a/vl.c
+++ b/vl.c
@@ -3820,7 +3820,7 @@ int main(int argc, char **argv, char **envp)
  */
 cpudef_init();
 
-if (cpu_model && is_help_option(cpu_model)) {
+if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
 list_cpus(stdout, &fprintf, cpu_model);
 exit(0);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 00/15] s390x cpu model implementation

2015-03-30 Thread Michael Mueller
This patch set in combination with its kernel kvm patch set proposes an
implementation of S390 cpu models. The origin of this item is to provide
a means for management interfaces like libvirt to draw decisions if life
guest migration to a target hypervisor is reasonable.

A migration constraint is that a target hypervisor is capable to run a
guest with the same S390 cpu model as the source hypervisor does. To
verify this condition, the administration interface employes the existing
QMP command "query-cpu-definitions" which returns a list of all currently
supported S390 cpu models of a given host system. Together with the newly
defined QMP command "query-cpu-model", which returns the current active
S390 cpu model of a guest, a conclusion can be drawn if a migration is
possible.

A S390 cpu model is defined as a triple of machine type, cpu facility set
and IBC value. Each historic, current and future triple receives a name
composed of the machine type and its general availability counter. This name
forms the cpu model name (e.g.: "2817-ga2".)

With means of the Instruction Blocking Control feature (IBC), the instruction
set available to a given guest is limitable.

Details:
- The QMP command query-cpu-model returns the active cpu model and the
  accellerator name it is using:

  {"name":"2066-ga1","accel":"kvm"}

Or just the empty model in case an accelerator does not take care of cpu models:

  {}

- A management instance like libvirt may probe by means of the QMP command
  query-cpu-definitions which models are defined and usable for specific
  accelerators and machine types. To implement this the cpu definition info
  type gets two optional fields named 'runnable' and 'is-default' representing
  the runnable cpu model for the given accelertor and machine type as well as
  the host cpu model.

  { "execute": "query-cpu-definitions",
"arguments": { "accel": "kvm", "machine": "s390-ccw-virtio" } }

  { "return": [ {"name": "2964-ga1","runnable": false, "is-default": false},
{"name": "2828-ga1","runnable": true,  "is-default": false},
{"name": "2827-ga2","runnable": true,  "is-default": true},
...
{"name": "2064-ga1","runnable": true,  "is-default": false} ] }

Or just host in case an accelerator does not take care of the cpu models:

  { "return": [ {"name": "host"} ] }

v3-v4:
- qemu probe mode is gone now
- optional parameters 'accel' and 'machine' added to QMP query-cpu-definitions
- z13 related facilities added
- private build directory issue fixed

v2-v3:
- using GTK-Doc style format now for function descriptions
- typo fixed (2/16)
- gen-facilties now used to generate cpu model specific facility lists
  and the qemu side facility mask during build time (5/16)
- gen-facilities added to make magic (5/16)
- element of struct S390CPUMachineProps now statically in cpu class (6/16)
- element of struct S390CPUProcessorProps now statically in cpu class (6/16)
- facility list also static now (6/16)
- typo fixed (7/16)
- zBC12-ga1 model now active on zEC12-ga2 host (11/16)
- operations on facility lists use QEMU bitmap API now (11/16)
- routine s390_cpu_model_init() introduced, called during cpu object
  realization to prepare the current accelarator (12/16) if a cpu
  model was selected
- missing comment added in description of CpuModelInfo type (13/16)
- accelerator field now mandatory for "query-cpu-model" (13/16)
- sorted list related comment to "query-cpu-definitions" dropped in
  commit message (13/16)
- comment for AccelCpuInfo type updated (13/16)
- routine s390_facility_test() factored out (15/16)

v1-v2:
- QEMU-side facility list mask introduced: this allows to enable guest
  facilities that are handled by instruction interception handlers
  implemented on qemu side. Similar to the facilities enabled by means
  of the KVM side facility list mask which are handled by kvm/kernel.
- Concept of soft facilities has been dropped
- Result type of QMP command query-cpu-definitions extended to hold
  additional information beside the cpu model name including which
  cpu model is runnable in current accelerator and machine context.

Michael Mueller (15):
  Introduce stub routine cpu_desc_avail
  target-s390x: Introduce cpu facilities
  target-s390x: Generate facility defines per cpu model
  target-s390x: Introduce cpu models
  target-s390x: Define cpu model specific facility lists
  target-s390x: Add cpu model alias definition routines
  target-s390x: Update linux-headers/asm-s390/kvm.h
  target-s390x: Add KVM VM attribute

Re: [Qemu-devel] [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-05 Thread Michael Mueller
On Wed, 4 Mar 2015 16:19:25 -0300
Eduardo Habkost  wrote:

> On Tue, Mar 03, 2015 at 11:55:24AM +0100, Michael Mueller wrote:
> > On Mon, 02 Mar 2015 17:57:01 +0100
> > Andreas Färber  wrote:
> > 
> > > Am 02.03.2015 um 17:43 schrieb Michael Mueller:
> > > > On Mon, 02 Mar 2015 14:57:21 +0100
> > > > Andreas Färber  wrote:
> > > > 
> > > >>>  int configure_accelerator(MachineState *ms)
> > > >>>  {
> > > >>> -const char *p;
> > > >>> +const char *p, *name;
> > > >>>  char buf[10];
> > > >>>  int ret;
> > > >>>  bool accel_initialised = false;
> > > >>>  bool init_failed = false;
> > > >>>  AccelClass *acc = NULL;
> > > >>> +ObjectClass *oc;
> > > >>> +bool probe_mode = false;
> > > >>>  
> > > >>>  p = qemu_opt_get(qemu_get_machine_opts(), "accel");
> > > >>>  if (p == NULL) {
> > > >>> -/* Use the default "accelerator", tcg */
> > > >>> -p = "tcg";
> > > >>> +oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
> > > >>> +name = object_class_get_name(oc);
> > > >>> +probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
> > > >>> +if (probe_mode) {
> > > >>> +/* Use these accelerators in probe mode, tcg should be 
> > > >>> last */
> > > >>> +p = probe_mode_accels;
> > > >>> +} else {
> > > >>> +/* Use the default "accelerator", tcg */
> > > >>> +p = "tcg";
> > > >>> +}
> > > >>>  }  
> > > >>
> > > >> Can't we instead use an explicit ,accel=probe or ,accel=auto?
> > > >> That would then obsolete the next patch.
> > > > 
> > > > How would you express the following with the accel= 
> > > > approach?
> > > > 
> > > > -probe -machine s390-ccw,accel=kvm 
> > > > 
> > > > Using machine "none" as default with tcg as last accelerator 
> > > > initialized should not break
> > > > anything.
> > > > 
> > > > -M none
> > > 
> > > Let me ask differently: What does -machine none or -M none have to do
> > > with probing? It reads as if you are introducing two probe modes. Why do
> > 
> > The machine none? nothing directly, I guess. What are real world use cases 
> > for that
> > machine type?
> > 
> > > you need both? If we have -probe, isn't that independent of which
> > 
> > It is just two different means to switch on the same mode.
> > 
> > > machine we specify? Who is going to call either, with which respective 
> > > goal?
> > 
> > -probe itself would be sufficient but I currently do not want to enforce 
> > the use of
> > a new parameter. Best would be not to have that mode at all if possible. 
> > 
> > The intended use case is driven by management interfaces that need to draw 
> > decisions
> > on, in this particular case runnable cpu models, with information 
> > originated by qemu.
> > 
> > Let me walk through Eduardo's suggestion first and crosscheck it with my 
> > requirements
> > before we enter in a maybe afterwards obsolete discussion.
> 
> I have been working on some changes to implement x86 CPU probing code
> that creates accel objects on the fly, that may be useful. See:
>   https://github.com/ehabkost/qemu-hacks/tree/work/user-accel-init
> 
> Especially the commit:
>   kvm: Move /dev/kvm opening/closing to open/close methods
> 

So the idea is to use kvm_open/close() in the query-cpu-definitions callback on 
the fly without
to disturb the KVM-side data structures for the machine probe instead of going 
through kvm_init()
during accelerator configuration?


> The next steps I plan are:
>  * Create AccelState object on TCG too, and somehow pass it as argument
>to cpu_x86_init()
>  * Change all kvm_enabled() occurrences on target-i386/cpu.c to use
>the provided accel object (including
>x86_cpu_get_supported_feature_word() and x86_cpu_filter_features())
>  * Use the new
>x86_cpu_get_supported_feature_word()/x86_cpu_filter_features() code
>to implement a is_runnable(X86CPUClass*, AccelState*) check
>  * Use the new is_runnable() check to extend query-cpu-definitions for x86 too
>  * Add -cpu string and machine-type arguments to the is_runnable() check
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 14/16] target-s390x: Extend QMP command query-cpu-definitions

2015-03-04 Thread Michael Mueller
On Mon, 2 Mar 2015 16:11:00 -0300
Eduardo Habkost  wrote:

> On Mon, Mar 02, 2015 at 01:44:06PM +0100, Michael Mueller wrote:
> > This patch implements the QMP command 'query-cpu-definitions' in the S390
> > context. The command returns a list of cpu model names in the current host
> > context. A consumer may successfully request each listed cpu model as long
> > for a given accelerator this model is runnable.
> > 
> > The QMP type AccelCpuModelInfo is introduced and the type CpuDefinitionInfo
> > is extended by the optional field 'accelerators'. It contains a list of 
> > named
> > accelerators and some indication whether the associated cpu model is 
> > runnable
> > or the default cpu model. The default cpu model is used if either no 
> > specific
> > cpu model is requested during QEMU startup or if the cpu model with name
> > 'host' is requested.
> > 
> > request:
> >   {"execute": "query-cpu-definitions"}
> > 
> > answer:
> >   {"return":
> > 
> > [{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]},
> >  
> > {"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> >  
> > {"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> >  ...
> >  
> > {"name":"2064-ga1","accelerators":[{"runnable":true,"name":"kvm","default":false}]}
> > ]
> >}
> 
> On x86, being runnable or not is something that depends on the
> machine-type. I expect that to happen in other machines as soon as they
> start implementing backwards compatiblity.
> 
> I see two options to implement that: 1) adding a "machine-type" argument
> to query-cpu-definitions; 2) returning a machine-type-based dictionary
> on the "runnable" property. The former sounds better to me as it won't
> require enumerating all machine-types every time.
> 
> In that case, why we do need to enumerate all accelerators on every
> query, either? We could have both "machine-type" and "accel" arguments
> to query-cpu-definitions, so callers will just ask for the
> acceleratores/machine-types they are interested into.
> 
> e.g.:
> 
> request:
>   {"execute": "query-cpu-definitions",
>"arguments": {"machine":"s390-virtio", "accel":"kvm"}}
> 
> answer:
>   {"return":
> [{"name":"2964-ga1","runnable":true},
>  {"name":"2828-ga1","runnable":false}
>  ...
> ]
>   }

I had some discussion with out libvirt people on that. I will compile a patch 
implementing this
to see how it fits..

> 
> We can also extend this to other variables, such as extra CPU flags that
> could make the CPU runnable or not. e.g.: want to know if "-machine
> foo,accel=bar -cpu xxx,+yyy,-zzz" is runnable? Send this request:
>   {"execute": "query-cpu-definitions",
>"arguments": {"machine":"s390-virtio", "accel":"kvm", 
> "cpu":"xxx,+yyy,-zzz"}}
> and get this response:
>   {"return": [{"name":"xxx","runnable":false}]}
> or maybe being more explicit in the response about the extra CPU flags:
>   {"return": [{"name":"xxx,+yyy,-zzz","runnable":false}]}
> 
> 
> >   {"execute": "query-cpu-definitions"}
> > 
> > answer:
> >   {"return":
> > 
> > [{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]},
> >  
> > {"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> >  
> > {"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> > 
> > Signed-off-by: Michael Mueller 
> > [...]
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-03 Thread Michael Mueller
On Mon, 2 Mar 2015 16:17:33 -0300
Eduardo Habkost  wrote:

> > +if (probe_mode) {
> > +/* Use these accelerators in probe mode, tcg should be last */
> > +p = probe_mode_accels;  
> 
> I don't fully understand the purpose of this patch yet (I will discuss
> it in a reply to the cover letter). But if you really want -machine none
> to trigger different behavior, why you didn't add a probe_mode field
> to MachineClass, so you can set it in the mahine_none class code?

I initially had this machine attribute but, when I remember correctly, but 
wasn't able to
communicate it down into the target code. But anyhow, the "mode" is eventually 
obsolete in light
of the temporarily constructed accelerators.. I will further comment on this as 
reply to your
comment on the cover letter to keep it in place.

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-03 Thread Michael Mueller
On Mon, 02 Mar 2015 17:57:01 +0100
Andreas Färber  wrote:

> Am 02.03.2015 um 17:43 schrieb Michael Mueller:
> > On Mon, 02 Mar 2015 14:57:21 +0100
> > Andreas Färber  wrote:
> > 
> >>>  int configure_accelerator(MachineState *ms)
> >>>  {
> >>> -const char *p;
> >>> +const char *p, *name;
> >>>  char buf[10];
> >>>  int ret;
> >>>  bool accel_initialised = false;
> >>>  bool init_failed = false;
> >>>  AccelClass *acc = NULL;
> >>> +ObjectClass *oc;
> >>> +bool probe_mode = false;
> >>>  
> >>>  p = qemu_opt_get(qemu_get_machine_opts(), "accel");
> >>>  if (p == NULL) {
> >>> -/* Use the default "accelerator", tcg */
> >>> -p = "tcg";
> >>> +oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
> >>> +name = object_class_get_name(oc);
> >>> +probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
> >>> +if (probe_mode) {
> >>> +/* Use these accelerators in probe mode, tcg should be last 
> >>> */
> >>> +p = probe_mode_accels;
> >>> +} else {
> >>> +/* Use the default "accelerator", tcg */
> >>> +p = "tcg";
> >>> +}
> >>>  }  
> >>
> >> Can't we instead use an explicit ,accel=probe or ,accel=auto?
> >> That would then obsolete the next patch.
> > 
> > How would you express the following with the accel= approach?
> > 
> > -probe -machine s390-ccw,accel=kvm 
> > 
> > Using machine "none" as default with tcg as last accelerator initialized 
> > should not break
> > anything.
> > 
> > -M none
> 
> Let me ask differently: What does -machine none or -M none have to do
> with probing? It reads as if you are introducing two probe modes. Why do

The machine none? nothing directly, I guess. What are real world use cases for 
that
machine type?

> you need both? If we have -probe, isn't that independent of which

It is just two different means to switch on the same mode.

> machine we specify? Who is going to call either, with which respective goal?

-probe itself would be sufficient but I currently do not want to enforce the 
use of
a new parameter. Best would be not to have that mode at all if possible. 

The intended use case is driven by management interfaces that need to draw 
decisions
on, in this particular case runnable cpu models, with information originated by 
qemu.

Let me walk through Eduardo's suggestion first and crosscheck it with my 
requirements
before we enter in a maybe afterwards obsolete discussion.

Thanks,
Michael

> 
> I think that changing the semantics of an absent ,accel=foo parameter to
> mean something else than its longtime default of tcg is a bad idea.
>
> Have you testing qtest with it? Doesn't -qtest imply accel=qtest or is
> that always passed explicitly?
> 
> Regards,
> Andreas
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-02 Thread Michael Mueller
On Mon, 02 Mar 2015 14:57:21 +0100
Andreas Färber  wrote:

> >  int configure_accelerator(MachineState *ms)
> >  {
> > -const char *p;
> > +const char *p, *name;
> >  char buf[10];
> >  int ret;
> >  bool accel_initialised = false;
> >  bool init_failed = false;
> >  AccelClass *acc = NULL;
> > +ObjectClass *oc;
> > +bool probe_mode = false;
> >  
> >  p = qemu_opt_get(qemu_get_machine_opts(), "accel");
> >  if (p == NULL) {
> > -/* Use the default "accelerator", tcg */
> > -p = "tcg";
> > +oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
> > +name = object_class_get_name(oc);
> > +probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
> > +if (probe_mode) {
> > +/* Use these accelerators in probe mode, tcg should be last */
> > +p = probe_mode_accels;
> > +} else {
> > +/* Use the default "accelerator", tcg */
> > +p = "tcg";
> > +}
> >  }  
> 
> Can't we instead use an explicit ,accel=probe or ,accel=auto?
> That would then obsolete the next patch.

How would you express the following with the accel= approach?

-probe -machine s390-ccw,accel=kvm 

Using machine "none" as default with tcg as last accelerator initialized should 
not break
anything.

-M none

The return code of configure_accelerator() is ignored anyway.

Thanks,
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 02/16] Introduce option --probe to switch into probe mode

2015-03-02 Thread Michael Mueller
The option --probe allows to switch into probe mode also for machines
different from none. If one or more accelerators are specified these
accelerators are used to provide probable properties. If no accelerator
is given a list of accelerators that support probing is used.

Signed-off-by: Michael Mueller 
---
 accel.c| 13 -
 include/sysemu/accel.h |  2 +-
 qemu-options.hx|  8 
 vl.c   |  7 ++-
 4 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/accel.c b/accel.c
index 260b009..4ed6df8 100644
--- a/accel.c
+++ b/accel.c
@@ -81,7 +81,7 @@ static int accel_init_machine(AccelClass *acc, MachineState 
*ms,
 return ret;
 }
 
-int configure_accelerator(MachineState *ms)
+int configure_accelerator(MachineState *ms, int probe)
 {
 const char *p, *name;
 char buf[10];
@@ -90,13 +90,16 @@ int configure_accelerator(MachineState *ms)
 bool init_failed = false;
 AccelClass *acc = NULL;
 ObjectClass *oc;
-bool probe_mode = false;
+bool probe_mode;
 
+probe_mode = probe != 0;
 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
 if (p == NULL) {
-oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
-name = object_class_get_name(oc);
-probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
+if (!probe_mode) {
+oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
+name = object_class_get_name(oc);
+probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
+}
 if (probe_mode) {
 /* Use these accelerators in probe mode, tcg should be last */
 p = probe_mode_accels;
diff --git a/include/sysemu/accel.h b/include/sysemu/accel.h
index 997720f..3adb6ba 100644
--- a/include/sysemu/accel.h
+++ b/include/sysemu/accel.h
@@ -57,6 +57,6 @@ typedef struct AccelClass {
 
 extern int tcg_tb_size;
 
-int configure_accelerator(MachineState *ms);
+int configure_accelerator(MachineState *ms, int probe);
 
 #endif
diff --git a/qemu-options.hx b/qemu-options.hx
index 85ca3ad..22e7544 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2847,6 +2847,14 @@ STEXI
 Do not start CPU at startup (you must type 'c' in the monitor).
 ETEXI
 
+DEF("probe", 0, QEMU_OPTION_probe, \
+"-probe  startup in probe mode, option -S is selected as well\n", 
QEMU_ARCH_ALL)
+STEXI
+@item -probe
+@findex -probe
+Startup in probe mode.
+ETEXI
+
 DEF("realtime", HAS_ARG, QEMU_OPTION_realtime,
 "-realtime [mlock=on|off]\n"
 "run qemu with realtime features\n"
diff --git a/vl.c b/vl.c
index e1ffd0a..ba1730c 100644
--- a/vl.c
+++ b/vl.c
@@ -138,6 +138,7 @@ bool enable_mlock = false;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
 int autostart;
+int probe;
 static int rtc_utc = 1;
 static int rtc_date_offset = -1; /* -1 means no change */
 QEMUClockType rtc_clock;
@@ -3144,6 +3145,10 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_S:
 autostart = 0;
 break;
+case QEMU_OPTION_probe:
+probe = 1;
+autostart = 0;
+break;
 case QEMU_OPTION_k:
 keyboard_layout = optarg;
 break;
@@ -4023,7 +4028,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-configure_accelerator(current_machine);
+configure_accelerator(current_machine, probe);
 
 if (qtest_chrdev) {
 Error *local_err = NULL;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 08/16] target-s390x: Add cpu model alias definition routines

2015-03-02 Thread Michael Mueller
This patch implements the infrastructure to dynamically add cpu
model aliases.

Signed-off-by: Michael Mueller 
Reviewed-by: Cornelia Huck 
---
 target-s390x/cpu-models.c | 89 +++
 target-s390x/cpu-models.h | 11 ++
 target-s390x/cpu.c|  1 +
 3 files changed, 101 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index bd9f0bc..608189d 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -87,3 +87,92 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM 
zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 
+static GSList *s390_cpu_aliases;
+
+static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
+{
+const char *aname = object_class_get_name((ObjectClass *) a);
+const char *bname = b;
+int blen;
+
+if (!strcmp(bname, "none") &&
+!strcmp(aname, TYPE_S390_CPU)) {
+return 0;
+}
+blen = strlen(bname);
+if (!strncasecmp(bname, aname, blen) &&
+!strcmp(aname + blen, "-" TYPE_S390_CPU)) {
+return 0;
+}
+return -1;
+}
+
+/**
+ * s390_cpu_class_by_name:
+ * @name: a cpu model or alias name
+ *
+ * The function searches for the requested cpu model name or an alias
+ * cpu model name and returns the associated object class.
+ *
+ * Returns: reference to object class on success or %NULL elsewise.
+ *
+ * Since: 2.3
+ */
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+GSList *list, *item;
+ObjectClass *ret = NULL;
+S390CPUAlias *alias;
+
+for (item = s390_cpu_aliases; item != NULL; item = item->next) {
+alias = (S390CPUAlias *) item->data;
+if (strcmp(alias->name, name) == 0) {
+return s390_cpu_class_by_name(alias->model);
+}
+}
+list = object_class_get_list(TYPE_S390_CPU, false);
+item = g_slist_find_custom(list, name, s390_cpu_compare_class_name);
+if (item) {
+ret = OBJECT_CLASS(item->data);
+}
+g_slist_free(list);
+return ret;
+}
+
+/**
+ * set_s390_cpu_alias:
+ * @name: the cpu alias name
+ * @model: the cpu model name
+ *
+ * The function registers the alias @name for an existing cpu @model.
+ *
+ * Returns: %0 in case of success
+ *  -%EINVAL if name or model is %NULL or both are idential
+ *   or model is not a valid cpu model
+ *  -%ENOMEM if internal memory allocation fails
+ *
+ * Since: 2.3
+ */
+int set_s390_cpu_alias(const char *name, const char *model)
+{
+S390CPUAlias *alias;
+
+if (!name || !model) {
+return -EINVAL;
+}
+if (!strcmp(name, model)) {
+return -EINVAL;
+}
+if (!s390_cpu_class_by_name(model)) {
+return -EINVAL;
+}
+alias = g_try_malloc0(sizeof(S390CPUAlias));
+if (!alias) {
+return -ENOMEM;
+}
+alias->name = g_strdup(name);
+alias->model = g_strdup(model);
+s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+return 0;
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index d5f0b59..a32f559 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -35,6 +35,17 @@
 #define cpu_class(x)  (((x) >> 20) & 0x3)
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
+ObjectClass *s390_cpu_class_by_name(const char *name);
+int set_s390_cpu_alias(const char *name, const char *model);
+
+/*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+char *name;
+char *model;
+} S390CPUAlias;
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index 7a26b91..1992910 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -308,6 +308,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
 #endif
 scc->cpu_reset = s390_cpu_reset;
 scc->initial_cpu_reset = s390_cpu_initial_reset;
+cc->class_by_name = s390_cpu_class_by_name;
 cc->reset = s390_cpu_full_reset;
 cc->has_work = s390_cpu_has_work;
 cc->do_interrupt = s390_cpu_do_interrupt;
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 03/16] Introduce stub routine cpu_desc_avail

2015-03-02 Thread Michael Mueller
This patch introduces the function cpu_desc_avail() which returns by
default true if not architecture specific implemented. Its intention
is to indicate if the cpu model description is available for display
by list_cpus(). This change allows cpu model descriptions to become
dynamically created by evaluating the runtime context instead of
putting static cpu model information at display.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 include/qemu-common.h  | 2 ++
 stubs/Makefile.objs| 1 +
 stubs/cpu-desc-avail.c | 6 ++
 vl.c   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 stubs/cpu-desc-avail.c

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 644b46d..45040f9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -481,4 +481,6 @@ int parse_debug_env(const char *name, int max, int initial);
 
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
+bool cpu_desc_avail(void);
+
 #endif
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5e347d0..fd7a489 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -40,3 +40,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += cpu-desc-avail.o
diff --git a/stubs/cpu-desc-avail.c b/stubs/cpu-desc-avail.c
new file mode 100644
index 000..0cd594e
--- /dev/null
+++ b/stubs/cpu-desc-avail.c
@@ -0,0 +1,6 @@
+#include "qemu-common.h"
+
+bool cpu_desc_avail(void)
+{
+return true;
+}
diff --git a/vl.c b/vl.c
index ba1730c..d337a74 100644
--- a/vl.c
+++ b/vl.c
@@ -3815,7 +3815,7 @@ int main(int argc, char **argv, char **envp)
  */
 cpudef_init();
 
-if (cpu_model && is_help_option(cpu_model)) {
+if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
 list_cpus(stdout, &fprintf, cpu_model);
 exit(0);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 05/16] target-s390x: Generate facility defines per cpu model

2015-03-02 Thread Michael Mueller
This patch introduces the helper "gen-facilities" which allows to generate
facility list definitions and masks 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-facilities.h" to be able to use named
facility bits instead of numbers. Its output will be feed back into the
cpu model related header file "target-s390x/cpu-models.h" by including
"target-s390x/gen-facilities.h" to implement model related data structures.

The following defines/symbols are expected to be provided by the cpu-facilities
header file:

FAC_LIST_ARCH_S390_SIZE_UINT8
FAC_N3
FAC_ZARCH
FAC_ZARCH_ACTIVE
...

The defines provided by gen-facilities follow the following schema:

FAC_LIST_CPU_S390_SIZE_UINT1 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT8 %PRIu32
FAC_LIST_CPU_S390_SIZE_UINT64 %PRIu32
FAC_LIST_CPU_S390_MASK_QEMU 0x%016PRIx64,0x%016PRIx64,...
FAC_LIST_CPU_S390__GA 0x%016PRIx64,0x%016PRIx64,...

Signed-off-by: Michael Mueller 
---
 Makefile.target   |   2 +-
 rules.mak |   3 +
 target-s390x/Makefile.objs|  18 ++
 target-s390x/gen-facilities.c | 401 ++
 4 files changed, 423 insertions(+), 1 deletion(-)
 create mode 100644 target-s390x/gen-facilities.c

diff --git a/Makefile.target b/Makefile.target
index 58c6ae1..d174d5e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -188,7 +188,7 @@ hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 qmp-commands-old.h: $(SRC_PATH)/qmp-commands.hx
$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN  
 $(TARGET_DIR)$@")
 
-clean:
+clean: clean-target
rm -f *.a *~ $(PROGS)
rm -f $(shell find . -name '*.[od]')
rm -f hmp-commands.h qmp-commands-old.h gdbstub-xml.c
diff --git a/rules.mak b/rules.mak
index 3a05627..d367e23 100644
--- a/rules.mak
+++ b/rules.mak
@@ -13,6 +13,9 @@ MAKEFLAGS += -rR
 %.m:
 %.mak:
 
+# default target cleanup
+clean-target:
+
 # Flags for C++ compilation
 QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
 
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index dd62cbd..1b65776 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -3,3 +3,21 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o 
misc_helper.o
 obj-y += gdbstub.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
+
+# build and run facility generator
+#
+fac = gen-facilities
+fac-src = $(SRC_PATH)/target-$(TARGET_BASE_ARCH)
+fac-dst = $(SRC_PATH)/$(TARGET_DIR)
+fac-bin = $(TARGET_DIR)$(fac)
+fac-h = $(fac-bin).h
+GENERATED_HEADERS += $(fac-dst)$(fac).h
+
+$(fac-dst)$(fac).h: $(fac-dst)$(fac)
+   $(call quiet-command,$< >$@,"  GEN   $(fac-h)")
+
+$(fac-dst)$(fac): $(fac-src)/$(fac).c $(fac-src)/cpu-facilities.h
+   $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(CFLAGS) -o 
$@ $<,"  CC$(fac-bin)")
+
+clean-target:
+   rm -f $(fac-bin) $(fac-h)
diff --git a/target-s390x/gen-facilities.c b/target-s390x/gen-facilities.c
new file mode 100644
index 000..9d48bcc
--- /dev/null
+++ b/target-s390x/gen-facilities.c
@@ -0,0 +1,401 @@
+/*
+ * S390 facility list/mask generator
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "cpu-facilities.h"
+
+/* BEGIN FACILITY DEFS */
+
+/***
+ * CMOS G7 processors
+ ***/
+
+/* 2064-GA1 */
+static uint16_t set_2064_GA1[] = {
+FAC_N3,
+FAC_ZARCH,
+FAC_ZARCH_ACTIVE,
+};
+#define clear_2064_GA1 EmptyFacs
+
+/* 2064-GA2 */
+static uint16_t set_2064_GA2[] = {
+FAC_EXTENDED_TRANSLATION_2,
+};
+#define clear_2064_GA2 EmptyFacs
+
+/* 2064-GA3 */
+#define set_2064_GA3 EmptyFacs
+#define clear_2064_GA3 EmptyFacs
+
+/* 2066-GA1 */
+#define set_2066_GA1 EmptyFacs
+#define clear_2066_GA1 EmptyFacs
+
+/***
+ * CMOS G8 processors
+ ***/
+
+/* 2084-GA1 */
+static uint16_t set_2084_GA1[] = {
+FAC_DAT_ENH,
+FAC_MESSAGE_SECURITY_ASSIST,
+FAC_LONG_DISPLACEMENT,
+FAC_LONG_DISPLACEMENT_FAST,
+FAC_HFP_MADDSUB,
+};
+#define clear_2084_GA1 EmptyFacs
+
+/* 2084-GA2 */
+static uint16_t set_2084_GA2[] = {
+4,
+};
+#define clear_2084_GA2 EmptyFacs
+
+/* 2084-GA3 */
+static uint16_t set_2084_GA3[] = {
+FAC_ASN_LX_REUSE,
+FAC_EXTENDED_TRANSLATION_3,
+};
+#define 

[PATCH v3 01/16] Introduce probe mode for machine type none

2015-03-02 Thread Michael Mueller
QEMU now switches into "probe mode" when the selected machine is "none" and no
specific accelerator(s) has been requested (i.e.: "-machine none").

In probe mode a by "_CONFIG" defines predefined list of accelerators run
their init() methods.

Signed-off-by: Michael Mueller 
---
 accel.c  | 31 +--
 include/hw/boards.h  |  1 +
 include/sysemu/kvm.h | 10 ++
 kvm-all.c|  3 +++
 4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/accel.c b/accel.c
index 74e41da..260b009 100644
--- a/accel.c
+++ b/accel.c
@@ -36,6 +36,9 @@
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
+static const char *probe_mode_accels =
+"kvm:"
+"tcg";
 
 static int tcg_init(MachineState *ms)
 {
@@ -59,13 +62,15 @@ static AccelClass *accel_find(const char *opt_name)
 return ac;
 }
 
-static int accel_init_machine(AccelClass *acc, MachineState *ms)
+static int accel_init_machine(AccelClass *acc, MachineState *ms,
+  bool probe_mode)
 {
 ObjectClass *oc = OBJECT_CLASS(acc);
 const char *cname = object_class_get_name(oc);
 AccelState *accel = ACCEL(object_new(cname));
 int ret;
 ms->accelerator = accel;
+ms->probe_mode = probe_mode;
 *(acc->allowed) = true;
 ret = acc->init_machine(ms);
 if (ret < 0) {
@@ -78,20 +83,30 @@ static int accel_init_machine(AccelClass *acc, MachineState 
*ms)
 
 int configure_accelerator(MachineState *ms)
 {
-const char *p;
+const char *p, *name;
 char buf[10];
 int ret;
 bool accel_initialised = false;
 bool init_failed = false;
 AccelClass *acc = NULL;
+ObjectClass *oc;
+bool probe_mode = false;
 
 p = qemu_opt_get(qemu_get_machine_opts(), "accel");
 if (p == NULL) {
-/* Use the default "accelerator", tcg */
-p = "tcg";
+oc = (ObjectClass *) MACHINE_GET_CLASS(current_machine);
+name = object_class_get_name(oc);
+probe_mode = !strcmp(name, "none" TYPE_MACHINE_SUFFIX);
+if (probe_mode) {
+/* Use these accelerators in probe mode, tcg should be last */
+p = probe_mode_accels;
+} else {
+/* Use the default "accelerator", tcg */
+p = "tcg";
+}
 }
 
-while (!accel_initialised && *p != '\0') {
+while ((probe_mode || !accel_initialised) && *p != '\0') {
 if (*p == ':') {
 p++;
 }
@@ -106,7 +121,7 @@ int configure_accelerator(MachineState *ms)
acc->name);
 continue;
 }
-ret = accel_init_machine(acc, ms);
+ret = accel_init_machine(acc, ms, probe_mode);
 if (ret < 0) {
 init_failed = true;
 fprintf(stderr, "failed to initialize %s: %s\n",
@@ -128,6 +143,10 @@ int configure_accelerator(MachineState *ms)
 fprintf(stderr, "Back to %s accelerator.\n", acc->name);
 }
 
+if (probe_mode) {
+accel_initialised = false;
+}
+
 return !accel_initialised;
 }
 
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 3ddc449..3253fa5 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -135,6 +135,7 @@ struct MachineState {
 bool usb;
 char *firmware;
 bool iommu;
+bool probe_mode;
 
 ram_addr_t ram_size;
 ram_addr_t maxram_size;
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 30cb84d..fbc18c8 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -50,6 +50,7 @@ extern bool kvm_msi_via_irqfd_allowed;
 extern bool kvm_gsi_routing_allowed;
 extern bool kvm_gsi_direct_mapping;
 extern bool kvm_readonly_mem_allowed;
+extern bool kvm_probe_mode;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()   (kvm_allowed)
@@ -143,6 +144,15 @@ extern bool kvm_readonly_mem_allowed;
  */
 #define kvm_readonly_mem_enabled() (kvm_readonly_mem_allowed)
 
+/**
+ * kvm_probe_mode_enabled:
+ *
+ * Returns: true if KVM is initialized for a machine type that
+ * has its probe_mode attribute set (ie QEMU was started in probe
+ * mode)
+ */
+#define kvm_probe_mode_enabled() (kvm_probe_mode)
+
 #else
 #define kvm_enabled()   (0)
 #define kvm_irqchip_in_kernel() (false)
diff --git a/kvm-all.c b/kvm-all.c
index 05a79c2..f9e4434 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -126,6 +126,7 @@ bool kvm_gsi_routing_allowed;
 bool kvm_gsi_direct_mapping;
 bool kvm_allowed;
 bool kvm_readonly_mem_allowed;
+bool kvm_probe_mode;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
 KVM_CAP_INFO(USER_MEMORY),
@@ -1471,6 +1472,8 @@ static int kvm_init(MachineState *ms)
 goto err;
 }
 
+kvm_probe_mode = ms->probe_mode;
+
 s->nr_slots = kvm_check_extension(s, KVM_CAP_NR_MEMSLOT

[PATCH v3 04/16] target-s390x: Introduce cpu facilities

2015-03-02 Thread Michael Mueller
The patch introduces S390 CPU facility bit numbers and names
as well as the architectural facility size limit in bytes.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-facilities.h | 76 +++
 1 file changed, 76 insertions(+)
 create mode 100644 target-s390x/cpu-facilities.h

diff --git a/target-s390x/cpu-facilities.h b/target-s390x/cpu-facilities.h
new file mode 100644
index 000..1f1716a
--- /dev/null
+++ b/target-s390x/cpu-facilities.h
@@ -0,0 +1,76 @@
+/*
+ * CPU facilities for s390
+ *
+ * Copyright 2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * 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_FACILITIES_H
+#define TARGET_S390X_CPU_FACILITIES_H
+
+/* architectural size of facilities is 2KB */
+#define FAC_LIST_ARCH_S390_SIZE_UINT8 (1<<11)
+
+/* CPU facility bits */
+typedef enum {
+FAC_N3  = 0,
+FAC_ZARCH   = 1,
+FAC_ZARCH_ACTIVE= 2,
+FAC_DAT_ENH = 3,
+FAC_ASN_LX_REUSE= 6,
+FAC_STFLE   = 7,
+FAC_ENHANCED_DAT_1  = 8,
+FAC_SENSE_RUNNING_STATUS= 9,
+FAC_CONDITIONAL_SSKE= 10,
+FAC_CONFIGURATION_TOPOLOGY  = 11,
+FAC_IPTE_RANGE  = 13,
+FAC_NONQ_KEY_SETTING= 14,
+FAC_EXTENDED_TRANSLATION_2  = 16,
+FAC_MESSAGE_SECURITY_ASSIST = 17,
+FAC_LONG_DISPLACEMENT   = 18,
+FAC_LONG_DISPLACEMENT_FAST  = 19,
+FAC_HFP_MADDSUB = 20,
+FAC_EXTENDED_IMMEDIATE  = 21,
+FAC_EXTENDED_TRANSLATION_3  = 22,
+FAC_HFP_UNNORMALIZED_EXT= 23,
+FAC_ETF2_ENH= 24,
+FAC_STORE_CLOCK_FAST= 25,
+FAC_PARSING_ENH = 26,
+FAC_MOVE_WITH_OPTIONAL_SPEC = 27,
+FAC_TOD_CLOCK_STEERING  = 28,
+FAC_ETF3_ENH= 30,
+FAC_EXTRACT_CPU_TIME= 31,
+FAC_COMPARE_AND_SWAP_AND_STORE  = 32,
+FAC_COMPARE_AND_SWAP_AND_STORE_2= 33,
+FAC_GENERAL_INSTRUCTIONS_EXT= 34,
+FAC_EXECUTE_EXT = 35,
+FAC_ENHANCED_MONITOR= 36,
+FAC_FLOATING_POINT_EXT  = 37,
+FAC_LOAD_PROGRAM_PARAMETERS = 40,
+FAC_FLOATING_POINT_SUPPPORT_ENH = 41,
+FAC_DFP = 42,
+FAC_DFP_FAST= 43,
+FAC_PFPO= 44,
+FAC_MULTI_45= 45,
+FAC_CMPSC_ENH   = 47,
+FAC_DFP_ZONED_CONVERSION= 48,
+FAC_MULTI_49= 49,
+FAC_CONSTRAINT_TRANSACTIONAL_EXE= 50,
+FAC_LOCAL_TLB_CLEARING  = 51,
+FAC_INTERLOCKED_ACCESS_2= 52,
+FAC_RESET_REFERENCE_BITS_MULTIPLE   = 66,
+FAC_CPU_MEASUREMENT_COUNTER = 67,
+FAC_CPU_MEASUREMENT_SAMPLING= 68,
+FAC_TRANSACTIONAL_EXE   = 73,
+FAC_ACCESS_EXCEPTION_FS_INDICATION  = 75,
+FAC_MESSAGE_SECURITY_ASSIST_3   = 76,
+FAC_MESSAGE_SECURITY_ASSIST_4   = 77,
+FAC_ENHANCED_DAT_2  = 78,
+} S390Facility;
+
+#endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 09/16] target-s390x: Update linux-headers/asm-s390/kvm.h

2015-03-02 Thread Michael Mueller
Signed-off-by: Michael Mueller 
---
 linux-headers/asm-s390/kvm.h | 20 
 1 file changed, 20 insertions(+)

diff --git a/linux-headers/asm-s390/kvm.h b/linux-headers/asm-s390/kvm.h
index d36b2fa..e38c942 100644
--- a/linux-headers/asm-s390/kvm.h
+++ b/linux-headers/asm-s390/kvm.h
@@ -57,11 +57,31 @@ struct kvm_s390_io_adapter_req {
 
 /* kvm attr_group  on vm fd */
 #define KVM_S390_VM_MEM_CTRL   0
+#define KVM_S390_VM_CPU_MODEL  3
 
 /* kvm attributes for mem_ctrl */
 #define KVM_S390_VM_MEM_ENABLE_CMMA0
 #define KVM_S390_VM_MEM_CLR_CMMA   1
 
+/* kvm S390 processor related attributes are r/w */
+#define KVM_S390_VM_CPU_PROCESSOR  0
+struct kvm_s390_vm_cpu_processor {
+   __u64 cpuid;
+   __u16 ibc;
+   __u8  pad[6];
+   __u64 fac_list[256];
+};
+
+/* kvm S390 machine related attributes are r/o */
+#define KVM_S390_VM_CPU_MACHINE1
+struct kvm_s390_vm_cpu_machine {
+   __u64 cpuid;
+   __u32 ibc_range;
+   __u8  pad[4];
+   __u64 fac_mask[256];
+   __u64 fac_list[256];
+};
+
 /* for KVM_GET_REGS and KVM_SET_REGS */
 struct kvm_regs {
/* general purpose regs for s390 */
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 06/16] target-s390x: Introduce cpu models

2015-03-02 Thread Michael Mueller
This patch implements the static part of the s390 cpu class definitions.
It defines s390 cpu models by means of virtual cpu ids (enum) which contain
information on the cpu generation, the machine class, the GA number and
the machine type. The cpu id is used to instantiate a cpu class per cpu
model.

In addition the patch introduces the QMP enumeration AccelId. It is used
to index certain cpu model poperties per accelerator.

Furthermore it extends the existing S390CPUClass by model related properties.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 qapi-schema.json   | 11 +++
 target-s390x/Makefile.objs |  1 +
 target-s390x/cpu-models.c  | 77 ++
 target-s390x/cpu-models.h  | 71 ++
 target-s390x/cpu-qom.h | 25 +++
 5 files changed, 185 insertions(+)
 create mode 100644 target-s390x/cpu-models.c
 create mode 100644 target-s390x/cpu-models.h

diff --git a/qapi-schema.json b/qapi-schema.json
index e16f8eb..ea436ec 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2473,6 +2473,17 @@
 ##
 { 'command': 'query-machines', 'returns': ['MachineInfo'] }
 
+
+##
+# @AccelId
+#
+# Defines accelerator ids
+#
+# Since: 2.3
+##
+{ 'enum': 'AccelId',
+  'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
+
 ##
 # @CpuDefinitionInfo:
 #
diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs
index 1b65776..4ee0f1d 100644
--- a/target-s390x/Makefile.objs
+++ b/target-s390x/Makefile.objs
@@ -1,6 +1,7 @@
 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 += cpu-models.o
 obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o mmu_helper.o
 obj-$(CONFIG_KVM) += kvm.o
 
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
new file mode 100644
index 000..3520691
--- /dev/null
+++ b/target-s390x/cpu-models.c
@@ -0,0 +1,77 @@
+/*
+ * CPU models for s390
+ *
+ * Copyright 2014,2015 IBM Corp.
+ *
+ * Author(s): Michael Mueller 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at
+ * your option) any later version. See the COPYING file in the top-level
+ * directory.
+ */
+
+#include "qemu-common.h"
+#include "cpu-models.h"
+
+#define S390_PROC_DEF(_name, _cpu_id, _desc)\
+static void \
+glue(_cpu_id, _cpu_class_init)  \
+(ObjectClass *oc, void *data)   \
+{   \
+DeviceClass *dc = DEVICE_CLASS(oc); \
+S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+\
+cc->is_active[ACCEL_ID_KVM] = true; \
+cc->mach.ga= cpu_ga(_cpu_id);   \
+cc->mach.class = cpu_class(_cpu_id);\
+cc->mach.order = cpu_order(_cpu_id);\
+cc->proc.gen   = cpu_generation(_cpu_id);   \
+cc->proc.ver   = S390_DEF_VERSION;  \
+cc->proc.id= S390_DEF_ID;   \
+cc->proc.type  = cpu_type(_cpu_id); \
+cc->proc.ibc   = S390_DEF_IBC;  \
+dc->desc   = _desc; \
+}   \
+static const TypeInfo   \
+glue(_cpu_id, _cpu_type_info) = {   \
+.name   = _name "-" TYPE_S390_CPU,  \
+.parent = TYPE_S390_CPU,\
+.class_init = glue(_cpu_id, _cpu_class_init),   \
+};  \
+static void \
+glue(_cpu_id, _cpu_register_types)(void)\
+{   \
+type_register_static(   \
+&glue(_cpu_id, _cpu_type_info));\
+}   \
+type_init(glue(_cpu_id, _cpu_register_types))
+
+/* define S390 CPU model classes */
+S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
+S

[PATCH v3 07/16] target-s390x: Define cpu model specific facility lists

2015-03-02 Thread Michael Mueller
This patch defines S390 cpu facilities and their presence at the
different cpu model levels. Beside defining a base which facilities
have to be requested per cpu model, these sets are associated to the
defined cpu classes and used to calculate the list of supported
cpu models in context of the current hosting machine model.

The also defined qemu side facility mask allows to implement and enable
facilities in QEMU land.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 12 
 target-s390x/cpu-models.h |  8 
 target-s390x/cpu.c|  1 +
 3 files changed, 21 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 3520691..bd9f0bc 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -12,6 +12,7 @@
 
 #include "qemu-common.h"
 #include "cpu-models.h"
+#include "gen-facilities.h"
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -20,6 +21,10 @@
 {   \
 DeviceClass *dc = DEVICE_CLASS(oc); \
 S390CPUClass *cc = S390_CPU_CLASS(oc);  \
+uint64_t nbits = FAC_LIST_CPU_S390_SIZE_UINT1;  \
+uint64_t fac_list[FAC_LIST_CPU_S390_SIZE_UINT64] = {\
+glue(FAC_LIST_, _cpu_id)\
+};  \
 \
 cc->is_active[ACCEL_ID_KVM] = true; \
 cc->mach.ga= cpu_ga(_cpu_id);   \
@@ -30,6 +35,7 @@
 cc->proc.id= S390_DEF_ID;   \
 cc->proc.type  = cpu_type(_cpu_id); \
 cc->proc.ibc   = S390_DEF_IBC;  \
+bitmap_copy(cc->proc.fac_list, fac_list, nbits);\
 dc->desc   = _desc; \
 }   \
 static const TypeInfo   \
@@ -46,6 +52,11 @@
 }   \
 type_init(glue(_cpu_id, _cpu_register_types))
 
+/* facilities implemented by qemu */
+uint64_t qemu_s390_fac_list_mask[FAC_LIST_CPU_S390_SIZE_UINT64] = {
+FAC_LIST_CPU_S390_MASK_QEMU
+};
+
 /* define S390 CPU model classes */
 S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
 S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
@@ -75,3 +86,4 @@ S390_PROC_DEF("2818-ga1", CPU_S390_2818_GA1, "IBM zEnterprise 
114 GA1")
 S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index db681bf..d5f0b59 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -13,6 +13,14 @@
 #ifndef TARGET_S390X_CPU_MODELS_H
 #define TARGET_S390X_CPU_MODELS_H
 
+#include "cpu-facilities.h"
+#include "gen-facilities.h"
+
+#define FAC_LIST_ARCH_S390_SIZE_UINT1 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 * BITS_PER_BYTE)
+#define FAC_LIST_ARCH_S390_SIZE_UINT64 \
+(FAC_LIST_ARCH_S390_SIZE_UINT8 / sizeof(uint64_t))
+
 #define S390_EC 0x1
 #define S390_BC 0x2
 
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index d2f6312..7a26b91 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -29,6 +29,7 @@
 #include "qemu/error-report.h"
 #include "hw/hw.h"
 #include "trace.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/arch_init.h"
 #endif
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 11/16] target-s390x: Add cpu class initialization routines

2015-03-02 Thread Michael Mueller
This patch provides routines to dynamically update the previously defined
S390 cpu classes in the current host context. The main function performing
this process is s390_setup_cpu_classes(). It takes the current host context
as parameter to setup the classes accordingly. It basically performs the
following sub-tasks:

- Update of cpu classes with accelerator specific host and QEMU properties
- Mark adequate cpu class as default cpu class to be used for cpu model 'host'
- Invalidate cpu classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common cpu model names
- Set cpu model alias 'host' to default cpu class

Forthermore the patch provides the following routines:

- cpu_desc_avail(), s390 specific stub indicating that list_cpus() can run
- s390_cpu_classes_initialized(), test if cpu classes have been initialized
- s390_probe_mode(), indicates if probe mode is active

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 458 ++
 target-s390x/cpu-models.h |  26 +++
 target-s390x/cpu.c|  17 +-
 target-s390x/kvm.c|   4 +-
 4 files changed, 503 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 608189d..83e590a 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -13,6 +13,7 @@
 #include "qemu-common.h"
 #include "cpu-models.h"
 #include "gen-facilities.h"
+#include "qemu/error-report.h"
 
 #define S390_PROC_DEF(_name, _cpu_id, _desc)\
 static void \
@@ -87,8 +88,41 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM 
zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 
+/* some types for calls to g_list_foreach() with parameters */
+typedef struct ParmBoolShortShortAccel {
+bool valid;
+unsigned short type;
+union {
+unsigned short class;
+unsigned short gen;
+unsigned short ga;
+};
+AccelId accel;
+} ParmBoolShortShortAccel;
+
+typedef struct ParmAddrAddrAccel {
+S390MachineProps *prop;
+S390CPUClass *host_cc;
+AccelId accel;
+} ParmAddrAddrAccel;
+
 static GSList *s390_cpu_aliases;
 
+/* compare order of two cpu classes for ascending sort */
+gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return -1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return 1;
+}
+return 0;
+}
+
 static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
 {
 const char *aname = object_class_get_name((ObjectClass *) a);
@@ -176,3 +210,427 @@ int set_s390_cpu_alias(const char *name, const char 
*model)
 return 0;
 }
 
+/* return machine class for specific machine type */
+static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShortAccel *parm = user_data;
+
+if (parm->valid || !cc->proc.type || parm->type != cc->proc.type) {
+return;
+}
+
+parm->class = cc->mach.class;
+parm->valid = true;
+}
+
+/* return machine class by machine type */
+static unsigned short machine_class(unsigned short type, void *user_data)
+{
+GSList *list = object_class_get_list(TYPE_S390_CPU, false);
+ParmBoolShortShortAccel parm_class, *parm = user_data;
+
+if (parm->type != type) {
+parm->class = 0;
+}
+if (!parm->class) {
+parm_class.type = type;
+parm_class.class = 0;
+parm_class.valid = false;
+g_slist_foreach(list, (GFunc) s390_machine_class_test_cpu_class,
+&parm_class);
+g_slist_free(list);
+if (parm_class.valid) {
+parm->class = parm_class.class;
+}
+}
+parm->type = type;
+
+return parm->class;
+}
+
+/* return CMOS generation for specific machine type */
+static void s390_machine_class_test_cpu_gen(gpointer data, gpointer user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShortAccel *parm = user_data;
+
+if (parm->valid) {
+return;
+}
+
+if (parm->type == cc->proc.type) {
+parm->gen = cc->proc.gen;
+parm->valid = true;
+}
+}
+
+/* return CMOS generation by machine type */
+static uint16_t machine_gen(unsigned short type)
+{
+GSList *list = object_class_get_list(T

[PATCH v3 10/16] target-s390x: Add KVM VM attribute interface for cpu models

2015-03-02 Thread Michael Mueller
The patch implements routines to set and retrieve processor configuration
data and to retrieve machine configuration data. The machine related data
is used together with the cpu model facility lists to determine the list of
supported cpu models of this host. The above mentioned routines have QEMU
trace point instrumentation.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.h |  39 ++
 target-s390x/kvm.c| 102 ++
 trace-events  |   3 ++
 3 files changed, 144 insertions(+)

diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index a32f559..b6b57d4 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -46,6 +46,45 @@ typedef struct S390CPUAlias {
 char *model;
 } S390CPUAlias;
 
+typedef struct S390ProcessorProps {
+uint64_t cpuid;
+uint16_t ibc;
+uint8_t  pad[6];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390ProcessorProps;
+
+typedef struct S390MachineProps {
+uint64_t cpuid;
+uint32_t ibc_range;
+uint8_t  pad[4];
+uint64_t fac_list_mask[FAC_LIST_ARCH_S390_SIZE_UINT64];
+uint64_t fac_list[FAC_LIST_ARCH_S390_SIZE_UINT64];
+} S390MachineProps;
+
+#ifdef CONFIG_KVM
+int kvm_s390_get_processor_props(S390ProcessorProps *prop);
+int kvm_s390_set_processor_props(S390ProcessorProps *prop);
+bool kvm_s390_cpu_classes_initialized(void);
+bool kvm_s390_probe_mode(void);
+#else
+static inline int kvm_s390_get_processor_props(S390ProcessorProps *prob)
+{
+return -ENOSYS;
+}
+static inline int kvm_s390_set_processor_props(S390ProcessorProps *prob)
+{
+return -ENOSYS;
+}
+static inline bool kvm_s390_cpu_classes_initialized(void)
+{
+return false;
+}
+static inline bool kvm_s390_probe_mode(void)
+{
+return false;
+}
+#endif
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index d7c57d9..5404137 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -43,6 +43,7 @@
 #include "hw/s390x/s390-pci-inst.h"
 #include "hw/s390x/s390-pci-bus.h"
 #include "hw/s390x/ipl.h"
+#include "cpu-models.h"
 
 /* #define DEBUG_KVM */
 
@@ -118,6 +119,7 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
 
 static int cap_sync_regs;
 static int cap_async_pf;
+static bool cpu_classes_initialized;
 
 static void *legacy_s390_alloc(size_t size, uint64_t *align);
 
@@ -173,6 +175,68 @@ static void kvm_s390_enable_cmma(KVMState *s)
 trace_kvm_enable_cmma(rc);
 }
 
+static int cpu_model_get(KVMState *s, uint64_t attr, uint64_t addr)
+{
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+return kvm_vm_ioctl(s, KVM_GET_DEVICE_ATTR, &dev_attr);
+}
+
+static int cpu_model_set(KVMState *s, uint64_t attr, uint64_t addr)
+{
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+.addr = addr,
+};
+
+return kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &dev_attr);
+}
+
+static int has_cpu_model_call(KVMState *s, uint64_t attr)
+{
+int rc;
+struct kvm_device_attr dev_attr = {
+.group = KVM_S390_VM_CPU_MODEL,
+.attr = attr,
+};
+
+if (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES) == 0) {
+return -ENOSYS;
+}
+
+rc = kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &dev_attr);
+if (rc == 0) {
+return 0;
+}
+return -EFAULT;
+}
+
+static int kvm_s390_get_machine_props(KVMState *s, S390MachineProps *prop)
+{
+int rc;
+
+rc = has_cpu_model_call(s, KVM_S390_VM_CPU_MACHINE);
+if (!rc) {
+rc = cpu_model_get(s, KVM_S390_VM_CPU_MACHINE, (uint64_t) prop);
+}
+trace_kvm_get_machine_props(rc, prop->cpuid, prop->ibc_range);
+return rc;
+}
+
+static void kvm_s390_setup_cpu_classes(KVMState *s)
+{
+S390MachineProps mach;
+
+if (!kvm_s390_get_machine_props(s, &mach)) {
+cpu_classes_initialized = false;
+}
+}
+
 int kvm_arch_init(KVMState *s)
 {
 cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS);
@@ -186,6 +250,8 @@ int kvm_arch_init(KVMState *s)
 || !kvm_check_extension(s, KVM_CAP_S390_COW)) {
 phys_mem_set_alloc(legacy_s390_alloc);
 }
+
+kvm_s390_setup_cpu_classes(s);
 return 0;
 }
 
@@ -1578,3 +1644,39 @@ int kvm_arch_fixup_msi_route(struct 
kvm_irq_routing_entry *route,
 route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id;
 return 0;
 }
+
+int kvm_s390_get_processor_props(S390ProcessorProps *prop)
+{
+int rc;
+
+rc = has_cpu_model_call(kvm_state, KVM_S390_VM_CPU_PROCESSOR);
+if (!rc) {
+rc = cpu_model_get(kvm_state,
+   KVM_S390_VM_CPU_PROCESSOR, (uint64_t) prop);
+}
+trace_kvm_get_processor_props(rc, prop->cpuid, prop->ibc);
+return rc;
+}
+
+int kvm_s3

[PATCH v3 14/16] target-s390x: Extend QMP command query-cpu-definitions

2015-03-02 Thread Michael Mueller
This patch implements the QMP command 'query-cpu-definitions' in the S390
context. The command returns a list of cpu model names in the current host
context. A consumer may successfully request each listed cpu model as long
for a given accelerator this model is runnable.

The QMP type AccelCpuModelInfo is introduced and the type CpuDefinitionInfo
is extended by the optional field 'accelerators'. It contains a list of named
accelerators and some indication whether the associated cpu model is runnable
or the default cpu model. The default cpu model is used if either no specific
cpu model is requested during QEMU startup or if the cpu model with name
'host' is requested.

request:
  {"execute": "query-cpu-definitions"}

answer:
  {"return":

[{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
 
{"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
 
{"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]},
 
{"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
 
{"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
 ...
 
{"name":"2064-ga1","accelerators":[{"runnable":true,"name":"kvm","default":false}]}
]
   }

Signed-off-by: Michael Mueller 
---
 qapi-schema.json  |  21 +-
 target-s390x/cpu-models.c |  15 +++
 target-s390x/cpu-models.h |   1 +
 target-s390x/cpu.c| 100 +++---
 4 files changed, 130 insertions(+), 7 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index e9b213f..44863e5 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2485,16 +2485,35 @@
   'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
 
 ##
+# @AccelCpuModelInfo:
+#
+# Accelerator specific CPU model data
+#
+# @name: the accelerator name
+#
+# @default: cpu model for 'host'
+#
+# @runnable: cpu model can be activated on hosting machine
+#
+# Since: 2.3
+#
+##
+{ 'type': 'AccelCpuModelInfo',
+  'data': { 'name': 'AccelId', 'default': 'bool', 'runnable': 'bool' } }
+
+##
 # @CpuDefinitionInfo:
 #
 # Virtual CPU definition.
 #
 # @name: the name of the CPU definition
 #
+# @accelerators: #optional cpu model offered per accelerator (since 2.3)
+#
 # Since: 1.2.0
 ##
 { 'type': 'CpuDefinitionInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*accelerators': ['AccelCpuModelInfo'] } }
 
 ##
 # @query-cpu-definitions:
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 116dbcc..7ad61df 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -211,6 +211,21 @@ int set_s390_cpu_alias(const char *name, const char *model)
 return 0;
 }
 
+/* compare order of two cpu classes for descending sort */
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach.order < cc_b->mach.order) {
+return 1;
+}
+if (cc_a->mach.order > cc_b->mach.order) {
+return -1;
+}
+return 0;
+}
+
 /* return machine class for specific machine type */
 static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
 {
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 51db298..3605aa4 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -110,6 +110,7 @@ static inline bool kvm_s390_probe_mode(void)
 
 int s390_setup_cpu_classes(AccelId accel, S390MachineProps *prop);
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b);
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b);
 void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 bool s390_probe_mode(void);
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index cefaff1..6bf6554 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -66,18 +66,106 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 }
 
 #ifndef CONFIG_USER_ONLY
-CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp)
+static AccelCpuModelIn

[PATCH v3 12/16] target-s390x: Prepare accelerator during cpu object realization

2015-03-02 Thread Michael Mueller
This patch implements routine s390_cpu_model_init(). It is called by the
realize function during instantiation of an cpu object. Its task is to
initialize the current accelerator with the properties of the selected
processor model.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 36 
 target-s390x/cpu-models.h |  4 
 target-s390x/cpu.c|  1 +
 3 files changed, 41 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 83e590a..c6c1771 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -107,6 +107,7 @@ typedef struct ParmAddrAddrAccel {
 } ParmAddrAddrAccel;
 
 static GSList *s390_cpu_aliases;
+static bool cpu_models_used;
 
 /* compare order of two cpu classes for ascending sort */
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
@@ -634,3 +635,38 @@ bool s390_probe_mode(void)
 return false;
 }
 
+/**
+ * s390_cpu_model_init:
+ * @cc: S390 CPU class
+ *
+ * This function intitializes the current accelerator with processor
+ * related properties.
+ *
+ * Since: 2.3
+ */
+void s390_cpu_model_init(S390CPUClass *cc)
+{
+S390ProcessorProps proc;
+
+/* none cpu model case */
+if (!strcmp(object_class_get_name(OBJECT_CLASS(cc)), TYPE_S390_CPU)) {
+return;
+}
+
+/* accelerator already prepared */
+if (cpu_models_used) {
+return;
+}
+
+proc.cpuid = cpuid(cc->proc);
+proc.ibc = cc->proc.ibc;
+bitmap_zero(proc.fac_list, FAC_LIST_ARCH_S390_SIZE_UINT1);
+bitmap_copy(proc.fac_list, cc->fac_list, FAC_LIST_CPU_S390_SIZE_UINT1);
+
+if (kvm_enabled()) {
+if (!kvm_s390_set_processor_props(&proc)) {
+cpu_models_used = true;
+}
+}
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index aa81c9b..f3f914a 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -45,6 +45,9 @@
 #define type_cpuid(x) ((uint64_t)((x) & 0x) << 16)
 #define id_cpuid(x)   ((uint64_t)((x) & 0xff) << 32)
 #define ver_cpuid(x)  ((uint64_t)((x) & 0xff) << 56)
+#define cpuid(x)  (ver_cpuid(x.ver) |  \
+   id_cpuid(x.id) |\
+   type_cpuid(x.type))
 
 #define oldest_ibc(x) (((uint32_t)(x) >> 16) & 0xfff)
 #define newest_ibc(x) ((uint32_t)(x) & 0xfff)
@@ -110,6 +113,7 @@ gint s390_cpu_class_asc_order_compare(gconstpointer a, 
gconstpointer b);
 void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 bool s390_probe_mode(void);
+void s390_cpu_model_init(S390CPUClass *cc);
 
 /*
  * bits 0-7   : CMOS generation
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index c9200ee..2f4192e 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -178,6 +178,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error 
**errp)
 CPUState *cs = CPU(dev);
 S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
 
+s390_cpu_model_init(scc);
 s390_cpu_gdb_init(cs);
 qemu_init_vcpu(cs);
 #if !defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 13/16] target-s390x: New QMP command query-cpu-model

2015-03-02 Thread Michael Mueller
This patch implements a new QMP request named 'query-cpu-model'.
It returns the cpu model of cpu 0 and its backing accelerator.

request:
  {"execute" : "query-cpu-model" }

answer:
  {"return" : {"name": "2827-ga2", "accelerator": "kvm" }}

Alias names are resolved to their respective machine type and GA names
already during cpu instantiation. Thus, also a cpu model like 'host'
which is implemented as alias will return its normalized cpu model name.

Furthermore the patch implements the following functions:

- s390_cpu_typename(), returns the currently selected cpu type name or NULL
- s390_cpu_models_used(), returns true if S390 cpu models are in use

Signed-off-by: Michael Mueller 
---
 include/sysemu/arch_init.h |  1 +
 qapi-schema.json   | 25 +
 qmp-commands.hx|  6 ++
 qmp.c  |  5 +
 stubs/Makefile.objs|  1 +
 stubs/arch-query-cpu-mod.c |  9 +
 target-s390x/cpu-models.c  | 13 +
 target-s390x/cpu-models.h  |  1 +
 target-s390x/cpu.c | 29 +
 9 files changed, 90 insertions(+)
 create mode 100644 stubs/arch-query-cpu-mod.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 54b36c1..86344a2 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -37,5 +37,6 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelInfo *arch_query_cpu_model(Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index ea436ec..e9b213f 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2507,6 +2507,31 @@
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# @accelerator: AccelId (name) of this cpu models acceletaror
+#
+# Since: 2.3
+##
+{ 'type': 'CpuModelInfo',
+  'data': { 'name': 'str', 'accelerator': 'AccelId' } }
+
+##
+# @query-cpu-model:
+#
+# Return the current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 2.3
+##
+{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a85d847..98bfedd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3392,6 +3392,12 @@ EQMP
 },
 
 {
+.name   = "query-cpu-model",
+.args_type  = "",
+.mhandler.cmd_new = qmp_marshal_input_query_cpu_model,
+},
+
+{
 .name   = "query-target",
 .args_type  = "",
 .mhandler.cmd_new = qmp_marshal_input_query_target,
diff --git a/qmp.c b/qmp.c
index d701cff..11b6172 100644
--- a/qmp.c
+++ b/qmp.c
@@ -573,6 +573,11 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error 
**errp)
 return arch_query_cpu_definitions(errp);
 }
 
+CpuModelInfo *qmp_query_cpu_model(Error **errp)
+{
+return arch_query_cpu_model(errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
 Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index fd7a489..45daa92 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,4 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-mod.o
 stub-obj-y += bdrv-commit-all.o
 stub-obj-y += chr-baum-init.o
 stub-obj-y += chr-msmouse.o
diff --git a/stubs/arch-query-cpu-mod.c b/stubs/arch-query-cpu-mod.c
new file mode 100644
index 000..90ebd08
--- /dev/null
+++ b/stubs/arch-query-cpu-mod.c
@@ -0,0 +1,9 @@
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+error_set(errp, QERR_UNSUPPORTED);
+return NULL;
+}
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index c6c1771..116dbcc 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -670,3 +670,16 @@ void s390_cpu_model_init(S390CPUClass *cc)
 }
 }
 
+/**
+ * s390_cpu_models_used:
+ *
+ * This function indicates if cpus with model properties are in use.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.3
+ */
+bool s390_cpu_models_used(void)
+{
+return cpu_models_used;
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index f3f914a..51db298 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -114,6 +114,7 @@ void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_init

[PATCH v3 15/16] target-s390x: Introduce facility test routine

2015-03-02 Thread Michael Mueller
The patch introduces routine s390_facility_test() which allows to
verify a specific facility bit is set.

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 30 ++
 target-s390x/cpu-models.h |  1 +
 2 files changed, 31 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 7ad61df..5c4eac5 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -698,3 +698,33 @@ bool s390_cpu_models_used(void)
 {
 return cpu_models_used;
 }
+
+static inline int test_facility(uint64_t *fac_list, uint16_t nr)
+{
+uint16_t word = nr / BITS_PER_LONG;
+uint16_t be_bit = (BITS_PER_LONG - 1) - (nr % BITS_PER_LONG);
+
+return (nr < FAC_LIST_CPU_S390_SIZE_UINT1) ?
+(fac_list[word] >> be_bit) & __UINT64_C(1) : 0;
+}
+
+/**
+ * s390_test_facility:
+ * @nr: facility bit number to test
+ * @cc: cpu class to test
+ *
+ * The functions tests if the cpu facility identified by bit @nr is available
+ * to the cpu class @cc.
+ *
+ * Returns: a boolean value.
+ *
+ * Since: 2.3
+ */
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr)
+{
+if (!cc) {
+return false;
+}
+return test_facility(cc->fac_list, nr) ? true : false;
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 3605aa4..557f5e5 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -116,6 +116,7 @@ bool s390_cpu_classes_initialized(void);
 bool s390_probe_mode(void);
 void s390_cpu_model_init(S390CPUClass *cc);
 bool s390_cpu_models_used(void);
+bool s390_test_facility(S390CPUClass *cc, uint16_t nr);
 
 /*
  * bits 0-7   : CMOS generation
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 16/16] target-s390x: Enable cpu model usage

2015-03-02 Thread Michael Mueller
This patch enables QEMU to instantiate S390 CPUs with cpu model types.

Signed-off-by: Michael Mueller 
---
 hw/s390x/s390-virtio.c | 12 +++-
 target-s390x/helper.c  |  9 ++---
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-virtio.c b/hw/s390x/s390-virtio.c
index 412e49b..0bf7632 100644
--- a/hw/s390x/s390-virtio.c
+++ b/hw/s390x/s390-virtio.c
@@ -32,6 +32,7 @@
 #include "hw/virtio/virtio.h"
 #include "hw/sysbus.h"
 #include "sysemu/kvm.h"
+#include "sysemu/cpus.h"
 #include "exec/address-spaces.h"
 
 #include "hw/s390x/s390-virtio-bus.h"
@@ -153,7 +154,12 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 int i;
 
 if (cpu_model == NULL) {
-cpu_model = "host";
+cpu_model = "none";
+}
+
+if (is_help_option(cpu_model)) {
+list_cpus(stdout, &fprintf, cpu_model);
+exit(0);
 }
 
 ipi_states = g_malloc(sizeof(S390CPU *) * smp_cpus);
@@ -163,6 +169,10 @@ void s390_init_cpus(const char *cpu_model, uint8_t 
*storage_keys)
 CPUState *cs;
 
 cpu = cpu_s390x_init(cpu_model);
+if (cpu == NULL) {
+fprintf(stderr, "Unable to find CPU definition\n");
+exit(1);
+}
 cs = CPU(cpu);
 
 ipi_states[i] = cpu;
diff --git a/target-s390x/helper.c b/target-s390x/helper.c
index e0fd8fc..5b6bad2 100644
--- a/target-s390x/helper.c
+++ b/target-s390x/helper.c
@@ -22,6 +22,7 @@
 #include "exec/gdbstub.h"
 #include "qemu/timer.h"
 #include "exec/cpu_ldst.h"
+#include "cpu-models.h"
 #ifndef CONFIG_USER_ONLY
 #include "sysemu/sysemu.h"
 #endif
@@ -66,13 +67,7 @@ void s390x_cpu_timer(void *opaque)
 
 S390CPU *cpu_s390x_init(const char *cpu_model)
 {
-S390CPU *cpu;
-
-cpu = S390_CPU(object_new(TYPE_S390_CPU));
-
-object_property_set_bool(OBJECT(cpu), true, "realized", NULL);
-
-return cpu;
+return S390_CPU(cpu_generic_init(TYPE_S390_CPU, cpu_model));
 }
 
 #if defined(CONFIG_USER_ONLY)
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/16] s390x cpu model implementation

2015-03-02 Thread Michael Mueller
This patch set in combination with its kernel kvm patch set proposes an
implementation of S390 cpu models. The origin of this item is to provide
a means for management interfaces like libvirt to draw decisions if life
guest migration to a target hypervisor is reasonable.

A migration constraint is that a target hypervisor is capable to run a
guest with the same S390 cpu model as the source hypervisor does. To
verify this condition, the administration interface employes the existing
QMP command "query-cpu-definitions" which returns a list of all currently
supported S390 cpu models of a given host system. Together with the newly
defined QMP command "query-cpu-model", which returns the current active
S390 cpu model of a guest, a conclusion can be drawn if a migration is
possible.

A S390 cpu model is defined as a triple of machine type, cpu facility set
and IBC value. Each historic, current and future triple receives a name
composed of the machine type and its general availability counter. This name
forms the cpu model name (e.g.: "2817-ga2".)

With means of the Instruction Blocking Control feature (IBC), the instruction
set available to a given guest is limitable.

Details:
- The QMP command query-cpu-model returns the active cpu model and the
  accellerator it is using:

  {"name":"2066-ga1","accelerator":"kvm"}

Or just the empty model in case an accelerator does not implement cpu
models yet:

  {}

- A management instance like libvirt may probe by means of the QMP command
  query-cpu-definitions which models are defined and usable for all
  supporting accelerators. To implement this the cpu definition info type gets
  an optional field named 'accelerators' which holds a list defining
  which cpu model is 'runnable' and in addition which one the 'default'
  cpu model is (i.e. the model to be used in the 'host' case).

  [{"name":"2964-ga1",
"accelerators":[{"name":"kvm","runnable":false,"default":false}]}

Or just 'host' in case an accelerator does not implement cpu models yet:

  [{"name":"host"}]

- For accel=kvm the cpu model initialization takes place in kvm_arch_init()

What's currently a little bit unclear to me is how to best initialize the
various accelerators for machine 'none'. I played around with different
options and finally came up with the following sugguestion:

Introduce a QEMU "probe mode" that gets entered in case the current machine
is "none" and no specific accelerator is requested on the cmd line. When
in that mode, loop trough a list of acellerators in configure_accelerator
and invoke all their init methods once. The last accelerator to init shall
be tcg.

In cpu model context that allows to initialize the S390 CPU classes for
each single accelertor which supports it. Whence the callback for
qemu-cpu-definitions allows to populate its answer string according to the
above sketched extended CpuDefinitionInfo type for multiplaccelerators. 

v2-v3:
- using GTK-Doc style format now for function descriptions
- typo fixed (2/16)
- gen-facilties now used to generate cpu model specific facility lists
  and the qemu side facility mask during build time (5/16)
- gen-facilities added to make magic (5/16)
- element of struct S390CPUMachineProps now statically in cpu class (6/16)
- element of struct S390CPUProcessorProps now statically in cpu class (6/16)
- facility list also static now (6/16)
- typo fixed (7/16)
- zBC12-ga1 model now active on zEC12-ga2 host (11/16)
- operations on facility lists use QEMU bitmap API now (11/16)
- routine s390_cpu_model_init() introduced, called during cpu object
  realization to prepare the current accelarator (12/16) if a cpu
  model was selected
- missing comment added in description of CpuModelInfo type (13/16)
- accelerator field now mandatory for "query-cpu-model" (13/16)
- sorted list related comment to "query-cpu-definitions" dropped in
  commit message (13/16)
- comment for AccelCpuInfo type updated (13/16)
- routine s390_facility_test() factored out (15/16)

v1-v2:
- QEMU-side facility list mask introduced: this allows to enable guest
  facilities that are handled by instruction interception handlers
  implemented on qemu side. Similar to the facilities enabled by means
  of the KVM side facility list mask which are handled by kvm/kernel.
- Concept of soft facilities has been dropped 
- Result type of QMP command query-cpu-definitions extended to hold
  additional information beside the cpu model name including which
  cpu model is runnable in current accelerator and machine context. 

Michael Mueller (16):
  Introduce probe mode for machine type none
  Introduce option --probe to switch into probe mode
  Introduce stub routine cpu_desc_avail
  target-s390x: Introduce cpu facilities
 

Re: [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 18:50:20 +0100
Alexander Graf  wrote:

> 
> 
> 
> > Am 20.02.2015 um 18:37 schrieb Michael Mueller :
> > 
> > On Fri, 20 Feb 2015 17:57:52 +0100
> > Alexander Graf  wrote:
> > 
> >> Because all CPUs we have in our list only expose 128 bits?
> > 
> > Here a STFLE result on a EC12 GA2, already more than 128 bits... Is that 
> > model on the list?
> 
> If that model has 3 elements, yes, the array should span 3.
> 
> I hope it's in the list. Every model wecare about should be, no?
> 

On my list? Yes!

> > 
> > [mimu@p57lp59 s390xfac]$ ./s390xfac -b
> > fac[0] = 0xfbfbfcfff840
> > fac[1] = 0xffde
> > fac[2] = 0x1800
> >> 
> >>> I want to have this independent from a future machine of the z/Arch. The 
> >>> kernel stores the
> >>> full facility set, KVM does and there is no good reason for QEMU not to 
> >>> do. If other
> >>> accelerators decide to just implement 64 or 128 bits of facilities that's 
> >>> ok...  
> >> 
> >> So you want to support CPUs that are not part of the list?
> > 
> > The architecture at least defines more than 2 or 3. Do you want me to limit 
> > it to an arbitrary
> > size?. Only in QEMU or also in the KVM interface?
> 
> Only internally in QEMU. The kvm interface should definitely be as big as the 
> spec allows!

Right, now we're on the same page again. That can be taken in consideration. 
... Although it's
just and optimization. :-)

Michael

> 
> Alex
> 
> > 
> > Thanks
> > Michael
> > 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 20:21:45 +0100
Alexander Graf  wrote:

> 
> 
> 
> > Am 20.02.2015 um 19:59 schrieb Michael Mueller :
> > 
> > On Fri, 20 Feb 2015 10:11:55 -0800
> > Richard Henderson  wrote:
> > 
> >>> +static inline uint64_t big_endian_bit(unsigned long nr)
> >>> +{
> >>> +return 1ul << (BITS_PER_LONG - (nr % BITS_PER_LONG));
> >>> +};  
> >> 
> >> This is buggy.  NR=0 should map to 63, not 64.
> > 
> > I'm sure I was asked to replace my constant 64 and 63 with that defines and 
> > at the end I
> > messed it up... :-(
> > 
> >> 
> >>> +return !!(*ptr & big_endian_bit(nr));  
> >> 
> >> Personally I dislike !! as an idiom.  Given that big_endian_bit isn't used
> >> anywhere else, can we integrate it and change this to
> >> 
> >> static inline int test_facility(unsigned long nr, uint64_t *fac_list)
> >> {
> >>  unsigned long word = nr / BITS_PER_LONG;
> >>  unsigned long be_bit = 63 - (nr % BITS_PER_LONG);
> >>  return (fac_list[word] >> be_bit) & 1;
> >> }
> > 
> > Yes, I just use it in this context. I will integrate your version.
> > 
> > BTW I changed the whole facility defining code to be generated by an 
> > external helper at
> > compile time. That is more simple and safe to change. I will send it with 
> > v3. See attachment
> > for an example of the generated header file.
> 
> Please make sure to use ULL with constants and uint64_t on variables. Long is 
> almost always
> wrong in QEMU.

yep

> 
> Alex
> 
> > 
> > Thanks,
> > Michael
> > 
> > 
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 18:00:19 +0100
Alexander Graf  wrote:

> > So above s390_set/get_processor_props() the code is accelerator 
> > independent.  
> 
> Any particular reason you can't do it like PPC?

That seems to be a short question... and when I started one year ago, I 
oriented myself on
the PPC version and I'm also willing to revisit it but I can't give you a quick 
answer different
from no currently to that.

There are no PVRs for s390x CPUs and thus I came up with "pseudo PVRs":

/*
 * bits 0-7   : CMOS generation
 * bits 8-9   : reserved
 * bits 10-11 : machine class 0=unknown 1=EC 2=BC
 * bits 12-15 : GA
 * bits 16-31 : machine type
 *
 * note: bits are named according to s390
 *   architecture specific endienness
 */
enum {
CPU_S390_2064_GA1 = 0x07112064,
CPU_S390_2064_GA2 = 0x07122064,
CPU_S390_2064_GA3 = 0x07132064,
CPU_S390_2066_GA1 = 0x07212066,
CPU_S390_2084_GA1 = 0x08112084,
CPU_S390_2084_GA2 = 0x08122084,
CPU_S390_2084_GA3 = 0x08132084,
CPU_S390_2084_GA4 = 0x08142084,
CPU_S390_2084_GA5 = 0x08152084,
CPU_S390_2086_GA1 = 0x08212086,
CPU_S390_2086_GA2 = 0x08222086,
CPU_S390_2086_GA3 = 0x08232086,
CPU_S390_2094_GA1 = 0x09112094,
CPU_S390_2094_GA2 = 0x09122094,
CPU_S390_2094_GA3 = 0x09132094,
CPU_S390_2096_GA1 = 0x09212096,
CPU_S390_2096_GA2 = 0x09222096,
CPU_S390_2097_GA1 = 0x0a112097,
CPU_S390_2097_GA2 = 0x0a122097,
CPU_S390_2097_GA3 = 0x0a132097,
CPU_S390_2098_GA1 = 0x0a212098,
CPU_S390_2098_GA2 = 0x0a222098,
CPU_S390_2817_GA1 = 0x0b112817,
CPU_S390_2817_GA2 = 0x0b122817,
CPU_S390_2818_GA1 = 0x0b212818,
CPU_S390_2827_GA1 = 0x0c112827,
CPU_S390_2827_GA2 = 0x0c122827,
CPU_S390_2828_GA1 = 0x0c212828,
CPU_S390_2964_GA1 = 0x0d112964,
};

And initially I had a version that was limiting the accelerator to be able to 
implement just them
with all their properties encapsulated in the a accelerator as well. After 
identifying the real
processor related attributes defining the model, I changed the interface such 
that KVM or
other accelerators give hints what it is able to support in dependency of the 
current code
version and the hosting machine and let QEMU decide how to set these attributes
(cpuid,ibc,fac_list). Thus I think the implementation is now quite open and 
easily adoptable also
for TCG and possibly others as well. Eventually the integration and also some 
trigger points of
my code are to adjust. So coming back to your question, the answer is still no 
for the whole item
but eventually yes if you have limited it to the s390_set/get_processor_props() 
triggers. But I
have to look into it first again. I will do that when I'm back on Tuesday 
morning.

Thanks and have a nice WE
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 10:11:55 -0800
Richard Henderson  wrote:

> > +static inline uint64_t big_endian_bit(unsigned long nr)
> > +{
> > +return 1ul << (BITS_PER_LONG - (nr % BITS_PER_LONG));
> > +};  
> 
> This is buggy.  NR=0 should map to 63, not 64.

I'm sure I was asked to replace my constant 64 and 63 with that defines and at 
the end I messed
it up... :-(

> 
> > +return !!(*ptr & big_endian_bit(nr));  
> 
> Personally I dislike !! as an idiom.  Given that big_endian_bit isn't used
> anywhere else, can we integrate it and change this to
> 
> static inline int test_facility(unsigned long nr, uint64_t *fac_list)
> {
>   unsigned long word = nr / BITS_PER_LONG;
>   unsigned long be_bit = 63 - (nr % BITS_PER_LONG);
>   return (fac_list[word] >> be_bit) & 1;
> }

Yes, I just use it in this context. I will integrate your version.

BTW I changed the whole facility defining code to be generated by an external 
helper at compile
time. That is more simple and safe to change. I will send it with v3. See 
attachment for an
example of the generated header file.

Thanks,
Michael

/*
 * AUTOMATICALLY GENERATED, DO NOT MODIFY HERE, EDIT
 * SOURCE FILE "target-s390x/tools/gen-facilities.c" INSTEAD.
 *
 * Copyright 2014, 2015 IBM Corp.
 *
 * 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_GEN_FACILITIES_H
#define TARGET_S390X_GEN_FACILITIES_H

/* S390 CPU facility defines per CPU model */
#define FAC_LIST_CPU_S390_2064_GA1 0xe000
#define FAC_LIST_CPU_S390_2064_GA2 0xe0008000
#define FAC_LIST_CPU_S390_2064_GA3 0xe0008000
#define FAC_LIST_CPU_S390_2066_GA1 0xe0008000
#define FAC_LIST_CPU_S390_2084_GA1 0xf000f800
#define FAC_LIST_CPU_S390_2084_GA2 0xf800f800
#define FAC_LIST_CPU_S390_2084_GA3 0xfa00fa00
#define FAC_LIST_CPU_S390_2086_GA1 0xfa00fa00
#define FAC_LIST_CPU_S390_2084_GA4 0xfa00fa00
#define FAC_LIST_CPU_S390_2086_GA2 0xfa00fa00
#define FAC_LIST_CPU_S390_2084_GA5 0xfa00fa08
#define FAC_LIST_CPU_S390_2086_GA3 0xfa00fa08
#define FAC_LIST_CPU_S390_2094_GA1 0xfb00ffcb
#define FAC_LIST_CPU_S390_2094_GA2 0xfb40ffdb8060
#define FAC_LIST_CPU_S390_2094_GA3 0xfb40ffdb8068
#define FAC_LIST_CPU_S390_2096_GA1 0xfb40ffdb8068
#define FAC_LIST_CPU_S390_2096_GA2 0xfb40ffdb8068
#define FAC_LIST_CPU_S390_2097_GA1 0xfbf0fffbf078
#define FAC_LIST_CPU_S390_2097_GA2 0xfbf0fffbf078,0x5800
#define FAC_LIST_CPU_S390_2098_GA1 0xfbf0fffbf078,0x5800
#define FAC_LIST_CPU_S390_2097_GA3 0xfbf0fffbf0f8,0x5800
#define FAC_LIST_CPU_S390_2098_GA2 0xfbf0fffbf0f8,0x5800
#define FAC_LIST_CPU_S390_2817_GA1 0xfbf0fffbfcfe,0x1810
#define FAC_LIST_CPU_S390_2817_GA2 0xfbf6fffbfcff,0x381c
#define FAC_LIST_CPU_S390_2818_GA1 0xfbf6fffbfcff,0x381c
#define FAC_LIST_CPU_S390_2827_GA1 0xfbf6fffbfcfff800,0x3dde
#define FAC_LIST_CPU_S390_2827_GA2 0xfbf6fffbfcfff800,0x3dde
#define FAC_LIST_CPU_S390_2828_GA1 0xfbf6fffbfcfff800,0x3dde
#define FAC_LIST_CPU_S390_2964_GA1 0xfbf6fffbfcfff800,0x3dde,0x4000

/* QEMU facility mask defines */
#define FAC_LIST_CPU_S390_MASK_QEMU 0x,0x0580

/* Maximum size of generated facility list defines */
#define FAC_LIST_CPU_S390_SIZE_UINT64 3

#endif


Re: [Qemu-devel] [RFC PATCH v2 09/15] cpu-model/s390: Add KVM VM attribute interface routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 17:59:14 +0100
Alexander Graf  wrote:

> But please give a nutshell explanation on what exactly you're patching
> at all here.

Please don't ask in riddles... :-)

S390ProcessorProps are attributes that represent cpu model related properties 
of the processor. 

typedef struct S390ProcessorProps {
uint64_t cpuid;
uint16_t ibc;
uint8_t  pad[6];
uint64_t fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64];
} S390ProcessorProps;

S390MachineProps are attributes that represent cpu model related properties 
that a specific host
offers.

fac_list_mask are the facilities that are supported by the accelerator code and 
the hosting
machine in case of KVM it is kvm_s390_fac_list_mask & STFLE, fac_list is STFLE 
only

typedef struct S390MachineProps {
uint64_t cpuid;
uint32_t ibc_range;
uint8_t  pad[4];
uint64_t fac_list_mask[S390_ARCH_FAC_LIST_SIZE_UINT64];
uint64_t fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64];
} S390MachineProps;

The various S390CPUModel classes represent all well defined cpu models (those 
which have been
implemented as real machines). Not all of these models are executable on a 
given host. Only the
most current machine implementation is able to run all models. The list of 
"runnable" cpu models
is calculated by "matching" the S390MachineProps with the S390CPUModel classes 
and the
qemu_s390_fac_list_mask[] (indicates the facilities that are implemented by 
QEMU itself.)

The qemu cpu_model is translated to the respective S390CPUModel class and its 
processor
properties (S390ProcessorProps) are used with the s390_set_proceccor_props() 
call to communicate
them to the accelerator what specific cpuid,ibc,fac_list shall be used.

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 17:57:52 +0100
Alexander Graf  wrote:

> Because all CPUs we have in our list only expose 128 bits?

Here a STFLE result on a EC12 GA2, already more than 128 bits... Is that model 
on the list?

[mimu@p57lp59 s390xfac]$ ./s390xfac -b
fac[0] = 0xfbfbfcfff840
fac[1] = 0xffde
fac[2] = 0x1800
> 
> > I want to have this independent from a future machine of the z/Arch. The 
> > kernel stores the
> > full facility set, KVM does and there is no good reason for QEMU not to do. 
> > If other
> > accelerators decide to just implement 64 or 128 bits of facilities that's 
> > ok...  
> 
> So you want to support CPUs that are not part of the list?

The architecture at least defines more than 2 or 3. Do you want me to limit it 
to an arbitrary
size?. Only in QEMU or also in the KVM interface?

Thanks
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 17:34:28 +0100
Andreas Färber  wrote:

> Please note that QEMU uses gtk-doc style, where the description goes
> between arguments and Returns:, and the function name gets a ':'.
> There's also fancy syntax like #CPUClass, %true, etc.

On my TODOs...

Thanks,
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 17:28:14 +0100
Andreas Färber  wrote:

Andreas,

> Sorry for my ignorance, but what is proc actually needed for? For
> initializing the class, there's .class_init (and cc->fac_list apparently
> is initialized here). If you need to pass info to KVM, you can do so in

yes, it is communication to the accelerator to prepare its local cpu model 
related data
structures which are used to initialize a vcpu (e.g. the facility list beside 
others) 

> DeviceClass::realize when the vCPU actually goes "live". A

I will look what "goes live" in detail means here, it should at least be before
kvm_arch_vcpu_setup() gets triggered on accelerator side.

> string-to-string (or string-to-ObjectClass) translation function seems
> like a weird point in time to take action with global effect.
> 
> Anyway, please implement the generic callback, then you can still call
> it from your own helper functions if needed.

Thanks a lot!
Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 17:12:49 +0100
Michael Mueller  wrote:

> Good spot, it's not being used yet. It's planned to be used with a patch that 
> implements zPCI
> related instructions on QEMU side. Maybe you have seen the discussion from 
> Frank Blaschka in
> this e-mail list in regard to that.

I will factor it out.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 08:02:42 -0800
Richard Henderson  wrote:

> > +/**
> > + * s390_test_facility - test if given facility bit is set facility list
> > + *  of given cpu class
> > + * @class: address of cpu class to test
> > + * @nr: bit number to test
> > + *
> > + * Returns: true in case it is set
> > + *  false in case it is not set
> > + */
> > +bool s390_test_facility(S390CPUClass *cc, unsigned long nr)
> > +{
> > +if (cc) {
> > +return test_facility(nr, cc->fac_list) ? true : false;
> > +}
> > +return false;
> > +}  
> 
> Where do you see this being used?

Good spot, it's not being used yet. It's planned to be used with a patch that 
implements zPCI
related instructions on QEMU side. Maybe you have seen the discussion from 
Frank Blaschka in this
e-mail list in regard to that.

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 16:41:49 +0100
Andreas Färber  wrote:

> Also a general comment: cpu-model/ is not an existing directory nor one
> you add, so please use "target-s390x: Add foo to S390CPU" or so.

I will address this with v3, thanks a lot for the hint, I never saw this as 
directories though...

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 16:41:49 +0100
Andreas Färber  wrote:

> Can't you just implement the class-level name-to-ObjectClass callback
> that other CPUs have grown for the above use case?

If it fulfills the requirements sure. Please point me to an example, sounds that
s390_select_cpu_model() is doing something similar to that, just that it hooks 
in
the s390_set_processor_props() call.

const char *s390_select_cpu_model(const char *model)
{
S390ProcessorProps proc;
const char *typename;
S390CPUClass *cc;

/* return already selected cpu typename */
typename = s390_cpu_typename();
if (typename) {
goto out;
}

/* return standard cpu typename when cpu models are unavailable */
typename = TYPE_S390_CPU;
if (!s390_cpu_classes_initialized() || !model) {
goto out;
}
cc = S390_CPU_CLASS(s390_cpu_class_by_name(model));
if (!cc) {
goto out;
}
proc.cpuid = cpuid(cc->proc);
proc.ibc = cc->proc->ibc;
memcpy(proc.fac_list, cc->fac_list, S390_ARCH_FAC_LIST_SIZE_BYTE);
if (s390_set_processor_props(&proc)) {
goto out;
}

/* return requested cpu typename in success case */
typename = object_class_get_name((ObjectClass *) cc);
out:
selected_cpu_typename = typename;
trace_select_cpu_model(model, typename);
return typename;
}


> 
> Also a general comment: cpu-model/ is not an existing directory nor one
> you add, so please use "target-s390x: Add foo to S390CPU" or so.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 16:22:20 +0100
Alexander Graf  wrote:

> >> 
> >> Just make this uint64_t fac_list[2]. That way we don't have to track any
> >> messy allocations.  
> > 
> > It will be something like "uint64_t 
> > fac_list[S390_CPU_FAC_LIST_SIZE_UINT64]" and in total 2KB
> > not just 16 bytes but I will change it.   
> 
> Why? Do we actually need that many? This is a qemu internal struct.

How do you know that 2 is a good size?

I want to have this independent from a future machine of the z/Arch. The kernel 
stores the full
facility set, KVM does and there is no good reason for QEMU not to do. If other 
accelerators
decide to just implement 64 or 128 bits of facilities that's ok...

Michael

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 13/15] cpu-model/s390: Add processor property routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 15:03:30 +0100
Alexander Graf  wrote:

> > 
> > - s390_get_proceccor_props()
> > - s390_set_proceccor_props()
> > 
> > They can be used to request or retrieve processor related information from 
> > an accelerator.
> > That information comprises the cpu identifier, the ICB value and the 
> > facility lists.
> > 
> > Signed-off-by: Michael Mueller   
> 
> Hrm, I still seem to miss the point of this interface. What do you need
> it for?

These functions make the internal s390 cpu model API independent from a 
specific accelerator:  

int s390_set_processor_props(S390ProcessorProps *prop)
{
if (kvm_enabled()) {
return kvm_s390_set_processor_props(prop);
}
return -ENOSYS;
}

It's called by:

s390_select_cpu_model(const char *model)

which is itself called by:

S390CPU *cpu_s390x_init(const char *cpu_model)
{
S390CPU *cpu;

cpu = S390_CPU(object_new(s390_select_cpu_model(cpu_model)));

object_property_set_bool(OBJECT(cpu), true, "realized", NULL);

return cpu;
}

So above s390_set/get_processor_props() the code is accelerator independent.

Michael





--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 09/15] cpu-model/s390: Add KVM VM attribute interface routines

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 14:59:20 +0100
Alexander Graf  wrote:

> > +typedef struct S390ProcessorProps {
> > +uint64_t cpuid;
> > +uint16_t ibc;
> > +uint8_t  pad[6];
> > +uint64_t fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64];
> > +} S390ProcessorProps;
> > +
> > +typedef struct S390MachineProps {
> > +uint64_t cpuid;
> > +uint32_t ibc_range;
> > +uint8_t  pad[4];
> > +uint64_t fac_list_mask[S390_ARCH_FAC_LIST_SIZE_UINT64];
> > +uint64_t fac_list[S390_ARCH_FAC_LIST_SIZE_UINT64];
> > +} S390MachineProps;  
> 
> What are those structs there for? To convert between a kvm facing
> interface to an internal interface?

Yes, that's their current use, but if the interface structs: 

+struct kvm_s390_vm_cpu_processor {
+   __u64 cpuid;
+   __u16 ibc;
+   __u8  pad[6];
+   __u64 fac_list[256];
+};
+
+/* kvm S390 machine related attributes are r/o */
+#define KVM_S390_VM_CPU_MACHINE1
+struct kvm_s390_vm_cpu_machine {
+   __u64 cpuid;
+   __u32 ibc_range;
+   __u8  pad[4];
+   __u64 fac_mask[256];
+   __u64 fac_list[256];
+};

are visible here, I'll reuse them... But stop, that will not work in the 
--disable-kvm case... I need them!
> 
> I don't think they're necessary. The internal layout is visible from the
> KVM code. Just either spawn the class straight from the kvm file or if
> you consider that ugly, pass the values of that struct that you need as
> function parameters to a function in cpu-models.c.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 14:55:32 +0100
Alexander Graf  wrote:

> >  /**
> >   * S390CPUClass:
> >   * @parent_realize: The parent class' realize handler.
> > @@ -52,6 +69,11 @@ typedef struct S390CPUClass {
> >  void (*load_normal)(CPUState *cpu);
> >  void (*cpu_reset)(CPUState *cpu);
> >  void (*initial_cpu_reset)(CPUState *cpu);
> > +bool is_active[ACCEL_ID_MAX]; /* model enabled for given host and 
> > accel */
> > +bool is_host[ACCEL_ID_MAX];   /* model markes host for given accel */
> > +uint64_t *fac_list;   /* active facility list */
> > +S390CPUMachineProps   *mach;  /* machine specific properties */
> > +S390CPUProcessorProps *proc;  /* processor specific properties */  
> 
> Sorry, same here. Just put the structs straight into the class struct.

Yep, consistent.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 04/15] cpu-model/s390: Introduce S390 CPU models

2015-02-20 Thread Michael Mueller
On Fri, 20 Feb 2015 14:54:23 +0100
Alexander Graf  wrote:

> >  
> > +/* machine related properties */
> > +typedef struct S390CPUMachineProps {
> > +uint16_t class;  /* machine class */
> > +uint16_t ga; /* availability number of machine */
> > +uint16_t order;  /* order of availability */
> > +} S390CPUMachineProps;
> > +
> > +/* processor related properties */
> > +typedef struct S390CPUProcessorProps {
> > +uint16_t gen;/* S390 CMOS generation */
> > +uint16_t ver;/* version of processor */
> > +uint32_t id; /* processor identification*/
> > +uint16_t type;   /* machine type */
> > +uint16_t ibc;/* IBC value */
> > +uint64_t *fac_list;  /* list of facilities */  
> 
> Just make this uint64_t fac_list[2]. That way we don't have to track any
> messy allocations.

It will be something like "uint64_t fac_list[S390_CPU_FAC_LIST_SIZE_UINT64]" 
and in total 2KB not
just 16 bytes but I will change it. 



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [RFC PATCH v2 12/15] cpu-model/s390: Extend QMP command query-cpu-definitions

2015-02-18 Thread Michael Mueller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, 17 Feb 2015 11:09:34 -0700
Eric Blake  wrote:

> On 02/17/2015 07:24 AM, Michael Mueller wrote:
> > This patch implements the QMP command 'query-cpu-definitions' in the S390
> > context. The command returns a in terms of machine release date descending
> > sorted list of cpu model names in the current host context.
> 
> returns a list of cpu model names sorted by descending release dates.
> 
> Does guaranteeing the sorting as part of the interface really matter, or
> would it be better to just return the list with no documented sorting
> (where callers treat it as unsorted)?

Yep, that is an implementation detail and I don't depend on that. If a sequence 
would be required
one cold model a field named "order". But as said, I don't require that and 
will update the
comment by dropping the "sorted list" part.

> 
> > A consumer may
> > successfully request each listed cpu model as long for a given accelerator
> > this model is runnable.
> > 
> > Thy QMP type AccelCpuModelInfo is introduced and the type CpuDefinitionInfo
> > is extended by the optional field 'accelerators'. It contains a list of 
> > named
> > accelerators and some indication whether the associated cpu model is 
> > runnable
> > or the default cpu model. The default cpu model is used either no specific 
> > cpu
> > was requested during QEMU startup or the cpu model with named 'host'.
> > 
> > request:
> >   {"execute": "query-cpu-definitions"}
> > 
> > answer:
> >   {"return":
> > 
> > [{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
> >  
> > {"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]},
> >  
> > {"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> >  
> > {"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
> >  ...
> >  
> > {"name":"2064-ga1","accelerators":[{"runnable":true,"name":"kvm","default":false}]}
> > ]
> >}
> > 
> 
> Looks okay from an interface perspective.
> 
> > Signed-off-by: Michael Mueller 
> > ---
> >  qapi-schema.json  |  21 +-
> >  target-s390x/cpu-models.c |  15 +++
> >  target-s390x/cpu-models.h |   1 +
> >  target-s390x/cpu.c| 100 
> > +++---
> >  4 files changed, 130 insertions(+), 7 deletions(-)
> > 
> > diff --git a/qapi-schema.json b/qapi-schema.json
> > index 9431fc2..a5d38ae 100644
> > --- a/qapi-schema.json
> > +++ b/qapi-schema.json
> > @@ -2485,16 +2485,35 @@
> >'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
> >  
> >  ##
> > +# @AccelCpuModelInfo:
> > +#
> > +# Accelerator specific CPU model data
> > +#
> > +# @id: the accelerator id
> > +#
> 
> There is no 'id' field below, did you mean 'name'?

I did rename that one time to often :-), will s/id/name/g ...

> 
> > +# @default: cpu model for 'host'
> > +#
> > +# @runnable: cpu model can be activated on hosting machine
> > +#
> > +# Since: 2.3.0
> > +#
> > +##
> > +{ 'type': 'AccelCpuModelInfo',
> > +  'data': { 'name': 'AccelId', 'default': 'bool', 'runnable': 'bool' } }
> > +
> > +##
> >  # @CpuDefinitionInfo:
> >  #
> >  # Virtual CPU definition.
> >  #
> >  # @name: the name of the CPU definition
> >  #
> > +# @accelerators: #optional cpu model offered per accelerator (since 2.3.0)
> > +#
> 
> Must the field be optional, or will we always provide it?  Since this is
> an output-only field, it is okay for back-compat to make the new field
> unconditional.

It will be always provided when an accelerator supports cpu models and 
implements the
probing mode. As I'm currently adopting it for s390/kvm only, I can't enforce 
it for all
other arch/accelerator combinations as it is an extension of an existing 
command...

Thanks
Michael

> 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJU5Ft5AAoJELPcPLQSJsKQ520P/A3EQqyY7buhBZWwVDQcA49J
FSzjyEt2JAJmZAlMFMaxbVDwJcm5PXEbCHR1+NuDXuyEYsPxqG7TxvP+3yLR2lLa
QbucHGd9M789Tg0hy2YPifIIB93LY5Kb3SNxhL52olyIrnsovHoBCbboMlmmKTk7
KyH6q2KXddjWtZbHy9WGQY91r56yMdsbfIxbYMJuJbJ/9Hr0lh0xB6W77mL8GIrV
dbURjaZXwgoGecVAlyEQcpInS2fl6XSX7Y2rCAq9Jp/9ZNfSQdOai19Md2cQ1JLi
92qYwgT8XV6bZOHJ1E8xc7+KlJRRH4MvYbWTNCVHEA3ewE5rYkspe92fEj82GZnc
eJV+hjZcq9cNaOF8bvhpjy+9zW8WdrwsQKbXNEeJDzDmnYhaaKcdKRa6qUDwYLQW
eg+TAfO+G9YNYfEpJH5okCo3t7elpYlkdcOvNtj1X2gFAmpjkbeVOUWSD1JmtJ5u
+s3XUagvQdzoIdpsziob0NEpLU62QFcqAa3ZNSY/FE7itTMnZs2+rvbYUxGyRjqz
BbEwPDoAMcFCO6CdK/hoZxV8RbCRH+MoDy+oLKXbxsF1rJcFfe5VGUQBTbYJUNEO
l87sUJBw5AqcU5/VpnuQn/unVCupQxour63T6WxzobvFT+rpMIR8mUQXaAEe9RfJ
8G8A5VXn8C4zrC2Am5G5
=cpfo
-END PGP SIGNATURE-


Re: [Qemu-devel] [RFC PATCH v2 02/15] cpu-model: Introduce option --probe to switch into probe mode

2015-02-18 Thread Michael Mueller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, 17 Feb 2015 12:16:20 -0700
Eric Blake  wrote:

> On 02/17/2015 07:24 AM, Michael Mueller wrote:
> > The option --probe allows to switch into probe mode also for machines
> > different from none. If one or more accelerators are specified these
> > accelerators are used to provide probable properties. If no accelerator
> > is given a list of accellerators that support probing is used.
> 
> s/accellerators/accelerators/

ups

> 
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> >  accel.c| 13 -
> >  include/sysemu/accel.h |  2 +-
> >  qemu-options.hx|  8 
> >  vl.c   |  7 ++-
> >  4 files changed, 23 insertions(+), 7 deletions(-)
> > 
> 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJU5FZ/AAoJELPcPLQSJsKQxGMP/0MnqhT4bAL98hgRnhPZyoEt
wGSB4zoBQ0VnhQ7XiXe2HhVn2y8I9XI2pn/GpQgDInlMQ7HYhM7UtWD3/Wlrp0ky
MyCNrsD0/cT3bjAhZ0OlGC3fqujVLVmxGc5wQrmymYKKNaWMoDNQt3PFYk6ZKHSh
2RzLFkWSzx3iWKcsZ5aA0Sxms21L0c+TPx9/EAvUohyul5tyGe0Sf7TleS0YBjLH
O4y1QmiXaFdGLag/wp535bSG1s4JkOxYgWKWohxVs7qwl0NNMbQPiL1Z9NO3ushs
5J9BjLD54fhmXnHEFHBaS1o//hL12wkssyUBdiCObpANltGZN23qvsh5zh2Rv/Sb
QqYDCBimqxn5Y4J9xUIzONNmrQ3y5jyJTuNK0Q9Wd9lEklgs9r5Bn/ro0/zKSCVH
zgLsjFqS6Rh2MZnu8Vvi8bEtle7zwYiQ0TfpFn1oaGJlzO7+9S6RbLIAO0XQlDxT
0R097n3D0VtLVznyHvJuRdyO4fdNuy4joo03Oej0/8HpKqaQxZhUSP7ReaIvcqyw
kqM2q0wPyIemFrg6WrNb2pVAqljSFOHNl0dNQPuoprWP3M6cXVWfE8IO01kjNIiy
muR2dh2w03JiPm3jwNEe+bEsw3lx7cLYx5fxh/8A7VD5Fh9nIVEawJXG5359hUiV
etSL5sdva53IUMkxWetu
=FFkJ
-END PGP SIGNATURE-


Re: [Qemu-devel] [RFC PATCH v2 11/15] cpu-model/s390: Add QMP command query-cpu-model

2015-02-18 Thread Michael Mueller
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Tue, 17 Feb 2015 11:03:11 -0700
Eric Blake  wrote:

> On 02/17/2015 07:24 AM, Michael Mueller wrote:
> > This patch implements a new QMP request named 'query-cpu-model'.
> > It returns the cpu model of cpu 0 and its backing accelerator.
> > 
> > request:
> >   {"execute" : "query-cpu-model" }
> > 
> > answer:
> >   {"return" : {"name": "2827-ga2", "accelerator": "kvm" }}
> > 
> > Alias names are resolved to their respective machine type and GA names
> > already during cpu instantiation. Thus, also a cpu model like 'host'
> > which is implemented as alias will return its normalized cpu model name.
> > 
> > Furthermore the patch implements the following functions:
> > 
> > - s390_cpu_typename(), returns the currently selected cpu type name or NULL
> > - s390_cpu_models_used(), returns true if S390 cpu models are in use
> > 
> > Signed-off-by: Michael Mueller 
> > ---
> >  
> > +##
> > +# @CpuModelInfo:
> > +#
> > +# Virtual CPU model definition.
> > +#
> > +# @name: the name of the CPU model definition
> > +#
> > +# Since: 2.3.0
> > +##
> > +{ 'type': 'CpuModelInfo',
> > +  'data': { 'name': 'str', '*accelerator': 'AccelId' } }
> 
> You didn't document '*accelerator', including mention that it is
> optional (why would it not be output always?).

Right, as it is a new command and all cpus once implementing it have an 
associated accelerator
there is no point in making it optional. Will add a comment as well.
> 
> > +
> > +##
> > +# @query-cpu-model:
> > +#
> > +# Return to current virtual CPU model
> 
> s/to/the/

yep

> 
> > +#
> > +# Returns: CpuModelInfo
> > +#
> > +# Since: 2.3.0
> 
> We aren't very consistent on '2.3' vs. '2.3.0', so I won't complain
> about that.

But you seem to prefer major and minor only, so I will skip the trailing 0.

> 
> > +##
> > +{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
> 
> Seems reasonable from the interface point of view; I have not closely
> reviewed the implementation.
> 

Thanks
Michael
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iQIcBAEBAgAGBQJU5E/fAAoJELPcPLQSJsKQYksP/inWhcSnQF6WgNTaF2qsEqyG
6kRyAwfVID9k0Rh1Eh3fDKbDDrtXe1pB3dbHlX6JWWrDCQCzfFxbRDElK3lX4k1g
ryAi9ZRPZ7TB88eGIS66vQ4J/O9WWe/I7tzoX2yeFcMRNa9+8dpyluPHWNYbeN6f
KkzQy15PabCiggwQuDfm+X4jiV7HtIdxRVNuOJV4j2U8p6Wp5YaZMEp8MJQ2tDMe
Uion91VZ2izLQ/rn+QIb1F28om03LWfh47sKzam9l9oomFglGhmHXkEktL+KCQTK
MSUQOiIK3rSzZiFq5dsjIAOo1bkrjYpPxUfxq0xDjreJoGkd1sbtQ663QHG0RUTT
1G0BNKHxNggkxoxyChaEYWopNyZ2wMEn3XBaVHvnfDqDyymsWo3nAQVWIMwFpHth
vSfBLY3CJnAW4HnDiaV3+sNDlFZlttzPE5jVXibR98sCdQORNEpCt9frdu1AToGB
MCiAwJMc1qescJMghsogCUzG9ElA7wbvGIv+e/uEGj7LB/1H0ZMIpN/QU9NDd3Fi
XpldGvPLIWRJq7/l8c6/KNg8SbTn1prtGZ1pKNOlkmn+BeEQjcihEmGOStoWny48
1hT08enhBJ9skXvWlGTvYBlohQ6vERwZ5B9E4tmSeLRQG+4YkE3JTyb0FJJScBoV
l1X+PmwiT2AfeXLlDHlm
=6Qmi
-END PGP SIGNATURE-


[RFC PATCH v2 03/15] cpu-model: Introduce stub routine cpu_desc_avail

2015-02-17 Thread Michael Mueller
This patch introduces the function cpu_desc_avail() which returns by
default true if not architecture specific implemented. Its intention
is to indicate if the cpu model description is available for display
by list_cpus(). This change allows cpu model descriptions to become
dynamically created by evaluating the runtime context instead of
putting static cpu model information at display.

Signed-off-by: Michael Mueller 
Reviewed-by: Thomas Huth 
---
 include/qemu-common.h  | 2 ++
 stubs/Makefile.objs| 1 +
 stubs/cpu-desc-avail.c | 6 ++
 vl.c   | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 stubs/cpu-desc-avail.c

diff --git a/include/qemu-common.h b/include/qemu-common.h
index 644b46d..45040f9 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -481,4 +481,6 @@ int parse_debug_env(const char *name, int max, int initial);
 
 const char *qemu_ether_ntoa(const MACAddr *mac);
 
+bool cpu_desc_avail(void);
+
 #endif
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5e347d0..fd7a489 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -40,3 +40,4 @@ stub-obj-$(CONFIG_WIN32) += fd-register.o
 stub-obj-y += cpus.o
 stub-obj-y += kvm.o
 stub-obj-y += qmp_pc_dimm_device_list.o
+stub-obj-y += cpu-desc-avail.o
diff --git a/stubs/cpu-desc-avail.c b/stubs/cpu-desc-avail.c
new file mode 100644
index 000..0cd594e
--- /dev/null
+++ b/stubs/cpu-desc-avail.c
@@ -0,0 +1,6 @@
+#include "qemu-common.h"
+
+bool cpu_desc_avail(void)
+{
+return true;
+}
diff --git a/vl.c b/vl.c
index 0fabc0b..130fb1e 100644
--- a/vl.c
+++ b/vl.c
@@ -3819,7 +3819,7 @@ int main(int argc, char **argv, char **envp)
  */
 cpudef_init();
 
-if (cpu_model && is_help_option(cpu_model)) {
+if (cpu_model && cpu_desc_avail() && is_help_option(cpu_model)) {
 list_cpus(stdout, &fprintf, cpu_model);
 exit(0);
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH v2 07/15] cpu-model/s390: Add cpu model alias definition routines

2015-02-17 Thread Michael Mueller
This patch implements the infrastructure to dynamically add cpu
model aliases.

Signed-off-by: Michael Mueller 
Reviewed-by: Cornelia Huck 
---
 target-s390x/cpu-models.c | 77 +++
 target-s390x/cpu-models.h | 11 +++
 2 files changed, 88 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 9e5c5fb..8d2c2e2 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -90,3 +90,80 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM 
zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 
+static GSList *s390_cpu_aliases;
+
+static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
+{
+const char *aname = object_class_get_name((ObjectClass *) a);
+const char *bname = b;
+int blen;
+
+blen = strlen(bname);
+if (!strncasecmp(bname, aname, blen) &&
+!strcmp(aname + blen, "-" TYPE_S390_CPU)) {
+return 0;
+}
+return -1;
+}
+
+/**
+ * s390_cpu_class_by_name - retrive cpu object class by given name
+ * @name: the cpu model name
+ *
+ * Returns: address of object class on success
+ *  NULL if name is not a valid model name
+ */
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+GSList *list, *item;
+ObjectClass *ret = NULL;
+S390CPUAlias *alias;
+
+for (item = s390_cpu_aliases; item != NULL; item = item->next) {
+alias = (S390CPUAlias *) item->data;
+if (strcmp(alias->name, name) == 0) {
+return s390_cpu_class_by_name(alias->model);
+}
+}
+list = object_class_get_list(TYPE_S390_CPU, false);
+item = g_slist_find_custom(list, name, s390_cpu_compare_class_name);
+if (item) {
+ret = OBJECT_CLASS(item->data);
+}
+g_slist_free(list);
+return ret;
+}
+
+/**
+ * set_s390_cpu_alias - define a alias for an existing cpu model
+ * @name: the cpu alias name
+ * @model: the cpu model name
+ *
+ * Returns: 0 on success
+ *  -EINVAL if name or model is NULL or both are idential
+ *  or model is not a valid cpu model
+ *  -ENOMEM if internal memory allocation fails
+ */
+int set_s390_cpu_alias(const char *name, const char *model)
+{
+S390CPUAlias *alias;
+
+if (!name || !model) {
+return -EINVAL;
+}
+if (!strcmp(name, model)) {
+return -EINVAL;
+}
+if (!s390_cpu_class_by_name(model)) {
+return -EINVAL;
+}
+alias = g_try_malloc0(sizeof(S390CPUAlias));
+if (!alias) {
+return -ENOMEM;
+}
+alias->name = g_strdup(name);
+alias->model = g_strdup(model);
+s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+return 0;
+}
+
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 41af159..623a7b2 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -34,6 +34,17 @@
 #define cpu_class(x)  (((x) >> 20) & 0x3)
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
+ObjectClass *s390_cpu_class_by_name(const char *name);
+int set_s390_cpu_alias(const char *name, const char *model);
+
+/*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+char *name;
+char *model;
+} S390CPUAlias;
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH v2 11/15] cpu-model/s390: Add QMP command query-cpu-model

2015-02-17 Thread Michael Mueller
This patch implements a new QMP request named 'query-cpu-model'.
It returns the cpu model of cpu 0 and its backing accelerator.

request:
  {"execute" : "query-cpu-model" }

answer:
  {"return" : {"name": "2827-ga2", "accelerator": "kvm" }}

Alias names are resolved to their respective machine type and GA names
already during cpu instantiation. Thus, also a cpu model like 'host'
which is implemented as alias will return its normalized cpu model name.

Furthermore the patch implements the following functions:

- s390_cpu_typename(), returns the currently selected cpu type name or NULL
- s390_cpu_models_used(), returns true if S390 cpu models are in use

Signed-off-by: Michael Mueller 
---
 include/sysemu/arch_init.h |  1 +
 qapi-schema.json   | 23 +++
 qmp-commands.hx|  6 ++
 qmp.c  |  5 +
 stubs/Makefile.objs|  1 +
 stubs/arch-query-cpu-mod.c |  9 +
 target-s390x/cpu-models.c  | 25 +
 target-s390x/cpu-models.h  |  2 ++
 target-s390x/cpu.c | 32 
 9 files changed, 104 insertions(+)
 create mode 100644 stubs/arch-query-cpu-mod.c

diff --git a/include/sysemu/arch_init.h b/include/sysemu/arch_init.h
index 54b36c1..86344a2 100644
--- a/include/sysemu/arch_init.h
+++ b/include/sysemu/arch_init.h
@@ -37,5 +37,6 @@ int kvm_available(void);
 int xen_available(void);
 
 CpuDefinitionInfoList *arch_query_cpu_definitions(Error **errp);
+CpuModelInfo *arch_query_cpu_model(Error **errp);
 
 #endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 4d237c8..9431fc2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2507,6 +2507,29 @@
 ##
 { 'command': 'query-cpu-definitions', 'returns': ['CpuDefinitionInfo'] }
 
+##
+# @CpuModelInfo:
+#
+# Virtual CPU model definition.
+#
+# @name: the name of the CPU model definition
+#
+# Since: 2.3.0
+##
+{ 'type': 'CpuModelInfo',
+  'data': { 'name': 'str', '*accelerator': 'AccelId' } }
+
+##
+# @query-cpu-model:
+#
+# Return to current virtual CPU model
+#
+# Returns: CpuModelInfo
+#
+# Since: 2.3.0
+##
+{ 'command': 'query-cpu-model', 'returns': 'CpuModelInfo' }
+
 # @AddfdInfo:
 #
 # Information about a file descriptor that was added to an fd set.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a85d847..98bfedd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3392,6 +3392,12 @@ EQMP
 },
 
 {
+.name   = "query-cpu-model",
+.args_type  = "",
+.mhandler.cmd_new = qmp_marshal_input_query_cpu_model,
+},
+
+{
 .name   = "query-target",
 .args_type  = "",
 .mhandler.cmd_new = qmp_marshal_input_query_target,
diff --git a/qmp.c b/qmp.c
index 6b2c4be..d32abbc 100644
--- a/qmp.c
+++ b/qmp.c
@@ -568,6 +568,11 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error 
**errp)
 return arch_query_cpu_definitions(errp);
 }
 
+CpuModelInfo *qmp_query_cpu_model(Error **errp)
+{
+return arch_query_cpu_model(errp);
+}
+
 void qmp_add_client(const char *protocol, const char *fdname,
 bool has_skipauth, bool skipauth, bool has_tls, bool tls,
 Error **errp)
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index fd7a489..45daa92 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -1,4 +1,5 @@
 stub-obj-y += arch-query-cpu-def.o
+stub-obj-y += arch-query-cpu-mod.o
 stub-obj-y += bdrv-commit-all.o
 stub-obj-y += chr-baum-init.o
 stub-obj-y += chr-msmouse.o
diff --git a/stubs/arch-query-cpu-mod.c b/stubs/arch-query-cpu-mod.c
new file mode 100644
index 000..90ebd08
--- /dev/null
+++ b/stubs/arch-query-cpu-mod.c
@@ -0,0 +1,9 @@
+#include "qemu-common.h"
+#include "sysemu/arch_init.h"
+#include "qapi/qmp/qerror.h"
+
+CpuModelInfo *arch_query_cpu_model(Error **errp)
+{
+error_set(errp, QERR_UNSUPPORTED);
+return NULL;
+}
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 9f40998..4d03adc 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -110,6 +110,7 @@ typedef struct ParmAddrAddrAccel {
 } ParmAddrAddrAccel;
 
 static GSList *s390_cpu_aliases;
+static const char *selected_cpu_typename;
 
 /* compare order of two cpu classes for ascending sort */
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
@@ -631,3 +632,27 @@ bool s390_probe_mode(void)
 return false;
 }
 
+/**
+ * s390_cpu_typename - get name of selected cpu class type
+ *
+ * Returns: address to name of selected cpu class type
+ *  NULL if no cpu class type has been selected yet
+ */
+const char *s390_cpu_typename(void)
+{
+return selected_cpu_typ

[RFC PATCH v2 10/15] cpu-model/s390: Add cpu class initialization routines

2015-02-17 Thread Michael Mueller
This patch provides routines to dynamically update the previously defined
S390 cpu classes in the current host context. The main function performing
this process is s390_setup_cpu_classes(). It takes the current host context
as parameter to setup the classes accordingly. It basically performs the
following sub-tasks:

- Update of cpu classes with accelerator specific host and QEMU properties
- Mark adequate cpu class as default cpu class to be used for cpu model 'host'
- Invalidate cpu classes not supported by this hosting machine
- Define machine type aliases to latest GA number of a processor model
- Define aliases for common cpu model names
- Set cpu model alias 'host' to default cpu class

Forthermore the patch provides the following routines:

- cpu_desc_avail(), s390 specific stub indicating that list_cpus() can run
- s390_cpu_classes_initialized(), test if cpu classes have been initialized
- s390_test_facility(), facility bit probe function for QEMU land
- s390_probe_mode, test if running in probe mode

Signed-off-by: Michael Mueller 
---
 target-s390x/cpu-models.c | 464 ++
 target-s390x/cpu-models.h |  27 +++
 target-s390x/cpu.c|  17 +-
 target-s390x/kvm.c|   4 +-
 4 files changed, 510 insertions(+), 2 deletions(-)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 8d2c2e2..9f40998 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -12,6 +12,7 @@
 
 #include "qemu-common.h"
 #include "cpu-models.h"
+#include "qemu/error-report.h"
 
 #define S390_FAC_NAME(n, _cpu_id) glue(glue(glue(FAC, n), _), _cpu_id)
 
@@ -90,8 +91,41 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM 
zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 
+/* some types for calls to g_list_foreach() with parameters */
+typedef struct ParmBoolShortShortAccel {
+bool valid;
+unsigned short type;
+union {
+unsigned short class;
+unsigned short gen;
+unsigned short ga;
+};
+AccelId accel;
+} ParmBoolShortShortAccel;
+
+typedef struct ParmAddrAddrAccel {
+S390MachineProps *prop;
+S390CPUClass *host_cc;
+AccelId accel;
+} ParmAddrAddrAccel;
+
 static GSList *s390_cpu_aliases;
 
+/* compare order of two cpu classes for ascending sort */
+gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach->order < cc_b->mach->order) {
+return -1;
+}
+if (cc_a->mach->order > cc_b->mach->order) {
+return 1;
+}
+return 0;
+}
+
 static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
 {
 const char *aname = object_class_get_name((ObjectClass *) a);
@@ -167,3 +201,433 @@ int set_s390_cpu_alias(const char *name, const char 
*model)
 return 0;
 }
 
+/* return machine class for specific machine type */
+static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShortAccel *parm = user_data;
+
+if (parm->valid || !cc->proc->type || parm->type != cc->proc->type) {
+return;
+}
+
+parm->class = cc->mach->class;
+parm->valid = true;
+}
+
+/* return machine class by machine type */
+static unsigned short machine_class(unsigned short type, void *user_data)
+{
+GSList *list = object_class_get_list(TYPE_S390_CPU, false);
+ParmBoolShortShortAccel parm_class, *parm = user_data;
+
+if (parm->type != type) {
+parm->class = 0;
+}
+if (!parm->class) {
+parm_class.type = type;
+parm_class.class = 0;
+parm_class.valid = false;
+g_slist_foreach(list, (GFunc) s390_machine_class_test_cpu_class,
+&parm_class);
+g_slist_free(list);
+if (parm_class.valid) {
+parm->class = parm_class.class;
+}
+}
+parm->type = type;
+
+return parm->class;
+}
+
+/* return CMOS generation for specific machine type */
+static void s390_machine_class_test_cpu_gen(gpointer data, gpointer user_data)
+{
+S390CPUClass *cc = S390_CPU_CLASS((ObjectClass *) data);
+ParmBoolShortShortAccel *parm = user_data;
+
+if (parm->valid) {
+return;
+}
+
+if (parm->type == cc->proc->type) {
+parm->gen = cc->proc->gen;
+parm->valid = true;
+}
+}
+
+/* return CMOS generation by machine type */
+static uint16_t machine_gen(unsigned short type)
+{
+GSList *list = object_class_get_list(TYPE_S390

[RFC PATCH v2 12/15] cpu-model/s390: Extend QMP command query-cpu-definitions

2015-02-17 Thread Michael Mueller
This patch implements the QMP command 'query-cpu-definitions' in the S390
context. The command returns a in terms of machine release date descending
sorted list of cpu model names in the current host context. A consumer may
successfully request each listed cpu model as long for a given accelerator
this model is runnable.

Thy QMP type AccelCpuModelInfo is introduced and the type CpuDefinitionInfo
is extended by the optional field 'accelerators'. It contains a list of named
accelerators and some indication whether the associated cpu model is runnable
or the default cpu model. The default cpu model is used either no specific cpu
was requested during QEMU startup or the cpu model with named 'host'.

request:
  {"execute": "query-cpu-definitions"}

answer:
  {"return":

[{"name":"2964-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
 
{"name":"2828-ga1","accelerators":[{"name":"kvm","runnable":false,"default":false}]},
 
{"name":"2827-ga2","accelerators":[{"name":"kvm","runnable":true,"default":true}]},
 
{"name":"2827-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
 
{"name":"2818-ga1","accelerators":[{"name":"kvm","runnable":true,"default":false}]},
 ...
 
{"name":"2064-ga1","accelerators":[{"runnable":true,"name":"kvm","default":false}]}
]
   }

Signed-off-by: Michael Mueller 
---
 qapi-schema.json  |  21 +-
 target-s390x/cpu-models.c |  15 +++
 target-s390x/cpu-models.h |   1 +
 target-s390x/cpu.c| 100 +++---
 4 files changed, 130 insertions(+), 7 deletions(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 9431fc2..a5d38ae 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -2485,16 +2485,35 @@
   'data': ['qtest', 'tcg', 'kvm', 'xen'  ] }
 
 ##
+# @AccelCpuModelInfo:
+#
+# Accelerator specific CPU model data
+#
+# @id: the accelerator id
+#
+# @default: cpu model for 'host'
+#
+# @runnable: cpu model can be activated on hosting machine
+#
+# Since: 2.3.0
+#
+##
+{ 'type': 'AccelCpuModelInfo',
+  'data': { 'name': 'AccelId', 'default': 'bool', 'runnable': 'bool' } }
+
+##
 # @CpuDefinitionInfo:
 #
 # Virtual CPU definition.
 #
 # @name: the name of the CPU definition
 #
+# @accelerators: #optional cpu model offered per accelerator (since 2.3.0)
+#
 # Since: 1.2.0
 ##
 { 'type': 'CpuDefinitionInfo',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*accelerators': ['AccelCpuModelInfo'] } }
 
 ##
 # @query-cpu-definitions:
diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index 4d03adc..c63b4c2 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -202,6 +202,21 @@ int set_s390_cpu_alias(const char *name, const char *model)
 return 0;
 }
 
+/* compare order of two cpu classes for descending sort */
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b)
+{
+S390CPUClass *cc_a = S390_CPU_CLASS((ObjectClass *) a);
+S390CPUClass *cc_b = S390_CPU_CLASS((ObjectClass *) b);
+
+if (cc_a->mach->order < cc_b->mach->order) {
+return 1;
+}
+if (cc_a->mach->order > cc_b->mach->order) {
+return -1;
+}
+return 0;
+}
+
 /* return machine class for specific machine type */
 static void s390_machine_class_test_cpu_class(gpointer data, gpointer 
user_data)
 {
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 23ac2c4..d41fc37 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -106,6 +106,7 @@ static inline bool kvm_s390_probe_mode(void)
 
 int s390_setup_cpu_classes(AccelId accel, S390MachineProps *prop);
 gint s390_cpu_class_asc_order_compare(gconstpointer a, gconstpointer b);
+gint s390_cpu_class_desc_order_compare(gconstpointer a, gconstpointer b);
 void s390_cpu_list_entry(gpointer data, gpointer user_data);
 bool s390_cpu_classes_initialized(void);
 bool s390_test_facility(S390CPUClass *cc, unsigned long nr);
diff --git a/target-s390x/cpu.c b/target-s390x/cpu.c
index d98578b..42d38b0 100644
--- a/target-s390x/cpu.c
+++ b/target-s390x/cpu.c
@@ -66,18 +66,106 @@ void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 }
 
 #ifndef CONFIG_USER_ONLY
-CpuDefinitionIn

  1   2   >