All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions
@ 2017-12-08 16:01 David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
                   ` (14 more replies)
  0 siblings, 15 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson, Alexander Graf

Both series in one piece as (most probably) most reviewing is done.

Wire up some io instructions and implement new facilitites. Make sure
to take care of MTTCG when it comes to atomic operations. Make CCW
hotplug work.

As we are now able to install/boot a Fedora 26/27 as well as an upstream
kernel compiled for z12, let's bump up the QEMU cpu model to a very
stripped down version of a z12 (with missing base features). Take care
of backwards compatibility (as we defined the QEMU model as
migration-safe).

Avilable at: https://github.com/davidhildenbrand/qemu.git s390x-queue

v2 -> v3:
- squashed the ASI/ASGI and ALSI/ALSGI patches.
 - Both now emulate old behavior.
- "s390x/tcg: implement Interlocked-Access Facility 2"
 - now also emulates old behavior.
- "s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD"
 - now forwards r1 into the helper.
- "s390x/tcg: implement extract-CPU-time facility"
 - takes care of user-only
- "s390x: change the QEMU cpu model to a stripped down z12"
  - const -> static const for two feature bitmaps


David Hildenbrand (14):
  s390x/kvm: factor out build_channel_report_mcic() into cpu.h
  s390x/tcg: fix and cleanup mcck injection
  s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD
  s390x/tcg: indicate value of TODPR in STCKE
  s390x/tcg: wire up STORE CHANNEL REPORT WORD
  s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess
    facility 1
  s390x/tcg: implement Interlocked-Access Facility 2
  s390x/tcg: wire up SET ADDRESS LIMIT
  s390x/tcg: wire up SET CHANNEL MONITOR
  s390x/tcg: Implement STORE CHANNEL PATH STATUS
  s390x/tcg: Implement SIGNAL ADAPTER instruction
  s390x/tcg: implement extract-CPU-time facility
  s390x/tcg: we already implement the Set-Program-Parameter facility
  s390x: change the QEMU cpu model to a stripped down z12

 hw/s390x/s390-virtio-ccw.c  |   8 +++
 target/s390x/cpu.h          |  26 +++++++
 target/s390x/cpu_models.c   |  97 +++++++++++---------------
 target/s390x/cpu_models.h   |   1 +
 target/s390x/excp_helper.c  |  12 ++--
 target/s390x/gen-features.c |  87 +++++++++++++++++++++++
 target/s390x/helper.h       |   6 +-
 target/s390x/insn-data.def  |  29 +++++---
 target/s390x/internal.h     |   6 +-
 target/s390x/kvm.c          |  25 +------
 target/s390x/misc_helper.c  |  59 ++++++++++++++--
 target/s390x/translate.c    | 164 ++++++++++++++++++++++++++++++++++++++++++++
 12 files changed, 415 insertions(+), 105 deletions(-)

-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-09  2:17   ` Richard Henderson
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 02/14] s390x/tcg: fix and cleanup mcck injection David Hildenbrand
                   ` (13 subsequent siblings)
  14 siblings, 1 reply; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

We'll need it later on in two places. Refactor it to just indicate the
validity bits. While at it, introduce a define for the used CR14 bit (we'll
also need later on).

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/cpu.h | 23 +++++++++++++++++++++++
 target/s390x/kvm.c | 25 ++-----------------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index 9cfbbbac04..f9d4d62c48 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -351,6 +351,9 @@ extern const struct VMStateDescription vmstate_s390_cpu;
 #define CR0_CPU_TIMER_SC        0x0000000000000400ULL
 #define CR0_SERVICE_SC          0x0000000000000200ULL
 
+/* Control register 14 bits */
+#define CR14_CHANNEL_REPORT_SC  0x0000000010000000ULL
+
 /* MMU */
 #define MMU_PRIMARY_IDX         0
 #define MMU_SECONDARY_IDX       1
@@ -674,6 +677,26 @@ struct sysib_322 {
 #define MCIC_VB_CT 0x0000000000020000ULL
 #define MCIC_VB_CC 0x0000000000010000ULL
 
+static inline uint64_t s390_build_validity_mcic(void)
+{
+    uint64_t mcic;
+
+    /*
+     * Indicate all validity bits (no damage) only. Other bits have to be
+     * added by the caller. (storage errors, subclasses and subclass modifiers)
+     */
+    mcic = MCIC_VB_WP | MCIC_VB_MS | MCIC_VB_PM | MCIC_VB_IA | MCIC_VB_FP |
+           MCIC_VB_GR | MCIC_VB_CR | MCIC_VB_ST | MCIC_VB_AR | MCIC_VB_PR |
+           MCIC_VB_FC | MCIC_VB_CT | MCIC_VB_CC;
+    if (s390_has_feat(S390_FEAT_VECTOR)) {
+        mcic |= MCIC_VB_VR;
+    }
+    if (s390_has_feat(S390_FEAT_GUARDED_STORAGE)) {
+        mcic |= MCIC_VB_GS;
+    }
+    return mcic;
+}
+
 
 /* cpu.c */
 int s390_get_clock(uint8_t *tod_high, uint64_t *tod_low);
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
index 97c45d5537..9b8b59f2a2 100644
--- a/target/s390x/kvm.c
+++ b/target/s390x/kvm.c
@@ -1852,33 +1852,12 @@ void kvm_s390_io_interrupt(uint16_t subchannel_id,
     kvm_s390_floating_interrupt(&irq);
 }
 
-static uint64_t build_channel_report_mcic(void)
-{
-    uint64_t mcic;
-
-    /* subclass: indicate channel report pending */
-    mcic = MCIC_SC_CP |
-    /* subclass modifiers: none */
-    /* storage errors: none */
-    /* validity bits: no damage */
-        MCIC_VB_WP | MCIC_VB_MS | MCIC_VB_PM | MCIC_VB_IA | MCIC_VB_FP |
-        MCIC_VB_GR | MCIC_VB_CR | MCIC_VB_ST | MCIC_VB_AR | MCIC_VB_PR |
-        MCIC_VB_FC | MCIC_VB_CT | MCIC_VB_CC;
-    if (s390_has_feat(S390_FEAT_VECTOR)) {
-        mcic |= MCIC_VB_VR;
-    }
-    if (s390_has_feat(S390_FEAT_GUARDED_STORAGE)) {
-        mcic |= MCIC_VB_GS;
-    }
-    return mcic;
-}
-
 void kvm_s390_crw_mchk(void)
 {
     struct kvm_s390_irq irq = {
         .type = KVM_S390_MCHK,
-        .u.mchk.cr14 = 1 << 28,
-        .u.mchk.mcic = build_channel_report_mcic(),
+        .u.mchk.cr14 = CR14_CHANNEL_REPORT_SC,
+        .u.mchk.mcic = s390_build_validity_mcic() | MCIC_SC_CP,
     };
     kvm_s390_floating_interrupt(&irq);
 }
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 02/14] s390x/tcg: fix and cleanup mcck injection
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD David Hildenbrand
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

The architecture mode indication wasn't stored. The split of certain
64bit fields was unnecessary. Also, the complete clock comparator, not
just bit 0-55 (starting at byte 1) was stored.

We now generate a proper MCIC via the same helper we use for KVM.

There is more to clean up, but we will change the other parts later on
either way.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/excp_helper.c | 12 ++++++------
 target/s390x/internal.h    |  6 +++---
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/target/s390x/excp_helper.c b/target/s390x/excp_helper.c
index d831537544..f4697a884d 100644
--- a/target/s390x/excp_helper.c
+++ b/target/s390x/excp_helper.c
@@ -395,6 +395,9 @@ static void do_mchk_interrupt(CPUS390XState *env)
 
     lowcore = cpu_map_lowcore(env);
 
+    /* we are always in z/Architecture mode */
+    lowcore->ar_access_id = 1;
+
     for (i = 0; i < 16; i++) {
         lowcore->floating_pt_save_area[i] = cpu_to_be64(get_freg(env, i)->ll);
         lowcore->gpregs_save_area[i] = cpu_to_be64(env->regs[i]);
@@ -404,13 +407,10 @@ static void do_mchk_interrupt(CPUS390XState *env)
     lowcore->prefixreg_save_area = cpu_to_be32(env->psa);
     lowcore->fpt_creg_save_area = cpu_to_be32(env->fpc);
     lowcore->tod_progreg_save_area = cpu_to_be32(env->todpr);
-    lowcore->cpu_timer_save_area[0] = cpu_to_be32(env->cputm >> 32);
-    lowcore->cpu_timer_save_area[1] = cpu_to_be32((uint32_t)env->cputm);
-    lowcore->clock_comp_save_area[0] = cpu_to_be32(env->ckc >> 32);
-    lowcore->clock_comp_save_area[1] = cpu_to_be32((uint32_t)env->ckc);
+    lowcore->cpu_timer_save_area = cpu_to_be64(env->cputm);
+    lowcore->clock_comp_save_area = cpu_to_be64(env->ckc >> 8);
 
-    lowcore->mcck_interruption_code[0] = cpu_to_be32(0x00400f1d);
-    lowcore->mcck_interruption_code[1] = cpu_to_be32(0x40330000);
+    lowcore->mcic = cpu_to_be64(s390_build_validity_mcic() | MCIC_SC_CP);
     lowcore->mcck_old_psw.mask = cpu_to_be64(get_psw_mask(env));
     lowcore->mcck_old_psw.addr = cpu_to_be64(env->psw.addr);
     mask = be64_to_cpu(lowcore->mcck_new_psw.mask);
diff --git a/target/s390x/internal.h b/target/s390x/internal.h
index 6817b2c432..1a88e4beb4 100644
--- a/target/s390x/internal.h
+++ b/target/s390x/internal.h
@@ -43,7 +43,7 @@ typedef struct LowCore {
     uint8_t         pad3[0xc8 - 0xc4];        /* 0x0c4 */
     uint32_t        stfl_fac_list;            /* 0x0c8 */
     uint8_t         pad4[0xe8 - 0xcc];        /* 0x0cc */
-    uint32_t        mcck_interruption_code[2]; /* 0x0e8 */
+    uint64_t        mcic;                     /* 0x0e8 */
     uint8_t         pad5[0xf4 - 0xf0];        /* 0x0f0 */
     uint32_t        external_damage_code;     /* 0x0f4 */
     uint64_t        failing_storage_address;  /* 0x0f8 */
@@ -118,8 +118,8 @@ typedef struct LowCore {
     uint32_t        fpt_creg_save_area;        /* 0x131c */
     uint8_t         pad16[0x1324 - 0x1320];    /* 0x1320 */
     uint32_t        tod_progreg_save_area;     /* 0x1324 */
-    uint32_t        cpu_timer_save_area[2];    /* 0x1328 */
-    uint32_t        clock_comp_save_area[2];   /* 0x1330 */
+    uint64_t        cpu_timer_save_area;       /* 0x1328 */
+    uint64_t        clock_comp_save_area;      /* 0x1330 */
     uint8_t         pad17[0x1340 - 0x1338];    /* 0x1338 */
     uint32_t        access_regs_save_area[16]; /* 0x1340 */
     uint64_t        cregs_save_area[16];       /* 0x1380 */
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 02/14] s390x/tcg: fix and cleanup mcck injection David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-09  2:20   ` Richard Henderson
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 04/14] s390x/tcg: indicate value of TODPR in STCKE David Hildenbrand
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

Needed for machine check handling inside Linux (when restoring registers).

Except for SIGP and machine checks, we don't make use of the register
yet. Sufficient for now.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/helper.h      |  1 +
 target/s390x/insn-data.def |  2 ++
 target/s390x/misc_helper.c | 11 +++++++++++
 target/s390x/translate.c   |  7 +++++++
 4 files changed, 21 insertions(+)

diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index 9459b73c73..3eb7715e5b 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -127,6 +127,7 @@ DEF_HELPER_3(load_psw, noreturn, env, i64, i64)
 DEF_HELPER_FLAGS_2(spx, TCG_CALL_NO_RWG, void, env, i64)
 DEF_HELPER_FLAGS_1(stck, TCG_CALL_NO_RWG_SE, i64, env)
 DEF_HELPER_FLAGS_2(sckc, TCG_CALL_NO_RWG, void, env, i64)
+DEF_HELPER_FLAGS_2(sckpf, TCG_CALL_NO_RWG, void, env, i64)
 DEF_HELPER_FLAGS_1(stckc, TCG_CALL_NO_RWG, i64, env)
 DEF_HELPER_FLAGS_2(spt, TCG_CALL_NO_RWG, void, env, i64)
 DEF_HELPER_FLAGS_1(stpt, TCG_CALL_NO_RWG, i64, env)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 16e27c8a35..8c2541f545 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -999,6 +999,8 @@
     C(0xb204, SCK,     S,     Z,   0, 0, 0, 0, 0, 0)
 /* SET CLOCK COMPARATOR */
     C(0xb206, SCKC,    S,     Z,   0, m2_64, 0, 0, sckc, 0)
+/* SET CLOCK PROGRAMMABLE FIELD */
+    C(0x0107, SCKPF,   E,     Z,   0, 0, 0, 0, sckpf, 0)
 /* SET CPU TIMER */
     C(0xb208, SPT,     S,     Z,   0, m2_64, 0, 0, spt, 0)
 /* SET PREFIX */
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 6d766ce1e7..769ec52e1d 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -146,6 +146,17 @@ void HELPER(sckc)(CPUS390XState *env, uint64_t time)
     timer_mod(env->tod_timer, env->tod_basetime + time);
 }
 
