Skip to contentSkip to conversation

more s390x fixes

GIT PULL Applied Cornelia Huck 2 participants 11 messages Oct 22, 2019

lore
Share & tools
lore
#0 lore raw

The following changes since commit e9d42461920f6f40f4d847a5ba18e90d095ed0b9:

Merge remote-tracking branch 'remotes/kraxel/tags/audio-20191018-pull-request' into staging (2019-10-18 14:13:11 +0100)

are available in the Git repository at:

https://github.com/cohuck/qemu tags/s390x-20191022

for you to fetch changes up to de60a92ea7b7977854420c58fd98f38cb6de6de6:

s390x/kvm: Set default cpu model for all machine classes (2019-10-21 18:03:08 +0200)

----------------------------------------------------------------
s390x fixes in tcg vector instruction handling and in the cpu model code

----------------------------------------------------------------

Andrew Jones (1):
s390x/cpumodel: Add missing visit_free

David Hildenbrand (8):
s390x/mmu: Remove duplicate check for MMU_DATA_STORE s390x/tcg: Fix VECTOR MULTIPLY LOGICAL ODD
s390x/tcg: Fix VECTOR MULTIPLY AND ADD *
s390x/tcg: Fix VECTOR SHIFT RIGHT ARITHMETIC BY BYTE s390x/tcg: Fix VECTOR SUBTRACT COMPUTE BORROW INDICATION s390x/tcg: Fix VECTOR SUBTRACT WITH BORROW INDICATION s390x/tcg: Fix VECTOR SUBTRACT WITH BORROW COMPUTE BORROW INDICATION s390x/kvm: Set default cpu model for all machine classes

 target/s390x/cpu_models.c       |  1 +
 target/s390x/kvm.c              | 10 ++++++++--
 target/s390x/mmu_helper.c       |  4 +---
 target/s390x/translate_vx.inc.c | 30 ++++++++++++------------------
 target/s390x/vec_int_helper.c   | 18 ++++++++++--------
 5 files changed, 32 insertions(+), 31 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

[PULL 1/9] s390x/cpumodel: Add missing visit_free

From: Andrew Jones <[email protected]>

Beata Michalska noticed this missing visit_free() while reviewing arm's implementation of qmp_query_cpu_model_expansion(), which is modeled off this s390x implementation.

Message-Id: <[email protected]>

---
 target/s390x/cpu_models.c | 1 +
 1 file changed, 1 insertion(+)
target/s390x/cpu_models.c +1 -0
index 009afc38b92d..7e92fb2e156d 100644
@@ -515,6 +515,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
         visitor = qobject_input_visitor_new(info->props);
         visit_start_struct(visitor, NULL, NULL, 0, errp);
         if (*errp) {
+            visit_free(visitor);
             object_unref(obj);
             return;
         }
Signature · 1 line
2.21.0
#2 lore raw

[PULL 7/9] s390x/tcg: Fix VECTOR SUBTRACT WITH BORROW INDICATION

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

Testing this, there seems to be something messed up. We are dealing with unsigned numbers. "Each operand is treated as an unsigned binary integer." Let's just implement as written in the PoP:

"A subtraction is performed by adding the contents of
the second operand with the bitwise complement of the third operand along with a borrow indication from the rightmost bit position of the fourth operand and the result is placed in the first operand."

We can reuse gen_ac2_i64().

Fixes 48390a7c2716 ("s390x/tcg: Implement VECTOR SUBTRACT WITH BORROW INDICATION")

Message-Id: <[email protected]>

---
 target/s390x/translate_vx.inc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
