s390x: first batch of 4.0 changes
The following changes since commit bb9bf94b3e8926553290bc9a7cb84315af422086:
Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into staging (2018-12-11 19:18:58 +0000)
are available in the Git repository at:
https://github.com/cohuck/qemu tags/s390x-20181212
for you to fetch changes up to c9aacaadeb42076c01b07e59dd94dcf73f751e05:
hw/s390x/virtio-ccw.c: Don't take address of fields in packed structs (2018-12-12 10:39:28 +0100)
----------------------------------------------------------------
s390x patches for 4.0:
- add 4.0 machine type
- various fixes and small changes
----------------------------------------------------------------
Christian Borntraeger (1):
s390/MAINTAINERS: Add Halil as kvm and machine maintainer
Cornelia Huck (2):
s390x: introduce 4.0 compat machine
vfio-ap: flag as compatible with balloon
David Hildenbrand (2):
s390x/zpci: drop msix.available
s390x/tod: Properly stop the KVM TOD while the guest is not running
Peter Maydell (1):
hw/s390x/virtio-ccw.c: Don't take address of fields in packed structs
MAINTAINERS | 4 +- hw/s390x/s390-pci-bus.c | 2 - hw/s390x/s390-pci-bus.h | 1 - hw/s390x/s390-virtio-ccw.c | 17 ++++++- hw/s390x/tod-kvm.c | 102 ++++++++++++++++++++++++++++++++++++- hw/s390x/virtio-ccw.c | 42 +++++++-------- hw/vfio/ap.c | 8 +++ include/hw/s390x/tod.h | 8 ++- 8 files changed, 156 insertions(+), 28 deletions(-)
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 1/6] s390x/zpci: drop msix.available
From: David Hildenbrand <[email protected]>
I fail to see why this is useful as we require MSIX always and completely fail adding a device.
Message-Id: <[email protected]>
--- hw/s390x/s390-pci-bus.c | 2 -- hw/s390x/s390-pci-bus.h | 1 - 2 files changed, 3 deletions(-)
hw/s390x/s390-pci-bus.c +0 -2
@@ -745,7 +745,6 @@ static int s390_pci_msix_init(S390PCIBusDevice *pbdev) pos =pci_find_capability (pbdev->pdev,PCI_CAP_ID_MSIX );if (!pos) { - pbdev->msix.available = false;return -1 ; }
@@ -761,7 +760,6 @@ static int s390_pci_msix_init(S390PCIBusDevice *pbdev) pbdev->msix.pba_bar = pba &PCI_MSIX_FLAGS_BIRMASK ; pbdev->msix.pba_offset = pba & ~PCI_MSIX_FLAGS_BIRMASK ; pbdev->msix.entries = (ctrl &PCI_MSIX_FLAGS_QSIZE ) +1 ; - pbdev->msix.available = true; name =g_strdup_printf ("msix-s390-%04x" , pbdev->uid); memory_region_init_io(&pbdev->msix_notify_mr, OBJECT(pbdev),
hw/s390x/s390-pci-bus.h +0 -1
@@ -252,7 +252,6 @@ typedef struct ChscSeiNt2Res { }QEMU_PACKED ChscSeiNt2Res; typedef struct S390MsixInfo { - bool available; uint8_t table_bar; uint8_t pba_bar; uint16_t entries;
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 2/6] s390x: introduce 4.0 compat machine
In reply to Cornelia Huck--- hw/s390x/s390-virtio-ccw.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/s390x/s390-virtio-ccw.c +16 -1
@@ -651,6 +651,9 @@ bool css_migration_enabled(void) } \ type_init(ccw_machine_register_##suffix) +#define CCW_COMPAT_3_1 \ + HW_COMPAT_3_1 +#define CCW_COMPAT_3_0 \ HW_COMPAT_3_0
@@ -742,14 +745,26 @@ bool css_migration_enabled(void) .value = "0",\ }, +static void ccw_machine_4_0_instance_options (MachineState *machine) +{ +} + +static void ccw_machine_4_0_class_options (MachineClass *mc) +{ +} +DEFINE_CCW_MACHINE(4_0, "4.0", true); +static void ccw_machine_3_1_instance_options (MachineState *machine) { +ccw_machine_4_0_instance_options (machine); }static void ccw_machine_3_1_class_options (MachineClass *mc) { +ccw_machine_4_0_class_options (mc); +SET_MACHINE_COMPAT (mc,CCW_COMPAT_3_1 ); } -DEFINE_CCW_MACHINE(3_1, "3.1", true); +DEFINE_CCW_MACHINE(3_1, "3.1", false);static void ccw_machine_3_0_instance_options (MachineState *machine) {
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 3/6] s390/MAINTAINERS: Add Halil as kvm and machine maintainer
In reply to Cornelia HuckFrom: Christian Borntraeger <[email protected]>
Halil does more work in this area than I do right now. Lets add Halil.
Message-Id: <[email protected]>
--- MAINTAINERS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
MAINTAINERS +3 -1
@@ -365,8 +365,9 @@ S: Maintained F: target/ppc/kvm.c S390 -M: Christian Borntraeger <[email protected]> +M: Halil Pasic <[email protected]> M: Cornelia Huck <[email protected]> +M: Christian Borntraeger <[email protected]> S: Maintained F: target/s390x/kvm.c F: target/s390x/kvm_s390x.h
@@ -1057,6 +1058,7 @@ S390 Machines ------------- S390 Virtio-ccw M: Cornelia Huck <[email protected]> +M: Halil Pasic <[email protected]> M: Christian Borntraeger <[email protected]> S: Supported F: hw/char/sclp*.[hc]
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 4/6] s390x/tod: Properly stop the KVM TOD while the guest is not running
In reply to Cornelia HuckFrom: David Hildenbrand <[email protected]>
Just like on other architectures, we should stop the clock while the guest is not running. This is already properly done for TCG. Right now, doing an offline migration (stop, migrate, cont) can easily trigger stalls in the guest.
Even doing a
(hmp) stop
... wait 2 minutes ...
(hmp) contwill already trigger stalls.
So whenever the guest stops, backup the KVM TOD. When continuing to run the guest, restore the KVM TOD.
One special case is starting a simple VM: Reading the TOD from KVM to stop it right away until the guest is actually started means that the time of any simple VM will already differ to the host time. We can simply leave the TOD running and the guest won't be able to recognize it.
For migration, we actually want to keep the TOD stopped until really starting the guest. To be able to catch most errors, we should however try to set the TOD in addition to simply storing it. So we can still catch basic migration problems.
If anything goes wrong while backing up/restoring the TOD, we have to ignore it (but print a warning). This is then basically a fallback to old behavior (TOD remains running).
I tested this very basically with an initrd:
1. Start a simple VM. Observed that the TOD is kept running. Old behavior.
2. Ordinary live migration. Observed that the TOD is temporarily stopped on the destination when setting the new value and correctly started when finally starting the guest.
3. Offline live migration. (stop, migrate, cont). Observed that the TOD will be stopped on the source with the "stop" command. On the destination, the TOD is temporarily stopped when setting the new value and correctly started when finally starting the guest via "cont".
4. Simple stop/cont correctly stops/starts the TOD. (multiple stops or conts in a row have no effect, so works as expected)
In the future, we might want to send the guest a special kind of time sync interrupt under some conditions, so it can synchronize its tod to the host tod. This is interesting for migration scenarios but also when we get time sync interrupts ourselves. This however will most probably have to be handled in KVM (e.g. when the tods differ too much) and is not desired e.g. when debugging the guest (single stepping should not result in permanent time syncs). I consider something like that an add-on on top of this basic "don't break the guest" handling.
Message-Id: <[email protected]>
--- hw/s390x/tod-kvm.c | 102 ++++++++++++++++++++++++++++++++++++++++- include/hw/s390x/tod.h | 8 +++- 2 files changed, 107 insertions(+), 3 deletions(-)
hw/s390x/tod-kvm.c +100 -2
@@ -10,10 +10,11 @@#include "qemu/osdep.h" #include "qapi/error.h" +#include "sysemu/sysemu.h" #include "hw/s390x/tod.h" #include "kvm_s390x.h" -static void kvm_s390_tod_get (const S390TODState *td,S390TOD *tod,Error **errp) +static void kvm_s390_get_tod_raw (S390TOD *tod,Error **errp) {int r;
@@ -27,7 +28,17 @@ static void kvm_s390_tod_get(const S390TODState *td, S390TOD *tod, Error **errp) } } -static void kvm_s390_tod_set (S390TODState *td,const S390TOD *tod,Error **errp) +static void kvm_s390_tod_get (const S390TODState *td,S390TOD *tod,Error **errp) +{ +if (td->stopped) { + *tod = td->base; +return ; + } + +kvm_s390_get_tod_raw (tod, errp); +} + +static void kvm_s390_set_tod_raw (const S390TOD *tod,Error **errp) {int r;
@@ -41,18 +52,105 @@ static void kvm_s390_tod_set(S390TODState *td, const S390TOD *tod, Error **errp) } } +static void kvm_s390_tod_set (S390TODState *td,const S390TOD *tod,Error **errp) +{ +Error *local_err =NULL ; + +/* +* Somebody (e.g. migration) set the TOD. We'll store it into KVM to +* properly detect errors now but take a look at the runstate to decide +* whether really to keep the tod running. E.g. during migration, this +* is the point where we want to stop the initially running TOD to fire +* it back up when actually starting the migrated guest. +*/ +kvm_s390_set_tod_raw (tod, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +if (runstate_is_running ()) { + td->stopped = false; + }else { + td->stopped = true; + td->base = *tod; + } +} + +static void kvm_s390_tod_vm_state_change (void *opaque,int running, +RunState state) +{ +S390TODState *td = opaque; +Error *local_err =NULL ; + +if (running && td->stopped) { +/* Set the old TOD when running the VM - start the TOD clock. */ +kvm_s390_set_tod_raw (&td->base, &local_err); +if (local_err) { +warn_report_err (local_err); + } +/* Treat errors like the TOD was running all the time. */ + td->stopped = false; + }else if (!running && !td->stopped) { +/* Store the TOD when stopping the VM - stop the TOD clock. */ +kvm_s390_get_tod_raw (&td->base, &local_err); +if (local_err) { +/* Keep the TOD running in case we could not back it up. */ +warn_report_err (local_err); + }else { + td->stopped = true; + } + } +} + +static void kvm_s390_tod_realize (DeviceState *dev,Error **errp) +{ +S390TODState *td =S390_TOD (dev); +S390TODClass *tdc =S390_TOD_GET_CLASS (td); +Error *local_err =NULL ; + + tdc->parent_realize (dev, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +/* +* We need to know when the VM gets started/stopped to start/stop the TOD. +* As we can never have more than one TOD instance (and that will never be +* removed), registering here and never unregistering is good enough. +*/ +qemu_add_vm_change_state_handler (kvm_s390_tod_vm_state_change, td); +} +static void kvm_s390_tod_class_init (ObjectClass *oc,void *data) {S390TODClass *tdc =S390_TOD_CLASS (oc); +device_class_set_parent_realize (DEVICE_CLASS (oc), kvm_s390_tod_realize, + &tdc->parent_realize); tdc->get = kvm_s390_tod_get; tdc->set = kvm_s390_tod_set; } +static void kvm_s390_tod_init (Object *obj) +{ +S390TODState *td =S390_TOD (obj); + +/* +* The TOD is initially running (value stored in KVM). Avoid needless +* loading/storing of the TOD when starting a simple VM, so let it +* run although the (never started) VM is stopped. For migration, we +* will properly set the TOD later. +*/ + td->stopped = false; +} +static TypeInfo kvm_s390_tod_info = { .name =TYPE_KVM_S390_TOD , .parent =TYPE_S390_TOD , .instance_size =sizeof (S390TODState), + .instance_init = kvm_s390_tod_init, .class_init = kvm_s390_tod_class_init, .class_size =sizeof (S390TODClass), };
include/hw/s390x/tod.h +7 -1
@@ -31,13 +31,19 @@ typedef struct S390TODState {/* private */ DeviceState parent_obj; -/* unused by KVM implementation */ +/* +* Used by TCG to remember the time base. Used by KVM to backup the TOD +* while the TOD is stopped. +*/ S390TOD base; +/* Used by KVM to remember if the TOD is stopped and base is valid. */ +bool stopped; } S390TODState; typedef struct S390TODClass { /* private */ DeviceClass parent_class; + void (*parent_realize)(DeviceState *dev, Error **errp); /* public */ void (*get)(const S390TODState *td, S390TOD *tod, Error **errp);
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 5/6] vfio-ap: flag as compatible with balloon
In reply to Cornelia Huckvfio-ap devices do not pin any pages in the host. Therefore, they are compatible with memory ballooning.
Flag them as compatible, so both vfio-ap and a balloon can be used simultaneously.
--- hw/vfio/ap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/vfio/ap.c +8 -0
@@ -104,6 +104,14 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) vapdev->vdev.name =g_strdup_printf ("%s" , mdevid); vapdev->vdev.dev = dev; +/* +* vfio-ap devices operate in a way compatible with +* memory ballooning, as no pages are pinned in the host. +* This needs to be set before vfio_get_device() for vfio common to +* handle the balloon inhibitor. +*/ + vapdev->vdev.balloon_allowed = true; + ret =vfio_get_device (vfio_group, mdevid, &vapdev->vdev, &local_err);if (ret) { goto out_get_dev_err;
Signature · 1 line
2.17.2
[Qemu-devel] [PULL 6/6] hw/s390x/virtio-ccw.c: Don't take address of fields in packed structs
In reply to Cornelia HuckFrom: Peter Maydell <[email protected]>
Taking the address of a field in a packed struct is a bad idea, because it might not be actually aligned enough for that pointer type (and thus cause a crash on dereference on some host architectures). Newer versions of clang warn about this. Avoid the bug by not using the "modify in place" byte swapping functions.
Patch produced with scripts/coccinelle/inplace-byteswaps.cocci (with a couple of long lines manually wrapped).
Message-Id: <[email protected]>
--- hw/s390x/virtio-ccw.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)
hw/s390x/virtio-ccw.c +22 -20
@@ -287,18 +287,18 @@ static int virtio_ccw_handle_set_vq(SubchDev *sch, CCW1 ccw, bool check_len, }if (is_legacy) {ccw_dstream_read (&sch->cds, linfo); -be64_to_cpus (&linfo.queue); -be32_to_cpus (&linfo.align); -be16_to_cpus (&linfo.index); -be16_to_cpus (&linfo.num); + linfo.queue =be64_to_cpu (linfo.queue); + linfo.align =be32_to_cpu (linfo.align); + linfo.index =be16_to_cpu (linfo.index); + linfo.num =be16_to_cpu (linfo.num); ret =virtio_ccw_set_vqs (sch,NULL , &linfo); }else {ccw_dstream_read (&sch->cds, info); -be64_to_cpus (&info.desc); -be16_to_cpus (&info.index); -be16_to_cpus (&info.num); -be64_to_cpus (&info.avail); -be64_to_cpus (&info.used); + info.desc =be64_to_cpu (info.desc); + info.index =be16_to_cpu (info.index); + info.num =be16_to_cpu (info.num); + info.avail =be64_to_cpu (info.avail); + info.used =be64_to_cpu (info.used); ret =virtio_ccw_set_vqs (sch, &info,NULL ); } sch->curr_status.scsw.count =0 ;
@@ -382,7 +382,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) features.features =0 ; }ccw_dstream_rewind (&sch->cds); -cpu_to_le32s (&features.features); + features.features =cpu_to_le32 (features.features);ccw_dstream_write (&sch->cds, features.features); sch->curr_status.scsw.count = ccw.count -sizeof (features); ret =0 ;
@@ -403,7 +403,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) ret = -EFAULT ; }else {ccw_dstream_read (&sch->cds, features); -le32_to_cpus (&features.features); + features.features =le32_to_cpu (features.features);if (features.index ==0 ) { virtio_set_features(vdev, (vdev->guest_features & 0xffffffff00000000ULL) |
@@ -546,7 +546,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) ret = -EFAULT ; }else {ccw_dstream_read (&sch->cds, indicators); -be64_to_cpus (&indicators); + indicators =be64_to_cpu (indicators); dev->indicators =get_indicator (indicators,sizeof (uint64_t )); sch->curr_status.scsw.count = ccw.count -sizeof (indicators); ret =0 ;
@@ -567,7 +567,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) ret = -EFAULT ; }else {ccw_dstream_read (&sch->cds, indicators); -be64_to_cpus (&indicators); + indicators =be64_to_cpu (indicators); dev->indicators2 =get_indicator (indicators,sizeof (uint64_t )); sch->curr_status.scsw.count = ccw.count -sizeof (indicators); ret =0 ;
@@ -588,14 +588,14 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) ret = -EFAULT ; }else {ccw_dstream_read (&sch->cds, vq_config.index); -be16_to_cpus (&vq_config.index); + vq_config.index =be16_to_cpu (vq_config.index);if (vq_config.index >=VIRTIO_QUEUE_MAX ) { ret = -EINVAL ;break ; } vq_config.num_max =virtio_queue_get_num (vdev, vq_config.index); -cpu_to_be16s (&vq_config.num_max); + vq_config.num_max =cpu_to_be16 (vq_config.num_max);ccw_dstream_write (&sch->cds, vq_config.num_max); sch->curr_status.scsw.count = ccw.count -sizeof (vq_config); ret =0 ;
@@ -621,9 +621,11 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)if (ccw_dstream_read (&sch->cds, thinint)) { ret = -EFAULT ; }else { -be64_to_cpus (&thinint.ind_bit); -be64_to_cpus (&thinint.summary_indicator); -be64_to_cpus (&thinint.device_indicator); + thinint.ind_bit =be64_to_cpu (thinint.ind_bit); + thinint.summary_indicator = +be64_to_cpu (thinint.summary_indicator); + thinint.device_indicator = +be64_to_cpu (thinint.device_indicator); dev->summary_indicator =get_indicator (thinint.summary_indicator,sizeof (uint8_t ));
@@ -654,8 +656,8 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)break ; }ccw_dstream_read_buf (&sch->cds, &revinfo,4 ); -be16_to_cpus (&revinfo.revision); -be16_to_cpus (&revinfo.length); + revinfo.revision =be16_to_cpu (revinfo.revision); + revinfo.length =be16_to_cpu (revinfo.length);if (ccw.count < len + revinfo.length || (check_len && ccw.count > len + revinfo.length)) { ret = -EINVAL ;
Signature · 1 line
2.17.2
Peter Maydell
AppliedQuoted 11 lines · Cornelia Huck
The following changes since commit
bb9bf94b3e8926553290bc9a7cb84315af422086:Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into staging (2018-12-11 19:18:58 +0000)
are available in the Git repository at:
https://github.com/cohuck/qemu tags/s390x-20181212
for you to fetch changes up to
c9aacaadeb42076c01b07e59dd94dcf73f751e05:
Quoted 8 lines
hw/s390x/virtio-ccw.c: Don't take address of fields in packed structs (2018-12-12 10:39:28 +0100)----------------------------------------------------------------
s390x patches for 4.0:
- add 4.0 machine type
- various fixes and small changes----------------------------------------------------------------
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.
-- PMM