+/* Set Tod Programmable Field */
+void HELPER(sckpf)(CPUS390XState *env, uint64_t r0)
+{
+    uint32_t val = r0;
+
+    if (val & 0xffff0000) {
+        s390_program_interrupt(env, PGM_SPECIFICATION, 2, GETPC());
+    }
+    env->todpr = val;
+}
+
 /* Store Clock Comparator */
 uint64_t HELPER(stckc)(CPUS390XState *env)
 {
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 26cf993405..d13f531c5b 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -3922,6 +3922,13 @@ static ExitStatus op_sckc(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_sckpf(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    gen_helper_sckpf(cpu_env, regs[0]);
+    return NO_EXIT;
+}
+
 static ExitStatus op_stckc(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 04/14] s390x/tcg: indicate value of TODPR in STCKE
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (2 preceding siblings ...)
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 05/14] s390x/tcg: wire up STORE CHANNEL REPORT WORD David Hildenbrand
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

We were not yet using the value of the TOD Programmable Register.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/translate.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index d13f531c5b..38e1770e5e 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -3897,7 +3897,10 @@ static ExitStatus op_stcke(DisasContext *s, DisasOps *o)
 {
     TCGv_i64 c1 = tcg_temp_new_i64();
     TCGv_i64 c2 = tcg_temp_new_i64();
+    TCGv_i64 todpr = tcg_temp_new_i64();
     gen_helper_stck(c1, cpu_env);
+    /* 16 bit value store in an uint32_t (only valid bits set) */
+    tcg_gen_ld32u_i64(todpr, cpu_env, offsetof(CPUS390XState, todpr));
     /* Shift the 64-bit value into its place as a zero-extended
        104-bit value.  Note that "bit positions 64-103 are always
        non-zero so that they compare differently to STCK"; we set
@@ -3905,11 +3908,13 @@ static ExitStatus op_stcke(DisasContext *s, DisasOps *o)
     tcg_gen_shli_i64(c2, c1, 56);
     tcg_gen_shri_i64(c1, c1, 8);
     tcg_gen_ori_i64(c2, c2, 0x10000);
+    tcg_gen_or_i64(c2, c2, todpr);
     tcg_gen_qemu_st64(c1, o->in2, get_mem_index(s));
     tcg_gen_addi_i64(o->in2, o->in2, 8);
     tcg_gen_qemu_st64(c2, o->in2, get_mem_index(s));
     tcg_temp_free_i64(c1);
     tcg_temp_free_i64(c2);
+    tcg_temp_free_i64(todpr);
     /* ??? We don't implement clock states.  */
     gen_op_movi_cc(s, 0);
     return NO_EXIT;
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 05/14] s390x/tcg: wire up STORE CHANNEL REPORT WORD
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (3 preceding siblings ...)
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 04/14] s390x/tcg: indicate value of TODPR in STCKE David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 06/14] s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess facility 1 David Hildenbrand
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

CRW machine check handling requires STCRW. So let's wire it up.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/helper.h      | 1 +
 target/s390x/insn-data.def | 1 +
 target/s390x/misc_helper.c | 9 +++++++++
 target/s390x/translate.c   | 8 ++++++++
 4 files changed, 19 insertions(+)

diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index 3eb7715e5b..ba11cfdc30 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -166,6 +166,7 @@ DEF_HELPER_3(msch, void, env, i64, i64)
 DEF_HELPER_2(rchp, void, env, i64)
 DEF_HELPER_2(rsch, void, env, i64)
 DEF_HELPER_3(ssch, void, env, i64, i64)
+DEF_HELPER_2(stcrw, void, env, i64)
 DEF_HELPER_3(stsch, void, env, i64, i64)
 DEF_HELPER_3(tsch, void, env, i64, i64)
 DEF_HELPER_2(chsc, void, env, i64)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 8c2541f545..43ab1963c8 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1055,6 +1055,7 @@
     C(0xb23b, RCHP,    S,     Z,   0, 0, 0, 0, rchp, 0)
     C(0xb238, RSCH,    S,     Z,   0, 0, 0, 0, rsch, 0)
     C(0xb233, SSCH,    S,     Z,   0, insn, 0, 0, ssch, 0)
+    C(0xb239, STCRW,   S,     Z,   0, insn, 0, 0, stcrw, 0)
     C(0xb234, STSCH,   S,     Z,   0, insn, 0, 0, stsch, 0)
     C(0xb235, TSCH,    S,     Z,   0, insn, 0, 0, tsch, 0)
     /* ??? Not listed in PoO ninth edition, but there's a linux driver that
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 769ec52e1d..04fb53d8a3 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -385,6 +385,15 @@ void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
     qemu_mutex_unlock_iothread();
 }
 
+void HELPER(stcrw)(CPUS390XState *env, uint64_t inst)
+{
+    S390CPU *cpu = s390_env_get_cpu(env);
+
+    qemu_mutex_lock_iothread();
+    ioinst_handle_stcrw(cpu, inst >> 16, GETPC());
+    qemu_mutex_unlock_iothread();
+}
+
 void HELPER(stsch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
 {
     S390CPU *cpu = s390_env_get_cpu(env);
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 38e1770e5e..08c1ace0d8 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4071,6 +4071,14 @@ static ExitStatus op_stsch(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_stcrw(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    gen_helper_stcrw(cpu_env, o->in2);
+    set_cc_static(s);
+    return NO_EXIT;
+}
+
 static ExitStatus op_tsch(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 06/14] s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess facility 1
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (4 preceding siblings ...)
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 05/14] s390x/tcg: wire up STORE CHANNEL REPORT WORD David Hildenbrand
@ 2017-12-08 16:01 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 07/14] s390x/tcg: implement Interlocked-Access Facility 2 David Hildenbrand
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:01 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

The semantics of ASI/ASGI/ALSI/ALSGI changed. Let's implement them just
like LOAD AND ADD, so they are atomic. Emulate old behavior.

This fixes random crashes when booting a Linux kernel compiled for
z196+ with SMP + MTTCG.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/insn-data.def |  8 ++++----
 target/s390x/translate.c   | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 43ab1963c8..166ee7c80b 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -39,10 +39,10 @@
     C(0xb9d8, AHHLR,   RRF_a, HW,  r2_sr32, r3, new, r1_32h, add, adds32)
 /* ADD IMMEDIATE */
     C(0xc209, AFI,     RIL_a, EI,  r1, i2, new, r1_32, add, adds32)
-    C(0xeb6a, ASI,     SIY,   GIE, m1_32s, i2, new, m1_32, add, adds32)
+    D(0xeb6a, ASI,     SIY,   GIE, la1, i2, new, 0, asi, adds32, MO_TESL)
     C(0xecd8, AHIK,    RIE_d, DO,  r3, i2, new, r1_32, add, adds32)
     C(0xc208, AGFI,    RIL_a, EI,  r1, i2, r1, 0, add, adds64)
-    C(0xeb7a, AGSI,    SIY,   GIE, m1_64, i2, new, m1_64, add, adds64)
+    D(0xeb7a, AGSI,    SIY,   GIE, la1, i2, new, 0, asi, adds64, MO_TEQ)
     C(0xecd9, AGHIK,   RIE_d, DO,  r3, i2, r1, 0, add, adds64)
 /* ADD IMMEDIATE HIGH */
     C(0xcc08, AIH,     RIL_a, HW,  r1_sr32, i2, new, r1_32h, add, adds32)
@@ -70,9 +70,9 @@
     C(0xc20b, ALFI,    RIL_a, EI,  r1, i2_32u, new, r1_32, add, addu32)
     C(0xc20a, ALGFI,   RIL_a, EI,  r1, i2_32u, r1, 0, add, addu64)
 /* ADD LOGICAL WITH SIGNED IMMEDIATE */
-    C(0xeb6e, ALSI,    SIY,   GIE, m1_32u, i2, new, m1_32, add, addu32)
+    D(0xeb6e, ALSI,    SIY,   GIE, la1, i2, new, 0, asi, addu32, MO_TEUL)
     C(0xecda, ALHSIK,  RIE_d, DO,  r3, i2, new, r1_32, add, addu32)
-    C(0xeb7e, ALGSI,   SIY,   GIE, m1_64, i2, new, m1_64, add, addu64)
+    D(0xeb7e, ALGSI,   SIY,   GIE, la1, i2, new, 0, asi, addu64, MO_TEQ)
     C(0xecdb, ALGHSIK, RIE_d, DO,  r3, i2, r1, 0, add, addu64)
 /* ADD LOGICAL WITH SIGNED IMMEDIATE HIGH */
     C(0xcc0a, ALSIH,   RIL_a, HW,  r1_sr32, i2, new, r1_32h, add, addu32)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 08c1ace0d8..7ab8e853ab 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -1364,6 +1364,27 @@ static ExitStatus op_addc(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_asi(DisasContext *s, DisasOps *o)
+{
+    o->in1 = tcg_temp_new_i64();
+
+    if (!s390_has_feat(S390_FEAT_STFLE_45)) {
+        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
+    } else {
+        /* Perform the atomic addition in memory. */
+        tcg_gen_atomic_fetch_add_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
+                                     s->insn->data);
+    }
+
+    /* Recompute also for atomic case: needed for setting CC. */
+    tcg_gen_add_i64(o->out, o->in1, o->in2);
+
+    if (!s390_has_feat(S390_FEAT_STFLE_45)) {
+        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
+    }
+    return NO_EXIT;
+}
+
 static ExitStatus op_aeb(DisasContext *s, DisasOps *o)
 {
     gen_helper_aeb(o->out, cpu_env, o->in1, o->in2);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 07/14] s390x/tcg: implement Interlocked-Access Facility 2
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (5 preceding siblings ...)
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 06/14] s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess facility 1 David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 08/14] s390x/tcg: wire up SET ADDRESS LIMIT David Hildenbrand
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

With this facility, OI/OIY, NI/NIY and XI/XIY are atomic. All operate on
one byte (MO_UB). Emulate old behavior.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/cpu_models.c  |  1 +
 target/s390x/insn-data.def | 12 ++++-----
 target/s390x/translate.c   | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index c4c37b3b15..94d24e423d 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -842,6 +842,7 @@ static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
         S390_FEAT_STFLE_45,
         S390_FEAT_STFLE_49,
         S390_FEAT_LOCAL_TLB_CLEARING,
+        S390_FEAT_INTERLOCKED_ACCESS_2,
         S390_FEAT_STFLE_53,
         S390_FEAT_MSA_EXT_5,
         S390_FEAT_MSA_EXT_3,
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 166ee7c80b..6cbd604814 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -99,8 +99,8 @@
     D(0xa505, NIHL,    RI_a,  Z,   r1_o, i2_16u, r1, 0, andi, 0, 0x1020)
     D(0xa506, NILH,    RI_a,  Z,   r1_o, i2_16u, r1, 0, andi, 0, 0x1010)
     D(0xa507, NILL,    RI_a,  Z,   r1_o, i2_16u, r1, 0, andi, 0, 0x1000)
-    C(0x9400, NI,      SI,    Z,   m1_8u, i2_8u, new, m1_8, and, nz64)
-    C(0xeb54, NIY,     SIY,   LD,  m1_8u, i2_8u, new, m1_8, and, nz64)
+    D(0x9400, NI,      SI,    Z,   la1, i2_8u, new, 0, ni, nz64, MO_UB)
+    D(0xeb54, NIY,     SIY,   LD,  la1, i2_8u, new, 0, ni, nz64, MO_UB)
 
 /* BRANCH AND SAVE */
     C(0x0d00, BASR,    RR_a,  Z,   0, r2_nz, r1, 0, bas, 0)
@@ -357,8 +357,8 @@
 /* EXCLUSIVE OR IMMEDIATE */
     D(0xc006, XIHF,    RIL_a, EI,  r1_o, i2_32u, r1, 0, xori, 0, 0x2020)
     D(0xc007, XILF,    RIL_a, EI,  r1_o, i2_32u, r1, 0, xori, 0, 0x2000)
-    C(0x9700, XI,      SI,    Z,   m1_8u, i2_8u, new, m1_8, xor, nz64)
-    C(0xeb57, XIY,     SIY,   LD,  m1_8u, i2_8u, new, m1_8, xor, nz64)
+    D(0x9700, XI,      SI,    Z,   la1, i2_8u, new, 0, xi, nz64, MO_UB)
+    D(0xeb57, XIY,     SIY,   LD,  la1, i2_8u, new, 0, xi, nz64, MO_UB)
 
 /* EXECUTE */
     C(0x4400, EX,      RX_a,  Z,   0, a2, 0, 0, ex, 0)
@@ -698,8 +698,8 @@
     D(0xa509, OIHL,    RI_a,  Z,   r1_o, i2_16u, r1, 0, ori, 0, 0x1020)
     D(0xa50a, OILH,    RI_a,  Z,   r1_o, i2_16u, r1, 0, ori, 0, 0x1010)
     D(0xa50b, OILL,    RI_a,  Z,   r1_o, i2_16u, r1, 0, ori, 0, 0x1000)
-    C(0x9600, OI,      SI,    Z,   m1_8u, i2_8u, new, m1_8, or, nz64)
-    C(0xeb56, OIY,     SIY,   LD,  m1_8u, i2_8u, new, m1_8, or, nz64)
+    D(0x9600, OI,      SI,    Z,   la1, i2_8u, new, 0, oi, nz64, MO_UB)
+    D(0xeb56, OIY,     SIY,   LD,  la1, i2_8u, new, 0, oi, nz64, MO_UB)
 
 /* PACK */
     /* Really format SS_b, but we pack both lengths into one argument
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 7ab8e853ab..de00b9471a 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -1427,6 +1427,27 @@ static ExitStatus op_andi(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_ni(DisasContext *s, DisasOps *o)
+{
+    o->in1 = tcg_temp_new_i64();
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
+    } else {
+        /* Perform the atomic operation in memory. */
+        tcg_gen_atomic_fetch_and_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
+                                     s->insn->data);
+    }
+
+    /* Recompute also for atomic case: needed for setting CC. */
+    tcg_gen_and_i64(o->out, o->in1, o->in2);
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
+    }
+    return NO_EXIT;
+}
+
 static ExitStatus op_bas(DisasContext *s, DisasOps *o)
 {
     tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc));
@@ -3378,6 +3399,27 @@ static ExitStatus op_ori(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_oi(DisasContext *s, DisasOps *o)
+{
+    o->in1 = tcg_temp_new_i64();
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
+    } else {
+        /* Perform the atomic operation in memory. */
+        tcg_gen_atomic_fetch_or_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
+                                    s->insn->data);
+    }
+
+    /* Recompute also for atomic case: needed for setting CC. */
+    tcg_gen_or_i64(o->out, o->in1, o->in2);
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
+    }
+    return NO_EXIT;
+}
+
 static ExitStatus op_pack(DisasContext *s, DisasOps *o)
 {
     TCGv_i32 l = tcg_const_i32(get_field(s->fields, l1));
@@ -4643,6 +4685,27 @@ static ExitStatus op_xori(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_xi(DisasContext *s, DisasOps *o)
+{
+    o->in1 = tcg_temp_new_i64();
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_ld_tl(o->in1, o->addr1, get_mem_index(s), s->insn->data);
+    } else {
+        /* Perform the atomic operation in memory. */
+        tcg_gen_atomic_fetch_xor_i64(o->in1, o->addr1, o->in2, get_mem_index(s),
+                                     s->insn->data);
+    }
+
+    /* Recompute also for atomic case: needed for setting CC. */
+    tcg_gen_xor_i64(o->out, o->in1, o->in2);
+
+    if (!s390_has_feat(S390_FEAT_INTERLOCKED_ACCESS_2)) {
+        tcg_gen_qemu_st_tl(o->out, o->addr1, get_mem_index(s), s->insn->data);
+    }
+    return NO_EXIT;
+}
+
 static ExitStatus op_zero(DisasContext *s, DisasOps *o)
 {
     o->out = tcg_const_i64(0);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 08/14] s390x/tcg: wire up SET ADDRESS LIMIT
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (6 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 07/14] s390x/tcg: implement Interlocked-Access Facility 2 David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 09/14] s390x/tcg: wire up SET CHANNEL MONITOR David Hildenbrand
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

