add PCI support for the s390 platform
cover add PCI support for the s390 platform
This set of patches implemets PCI support for the s390 platform. Now it is possible to run virtio-net-pci and potentially all virtual pci devices conforming to s390 platform constrains. (In parallel I also post some changes to make vfio run on s390)
I hope to get feedback and guidance especially for
kvm: extend kvm_irqchip_add_msi_route to work on s390
which adds the s390 interpretation of MSI-X to the common kvm add_msi_route functionality.
Thx for any help,
Frank
Frank Blaschka (3):
s390: Add PCI bus support
s390: implement pci instructions
kvm: extend kvm_irqchip_add_msi_route to work on s390
default-configs/s390x-softmmu.mak | 1 + hw/s390x/Makefile.objs | 1 + hw/s390x/css.c | 5 + hw/s390x/css.h | 1 + hw/s390x/s390-pci-bus.c | 447 +++++++++++++++++++++++ hw/s390x/s390-pci-bus.h | 252 +++++++++++++ hw/s390x/s390-virtio-ccw.c | 3 + hw/s390x/sclp.c | 10 +- include/hw/s390x/sclp.h | 8 + include/sysemu/kvm.h | 4 + kvm-all.c | 2 + target-arm/kvm.c | 5 + target-i386/kvm.c | 5 + target-mips/kvm.c | 5 + target-ppc/kvm.c | 5 + target-s390x/Makefile.objs | 2 +- target-s390x/cpu-models.h | 8 +- target-s390x/ioinst.c | 52 +++ target-s390x/ioinst.h | 1 + target-s390x/kvm.c | 77 ++++ target-s390x/pci_ic.c | 735 ++++++++++++++++++++++++++++++++++++++ target-s390x/pci_ic.h | 316 ++++++++++++++++ 22 files changed, 1942 insertions(+), 3 deletions(-) create mode 100644 hw/s390x/s390-pci-bus.c create mode 100644 hw/s390x/s390-pci-bus.h create mode 100644 target-s390x/pci_ic.c create mode 100644 target-s390x/pci_ic.h
Signature · 1 line
1.8.5.5
RFC PATCH 1/3 s390: Add PCI bus support
From: Frank Blaschka <[email protected]>
This patch implements a pci bus for s390x together with infrastructure to generate and handle hotplug events, to configure/unconfigure via sclp instruction, to do iommu translations and provide s390 support for MSI/MSI-X notification processing.
--- default-configs/s390x-softmmu.mak | 1 + hw/s390x/Makefile.objs | 1 + hw/s390x/css.c | 5 + hw/s390x/css.h | 1 + hw/s390x/s390-pci-bus.c | 447 ++++++++++++++++++++++++++++++++++++++ hw/s390x/s390-pci-bus.h | 252 +++++++++++++++++++++ hw/s390x/s390-virtio-ccw.c | 3 + hw/s390x/sclp.c | 10 +- include/hw/s390x/sclp.h | 8 + target-s390x/cpu-models.h | 8 +- target-s390x/ioinst.c | 52 +++++ target-s390x/ioinst.h | 1 + 12 files changed, 787 insertions(+), 2 deletions(-) create mode 100644 hw/s390x/s390-pci-bus.c create mode 100644 hw/s390x/s390-pci-bus.h
default-configs/s390x-softmmu.mak +1 -0
@@ -1,3 +1,4 @@ +include pci.mak CONFIG_VIRTIO=y CONFIG_SCLPCONSOLE=y CONFIG_S390_FLIC=y
hw/s390x/Makefile.objs +1 -0
@@ -8,4 +8,5 @@ obj-y += ipl.o obj-y += css.o obj-y += s390-virtio-ccw.o obj-y += virtio-ccw.o +obj-y += s390-pci-bus.o obj-$(CONFIG_S390_CONFIG) += config.o
hw/s390x/css.c +5 -0
@@ -1299,6 +1299,11 @@ void css_generate_chp_crws(uint8_t cssid, uint8_t chpid)/* TODO */ } +void css_generate_css_crws (uint8_t cssid) +{ +css_queue_crw (CRW_RSC_CSS ,0 ,0 ,0 ); +} +int css_enable_mcsse (void ) {trace_css_enable_facility ("mcsse" );
hw/s390x/css.h +1 -0
@@ -101,6 +101,7 @@ void css_queue_crw(uint8_t rsc, uint8_t erc, int chain, uint16_t rsid);void css_generate_sch_crws (uint8_t cssid,uint8_t ssid,uint16_t schid,int hotplugged,int add);void css_generate_chp_crws (uint8_t cssid,uint8_t chpid); +void css_generate_css_crws (uint8_t cssid);void css_adapter_interrupt (uint8_t isc);#define CSS_IO_ADAPTER_VIRTIO 1
hw/s390x/s390-pci-bus.c new file +447 -0
447 lines not on this page · raw message
hw/s390x/s390-pci-bus.h new file +252 -0
252 lines not on this page · raw message
hw/s390x/s390-virtio-ccw.c +3 -0
@@ -20,6 +20,7 @@#include "virtio-ccw.h" #include "qemu/config-file.h" #include "qemu/error-report.h" +#include "s390-pci-bus.h" #define TYPE_S390_CCW_MACHINE "s390-ccw-machine"
@@ -130,6 +131,8 @@ static void ccw_init(MachineState *machine)s390_config_dev_init (); +s390_pci_bus_init (); +s390_set_vm_name ();s390_set_cpu_model (machine->cpu_model);
hw/s390x/sclp.c +9 -1
@@ -20,6 +20,7 @@#include "qemu/config-file.h" #include "hw/s390x/sclp.h" #include "hw/s390x/event-facility.h" +#include "hw/s390x/s390-pci-bus.h" static inline SCLPEventFacility *get_event_facility (void ) {
@@ -62,7 +63,8 @@ static void read_SCP_info(SCCB *sccb) read_info->entries[i].type =0 ; } - read_info->facilities =cpu_to_be64 (SCLP_HAS_CPU_INFO ); + read_info->facilities =cpu_to_be64 (SCLP_HAS_CPU_INFO | +SCLP_HAS_PCI_RECONFIG );/* * The storage increment size is a multiple of 1M and is a power of 2.
@@ -350,6 +352,12 @@ static void sclp_execute(SCCB *sccb, uint32_t code)case SCLP_UNASSIGN_STORAGE :unassign_storage (sccb);break ; +case SCLP_CMDW_CONFIGURE_PCI : +s390_pci_sclp_configure (1 , sccb); +break ; +case SCLP_CMDW_DECONFIGURE_PCI : +s390_pci_sclp_configure (0 , sccb); +break ;default : efc->command_handler (ef, sccb, code);break ;
include/hw/s390x/sclp.h +8 -0
@@ -43,14 +43,22 @@#define SCLP_CMDW_CONFIGURE_CPU 0x00110001#define SCLP_CMDW_DECONFIGURE_CPU 0x00100001 +/* SCLP PCI codes */ +#define SCLP_HAS_PCI_RECONFIG 0x0000000040000000ULL +#define SCLP_CMDW_CONFIGURE_PCI 0x001a0001 +#define SCLP_CMDW_DECONFIGURE_PCI 0x001b0001 +#define SCLP_RECONFIG_PCI_ATPYE 2 +/* SCLP response codes */ #define SCLP_RC_NORMAL_READ_COMPLETION 0x0010#define SCLP_RC_NORMAL_COMPLETION 0x0020#define SCLP_RC_SCCB_BOUNDARY_VIOLATION 0x0100 +#define SCLP_RC_NO_ACTION_REQUIRED 0x0120#define SCLP_RC_INVALID_SCLP_COMMAND 0x01f0#define SCLP_RC_CONTAINED_EQUIPMENT_CHECK 0x0340#define SCLP_RC_INSUFFICIENT_SCCB_LENGTH 0x0300#define SCLP_RC_STANDBY_READ_COMPLETION 0x0410 +#define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED 0x09f0#define SCLP_RC_INVALID_FUNCTION 0x40f0#define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0#define SCLP_RC_INVALID_SELECTION_MASK 0x70f0
target-s390x/cpu-models.h +7 -1
@@ -192,6 +192,9 @@ typedef enum {FAC_RESET_REFERENCE_BITS_MULTIPLE =66 ,FAC_CPU_MEASUREMENT_COUNTER =67 ,FAC_CPU_MEASUREMENT_SAMPLING =68 , +FAC_ZPCI =69 , +FAC_ADAPTER_EVENT_NOTIFICATION =71 , +FAC_ADAPTER_INT_SUPPRESSION =72 ,FAC_TRANSACTIONAL_EXE =73 ,FAC_ACCESS_EXCEPTION_FS_INDICATION =75 , FAC_MESSAGE_SECURITY_ASSIST_3 = 76,
@@ -351,7 +354,10 @@ typedef enum {#define FAC1_CPU_S390_2827_GA1 \ (FAC1_CPU_S390_2817_GA2 \ | FAC_BIT(1, FAC_TRANSACTIONAL_EXE) \ - | FAC_BIT(1, FAC_ENHANCED_DAT_2)) + | FAC_BIT(1, FAC_ENHANCED_DAT_2) \ + | FAC_BIT(1, FAC_ZPCI) \ + | FAC_BIT(1, FAC_ADAPTER_EVENT_NOTIFICATION) \ + | FAC_BIT(1, FAC_ADAPTER_INT_SUPPRESSION))#define FAC0_CPU_S390_2827_GA2 FAC0_CPU_S390_2827_GA1#define FAC1_CPU_S390_2827_GA2 FAC1_CPU_S390_2827_GA1
target-s390x/ioinst.c +52 -0
76 lines not on this page · raw message
target-s390x/ioinst.h +1 -0
@@ -204,6 +204,7 @@ typedef struct CRW {#define CRW_RSC_SUBCH 0x3#define CRW_RSC_CHP 0x4 +#define CRW_RSC_CSS 0xb/* I/O interruption code */ typedef struct IOIntCode {
Signature · 1 line
1.8.5.5
RFC PATCH 2/3 s390: implement pci instructions
In reply to Frank BlaschkaFrom: Frank Blaschka <[email protected]>
This patch implements the s390 pci instructions in qemu. It allows to access and drive pci devices attached to the s390 pci bus. Because of platform constrains devices using IO BARs are not supported. Also a device has to support MSI/MSI-X to run on s390.
--- target-s390x/Makefile.objs | 2 +- target-s390x/kvm.c | 52 ++++ target-s390x/pci_ic.c | 735 +++++++++++++++++++++++++++++++++++++++++++++ target-s390x/pci_ic.h | 316 +++++++++++++++++++ 4 files changed, 1104 insertions(+), 1 deletion(-) create mode 100644 target-s390x/pci_ic.c create mode 100644 target-s390x/pci_ic.h
target-s390x/Makefile.objs +1 -1
@@ -3,4 +3,4 @@ obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o obj-y += gdbstub.o obj-y += cpu-models.o obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o -obj-$(CONFIG_KVM) += kvm.o +obj-$(CONFIG_KVM) += kvm.o pci_ic.o
target-s390x/kvm.c +52 -0
96 lines not on this page · raw message
target-s390x/pci_ic.c new file +735 -0
735 lines not on this page · raw message
target-s390x/pci_ic.h new file +316 -0
316 lines not on this page · raw message
Signature · 1 line
1.8.5.5
Re: [Qemu-devel] [PATCH 2/3 RFC] s390: implement pci instructions
Hi Frank,
Quoted 16 lines · On Wed, 22 Oct 2014 17:11:59 +0200 Frank Blaschka…
From: Frank Blaschka <[email protected]>
This patch implements the s390 pci instructions in qemu. It allows to access and drive pci devices attached to the s390 pci bus. Because of platform constrains devices using IO BARs are not supported. Also a device has to support MSI/MSI-X to run on s390.
Signed-off-by Frank Blaschka <[email protected]>--- target-s390x/Makefile.objs | 2 +- target-s390x/kvm.c | 52 ++++ target-s390x/pci_ic.c | 735 +++++++++++++++++++++++++++++++++++++++++++++ target-s390x/pci_ic.h | 316 +++++++++++++++++++ 4 files changed, 1104 insertions(+), 1 deletion(-) create mode 100644 target-s390x/pci_ic.c create mode 100644 target-s390x/pci_ic.h
...
Quoted 120 lines
target-s390x/pci_ic.c new file +114
-0@@ -0,0 +1,735 @@ +/* +* s390 PCI intercepts +* +* Copyright 2014 IBM Corp. +* Author(s): Frank Blaschka <[email protected]> +* Hong Bo Li <[email protected]> +* Yi Min Zhao <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at +* your option) any later version. See the COPYING file in the top-level +* directory. +*/ + +#include <sys/types.h> +#include <sys/ioctl.h> +#include <sys/mman.h> + +#include <linux/kvm.h> +#include <asm/ptrace.h> +#include <hw/pci/pci.h> +#include <hw/pci/pci_host.h> +#include <net/net.h> + +#include "qemu-common.h" +#include "qemu/timer.h" +#include "migration/qemu-file.h" +#include "sysemu/sysemu.h" +#include "sysemu/kvm.h" +#include "cpu.h" +#include "sysemu/device_tree.h" +#include "monitor/monitor.h" +#include "pci_ic.h" + +#include "hw/hw.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci_host.h" +#include "hw/s390x/s390-pci-bus.h" +#include "exec/exec-all.h" +#include "exec/memory-internal.h" + +/* #define DEBUG_S390PCI_IC */ +#ifdef DEBUG_S390PCI_IC +#define DPRINTF (fmt, ...) \ + do { fprintf(stderr, "s390pci_ic: " fmt, ## __VA_ARGS__); } while (0) +#else +#define DPRINTF (fmt, ...) \ + do { } while (0) +#endif + +static uint64_t resume_token; + +static uint8_t barsize (uint64_t size) +{ +uint64_t mask =1 ; +int i; + +if (!size) { +return 0 ; + } + +for (i =0 ; i <64 ; i++) { +if (size & mask) { +break ; + } + mask = (mask <<1 ); + } + +return i; +} + +static void s390_set_status_code (CPUS390XState *env, +uint8_t r,uint64_t status_code) +{ + env->regs[r] &= ~0xff000000 ; + env->regs[r] |= (status_code &0xff ) <<24 ; +} + +static int list_pci (ClpReqRspListPci *rrb,uint8_t *cc) +{ +S390PCIBusDevice *pbdev; +uint32_t res_code, initial_l2, g_l2, finish; +int rc, idx; + + rc =0 ; +if (be16_to_cpu (rrb->request.hdr.len) !=32 ) { + res_code =CLP_RC_LEN ; + rc = -EINVAL ; + goto out; + } + +if ((be32_to_cpu (rrb->request.fmt) &CLP_MASK_FMT ) !=0 ) { + res_code =CLP_RC_FMT ; + rc = -EINVAL ; + goto out; + } + +if ((be32_to_cpu (rrb->request.fmt) & ~CLP_MASK_FMT ) !=0 || + rrb->request.reserved1 !=0 || + rrb->request.reserved2 !=0 ) { + res_code =CLP_RC_RESNOT0 ; + rc = -EINVAL ; + goto out; + } + +if (be64_to_cpu (rrb->request.resume_token) ==0 ) { + resume_token =0 ; + }else if (be64_to_cpu (rrb->request.resume_token) != resume_token) { + res_code =CLP_RC_LISTPCI_BADRT ; + rc = -EINVAL ; + goto out; + } +
target-s390x/pci_ic.c line 124
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+if (be16_to_cpu (rrb->response.hdr.len) <48 ) { + res_code =CLP_RC_8K ; + rc = -EINVAL ; + goto out; + } + + initial_l2 =be16_to_cpu (rrb->response.hdr.len); +if ((initial_l2 -LIST_PCI_HDR_LEN ) %sizeof (ClpFhListEntry) + !=0 ) { + rc = -EINVAL ;
Don't you need to set res_code to a proper value here, too?
Quoted 39 lines
target-s390x/pci_ic.c new file +39
-0+ goto out; + } + + rrb->response.fmt =0 ; + rrb->response.reserved1 = rrb->response.reserved2 =0 ; + rrb->response.mdd =cpu_to_be32 (FH_VIRT ); + rrb->response.max_fn =cpu_to_be16 (PCI_MAX_FUNCTIONS ); + rrb->response.entry_size =sizeof (ClpFhListEntry); + finish =0 ; + idx = resume_token; + g_l2 =LIST_PCI_HDR_LEN ; +do { + pbdev =s390_pci_find_dev_by_idx (idx); +if (!pbdev) { + finish =1 ; +break ; + } + rrb->response.fh_list[idx - resume_token].device_id = +pci_get_word (pbdev->pdev->config +PCI_DEVICE_ID ); + rrb->response.fh_list[idx - resume_token].vendor_id = +pci_get_word (pbdev->pdev->config +PCI_VENDOR_ID ); + rrb->response.fh_list[idx - resume_token].config = +cpu_to_be32 (0x80000000 ); + rrb->response.fh_list[idx - resume_token].fid =cpu_to_be32 (pbdev->fid); + rrb->response.fh_list[idx - resume_token].fh =cpu_to_be32 (pbdev->fh); + + g_l2 +=sizeof (ClpFhListEntry); +DPRINTF ("g_l2 %d vendor id 0x%x device id 0x%x fid 0x%x fh 0x%x\n" , + g_l2, + rrb->response.fh_list[idx - resume_token].vendor_id, + rrb->response.fh_list[idx - resume_token].device_id, + rrb->response.fh_list[idx - resume_token].fid, + rrb->response.fh_list[idx - resume_token].fh); + idx++; + }while (g_l2 < initial_l2); + +if (finish ==1 ) { + resume_token =0 ; + }else {
target-s390x/pci_ic.c line 173
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+ resume_token = idx; + } + rrb->response.resume_token =cpu_to_be64 (resume_token); + rrb->response.hdr.len =cpu_to_be16 (g_l2); + rrb->response.hdr.rsp =cpu_to_be16 (CLP_RC_OK ); +out: +if (rc) { +DPRINTF ("list pci failed rc 0x%x\n" , rc); + rrb->response.hdr.rsp =cpu_to_be16 (res_code); + *cc =3 ;
Not sure, but I think the condition code is only set to 3 when no response has been generated ... so I think you could simply remove the cc magic from this function?
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+ } +return rc; +} + +int kvm_clp_service_call (S390CPU *cpu,struct kvm_run *run) +{ +ClpReqHdr *reqh; +ClpRspHdr *resh; +S390PCIBusDevice *pbdev; +uint32_t req_len;
target-s390x/pci_ic.c line 193
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+uint32_t res_len; +uint8_t *buffer; +uint8_t cc; +CPUS390XState *env = &cpu->env; +uint8_t r2 = (run->s390_sieic.ipb &0x000f0000 ) >>16 ; +int rc =0 ; +int i; + + buffer =g_malloc0 (4096 *2 ); +cpu_synchronize_state (CPU (cpu));
CLP is a priviledged function, too, so you should also check PSW_MASK_PSTATE here.
target-s390x/pci_ic.c line 203
Quoted 9 lines
target-s390x/pci_ic.c new file +9
-0+cpu_physical_memory_rw (env->regs[r2], buffer,sizeof (reqh),0 ); + reqh = (ClpReqHdr *)buffer; + req_len =be16_to_cpu (reqh->len); + +cpu_physical_memory_rw (env->regs[r2], buffer, req_len +sizeof (resh),0 ); + resh = (ClpRspHdr *)(buffer + req_len); + res_len =be16_to_cpu (resh->len); + +cpu_physical_memory_rw (env->regs[r2], buffer, req_len + res_len,0 );
Not sure, but do you really have to read the _response_ buffer here, too? I'd rather expect that the response area is only written to...
Anyway, you should do some sanity checks on req_len (and res_len) first, or the guest could use this to create a buffer overflow in the host.
Quoted 85 lines
target-s390x/pci_ic.c new file +85
-0+switch (reqh->cmd) { +case CLP_LIST_PCI : { +ClpReqRspListPci *rrb = (ClpReqRspListPci *)buffer; + rc =list_pci (rrb, &cc); +break ; + } +case CLP_SET_PCI_FN : { +ClpReqSetPci *reqsetpci = (ClpReqSetPci *)reqh; +ClpRspSetPci *ressetpci = (ClpRspSetPci *)resh; + + pbdev =s390_pci_find_dev_by_fh (be32_to_cpu (reqsetpci->fh)); +if (!pbdev) { + ressetpci->hdr.rsp =cpu_to_be16 (CLP_RC_SETPCIFN_FH ); + goto out; + } + +switch (reqsetpci->oc) { +case CLP_SET_ENABLE_PCI_FN : +if (pbdev->is_virt) { + pbdev->fh = pbdev->fh |1 <<ENABLE_BIT_OFFSET ; + ressetpci->fh =cpu_to_be32 (pbdev->fh); + ressetpci->hdr.rsp =cpu_to_be16 (CLP_RC_OK ); + }else { + pbdev->fh =be32_to_cpu (ressetpci->fh); + } +break ; +case CLP_SET_DISABLE_PCI_FN : +if (pbdev->is_virt) { + pbdev->fh = pbdev->fh & ~(1 <<ENABLE_BIT_OFFSET ); + ressetpci->fh =cpu_to_be32 (pbdev->fh); + ressetpci->hdr.rsp =cpu_to_be16 (CLP_RC_OK ); + }else { + pbdev->fh =be32_to_cpu (ressetpci->fh); + } +break ; +default : +DPRINTF ("unknown set pci command\n" ); + ressetpci->hdr.rsp =cpu_to_be16 (CLP_RC_SETPCIFN_FHOP ); +break ; + } +break ; + } +case CLP_QUERY_PCI_FN : { +ClpReqQueryPci *reqquery = (ClpReqQueryPci *)reqh; +ClpRspQueryPci *resquery = (ClpRspQueryPci *)resh; + + pbdev =s390_pci_find_dev_by_fh (reqquery->fh); +if (!pbdev) { +DPRINTF ("query pci no pci dev\n" ); +return -EIO ; + } + +for (i =0 ; i <PCI_BAR_COUNT ; i++) { +uint64_t data =pci_host_config_read_common (pbdev->pdev, +0x10 + (i *4 ),pci_config_size (pbdev->pdev),4 ); + + resquery->bar[i] =bswap32 (data); + resquery->bar_size[i] =barsize (pbdev->pdev->io_regions[i].size); +DPRINTF ("bar %d addr 0x%x size 0x%lx barsize 0x%x\n" , i, + resquery->bar[i], pbdev->pdev->io_regions[i].size, + resquery->bar_size[i]); + } + +/* may optain from host dev (e.g. via new sysfs attr */ + resquery->sdma =0x100000000 ; + resquery->edma =0x1ffffffffffffff ; + resquery->pchid =0 ; + resquery->ug =1 ; + + resquery->hdr.rsp =CLP_RC_OK ; +break ; + } +case CLP_QUERY_PCI_FNGRP : { +ClpRspQueryPciGrp *resgrp = (ClpRspQueryPciGrp *)resh; +/* find function group for now we go with fixed values */ + resgrp->fr =1 ; + resgrp->dasm =0 ; + resgrp->msia =ZPCI_MSI_ADDR ; + resgrp->mui =0 ; + resgrp->i =128 ; + resgrp->version =0 ; + + resgrp->hdr.rsp =CLP_RC_OK ; +break ; + }
target-s390x/pci_ic.c line 299
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+default : +DPRINTF ("unknown clp command\n" ); + resh->rsp =cpu_to_be16 (CLP_RC_CMD ); +break ; + } + +out: +cpu_physical_memory_rw (env->regs[r2], buffer, req_len + res_len,1 ); +g_free (buffer); +setcc (cpu,0 );
Here you are ignoring the "cc" variable that gets set by list_pci() anyway ... So either the cc variable can be removed from this function here, too, or you should use it here instead of the 0 ?
target-s390x/pci_ic.c line 298
Quoted 1 line
target-s390x/pci_ic.c new file +1
-0+return rc;
Also if list_pci() returned an error code and you pass this negative value up to the caller, the handle_instruction() in kvm.c will finally inject an operation program exception. I doubt that's want you want, so this function here should likely always return zero instead?
Quoted 40 lines
target-s390x/pci_ic.c new file +40
-0+} + +int kvm_pcilg_service_call (S390CPU *cpu,struct kvm_run *run) +{ +CPUS390XState *env = &cpu->env; +S390PCIBusDevice *pbdev; +uint8_t r1 = (run->s390_sieic.ipb &0x00f00000 ) >>20 ; +uint8_t r2 = (run->s390_sieic.ipb &0x000f0000 ) >>16 ; +PciLgStg *rp; +uint64_t offset; +uint64_t data; + +cpu_synchronize_state (CPU (cpu)); + +if (env->psw.mask &PSW_MASK_PSTATE ) { +program_interrupt (env,PGM_PRIVILEGED ,4 ); +return 0 ; + } + +if (r2 &0x1 ) { +program_interrupt (env,PGM_SPECIFICATION ,4 ); +return 0 ; + } + + rp = (PciLgStg *)&env->regs[r2]; + offset = env->regs[r2 +1 ]; + + pbdev =s390_pci_find_dev_by_fh (rp->fh); +if (!pbdev) { +DPRINTF ("pcilg no pci dev\n" ); +setcc (cpu,3 ); +return 0 ; + } + +if (rp->pcias <6 ) { +if ((8 - (offset &0x7 )) < (rp->len &0xF )) { +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } +MemoryRegion *mr = pbdev->pdev->io_regions[rp->pcias].memory;
target-s390x/pci_ic.c line 350
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+io_mem_read (mr, offset, &data, rp->len); + }else if (rp->pcias ==15 ) { +if ((4 - (offset &0x3 )) < (rp->len &0xF )) { +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } + data =pci_host_config_read_common ( + pbdev->pdev, offset,pci_config_size (pbdev->pdev), rp->len); + +switch (rp->len) {
The rp->len field is only in the lowest 4 bits of the register, but you've only masked it when checking for the PGM_OPERAND condition... May I suggest that you introduce a new local variable a la:
len = rp->len & 0x0f;
and use that everywhere instead of rp->len ?
Quoted 9 lines
target-s390x/pci_ic.c new file +9
-0+case 1 : +break ; +case 2 : + data =cpu_to_le16 (data); +break ; +case 4 : + data =cpu_to_le32 (data); +break ; +case 8 :
target-s390x/pci_ic.c line 369
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+ data =cpu_to_le64 (data); +break ; +default : +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } + }else { +DPRINTF ("invalid space\n" ); +setcc (cpu,1 ); +s390_set_status_code (env, r2,20ul );
Maybe you could introduce a proper #define for that "20" status code here and everywhere else? Also I think you can omit the "ul" suffix.
Quoted 83 lines
target-s390x/pci_ic.c new file +83
-0+return 0 ; + } + + env->regs[r1] = data; +setcc (cpu,0 ); +return 0 ; +} + +static void update_msix_table_msg_data (S390PCIBusDevice *pbdev,uint64_t offset, +uint64_t *data,uint8_t len) +{ +uint32_t msg_data; + +if (offset %PCI_MSIX_ENTRY_SIZE !=8 ) { +return ; + } + +if (len !=4 ) { +DPRINTF ("access msix table msg data but len is %d\n" , len); +return ; + } + + msg_data = (pbdev->fid <<ZPCI_MSI_VEC_BITS ) |le32_to_cpu (*data); + *data =cpu_to_le32 (msg_data); +DPRINTF ("update msix msg_data to 0x%x\n" , msg_data); +} + +static int trap_msix (S390PCIBusDevice *pbdev,uint64_t offset,uint8_t pcias) +{ +if (pbdev->msix.available && pbdev->msix.table_bar == pcias && + offset >= pbdev->msix.table_offset && + offset <= pbdev->msix.table_offset + + (pbdev->msix.entries -1 ) *PCI_MSIX_ENTRY_SIZE ) { +return 1 ; + }else { +return 0 ; + } +} + +int kvm_pcistg_service_call (S390CPU *cpu,struct kvm_run *run) +{ +CPUS390XState *env = &cpu->env; +uint8_t r1 = (run->s390_sieic.ipb &0x00f00000 ) >>20 ; +uint8_t r2 = (run->s390_sieic.ipb &0x000f0000 ) >>16 ; +PciLgStg *rp; +uint64_t offset, data; +S390PCIBusDevice *pbdev; + +cpu_synchronize_state (CPU (cpu)); + +if (env->psw.mask &PSW_MASK_PSTATE ) { +program_interrupt (env,PGM_PRIVILEGED ,4 ); +return 0 ; + } + +if (r2 &0x1 ) { +program_interrupt (env,PGM_SPECIFICATION ,4 ); +return 0 ; + } + + rp = (PciLgStg *)&env->regs[r2]; + offset = env->regs[r2 +1 ]; + + pbdev =s390_pci_find_dev_by_fh (rp->fh); +if (!pbdev) { +DPRINTF ("pcistg no pci dev\n" ); +setcc (cpu,3 ); +return 0 ; + } + + data = env->regs[r1]; + +if (rp->pcias <6 ) { +if ((8 - (offset &0x7 )) < (rp->len &0xF )) { +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } +MemoryRegion *mr; +if (trap_msix (pbdev, offset, rp->pcias)) { + offset = offset - pbdev->msix.table_offset; + mr = &pbdev->pdev->msix_table_mmio; +update_msix_table_msg_data (pbdev, offset, &data, rp->len); + }else {
target-s390x/pci_ic.c line 462
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+ mr = pbdev->pdev->io_regions[rp->pcias].memory; + } + +io_mem_write (mr, offset, data, rp->len); + }else if (rp->pcias ==15 ) { +if ((4 - (offset &0x3 )) < (rp->len &0xF )) { +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } +switch (rp->len) {
The comment from pcilg also applies here -- rp->len is 4-bits only again.
Quoted 78 lines
target-s390x/pci_ic.c new file +78
-0+case 1 : +break ; +case 2 : + data =le16_to_cpu (data); +break ; +case 4 : + data =le32_to_cpu (data); +break ; +case 8 : + data =le64_to_cpu (data); +break ; +default : +program_interrupt (env,PGM_OPERAND ,4 ); +return 0 ; + } + +pci_host_config_write_common (pbdev->pdev, offset, +pci_config_size (pbdev->pdev), + data, rp->len); + }else { +DPRINTF ("pcistg invalid space\n" ); +setcc (cpu,1 ); +s390_set_status_code (env, r2,20ul ); +return 0 ; + } + +setcc (cpu,0 ); +return 0 ; +} + +int kvm_rpcit_service_call (S390CPU *cpu,struct kvm_run *run) +{ +CPUS390XState *env = &cpu->env; +uint8_t r1 = (run->s390_sieic.ipb &0x00f00000 ) >>20 ; +uint8_t r2 = (run->s390_sieic.ipb &0x000f0000 ) >>16 ; +uint32_t fh; +uint64_t pte; +S390PCIBusDevice *pbdev; +ram_addr_t size; +int flags; +IOMMUTLBEntry entry; + +cpu_synchronize_state (CPU (cpu)); + +if (env->psw.mask &PSW_MASK_PSTATE ) { +program_interrupt (env,PGM_PRIVILEGED ,4 ); +return 0 ; + } + +if (r2 &0x1 ) { +program_interrupt (env,PGM_SPECIFICATION ,4 ); +return 0 ; + } + + fh = env->regs[r1] >>32 ; + size = env->regs[r2 +1 ]; + + pbdev =s390_pci_find_dev_by_fh (fh); + +if (!pbdev) { +DPRINTF ("rpcit no pci dev\n" ); +setcc (cpu,3 ); +return 0 ; + } + + pte =s390_guest_io_table_walk (pbdev->g_iota, env->regs[r2]); + flags = pte &ZPCI_PTE_FLAG_MASK ; + entry.target_as = &address_space_memory; + entry.iova = env->regs[r2]; + entry.translated_addr = pte &ZPCI_PTE_ADDR_MASK ; + entry.addr_mask = size -1 ; + +if (flags &ZPCI_PTE_INVALID ) { + entry.perm =IOMMU_NONE ; + }else { + entry.perm =IOMMU_RW ; + } +
target-s390x/pci_ic.c line 550
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+memory_region_notify_iommu (pci_device_iommu_address_space ( + pbdev->pdev)->root, entry); + +setcc (cpu,0 ); +return 0 ; +} + +int kvm_sic_service_call (S390CPU *cpu,struct kvm_run *run) +{ +DPRINTF ("sic\n" );
Is it ok to simply ignore this call? Or would it be better to inject a program check instead, so that this does not go unnoticed by the guest?
Quoted 46 lines
target-s390x/pci_ic.c new file +46
-0+return 0 ; +} + +int kvm_pcistb_service_call (S390CPU *cpu,struct kvm_run *run) +{ +CPUS390XState *env = &cpu->env; +uint8_t r1 = (run->s390_sieic.ipa &0x00f0 ) >>4 ; +uint8_t r3 = run->s390_sieic.ipa &0x000f ; +PciStb *rp; +uint64_t gaddr; +uint64_t *uaddr, *pu; +hwaddr len; +S390PCIBusDevice *pbdev; +MemoryRegion *mr; +int i; + +cpu_synchronize_state (CPU (cpu)); + +if (env->psw.mask &PSW_MASK_PSTATE ) { +program_interrupt (env,PGM_PRIVILEGED ,6 ); +return 0 ; + } + + rp = (PciStb *)&env->regs[r1]; +if (rp->pcias >5 ) { +DPRINTF ("pcistb invalid space\n" ); +s390_set_status_code (env, r1,20ul ); +return 0 ; + } + +switch (rp->len) { +case 16 : +case 32 : +case 64 : +case 128 : +break ; +default : +program_interrupt (env,PGM_SPECIFICATION ,6 ); +return 0 ; + } + + gaddr =get_base_disp_rsy (cpu, run); + len = rp->len; + + pbdev =s390_pci_find_dev_by_fh (rp->fh); +if (!pbdev) {
target-s390x/pci_ic.c line 606
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+DPRINTF ("pcistb no pci dev fh 0x%x\n" , rp->fh); +setcc (cpu,3 ); +return 0 ; + } + + uaddr =cpu_physical_memory_map (gaddr, &len,0 ); + mr = pbdev->pdev->io_regions[rp->pcias].memory; +if (!memory_region_access_valid (mr, env->regs[r3], rp->len, true)) { +cpu_physical_memory_unmap (uaddr, len,0 , len); +program_interrupt (env,PGM_OPERAND ,6 );
PGM_ADDRESSING might be the better choice in this case.
Quoted 13 lines
target-s390x/pci_ic.c new file +13
-0+return 0 ; + } + + pu = uaddr; +for (i =0 ; i < rp->len /8 ; i++) { +io_mem_write (mr, env->regs[r3] + i *8 , *pu,8 ); + pu++; + } + +cpu_physical_memory_unmap (uaddr, len,0 , len); +setcc (cpu,0 ); +return 0 ; +}
...
Quoted 63 lines
target-s390x/pci_ic.c new file +63
-0+int kvm_mpcifc_service_call (S390CPU *cpu,struct kvm_run *run) +{ +CPUS390XState *env = &cpu->env; +uint8_t r1 = (run->s390_sieic.ipa &0x00f0 ) >>4 ; +uint8_t oc; +uint32_t fh; +uint64_t fiba; +ZpciFib fib; +S390PCIBusDevice *pbdev; + +cpu_synchronize_state (CPU (cpu)); + +if (env->psw.mask &PSW_MASK_PSTATE ) { +program_interrupt (env,PGM_PRIVILEGED ,6 ); +return 0 ; + } + + oc = env->regs[r1] &0xff ; + fh = env->regs[r1] >>32 ; + fiba =get_base_disp_rxy (cpu, run); + +if (fiba &0x7 ) { +program_interrupt (env,PGM_SPECIFICATION ,6 ); +return 0 ; + } + + pbdev =s390_pci_find_dev_by_fh (fh); +if (!pbdev) { +DPRINTF ("mpcifc no pci dev fh 0x%x\n" , fh); +setcc (cpu,3 ); +return 0 ; + } + +cpu_physical_memory_rw (fiba, (uint8_t *)&fib,sizeof (fib),0 ); + +switch (oc) { +case ZPCI_MOD_FC_REG_INT : { + pbdev->isc =FIB_DATA_ISC (fib.data); +reg_irqs (env, pbdev, fib); +break ; + } +case ZPCI_MOD_FC_DEREG_INT : +dereg_irqs (pbdev); +break ; +case ZPCI_MOD_FC_REG_IOAT : +if (fib.pba > fib.pal) { +program_interrupt (&cpu->env,PGM_OPERAND ,6 ); +return 0 ; + } + pbdev->g_iota = fib.iota & ~ZPCI_IOTA_RTTO_FLAG ; +break ; +case ZPCI_MOD_FC_DEREG_IOAT : +break ; +case ZPCI_MOD_FC_REREG_IOAT : +break ; +case ZPCI_MOD_FC_RESET_ERROR : +break ; +case ZPCI_MOD_FC_RESET_BLOCK : +break ; +case ZPCI_MOD_FC_SET_MEASURE : +break ; +default : +program_interrupt (&cpu->env,PGM_OPERAND ,6 );
target-s390x/pci_ic.c line 733
Quoted 10 lines
target-s390x/pci_ic.c new file +10
-0+return 0 ; + } + +setcc (cpu,0 ); +return 0 ; +} + +int kvm_stpcifc_service_call (S390CPU *cpu,struct kvm_run *run) +{ +DPRINTF ("stpcifc\n" );
As with SIC, I wonder whether it might be better to inject an exception by default?
target-s390x/pci_ic.c
Quoted 2 lines
target-s390x/pci_ic.c new file +2
-0+return 0 ; +}
Thomas
PATCH 3/3 kvm: extend kvm_irqchip_add_msi_route to work on s390
In reply to Frank BlaschkaFrom: Frank Blaschka <[email protected]>
on s390 MSI-X irqs are presented as thin or adapter interrupts for this we have to reorganize the routing entry to contain valid information for the adapter interrupt code on s390. To minimize impact on existing code we introduce an architecture function to fixup the routing entry.
--- include/sysemu/kvm.h | 4 ++++ kvm-all.c | 2 ++ target-arm/kvm.c | 5 +++++ target-i386/kvm.c | 5 +++++ target-mips/kvm.c | 5 +++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 25 +++++++++++++++++++++++++ 7 files changed, 51 insertions(+)
include/sysemu/kvm.h +4 -0
@@ -148,6 +148,7 @@ extern bool kvm_readonly_mem_allowed;struct kvm_run ;struct kvm_lapic_state ; +struct kvm_irq_routing_entry ; typedef struct KVMCapabilityInfo { const char *name;
@@ -261,6 +262,9 @@ int kvm_arch_on_sigbus(int code, void *addr);void kvm_arch_init_irq_routing (KVMState *s); +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data); +int kvm_set_irq (KVMState *s,int irq,int level);int kvm_irqchip_send_msi (KVMState *s,MSIMessage msg);
kvm-all.c +2 -0
@@ -1198,6 +1198,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg) kroute.u.msi.address_lo = (uint32_t )msg.address; kroute.u.msi.address_hi = msg.address >>32 ; kroute.u.msi.data =le32_to_cpu (msg.data); +kvm_arch_fixup_msi_route (&kroute, msg.address, msg.data);kvm_add_routing_entry (s, &kroute);kvm_irqchip_commit_routes (s);
@@ -1223,6 +1224,7 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg) kroute.u.msi.address_lo = (uint32_t )msg.address; kroute.u.msi.address_hi = msg.address >>32 ; kroute.u.msi.data =le32_to_cpu (msg.data); +kvm_arch_fixup_msi_route (&kroute, msg.address, msg.data);return kvm_update_routing_entry (s, &kroute); }
target-arm/kvm.c +5 -0
@@ -441,3 +441,8 @@ int kvm_arch_irqchip_create(KVMState *s)return 0 ; } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +}
target-i386/kvm.c +5 -0
@@ -2688,3 +2688,8 @@ int kvm_device_msix_deassign(KVMState *s, uint32_t dev_id)return kvm_deassign_irq_internal (s, dev_id,KVM_DEV_IRQ_GUEST_MSIX |KVM_DEV_IRQ_HOST_MSIX ); } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +}
target-mips/kvm.c +5 -0
@@ -688,3 +688,8 @@ int kvm_arch_get_registers(CPUState *cs)return ret; } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +}
target-ppc/kvm.c +5 -0
@@ -2388,3 +2388,8 @@ out_close: error_out:return ; } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +}
target-s390x/kvm.c +25 -0
@@ -43,6 +43,7 @@#include "trace.h" #include "qapi-event.h" #include "pci_ic.h" +#include "hw/s390x/s390-pci-bus.h" /* #define DEBUG_KVM */
@@ -1639,3 +1640,27 @@ int kvm_s390_get_machine_props(S390MachineProps *prop) {return cpu_model_get (KVM_S390_VM_CPU_MACHINE , (uint64_t ) prop); } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +S390PCIBusDevice *pbdev; +uint32_t fid = data >>ZPCI_MSI_VEC_BITS ; +uint32_t vec = data &ZPCI_MSI_VEC_MASK ; + + pbdev =s390_pci_find_dev_by_fid (fid); +if (!pbdev) { +DPRINTF ("add_msi_route no dev\n" ); +return ; + } + + pbdev->routes.adapter.ind_offset = vec; + + route->type =KVM_IRQ_ROUTING_S390_ADAPTER ; + route->flags =0 ; + route->u.adapter.summary_addr = pbdev->routes.adapter.summary_addr; + route->u.adapter.ind_addr = pbdev->routes.adapter.ind_addr; + route->u.adapter.summary_offset = pbdev->routes.adapter.summary_offset; + route->u.adapter.ind_offset = pbdev->routes.adapter.ind_offset; + route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id; +}
Signature · 1 line
1.8.5.5
Re: [Qemu-devel] [PATCH 3/3 RPC] kvm: extend kvm_irqchip_add_msi_route to work on s390
Quoted 33 lines · On Wed, 22 Oct 2014 17:12:00 +0200 Frank Blaschka…
From: Frank Blaschka <[email protected]>
on s390 MSI-X irqs are presented as thin or adapter interrupts for this we have to reorganize the routing entry to contain valid information for the adapter interrupt code on s390. To minimize impact on existing code we introduce an architecture function to fixup the routing entry.
Signed-off-by Frank Blaschka <[email protected]>--- include/sysemu/kvm.h | 4 ++++ kvm-all.c | 2 ++ target-arm/kvm.c | 5 +++++ target-i386/kvm.c | 5 +++++ target-mips/kvm.c | 5 +++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 25 +++++++++++++++++++++++++ 7 files changed, 51 insertions(+)target-s390x/kvm.c +1
-0@@ -43,6 +43,7 @@#include "trace.h" #include "qapi-event.h" #include "pci_ic.h" +#include "hw/s390x/s390-pci-bus.h" /* #define DEBUG_KVM */
target-s390x/kvm.c int kvm_s390_get_machine_props(S390MachineProps *prop) · line 1649
Quoted 10 lines
target-s390x/kvm.c +7
-0@@ -1639,3 +1640,27 @@ int kvm_s390_get_machine_props(S390MachineProps *prop) {return cpu_model_get (KVM_S390_VM_CPU_MACHINE , (uint64_t ) prop); } + +void kvm_arch_fixup_msi_route (struct kvm_irq_routing_entry *route, +uint64_t address,uint32_t data) +{ +S390PCIBusDevice *pbdev; +uint32_t fid = data >>ZPCI_MSI_VEC_BITS ; +uint32_t vec = data &ZPCI_MSI_VEC_MASK ;
I think this needs a comment so it is easier to understand why you're mucking around with PCI devices and I/O adapters here without referring to git blame :)
target-s390x/kvm.c int kvm_s390_get_machine_props(S390MachineProps *prop) · line 1654
Quoted 5 lines
target-s390x/kvm.c +5
-0+ + pbdev =s390_pci_find_dev_by_fid (fid); +if (!pbdev) { +DPRINTF ("add_msi_route no dev\n" ); +return ;
This feels wrong. Shouldn't this function fail if you can't find the pci device? The calling function can probably just release the virq again and return an error.
Quoted 12 lines
target-s390x/kvm.c +12
-0+ } + + pbdev->routes.adapter.ind_offset = vec; + + route->type =KVM_IRQ_ROUTING_S390_ADAPTER ; + route->flags =0 ; + route->u.adapter.summary_addr = pbdev->routes.adapter.summary_addr; + route->u.adapter.ind_addr = pbdev->routes.adapter.ind_addr; + route->u.adapter.summary_offset = pbdev->routes.adapter.summary_offset; + route->u.adapter.ind_offset = pbdev->routes.adapter.ind_offset; + route->u.adapter.adapter_id = pbdev->routes.adapter.adapter_id; +}
Quoted 5 lines · Frank Blaschka
This set of patches implemets PCI support for the s390 platform. Now it is possible to run virtio-net-pci and potentially all virtual pci devices conforming to s390 platform constrains. (In parallel I also post some changes to make vfio run on s390)
Quoted 8 lines
I hope to get feedback and guidance especially for
kvm: extend
kvm_irqchip_add_msi_routeto work on s390which adds the s390 interpretation of MSI-X to the common kvm
add_msi_routefunctionality.Thx for any help,
The patch set certainly looks like way-above-RFC-quality to me ;). Unfortunately timing is suboptimal with soft freeze in place already and hard freeze coming up soon, but from a quick glimpse I like it. No reviewed-by yet though, as I'd have to dig in further for that ;).
Alex