Skip to contentSkip to conversation

target/s390x: Fix the "ignored match" case in VSTRS

PATCH In review Ilya Leoshkevich 4 participants 16 messages Aug 4, 2023 – Aug 23, 2023

lore
Share & tools
lore
#0 lore raw

cover target/s390x: Fix the "ignored match" case in VSTRS

Hi,

this series should hopefully fix the issue with __strstr_arch13(), which Claudio reported. I have to admit I did not manage to fully reproduce it, but at least with this change the traces of a simple test from TCG and real hardware match.

I've also fuzzed the changed helper and strstr() itself; not sure whether anything generic may come out of it, but here are the links anyway [1] [2].

Patch 1 makes glibc pick __strstr_arch13() in qemu-user, patch 2 is the fix and patch 3 is the test (generated from Claudio's strings and further fuzzer's findings).

[1] https://gist.github.com/iii-i/5adad06d911c46079d4388001b22ab61
[2] https://gist.github.com/iii-i/c425800e75796eae65660491ac511356

Ilya Leoshkevich (3):
linux-user/elfload: Enable vxe2 on s390x target/s390x: Fix the "ignored match" case in VSTRS tests/tcg/s390x: Test VSTRS

 linux-user/elfload.c                 |  1 +
 target/s390x/tcg/vec_string_helper.c | 54 ++++++-----------
 tests/tcg/s390x/Makefile.target      |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c        | 88 ++++++++++++++++++++++++++++
 4 files changed, 107 insertions(+), 37 deletions(-)
 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/3 linux-user/elfload: Enable vxe2 on s390x

The vxe2 hwcap is not set for programs running in linux-user, but is set by a Linux kernel running in softmmu. Add it to the former.

---
 linux-user/elfload.c | 1 +
 1 file changed, 1 insertion(+)
linux-user/elfload.c +1 -0
index 861ec07abcd..33b20548721 100644
@@ -1614,6 +1614,7 @@ uint32_t get_elf_hwcap(void)
     }
     GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
     GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
+    GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
 
     return hwcap;
 }
Signature · 1 line
2.41.0
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] linux-user/elfload: Enable vxe2 on s390x

In reply to Ilya Leoshkevich
Quoted 13 lines · Ilya Leoshkevich

The vxe2 hwcap is not set for programs running in linux-user, but is set by a Linux kernel running in softmmu. Add it to the former.

---
  linux-user/elfload.c | 1 +
  1 file changed, 1 insertion(+)
linux-user/elfload.c +0 -0
index 861ec07abcd..33b20548721 100644

linux-user/elfload.c uint32_t get_elf_hwcap(void) · line 1620

Quoted 7 lines
linux-user/elfload.c +1 -0
@@ -1614,6 +1614,7 @@ uint32_t get_elf_hwcap(void)
      }
      GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
      GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
+    GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
 
      return hwcap;
  }
Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] linux-user/elfload: Enable vxe2 on s390x

In reply to Ilya Leoshkevich
Quoted 13 lines · Ilya Leoshkevich

The vxe2 hwcap is not set for programs running in linux-user, but is set by a Linux kernel running in softmmu. Add it to the former.

---
 linux-user/elfload.c | 1 +
 1 file changed, 1 insertion(+)
linux-user/elfload.c +0 -0
index 861ec07abcd..33b20548721 100644

linux-user/elfload.c uint32_t get_elf_hwcap(void) · line 1620

Quoted 7 lines
linux-user/elfload.c +1 -0
@@ -1614,6 +1614,7 @@ uint32_t get_elf_hwcap(void)
     }
     GET_FEATURE(S390_FEAT_VECTOR, HWCAP_S390_VXRS);
     GET_FEATURE(S390_FEAT_VECTOR_ENH, HWCAP_S390_VXRS_EXT);
+    GET_FEATURE(S390_FEAT_VECTOR_ENH2, HWCAP_S390_VXRS_EXT2);
 
     return hwcap;
 }
#5 lore raw

PATCH 2/3 target/s390x: Fix the "ignored match" case in VSTRS