Let's handle it just like KVM:
    Depending on the model, this instruction may not be
    provided. When this instruction is not provided, it is
    checked for operand exception and privileged-opera-
    tion exception, and then is suppressed.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/helper.h      | 1 +
 target/s390x/insn-data.def | 1 +
 target/s390x/misc_helper.c | 9 +++++++++
 target/s390x/translate.c   | 7 +++++++
 4 files changed, 18 insertions(+)

diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index ba11cfdc30..f1acc34f36 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -165,6 +165,7 @@ DEF_HELPER_2(hsch, void, env, i64)
 DEF_HELPER_3(msch, void, env, i64, i64)
 DEF_HELPER_2(rchp, void, env, i64)
 DEF_HELPER_2(rsch, void, env, i64)
+DEF_HELPER_2(sal, void, env, i64)
 DEF_HELPER_3(ssch, void, env, i64, i64)
 DEF_HELPER_2(stcrw, void, env, i64)
 DEF_HELPER_3(stsch, void, env, i64, i64)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 6cbd604814..11746f5298 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1054,6 +1054,7 @@
     C(0xb232, MSCH,    S,     Z,   0, insn, 0, 0, msch, 0)
     C(0xb23b, RCHP,    S,     Z,   0, 0, 0, 0, rchp, 0)
     C(0xb238, RSCH,    S,     Z,   0, 0, 0, 0, rsch, 0)
+    C(0xb237, SAL,     S,     Z,   0, 0, 0, 0, sal, 0)
     C(0xb233, SSCH,    S,     Z,   0, insn, 0, 0, ssch, 0)
     C(0xb239, STCRW,   S,     Z,   0, insn, 0, 0, stcrw, 0)
     C(0xb234, STSCH,   S,     Z,   0, insn, 0, 0, stsch, 0)
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 04fb53d8a3..1941c9c3de 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -377,6 +377,15 @@ void HELPER(rsch)(CPUS390XState *env, uint64_t r1)
     qemu_mutex_unlock_iothread();
 }
 
+void HELPER(sal)(CPUS390XState *env, uint64_t r1)
+{
+    S390CPU *cpu = s390_env_get_cpu(env);
+
+    qemu_mutex_lock_iothread();
+    ioinst_handle_sal(cpu, r1, GETPC());
+    qemu_mutex_unlock_iothread();
+}
+
 void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
 {
     S390CPU *cpu = s390_env_get_cpu(env);
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index de00b9471a..30d3d767ea 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4118,6 +4118,13 @@ static ExitStatus op_rsch(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_sal(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    gen_helper_sal(cpu_env, regs[1]);
+    return NO_EXIT;
+}
+
 static ExitStatus op_ssch(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 09/14] s390x/tcg: wire up SET CHANNEL MONITOR
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (7 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 08/14] s390x/tcg: wire up SET ADDRESS LIMIT David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 10/14] s390x/tcg: Implement STORE CHANNEL PATH STATUS David Hildenbrand
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

Let's just wire it up like KVM.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/helper.h      | 1 +
 target/s390x/insn-data.def | 1 +
 target/s390x/misc_helper.c | 9 +++++++++
 target/s390x/translate.c   | 7 +++++++
 4 files changed, 18 insertions(+)

diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index f1acc34f36..102fbdd7b9 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -166,6 +166,7 @@ DEF_HELPER_3(msch, void, env, i64, i64)
 DEF_HELPER_2(rchp, void, env, i64)
 DEF_HELPER_2(rsch, void, env, i64)
 DEF_HELPER_2(sal, void, env, i64)
+DEF_HELPER_4(schm, void, env, i64, i64, i64)
 DEF_HELPER_3(ssch, void, env, i64, i64)
 DEF_HELPER_2(stcrw, void, env, i64)
 DEF_HELPER_3(stsch, void, env, i64, i64)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 11746f5298..0c225d5e78 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1055,6 +1055,7 @@
     C(0xb23b, RCHP,    S,     Z,   0, 0, 0, 0, rchp, 0)
     C(0xb238, RSCH,    S,     Z,   0, 0, 0, 0, rsch, 0)
     C(0xb237, SAL,     S,     Z,   0, 0, 0, 0, sal, 0)
+    C(0xb23c, SCHM,    S,     Z,   0, insn, 0, 0, schm, 0)
     C(0xb233, SSCH,    S,     Z,   0, insn, 0, 0, ssch, 0)
     C(0xb239, STCRW,   S,     Z,   0, insn, 0, 0, stcrw, 0)
     C(0xb234, STSCH,   S,     Z,   0, insn, 0, 0, stsch, 0)
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 1941c9c3de..7ddade2f0e 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -386,6 +386,15 @@ void HELPER(sal)(CPUS390XState *env, uint64_t r1)
     qemu_mutex_unlock_iothread();
 }
 
+void HELPER(schm)(CPUS390XState *env, uint64_t r1, uint64_t r2, uint64_t inst)
+{
+    S390CPU *cpu = s390_env_get_cpu(env);
+
+    qemu_mutex_lock_iothread();
+    ioinst_handle_schm(cpu, r1, r2, inst >> 16, GETPC());
+    qemu_mutex_unlock_iothread();
+}
+
 void HELPER(ssch)(CPUS390XState *env, uint64_t r1, uint64_t inst)
 {
     S390CPU *cpu = s390_env_get_cpu(env);
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 30d3d767ea..8cf35a7b49 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4125,6 +4125,13 @@ static ExitStatus op_sal(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_schm(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    gen_helper_schm(cpu_env, regs[1], regs[2], o->in2);
+    return NO_EXIT;
+}
+
 static ExitStatus op_ssch(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 10/14] s390x/tcg: Implement STORE CHANNEL PATH STATUS
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (8 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 09/14] s390x/tcg: wire up SET CHANNEL MONITOR David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 11/14] s390x/tcg: Implement SIGNAL ADAPTER instruction David Hildenbrand
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

Just like KVM does, we should suppress this instruction:
    When this instruction is not provided, it is
    checked for privileged operation exception and the
    instruction is suppressed by the machine

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/insn-data.def | 1 +
 target/s390x/translate.c   | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 0c225d5e78..2e47a6b5bc 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1056,6 +1056,7 @@
     C(0xb238, RSCH,    S,     Z,   0, 0, 0, 0, rsch, 0)
     C(0xb237, SAL,     S,     Z,   0, 0, 0, 0, sal, 0)
     C(0xb23c, SCHM,    S,     Z,   0, insn, 0, 0, schm, 0)
+    C(0xb23a, STCPS,   S,     Z,   0, 0, 0, 0, stcps, 0)
     C(0xb233, SSCH,    S,     Z,   0, insn, 0, 0, ssch, 0)
     C(0xb239, STCRW,   S,     Z,   0, insn, 0, 0, stcrw, 0)
     C(0xb234, STSCH,   S,     Z,   0, insn, 0, 0, stsch, 0)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 8cf35a7b49..16febf4274 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4132,6 +4132,13 @@ static ExitStatus op_schm(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_stcps(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    /* The instruction is suppressed if not provided. */
+    return NO_EXIT;
+}
+
 static ExitStatus op_ssch(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 11/14] s390x/tcg: Implement SIGNAL ADAPTER instruction
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (9 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 10/14] s390x/tcg: Implement STORE CHANNEL PATH STATUS David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 12/14] s390x/tcg: implement extract-CPU-time facility David Hildenbrand
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

KVM suppresses SIGA, setting cc=3. Let's do the same for TCG, so we're at
least equal.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/insn-data.def | 1 +
 target/s390x/translate.c   | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 2e47a6b5bc..250741330d 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -1056,6 +1056,7 @@
     C(0xb238, RSCH,    S,     Z,   0, 0, 0, 0, rsch, 0)
     C(0xb237, SAL,     S,     Z,   0, 0, 0, 0, sal, 0)
     C(0xb23c, SCHM,    S,     Z,   0, insn, 0, 0, schm, 0)
+    C(0xb274, SIGA,    S,     Z,   0, 0, 0, 0, siga, 0)
     C(0xb23a, STCPS,   S,     Z,   0, 0, 0, 0, stcps, 0)
     C(0xb233, SSCH,    S,     Z,   0, insn, 0, 0, ssch, 0)
     C(0xb239, STCRW,   S,     Z,   0, insn, 0, 0, stcrw, 0)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 16febf4274..83e1df0f48 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -4132,6 +4132,14 @@ static ExitStatus op_schm(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_siga(DisasContext *s, DisasOps *o)
+{
+    check_privileged(s);
+    /* From KVM code: Not provided, set CC = 3 for subchannel not operational */
+    gen_op_movi_cc(s, 3);
+    return NO_EXIT;
+}
+
 static ExitStatus op_stcps(DisasContext *s, DisasOps *o)
 {
     check_privileged(s);
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 12/14] s390x/tcg: implement extract-CPU-time facility
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (10 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 11/14] s390x/tcg: Implement SIGNAL ADAPTER instruction David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 13/14] s390x/tcg: we already implement the Set-Program-Parameter facility David Hildenbrand
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

It only provides the EXTRACT CPU TIME instruction. We can reuse the stpt
helper, which calculates the CPU timer value.

As the instruction is not privileged, but we don't have a CPU timer
value in case of linux user, we simply reuse cpu_get_host_ticks() to
produce some descending value.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/cpu_models.c  |  1 +
 target/s390x/helper.h      |  2 +-
 target/s390x/insn-data.def |  2 ++
 target/s390x/misc_helper.c | 21 +++++++++++++++------
 target/s390x/translate.c   | 31 +++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 94d24e423d..0be037eac1 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -834,6 +834,7 @@ static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
         S390_FEAT_STORE_CLOCK_FAST,
         S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
         S390_FEAT_ETF3_ENH,
+        S390_FEAT_EXTRACT_CPU_TIME,
         S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
         S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
         S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
diff --git a/target/s390x/helper.h b/target/s390x/helper.h
index 102fbdd7b9..2f17b62d3d 100644
--- a/target/s390x/helper.h
+++ b/target/s390x/helper.h
@@ -119,6 +119,7 @@ DEF_HELPER_4(cu24, i32, env, i32, i32, i32)
 DEF_HELPER_4(cu41, i32, env, i32, i32, i32)
 DEF_HELPER_4(cu42, i32, env, i32, i32, i32)
 DEF_HELPER_5(msa, i32, env, i32, i32, i32, i32)
+DEF_HELPER_FLAGS_1(stpt, TCG_CALL_NO_RWG, i64, env)
 
 #ifndef CONFIG_USER_ONLY
 DEF_HELPER_3(servc, i32, env, i64, i64)
@@ -130,7 +131,6 @@ DEF_HELPER_FLAGS_2(sckc, TCG_CALL_NO_RWG, void, env, i64)
 DEF_HELPER_FLAGS_2(sckpf, TCG_CALL_NO_RWG, void, env, i64)
 DEF_HELPER_FLAGS_1(stckc, TCG_CALL_NO_RWG, i64, env)
 DEF_HELPER_FLAGS_2(spt, TCG_CALL_NO_RWG, void, env, i64)
-DEF_HELPER_FLAGS_1(stpt, TCG_CALL_NO_RWG, i64, env)
 DEF_HELPER_4(stsi, i32, env, i64, i64, i64)
 DEF_HELPER_FLAGS_4(lctl, TCG_CALL_NO_WG, void, env, i32, i64, i32)
 DEF_HELPER_FLAGS_4(lctlg, TCG_CALL_NO_WG, void, env, i32, i64, i32)
diff --git a/target/s390x/insn-data.def b/target/s390x/insn-data.def
index 250741330d..11ee43dcbc 100644
--- a/target/s390x/insn-data.def
+++ b/target/s390x/insn-data.def
@@ -369,6 +369,8 @@
     C(0xb24f, EAR,     RRE,   Z,   0, 0, new, r1_32, ear, 0)
 /* EXTRACT CPU ATTRIBUTE */
     C(0xeb4c, ECAG,    RSY_a, GIE, 0, a2, r1, 0, ecag, 0)
+/* EXTRACT CPU TIME */
+    C(0xc801, ECTG,    SSF,   ECT, 0, 0, 0, 0, ectg, 0)
 /* EXTRACT FPC */
     C(0xb38c, EFPC,    RRE,   Z,   0, 0, new, r1_32, efpc, 0)
 /* EXTRACT PSW */
diff --git a/target/s390x/misc_helper.c b/target/s390x/misc_helper.c
index 7ddade2f0e..86da6aab7e 100644
--- a/target/s390x/misc_helper.c
+++ b/target/s390x/misc_helper.c
@@ -55,6 +55,21 @@ void HELPER(exception)(CPUS390XState *env, uint32_t excp)
     cpu_loop_exit(cs);
 }
 
+/* Store CPU Timer (also used for EXTRACT CPU TIME) */
+uint64_t HELPER(stpt)(CPUS390XState *env)
+{
+#if defined(CONFIG_USER_ONLY)
+    /*
+     * Fake a descending CPU timer. We could get negative values here,
+     * but we don't care as it is up to the OS when to process that
+     * interrupt and reset to > 0.
+     */
+    return UINT64_MAX - (uint64_t)cpu_get_host_ticks();
+#else
+    return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+#endif
+}
+
 #ifndef CONFIG_USER_ONLY
 
 /* SCLP service call */
@@ -178,12 +193,6 @@ void HELPER(spt)(CPUS390XState *env, uint64_t time)
     timer_mod(env->cpu_timer, env->cputm);
 }
 
