next patches for s390x/kvm
Peter,
The following changes since commit 25930ed60aad49f1fdd7de05272317c86ce1275b:
Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2016-09-27 23:10:12 +0100)
are available in the git repository at:
git://github.com/borntraeger/qemu.git tags/s390x-20160927
for you to fetch changes up to 794afd7096f1ef3ea632b5cf75998562a2f8029a:
s390x/kvm: fix build against qemu_uuid (2016-09-28 13:24:51 +0200)
----------------------------------------------------------------
Couple of s390x patches:
- some PCI cleanups
- fix build error due to uuid rework
- fix potential deadlock in sigp handling
- enable ccw devices in BIOS and enforce checking in QEMU
----------------------------------------------------------------
Christian Borntraeger (3):
s390x/kvm: Fix potential deadlock in sigp handling
pc-bios/s390-ccw.img: rebuild image
s390x/kvm: fix build against qemu_uuidDong Jia Shi (1):
pc-bios/s390-ccw: enable subchannel for IPL I/O devices
Pierre Morel (1):
s390x/pci: re-arrange variable declarations
Sascha Silbe (1):
s390x/css: {c,h,t,r,x}sch: require enable AND device number validYi Min Zhao (2):
s390x/pci: assign msix io region for each pci device
s390x/pci: code cleanuphw/s390x/css.c | 12 ++++++------ hw/s390x/s390-pci-bus.c | 48 +++++++++++++++++++++++++--------------------- hw/s390x/s390-pci-bus.h | 4 ++-- hw/s390x/s390-pci-inst.c | 6 ++++-- pc-bios/s390-ccw.img | Bin 26440 -> 26392 bytes pc-bios/s390-ccw/virtio.c | 3 ++- target-s390x/kvm.c | 13 ++++++++++++- 7 files changed, 52 insertions(+), 34 deletions(-)
[Qemu-devel] [PULL 1/8] s390x/pci: re-arrange variable declarations
From: Pierre Morel <[email protected]>
Pull mr variable declarations at the top of the functions instead of mixing them up with the code. This is in preparation for followup patches.
--- hw/s390x/s390-pci-inst.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
hw/s390x/s390-pci-inst.c +4 -2
@@ -315,6 +315,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)S390PCIBusDevice *pbdev;uint64_t offset;uint64_t data; +MemoryRegion *mr;uint8_t len;uint32_t fh;uint8_t pcias;
@@ -363,7 +364,7 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)program_interrupt (env,PGM_OPERAND ,4 );return 0 ; } -MemoryRegion *mr = pbdev->pdev->io_regions[pcias].memory; + mr = pbdev->pdev->io_regions[pcias].memory;memory_region_dispatch_read (mr, offset, &data, len,MEMTXATTRS_UNSPECIFIED ); }else if (pcias ==15 ) {
@@ -442,6 +443,7 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)CPUS390XState *env = &cpu->env;uint64_t offset, data;S390PCIBusDevice *pbdev; +MemoryRegion *mr;uint8_t len;uint32_t fh;uint8_t pcias;
@@ -491,7 +493,7 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8_t r2)program_interrupt (env,PGM_OPERAND ,4 );return 0 ; } -MemoryRegion *mr; +if (trap_msix (pbdev, offset, pcias)) { offset = offset - pbdev->msix.table_offset; mr = &pbdev->pdev->msix_table_mmio;
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 4/8] s390x/kvm: Fix potential deadlock in sigp handling
In reply to Christian BorntraegerIf two VCPUs exit at the same time and target each other with a sigp, both could run into a deadlock as run_on_cpu on CPU0 will free the BQL when starting the CPU1 target routine. CPU1 will run its sigp initiater for CPU0 before handling the run_on_cpu requests, thus resulting in a dead lock.
As all qemu SIGPs are slow path anway we can use a big sigp lock and allow only one SIGP for the guest at a time. We will return condition code 2 (BUSY) on contention to the guest.
--- target-s390x/kvm.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target-s390x/kvm.c +11 -0
@@ -132,6 +132,8 @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { KVM_CAP_LAST_INFO }; +static QemuMutex qemu_sigp_mutex; +static int cap_sync_regs;static int cap_async_pf;static int cap_mem_op;
@@ -287,6 +289,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } +qemu_mutex_init (&qemu_sigp_mutex); +return 0 ; }
@@ -1774,6 +1778,11 @@ static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1) status_reg = &env->regs[r1]; param = (r1 %2 ) ? env->regs[r1] : env->regs[r1 +1 ]; +if (qemu_mutex_trylock (&qemu_sigp_mutex)) { + ret =SIGP_CC_BUSY ; + goto out; + } +switch (order) {case SIGP_SET_ARCH : ret =sigp_set_architecture (cpu, param, status_reg);
@@ -1783,7 +1792,9 @@ static int handle_sigp(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1) dst_cpu =s390_cpu_addr2state (env->regs[r3]); ret =handle_sigp_single_dst (dst_cpu, order, param, status_reg); } +qemu_mutex_unlock (&qemu_sigp_mutex); +out:trace_kvm_sigp_finished (order,CPU (cpu)->cpu_index, dst_cpu ?CPU (dst_cpu)->cpu_index :-1 , ret);
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 5/8] pc-bios/s390-ccw: enable subchannel for IPL I/O devices
In reply to Christian BorntraegerFrom: Dong Jia Shi <[email protected]>
IPL should cause the IPL I/O device to become enabled. So when handling the IPL program, we should set the E (Enable) bit. However, virtio-ccw does not know whether it's dealing with an IPL device or not. Since trying to perform I/O on a disabled device doesn't make any sense, let's just always enable it. At the same time we can remove the SCSW_FCTL_START_FUNC flag as it is ignored for msch anyway and did not enable the device as intended.
--- pc-bios/s390-ccw/virtio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
pc-bios/s390-ccw/virtio.c +2 -1
@@ -97,7 +97,8 @@ static int run_ccw(VDev *vdev, int cmd, void *ptr, int len)/* start command processing */ stsch_err (vdev->schid, &schib); - schib.scsw.ctrl =SCSW_FCTL_START_FUNC ; +/* enable the subchannel for IPL device */ + schib.pmcw.ena =1 ;msch (vdev->schid, &schib);/* start subchannel command */
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 8/8] s390x/kvm: fix build against qemu_uuid
In reply to Christian Borntraegercommit 9c5ce8db2e5c ("vl: Switch qemu_uuid to QemuUUID") changed most users of qemu_uuid but not all. Fix a build error on s390/kvm.
--- target-s390x/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-s390x/kvm.c +1 -1
@@ -1999,7 +1999,7 @@ static void insert_stsi_3_2_2(S390CPU *cpu, __u64 addr, uint8_t ar)strcpy ((char *)sysib.ext_names[0 ],"KVMguest" ); }/* Insert UUID */ -memcpy (sysib.vm[0 ].uuid, qemu_uuid,sizeof (sysib.vm[0 ].uuid)); +memcpy (sysib.vm[0 ].uuid, &qemu_uuid,sizeof (sysib.vm[0 ].uuid));s390_cpu_virt_mem_write (cpu, addr, ar, &sysib,sizeof (sysib)); }
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 3/8] s390x/pci: code cleanup
In reply to Christian BorntraegerFrom: Yi Min Zhao <[email protected]>
Now that each S390 PCI device uses an IO region as MSIX region. The code in s390_translate_iommu() will never be triggered. Let's remove it.
--- hw/s390x/s390-pci-bus.c | 11 ----------- 1 file changed, 11 deletions(-)
hw/s390x/s390-pci-bus.c +0 -11
@@ -404,17 +404,6 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr,DPRINTF ("iommu trans addr 0x%" PRIx64"\n" , addr); -/* s390 does not have an APIC mapped to main storage so we use -* a separate AddressSpace only for msix notifications -*/ -if (addr ==ZPCI_MSI_ADDR ) { - ret.iova = addr; - ret.translated_addr = addr; - ret.addr_mask =0xfff ; - ret.perm =IOMMU_RW ; -return ret; - } -if (addr < pbdev->pba || addr > pbdev->pal) {return ret; }
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 7/8] s390x/css: {c, h, t, r, x}sch: require enable AND device number valid
In reply to Christian BorntraegerFrom: Sascha Silbe <[email protected]>
According to the PoP, subchannels are only considered operational if they are enabled _and_ the device number is valid. With the current checks being enabled _or_ having a valid device number was sufficient. This caused qemu to allow IO on subchannels that were not enabled.
Fix the checks to require both bits to be set.
--- hw/s390x/css.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
hw/s390x/css.c +6 -6
@@ -775,7 +775,7 @@ int css_do_xsch(SubchDev *sch)PMCW *p = &sch->curr_status.pmcw;int ret; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) { ret = -ENODEV ; goto out; }
@@ -815,7 +815,7 @@ int css_do_csch(SubchDev *sch)PMCW *p = &sch->curr_status.pmcw;int ret; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) { ret = -ENODEV ; goto out; }
@@ -837,7 +837,7 @@ int css_do_hsch(SubchDev *sch)PMCW *p = &sch->curr_status.pmcw;int ret; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) { ret = -ENODEV ; goto out; }
@@ -913,7 +913,7 @@ int css_do_ssch(SubchDev *sch, ORB *orb)PMCW *p = &sch->curr_status.pmcw;int ret; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) { ret = -ENODEV ; goto out; }
@@ -990,7 +990,7 @@ int css_do_tsch_get_irb(SubchDev *sch, IRB *target_irb, int *irb_len)uint16_t stctl;IRB irb; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) {return 3 ; }
@@ -1196,7 +1196,7 @@ int css_do_rsch(SubchDev *sch)PMCW *p = &sch->curr_status.pmcw;int ret; -if (!(p->flags & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA ))) { +if (~(p->flags) & (PMCW_FLAGS_MASK_DNV |PMCW_FLAGS_MASK_ENA )) { ret = -ENODEV ; goto out; }
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 6/8] pc-bios/s390-ccw.img: rebuild image
In reply to Christian BorntraegerContains:
- pc-bios/s390-ccw: enable subchannel for IPL I/O devices
--- pc-bios/s390-ccw.img | Bin 26440 -> 26392 bytes 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
Signature · 1 line
2.5.5
[Qemu-devel] [PULL 2/8] s390x/pci: assign msix io region for each pci device
In reply to Christian BorntraegerFrom: Yi Min Zhao <[email protected]>
For efficiency we now assign one msix io region for each pci device and provide it with the pointer to the zPCI device as opaque parameter. In addition, we remove msix address space and add msix io region as a subregion to the root memory region of pci device.
--- hw/s390x/s390-pci-bus.c | 37 ++++++++++++++++++++++++++----------- hw/s390x/s390-pci-bus.h | 4 ++-- 2 files changed, 28 insertions(+), 13 deletions(-)
hw/s390x/s390-pci-bus.c +26 -11
@@ -383,7 +383,6 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr,uint64_t pte;uint32_t flags;S390PCIBusDevice *pbdev =container_of (iommu, S390PCIBusDevice, iommu_mr); -S390pciState *s;IOMMUTLBEntry ret = { .target_as = &address_space_memory, .iova =0 ,
@@ -405,12 +404,10 @@ static IOMMUTLBEntry s390_translate_iommu(MemoryRegion *iommu, hwaddr addr,DPRINTF ("iommu trans addr 0x%" PRIx64"\n" , addr); - s =S390_PCI_HOST_BRIDGE (pci_device_root_bus (pbdev->pdev)->qbus.parent);/* s390 does not have an APIC mapped to main storage so we use * a separate AddressSpace only for msix notifications */ if (addr ==ZPCI_MSI_ADDR ) { - ret.target_as = &s->msix_notify_as; ret.iova = addr; ret.translated_addr = addr; ret.addr_mask =0xfff ;
@@ -476,7 +473,7 @@ static uint8_t set_ind_atomic(uint64_t ind_loc, uint8_t to_be_set)static void s390_msi_ctrl_write (void *opaque,hwaddr addr,uint64_t data,unsigned int size) { -S390PCIBusDevice *pbdev; +S390PCIBusDevice *pbdev = opaque;uint32_t io_int_word;uint32_t idx = data >>ZPCI_MSI_VEC_BITS ;uint32_t vec = data &ZPCI_MSI_VEC_MASK ;
@@ -486,7 +483,6 @@ static void s390_msi_ctrl_write(void *opaque, hwaddr addr, uint64_t data,DPRINTF ("write_msix data 0x%" PRIx64" idx %d vec 0x%x\n" , data, idx, vec); - pbdev =s390_pci_find_dev_by_idx (idx);if (!pbdev) { e |= (vec <<ERR_EVENT_MVN_OFFSET );s390_pci_generate_error_event (ERR_EVENT_NOMSI , idx,0 , addr, e);
@@ -548,10 +544,6 @@ static void s390_pcihost_init_as(S390pciState *s) s->iommu[i] = iommu; } - -memory_region_init_io (&s->msix_notify_mr,OBJECT (s), - &s390_msi_ctrl_ops, s,"msix-s390" ,UINT64_MAX ); -address_space_init (&s->msix_notify_as, &s->msix_notify_mr,"msix-pci" ); }static int s390_pcihost_init (SysBusDevice *dev)
@@ -581,7 +573,7 @@ static int s390_pcihost_init(SysBusDevice *dev)return 0 ; } -static int s390_pcihost_setup_msix (S390PCIBusDevice *pbdev) +static int s390_pci_setup_msix (S390PCIBusDevice *pbdev) {uint8_t pos;uint16_t ctrl;
@@ -609,6 +601,26 @@ static int s390_pcihost_setup_msix(S390PCIBusDevice *pbdev)return 0 ; } +static void s390_pci_msix_init (S390PCIBusDevice *pbdev) +{ +char *name; + + name =g_strdup_printf ("msix-s390-%04x" , pbdev->uid); + +memory_region_init_io (&pbdev->msix_notify_mr,OBJECT (pbdev), + &s390_msi_ctrl_ops, pbdev, name,PAGE_SIZE ); +memory_region_add_subregion (&pbdev->iommu->mr,ZPCI_MSI_ADDR , + &pbdev->msix_notify_mr); + +g_free (name); +} + +static void s390_pci_msix_free (S390PCIBusDevice *pbdev) +{ +memory_region_del_subregion (&pbdev->iommu->mr, &pbdev->msix_notify_mr); +object_unparent (OBJECT (&pbdev->msix_notify_mr)); +} +static S390PCIBusDevice *s390_pci_device_new (const char *target) {DeviceState *dev =NULL ;
@@ -662,7 +674,9 @@ static void s390_pcihost_hot_plug(HotplugHandler *hotplug_dev, pbdev->pdev = pdev; pbdev->iommu = s->iommu[PCI_SLOT (pdev->devfn)]; pbdev->state =ZPCI_FS_STANDBY ; -s390_pcihost_setup_msix (pbdev); + +s390_pci_msix_init (pbdev); +s390_pci_setup_msix (pbdev);if (dev->hotplugged) { s390_pci_generate_plug_event(HP_EVENT_RESERVED_TO_STANDBY,
@@ -749,6 +763,7 @@ static void s390_pcihost_hot_unplug(HotplugHandler *hotplug_dev,s390_pci_generate_plug_event (HP_EVENT_STANDBY_TO_RESERVED , pbdev->fh, pbdev->fid);object_unparent (OBJECT (pci_dev)); +s390_pci_msix_free (pbdev); pbdev->pdev =NULL ; pbdev->state =ZPCI_FS_RESERVED ; out:
hw/s390x/s390-pci-bus.h +2 -2
@@ -82,6 +82,7 @@#define ZPCI_EDMA_ADDR 0x1ffffffffffffffULL#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT)#define PAGE_MASK (~(PAGE_SIZE-1))#define PAGE_DEFAULT_ACC 0#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4)
@@ -283,6 +284,7 @@ typedef struct S390PCIBusDevice {AdapterRoutes routes;S390PCIIOMMU *iommu;MemoryRegion iommu_mr; +MemoryRegion msix_notify_mr;IndAddr *summary_ind;IndAddr *indicator;QEMUTimer *release_timer;
@@ -297,8 +299,6 @@ typedef struct S390pciState {S390PCIBus *bus;S390PCIBusDevice *pbdev[PCI_SLOT_MAX ];S390PCIIOMMU *iommu[PCI_SLOT_MAX ]; -AddressSpace msix_notify_as; -MemoryRegion msix_notify_mr; QTAILQ_HEAD(, SeiContainer) pending_sei; } S390pciState;
Signature · 1 line
2.5.5
Peter Maydell
AppliedQuoted 12 lines · Christian Borntraeger
Peter,
The following changes since commit
25930ed60aad49f1fdd7de05272317c86ce1275b:Merge remote-tracking branch 'remotes/ehabkost/tags/x86-pull-request' into staging (2016-09-27 23:10:12 +0100)
are available in the git repository at:
git://github.com/borntraeger/qemu.gittags/s390x-20160927for you to fetch changes up to
794afd7096f1ef3ea632b5cf75998562a2f8029a:
Quoted 8 lines
s390x/kvm: fix build against
qemu_uuid(2016-09-28 13:24:51 +0200)----------------------------------------------------------------
Couple of s390x patches:
- some PCI cleanups
- fix build error due to uuid rework
- fix potential deadlock in sigp handling
- enable ccw devices in BIOS and enforce checking in QEMU
Applied, thanks.
-- PMM