In reply to Ilya Leoshkevich

Currently the emulation of VSTRS recognizes partial matches in presence of \0 in the haystack, which, according to PoP, is not correct:

If the ZS flag is one and a zero byte was detected in the second operand, then there can not be a partial match ...

Add a check for this. While at it, fold a number of explicitly handled special cases into the generic logic.

---
 target/s390x/tcg/vec_string_helper.c | 54 +++++++++-------------------
 1 file changed, 17 insertions(+), 37 deletions(-)
target/s390x/tcg/vec_string_helper.c +17 -37
index 9b85becdfbf..a19f429768f 100644
@@ -474,9 +474,9 @@ DEF_VSTRC_CC_RT_HELPER(32)
 static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
                  const S390Vector *v4, uint8_t es, bool zs)
 {
-    int substr_elen, substr_0, str_elen, i, j, k, cc;
+    int substr_elen, i, j, k, cc;
     int nelem = 16 >> es;
-    bool eos = false;
+    int str_leftmost_0;
 
     substr_elen = s390_vec_read_element8(v4, 7) >> es;
 
@@ -498,47 +498,20 @@ static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
     }
 
     /* If ZS, look for eos in the searched string. */
+    str_leftmost_0 = nelem;
     if (zs) {
         for (k = 0; k < nelem; k++) {
             if (s390_vec_read_element(v2, k, es) == 0) {
-                eos = true;
+                str_leftmost_0 = k;
                 break;
             }
         }
-        str_elen = k;
-    } else {
-        str_elen = nelem;
     }
 