-/* Store CPU Timer */
-uint64_t HELPER(stpt)(CPUS390XState *env)
-{
-    return time2tod(env->cputm - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
-}
-
 /* Store System Information */
 uint32_t HELPER(stsi)(CPUS390XState *env, uint64_t a0,
                       uint64_t r0, uint64_t r1)
diff --git a/target/s390x/translate.c b/target/s390x/translate.c
index 83e1df0f48..eede2ed157 100644
--- a/target/s390x/translate.c
+++ b/target/s390x/translate.c
@@ -3917,6 +3917,36 @@ static ExitStatus op_spm(DisasContext *s, DisasOps *o)
     return NO_EXIT;
 }
 
+static ExitStatus op_ectg(DisasContext *s, DisasOps *o)
+{
+    int b1 = get_field(s->fields, b1);
+    int d1 = get_field(s->fields, d1);
+    int b2 = get_field(s->fields, b2);
+    int d2 = get_field(s->fields, d2);
+    int r3 = get_field(s->fields, r3);
+    TCGv_i64 tmp = tcg_temp_new_i64();
+
+    /* fetch all operands first */
+    o->in1 = tcg_temp_new_i64();
+    tcg_gen_addi_i64(o->in1, regs[b1], d1);
+    o->in2 = tcg_temp_new_i64();
+    tcg_gen_addi_i64(o->in2, regs[b2], d2);
+    o->addr1 = get_address(s, 0, r3, 0);
+
+    /* load the third operand into r3 before modifying anything */
+    tcg_gen_qemu_ld64(regs[r3], o->addr1, get_mem_index(s));
+
+    /* subtract CPU timer from first operand and store in GR0 */
+    gen_helper_stpt(tmp, cpu_env);
+    tcg_gen_sub_i64(regs[0], o->in1, tmp);
+
+    /* store second operand in GR1 */
+    tcg_gen_mov_i64(regs[1], o->in2);
+
+    tcg_temp_free_i64(tmp);
+    return NO_EXIT;
+}
+
 #ifndef CONFIG_USER_ONLY
 static ExitStatus op_spka(DisasContext *s, DisasOps *o)
 {
@@ -5679,6 +5709,7 @@ enum DisasInsnEnum {
 #define FAC_MSA3        S390_FEAT_MSA_EXT_3 /* msa-extension-3 facility */
 #define FAC_MSA4        S390_FEAT_MSA_EXT_4 /* msa-extension-4 facility */
 #define FAC_MSA5        S390_FEAT_MSA_EXT_5 /* msa-extension-5 facility */
+#define FAC_ECT         S390_FEAT_EXTRACT_CPU_TIME
 
 static const DisasInsn insn_info[] = {
 #include "insn-data.def"
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 13/14] s390x/tcg: we already implement the Set-Program-Parameter facility
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (11 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 12/14] s390x/tcg: implement extract-CPU-time facility David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12 David Hildenbrand
  2017-12-11 10:13 ` [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions Cornelia Huck
  14 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

The Set-Program-Parameter facility (also known as Load-Program-Parameter
facility) provides the LPP instruction used to load the program
parameter. We already implement that instruction in TCG, so add it to our
list.

Note: Not documented in the PoP but in "The Load-Program-Parameter and
CPU-Measurement Facilities) - SA23-2260-05 document.

While at it, make the whole list ordered (according to cpu_features_def.h).

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/cpu_models.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 0be037eac1..edac7fdecf 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -824,12 +824,12 @@ static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
         S390_FEAT_IDTE_SEGMENT,
         S390_FEAT_STFLE,
         S390_FEAT_SENSE_RUNNING_STATUS,
-        S390_FEAT_EXTENDED_IMMEDIATE,
         S390_FEAT_EXTENDED_TRANSLATION_2,
         S390_FEAT_MSA,
-        S390_FEAT_EXTENDED_TRANSLATION_3,
         S390_FEAT_LONG_DISPLACEMENT,
         S390_FEAT_LONG_DISPLACEMENT_FAST,
+        S390_FEAT_EXTENDED_IMMEDIATE,
+        S390_FEAT_EXTENDED_TRANSLATION_3,
         S390_FEAT_ETF2_ENH,
         S390_FEAT_STORE_CLOCK_FAST,
         S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
@@ -839,6 +839,7 @@ static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
         S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
         S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
         S390_FEAT_EXECUTE_EXT,
+        S390_FEAT_SET_PROGRAM_PARAMETERS,
         S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
         S390_FEAT_STFLE_45,
         S390_FEAT_STFLE_49,
-- 
2.14.3

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

* [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (12 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 13/14] s390x/tcg: we already implement the Set-Program-Parameter facility David Hildenbrand
@ 2017-12-08 16:02 ` David Hildenbrand
  2017-12-08 16:26   ` Cornelia Huck
  2017-12-11 10:13 ` [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions Cornelia Huck
  14 siblings, 1 reply; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:02 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

We are good enough to boot upstream Linux kernels / Fedora 26/27. That
should be sufficient for now.

As the QEMU CPU model is migration safe, let's add compatibility code.
Generate the feature list to reduce the chance of messing things up in the
future.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/s390x/s390-virtio-ccw.c  |   8 ++++
 target/s390x/cpu.h          |   3 ++
 target/s390x/cpu_models.c   | 100 ++++++++++++++++++--------------------------
 target/s390x/cpu_models.h   |   1 +
 target/s390x/gen-features.c |  87 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 140 insertions(+), 59 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index a23b8aec9f..9666fca04f 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -721,6 +721,10 @@ bool css_migration_enabled(void)
 
 static void ccw_machine_2_12_instance_options(MachineState *machine)
 {
+    static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
+
+    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
+    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
 }
 
 static void ccw_machine_2_12_class_options(MachineClass *mc)
@@ -730,7 +734,11 @@ DEFINE_CCW_MACHINE(2_12, "2.12", true);
 
 static void ccw_machine_2_11_instance_options(MachineState *machine)
 {
+    static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
     ccw_machine_2_12_instance_options(machine);
+
+    /* before 2.12 we emulated the very first z900 */
+    s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
 }
 
 static void ccw_machine_2_11_class_options(MachineClass *mc)
diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index f9d4d62c48..6a91739ece 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -722,6 +722,9 @@ static inline unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
 /* cpu_models.c */
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 #define cpu_list s390_cpu_list
+void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                             const S390FeatBitmap features);
+
 
 /* helper.c */
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model)
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index edac7fdecf..f0577f8155 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -15,7 +15,6 @@
 #include "internal.h"
 #include "kvm_s390x.h"
 #include "sysemu/kvm.h"
-#include "gen-features.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qemu/error-report.h"
@@ -81,6 +80,11 @@ static S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"),
 };
 
+#define QEMU_MAX_CPU_TYPE 0x2827
+#define QEMU_MAX_CPU_GEN 12
+#define QEMU_MAX_CPU_EC_GA 2
+static const S390FeatBitmap qemu_max_cpu_feat = { S390_FEAT_LIST_QEMU_MAX };
+
 /* features part of a base model but not relevant for finding a base model */
 S390FeatBitmap ignored_base_feat;
 
@@ -812,51 +816,6 @@ static void check_compatibility(const S390CPUModel *max_model,
                   "available in the configuration: ");
 }
 
-/**
- * The base TCG CPU model "qemu" is based on the z900. However, we already
- * can also emulate some additional features of later CPU generations, so
- * we add these additional feature bits here.
- */
-static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
-{
-    static const int feats[] = {
-        S390_FEAT_DAT_ENH,
-        S390_FEAT_IDTE_SEGMENT,
-        S390_FEAT_STFLE,
-        S390_FEAT_SENSE_RUNNING_STATUS,
-        S390_FEAT_EXTENDED_TRANSLATION_2,
-        S390_FEAT_MSA,
-        S390_FEAT_LONG_DISPLACEMENT,
-        S390_FEAT_LONG_DISPLACEMENT_FAST,
-        S390_FEAT_EXTENDED_IMMEDIATE,
-        S390_FEAT_EXTENDED_TRANSLATION_3,
-        S390_FEAT_ETF2_ENH,
-        S390_FEAT_STORE_CLOCK_FAST,
-        S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
-        S390_FEAT_ETF3_ENH,
-        S390_FEAT_EXTRACT_CPU_TIME,
-        S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
-        S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
-        S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
-        S390_FEAT_EXECUTE_EXT,
-        S390_FEAT_SET_PROGRAM_PARAMETERS,
-        S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
-        S390_FEAT_STFLE_45,
-        S390_FEAT_STFLE_49,
-        S390_FEAT_LOCAL_TLB_CLEARING,
-        S390_FEAT_INTERLOCKED_ACCESS_2,
-        S390_FEAT_STFLE_53,
-        S390_FEAT_MSA_EXT_5,
-        S390_FEAT_MSA_EXT_3,
-        S390_FEAT_MSA_EXT_4,
-    };
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(feats); i++) {
-        set_bit(feats[i], fbm);
-    }
-}
-
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
     static S390CPUModel max_model;
@@ -869,12 +828,10 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
     if (kvm_enabled()) {
         kvm_s390_get_host_cpu_model(&max_model, errp);
     } else {
-        /* TCG emulates a z900 (with some optional additional features) */
-        max_model.def = &s390_cpu_defs[0];
-        bitmap_copy(max_model.features, max_model.def->default_feat,
-                    S390_FEAT_MAX);
-        add_qemu_cpu_model_features(max_model.features);
-    }
+        max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
+                                          QEMU_MAX_CPU_EC_GA, NULL);
+        bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
+   }
     if (!*errp) {
         cached = true;
         return &max_model;
@@ -1130,18 +1087,43 @@ static void s390_host_cpu_model_initfn(Object *obj)
 }
 #endif
 
+static S390CPUDef s390_qemu_cpu_def;
+static S390CPUModel s390_qemu_cpu_model;
+
+/* Set the qemu CPU model (on machine initialization). Must not be called
+ * once CPUs have been created.
+ */
+void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                             const S390FeatBitmap features)
+{
+    const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL);
+
+    g_assert(def);
+    g_assert(QTAILQ_EMPTY(&cpus));
+
+    /* TCG emulates some features that can usually not be enabled with
+     * the emulated machine generation. Make sure they can be enabled
+     * when using the QEMU model by adding them to full_feat. We have
+     * to copy the definition to do that.
+     */
+    memcpy(&s390_qemu_cpu_def, def, sizeof(s390_qemu_cpu_def));
+    bitmap_or(s390_qemu_cpu_def.full_feat, s390_qemu_cpu_def.full_feat,
+              qemu_max_cpu_feat, S390_FEAT_MAX);
+
+    /* build the CPU model */
+    s390_qemu_cpu_model.def = &s390_qemu_cpu_def;
+    bitmap_copy(s390_qemu_cpu_model.features, features, S390_FEAT_MAX);
+}
+
 static void s390_qemu_cpu_model_initfn(Object *obj)
 {
-    static S390CPUDef s390_qemu_cpu_defs;
     S390CPU *cpu = S390_CPU(obj);
 
     cpu->model = g_malloc0(sizeof(*cpu->model));
-    /* TCG emulates a z900 (with some optional additional features) */
-    memcpy(&s390_qemu_cpu_defs, &s390_cpu_defs[0], sizeof(s390_qemu_cpu_defs));
-    add_qemu_cpu_model_features(s390_qemu_cpu_defs.full_feat);
-    cpu->model->def = &s390_qemu_cpu_defs;
-    bitmap_copy(cpu->model->features, cpu->model->def->default_feat,
-                S390_FEAT_MAX);
+    /* has to be initialized by now via s390_set_qemu_cpu_model() */
+    g_assert(s390_qemu_cpu_model.def);
+    /* copy the CPU model so we can modify it */
+    memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
 }
 
 static void s390_cpu_model_finalize(Object *obj)
diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h
index 4c6dee1871..11cf5386fb 100644
--- a/target/s390x/cpu_models.h
+++ b/target/s390x/cpu_models.h
@@ -14,6 +14,7 @@
 #define TARGET_S390X_CPU_MODELS_H
 
 #include "cpu_features.h"
+#include "gen-features.h"
 #include "qom/cpu.h"
 
 /* static CPU definition */
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 68e6c31b4b..983f2dcd52 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -536,6 +536,51 @@ static uint16_t default_GEN14_GA1[] = {
     S390_FEAT_GROUP_MSA_EXT_8,
 };
 
+/* QEMU (CPU model) features */
+
+static uint16_t qemu_V2_11[] = {
+    S390_FEAT_GROUP_PLO,
+    S390_FEAT_ESAN3,
+    S390_FEAT_ZARCH,
+};
+
+static uint16_t qemu_V2_12[] = {
+    S390_FEAT_DAT_ENH,
+    S390_FEAT_IDTE_SEGMENT,
+    S390_FEAT_STFLE,
+    S390_FEAT_SENSE_RUNNING_STATUS,
+    S390_FEAT_EXTENDED_TRANSLATION_2,
+    S390_FEAT_MSA,
+    S390_FEAT_LONG_DISPLACEMENT,
+    S390_FEAT_LONG_DISPLACEMENT_FAST,
+    S390_FEAT_EXTENDED_IMMEDIATE,
+    S390_FEAT_EXTENDED_TRANSLATION_3,
+    S390_FEAT_ETF2_ENH,
+    S390_FEAT_STORE_CLOCK_FAST,
+    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
+    S390_FEAT_ETF3_ENH,
+    S390_FEAT_EXTRACT_CPU_TIME,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
+    S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
+    S390_FEAT_EXECUTE_EXT,
+    S390_FEAT_SET_PROGRAM_PARAMETERS,
+    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
+    S390_FEAT_STFLE_45,
+    S390_FEAT_STFLE_49,
+    S390_FEAT_LOCAL_TLB_CLEARING,
+    S390_FEAT_INTERLOCKED_ACCESS_2,
+    S390_FEAT_STFLE_53,
+    S390_FEAT_MSA_EXT_4,
+    S390_FEAT_MSA_EXT_3,
+};
+
+/* add all new definitions before this point */
+static uint16_t qemu_MAX[] = {
+    /* generates a dependency warning, leave it out for now */
+    S390_FEAT_MSA_EXT_5,
+};
+
 /****** END FEATURE DEFS ******/
 
 #define _YEARS  "2016"
@@ -627,6 +672,24 @@ static FeatGroupDefSpec FeatGroupDef[] = {
     FEAT_GROUP_INITIALIZER(MSA_EXT_8),
 };
 
