From d0a17829d0d53f9b03127bf6a03cc1e19c2741ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Wed, 9 Mar 2022 11:22:48 +0000 Subject: [PATCH 1/7] tests/tcg: drop -cpu max from s390x sha512-mvx invocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With -cpu max we get a warning: qemu-s390x: warning: 'msa5-base' requires 'kimd-sha-512'. But dropping the -cpu max and it still runs fine. Signed-off-by: Alex Bennée Message-Id: <20220309112248.4083619-1-alex.bennee@linaro.org> Reviewed-by: Richard Henderson Reviewed-by: David Hildenbrand Tested-by: Thomas Huth Signed-off-by: Thomas Huth --- tests/tcg/s390x/Makefile.target | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target index 257c568c58..7aa502a557 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -34,6 +34,4 @@ sha512-mvx: CFLAGS=-march=z13 -mvx -O3 sha512-mvx: sha512.c $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) -run-sha512-mvx: QEMU_OPTS+=-cpu max - TESTS+=sha512-mvx From fc3dd86a290a9c7c3c3273961b03058ae8f1d49f Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Mon, 14 Mar 2022 11:42:30 +0100 Subject: [PATCH 2/7] s390x/tcg: Fix BRASL with a large negative offset When RI2 is 0x80000000, qemu enters an infinite loop instead of jumping backwards. Fix by adding a missing cast, like in in2_ri2(). Fixes: 8ac33cdb8bfb ("Convert BRANCH AND SAVE") Signed-off-by: Ilya Leoshkevich Message-Id: <20220314104232.675863-2-iii@linux.ibm.com> Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson Signed-off-by: Thomas Huth --- target/s390x/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 904b51542f..41c8696185 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -1597,7 +1597,7 @@ static DisasJumpType op_bal(DisasContext *s, DisasOps *o) static DisasJumpType op_basi(DisasContext *s, DisasOps *o) { pc_to_link_info(o->out, s, s->pc_tmp); - return help_goto_direct(s, s->base.pc_next + 2 * get_field(s, i2)); + return help_goto_direct(s, s->base.pc_next + (int64_t)get_field(s, i2) * 2); } static DisasJumpType op_bc(DisasContext *s, DisasOps *o) From 16ed5f14215b20c8dc49b96e2149032ba3238beb Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Mon, 14 Mar 2022 11:42:31 +0100 Subject: [PATCH 3/7] s390x/tcg: Fix BRCL with a large negative offset When RI2 is 0x80000000, qemu enters an infinite loop instead of jumping backwards. Fix by adding a missing cast, like in in2_ri2(). Fixes: 7233f2ed1717 ("target-s390: Convert BRANCH ON CONDITION") Signed-off-by: Ilya Leoshkevich Message-Id: <20220314104232.675863-3-iii@linux.ibm.com> Reviewed-by: David Hildenbrand Reviewed-by: Richard Henderson Signed-off-by: Thomas Huth --- target/s390x/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index 41c8696185..5acfc0ff9b 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -1201,7 +1201,7 @@ static DisasJumpType help_branch(DisasContext *s, DisasCompare *c, bool is_imm, int imm, TCGv_i64 cdest) { DisasJumpType ret; - uint64_t dest = s->base.pc_next + 2 * imm; + uint64_t dest = s->base.pc_next + (int64_t)imm * 2; TCGLabel *lab; /* Take care of the special cases first. */ From c587bddb530c2f48b1a43b6df5028f78c39c81c3 Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Mon, 14 Mar 2022 11:42:32 +0100 Subject: [PATCH 4/7] tests/tcg/s390x: Test BRASL and BRCL with large negative offsets Add a small test in order to prevent regressions. Signed-off-by: Ilya Leoshkevich Message-Id: <20220314104232.675863-4-iii@linux.ibm.com> Reviewed-by: Richard Henderson Reviewed-by: David Hildenbrand Signed-off-by: Thomas Huth --- tests/tcg/s390x/Makefile.target | 1 + tests/tcg/s390x/branch-relative-long.c | 68 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/tcg/s390x/branch-relative-long.c diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target index 7aa502a557..f0d474a245 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -15,6 +15,7 @@ TESTS+=mvc TESTS+=shift TESTS+=trap TESTS+=signals-s390x +TESTS+=branch-relative-long ifneq ($(HAVE_GDB_BIN),) GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py diff --git a/tests/tcg/s390x/branch-relative-long.c b/tests/tcg/s390x/branch-relative-long.c new file mode 100644 index 0000000000..94219afcad --- /dev/null +++ b/tests/tcg/s390x/branch-relative-long.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include + +#define DEFINE_ASM(_name, _code) \ + extern const char _name[]; \ + extern const char _name ## _end[]; \ + asm(" .globl " #_name "\n" \ + #_name ":\n" \ + " " _code "\n" \ + " .globl " #_name "_end\n" \ + #_name "_end:\n"); + +DEFINE_ASM(br_r14, "br %r14"); +DEFINE_ASM(brasl_r0, "brasl %r0,.-0x100000000"); +DEFINE_ASM(brcl_0xf, "brcl 0xf,.-0x100000000"); + +struct test { + const char *code; + const char *code_end; +}; + +static const struct test tests[] = { + { + .code = brasl_r0, + .code_end = brasl_r0_end, + }, + { + .code = brcl_0xf, + .code_end = brcl_0xf_end, + }, +}; + +int main(void) +{ + unsigned char *buf; + size_t length = 0; + size_t i; + + for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { + size_t test_length = 0x100000000 + (tests[i].code_end - tests[i].code); + + if (test_length > length) { + length = test_length; + } + } + + buf = mmap(NULL, length, PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); + if (buf == MAP_FAILED) { + perror("SKIP: mmap() failed"); + return 0; + } + + memcpy(buf, br_r14, br_r14_end - br_r14); + for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { + void (*code)(void) = (void *)(buf + 0x100000000); + + memcpy(code, tests[i].code, tests[i].code_end - tests[i].code); + code(); + memset(code, 0, tests[i].code_end - tests[i].code); + } + + munmap(buf, length); + + return 0; +} From 5e2d19b3cd18184dde9a4793c3fbd8283ebffdfc Mon Sep 17 00:00:00 2001 From: Beraldo Leal Date: Fri, 11 Mar 2022 14:11:27 -0300 Subject: [PATCH 5/7] tests/avocado: start PhoneServer upfront MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Race conditions can happen with the current code, because the port that was available might not be anymore by the time the server is started. By setting the port to 0, PhoneServer it will use the OS default behavior to get a free port, then we save this information so we can later configure the guest. Suggested-by: Daniel P. Berrangé Signed-off-by: Beraldo Leal Message-Id: <20220311171127.2189534-1-bleal@redhat.com> Signed-off-by: Thomas Huth --- tests/avocado/avocado_qemu/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado_qemu/__init__.py index 9b056b5ce5..ac85e36a4d 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -18,7 +18,7 @@ import time import uuid import avocado -from avocado.utils import cloudinit, datadrainer, network, process, ssh, vmimage +from avocado.utils import cloudinit, datadrainer, process, ssh, vmimage from avocado.utils.path import find_command #: The QEMU build root directory. It may also be the source directory @@ -602,9 +602,6 @@ class LinuxTest(LinuxSSHMixIn, QemuSystemTest): self.log.info('Preparing cloudinit image') try: cloudinit_iso = os.path.join(self.workdir, 'cloudinit.iso') - self.phone_home_port = network.find_free_port() - if not self.phone_home_port: - self.cancel('Failed to get a free port') pubkey_content = None if ssh_pubkey: with open(ssh_pubkey) as pubkey: @@ -614,7 +611,7 @@ class LinuxTest(LinuxSSHMixIn, QemuSystemTest): password=self.password, # QEMU's hard coded usermode router address phone_home_host='10.0.2.2', - phone_home_port=self.phone_home_port, + phone_home_port=self.phone_server.server_port, authorized_key=pubkey_content) except Exception: self.cancel('Failed to prepare the cloudinit image') @@ -625,6 +622,8 @@ class LinuxTest(LinuxSSHMixIn, QemuSystemTest): self.vm.add_args('-drive', 'file=%s' % path) def set_up_cloudinit(self, ssh_pubkey=None): + self.phone_server = cloudinit.PhoneHomeServer(('0.0.0.0', 0), + self.name) cloudinit_iso = self.prepare_cloudinit(ssh_pubkey) self.vm.add_args('-drive', 'file=%s,format=raw' % cloudinit_iso) @@ -635,7 +634,9 @@ class LinuxTest(LinuxSSHMixIn, QemuSystemTest): logger=self.log.getChild('console')) console_drainer.start() self.log.info('VM launched, waiting for boot confirmation from guest') - cloudinit.wait_for_phone_home(('0.0.0.0', self.phone_home_port), self.name) + while not self.phone_server.instance_phoned_back: + self.phone_server.handle_request() + if set_up_ssh_connection: self.log.info('Setting up the SSH connection') self.ssh_connect(self.username, self.ssh_key) From 46697cb96e1cc6c3f1edbe572cee1ce9ac97cc58 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Mon, 14 Mar 2022 17:25:06 -0700 Subject: [PATCH 6/7] accel/tcg: Fix cpu_ldq_be_mmu typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the conversion to cpu_ld_*_mmu, the retaddr parameter was corrupted in the one case of cpu_ldq_be_mmu. Fixes: f83bcecb1 ("accel/tcg: Add cpu_{ld,st}*_mmu interfaces") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/902 Signed-off-by: Richard Henderson Message-Id: <20220315002506.152030-1-richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé Tested-by: Thomas Huth Signed-off-by: Thomas Huth --- accel/tcg/cputlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 3b918fe018..2035b2ac0a 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2174,7 +2174,7 @@ uint32_t cpu_ldl_be_mmu(CPUArchState *env, abi_ptr addr, uint64_t cpu_ldq_be_mmu(CPUArchState *env, abi_ptr addr, MemOpIdx oi, uintptr_t ra) { - return cpu_load_helper(env, addr, oi, MO_BEUQ, helper_be_ldq_mmu); + return cpu_load_helper(env, addr, oi, ra, helper_be_ldq_mmu); } uint16_t cpu_ldw_le_mmu(CPUArchState *env, abi_ptr addr, From 377bf6f37da11d14641a0e973c4ed272259cca9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 14 Mar 2022 15:01:08 +0100 Subject: [PATCH 7/7] softmmu: List CPU types again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit e0220bb5b2 made cpus.c target-agnostic but didn't notice the cpu_list() function is only defined in target-specific code in "cpu.h". Move list_cpus() declaration to "exec/cpu-common.h" because this function is not softmmu-specific and can also be used by user-mode, along with moving its implementation to cpu.c, which is compiled per target. Fixes: e0220bb5b2 ("softmmu: Build target-agnostic objects once") Reported-by: Max Filippov Suggested-by: Paolo Bonzini Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20220314140108.26222-1-philippe.mathieu.daude@gmail.com> Tested-by: Max Filippov Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- cpu.c | 9 +++++++++ include/exec/cpu-common.h | 2 ++ include/sysemu/cpus.h | 2 -- softmmu/cpus.c | 8 -------- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cpu.c b/cpu.c index d564886149..be1f8b074c 100644 --- a/cpu.c +++ b/cpu.c @@ -35,6 +35,7 @@ #include "sysemu/tcg.h" #include "sysemu/kvm.h" #include "sysemu/replay.h" +#include "exec/cpu-common.h" #include "exec/exec-all.h" #include "exec/translate-all.h" #include "exec/log.h" @@ -266,6 +267,14 @@ const char *parse_cpu_option(const char *cpu_option) return cpu_type; } +void list_cpus(const char *optarg) +{ + /* XXX: implement xxx_cpu_list for targets that still miss it */ +#if defined(cpu_list) + cpu_list(); +#endif +} + #if defined(CONFIG_USER_ONLY) void tb_invalidate_phys_addr(target_ulong addr) { diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 7f7b5943c7..50a7d2912e 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -158,4 +158,6 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, /* vl.c */ extern int singlestep; +void list_cpus(const char *optarg); + #endif /* CPU_COMMON_H */ diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index 868f1192de..b5c87d48b3 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -55,6 +55,4 @@ extern int smp_cores; extern int smp_threads; #endif -void list_cpus(const char *optarg); - #endif diff --git a/softmmu/cpus.c b/softmmu/cpus.c index e1d84c8ccb..7b75bb66d5 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -728,14 +728,6 @@ int vm_stop_force_state(RunState state) } } -void list_cpus(const char *optarg) -{ - /* XXX: implement xxx_cpu_list for targets that still miss it */ -#if defined(cpu_list) - cpu_list(); -#endif -} - void qmp_memsave(int64_t addr, int64_t size, const char *filename, bool has_cpu, int64_t cpu_index, Error **errp) {