-    substr_0 = s390_vec_read_element(v3, 0, es);
-
-    for (k = 0; ; k++) {
-        for (; k < str_elen; k++) {
-            if (s390_vec_read_element(v2, k, es) == substr_0) {
-                break;
-            }
-        }
-
-        /* If we reached the end of the string, no match. */
-        if (k == str_elen) {
-            cc = eos; /* no match (with or without zero char) */
-            goto done;
-        }
-
-        /* If the substring is only one char, match. */
-        if (substr_elen == 1) {
-            cc = 2; /* full match */
-            goto done;
-        }
-
-        /* If the match begins at the last char, we have a partial match. */
-        if (k == str_elen - 1) {
-            cc = 3; /* partial match */
-            goto done;
-        }
-
+    cc = str_leftmost_0 == nelem ? 0 : 1;  /* No match. */
+    for (k = 0; k < nelem; k++) {
         i = MIN(nelem, k + substr_elen);
-        for (j = k + 1; j < i; j++) {
+        for (j = k; j < i; j++) {
             uint32_t e2 = s390_vec_read_element(v2, j, es);
             uint32_t e3 = s390_vec_read_element(v3, j - k, es);
             if (e2 != e3) {
@@ -546,9 +519,16 @@ static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
             }
         }
         if (j == i) {
-            /* Matched up until "end". */
-            cc = i - k == substr_elen ? 2 : 3; /* full or partial match */
-            goto done;
+            /* All elements matched. */
+            if (k > str_leftmost_0) {
+                cc = 1;  /* Ignored match. */
+                k = nelem;
+            } else if (i - k == substr_elen) {
+                cc = 2;  /* Full match. */
+            } else {
+                cc = 3;  /* Partial match. */
+            }
+            break;
         }
     }
 
Signature · 1 line
2.41.0
#6 lore raw
Quoted 9 lines · Ilya Leoshkevich

Currently the emulation of VSTRS recognizes partial matches in presence of \0 in the haystack, which, according to PoP, is not correct:

If the ZS flag is one and a zero byte was detected in the second operand, then there can not be a partial match ...

Add a check for this. While at it, fold a number of explicitly handled special cases into the generic logic.

Can we split that off? Or doesn't it make sense to split it off after fixing the issue?

Signature · 3 lines
Cheers,

David / dhildenb
#7 lore raw
Quoted 9 lines · David Hildenbrand
Quoted 8 lines · Ilya Leoshkevich

Currently the emulation of VSTRS recognizes partial matches in presence
of \0 in the haystack, which, according to PoP, is not correct:

     If the ZS flag is one and a zero byte was detected in the second operand, then there can not be a partial match ...

Quoted 6 lines
Quoted 3 lines

Add a check for this. While at it, fold a number of explicitly handled
special cases into the generic logic.

Can we split that off? Or doesn't it make sense to split it off after fixing the issue?

I could do this if this is important, e.g., for stable, but I came to the conclusion that I needed to get rid of the special cases after I had to add the new check to more than one place.

#8 lore raw
Quoted 14 lines · Ilya Leoshkevich
Quoted 13 lines · David Hildenbrand
Quoted 11 lines · Ilya Leoshkevich

Currently the emulation of VSTRS recognizes partial matches in presence
of \0 in the haystack, which, according to PoP, is not correct:

     If the ZS flag is one and a zero byte was detected in the second operand, then there can not be a partial match ...

Add a check for this. While at it, fold a number of explicitly handled
special cases into the generic logic.

Quoted 6 lines
Quoted 2 lines

Can we split that off? Or doesn't it make sense to split it off after fixing the issue?

I could do this if this is important, e.g., for stable, but I came to the conclusion that I needed to get rid of the special cases after I had to add the new check to more than one place.

Okay, so let's keep it as is.

Fortunately you heavily test that code! :)

Signature · 3 lines
Cheers,

David / dhildenb
Tested-by on v1 2/3
#9 lore raw
In reply to Ilya Leoshkevich
Quoted 7 lines · Ilya Leoshkevich

Currently the emulation of VSTRS recognizes partial matches in presence of \0 in the haystack, which, according to PoP, is not correct:

If the ZS flag is one and a zero byte was detected in the second operand, then there can not be a partial match ...

Quoted 8 lines

Add a check for this. While at it, fold a number of explicitly handled special cases into the generic logic.

verified that it fixes the problem I encountered,

Quoted 93 lines
---
 target/s390x/tcg/vec_string_helper.c | 54 +++++++++-------------------
 1 file changed, 17 insertions(+), 37 deletions(-)
target/s390x/tcg/vec_string_helper.c +17 -37
index 9b85becdfbf..a19f429768f 100644
@@ -474,9 +474,9 @@ DEF_VSTRC_CC_RT_HELPER(32)
 static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
                  const S390Vector *v4, uint8_t es, bool zs)
 {
-    int substr_elen, substr_0, str_elen, i, j, k, cc;
+    int substr_elen, i, j, k, cc;
     int nelem = 16 >> es;
-    bool eos = false;
+    int str_leftmost_0;
 
     substr_elen = s390_vec_read_element8(v4, 7) >> es;
 
@@ -498,47 +498,20 @@ static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
     }
 
     /* If ZS, look for eos in the searched string. */
+    str_leftmost_0 = nelem;
     if (zs) {
         for (k = 0; k < nelem; k++) {
             if (s390_vec_read_element(v2, k, es) == 0) {
-                eos = true;
+                str_leftmost_0 = k;
                 break;
             }
         }
-        str_elen = k;
-    } else {
-        str_elen = nelem;
     }
 