+#define QEMU_FEAT_INITIALIZER(_name)                   \
+    {                                                  \
+        .name = "S390_FEAT_LIST_QEMU_" #_name,         \
+        .bits =                                        \
+            { .data = qemu_##_name,                    \
+              .len = ARRAY_SIZE(qemu_##_name) },       \
+    }
+
+/*******************************
+ * QEMU (CPU model) features
+ *******************************/
+static FeatGroupDefSpec QemuFeatDef[] = {
+    QEMU_FEAT_INITIALIZER(V2_11),
+    QEMU_FEAT_INITIALIZER(V2_12),
+    QEMU_FEAT_INITIALIZER(MAX),
+};
+
+
 static void set_bits(uint64_t list[], BitSpec bits)
 {
     uint32_t i;
@@ -684,6 +747,29 @@ static void print_feature_defs(void)
     }
 }
 
+static void print_qemu_feature_defs(void)
+{
+    uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
+    int i, j;
+
+    printf("\n/* QEMU (CPU model) feature list data */\n");
+
+    /* for now we assume that we only add new features */
+    for (i = 0; i < ARRAY_SIZE(QemuFeatDef); i++) {
+        set_bits(feat, QemuFeatDef[i].bits);
+
+        printf("#define %s\t", QemuFeatDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(feat); j++) {
+            printf("0x%016"PRIx64"ULL", feat[j]);
+            if (j < ARRAY_SIZE(feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+    }
+}
+
 static void print_feature_group_defs(void)
 {
     int i, j;
@@ -721,6 +807,7 @@ int main(int argc, char *argv[])
            "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
     print_feature_defs();
     print_feature_group_defs();
+    print_qemu_feature_defs();
     printf("\n#endif\n");
     return 0;
 }
-- 
2.14.3

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12 David Hildenbrand
@ 2017-12-08 16:26   ` Cornelia Huck
  2017-12-08 16:29     ` David Hildenbrand
  2017-12-08 16:55     ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
  0 siblings, 2 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-08 16:26 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Fri,  8 Dec 2017 17:02:07 +0100
David Hildenbrand <david@redhat.com> wrote:

> We are good enough to boot upstream Linux kernels / Fedora 26/27. That
> should be sufficient for now.
> 
> As the QEMU CPU model is migration safe, let's add compatibility code.
> Generate the feature list to reduce the chance of messing things up in the
> future.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  hw/s390x/s390-virtio-ccw.c  |   8 ++++
>  target/s390x/cpu.h          |   3 ++
>  target/s390x/cpu_models.c   | 100 ++++++++++++++++++--------------------------
>  target/s390x/cpu_models.h   |   1 +
>  target/s390x/gen-features.c |  87 ++++++++++++++++++++++++++++++++++++++
>  5 files changed, 140 insertions(+), 59 deletions(-)

Unfortunately, this patch makes mingw unhappy (x86_64-w64-mingw32 on my
F26 laptop):

In file included from /home/cohuck/git/qemu/target/s390x/cpu_models.h:17:0,
                 from /home/cohuck/git/qemu/target/s390x/cpu.h:28,
                 from /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:16:
/home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c: In function 'ccw_machine_2_12_instance_options':
./gen-features.h:96:35: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
 #define S390_FEAT_LIST_QEMU_V2_12 0x3000e918fd6de14fULL,0x000ffffff0000000ULL,0x0000000000000000ULL,0x0000000000000000ULL
                                   ^
/home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:728:51: note: in expansion of macro 'S390_FEAT_LIST_QEMU_V2_12'
     static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~


> 
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index a23b8aec9f..9666fca04f 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -721,6 +721,10 @@ bool css_migration_enabled(void)
>  
>  static void ccw_machine_2_12_instance_options(MachineState *machine)
>  {
> +    static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
> +
> +    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
> +    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
>  }
>  
>  static void ccw_machine_2_12_class_options(MachineClass *mc)
> @@ -730,7 +734,11 @@ DEFINE_CCW_MACHINE(2_12, "2.12", true);
>  
>  static void ccw_machine_2_11_instance_options(MachineState *machine)
>  {
> +    static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
>      ccw_machine_2_12_instance_options(machine);
> +
> +    /* before 2.12 we emulated the very first z900 */
> +    s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
>  }
>  
>  static void ccw_machine_2_11_class_options(MachineClass *mc)
> diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
> index f9d4d62c48..6a91739ece 100644
> --- a/target/s390x/cpu.h
> +++ b/target/s390x/cpu.h
> @@ -722,6 +722,9 @@ static inline unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
>  /* cpu_models.c */
>  void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
>  #define cpu_list s390_cpu_list
> +void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
> +                             const S390FeatBitmap features);
> +
>  
>  /* helper.c */
>  #define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model)
> diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
> index edac7fdecf..f0577f8155 100644
> --- a/target/s390x/cpu_models.c
> +++ b/target/s390x/cpu_models.c
> @@ -15,7 +15,6 @@
>  #include "internal.h"
>  #include "kvm_s390x.h"
>  #include "sysemu/kvm.h"
> -#include "gen-features.h"
>  #include "qapi/error.h"
>  #include "qapi/visitor.h"
>  #include "qemu/error-report.h"
> @@ -81,6 +80,11 @@ static S390CPUDef s390_cpu_defs[] = {
>      CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"),
>  };
>  
> +#define QEMU_MAX_CPU_TYPE 0x2827
> +#define QEMU_MAX_CPU_GEN 12
> +#define QEMU_MAX_CPU_EC_GA 2
> +static const S390FeatBitmap qemu_max_cpu_feat = { S390_FEAT_LIST_QEMU_MAX };
> +
>  /* features part of a base model but not relevant for finding a base model */
>  S390FeatBitmap ignored_base_feat;
>  
> @@ -812,51 +816,6 @@ static void check_compatibility(const S390CPUModel *max_model,
>                    "available in the configuration: ");
>  }
>  
> -/**
> - * The base TCG CPU model "qemu" is based on the z900. However, we already
> - * can also emulate some additional features of later CPU generations, so
> - * we add these additional feature bits here.
> - */
> -static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
> -{
> -    static const int feats[] = {
> -        S390_FEAT_DAT_ENH,
> -        S390_FEAT_IDTE_SEGMENT,
> -        S390_FEAT_STFLE,
> -        S390_FEAT_SENSE_RUNNING_STATUS,
> -        S390_FEAT_EXTENDED_TRANSLATION_2,
> -        S390_FEAT_MSA,
> -        S390_FEAT_LONG_DISPLACEMENT,
> -        S390_FEAT_LONG_DISPLACEMENT_FAST,
> -        S390_FEAT_EXTENDED_IMMEDIATE,
> -        S390_FEAT_EXTENDED_TRANSLATION_3,
> -        S390_FEAT_ETF2_ENH,
> -        S390_FEAT_STORE_CLOCK_FAST,
> -        S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
> -        S390_FEAT_ETF3_ENH,
> -        S390_FEAT_EXTRACT_CPU_TIME,
> -        S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
> -        S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
> -        S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
> -        S390_FEAT_EXECUTE_EXT,
> -        S390_FEAT_SET_PROGRAM_PARAMETERS,
> -        S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
> -        S390_FEAT_STFLE_45,
> -        S390_FEAT_STFLE_49,
> -        S390_FEAT_LOCAL_TLB_CLEARING,
> -        S390_FEAT_INTERLOCKED_ACCESS_2,
> -        S390_FEAT_STFLE_53,
> -        S390_FEAT_MSA_EXT_5,
> -        S390_FEAT_MSA_EXT_3,
> -        S390_FEAT_MSA_EXT_4,
> -    };
> -    int i;
> -
> -    for (i = 0; i < ARRAY_SIZE(feats); i++) {
> -        set_bit(feats[i], fbm);
> -    }
> -}
> -
>  static S390CPUModel *get_max_cpu_model(Error **errp)
>  {
>      static S390CPUModel max_model;
> @@ -869,12 +828,10 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
>      if (kvm_enabled()) {
>          kvm_s390_get_host_cpu_model(&max_model, errp);
>      } else {
> -        /* TCG emulates a z900 (with some optional additional features) */
> -        max_model.def = &s390_cpu_defs[0];
> -        bitmap_copy(max_model.features, max_model.def->default_feat,
> -                    S390_FEAT_MAX);
> -        add_qemu_cpu_model_features(max_model.features);
> -    }
> +        max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
> +                                          QEMU_MAX_CPU_EC_GA, NULL);
> +        bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
> +   }
>      if (!*errp) {
>          cached = true;
>          return &max_model;
> @@ -1130,18 +1087,43 @@ static void s390_host_cpu_model_initfn(Object *obj)
>  }
>  #endif
>  
> +static S390CPUDef s390_qemu_cpu_def;
> +static S390CPUModel s390_qemu_cpu_model;
> +
> +/* Set the qemu CPU model (on machine initialization). Must not be called
> + * once CPUs have been created.
> + */
> +void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
> +                             const S390FeatBitmap features)
> +{
> +    const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL);
> +
> +    g_assert(def);
> +    g_assert(QTAILQ_EMPTY(&cpus));
> +
> +    /* TCG emulates some features that can usually not be enabled with
> +     * the emulated machine generation. Make sure they can be enabled
> +     * when using the QEMU model by adding them to full_feat. We have
> +     * to copy the definition to do that.
> +     */
> +    memcpy(&s390_qemu_cpu_def, def, sizeof(s390_qemu_cpu_def));
> +    bitmap_or(s390_qemu_cpu_def.full_feat, s390_qemu_cpu_def.full_feat,
> +              qemu_max_cpu_feat, S390_FEAT_MAX);
> +
> +    /* build the CPU model */
> +    s390_qemu_cpu_model.def = &s390_qemu_cpu_def;
> +    bitmap_copy(s390_qemu_cpu_model.features, features, S390_FEAT_MAX);
> +}
> +
>  static void s390_qemu_cpu_model_initfn(Object *obj)
>  {
> -    static S390CPUDef s390_qemu_cpu_defs;
>      S390CPU *cpu = S390_CPU(obj);
>  
>      cpu->model = g_malloc0(sizeof(*cpu->model));
> -    /* TCG emulates a z900 (with some optional additional features) */
> -    memcpy(&s390_qemu_cpu_defs, &s390_cpu_defs[0], sizeof(s390_qemu_cpu_defs));
> -    add_qemu_cpu_model_features(s390_qemu_cpu_defs.full_feat);
> -    cpu->model->def = &s390_qemu_cpu_defs;
> -    bitmap_copy(cpu->model->features, cpu->model->def->default_feat,
> -                S390_FEAT_MAX);
> +    /* has to be initialized by now via s390_set_qemu_cpu_model() */
> +    g_assert(s390_qemu_cpu_model.def);
> +    /* copy the CPU model so we can modify it */
> +    memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
>  }
>  
>  static void s390_cpu_model_finalize(Object *obj)
> diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h
> index 4c6dee1871..11cf5386fb 100644
> --- a/target/s390x/cpu_models.h
> +++ b/target/s390x/cpu_models.h
> @@ -14,6 +14,7 @@
>  #define TARGET_S390X_CPU_MODELS_H
>  
>  #include "cpu_features.h"
> +#include "gen-features.h"
>  #include "qom/cpu.h"
>  
>  /* static CPU definition */
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index 68e6c31b4b..983f2dcd52 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -536,6 +536,51 @@ static uint16_t default_GEN14_GA1[] = {
>      S390_FEAT_GROUP_MSA_EXT_8,
>  };
>  
> +/* QEMU (CPU model) features */
> +
> +static uint16_t qemu_V2_11[] = {
> +    S390_FEAT_GROUP_PLO,
> +    S390_FEAT_ESAN3,
> +    S390_FEAT_ZARCH,
> +};
> +
> +static uint16_t qemu_V2_12[] = {
> +    S390_FEAT_DAT_ENH,
> +    S390_FEAT_IDTE_SEGMENT,
> +    S390_FEAT_STFLE,
> +    S390_FEAT_SENSE_RUNNING_STATUS,
> +    S390_FEAT_EXTENDED_TRANSLATION_2,
> +    S390_FEAT_MSA,
> +    S390_FEAT_LONG_DISPLACEMENT,
> +    S390_FEAT_LONG_DISPLACEMENT_FAST,
> +    S390_FEAT_EXTENDED_IMMEDIATE,
> +    S390_FEAT_EXTENDED_TRANSLATION_3,
> +    S390_FEAT_ETF2_ENH,
> +    S390_FEAT_STORE_CLOCK_FAST,
> +    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
> +    S390_FEAT_ETF3_ENH,
> +    S390_FEAT_EXTRACT_CPU_TIME,
> +    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
> +    S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
> +    S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
> +    S390_FEAT_EXECUTE_EXT,
> +    S390_FEAT_SET_PROGRAM_PARAMETERS,
> +    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
> +    S390_FEAT_STFLE_45,
> +    S390_FEAT_STFLE_49,
> +    S390_FEAT_LOCAL_TLB_CLEARING,
> +    S390_FEAT_INTERLOCKED_ACCESS_2,
> +    S390_FEAT_STFLE_53,
> +    S390_FEAT_MSA_EXT_4,
> +    S390_FEAT_MSA_EXT_3,
> +};
> +
> +/* add all new definitions before this point */
> +static uint16_t qemu_MAX[] = {
> +    /* generates a dependency warning, leave it out for now */
> +    S390_FEAT_MSA_EXT_5,
> +};
> +
>  /****** END FEATURE DEFS ******/
>  
>  #define _YEARS  "2016"
> @@ -627,6 +672,24 @@ static FeatGroupDefSpec FeatGroupDef[] = {
>      FEAT_GROUP_INITIALIZER(MSA_EXT_8),
>  };
>  
> +#define QEMU_FEAT_INITIALIZER(_name)                   \
> +    {                                                  \
> +        .name = "S390_FEAT_LIST_QEMU_" #_name,         \
> +        .bits =                                        \
> +            { .data = qemu_##_name,                    \
> +              .len = ARRAY_SIZE(qemu_##_name) },       \
> +    }
> +
> +/*******************************
> + * QEMU (CPU model) features
> + *******************************/
> +static FeatGroupDefSpec QemuFeatDef[] = {
> +    QEMU_FEAT_INITIALIZER(V2_11),
> +    QEMU_FEAT_INITIALIZER(V2_12),
> +    QEMU_FEAT_INITIALIZER(MAX),
> +};
> +
> +
>  static void set_bits(uint64_t list[], BitSpec bits)
>  {
>      uint32_t i;
> @@ -684,6 +747,29 @@ static void print_feature_defs(void)
>      }
>  }
>  
> +static void print_qemu_feature_defs(void)
> +{
> +    uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
> +    int i, j;
> +
> +    printf("\n/* QEMU (CPU model) feature list data */\n");
> +
> +    /* for now we assume that we only add new features */
> +    for (i = 0; i < ARRAY_SIZE(QemuFeatDef); i++) {
> +        set_bits(feat, QemuFeatDef[i].bits);
> +
> +        printf("#define %s\t", QemuFeatDef[i].name);
> +        for (j = 0; j < ARRAY_SIZE(feat); j++) {
> +            printf("0x%016"PRIx64"ULL", feat[j]);
> +            if (j < ARRAY_SIZE(feat) - 1) {
> +                printf(",");
> +            } else {
> +                printf("\n");
> +            }
> +        }
> +    }
> +}
> +
>  static void print_feature_group_defs(void)
>  {
>      int i, j;
> @@ -721,6 +807,7 @@ int main(int argc, char *argv[])
>             "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
>      print_feature_defs();
>      print_feature_group_defs();
> +    print_qemu_feature_defs();
>      printf("\n#endif\n");
>      return 0;
>  }

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:26   ` Cornelia Huck
@ 2017-12-08 16:29     ` David Hildenbrand
  2017-12-08 16:34       ` Daniel P. Berrange
  2017-12-08 16:55     ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
  1 sibling, 1 reply; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:29 UTC (permalink / raw)
  To: Cornelia Huck
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On 08.12.2017 17:26, Cornelia Huck wrote:
> On Fri,  8 Dec 2017 17:02:07 +0100
> David Hildenbrand <david@redhat.com> wrote:
> 
>> We are good enough to boot upstream Linux kernels / Fedora 26/27. That
>> should be sufficient for now.
>>
>> As the QEMU CPU model is migration safe, let's add compatibility code.
>> Generate the feature list to reduce the chance of messing things up in the
>> future.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>  hw/s390x/s390-virtio-ccw.c  |   8 ++++
>>  target/s390x/cpu.h          |   3 ++
>>  target/s390x/cpu_models.c   | 100 ++++++++++++++++++--------------------------
>>  target/s390x/cpu_models.h   |   1 +
>>  target/s390x/gen-features.c |  87 ++++++++++++++++++++++++++++++++++++++
>>  5 files changed, 140 insertions(+), 59 deletions(-)
> 
> Unfortunately, this patch makes mingw unhappy (x86_64-w64-mingw32 on my
> F26 laptop):
> 
> In file included from /home/cohuck/git/qemu/target/s390x/cpu_models.h:17:0,
>                  from /home/cohuck/git/qemu/target/s390x/cpu.h:28,
>                  from /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:16:
> /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c: In function 'ccw_machine_2_12_instance_options':
> ./gen-features.h:96:35: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
>  #define S390_FEAT_LIST_QEMU_V2_12 0x3000e918fd6de14fULL,0x000ffffff0000000ULL,0x0000000000000000ULL,0x0000000000000000ULL
>                                    ^
> /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:728:51: note: in expansion of macro 'S390_FEAT_LIST_QEMU_V2_12'
>      static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
>                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~

Huh? we have ULL added to all constants, this should not get reported.

-- 

Thanks,

David / dhildenb

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:29     ` David Hildenbrand
@ 2017-12-08 16:34       ` Daniel P. Berrange
  2017-12-08 16:39         ` David Hildenbrand
  0 siblings, 1 reply; 31+ messages in thread
From: Daniel P. Berrange @ 2017-12-08 16:34 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Cornelia Huck, Christian Borntraeger, qemu-s390x, qemu-devel,
	Alexander Graf, Richard Henderson

On Fri, Dec 08, 2017 at 05:29:36PM +0100, David Hildenbrand wrote:
> On 08.12.2017 17:26, Cornelia Huck wrote:
> > On Fri,  8 Dec 2017 17:02:07 +0100
> > David Hildenbrand <david@redhat.com> wrote:
> > 
> >> We are good enough to boot upstream Linux kernels / Fedora 26/27. That
> >> should be sufficient for now.
> >>
> >> As the QEMU CPU model is migration safe, let's add compatibility code.
> >> Generate the feature list to reduce the chance of messing things up in the
> >> future.
> >>
> >> Signed-off-by: David Hildenbrand <david@redhat.com>
> >> ---
> >>  hw/s390x/s390-virtio-ccw.c  |   8 ++++
> >>  target/s390x/cpu.h          |   3 ++
> >>  target/s390x/cpu_models.c   | 100 ++++++++++++++++++--------------------------
> >>  target/s390x/cpu_models.h   |   1 +
> >>  target/s390x/gen-features.c |  87 ++++++++++++++++++++++++++++++++++++++
> >>  5 files changed, 140 insertions(+), 59 deletions(-)
> > 
> > Unfortunately, this patch makes mingw unhappy (x86_64-w64-mingw32 on my
> > F26 laptop):
> > 
> > In file included from /home/cohuck/git/qemu/target/s390x/cpu_models.h:17:0,
> >                  from /home/cohuck/git/qemu/target/s390x/cpu.h:28,
> >                  from /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:16:
> > /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c: In function 'ccw_machine_2_12_instance_options':
> > ./gen-features.h:96:35: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
> >  #define S390_FEAT_LIST_QEMU_V2_12 0x3000e918fd6de14fULL,0x000ffffff0000000ULL,0x0000000000000000ULL,0x0000000000000000ULL
> >                                    ^
> > /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:728:51: note: in expansion of macro 'S390_FEAT_LIST_QEMU_V2_12'
> >      static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
> >                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Huh? we have ULL added to all constants, this should not get reported.

Isn't the problem here the S390FeatBitmap type which is a 'unsigned long',
so not guaranteed to be 64-bits on 32-bit hosts ?

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:34       ` Daniel P. Berrange
@ 2017-12-08 16:39         ` David Hildenbrand
  0 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:39 UTC (permalink / raw)
  To: Daniel P. Berrange
  Cc: Cornelia Huck, Christian Borntraeger, qemu-s390x, qemu-devel,
	Alexander Graf, Richard Henderson

On 08.12.2017 17:34, Daniel P. Berrange wrote:
> On Fri, Dec 08, 2017 at 05:29:36PM +0100, David Hildenbrand wrote:
>> On 08.12.2017 17:26, Cornelia Huck wrote:
>>> On Fri,  8 Dec 2017 17:02:07 +0100
>>> David Hildenbrand <david@redhat.com> wrote:
>>>
>>>> We are good enough to boot upstream Linux kernels / Fedora 26/27. That
>>>> should be sufficient for now.
>>>>
>>>> As the QEMU CPU model is migration safe, let's add compatibility code.
>>>> Generate the feature list to reduce the chance of messing things up in the
>>>> future.
>>>>
>>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>>> ---
>>>>  hw/s390x/s390-virtio-ccw.c  |   8 ++++
>>>>  target/s390x/cpu.h          |   3 ++
>>>>  target/s390x/cpu_models.c   | 100 ++++++++++++++++++--------------------------
>>>>  target/s390x/cpu_models.h   |   1 +
>>>>  target/s390x/gen-features.c |  87 ++++++++++++++++++++++++++++++++++++++
>>>>  5 files changed, 140 insertions(+), 59 deletions(-)
>>>
>>> Unfortunately, this patch makes mingw unhappy (x86_64-w64-mingw32 on my
>>> F26 laptop):
>>>
>>> In file included from /home/cohuck/git/qemu/target/s390x/cpu_models.h:17:0,
>>>                  from /home/cohuck/git/qemu/target/s390x/cpu.h:28,
>>>                  from /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:16:
>>> /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c: In function 'ccw_machine_2_12_instance_options':
>>> ./gen-features.h:96:35: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
>>>  #define S390_FEAT_LIST_QEMU_V2_12 0x3000e918fd6de14fULL,0x000ffffff0000000ULL,0x0000000000000000ULL,0x0000000000000000ULL
>>>                                    ^
>>> /home/cohuck/git/qemu/hw/s390x/s390-virtio-ccw.c:728:51: note: in expansion of macro 'S390_FEAT_LIST_QEMU_V2_12'
>>>      static const S390FeatBitmap qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
>>>                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> Huh? we have ULL added to all constants, this should not get reported.
> 
> Isn't the problem here the S390FeatBitmap type which is a 'unsigned long',
> so not guaranteed to be 64-bits on 32-bit hosts ?

Right, I remember why I needed that ugly hack in cpu_model.c, where we
initialize the bitmap from an array (e.g. base_init). Thanks for the hint.

> 
> Regards,
> Daniel
> 


-- 

Thanks,

David / dhildenb

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

* [Qemu-devel] [PATCH v4 for-2-12] s390x: change the QEMU cpu model to a stripped down z12
  2017-12-08 16:26   ` Cornelia Huck
  2017-12-08 16:29     ` David Hildenbrand
@ 2017-12-08 16:55     ` David Hildenbrand
  2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
  2017-12-13 17:15       ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
  1 sibling, 2 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-08 16:55 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

We are good enough to boot upstream Linux kernels / Fedora 26/27. That
should be sufficient for now.

As the QEMU CPU model is migration safe, let's add compatibility code.
Generate the feature list to reduce the chance of messing things up in the
future.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 hw/s390x/s390-virtio-ccw.c  |   8 ++++
 target/s390x/cpu.h          |   3 ++
 target/s390x/cpu_models.c   | 103 +++++++++++++++++++-------------------------
 target/s390x/cpu_models.h   |   1 +
 target/s390x/gen-features.c |  87 +++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 59 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index a23b8aec9f..b76d87bb5d 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -721,6 +721,10 @@ bool css_migration_enabled(void)
 
 static void ccw_machine_2_12_instance_options(MachineState *machine)
 {
+    static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
+
+    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
+    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
 }
 
 static void ccw_machine_2_12_class_options(MachineClass *mc)
@@ -730,7 +734,11 @@ DEFINE_CCW_MACHINE(2_12, "2.12", true);
 
 static void ccw_machine_2_11_instance_options(MachineState *machine)
 {
+    static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_11 };
     ccw_machine_2_12_instance_options(machine);
+
+    /* before 2.12 we emulated the very first z900 */
+    s390_set_qemu_cpu_model(0x2064, 7, 1, qemu_cpu_feat);
 }
 
 static void ccw_machine_2_11_class_options(MachineClass *mc)
diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index f9d4d62c48..1a8b6b9ae9 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -722,6 +722,9 @@ static inline unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
 /* cpu_models.c */
 void s390_cpu_list(FILE *f, fprintf_function cpu_fprintf);
 #define cpu_list s390_cpu_list
+void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                             const S390FeatInit feat_init);
+
 
 /* helper.c */
 #define cpu_init(cpu_model) cpu_generic_init(TYPE_S390_CPU, cpu_model)
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index edac7fdecf..7404ef52c6 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -15,7 +15,6 @@
 #include "internal.h"
 #include "kvm_s390x.h"
 #include "sysemu/kvm.h"
-#include "gen-features.h"
 #include "qapi/error.h"
 #include "qapi/visitor.h"
 #include "qemu/error-report.h"
@@ -81,6 +80,12 @@ static S390CPUDef s390_cpu_defs[] = {
     CPUDEF_INIT(0x3906, 14, 1, 47, 0x08000000U, "z14", "IBM z14 GA1"),
 };
 
+#define QEMU_MAX_CPU_TYPE 0x2827
+#define QEMU_MAX_CPU_GEN 12
+#define QEMU_MAX_CPU_EC_GA 2
+static const S390FeatInit qemu_max_cpu_feat_init = { S390_FEAT_LIST_QEMU_MAX };
+static S390FeatBitmap qemu_max_cpu_feat;
+
 /* features part of a base model but not relevant for finding a base model */
 S390FeatBitmap ignored_base_feat;
 
@@ -812,51 +817,6 @@ static void check_compatibility(const S390CPUModel *max_model,
                   "available in the configuration: ");
 }
 
-/**
- * The base TCG CPU model "qemu" is based on the z900. However, we already
- * can also emulate some additional features of later CPU generations, so
- * we add these additional feature bits here.
- */
-static void add_qemu_cpu_model_features(S390FeatBitmap fbm)
-{
-    static const int feats[] = {
-        S390_FEAT_DAT_ENH,
-        S390_FEAT_IDTE_SEGMENT,
-        S390_FEAT_STFLE,
-        S390_FEAT_SENSE_RUNNING_STATUS,
-        S390_FEAT_EXTENDED_TRANSLATION_2,
-        S390_FEAT_MSA,
-        S390_FEAT_LONG_DISPLACEMENT,
-        S390_FEAT_LONG_DISPLACEMENT_FAST,
-        S390_FEAT_EXTENDED_IMMEDIATE,
-        S390_FEAT_EXTENDED_TRANSLATION_3,
-        S390_FEAT_ETF2_ENH,
-        S390_FEAT_STORE_CLOCK_FAST,
-        S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
-        S390_FEAT_ETF3_ENH,
-        S390_FEAT_EXTRACT_CPU_TIME,
-        S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
-        S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
-        S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
-        S390_FEAT_EXECUTE_EXT,
-        S390_FEAT_SET_PROGRAM_PARAMETERS,
-        S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
-        S390_FEAT_STFLE_45,
-        S390_FEAT_STFLE_49,
-        S390_FEAT_LOCAL_TLB_CLEARING,
-        S390_FEAT_INTERLOCKED_ACCESS_2,
-        S390_FEAT_STFLE_53,
-        S390_FEAT_MSA_EXT_5,
-        S390_FEAT_MSA_EXT_3,
-        S390_FEAT_MSA_EXT_4,
-    };
-    int i;
-
-    for (i = 0; i < ARRAY_SIZE(feats); i++) {
-        set_bit(feats[i], fbm);
-    }
-}
-
 static S390CPUModel *get_max_cpu_model(Error **errp)
 {
     static S390CPUModel max_model;
@@ -869,12 +829,10 @@ static S390CPUModel *get_max_cpu_model(Error **errp)
     if (kvm_enabled()) {
         kvm_s390_get_host_cpu_model(&max_model, errp);
     } else {
-        /* TCG emulates a z900 (with some optional additional features) */
-        max_model.def = &s390_cpu_defs[0];
-        bitmap_copy(max_model.features, max_model.def->default_feat,
-                    S390_FEAT_MAX);
-        add_qemu_cpu_model_features(max_model.features);
-    }
+        max_model.def = s390_find_cpu_def(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
+                                          QEMU_MAX_CPU_EC_GA, NULL);
+        bitmap_copy(max_model.features, qemu_max_cpu_feat, S390_FEAT_MAX);
+   }
     if (!*errp) {
         cached = true;
         return &max_model;
@@ -1130,18 +1088,44 @@ static void s390_host_cpu_model_initfn(Object *obj)
 }
 #endif
 
+static S390CPUDef s390_qemu_cpu_def;
+static S390CPUModel s390_qemu_cpu_model;
+
+/* Set the qemu CPU model (on machine initialization). Must not be called
+ * once CPUs have been created.
+ */
+void s390_set_qemu_cpu_model(uint16_t type, uint8_t gen, uint8_t ec_ga,
+                             const S390FeatInit feat_init)
+{
+    const S390CPUDef *def = s390_find_cpu_def(type, gen, ec_ga, NULL);
+
+    g_assert(def);
+    g_assert(QTAILQ_EMPTY(&cpus));
+
+    /* TCG emulates some features that can usually not be enabled with
+     * the emulated machine generation. Make sure they can be enabled
+     * when using the QEMU model by adding them to full_feat. We have
+     * to copy the definition to do that.
+     */
+    memcpy(&s390_qemu_cpu_def, def, sizeof(s390_qemu_cpu_def));
+    bitmap_or(s390_qemu_cpu_def.full_feat, s390_qemu_cpu_def.full_feat,
+              qemu_max_cpu_feat, S390_FEAT_MAX);
+
+    /* build the CPU model */
+    s390_qemu_cpu_model.def = &s390_qemu_cpu_def;
+    bitmap_zero(s390_qemu_cpu_model.features, S390_FEAT_MAX);
+    s390_init_feat_bitmap(feat_init, s390_qemu_cpu_model.features);
+}
+
 static void s390_qemu_cpu_model_initfn(Object *obj)
 {
-    static S390CPUDef s390_qemu_cpu_defs;
     S390CPU *cpu = S390_CPU(obj);
 
     cpu->model = g_malloc0(sizeof(*cpu->model));
-    /* TCG emulates a z900 (with some optional additional features) */
-    memcpy(&s390_qemu_cpu_defs, &s390_cpu_defs[0], sizeof(s390_qemu_cpu_defs));
-    add_qemu_cpu_model_features(s390_qemu_cpu_defs.full_feat);
-    cpu->model->def = &s390_qemu_cpu_defs;
-    bitmap_copy(cpu->model->features, cpu->model->def->default_feat,
-                S390_FEAT_MAX);
+    /* has to be initialized by now via s390_set_qemu_cpu_model() */
+    g_assert(s390_qemu_cpu_model.def);
+    /* copy the CPU model so we can modify it */
+    memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
 }
 
 static void s390_cpu_model_finalize(Object *obj)
@@ -1287,6 +1271,7 @@ static void register_types(void)
     init_ignored_base_feat();
 
     /* init all bitmaps from gnerated data initially */
+    s390_init_feat_bitmap(qemu_max_cpu_feat_init, qemu_max_cpu_feat);
     for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
         s390_init_feat_bitmap(s390_cpu_defs[i].base_init,
                               s390_cpu_defs[i].base_feat);
diff --git a/target/s390x/cpu_models.h b/target/s390x/cpu_models.h
index 4c6dee1871..11cf5386fb 100644
--- a/target/s390x/cpu_models.h
+++ b/target/s390x/cpu_models.h
@@ -14,6 +14,7 @@
 #define TARGET_S390X_CPU_MODELS_H
 
 #include "cpu_features.h"
+#include "gen-features.h"
 #include "qom/cpu.h"
 
 /* static CPU definition */
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 68e6c31b4b..983f2dcd52 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -536,6 +536,51 @@ static uint16_t default_GEN14_GA1[] = {
     S390_FEAT_GROUP_MSA_EXT_8,
 };
 
+/* QEMU (CPU model) features */
+
+static uint16_t qemu_V2_11[] = {
+    S390_FEAT_GROUP_PLO,
+    S390_FEAT_ESAN3,
+    S390_FEAT_ZARCH,
+};
+
+static uint16_t qemu_V2_12[] = {
+    S390_FEAT_DAT_ENH,
+    S390_FEAT_IDTE_SEGMENT,
+    S390_FEAT_STFLE,
+    S390_FEAT_SENSE_RUNNING_STATUS,
+    S390_FEAT_EXTENDED_TRANSLATION_2,
+    S390_FEAT_MSA,
+    S390_FEAT_LONG_DISPLACEMENT,
+    S390_FEAT_LONG_DISPLACEMENT_FAST,
+    S390_FEAT_EXTENDED_IMMEDIATE,
+    S390_FEAT_EXTENDED_TRANSLATION_3,
+    S390_FEAT_ETF2_ENH,
+    S390_FEAT_STORE_CLOCK_FAST,
+    S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
+    S390_FEAT_ETF3_ENH,
+    S390_FEAT_EXTRACT_CPU_TIME,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
+    S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
+    S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
+    S390_FEAT_EXECUTE_EXT,
+    S390_FEAT_SET_PROGRAM_PARAMETERS,
+    S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
+    S390_FEAT_STFLE_45,
+    S390_FEAT_STFLE_49,
+    S390_FEAT_LOCAL_TLB_CLEARING,
+    S390_FEAT_INTERLOCKED_ACCESS_2,
+    S390_FEAT_STFLE_53,
+    S390_FEAT_MSA_EXT_4,
+    S390_FEAT_MSA_EXT_3,
+};
+
+/* add all new definitions before this point */
+static uint16_t qemu_MAX[] = {
+    /* generates a dependency warning, leave it out for now */
+    S390_FEAT_MSA_EXT_5,
+};
+
 /****** END FEATURE DEFS ******/
 
 #define _YEARS  "2016"
@@ -627,6 +672,24 @@ static FeatGroupDefSpec FeatGroupDef[] = {
     FEAT_GROUP_INITIALIZER(MSA_EXT_8),
 };
 
+#define QEMU_FEAT_INITIALIZER(_name)                   \
+    {                                                  \
+        .name = "S390_FEAT_LIST_QEMU_" #_name,         \
+        .bits =                                        \
+            { .data = qemu_##_name,                    \
+              .len = ARRAY_SIZE(qemu_##_name) },       \
+    }
+
+/*******************************
+ * QEMU (CPU model) features
+ *******************************/
+static FeatGroupDefSpec QemuFeatDef[] = {
+    QEMU_FEAT_INITIALIZER(V2_11),
+    QEMU_FEAT_INITIALIZER(V2_12),
+    QEMU_FEAT_INITIALIZER(MAX),
+};
+
+
 static void set_bits(uint64_t list[], BitSpec bits)
 {
     uint32_t i;
@@ -684,6 +747,29 @@ static void print_feature_defs(void)
     }
 }
 
+static void print_qemu_feature_defs(void)
+{
+    uint64_t feat[S390_FEAT_MAX / 64 + 1] = {};
+    int i, j;
+
+    printf("\n/* QEMU (CPU model) feature list data */\n");
+
+    /* for now we assume that we only add new features */
+    for (i = 0; i < ARRAY_SIZE(QemuFeatDef); i++) {
+        set_bits(feat, QemuFeatDef[i].bits);
+
+        printf("#define %s\t", QemuFeatDef[i].name);
+        for (j = 0; j < ARRAY_SIZE(feat); j++) {
+            printf("0x%016"PRIx64"ULL", feat[j]);
+            if (j < ARRAY_SIZE(feat) - 1) {
+                printf(",");
+            } else {
+                printf("\n");
+            }
+        }
+    }
+}
+
 static void print_feature_group_defs(void)
 {
     int i, j;
@@ -721,6 +807,7 @@ int main(int argc, char *argv[])
            "#ifndef %s\n#define %s\n", __FILE__, _YEARS, _NAME_H, _NAME_H);
     print_feature_defs();
     print_feature_group_defs();
+    print_qemu_feature_defs();
     printf("\n#endif\n");
     return 0;
 }
-- 
2.14.3

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
@ 2017-12-09  2:17   ` Richard Henderson
  0 siblings, 0 replies; 31+ messages in thread
From: Richard Henderson @ 2017-12-09  2:17 UTC (permalink / raw)
  To: David Hildenbrand, qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Alexander Graf

On 12/08/2017 08:01 AM, David Hildenbrand wrote:
> We'll need it later on in two places. Refactor it to just indicate the
> validity bits. While at it, introduce a define for the used CR14 bit (we'll
> also need later on).
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  target/s390x/cpu.h | 23 +++++++++++++++++++++++
>  target/s390x/kvm.c | 25 ++-----------------------
>  2 files changed, 25 insertions(+), 23 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD
  2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD David Hildenbrand
@ 2017-12-09  2:20   ` Richard Henderson
  0 siblings, 0 replies; 31+ messages in thread
From: Richard Henderson @ 2017-12-09  2:20 UTC (permalink / raw)
  To: David Hildenbrand, qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Alexander Graf

On 12/08/2017 08:01 AM, David Hildenbrand wrote:
> Needed for machine check handling inside Linux (when restoring registers).
> 
> Except for SIGP and machine checks, we don't make use of the register
> yet. Sufficient for now.
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  target/s390x/helper.h      |  1 +
>  target/s390x/insn-data.def |  2 ++
>  target/s390x/misc_helper.c | 11 +++++++++++
>  target/s390x/translate.c   |  7 +++++++
>  4 files changed, 21 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

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

* Re: [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions
  2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
                   ` (13 preceding siblings ...)
  2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12 David Hildenbrand
@ 2017-12-11 10:13 ` Cornelia Huck
  14 siblings, 0 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-11 10:13 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Fri,  8 Dec 2017 17:01:53 +0100
David Hildenbrand <david@redhat.com> wrote:

> Both series in one piece as (most probably) most reviewing is done.
> 
> Wire up some io instructions and implement new facilitites. Make sure
> to take care of MTTCG when it comes to atomic operations. Make CCW
> hotplug work.
> 
> As we are now able to install/boot a Fedora 26/27 as well as an upstream
> kernel compiled for z12, let's bump up the QEMU cpu model to a very
> stripped down version of a z12 (with missing base features). Take care
> of backwards compatibility (as we defined the QEMU model as
> migration-safe).

Thanks, queued to s390-next (with v4 of patch 14).

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

* [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine
  2017-12-08 16:55     ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
@ 2017-12-13 13:24       ` David Hildenbrand
  2017-12-13 13:34         ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
                           ` (2 more replies)
  2017-12-13 17:15       ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
  1 sibling, 3 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-13 13:24 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

Make sure "-cpu qemu" works with "-M none".

Signed-off-by: David Hildenbrand <david@redhat.com>
---

Conny, if this is okay, can you squash with the original patch?

 hw/s390x/s390-virtio-ccw.c  | 4 ----
 target/s390x/cpu_models.c   | 7 +++++--
 target/s390x/gen-features.c | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index c1f96418fa..466e45343c 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -725,10 +725,6 @@ bool css_migration_enabled(void)
 
 static void ccw_machine_2_12_instance_options(MachineState *machine)
 {
-    static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
-
-    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
-    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
 }
 
 static void ccw_machine_2_12_class_options(MachineClass *mc)
diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
index 7404ef52c6..212a5f0697 100644
--- a/target/s390x/cpu_models.c
+++ b/target/s390x/cpu_models.c
@@ -1122,8 +1122,6 @@ static void s390_qemu_cpu_model_initfn(Object *obj)
     S390CPU *cpu = S390_CPU(obj);
 
     cpu->model = g_malloc0(sizeof(*cpu->model));
-    /* has to be initialized by now via s390_set_qemu_cpu_model() */
-    g_assert(s390_qemu_cpu_model.def);
     /* copy the CPU model so we can modify it */
     memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
 }
@@ -1266,6 +1264,7 @@ static void init_ignored_base_feat(void)
 
 static void register_types(void)
 {
+    static const S390FeatInit qemu_latest_init = { S390_FEAT_LIST_QEMU_LATEST };
     int i;
 
     init_ignored_base_feat();
@@ -1281,6 +1280,10 @@ static void register_types(void)
                               s390_cpu_defs[i].full_feat);
     }
 
+    /* initialize the qemu model with latest definition */
+    s390_set_qemu_cpu_model(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
+                            QEMU_MAX_CPU_EC_GA, qemu_latest_init);
+
     for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
         char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
         TypeInfo ti_base = {
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 983f2dcd52..deace660e1 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -544,7 +544,7 @@ static uint16_t qemu_V2_11[] = {
     S390_FEAT_ZARCH,
 };
 
-static uint16_t qemu_V2_12[] = {
+static uint16_t qemu_LATEST[] = {
     S390_FEAT_DAT_ENH,
     S390_FEAT_IDTE_SEGMENT,
     S390_FEAT_STFLE,
@@ -685,7 +685,7 @@ static FeatGroupDefSpec FeatGroupDef[] = {
  *******************************/
 static FeatGroupDefSpec QemuFeatDef[] = {
     QEMU_FEAT_INITIALIZER(V2_11),
-    QEMU_FEAT_INITIALIZER(V2_12),
+    QEMU_FEAT_INITIALIZER(LATEST),
     QEMU_FEAT_INITIALIZER(MAX),
 };
 
-- 
2.14.3

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

* Re: [Qemu-devel] [qemu-s390x] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine
  2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
@ 2017-12-13 13:34         ` Christian Borntraeger
  2017-12-13 13:38           ` David Hildenbrand
  2017-12-13 17:17         ` [Qemu-devel] " Cornelia Huck
  2017-12-14 12:18         ` Cornelia Huck
  2 siblings, 1 reply; 31+ messages in thread
From: Christian Borntraeger @ 2017-12-13 13:34 UTC (permalink / raw)
  To: David Hildenbrand, qemu-s390x, qemu-devel
  Cc: Cornelia Huck, Alexander Graf, Richard Henderson



On 12/13/2017 02:24 PM, David Hildenbrand wrote:
> Make sure "-cpu qemu" works with "-M none".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> 
> Conny, if this is okay, can you squash with the original patch?
> 
>  hw/s390x/s390-virtio-ccw.c  | 4 ----
>  target/s390x/cpu_models.c   | 7 +++++--
>  target/s390x/gen-features.c | 4 ++--
>  3 files changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
> index c1f96418fa..466e45343c 100644
> --- a/hw/s390x/s390-virtio-ccw.c
> +++ b/hw/s390x/s390-virtio-ccw.c
> @@ -725,10 +725,6 @@ bool css_migration_enabled(void)
> 
>  static void ccw_machine_2_12_instance_options(MachineState *machine)
>  {
> -    static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
> -
> -    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
> -    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
>  }

So what happens now when you specify a 2.10 machine? 


> 
>  static void ccw_machine_2_12_class_options(MachineClass *mc)
> diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c
> index 7404ef52c6..212a5f0697 100644
> --- a/target/s390x/cpu_models.c
> +++ b/target/s390x/cpu_models.c
> @@ -1122,8 +1122,6 @@ static void s390_qemu_cpu_model_initfn(Object *obj)
>      S390CPU *cpu = S390_CPU(obj);
> 
>      cpu->model = g_malloc0(sizeof(*cpu->model));
> -    /* has to be initialized by now via s390_set_qemu_cpu_model() */
> -    g_assert(s390_qemu_cpu_model.def);
>      /* copy the CPU model so we can modify it */
>      memcpy(cpu->model, &s390_qemu_cpu_model, sizeof(*cpu->model));
>  }
> @@ -1266,6 +1264,7 @@ static void init_ignored_base_feat(void)
> 
>  static void register_types(void)
>  {
> +    static const S390FeatInit qemu_latest_init = { S390_FEAT_LIST_QEMU_LATEST };
>      int i;
> 
>      init_ignored_base_feat();
> @@ -1281,6 +1280,10 @@ static void register_types(void)
>                                s390_cpu_defs[i].full_feat);
>      }
> 
> +    /* initialize the qemu model with latest definition */
> +    s390_set_qemu_cpu_model(QEMU_MAX_CPU_TYPE, QEMU_MAX_CPU_GEN,
> +                            QEMU_MAX_CPU_EC_GA, qemu_latest_init);
> +
>      for (i = 0; i < ARRAY_SIZE(s390_cpu_defs); i++) {
>          char *base_name = s390_base_cpu_type_name(s390_cpu_defs[i].name);
>          TypeInfo ti_base = {
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index 983f2dcd52..deace660e1 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -544,7 +544,7 @@ static uint16_t qemu_V2_11[] = {
>      S390_FEAT_ZARCH,
>  };
> 
> -static uint16_t qemu_V2_12[] = {
> +static uint16_t qemu_LATEST[] = {
>      S390_FEAT_DAT_ENH,
>      S390_FEAT_IDTE_SEGMENT,
>      S390_FEAT_STFLE,
> @@ -685,7 +685,7 @@ static FeatGroupDefSpec FeatGroupDef[] = {
>   *******************************/
>  static FeatGroupDefSpec QemuFeatDef[] = {
>      QEMU_FEAT_INITIALIZER(V2_11),
> -    QEMU_FEAT_INITIALIZER(V2_12),
> +    QEMU_FEAT_INITIALIZER(LATEST),
>      QEMU_FEAT_INITIALIZER(MAX),
>  };
> 

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

* Re: [Qemu-devel] [qemu-s390x] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine
  2017-12-13 13:34         ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
@ 2017-12-13 13:38           ` David Hildenbrand
  0 siblings, 0 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-13 13:38 UTC (permalink / raw)
  To: Christian Borntraeger, qemu-s390x, qemu-devel
  Cc: Cornelia Huck, Alexander Graf, Richard Henderson

On 13.12.2017 14:34, Christian Borntraeger wrote:
> 
> 
> On 12/13/2017 02:24 PM, David Hildenbrand wrote:
>> Make sure "-cpu qemu" works with "-M none".
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
>> ---
>>
>> Conny, if this is okay, can you squash with the original patch?
>>
>>  hw/s390x/s390-virtio-ccw.c  | 4 ----
>>  target/s390x/cpu_models.c   | 7 +++++--
>>  target/s390x/gen-features.c | 4 ++--
>>  3 files changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
>> index c1f96418fa..466e45343c 100644
>> --- a/hw/s390x/s390-virtio-ccw.c
>> +++ b/hw/s390x/s390-virtio-ccw.c
>> @@ -725,10 +725,6 @@ bool css_migration_enabled(void)
>>
>>  static void ccw_machine_2_12_instance_options(MachineState *machine)
>>  {
>> -    static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V2_12 };
>> -
>> -    /* with 2.12 we emulated a stripped down zEC12 (GA 2) */
>> -    s390_set_qemu_cpu_model(0x2827, 12, 2, qemu_cpu_feat);
>>  }
> 
> So what happens now when you specify a 2.10 machine? 

