s390x fixes for -rc3
The following changes since commit 2a6bcfdebe4115993a032395d459f5e0cf27a01e:
Merge remote-tracking branch 'remotes/famz/tags/testing-pull-request' into staging (2018-04-09 10:21:14 +0100)
are available in the Git repository at:
git://github.com/cohuck/qemu tags/s390x-20180409
for you to fetch changes up to b3a184f51fbed3401694a9619e6842f882a64fee:
s390x: load_psw() should only exchange the PSW for KVM (2018-04-09 13:59:06 +0200)
----------------------------------------------------------------
Fixes for s390x: kvm, vfio-ccw, ipl code, bios. Includes a rebuild of s390-ccw.img and s390-netboot.img.
----------------------------------------------------------------
Cornelia Huck (1):
pc-bios/s390: update images
David Hildenbrand (3):
s390x/kvm: call cpu_synchronize_state() on every
kvm_arch_handle_exit()
s390x/mmu: don't overwrite pending exception in mmu translate
s390x: load_psw() should only exchange the PSW for KVM
Greg Kurz (1):
vfio-ccw: fix memory leaks in vfio_ccw_realize()
Viktor Mihajlovski (3):
s390: Refactor IPL parameter block generation
s390: Ensure IPL from SCSI works as expected
s390: Do not pass inofficial IPL type to the guest
hw/s390x/ipl.c | 112 ++++++++++++++++++++++++++++++++------------- hw/vfio/ccw.c | 2 + pc-bios/s390-ccw.img | Bin 30568 -> 30520 bytes pc-bios/s390-ccw/bootmap.c | 7 +++ pc-bios/s390-ccw/iplb.h | 15 +++++- pc-bios/s390-netboot.img | Bin 83776 -> 83856 bytes target/s390x/helper.c | 10 ++-- target/s390x/kvm.c | 2 + target/s390x/mmu_helper.c | 2 +- 9 files changed, 111 insertions(+), 39 deletions(-)
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 1/8] s390x/kvm: call cpu_synchronize_state() on every kvm_arch_handle_exit()
From: David Hildenbrand <[email protected]>
Manually having to use cpu_synchronize_state() is error prone. And as Christian Borntraeger discovered, e.g. handle_diag() is currently missing a cpu_synchronize_state(), as decode_basedisp_s() uses a general purpose register value internally.
So let's do an overall cpu_synchronize_state(), which fixes at least the one mentioned BUG. We will clean up the superfluous cpu_synchronize_state() calls later.
We now also call it (although maybe not neded) for
- KVM_EXIT_S390_RESET -> s390_reipl_request()
- KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit()
- unmanagable/unimplemented intercepts
- ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted
- Scenarios where we inject an operation exception
- handle_stsi()
I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels.
Message-Id: <[email protected]>
--- target/s390x/kvm.c | 2 ++ 1 file changed, 2 insertions(+)
target/s390x/kvm.c +2 -0
@@ -1778,6 +1778,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)qemu_mutex_lock_iothread (); +cpu_synchronize_state (cs); +switch (run->exit_reason) {case KVM_EXIT_S390_SIEIC : ret =handle_intercept (cpu);
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 2/8] s390: Refactor IPL parameter block generation
In reply to Cornelia HuckFrom: Viktor Mihajlovski <[email protected]>
Splitting out the the CCW device extraction allows reuse.
Message-Id: <[email protected]>
--- hw/s390x/ipl.c | 81 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 30 deletions(-)
hw/s390x/ipl.c +51 -30
@@ -279,44 +279,52 @@ static void s390_ipl_set_boot_menu(S390IPLState *ipl) *timeout =cpu_to_be32 (splash_time); } +static CcwDevice *s390_get_ccw_device (DeviceState *dev_st) +{ +CcwDevice *ccw_dev =NULL ; + +if (dev_st) { +VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *) +object_dynamic_cast (OBJECT (qdev_get_parent_bus (dev_st)->parent), +TYPE_VIRTIO_CCW_DEVICE ); +if (virtio_ccw_dev) { + ccw_dev =CCW_DEVICE (virtio_ccw_dev); + }else { +SCSIDevice *sd = (SCSIDevice *) +object_dynamic_cast (OBJECT (dev_st), +TYPE_SCSI_DEVICE ); +if (sd) { +SCSIBus *bus =scsi_bus_from_device (sd); +VirtIOSCSI *vdev =container_of (bus, VirtIOSCSI, bus); +VirtIOSCSICcw *scsi_ccw =container_of (vdev, VirtIOSCSICcw, + vdev); + + ccw_dev = (CcwDevice *)object_dynamic_cast (OBJECT (scsi_ccw), +TYPE_CCW_DEVICE ); + } + } + } +return ccw_dev; +} +static bool s390_gen_initial_iplb (S390IPLState *ipl) {DeviceState *dev_st; +CcwDevice *ccw_dev =NULL ; dev_st =get_boot_device (0 );if (dev_st) { -VirtioCcwDevice *virtio_ccw_dev = (VirtioCcwDevice *) -object_dynamic_cast (OBJECT (qdev_get_parent_bus (dev_st)->parent), -TYPE_VIRTIO_CCW_DEVICE ); + ccw_dev =s390_get_ccw_device (dev_st); + } + +/* +* Currently allow IPL only from CCW devices. +*/ +if (ccw_dev) {SCSIDevice *sd = (SCSIDevice *)object_dynamic_cast (OBJECT (dev_st),TYPE_SCSI_DEVICE ); -VirtIONet *vn = (VirtIONet *)object_dynamic_cast (OBJECT (dev_st), -TYPE_VIRTIO_NET ); - -if (vn) { - ipl->netboot = true; - } -if (virtio_ccw_dev) { -CcwDevice *ccw_dev =CCW_DEVICE (virtio_ccw_dev); - - ipl->iplb.len =cpu_to_be32 (S390_IPLB_MIN_CCW_LEN ); - ipl->iplb.blk0_len = -cpu_to_be32 (S390_IPLB_MIN_CCW_LEN -S390_IPLB_HEADER_LEN ); - ipl->iplb.pbt =S390_IPL_TYPE_CCW ; - ipl->iplb.ccw.devno =cpu_to_be16 (ccw_dev->sch->devno); - ipl->iplb.ccw.ssid = ccw_dev->sch->ssid &3 ; - }else if (sd) { -SCSIBus *bus =scsi_bus_from_device (sd); -VirtIOSCSI *vdev =container_of (bus, VirtIOSCSI, bus); -VirtIOSCSICcw *scsi_ccw =container_of (vdev, VirtIOSCSICcw, vdev); -CcwDevice *ccw_dev; - - ccw_dev = (CcwDevice *)object_dynamic_cast (OBJECT (scsi_ccw), -TYPE_CCW_DEVICE ); -if (!ccw_dev) {/* It might be a PCI device instead */ -return false; - } +if (sd) { ipl->iplb.len =cpu_to_be32 (S390_IPLB_MIN_QEMU_SCSI_LEN ); ipl->iplb.blk0_len =cpu_to_be32 (S390_IPLB_MIN_QEMU_SCSI_LEN -S390_IPLB_HEADER_LEN );
@@ -327,12 +335,25 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) ipl->iplb.scsi.devno =cpu_to_be16 (ccw_dev->sch->devno); ipl->iplb.scsi.ssid = ccw_dev->sch->ssid &3 ; }else { -return false;/* unknown device */ +VirtIONet *vn = (VirtIONet *)object_dynamic_cast (OBJECT (dev_st), +TYPE_VIRTIO_NET ); + + ipl->iplb.len =cpu_to_be32 (S390_IPLB_MIN_CCW_LEN ); + ipl->iplb.blk0_len = +cpu_to_be32 (S390_IPLB_MIN_CCW_LEN -S390_IPLB_HEADER_LEN ); + ipl->iplb.pbt =S390_IPL_TYPE_CCW ; + ipl->iplb.ccw.devno =cpu_to_be16 (ccw_dev->sch->devno); + ipl->iplb.ccw.ssid = ccw_dev->sch->ssid &3 ; + +if (vn) { + ipl->netboot = true; + } }if (!s390_ipl_set_loadparm (ipl->iplb.loadparm)) { ipl->iplb.flags |=DIAG308_FLAGS_LP_VALID ; } +return true; }
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 3/8] s390: Ensure IPL from SCSI works as expected
In reply to Cornelia HuckFrom: Viktor Mihajlovski <[email protected]>
Operating systems may request an IPL from a virtio-scsi device by specifying an IPL parameter type of CCW. In this case QEMU won't set up the IPLB correctly. The BIOS will still detect it's a SCSI device to boot from, but it will now have to search for the first LUN and attempt to boot from there. However this may not be the original boot LUN if there's more than one SCSI disk attached to the HBA.
With this change QEMU will detect that the request is for a SCSI device and will rebuild the initial IPL parameter info if it's the SCSI device used for the first boot. In consequence the BIOS can use the boot LUN from the IPL information block.
In case a different SCSI device has been set, the BIOS will find and use the first available LUN.
Message-Id: <[email protected]>
--- hw/s390x/ipl.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
hw/s390x/ipl.c +29 -2
@@ -427,7 +427,8 @@ unref_mr:return img_size; } -static bool is_virtio_net_device (IplParameterBlock *iplb) +static bool is_virtio_ccw_device_of_type (IplParameterBlock *iplb, +int virtio_id) {uint8_t cssid;uint8_t ssid;
@@ -447,13 +448,23 @@ static bool is_virtio_net_device(IplParameterBlock *iplb) sch =css_find_subch (1 , cssid, ssid, schid);if (sch && sch->devno == devno) { -return sch->id.cu_model ==VIRTIO_ID_NET ; +return sch->id.cu_model == virtio_id; } } }return false; } +static bool is_virtio_net_device (IplParameterBlock *iplb) +{ +return is_virtio_ccw_device_of_type (iplb,VIRTIO_ID_NET ); +} + +static bool is_virtio_scsi_device (IplParameterBlock *iplb) +{ +return is_virtio_ccw_device_of_type (iplb,VIRTIO_ID_SCSI ); +} +void s390_ipl_update_diag308 (IplParameterBlock *iplb) {S390IPLState *ipl =get_ipl_device ();
@@ -478,6 +489,22 @@ void s390_reipl_request(void)S390IPLState *ipl =get_ipl_device (); ipl->reipl_requested = true; +if (ipl->iplb_valid && + !ipl->netboot && + ipl->iplb.pbt ==S390_IPL_TYPE_CCW && +is_virtio_scsi_device (&ipl->iplb)) { +CcwDevice *ccw_dev =s390_get_ccw_device (get_boot_device (0 )); + +if (ccw_dev && +cpu_to_be16 (ccw_dev->sch->devno) == ipl->iplb.ccw.devno && + (ccw_dev->sch->ssid &3 ) == ipl->iplb.ccw.ssid) { +/* +* this is the original boot device's SCSI +* so restore IPL parameter info from it +*/ + ipl->iplb_valid =s390_gen_initial_iplb (ipl); + } + }qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); }
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 4/8] s390: Do not pass inofficial IPL type to the guest
In reply to Cornelia HuckFrom: Viktor Mihajlovski <[email protected]>
IPL over a virtio-scsi device requires special handling not available in the real architecture. For this purpose the IPL type 0xFF has been chosen as means of communication between QEMU and the pc-bios. However, a guest OS could be confused by seeing an unknown IPL type.
This change sets the IPL parameter type to 0x02 (CCW) to prevent this. Pre-existing Linux has looked up the IPL parameters only in the case of FCP IPL. This means that the behavior should stay the same even if Linux checks for the IPL type unconditionally.
Message-Id: <[email protected]>
--- pc-bios/s390-ccw/bootmap.c | 7 +++++++ pc-bios/s390-ccw/iplb.h | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-)
pc-bios/s390-ccw/bootmap.c +7 -0
@@ -70,6 +70,13 @@ static void jump_to_IPL_code(uint64_t address) {/* store the subsystem information _after_ the bootmap was loaded */ write_subsystem_identification (); + +/* prevent unknown IPL types in the guest */ +if (iplb.pbt ==S390_IPL_TYPE_QEMU_SCSI ) { + iplb.pbt =S390_IPL_TYPE_CCW ; +set_iplb (&iplb); + } +/* * The IPL PSW is at address 0. We also must not overwrite the * content of non-BIOS memory after we loaded the guest, so we
pc-bios/s390-ccw/iplb.h +13 -2
@@ -97,16 +97,27 @@ extern QemuIplParameters qipl;#define S390_IPL_TYPE_CCW 0x02#define S390_IPL_TYPE_QEMU_SCSI 0xff -static inline bool store_iplb (IplParameterBlock *iplb) +static inline bool manage_iplb (IplParameterBlock *iplb,bool store) { register unsigned long addr asm("0") = (unsigned long) iplb; register unsigned long rc asm("1") = 0; asmvolatile ("diag %0,%2,0x308\n" :"+d" (addr),"+d" (rc) - :"d" (6 ) + :"d" (store ?6 :5 ) :"memory" ,"cc" );return rc ==0x01 ; } + +static inline bool store_iplb (IplParameterBlock *iplb) +{ +return manage_iplb (iplb, true); +} + +static inline bool set_iplb (IplParameterBlock *iplb) +{ +return manage_iplb (iplb, false); +} +#endif /* IPLB_H */
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 6/8] vfio-ccw: fix memory leaks in vfio_ccw_realize()
In reply to Cornelia HuckFrom: Greg Kurz <[email protected]>
If the subchannel is already attached or if vfio_get_device() fails, the code jumps to the 'out_device_err' label and doesn't free the string it has just allocated.
The code should be reworked so that vcdev->vdev.name only gets set when the device has been attached, and freed when it is about to be detached. This could be achieved with the addition of a vfio_ccw_get_device() function that would be the counterpart of vfio_put_device(). But this is a more elaborate cleanup that should be done in a follow-up. For now, let's just add calls to g_free() on the buggy error paths.
Message-Id: <152311222681.203086.8874800175539040298.stgit@bahia>
--- hw/vfio/ccw.c | 2 ++ 1 file changed, 2 insertions(+)
hw/vfio/ccw.c +2 -0
@@ -357,11 +357,13 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)if (strcmp (vbasedev->name, vcdev->vdev.name) ==0 ) {error_setg (&err,"vfio: subchannel %s has already been attached" , vcdev->vdev.name); +g_free (vcdev->vdev.name); goto out_device_err; } }if (vfio_get_device (group, cdev->mdevid, &vcdev->vdev, &err)) { +g_free (vcdev->vdev.name); goto out_device_err; }
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 7/8] s390x/mmu: don't overwrite pending exception in mmu translate
In reply to Cornelia HuckFrom: David Hildenbrand <[email protected]>
If we already triggered another exception, don't overwrite it with a protection exception.
Only applies to old KVM instances without the virtual memory access IOCTL in KVM.
Message-Id: <[email protected]>
--- target/s390x/mmu_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/mmu_helper.c +1 -1
@@ -325,7 +325,7 @@ static int mmu_translate_asce(CPUS390XState *env, target_ulong vaddr, r =mmu_translate_region (env, vaddr, asc, asce, level, raddr, flags, rw, exc); -if (rw ==MMU_DATA_STORE && !(*flags &PAGE_WRITE )) { +if (!r && rw ==MMU_DATA_STORE && !(*flags &PAGE_WRITE )) {trigger_prot_fault (env, vaddr, asc, rw, exc);return -1 ; }
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 8/8] s390x: load_psw() should only exchange the PSW for KVM
In reply to Cornelia HuckFrom: David Hildenbrand <[email protected]>
Let's simplify it a bit. On some weird circumstances we would have tried to recompute watchpoints when running under KVM. load_psw() is called from do_restart_interrupt() during a SIGP RESTART if the target CPU is STOPPED. Let's touch watchpoints only in the TCG case - where they are used for PER emulation.
Message-Id: <[email protected]>
--- target/s390x/helper.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
target/s390x/helper.c +6 -4
@@ -103,16 +103,18 @@ void load_psw(CPUS390XState *env, uint64_t mask, uint64_t addr) env->psw.addr = addr; env->psw.mask = mask; -if (tcg_enabled ()) { - env->cc_op = (mask >>44 ) &3 ; + +/* KVM will handle all WAITs and trigger a WAIT exit on disabled_wait */ +if (!tcg_enabled ()) { +return ; } + env->cc_op = (mask >>44 ) &3 ;if ((old_mask ^ mask) &PSW_MASK_PER ) {s390_cpu_recompute_watchpoints (CPU (s390_env_get_cpu (env))); } -/* KVM will handle all WAITs and trigger a WAIT exit on disabled_wait */ -if (tcg_enabled () && (mask &PSW_MASK_WAIT )) { +if (mask &PSW_MASK_WAIT ) {s390_handle_wait (s390_env_get_cpu (env)); } }
Signature · 1 line
2.14.3
[Qemu-devel] [PULL for-2.12 5/8] pc-bios/s390: update images
In reply to Cornelia HuckContains the following commits:
- s390: Do not pass inofficial IPL type to the guest
For s390-netboot.img, this also contains the following commits (update was forgotten last time):
- pc-bios/s390-ccw: Move string arrays from bootmap header to .c file
- pc-bios/s390-ccw: Increase virtio timeout to 30 seconds
--- pc-bios/s390-ccw.img | Bin 30568 -> 30520 bytes pc-bios/s390-netboot.img | Bin 83776 -> 83856 bytes 2 files changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
pc-bios/s390-netboot.img binary +0 -0
Signature · 1 line
2.14.3
Peter Maydell
AppliedQuoted 10 lines · Cornelia Huck
The following changes since commit
2a6bcfdebe4115993a032395d459f5e0cf27a01e:Merge remote-tracking branch 'remotes/famz/tags/testing-pull-request' into staging (2018-04-09 10:21:14 +0100)
are available in the Git repository at:
git://github.com/cohuck/qemutags/s390x-20180409for you to fetch changes up to
b3a184f51fbed3401694a9619e6842f882a64fee:
Quoted 7 lines
s390x:
load_psw()should only exchange the PSW for KVM (2018-04-09 13:59:06 +0200)----------------------------------------------------------------
Fixes for s390x: kvm, vfio-ccw, ipl code, bios. Includes a rebuild of s390-ccw.img and s390-netboot.img.----------------------------------------------------------------
Applied, thanks.
-- PMM