-    substr_0 = s390_vec_read_element(v3, 0, es);
-
-    for (k = 0; ; k++) {
-        for (; k < str_elen; k++) {
-            if (s390_vec_read_element(v2, k, es) == substr_0) {
-                break;
-            }
-        }
-
-        /* If we reached the end of the string, no match. */
-        if (k == str_elen) {
-            cc = eos; /* no match (with or without zero char) */
-            goto done;
-        }
-
-        /* If the substring is only one char, match. */
-        if (substr_elen == 1) {
-            cc = 2; /* full match */
-            goto done;
-        }
-
-        /* If the match begins at the last char, we have a partial match. */
-        if (k == str_elen - 1) {
-            cc = 3; /* partial match */
-            goto done;
-        }
-
+    cc = str_leftmost_0 == nelem ? 0 : 1;  /* No match. */
+    for (k = 0; k < nelem; k++) {
         i = MIN(nelem, k + substr_elen);
-        for (j = k + 1; j < i; j++) {
+        for (j = k; j < i; j++) {
             uint32_t e2 = s390_vec_read_element(v2, j, es);
             uint32_t e3 = s390_vec_read_element(v3, j - k, es);
             if (e2 != e3) {
@@ -546,9 +519,16 @@ static int vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
             }
         }
         if (j == i) {
-            /* Matched up until "end". */
-            cc = i - k == substr_elen ? 2 : 3; /* full or partial match */
-            goto done;
+            /* All elements matched. */
+            if (k > str_leftmost_0) {
+                cc = 1;  /* Ignored match. */
+                k = nelem;
+            } else if (i - k == substr_elen) {
+                cc = 2;  /* Full match. */
+            } else {
+                cc = 3;  /* Partial match. */
+            }
+            break;
         }
     }
 
#10 lore raw

PATCH 3/3 tests/tcg/s390x: Test VSTRS

In reply to Ilya Leoshkevich

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c   | 88 +++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c
tests/tcg/s390x/Makefile.target +1 -0
index 1fc98099070..8ba36e5985b 100644
@@ -73,6 +73,7 @@ ifneq ($(CROSS_CC_HAS_Z15),)
 Z15_TESTS=vxeh2_vs
 Z15_TESTS+=vxeh2_vcvt
 Z15_TESTS+=vxeh2_vlstr
+Z15_TESTS+=vxeh2_vstrs
 $(Z15_TESTS): CFLAGS+=-march=z15 -O2
 TESTS+=$(Z15_TESTS)
 endif
tests/tcg/s390x/vxeh2_vstrs.c new file +88 -0

88 lines not on this page · raw message

Signature · 1 line
2.41.0
#11 lore raw

Re: [PATCH 3/3] tests/tcg/s390x: Test VSTRS

Quoted 46 lines · Ilya Leoshkevich

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c   | 88 +++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c
tests/tcg/s390x/Makefile.target +1 -0
index 1fc98099070..8ba36e5985b 100644
@@ -73,6 +73,7 @@ ifneq ($(CROSS_CC_HAS_Z15),)
 Z15_TESTS=vxeh2_vs
 Z15_TESTS+=vxeh2_vcvt
 Z15_TESTS+=vxeh2_vlstr
+Z15_TESTS+=vxeh2_vstrs
 $(Z15_TESTS): CFLAGS+=-march=z15 -O2
 TESTS+=$(Z15_TESTS)
 endif
tests/tcg/s390x/vxeh2_vstrs.c new file +19 -0
new file mode 100644
index 00000000000..313ec1d728f
@@ -0,0 +1,88 @@
+/*
+ * Test the VSTRS instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "vx.h"
+
+static inline __attribute__((__always_inline__)) int
+vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
+      const S390Vector *v4, const uint8_t m5, const uint8_t m6)
+{
+    int cc;
+
+    asm("vstrs %[v1],%[v2],%[v3],%[v4],%[m5],%[m6]\n"
+        "ipm %[cc]"

tests/tcg/s390x/vxeh2_vstrs.c line 29

Quoted 10 lines
tests/tcg/s390x/vxeh2_vstrs.c new file +10 -0
+        : [v1] "=v" (v1->v)
+        , [cc] "=r" (cc)
+        : [v2] "v" (v2->v)
+        , [v3] "v" (v3->v)
+        , [v4] "v" (v4->v)
+        , [m5] "i" (m5)
+        , [m6]  "i" (m6)
+        : "cc");
+
+    return (cc >> 28) & 3;

Following the POp, I am puzzled by the use of an "int" to contain the register result of the IPM instruction, should it not be a 64bit variable? bits 0-31 are left unchanged / are uninteresting, is that enough to avoid having to use a properly sized variable?

I see that this is done elsewhere in the tests (sometimes a 64bit variable is used, sometimes just 'int'), so I assume it's probably fine.

Otherwise lgtm,

Claudio

Quoted 59 lines
tests/tcg/s390x/vxeh2_vstrs.c new file +59 -0
+}
+
+static void test_ignored_match(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x222000205e410000ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0x205e410000000000ULL, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 3, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
+    assert(v1.d[0] == 16);
+    assert(v1.d[1] == 0);
+}
+
+static void test_empty_needle(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x5300000000000000ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 0, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 2);
+    assert(v1.d[0] == 0);
+    assert(v1.d[1] == 0);
+}
+
+static void test_max_length(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x1122334455667700ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 16, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 3);
+    assert(v1.d[0] == 7);
+    assert(v1.d[1] == 0);
+}
+
+static void test_no_match(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0xffffff000fffff00ULL, .d[1] = 0x82b};
+    S390Vector v3 = {.d[0] = 0xfffffffeffffffffULL,
+                     .d[1] = 0xffffffff00000000ULL};
+    S390Vector v4 = {.d[0] = 11, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
+    assert(v1.d[0] == 16);
+    assert(v1.d[1] == 0);
+}
+
+int main(void)
+{
+    test_ignored_match();
+    test_empty_needle();
+    test_max_length();
+    test_no_match();
+    return EXIT_SUCCESS;
+}
#12 lore raw

Re: [PATCH 3/3] tests/tcg/s390x: Test VSTRS

Quoted 57 lines · Claudio Fontana
Quoted 56 lines · Ilya Leoshkevich

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c   | 88
+++++++++++++++++++++++++++++++++

 2 files changed, 89 insertions(+)

 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c

tests/tcg/s390x/Makefile.target +0 -0
index 1fc98099070..8ba36e5985b 100644
@@ -73,6 +73,7 @@ ifneq ($(CROSS_CC_HAS_Z15),)

 Z15_TESTS=vxeh2_vs
 Z15_TESTS+=vxeh2_vcvt
 Z15_TESTS+=vxeh2_vlstr
+Z15_TESTS+=vxeh2_vstrs
 $(Z15_TESTS): CFLAGS+=-march=z15 -O2
 TESTS+=$(Z15_TESTS)
 endif

tests/tcg/s390x/vxeh2_vstrs.c new file +26 -0
new file mode 100644
index 00000000000..313ec1d728f
@@ -0,0 +1,88 @@
+/*
+ * Test the VSTRS instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "vx.h"
+
+static inline __attribute__((__always_inline__)) int
+vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
+      const S390Vector *v4, const uint8_t m5, const uint8_t m6)
+{
+    int cc;
+
+    asm("vstrs %[v1],%[v2],%[v3],%[v4],%[m5],%[m6]\n"
+        "ipm %[cc]"
+        : [v1] "=v" (v1->v)
+        , [cc] "=r" (cc)
+        : [v2] "v" (v2->v)
+        , [v3] "v" (v3->v)
+        , [v4] "v" (v4->v)
+        , [m5] "i" (m5)
+        , [m6]  "i" (m6)
Quoted 8 lines

tests/tcg/s390x/vxeh2_vstrs.c line 29

Quoted 3 lines
tests/tcg/s390x/vxeh2_vstrs.c new file +3 -0
+        : "cc");
+
+    return (cc >> 28) & 3;

Following the POp, I am puzzled by the use of an "int" to contain the register result of the IPM instruction, should it not be a 64bit variable?
bits 0-31 are left unchanged / are uninteresting, is that enough to avoid having to use a properly sized variable?

The compiler understands that if the type is int, then the asm block will not touch the upper 32 bits of the register that's assigned to it. This observation is used not only in the QEMU tests, but also all over arch/s390 in the Linux kernel.

Quoted 8 lines

I see that this is done elsewhere in the tests (sometimes a 64bit variable is used, sometimes just 'int'), so I assume it's probably fine.

Otherwise lgtm,

Claudio

[...]

Quoted 1 line
#13 lore raw

Re: [PATCH 3/3] tests/tcg/s390x: Test VSTRS

Quoted 67 lines · Ilya Leoshkevich
Quoted 57 lines · Claudio Fontana
Quoted 56 lines · Ilya Leoshkevich

Add a small test to prevent regressions.

---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c   | 88
+++++++++++++++++++++++++++++++++

 2 files changed, 89 insertions(+)

 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c

tests/tcg/s390x/Makefile.target +0 -0
index 1fc98099070..8ba36e5985b 100644
@@ -73,6 +73,7 @@ ifneq ($(CROSS_CC_HAS_Z15),)

 Z15_TESTS=vxeh2_vs
 Z15_TESTS+=vxeh2_vcvt
 Z15_TESTS+=vxeh2_vlstr
+Z15_TESTS+=vxeh2_vstrs
 $(Z15_TESTS): CFLAGS+=-march=z15 -O2
 TESTS+=$(Z15_TESTS)
 endif

tests/tcg/s390x/vxeh2_vstrs.c new file +26 -0
new file mode 100644
index 00000000000..313ec1d728f
@@ -0,0 +1,88 @@
+/*
+ * Test the VSTRS instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "vx.h"
+
+static inline __attribute__((__always_inline__)) int
+vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
+      const S390Vector *v4, const uint8_t m5, const uint8_t m6)
+{
+    int cc;
+
+    asm("vstrs %[v1],%[v2],%[v3],%[v4],%[m5],%[m6]\n"
+        "ipm %[cc]"
+        : [v1] "=v" (v1->v)
+        , [cc] "=r" (cc)
+        : [v2] "v" (v2->v)
+        , [v3] "v" (v3->v)
+        , [v4] "v" (v4->v)
+        , [m5] "i" (m5)
+        , [m6]  "i" (m6)
Quoted 8 lines

tests/tcg/s390x/vxeh2_vstrs.c line 29

Quoted 3 lines
tests/tcg/s390x/vxeh2_vstrs.c new file +3 -0
+        : "cc");
+
+    return (cc >> 28) & 3;

Following the POp, I am puzzled by the use of an "int" to contain the register result of the IPM instruction, should it not be a 64bit variable?
bits 0-31 are left unchanged / are uninteresting, is that enough to avoid having to use a properly sized variable?

Quoted 4 lines

The compiler understands that if the type is int, then the asm block will not touch the upper 32 bits of the register that's assigned to it. This observation is used not only in the QEMU tests, but also all over arch/s390 in the Linux kernel.

Thank you,

Claudio

Quoted 12 lines
Quoted 8 lines

I see that this is done elsewhere in the tests (sometimes a 64bit variable is used, sometimes just 'int'), so I assume it's probably fine.

Otherwise lgtm,

Claudio

[...]

Quoted 1 line
#14 lore raw

Re: [PATCH 3/3] tests/tcg/s390x: Test VSTRS

In reply to Ilya Leoshkevich
Quoted 3 lines · Ilya Leoshkevich

Add a small test to prevent regressions.

Something seems off in the wiring of the make check target?

I built with:

./configure --target-list=s390x-linux-user,s390x-softmmu

make -j
make -j check-help

...

Individual test suites:

 make check-qtest-TARGET     Run qtest tests for given target
 make check-qtest            Run qtest tests
 make check-unit             Run qobject tests
 make check-qapi-schema      Run QAPI schema tests
 make check-block            Run block tests
 make check-tcg              Run TCG tests

...

make -j check-tcg

changing dir to build for make "check-tcg"... make[1]: Entering directory '/root/git/qemu/build' make[1]: Nothing to be done for 'check-tcg'. make[1]: Leaving directory '/root/git/qemu/build'

Why is this not running any tests for tcg?

I tried also to run the general make check,
but even in this case the tcg tests do not seem to trigger.

Thanks,

Claudio

Quoted 112 lines
---
 tests/tcg/s390x/Makefile.target |  1 +
 tests/tcg/s390x/vxeh2_vstrs.c   | 88 +++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
 create mode 100644 tests/tcg/s390x/vxeh2_vstrs.c
tests/tcg/s390x/Makefile.target +1 -0
index 1fc98099070..8ba36e5985b 100644
@@ -73,6 +73,7 @@ ifneq ($(CROSS_CC_HAS_Z15),)
 Z15_TESTS=vxeh2_vs
 Z15_TESTS+=vxeh2_vcvt
 Z15_TESTS+=vxeh2_vlstr
+Z15_TESTS+=vxeh2_vstrs
 $(Z15_TESTS): CFLAGS+=-march=z15 -O2
 TESTS+=$(Z15_TESTS)
 endif
tests/tcg/s390x/vxeh2_vstrs.c new file +88 -0
new file mode 100644
index 00000000000..313ec1d728f
@@ -0,0 +1,88 @@
+/*
+ * Test the VSTRS instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "vx.h"
+
+static inline __attribute__((__always_inline__)) int
+vstrs(S390Vector *v1, const S390Vector *v2, const S390Vector *v3,
+      const S390Vector *v4, const uint8_t m5, const uint8_t m6)
+{
+    int cc;
+
+    asm("vstrs %[v1],%[v2],%[v3],%[v4],%[m5],%[m6]\n"
+        "ipm %[cc]"
+        : [v1] "=v" (v1->v)
+        , [cc] "=r" (cc)
+        : [v2] "v" (v2->v)
+        , [v3] "v" (v3->v)
+        , [v4] "v" (v4->v)
+        , [m5] "i" (m5)
+        , [m6]  "i" (m6)
+        : "cc");
+
+    return (cc >> 28) & 3;
+}
+
+static void test_ignored_match(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x222000205e410000ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0x205e410000000000ULL, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 3, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
+    assert(v1.d[0] == 16);
+    assert(v1.d[1] == 0);
+}
+
+static void test_empty_needle(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x5300000000000000ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 0, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 2);
+    assert(v1.d[0] == 0);
+    assert(v1.d[1] == 0);
+}
+
+static void test_max_length(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0x1122334455667700ULL, .d[1] = 0};
+    S390Vector v3 = {.d[0] = 0, .d[1] = 0};
+    S390Vector v4 = {.d[0] = 16, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 0) == 3);
+    assert(v1.d[0] == 7);
+    assert(v1.d[1] == 0);
+}
+
+static void test_no_match(void)
+{
+    S390Vector v1;
+    S390Vector v2 = {.d[0] = 0xffffff000fffff00ULL, .d[1] = 0x82b};
+    S390Vector v3 = {.d[0] = 0xfffffffeffffffffULL,
+                     .d[1] = 0xffffffff00000000ULL};
+    S390Vector v4 = {.d[0] = 11, .d[1] = 0};
+
+    assert(vstrs(&v1, &v2, &v3, &v4, 0, 2) == 1);
+    assert(v1.d[0] == 16);
+    assert(v1.d[1] == 0);
+}
+
+int main(void)
+{
+    test_ignored_match();
+    test_empty_needle();
+    test_max_length();
+    test_no_match();
+    return EXIT_SUCCESS;
+}
#15 lore raw

Re: [PATCH 3/3] tests/tcg/s390x: Test VSTRS

Quoted 35 lines · Claudio Fontana
Quoted 3 lines · Ilya Leoshkevich

Add a small test to prevent regressions.

Something seems off in the wiring of the make check target?

I built with:

./configure --target-list=s390x-linux-user,s390x-softmmu

make -j
make -j check-help

...

Individual test suites:

 make check-qtest-TARGET     Run qtest tests for given target
 make check-qtest            Run qtest tests
 make check-unit             Run qobject tests
 make check-qapi-schema      Run QAPI schema tests
 make check-block            Run block tests
 make check-tcg              Run TCG tests

...

make -j check-tcg

changing dir to build for make "check-tcg"... make[1]: Entering directory '/root/git/qemu/build' make[1]: Nothing to be done for 'check-tcg'. make[1]: Leaving directory '/root/git/qemu/build'

Quoted 8 lines

Why is this not running any tests for tcg?

I tried also to run the general make check,
but even in this case the tcg tests do not seem to trigger.

Thanks,

Claudio

Hi,

I believe you need either s390x-linux-gnu-gcc or docker/podman to run the tcg tests.

Best regards,
Ilya