From 592711e330972044e8666f6da32079d67e26a716 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 18 Nov 2020 10:03:44 +0100 Subject: [PATCH 1/6] hw/watchdog/wdt_diag288: Remove unnecessary includes Neither sysbus.h nor module.h are required to compile this file. diag288 is not a sysbus device, and module.h (for type_init) is included eventually through qom/object.h. Signed-off-by: Thomas Huth Reviewed-by: Christian Borntraeger Message-Id: <20201118090344.243117-1-thuth@redhat.com> [CH: tweaked description] Signed-off-by: Cornelia Huck --- hw/watchdog/wdt_diag288.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/hw/watchdog/wdt_diag288.c b/hw/watchdog/wdt_diag288.c index 71a945f0bd..4c4b6a6ab7 100644 --- a/hw/watchdog/wdt_diag288.c +++ b/hw/watchdog/wdt_diag288.c @@ -14,12 +14,10 @@ #include "qemu/osdep.h" #include "sysemu/reset.h" #include "sysemu/watchdog.h" -#include "hw/sysbus.h" #include "qemu/timer.h" #include "hw/watchdog/wdt_diag288.h" #include "migration/vmstate.h" #include "qemu/log.h" -#include "qemu/module.h" static WatchdogTimerModel model = { .wdt_name = TYPE_WDT_DIAG288, From 2d9ca5a37b12902f461d901e783cc2ffa4842b93 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Thu, 26 Nov 2020 14:01:58 +0100 Subject: [PATCH 2/6] tests/acceptance: add a test for devices on s390x This adds a very basic test for checking that we present devices in a way that Linux can consume: boot with both virtio-net-ccw and virtio-net-pci attached and then verify that Linux is able to see and detect these devices. Signed-off-by: Cornelia Huck Reviewed-by: Thomas Huth Reviewed-by: Wainer dos Santos Moschetta Message-Id: <20201126130158.1471985-1-cohuck@redhat.com> --- MAINTAINERS | 1 + tests/acceptance/machine_s390_ccw_virtio.py | 68 +++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 tests/acceptance/machine_s390_ccw_virtio.py diff --git a/MAINTAINERS b/MAINTAINERS index a83416d54c..a0dcd6b597 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1426,6 +1426,7 @@ F: include/hw/s390x/ F: hw/watchdog/wdt_diag288.c F: include/hw/watchdog/wdt_diag288.h F: default-configs/s390x-softmmu.mak +F: tests/acceptance/machine_s390_ccw_virtio.py T: git https://github.com/cohuck/qemu.git s390-next T: git https://github.com/borntraeger/qemu.git s390-next L: qemu-s390x@nongnu.org diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py new file mode 100644 index 0000000000..db6352c444 --- /dev/null +++ b/tests/acceptance/machine_s390_ccw_virtio.py @@ -0,0 +1,68 @@ +# Functional test that boots an s390x Linux guest with ccw and PCI devices +# attached and checks whether the devices are recognized by Linux +# +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Cornelia Huck +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + + +from avocado_qemu import Test +from avocado_qemu import exec_command_and_wait_for_pattern +from avocado_qemu import wait_for_console_pattern + +class S390CCWVirtioMachine(Test): + KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' + + def wait_for_console_pattern(self, success_message, vm=None): + wait_for_console_pattern(self, success_message, + failure_message='Kernel panic - not syncing', + vm=vm) + + timeout = 120 + + def test_s390x_devices(self): + + """ + :avocado: tags=arch:s390x + :avocado: tags=machine:s390-ccw-virtio + """ + + kernel_url = ('https://snapshot.debian.org/archive/debian/' + '20201126T092837Z/dists/buster/main/installer-s390x/' + '20190702+deb10u6/images/generic/kernel.debian') + kernel_hash = '5821fbee57d6220a067a8b967d24595621aa1eb6' + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) + + initrd_url = ('https://snapshot.debian.org/archive/debian/' + '20201126T092837Z/dists/buster/main/installer-s390x/' + '20190702+deb10u6/images/generic/initrd.debian') + initrd_hash = '81ba09c97bef46e8f4660ac25b4ac0a5be3a94d6' + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) + + self.vm.set_console() + kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + + 'console=sclp0 root=/dev/ram0 BOOT_DEBUG=3') + self.vm.add_args('-nographic', + '-kernel', kernel_path, + '-initrd', initrd_path, + '-append', kernel_command_line, + '-device', 'virtio-net-ccw,devno=fe.1.1111', + '-device', 'zpci,uid=5,target=zzz', + '-device', 'virtio-net-pci,id=zzz') + self.vm.launch() + + shell_ready = "sh: can't access tty; job control turned off" + self.wait_for_console_pattern(shell_ready) + # first debug shell is too early, we need to wait for device detection + exec_command_and_wait_for_pattern(self, 'exit', shell_ready) + + ccw_bus_id="0.1.1111" + pci_bus_id="0005:00:00.0" + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', + ccw_bus_id) + exec_command_and_wait_for_pattern(self, 'ls /sys/bus/pci/devices/', + pci_bus_id) From 083470b579bd7587bf2ecf479eced8ef6103614c Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Mon, 30 Nov 2020 19:02:14 +0100 Subject: [PATCH 3/6] tests/acceptance: test virtio-ccw revision handling The max_revision prop of virtio-ccw devices can be used to force an older revision for compatibility handling. The easiest way to check this is to force a device to revision 0, which turns off virtio-1. Signed-off-by: Cornelia Huck [re-formatted overlong lines] Reviewed-by: Thomas Huth Reviewed-by: Wainer dos Santos Moschetta Message-Id: <20201130180216.15366-2-cohuck@redhat.com> --- tests/acceptance/machine_s390_ccw_virtio.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py index db6352c444..c681271972 100644 --- a/tests/acceptance/machine_s390_ccw_virtio.py +++ b/tests/acceptance/machine_s390_ccw_virtio.py @@ -51,6 +51,10 @@ class S390CCWVirtioMachine(Test): '-initrd', initrd_path, '-append', kernel_command_line, '-device', 'virtio-net-ccw,devno=fe.1.1111', + '-device', + 'virtio-rng-ccw,devno=fe.2.0000,max_revision=0', + '-device', + 'virtio-rng-ccw,devno=fe.3.1234,max_revision=2', '-device', 'zpci,uid=5,target=zzz', '-device', 'virtio-net-pci,id=zzz') self.vm.launch() @@ -60,9 +64,21 @@ class S390CCWVirtioMachine(Test): # first debug shell is too early, we need to wait for device detection exec_command_and_wait_for_pattern(self, 'exit', shell_ready) - ccw_bus_id="0.1.1111" + ccw_bus_ids="0.1.1111 0.2.0000 0.3.1234" pci_bus_id="0005:00:00.0" exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', - ccw_bus_id) + ccw_bus_ids) exec_command_and_wait_for_pattern(self, 'ls /sys/bus/pci/devices/', pci_bus_id) + # check that the device at 0.2.0000 is in legacy mode, while the + # device at 0.3.1234 has the virtio-1 feature bit set + virtio_rng_features="00000000000000000000000000001100" + \ + "10000000000000000000000000000000" + virtio_rng_features_legacy="00000000000000000000000000001100" + \ + "00000000000000000000000000000000" + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/ccw/devices/0.2.0000/virtio?/features', + virtio_rng_features_legacy) + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/ccw/devices/0.3.1234/virtio?/features', + virtio_rng_features) From 864852ccb8359bda6b7fc51b676b3426562715e0 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Mon, 30 Nov 2020 19:02:15 +0100 Subject: [PATCH 4/6] tests/acceptance: verify s390x device detection The kernel/initrd combination does not provide the virtio-net driver; therefore, simply check whether the presented device type is indeed virtio-net for the two virtio-net-{ccw,pci} devices. Signed-off-by: Cornelia Huck [re-formatted overlong lines] Reviewed-by: Thomas Huth Reviewed-by: Wainer dos Santos Moschetta Message-Id: <20201130180216.15366-3-cohuck@redhat.com> --- tests/acceptance/machine_s390_ccw_virtio.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py index c681271972..ebea1b755c 100644 --- a/tests/acceptance/machine_s390_ccw_virtio.py +++ b/tests/acceptance/machine_s390_ccw_virtio.py @@ -82,3 +82,14 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/ccw/devices/0.3.1234/virtio?/features', virtio_rng_features) + # verify that we indeed have virtio-net devices (without having the + # virtio-net driver handy) + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/ccw/devices/0.1.1111/cutype', + '3832/01') + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_vendor', + '0x1af4') + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_device', + '0x0001') From 085cec59cfd651a24ab8233c494a0e174de8ab5d Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Mon, 30 Nov 2020 19:02:16 +0100 Subject: [PATCH 5/6] tests/acceptance: test s390x zpci fid propagation Verify that a fid specified on the command line shows up correctly as the function_id in the guest. Signed-off-by: Cornelia Huck [re-formatted overlong lines] Reviewed-by: Thomas Huth Reviewed-by: Wainer dos Santos Moschetta Message-Id: <20201130180216.15366-4-cohuck@redhat.com> --- tests/acceptance/machine_s390_ccw_virtio.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py index ebea1b755c..81d1408881 100644 --- a/tests/acceptance/machine_s390_ccw_virtio.py +++ b/tests/acceptance/machine_s390_ccw_virtio.py @@ -56,7 +56,9 @@ class S390CCWVirtioMachine(Test): '-device', 'virtio-rng-ccw,devno=fe.3.1234,max_revision=2', '-device', 'zpci,uid=5,target=zzz', - '-device', 'virtio-net-pci,id=zzz') + '-device', 'virtio-net-pci,id=zzz', + '-device', 'zpci,uid=0xa,fid=12,target=serial', + '-device', 'virtio-serial-pci,id=serial') self.vm.launch() shell_ready = "sh: can't access tty; job control turned off" @@ -65,11 +67,11 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'exit', shell_ready) ccw_bus_ids="0.1.1111 0.2.0000 0.3.1234" - pci_bus_id="0005:00:00.0" + pci_bus_ids="0005:00:00.0 000a:00:00.0" exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/', ccw_bus_ids) exec_command_and_wait_for_pattern(self, 'ls /sys/bus/pci/devices/', - pci_bus_id) + pci_bus_ids) # check that the device at 0.2.0000 is in legacy mode, while the # device at 0.3.1234 has the virtio-1 feature bit set virtio_rng_features="00000000000000000000000000001100" + \ @@ -93,3 +95,7 @@ class S390CCWVirtioMachine(Test): exec_command_and_wait_for_pattern(self, 'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_device', '0x0001') + # check fid propagation + exec_command_and_wait_for_pattern(self, + 'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id', + '0x0000000c') From c7454f05171405b8013a9d6b57045cd614ccc386 Mon Sep 17 00:00:00 2001 From: Gan Qixin Date: Fri, 4 Dec 2020 16:12:09 +0800 Subject: [PATCH 6/6] s390x/cpu: Use timer_free() in the finalize function to avoid memleaks When running device-introspect-test, a memory leak occurred in the s390_cpu_initfn function, this patch use timer_free() in the finalize function to fix it. ASAN shows memory leak stack: Direct leak of 3552 byte(s) in 74 object(s) allocated from: #0 0xfffeb3d4e1f0 in __interceptor_calloc (/lib64/libasan.so.5+0xee1f0) #1 0xfffeb36e6800 in g_malloc0 (/lib64/libglib-2.0.so.0+0x56800) #2 0xaaad51a8f9c4 in timer_new_full qemu/include/qemu/timer.h:523 #3 0xaaad51a8f9c4 in timer_new qemu/include/qemu/timer.h:544 #4 0xaaad51a8f9c4 in timer_new_ns qemu/include/qemu/timer.h:562 #5 0xaaad51a8f9c4 in s390_cpu_initfn qemu/target/s390x/cpu.c:304 #6 0xaaad51e00f58 in object_init_with_type qemu/qom/object.c:371 #7 0xaaad51e0406c in object_initialize_with_type qemu/qom/object.c:515 #8 0xaaad51e042e0 in object_new_with_type qemu/qom/object.c:729 #9 0xaaad51e3ff40 in qmp_device_list_properties qemu/qom/qom-qmp-cmds.c:153 #10 0xaaad51910518 in qdev_device_help qemu/softmmu/qdev-monitor.c:283 #11 0xaaad51911918 in qmp_device_add qemu/softmmu/qdev-monitor.c:801 #12 0xaaad51911e48 in hmp_device_add qemu/softmmu/qdev-monitor.c:916 Reported-by: Euler Robot Signed-off-by: Gan Qixin Reviewed-by: David Hildenbrand Message-Id: <20201204081209.360524-4-ganqixin@huawei.com> Signed-off-by: Cornelia Huck --- target/s390x/cpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 7b66718c44..8a734c2f8c 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -313,6 +313,11 @@ static void s390_cpu_finalize(Object *obj) #if !defined(CONFIG_USER_ONLY) S390CPU *cpu = S390_CPU(obj); + timer_del(cpu->env.tod_timer); + timer_free(cpu->env.tod_timer); + timer_del(cpu->env.cpu_timer); + timer_free(cpu->env.cpu_timer); + qemu_unregister_reset(s390_cpu_machine_reset_cb, cpu); g_free(cpu->irqstate); #endif