the 2.11 handler is called, initializing it to a z900.

$ qemu-system-s390x -nographic -machine s390-ccw-virtio-2.10 -hda
guest-tcg.qcow2
LOADPARM=[........]
Using virtio-blk.
Using SCSI scheme.
.....
The Linux kernel requires more recent processor hardware
Detected machine-type number: 2064
Missing facilities: 18,21,25,27,32,33,34,35,45,49,52
See Principles of Operations for facility bits

$ qemu-system-s390x -nographic -machine s390-ccw-virtio-2.12 -hda
guest-tcg.qcow2
LOADPARM=[........]
Using virtio-blk.
Using SCSI scheme.
.....
[    0.325571] Linux version 4.13.9-300.fc27.s390x ...

-- 

Thanks,

David / dhildenb

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

* [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model
  2017-12-08 16:55     ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
  2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
@ 2017-12-13 17:15       ` David Hildenbrand
  2017-12-13 17:21         ` Cornelia Huck
  2017-12-14 12:19         ` Cornelia Huck
  1 sibling, 2 replies; 31+ messages in thread
From: David Hildenbrand @ 2017-12-13 17:15 UTC (permalink / raw)
  To: qemu-s390x, qemu-devel
  Cc: Christian Borntraeger, Cornelia Huck, Richard Henderson,
	Alexander Graf, David Hildenbrand

As Cornelia noticed, -cpu qemu will not boot on a z12 machine. Don't
enable z13 features as default for now (as we are emulating a z12 in
TCG for now).

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 target/s390x/gen-features.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index deace660e1..b24f6ada5b 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -570,13 +570,14 @@ static uint16_t qemu_LATEST[] = {
     S390_FEAT_STFLE_49,
     S390_FEAT_LOCAL_TLB_CLEARING,
     S390_FEAT_INTERLOCKED_ACCESS_2,
-    S390_FEAT_STFLE_53,
     S390_FEAT_MSA_EXT_4,
     S390_FEAT_MSA_EXT_3,
 };
 
 /* add all new definitions before this point */
 static uint16_t qemu_MAX[] = {
+    /* z13+ features */
+    S390_FEAT_STFLE_53,
     /* generates a dependency warning, leave it out for now */
     S390_FEAT_MSA_EXT_5,
 };
-- 
2.14.3

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

* Re: [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine
  2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
  2017-12-13 13:34         ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
@ 2017-12-13 17:17         ` Cornelia Huck
  2017-12-14 12:18         ` Cornelia Huck
  2 siblings, 0 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-13 17:17 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Wed, 13 Dec 2017 14:24:07 +0100
David Hildenbrand <david@redhat.com> wrote:

> Make sure "-cpu qemu" works with "-M none".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

This fixes using libvirt for me.

> ---
> 
> Conny, if this is okay, can you squash with the original patch?

Sure. Waiting until tomorrow in case anyone has feedback.

> 
>  hw/s390x/s390-virtio-ccw.c  | 4 ----
>  target/s390x/cpu_models.c   | 7 +++++--
>  target/s390x/gen-features.c | 4 ++--
>  3 files changed, 7 insertions(+), 8 deletions(-)

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

* Re: [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model
  2017-12-13 17:15       ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
@ 2017-12-13 17:21         ` Cornelia Huck
  2017-12-14 12:19         ` Cornelia Huck
  1 sibling, 0 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-13 17:21 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Wed, 13 Dec 2017 18:15:12 +0100
David Hildenbrand <david@redhat.com> wrote:

> As Cornelia noticed, -cpu qemu will not boot on a z12 machine. Don't
> enable z13 features as default for now (as we are emulating a z12 in
> TCG for now).
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  target/s390x/gen-features.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index deace660e1..b24f6ada5b 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -570,13 +570,14 @@ static uint16_t qemu_LATEST[] = {
>      S390_FEAT_STFLE_49,
>      S390_FEAT_LOCAL_TLB_CLEARING,
>      S390_FEAT_INTERLOCKED_ACCESS_2,
> -    S390_FEAT_STFLE_53,
>      S390_FEAT_MSA_EXT_4,
>      S390_FEAT_MSA_EXT_3,
>  };
>  
>  /* add all new definitions before this point */
>  static uint16_t qemu_MAX[] = {
> +    /* z13+ features */
> +    S390_FEAT_STFLE_53,
>      /* generates a dependency warning, leave it out for now */
>      S390_FEAT_MSA_EXT_5,
>  };

I can now boot a kvm guest with -cpu qemu on a z12 LPAR.

I'll wait until tomorrow for feedback and squash as well.

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

* Re: [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine
  2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
  2017-12-13 13:34         ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
  2017-12-13 17:17         ` [Qemu-devel] " Cornelia Huck
@ 2017-12-14 12:18         ` Cornelia Huck
  2 siblings, 0 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-14 12:18 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Wed, 13 Dec 2017 14:24:07 +0100
David Hildenbrand <david@redhat.com> wrote:

> Make sure "-cpu qemu" works with "-M none".
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> 
> Conny, if this is okay, can you squash with the original patch?
> 
>  hw/s390x/s390-virtio-ccw.c  | 4 ----
>  target/s390x/cpu_models.c   | 7 +++++--
>  target/s390x/gen-features.c | 4 ++--
>  3 files changed, 7 insertions(+), 8 deletions(-)

Squashed into "s390x: change the QEMU cpu model to a stripped down z12".

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

* Re: [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model
  2017-12-13 17:15       ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
  2017-12-13 17:21         ` Cornelia Huck
@ 2017-12-14 12:19         ` Cornelia Huck
  1 sibling, 0 replies; 31+ messages in thread
From: Cornelia Huck @ 2017-12-14 12:19 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: qemu-s390x, qemu-devel, Christian Borntraeger, Richard Henderson,
	Alexander Graf

On Wed, 13 Dec 2017 18:15:12 +0100
David Hildenbrand <david@redhat.com> wrote:

> As Cornelia noticed, -cpu qemu will not boot on a z12 machine. Don't
> enable z13 features as default for now (as we are emulating a z12 in
> TCG for now).
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
>  target/s390x/gen-features.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index deace660e1..b24f6ada5b 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -570,13 +570,14 @@ static uint16_t qemu_LATEST[] = {
>      S390_FEAT_STFLE_49,
>      S390_FEAT_LOCAL_TLB_CLEARING,
>      S390_FEAT_INTERLOCKED_ACCESS_2,
> -    S390_FEAT_STFLE_53,
>      S390_FEAT_MSA_EXT_4,
>      S390_FEAT_MSA_EXT_3,
>  };
>  
>  /* add all new definitions before this point */
>  static uint16_t qemu_MAX[] = {
> +    /* z13+ features */
> +    S390_FEAT_STFLE_53,
>      /* generates a dependency warning, leave it out for now */
>      S390_FEAT_MSA_EXT_5,
>  };

Squashed into "s390x: change the QEMU cpu model to a stripped down z12"
and pushed out to s390-next.

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

end of thread, other threads:[~2017-12-14 12:19 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08 16:01 [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 01/14] s390x/kvm: factor out build_channel_report_mcic() into cpu.h David Hildenbrand
2017-12-09  2:17   ` Richard Henderson
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 02/14] s390x/tcg: fix and cleanup mcck injection David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 03/14] s390x/tcg: implement SET CLOCK PROGRAMMABLE FIELD David Hildenbrand
2017-12-09  2:20   ` Richard Henderson
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 04/14] s390x/tcg: indicate value of TODPR in STCKE David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 05/14] s390x/tcg: wire up STORE CHANNEL REPORT WORD David Hildenbrand
2017-12-08 16:01 ` [Qemu-devel] [PATCH v3 for-2.12 06/14] s390x/tcg: ASI/ASGI/ALSI/ALSGI are atomic with Interlocked-acccess facility 1 David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 07/14] s390x/tcg: implement Interlocked-Access Facility 2 David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 08/14] s390x/tcg: wire up SET ADDRESS LIMIT David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 09/14] s390x/tcg: wire up SET CHANNEL MONITOR David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 10/14] s390x/tcg: Implement STORE CHANNEL PATH STATUS David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 11/14] s390x/tcg: Implement SIGNAL ADAPTER instruction David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 12/14] s390x/tcg: implement extract-CPU-time facility David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 13/14] s390x/tcg: we already implement the Set-Program-Parameter facility David Hildenbrand
2017-12-08 16:02 ` [Qemu-devel] [PATCH v3 for-2.12 14/14] s390x: change the QEMU cpu model to a stripped down z12 David Hildenbrand
2017-12-08 16:26   ` Cornelia Huck
2017-12-08 16:29     ` David Hildenbrand
2017-12-08 16:34       ` Daniel P. Berrange
2017-12-08 16:39         ` David Hildenbrand
2017-12-08 16:55     ` [Qemu-devel] [PATCH v4 for-2-12] " David Hildenbrand
2017-12-13 13:24       ` [Qemu-devel] [PATCH v1] s390x/cpumodel: make qemu cpu model play with "none" machine David Hildenbrand
2017-12-13 13:34         ` [Qemu-devel] [qemu-s390x] " Christian Borntraeger
2017-12-13 13:38           ` David Hildenbrand
2017-12-13 17:17         ` [Qemu-devel] " Cornelia Huck
2017-12-14 12:18         ` Cornelia Huck
2017-12-13 17:15       ` [Qemu-devel] [PATCH v1] s390x/tcg: don't include z13 features in the qemu model David Hildenbrand
2017-12-13 17:21         ` Cornelia Huck
2017-12-14 12:19         ` Cornelia Huck
2017-12-11 10:13 ` [Qemu-devel] [PATCH v3 for-2.12 00/14] s390x/tcg: CCW hotplug, facilities, instructions Cornelia Huck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.