From 9abf567d95a4e840df868ca993219175fbef8c22 Mon Sep 17 00:00:00 2001 From: Christian Borntraeger Date: Mon, 23 Jul 2012 21:37:04 +0000 Subject: [PATCH 1/2] s390: Fix error handling and condition code of service call Invalid sccb addresses will cause specification or addressing exception. Lets add those checks. Furthermore, the good case (cc=0) was incorrect for KVM, we did not set the CC at all. We now use return codes < 0 as program checks and return codes > 0 as condition code values. Signed-off-by: Christian Borntraeger Signed-off-by: Alexander Graf --- target-s390x/kvm.c | 5 +++-- target-s390x/op_helper.c | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 47008c24f2..07edf93690 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -273,9 +273,10 @@ static int kvm_sclp_service_call(CPUS390XState *env, struct kvm_run *run, code = env->regs[(ipbh0 & 0xf0) >> 4]; r = sclp_service_call(env, sccb, code); - if (r) { - setcc(env, 3); + if (r < 0) { + enter_pgmcheck(env, -r); } + setcc(env, r); return 0; } diff --git a/target-s390x/op_helper.c b/target-s390x/op_helper.c index 7b7247316e..91dd8dc3fb 100644 --- a/target-s390x/op_helper.c +++ b/target-s390x/op_helper.c @@ -19,6 +19,8 @@ */ #include "cpu.h" +#include "memory.h" +#include "cputlb.h" #include "dyngen-exec.h" #include "host-utils.h" #include "helper.h" @@ -2366,6 +2368,9 @@ static void ext_interrupt(CPUS390XState *env, int type, uint32_t param, cpu_inject_ext(env, type, param, param64); } +/* + * ret < 0 indicates program check, ret = 0,1,2,3 -> cc + */ int sclp_service_call(CPUS390XState *env, uint32_t sccb, uint64_t code) { int r = 0; @@ -2375,10 +2380,12 @@ int sclp_service_call(CPUS390XState *env, uint32_t sccb, uint64_t code) printf("sclp(0x%x, 0x%" PRIx64 ")\n", sccb, code); #endif + /* basic checks */ + if (!memory_region_is_ram(phys_page_find(sccb >> TARGET_PAGE_BITS)->mr)) { + return -PGM_ADDRESSING; + } if (sccb & ~0x7ffffff8ul) { - fprintf(stderr, "KVM: invalid sccb address 0x%x\n", sccb); - r = -1; - goto out; + return -PGM_SPECIFICATION; } switch(code) { @@ -2405,22 +2412,24 @@ int sclp_service_call(CPUS390XState *env, uint32_t sccb, uint64_t code) #ifdef DEBUG_HELPER printf("KVM: invalid sclp call 0x%x / 0x%" PRIx64 "x\n", sccb, code); #endif - r = -1; + r = 3; break; } -out: return r; } /* SCLP service call */ uint32_t HELPER(servc)(uint32_t r1, uint64_t r2) { - if (sclp_service_call(env, r1, r2)) { - return 3; - } + int r; - return 0; + r = sclp_service_call(env, r1, r2); + if (r < 0) { + program_interrupt(env, -r, 4); + return 0; + } + return r; } /* DIAG */ From 000a1a3800b532f97b939ebb777d5a14418f44a6 Mon Sep 17 00:00:00 2001 From: Christian Borntraeger Date: Mon, 23 Jul 2012 21:37:05 +0000 Subject: [PATCH 2/2] s390: provide interface for service interrupt/introduce interrupt.c This patch creates interrupt.c. The first user is a callback for hw/* code to trigger an service interrupt for a given sccb value. Several interrupt types for s390 are floating (can be delivered to all CPUs). so this code does not belong to a specific CPU. Other interrupts (like the virtio one) are also floating and can be moved here later on. Signed-off-by: Christian Borntraeger Signed-off-by: Alexander Graf --- target-s390x/Makefile.objs | 2 +- target-s390x/cpu.h | 3 +++ target-s390x/interrupt.c | 29 +++++++++++++++++++++++++++++ target-s390x/op_helper.c | 16 +--------------- 4 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 target-s390x/interrupt.c diff --git a/target-s390x/Makefile.objs b/target-s390x/Makefile.objs index 262747f8a6..80be3bbdb2 100644 --- a/target-s390x/Makefile.objs +++ b/target-s390x/Makefile.objs @@ -1,4 +1,4 @@ -obj-y += translate.o op_helper.o helper.o cpu.o +obj-y += translate.o op_helper.o helper.o cpu.o interrupt.o obj-$(CONFIG_SOFTMMU) += machine.o obj-$(CONFIG_KVM) += kvm.o diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index c30ac3a0e1..18ac6e3938 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -320,6 +320,9 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr); void s390_add_running_cpu(CPUS390XState *env); unsigned s390_del_running_cpu(CPUS390XState *env); +/* service interrupts are floating therefore we must not pass an cpustate */ +void s390_sclp_extint(uint32_t parm); + /* from s390-virtio-bus */ extern const target_phys_addr_t virtio_size; diff --git a/target-s390x/interrupt.c b/target-s390x/interrupt.c new file mode 100644 index 0000000000..c1b034f775 --- /dev/null +++ b/target-s390x/interrupt.c @@ -0,0 +1,29 @@ +/* + * QEMU S/390 Interrupt support + * + * Copyright IBM, Corp. 2012 + * + * 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 "cpu.h" +#include "kvm.h" + +#if !defined(CONFIG_USER_ONLY) +/* service interrupts are floating therefore we must not pass an cpustate */ +void s390_sclp_extint(uint32_t parm) +{ + S390CPU *dummy_cpu = s390_cpu_addr2state(0); + CPUS390XState *env = &dummy_cpu->env; + + if (kvm_enabled()) { +#ifdef CONFIG_KVM + kvm_s390_interrupt_internal(env, KVM_S390_INT_SERVICE, parm, 0, 1); +#endif + } else { + env->psw.addr += 4; + cpu_inject_ext(env, EXT_SERVICE, parm, 0); + } +} +#endif diff --git a/target-s390x/op_helper.c b/target-s390x/op_helper.c index 91dd8dc3fb..abc35ddd7b 100644 --- a/target-s390x/op_helper.c +++ b/target-s390x/op_helper.c @@ -2362,12 +2362,6 @@ static void program_interrupt(CPUS390XState *env, uint32_t code, int ilc) } } -static void ext_interrupt(CPUS390XState *env, int type, uint32_t param, - uint64_t param64) -{ - cpu_inject_ext(env, type, param, param64); -} - /* * ret < 0 indicates program check, ret = 0,1,2,3 -> cc */ @@ -2398,15 +2392,7 @@ int sclp_service_call(CPUS390XState *env, uint32_t sccb, uint64_t code) stb_phys(sccb + SCP_INCREMENT, 1 << shift); stw_phys(sccb + SCP_RESPONSE_CODE, 0x10); - if (kvm_enabled()) { -#ifdef CONFIG_KVM - kvm_s390_interrupt_internal(env, KVM_S390_INT_SERVICE, - sccb & ~3, 0, 1); -#endif - } else { - env->psw.addr += 4; - ext_interrupt(env, EXT_SERVICE, sccb & ~3, 0); - } + s390_sclp_extint(sccb & ~3); break; default: #ifdef DEBUG_HELPER