[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/20] tests/tcg/s390x: Test modifying code using the MVC instruct
From: |
Thomas Huth |
Subject: |
[PULL 09/20] tests/tcg/s390x: Test modifying code using the MVC instruction |
Date: |
Thu, 30 Jan 2025 14:15:23 +0100 |
From: Ilya Leoshkevich <iii@linux.ibm.com>
Add a small test to prevent regressions.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-ID: <20250128001338.11474-2-iii@linux.ibm.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/tcg/s390x/mvc-smc.c | 82 +++++++++++++++++++++++++
tests/tcg/s390x/Makefile.softmmu-target | 1 +
2 files changed, 83 insertions(+)
create mode 100644 tests/tcg/s390x/mvc-smc.c
diff --git a/tests/tcg/s390x/mvc-smc.c b/tests/tcg/s390x/mvc-smc.c
new file mode 100644
index 0000000000..d68f60caa8
--- /dev/null
+++ b/tests/tcg/s390x/mvc-smc.c
@@ -0,0 +1,82 @@
+/*
+ * Test modifying code using the MVC instruction.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <minilib.h>
+
+#define PAGE_SIZE 4096
+#define BR_14_SIZE 2
+#define RWX_OFFSET 2
+
+static unsigned char rw[PAGE_SIZE + BR_14_SIZE];
+static unsigned char rwx[RWX_OFFSET + sizeof(rw)]
+ __attribute__((aligned(PAGE_SIZE)));
+
+typedef unsigned long (*function_t)(unsigned long);
+
+static int emit_function(unsigned char *p, int n)
+{
+ int i = 0, val = 0;
+
+ while (i < n - 2) {
+ /* aghi %r2,1 */
+ p[i++] = 0xa7;
+ p[i++] = 0x2b;
+ p[i++] = 0x00;
+ p[i++] = 0x01;
+ val++;
+ }
+
+ /* br %r14 */
+ p[i++] = 0x07;
+ p[i++] = 0xfe;
+
+ return val;
+}
+
+static void memcpy_mvc(void *dest, void *src, unsigned long n)
+{
+ while (n >= 256) {
+ asm("mvc 0(256,%[dest]),0(%[src])"
+ :
+ : [dest] "a" (dest)
+ , [src] "a" (src)
+ : "memory");
+ dest += 256;
+ src += 256;
+ n -= 256;
+ }
+ asm("exrl %[n],0f\n"
+ "j 1f\n"
+ "0: mvc 0(1,%[dest]),0(%[src])\n"
+ "1:"
+ :
+ : [dest] "a" (dest)
+ , [src] "a" (src)
+ , [n] "a" (n)
+ : "memory");
+}
+
+int main(void)
+{
+ int expected, size;
+
+ /* Create a TB. */
+ size = sizeof(rwx) - RWX_OFFSET - 4;
+ expected = emit_function(rwx + RWX_OFFSET, size);
+ if (((function_t)(rwx + RWX_OFFSET))(0) != expected) {
+ return 1;
+ }
+
+ /* Overwrite the TB. */
+ size += 4;
+ expected = emit_function(rw, size);
+ memcpy_mvc(rwx + RWX_OFFSET, rw, size);
+ if (((function_t)(rwx + RWX_OFFSET))(0) != expected) {
+ return 2;
+ }
+
+ return 0;
+}
diff --git a/tests/tcg/s390x/Makefile.softmmu-target
b/tests/tcg/s390x/Makefile.softmmu-target
index 7adde2fa08..8cd4667c63 100644
--- a/tests/tcg/s390x/Makefile.softmmu-target
+++ b/tests/tcg/s390x/Makefile.softmmu-target
@@ -42,6 +42,7 @@ $(ASM_TESTS): LDFLAGS += -Wl,-T$(LINK_SCRIPT)
-Wl,--build-id=none
$(ASM_TESTS): $(LINK_SCRIPT)
TESTS += $(ASM_TESTS)
+MULTIARCH_TESTS += mvc-smc
S390X_MULTIARCH_RUNTIME_OBJS = head64.o console.o $(MINILIB_OBJS)
$(MULTIARCH_TESTS): $(S390X_MULTIARCH_RUNTIME_OBJS)
$(MULTIARCH_TESTS): LDFLAGS += $(S390X_MULTIARCH_RUNTIME_OBJS)
--
2.48.1
- [PULL 00/20] Functional tests, s390x improvements and slirp fixes, Thomas Huth, 2025/01/30
- [PULL 01/20] tests/functional/qemu_test/decorators: Fix bad check for imports, Thomas Huth, 2025/01/30
- [PULL 03/20] tests/functional: Convert the migration avocado test, Thomas Huth, 2025/01/30
- [PULL 06/20] tests/functional/test_mips_malta: Fix comment about endianness of the test, Thomas Huth, 2025/01/30
- [PULL 02/20] tests/functional: Fix broken decorators with lamda functions, Thomas Huth, 2025/01/30
- [PULL 04/20] tests/functional: Fix the aarch64_tcg_plugins test, Thomas Huth, 2025/01/30
- [PULL 05/20] tests/functional: Add a ppc64 mac99 test, Thomas Huth, 2025/01/30
- [PULL 09/20] tests/tcg/s390x: Test modifying code using the MVC instruction,
Thomas Huth <=
- [PULL 14/20] tests/functional: Extend PPC 40p test with Linux boot, Thomas Huth, 2025/01/30
- [PULL 15/20] tests/functional: Add a decorator for skipping long running tests, Thomas Huth, 2025/01/30
- [PULL 16/20] tests/functional: Add the ReplayKernelBase class, Thomas Huth, 2025/01/30
- [PULL 11/20] virtio-balloon-pci: Allow setting nvectors, so we can use MSI-X, Thomas Huth, 2025/01/30
- [PULL 13/20] s390x/s390-virtio-ccw: Support plugging PCI-based virtio memory devices, Thomas Huth, 2025/01/30
- [PULL 17/20] tests/functional/test_mipsel_malta: Convert the mipsel replay tests, Thomas Huth, 2025/01/30
- [PULL 10/20] hw/s390x/s390-virtio-ccw: Fix a record/replay deadlock, Thomas Huth, 2025/01/30
- [PULL 20/20] net/slirp: libslirp 4.9.0 compatibility, Thomas Huth, 2025/01/30
- [PULL 08/20] target/s390x: Fix MVC not always invalidating translation blocks, Thomas Huth, 2025/01/30
- [PULL 12/20] virtio-mem-pci: Allow setting nvectors, so we can use MSI-X, Thomas Huth, 2025/01/30