target/s390x/translate_vx.inc.c +5 -5
index 6032021d82e7..fd746ba35fb6 100644
@@ -2187,13 +2187,13 @@ static void gen_sbi2_i64(TCGv_i64 dl, TCGv_i64 dh, TCGv_i64 al, TCGv_i64 ah,
                          TCGv_i64 bl, TCGv_i64 bh, TCGv_i64 cl, TCGv_i64 ch)
 {
     TCGv_i64 tl = tcg_temp_new_i64();
-    TCGv_i64 zero = tcg_const_i64(0);
+    TCGv_i64 th = tcg_temp_new_i64();
 
-    tcg_gen_andi_i64(tl, cl, 1);
-    tcg_gen_sub2_i64(dl, dh, al, ah, bl, bh);
-    tcg_gen_sub2_i64(dl, dh, dl, dh, tl, zero);
+    tcg_gen_not_i64(tl, bl);
+    tcg_gen_not_i64(th, bh);
+    gen_ac2_i64(dl, dh, al, ah, tl, th, cl, ch);
     tcg_temp_free_i64(tl);
-    tcg_temp_free_i64(zero);
+    tcg_temp_free_i64(th);
 }
 
 static DisasJumpType op_vsbi(DisasContext *s, DisasOps *o)
Signature · 1 line
2.21.0
#3 lore raw

[PULL 2/9] s390x/mmu: Remove duplicate check for MMU_DATA_STORE

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

No need to double-check if we have a write.

Found by Coverity (CID: 1406404).

Fixes 31b59419069e ("target/s390x: Return exception from mmu_translate_real")
Cc Peter Maydell <[email protected]>

Message-Id: <[email protected]>

---
 target/s390x/mmu_helper.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/mmu_helper.c +1 -3
index 90b81335f920..c9f3f3475010 100644
@@ -556,9 +556,7 @@ int mmu_translate_real(CPUS390XState *env, target_ulong raddr, int rw,
         *flags |= PAGE_WRITE_INV;
         if (is_low_address(raddr) && rw == MMU_DATA_STORE) {
             /* LAP sets bit 56 */
-            *tec = (raddr & TARGET_PAGE_MASK)
-                 | (rw == MMU_DATA_STORE ? FS_WRITE : FS_READ)
-                 | 0x80;
+            *tec = (raddr & TARGET_PAGE_MASK) | FS_WRITE | 0x80;
             return PGM_PROTECTION;
         }
     }
Signature · 1 line
2.21.0
#4 lore raw

[PULL 4/9] s390x/tcg: Fix VECTOR MULTIPLY AND ADD *

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

We missed that we always read a "double-wide even-odd element pair of the fourth operand". Fix it in all four variants.

Fixes 1b430aec4157 ("s390x/tcg: Implement VECTOR MULTIPLY AND ADD *")

Message-Id: <[email protected]>

---
 target/s390x/vec_int_helper.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/s390x/vec_int_helper.c +4 -4
index 03ae8631d958..1b3aaecbdb3d 100644
@@ -336,7 +336,7 @@ void HELPER(gvec_vmae##BITS)(void *v1, const void *v2, const void *v3,         \
     for (i = 0, j = 0; i < (128 / TBITS); i++, j += 2) {                       \
         int##TBITS##_t a = (int##BITS##_t)s390_vec_read_element##BITS(v2, j);  \
         int##TBITS##_t b = (int##BITS##_t)s390_vec_read_element##BITS(v3, j);  \
-        int##TBITS##_t c = (int##BITS##_t)s390_vec_read_element##BITS(v4, j);  \
+        int##TBITS##_t c = s390_vec_read_element##TBITS(v4, i);                \
                                                                                \
         s390_vec_write_element##TBITS(v1, i, a * b + c);                       \
     }                                                                          \
@@ -354,7 +354,7 @@ void HELPER(gvec_vmale##BITS)(void *v1, const void *v2, const void *v3,        \
     for (i = 0, j = 0; i < (128 / TBITS); i++, j += 2) {                       \
         uint##TBITS##_t a = s390_vec_read_element##BITS(v2, j);                \
         uint##TBITS##_t b = s390_vec_read_element##BITS(v3, j);                \
-        uint##TBITS##_t c = s390_vec_read_element##BITS(v4, j);                \
+        uint##TBITS##_t c = s390_vec_read_element##TBITS(v4, i);               \
                                                                                \
         s390_vec_write_element##TBITS(v1, i, a * b + c);                       \
     }                                                                          \
@@ -372,7 +372,7 @@ void HELPER(gvec_vmao##BITS)(void *v1, const void *v2, const void *v3,         \
     for (i = 0, j = 1; i < (128 / TBITS); i++, j += 2) {                       \
         int##TBITS##_t a = (int##BITS##_t)s390_vec_read_element##BITS(v2, j);  \
         int##TBITS##_t b = (int##BITS##_t)s390_vec_read_element##BITS(v3, j);  \
-        int##TBITS##_t c = (int##BITS##_t)s390_vec_read_element##BITS(v4, j);  \
+        int##TBITS##_t c = s390_vec_read_element##TBITS(v4, i);                \
                                                                                \
         s390_vec_write_element##TBITS(v1, i, a * b + c);                       \
     }                                                                          \
@@ -390,7 +390,7 @@ void HELPER(gvec_vmalo##BITS)(void *v1, const void *v2, const void *v3,        \
     for (i = 0, j = 1; i < (128 / TBITS); i++, j += 2) {                       \
         uint##TBITS##_t a = s390_vec_read_element##BITS(v2, j);                \
         uint##TBITS##_t b = s390_vec_read_element##BITS(v3, j);                \
-        uint##TBITS##_t c = s390_vec_read_element##BITS(v4, j);                \
+        uint##TBITS##_t c = s390_vec_read_element##TBITS(v4, i);               \
                                                                                \
         s390_vec_write_element##TBITS(v1, i, a * b + c);                       \
     }                                                                          \
Signature · 1 line
2.21.0
#5 lore raw

[PULL 9/9] s390x/kvm: Set default cpu model for all machine classes

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model ("qemu-s390x-cpu" instead of "host-s390x-cpu") as "default-cpu-type".

Doing a

    {"execute":"query-machines"}
under KVM now results in
    {"return": [
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-4.0",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false},
        {
            "hotpluggable-cpus": true,
            "name": "s390-ccw-virtio-2.7",
            "numa-mem-supported": false,
            "default-cpu-type": "host-s390x-cpu",
            "cpu-max": 248,
            "deprecated": false
        } ...

Libvirt probes all machines via "-machine none,accel=kvm:tcg" and will currently see the wrong CPU model under KVM.

Fixes b6805e127c6b ("s390x: use generic cpu_model parsing")
Cc Igor Mammedov <[email protected]>

Message-Id: <[email protected]>

---
 target/s390x/kvm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
target/s390x/kvm.c +8 -2
index c24c869e7703..0c9d14b4b115 100644
@@ -320,11 +320,17 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)
     cap_hpage_1m = 1;
 }
 
-int kvm_arch_init(MachineState *ms, KVMState *s)
+static void ccw_machine_class_foreach(ObjectClass *oc, void *opaque)
 {
-    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    MachineClass *mc = MACHINE_CLASS(oc);
 
     mc->default_cpu_type = S390_CPU_TYPE_NAME("host");
+}
+
+int kvm_arch_init(MachineState *ms, KVMState *s)
+{
+    object_class_foreach(ccw_machine_class_foreach, TYPE_S390_CCW_MACHINE,
+                         false, NULL);
 
     if (!kvm_check_extension(kvm_state, KVM_CAP_DEVICE_CTRL)) {
         error_report("KVM is missing capability KVM_CAP_DEVICE_CTRL - "
Signature · 1 line
2.21.0
#6 lore raw

[PULL 3/9] s390x/tcg: Fix VECTOR MULTIPLY LOGICAL ODD

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

We have to read from odd offsets.

Fixes 2bf3ee38f1f8 ("s390x/tcg: Implement VECTOR MULTIPLY *")

Message-Id: <[email protected]>

---
 target/s390x/vec_int_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/vec_int_helper.c +1 -1
index 68eaae407b47..03ae8631d958 100644
@@ -488,7 +488,7 @@ void HELPER(gvec_vmlo##BITS)(void *v1, const void *v2, const void *v3,         \
 {                                                                              \
     int i, j;                                                                  \
                                                                                \
-    for (i = 0, j = 0; i < (128 / TBITS); i++, j += 2) {                       \
+    for (i = 0, j = 1; i < (128 / TBITS); i++, j += 2) {                       \
         const uint##TBITS##_t a = s390_vec_read_element##BITS(v2, j);          \
         const uint##TBITS##_t b = s390_vec_read_element##BITS(v3, j);          \
                                                                                \
Signature · 1 line
2.21.0
#7 lore raw

[PULL 5/9] s390x/tcg: Fix VECTOR SHIFT RIGHT ARITHMETIC BY BYTE

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

We forgot to propagate the highest bit accross the high doubleword in two cases (shift >=64).

Fixes 5f724887e3dd ("s390x/tcg: Implement VECTOR SHIFT RIGHT ARITHMETIC")

Message-Id: <[email protected]>

---
 target/s390x/vec_int_helper.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/s390x/vec_int_helper.c +4 -2
index 1b3aaecbdb3d..d38405848fed 100644
@@ -70,15 +70,17 @@ static void s390_vec_sar(S390Vector *d, const S390Vector *a, uint64_t count)
         d->doubleword[0] = a->doubleword[0];
         d->doubleword[1] = a->doubleword[1];
     } else if (count == 64) {
+        tmp = (int64_t)a->doubleword[0] >> 63;
         d->doubleword[1] = a->doubleword[0];
-        d->doubleword[0] = 0;
+        d->doubleword[0] = tmp;
     } else if (count < 64) {
         tmp = a->doubleword[1] >> count;
         d->doubleword[1] = deposit64(tmp, 64 - count, count, a->doubleword[0]);
         d->doubleword[0] = (int64_t)a->doubleword[0] >> count;
     } else {
+        tmp = (int64_t)a->doubleword[0] >> 63;
         d->doubleword[1] = (int64_t)a->doubleword[0] >> (count - 64);
-        d->doubleword[0] = 0;
+        d->doubleword[0] = tmp;
     }
 }
 
Signature · 1 line
2.21.0
#8 lore raw

[PULL 6/9] s390x/tcg: Fix VECTOR SUBTRACT COMPUTE BORROW INDICATION

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

Looks like my idea of what a "borrow" is was wrong. The PoP says:

"If the resulting subtraction results in a carry out of bit zero, a value of one is placed in the corresponding element of the first operand; otherwise, a value of zero is placed in the corresponding element"

As clarified by Richard, all we have to do is invert the result.

Fixes 1ee2d7ba72f6 ("s390x/tcg: Implement VECTOR SUBTRACT COMPUTE BORROW INDICATION")

Message-Id: <[email protected]>

---
 target/s390x/translate_vx.inc.c | 7 ++++---
 target/s390x/vec_int_helper.c   | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
target/s390x/translate_vx.inc.c +4 -3
index 5ce7bfb0afc5..6032021d82e7 100644
@@ -2132,12 +2132,12 @@ static DisasJumpType op_vs(DisasContext *s, DisasOps *o)
 
 static void gen_scbi_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
 {
-    tcg_gen_setcond_i32(TCG_COND_LTU, d, a, b);
+    tcg_gen_setcond_i32(TCG_COND_GEU, d, a, b);
 }
 
 static void gen_scbi_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
 {
-    tcg_gen_setcond_i64(TCG_COND_LTU, d, a, b);
+    tcg_gen_setcond_i64(TCG_COND_GEU, d, a, b);
 }
 
 static void gen_scbi2_i64(TCGv_i64 dl, TCGv_i64 dh, TCGv_i64 al,
@@ -2151,7 +2151,8 @@ static void gen_scbi2_i64(TCGv_i64 dl, TCGv_i64 dh, TCGv_i64 al,
     tcg_gen_andi_i64(th, th, 1);
     tcg_gen_sub2_i64(tl, th, ah, zero, th, zero);
     tcg_gen_sub2_i64(tl, th, tl, th, bh, zero);
-    tcg_gen_andi_i64(dl, th, 1);
+    /* "invert" the result: -1 -> 0; 0 -> 1 */
+    tcg_gen_addi_i64(dl, th, 1);
     tcg_gen_mov_i64(dh, zero);
 
     tcg_temp_free_i64(th);
target/s390x/vec_int_helper.c +1 -1
index d38405848fed..0d6bc13dd603 100644
@@ -593,7 +593,7 @@ void HELPER(gvec_vscbi##BITS)(void *v1, const void *v2, const void *v3,        \
         const uint##BITS##_t a = s390_vec_read_element##BITS(v2, i);           \
         const uint##BITS##_t b = s390_vec_read_element##BITS(v3, i);           \
                                                                                \
-        s390_vec_write_element##BITS(v1, i, a < b);                            \
+        s390_vec_write_element##BITS(v1, i, a >= b);                           \
     }                                                                          \
 }
 DEF_VSCBI(8)
Signature · 1 line
2.21.0
#9 lore raw

[PULL 8/9] s390x/tcg: Fix VECTOR SUBTRACT WITH BORROW COMPUTE BORROW INDICATION

In reply to Cornelia Huck

From: David Hildenbrand <[email protected]>

The numbers are unsigned, the computation is wrong. "Each operand is treated as an unsigned binary integer".
Let's implement as given in the PoP:

"A subtraction is performed by adding the contents of the second operand
with the bitwise complement of the third operand along with a borrow indication from the rightmost bit of the fourth operand."

Reuse gen_accc2_i64().

Fixes bc725e65152c ("s390x/tcg: Implement VECTOR SUBTRACT WITH BORROW COMPUTE BORROW INDICATION")

Message-Id: <[email protected]>

---
 target/s390x/translate_vx.inc.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
target/s390x/translate_vx.inc.c +3 -10
index fd746ba35fb6..71059f9ca0a0 100644
@@ -2214,20 +2214,13 @@ static void gen_sbcbi2_i64(TCGv_i64 dl, TCGv_i64 dh, TCGv_i64 al, TCGv_i64 ah,
 {
     TCGv_i64 th = tcg_temp_new_i64();
     TCGv_i64 tl = tcg_temp_new_i64();
-    TCGv_i64 zero = tcg_const_i64(0);
 
-    tcg_gen_andi_i64(tl, cl, 1);
-    tcg_gen_sub2_i64(tl, th, al, zero, tl, zero);
-    tcg_gen_sub2_i64(tl, th, tl, th, bl, zero);
-    tcg_gen_andi_i64(th, th, 1);
-    tcg_gen_sub2_i64(tl, th, ah, zero, th, zero);
-    tcg_gen_sub2_i64(tl, th, tl, th, bh, zero);
-    tcg_gen_andi_i64(dl, th, 1);
-    tcg_gen_mov_i64(dh, zero);
+    tcg_gen_not_i64(tl, bl);
+    tcg_gen_not_i64(th, bh);
+    gen_accc2_i64(dl, dh, al, ah, tl, th, cl, ch);
 
     tcg_temp_free_i64(tl);
     tcg_temp_free_i64(th);
-    tcg_temp_free_i64(zero);
 }
 
 static DisasJumpType op_vsbcbi(DisasContext *s, DisasOps *o)
Signature · 1 line
2.21.0
#10 lore raw
In reply to Cornelia Huck
Quoted 9 lines · Cornelia Huck

The following changes since commit e9d42461920f6f40f4d847a5ba18e90d095ed0b9:

Merge remote-tracking branch 'remotes/kraxel/tags/audio-20191018-pull-request' into staging (2019-10-18 14:13:11 +0100)

are available in the Git repository at:

https://github.com/cohuck/qemu tags/s390x-20191022

Quoted 8 lines

for you to fetch changes up to de60a92ea7b7977854420c58fd98f38cb6de6de6:

s390x/kvm: Set default cpu model for all machine classes (2019-10-21 18:03:08 +0200)

----------------------------------------------------------------
s390x fixes in tcg vector instruction handling and in the cpu model code

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.

-- PMM