From 4cb88c3c378ae8c86c0ba53619caf6924f72239c Mon Sep 17 00:00:00 2001 From: Dominik Dingel Date: Fri, 11 Apr 2014 13:47:40 +0200 Subject: s390x/kvm: enable/reset cmma via vm attributes Exploit the new api for userspace-controlled cmma. If supported, enable cmma during kvm initialization and register a reset handler for cmma, which is also called directly from the load IPL code. The reset functionality is needed to reset the cmma state of the guest pages, e.g. if a system reset is triggered via qemu monitor; otherwise this could result in data corruption. A guest triggered reboot may now lead to multiple cmma resets; this is OK, however, as this is slowpath anyway and the simplest way to achieve the intended effects. Signed-off-by: Dominik Dingel Acked-by: Christian Borntraeger Acked-by: Cornelia Huck Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 12 ++++++++++ target-s390x/kvm.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/misc_helper.c | 2 ++ 3 files changed, 72 insertions(+) (limited to 'target-s390x') diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 06454d6..808b906 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -1074,6 +1074,7 @@ void kvm_s390_enable_css_support(S390CPU *cpu); int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, int vq, bool assign); int kvm_s390_cpu_restart(S390CPU *cpu); +void kvm_s390_clear_cmma_callback(void *opaque); #else static inline void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, @@ -1098,8 +1099,19 @@ static inline int kvm_s390_cpu_restart(S390CPU *cpu) { return -ENOSYS; } +static inline void kvm_s390_clear_cmma_callback(void *opaque) +{ +} #endif +static inline void cmma_reset(S390CPU *cpu) +{ + if (kvm_enabled()) { + CPUState *cs = CPU(cpu); + kvm_s390_clear_cmma_callback(cs->kvm_state); + } +} + static inline int s390_cpu_restart(S390CPU *cpu) { if (kvm_enabled()) { diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 7a07f9d..0a2a205 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -32,6 +32,7 @@ #include "qemu/timer.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "hw/hw.h" #include "cpu.h" #include "sysemu/device_tree.h" #include "qapi/qmp/qjson.h" @@ -104,10 +105,67 @@ static int cap_async_pf; static void *legacy_s390_alloc(size_t size); +static int kvm_s390_check_clear_cmma(KVMState *s) +{ + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_CLR_CMMA, + }; + + return kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr); +} + +static int kvm_s390_check_enable_cmma(KVMState *s) +{ + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_ENABLE_CMMA, + }; + + return kvm_vm_ioctl(s, KVM_HAS_DEVICE_ATTR, &attr); +} + +void kvm_s390_clear_cmma_callback(void *opaque) +{ + int rc; + KVMState *s = opaque; + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_CLR_CMMA, + }; + + rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr); + trace_kvm_clear_cmma(rc); +} + +static void kvm_s390_enable_cmma(KVMState *s) +{ + int rc; + struct kvm_device_attr attr = { + .group = KVM_S390_VM_MEM_CTRL, + .attr = KVM_S390_VM_MEM_ENABLE_CMMA, + }; + + if (kvm_s390_check_enable_cmma(s) || kvm_s390_check_clear_cmma(s)) { + return; + } + + rc = kvm_vm_ioctl(s, KVM_SET_DEVICE_ATTR, &attr); + if (!rc) { + qemu_register_reset(kvm_s390_clear_cmma_callback, s); + } + trace_kvm_enable_cmma(rc); +} + int kvm_arch_init(KVMState *s) { cap_sync_regs = kvm_check_extension(s, KVM_CAP_SYNC_REGS); cap_async_pf = kvm_check_extension(s, KVM_CAP_ASYNC_PF); + + if (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES)) { + kvm_s390_enable_cmma(s); + } + if (!kvm_check_extension(s, KVM_CAP_S390_GMAP) || !kvm_check_extension(s, KVM_CAP_S390_COW)) { phys_mem_set_alloc(legacy_s390_alloc); diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c index 9dae025..519edb8 100644 --- a/target-s390x/misc_helper.c +++ b/target-s390x/misc_helper.c @@ -136,6 +136,7 @@ static int modified_clear_reset(S390CPU *cpu) pause_all_vcpus(); cpu_synchronize_all_states(); cpu_full_reset_all(); + cmma_reset(cpu); io_subsystem_reset(); scc->load_normal(CPU(cpu)); cpu_synchronize_all_post_reset(); @@ -150,6 +151,7 @@ static int load_normal_reset(S390CPU *cpu) pause_all_vcpus(); cpu_synchronize_all_states(); cpu_reset_all(); + cmma_reset(cpu); io_subsystem_reset(); scc->initial_cpu_reset(CPU(cpu)); scc->load_normal(CPU(cpu)); -- cgit v1.1 From a2689242b10a7bbc9a952659a2a5cc04a86d10e1 Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Thu, 20 Mar 2014 21:49:18 +0100 Subject: s390x/kvm: Log unmanageable external interruptions Interception code 0x14 only drops to userspace when an unmanageable external interruption interception occured (e.g. if the External New PSW does not disable external interruptions). Instead of bailing out via the default handler, it is better to inform the user with a proper error message that also includes the bad PSW, and to stop the affected CPU with a panic event instead. Signed-off-by: Thomas Huth Signed-off-by: Jens Freimann Reviewed-by: David Hildenbrand Acked-by: Christian Borntraeger Signed-off-by: Cornelia Huck --- target-s390x/kvm.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'target-s390x') diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 0a2a205..be703bd 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -83,6 +83,7 @@ #define DIAG_KVM_BREAKPOINT 0x501 #define ICPT_INSTRUCTION 0x04 +#define ICPT_EXT_INT 0x14 #define ICPT_WAITPSW 0x1c #define ICPT_SOFT_INTERCEPT 0x24 #define ICPT_CPU_STOP 0x28 @@ -930,6 +931,28 @@ static bool is_special_wait_psw(CPUState *cs) return cs->kvm_run->psw_addr == 0xfffUL; } +static void guest_panicked(void) +{ + QObject *data; + + data = qobject_from_jsonf("{ 'action': %s }", "pause"); + monitor_protocol_event(QEVENT_GUEST_PANICKED, data); + qobject_decref(data); + + vm_stop(RUN_STATE_GUEST_PANICKED); +} + +static void unmanageable_intercept(S390CPU *cpu, const char *str, int pswoffset) +{ + CPUState *cs = CPU(cpu); + + error_report("Unmanageable %s! CPU%i new PSW: 0x%016lx:%016lx", + str, cs->cpu_index, ldq_phys(cs->as, cpu->env.psa + pswoffset), + ldq_phys(cs->as, cpu->env.psa + pswoffset + 8)); + s390_del_running_cpu(cpu); + guest_panicked(); +} + static int handle_intercept(S390CPU *cpu) { CPUState *cs = CPU(cpu); @@ -943,18 +966,18 @@ static int handle_intercept(S390CPU *cpu) case ICPT_INSTRUCTION: r = handle_instruction(cpu, run); break; + case ICPT_EXT_INT: + unmanageable_intercept(cpu, "external interrupt", + offsetof(LowCore, external_new_psw)); + r = EXCP_HALTED; + break; case ICPT_WAITPSW: /* disabled wait, since enabled wait is handled in kernel */ if (s390_del_running_cpu(cpu) == 0) { if (is_special_wait_psw(cs)) { qemu_system_shutdown_request(); } else { - QObject *data; - - data = qobject_from_jsonf("{ 'action': %s }", "pause"); - monitor_protocol_event(QEVENT_GUEST_PANICKED, data); - qobject_decref(data); - vm_stop(RUN_STATE_GUEST_PANICKED); + guest_panicked(); } } r = EXCP_HALTED; -- cgit v1.1 From 6449a41a4d4082ddb0a6e156c7e8932fe7d60fbf Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Wed, 7 May 2014 09:45:21 +0200 Subject: s390x/kvm: Log unmanageable program interruptions The kernel only drops to userspace if an endless program interrupt loop has been detected. Let's print an error message in this case to inform the user about the crash and stop the affected CPU with a panic event, just like it is already done for the external interruption loop detection. Signed-off-by: Thomas Huth Signed-off-by: Jens Freimann Reviewed-by: Cornelia Huck Signed-off-by: Cornelia Huck --- target-s390x/kvm.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'target-s390x') diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index be703bd..9adda1b 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -83,6 +83,7 @@ #define DIAG_KVM_BREAKPOINT 0x501 #define ICPT_INSTRUCTION 0x04 +#define ICPT_PROGRAM 0x08 #define ICPT_EXT_INT 0x14 #define ICPT_WAITPSW 0x1c #define ICPT_SOFT_INTERCEPT 0x24 @@ -966,6 +967,11 @@ static int handle_intercept(S390CPU *cpu) case ICPT_INSTRUCTION: r = handle_instruction(cpu, run); break; + case ICPT_PROGRAM: + unmanageable_intercept(cpu, "program interrupt", + offsetof(LowCore, program_new_psw)); + r = EXCP_HALTED; + break; case ICPT_EXT_INT: unmanageable_intercept(cpu, "external interrupt", offsetof(LowCore, external_new_psw)); -- cgit v1.1 From 79afc36d91be7550affbe7db227b4552451da41d Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Tue, 11 Mar 2014 13:52:06 +0100 Subject: s390x: consolidate floating interrupts Move the injection code for all floating interrupts to interrupt.c and add a comment. Also get rid of the #ifdef CONFIG_KVM for the service interrupt. Reviewed-by: Thomas Huth Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 32 +++++++++----------------------- target-s390x/interrupt.c | 44 ++++++++++++++++++++++++++++++++++++++------ target-s390x/kvm.c | 5 +++++ 3 files changed, 52 insertions(+), 29 deletions(-) (limited to 'target-s390x') diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 808b906..5940f22 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -357,6 +357,7 @@ void s390x_tod_timer(void *opaque); void s390x_cpu_timer(void *opaque); int s390_virtio_hypercall(CPUS390XState *env); +void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token); #ifdef CONFIG_KVM void kvm_s390_reset_vcpu(S390CPU *cpu); @@ -364,6 +365,7 @@ void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code); void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token); void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, uint64_t parm64, int vm); +void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm); #else static inline void kvm_s390_reset_vcpu(S390CPU *cpu) { @@ -383,6 +385,9 @@ static inline void kvm_s390_interrupt_internal(S390CPU *cpu, int type, int vm) { } +static inline void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm) +{ +} #endif S390CPU *s390_cpu_addr2state(uint16_t cpu_addr); void s390_add_running_cpu(S390CPU *cpu); @@ -1120,29 +1125,10 @@ static inline int s390_cpu_restart(S390CPU *cpu) return -ENOSYS; } -static inline void s390_io_interrupt(S390CPU *cpu, - uint16_t subchannel_id, - uint16_t subchannel_nr, - uint32_t io_int_parm, - uint32_t io_int_word) -{ - if (kvm_enabled()) { - kvm_s390_io_interrupt(cpu, subchannel_id, subchannel_nr, io_int_parm, - io_int_word); - } else { - cpu_inject_io(cpu, subchannel_id, subchannel_nr, io_int_parm, - io_int_word); - } -} - -static inline void s390_crw_mchk(S390CPU *cpu) -{ - if (kvm_enabled()) { - kvm_s390_crw_mchk(cpu); - } else { - cpu_inject_crw_mchk(cpu); - } -} +void s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, + uint16_t subchannel_nr, uint32_t io_int_parm, + uint32_t io_int_word); +void s390_crw_mchk(S390CPU *cpu); static inline int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id, int vq, diff --git a/target-s390x/interrupt.c b/target-s390x/interrupt.c index 6d6580d..c32bdcb 100644 --- a/target-s390x/interrupt.c +++ b/target-s390x/interrupt.c @@ -1,7 +1,7 @@ /* * QEMU S/390 Interrupt support * - * Copyright IBM, Corp. 2012 + * Copyright IBM Corp. 2012, 2014 * * 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. @@ -10,21 +10,53 @@ #include "cpu.h" #include "sysemu/kvm.h" +/* + * All of the following interrupts are floating, i.e. not per-vcpu. + * We just need a dummy cpustate in order to be able to inject. + */ #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(dummy_cpu, KVM_S390_INT_SERVICE, parm, - 0, 1); -#endif + kvm_s390_service_interrupt(dummy_cpu, parm); } else { env->psw.addr += 4; cpu_inject_ext(dummy_cpu, EXT_SERVICE, parm, 0); } } + +void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token) +{ + if (kvm_enabled()) { + kvm_s390_virtio_irq(cpu, config_change, token); + } else { + cpu_inject_ext(cpu, EXT_VIRTIO, config_change, token); + } +} + +void s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, + uint16_t subchannel_nr, uint32_t io_int_parm, + uint32_t io_int_word) +{ + if (kvm_enabled()) { + kvm_s390_io_interrupt(cpu, subchannel_id, subchannel_nr, io_int_parm, + io_int_word); + } else { + cpu_inject_io(cpu, subchannel_id, subchannel_nr, io_int_parm, + io_int_word); + } +} + +void s390_crw_mchk(S390CPU *cpu) +{ + if (kvm_enabled()) { + kvm_s390_crw_mchk(cpu); + } else { + cpu_inject_crw_mchk(cpu); + } +} + #endif diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 9adda1b..9474f81 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -593,6 +593,11 @@ void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code) kvm_s390_interrupt_internal(cpu, type, code, 0, 0); } +void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm) +{ + kvm_s390_interrupt_internal(cpu, KVM_S390_INT_SERVICE, parm, 0 , 1); +} + static void enter_pgmcheck(S390CPU *cpu, uint16_t code) { kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code); -- cgit v1.1 From 66ad0893f07f194b5c8607cb81061b8d7202511c Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Tue, 11 Mar 2014 17:10:07 +0100 Subject: s390x/kvm: add alternative injection interface Add kvm_s390_{vcpu,floating}_interrupt, which offer the possibility to inject interrupts with larger payloads (when a kvm backend becomes available). Moreover, kvm_s390_floating_interrupt() does no longer have the bogus requirement for a vcpu. Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 2 ++ target-s390x/kvm.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) (limited to 'target-s390x') diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 5940f22..644d126 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -366,6 +366,8 @@ void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token); void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, uint64_t parm64, int vm); void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm); +void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq); +void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq); #else static inline void kvm_s390_reset_vcpu(S390CPU *cpu) { diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 9474f81..0d36ab4 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -555,6 +555,92 @@ int kvm_arch_process_async_events(CPUState *cs) return cs->halted; } +static int s390_kvm_irq_to_interrupt(struct kvm_s390_irq *irq, + struct kvm_s390_interrupt *interrupt) +{ + int r = 0; + + interrupt->type = irq->type; + switch (irq->type) { + case KVM_S390_INT_VIRTIO: + interrupt->parm = irq->u.ext.ext_params; + /* fall through */ + case KVM_S390_INT_PFAULT_INIT: + case KVM_S390_INT_PFAULT_DONE: + interrupt->parm64 = irq->u.ext.ext_params2; + break; + case KVM_S390_PROGRAM_INT: + interrupt->parm = irq->u.pgm.code; + break; + case KVM_S390_SIGP_SET_PREFIX: + interrupt->parm = irq->u.prefix.address; + break; + case KVM_S390_INT_SERVICE: + interrupt->parm = irq->u.ext.ext_params; + break; + case KVM_S390_MCHK: + interrupt->parm = irq->u.mchk.cr14; + interrupt->parm64 = irq->u.mchk.mcic; + break; + case KVM_S390_INT_EXTERNAL_CALL: + interrupt->parm = irq->u.extcall.code; + break; + case KVM_S390_INT_EMERGENCY: + interrupt->parm = irq->u.emerg.code; + break; + case KVM_S390_SIGP_STOP: + case KVM_S390_RESTART: + break; /* These types have no parameters */ + case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: + interrupt->parm = irq->u.io.subchannel_id << 16; + interrupt->parm |= irq->u.io.subchannel_nr; + interrupt->parm64 = (uint64_t)irq->u.io.io_int_parm << 32; + interrupt->parm64 |= irq->u.io.io_int_word; + break; + default: + r = -EINVAL; + break; + } + return r; +} + +void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq) +{ + struct kvm_s390_interrupt kvmint = {}; + CPUState *cs = CPU(cpu); + int r; + + r = s390_kvm_irq_to_interrupt(irq, &kvmint); + if (r < 0) { + fprintf(stderr, "%s called with bogus interrupt\n", __func__); + exit(1); + } + + r = kvm_vcpu_ioctl(cs, KVM_S390_INTERRUPT, &kvmint); + if (r < 0) { + fprintf(stderr, "KVM failed to inject interrupt\n"); + exit(1); + } +} + +void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) +{ + struct kvm_s390_interrupt kvmint = {}; + int r; + + r = s390_kvm_irq_to_interrupt(irq, &kvmint); + if (r < 0) { + fprintf(stderr, "%s called with bogus interrupt\n", __func__); + exit(1); + } + + r = kvm_vm_ioctl(kvm_state, KVM_S390_INTERRUPT, &kvmint); + if (r < 0) { + fprintf(stderr, "KVM failed to inject interrupt\n"); + exit(1); + } +} + void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, uint64_t parm64, int vm) { -- cgit v1.1 From de13d2161473d02ae97ec0f8e4503147554892dd Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Tue, 11 Mar 2014 13:19:43 +0100 Subject: s390x: cleanup interrupt injection Remove the need for a cpu to inject a floating interrupt on kvm. Acked-by: Thomas Huth Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 41 ++++++------------ target-s390x/interrupt.c | 38 ++++++++++------- target-s390x/kvm.c | 104 ++++++++++++++++++++------------------------- target-s390x/misc_helper.c | 7 ++- 4 files changed, 85 insertions(+), 105 deletions(-) (limited to 'target-s390x') diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 644d126..9982c35 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -357,37 +357,22 @@ void s390x_tod_timer(void *opaque); void s390x_cpu_timer(void *opaque); int s390_virtio_hypercall(CPUS390XState *env); -void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token); +void s390_virtio_irq(int config_change, uint64_t token); #ifdef CONFIG_KVM void kvm_s390_reset_vcpu(S390CPU *cpu); -void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code); -void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token); -void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, - uint64_t parm64, int vm); -void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm); +void kvm_s390_virtio_irq(int config_change, uint64_t token); +void kvm_s390_service_interrupt(uint32_t parm); void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq); void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq); #else static inline void kvm_s390_reset_vcpu(S390CPU *cpu) { } - -static inline void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code) -{ -} - -static inline void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, - uint64_t token) -{ -} - -static inline void kvm_s390_interrupt_internal(S390CPU *cpu, int type, - uint32_t parm, uint64_t parm64, - int vm) +static inline void kvm_s390_virtio_irq(int config_change, uint64_t token) { } -static inline void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm) +static inline void kvm_s390_service_interrupt(uint32_t parm) { } #endif @@ -1073,24 +1058,23 @@ void QEMU_NORETURN runtime_exception(CPUS390XState *env, int excp, uintptr_t retaddr); #ifdef CONFIG_KVM -void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, +void kvm_s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr, uint32_t io_int_parm, uint32_t io_int_word); -void kvm_s390_crw_mchk(S390CPU *cpu); +void kvm_s390_crw_mchk(void); void kvm_s390_enable_css_support(S390CPU *cpu); int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, int vq, bool assign); int kvm_s390_cpu_restart(S390CPU *cpu); void kvm_s390_clear_cmma_callback(void *opaque); #else -static inline void kvm_s390_io_interrupt(S390CPU *cpu, - uint16_t subchannel_id, +static inline void kvm_s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr, uint32_t io_int_parm, uint32_t io_int_word) { } -static inline void kvm_s390_crw_mchk(S390CPU *cpu) +static inline void kvm_s390_crw_mchk(void) { } static inline void kvm_s390_enable_css_support(S390CPU *cpu) @@ -1127,10 +1111,9 @@ static inline int s390_cpu_restart(S390CPU *cpu) return -ENOSYS; } -void s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, - uint16_t subchannel_nr, uint32_t io_int_parm, - uint32_t io_int_word); -void s390_crw_mchk(S390CPU *cpu); +void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr, + uint32_t io_int_parm, uint32_t io_int_word); +void s390_crw_mchk(void); static inline int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id, int vq, diff --git a/target-s390x/interrupt.c b/target-s390x/interrupt.c index c32bdcb..23a9114 100644 --- a/target-s390x/interrupt.c +++ b/target-s390x/interrupt.c @@ -12,50 +12,56 @@ /* * All of the following interrupts are floating, i.e. not per-vcpu. - * We just need a dummy cpustate in order to be able to inject. + * We just need a dummy cpustate in order to be able to inject in the + * non-kvm case. */ #if !defined(CONFIG_USER_ONLY) void s390_sclp_extint(uint32_t parm) { - S390CPU *dummy_cpu = s390_cpu_addr2state(0); - CPUS390XState *env = &dummy_cpu->env; - if (kvm_enabled()) { - kvm_s390_service_interrupt(dummy_cpu, parm); + kvm_s390_service_interrupt(parm); } else { + S390CPU *dummy_cpu = s390_cpu_addr2state(0); + CPUS390XState *env = &dummy_cpu->env; + env->psw.addr += 4; cpu_inject_ext(dummy_cpu, EXT_SERVICE, parm, 0); } } -void s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token) +void s390_virtio_irq(int config_change, uint64_t token) { if (kvm_enabled()) { - kvm_s390_virtio_irq(cpu, config_change, token); + kvm_s390_virtio_irq(config_change, token); } else { - cpu_inject_ext(cpu, EXT_VIRTIO, config_change, token); + S390CPU *dummy_cpu = s390_cpu_addr2state(0); + + cpu_inject_ext(dummy_cpu, EXT_VIRTIO, config_change, token); } } -void s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, - uint16_t subchannel_nr, uint32_t io_int_parm, - uint32_t io_int_word) +void s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr, + uint32_t io_int_parm, uint32_t io_int_word) { if (kvm_enabled()) { - kvm_s390_io_interrupt(cpu, subchannel_id, subchannel_nr, io_int_parm, + kvm_s390_io_interrupt(subchannel_id, subchannel_nr, io_int_parm, io_int_word); } else { - cpu_inject_io(cpu, subchannel_id, subchannel_nr, io_int_parm, + S390CPU *dummy_cpu = s390_cpu_addr2state(0); + + cpu_inject_io(dummy_cpu, subchannel_id, subchannel_nr, io_int_parm, io_int_word); } } -void s390_crw_mchk(S390CPU *cpu) +void s390_crw_mchk(void) { if (kvm_enabled()) { - kvm_s390_crw_mchk(cpu); + kvm_s390_crw_mchk(); } else { - cpu_inject_crw_mchk(cpu); + S390CPU *dummy_cpu = s390_cpu_addr2state(0); + + cpu_inject_crw_mchk(dummy_cpu); } } diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index 0d36ab4..a2133ff 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -641,52 +641,35 @@ void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) } } -void kvm_s390_interrupt_internal(S390CPU *cpu, int type, uint32_t parm, - uint64_t parm64, int vm) +void kvm_s390_virtio_irq(int config_change, uint64_t token) { - CPUState *cs = CPU(cpu); - struct kvm_s390_interrupt kvmint; - int r; - - if (!cs->kvm_state) { - return; - } - - kvmint.type = type; - kvmint.parm = parm; - kvmint.parm64 = parm64; - - if (vm) { - r = kvm_vm_ioctl(cs->kvm_state, KVM_S390_INTERRUPT, &kvmint); - } else { - r = kvm_vcpu_ioctl(cs, KVM_S390_INTERRUPT, &kvmint); - } - - if (r < 0) { - fprintf(stderr, "KVM failed to inject interrupt\n"); - exit(1); - } -} + struct kvm_s390_irq irq = { + .type = KVM_S390_INT_VIRTIO, + .u.ext.ext_params = config_change, + .u.ext.ext_params2 = token, + }; -void kvm_s390_virtio_irq(S390CPU *cpu, int config_change, uint64_t token) -{ - kvm_s390_interrupt_internal(cpu, KVM_S390_INT_VIRTIO, config_change, - token, 1); + kvm_s390_floating_interrupt(&irq); } -void kvm_s390_interrupt(S390CPU *cpu, int type, uint32_t code) +void kvm_s390_service_interrupt(uint32_t parm) { - kvm_s390_interrupt_internal(cpu, type, code, 0, 0); -} + struct kvm_s390_irq irq = { + .type = KVM_S390_INT_SERVICE, + .u.ext.ext_params = parm, + }; -void kvm_s390_service_interrupt(S390CPU *cpu, uint32_t parm) -{ - kvm_s390_interrupt_internal(cpu, KVM_S390_INT_SERVICE, parm, 0 , 1); + kvm_s390_floating_interrupt(&irq); } static void enter_pgmcheck(S390CPU *cpu, uint16_t code) { - kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code); + struct kvm_s390_irq irq = { + .type = KVM_S390_PROGRAM_INT, + .u.pgm.code = code, + }; + + kvm_s390_vcpu_interrupt(cpu, &irq); } static int kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run, @@ -902,7 +885,11 @@ static int kvm_s390_cpu_start(S390CPU *cpu) int kvm_s390_cpu_restart(S390CPU *cpu) { - kvm_s390_interrupt(cpu, KVM_S390_RESTART, 0); + struct kvm_s390_irq irq = { + .type = KVM_S390_RESTART, + }; + + kvm_s390_vcpu_interrupt(cpu, &irq); s390_add_running_cpu(cpu); qemu_cpu_kick(CPU(cpu)); DPRINTF("DONE: KVM cpu restart: %p\n", &cpu->env); @@ -1122,18 +1109,10 @@ static int handle_tsch(S390CPU *cpu) * If an I/O interrupt had been dequeued, we have to reinject it. */ if (run->s390_tsch.dequeued) { - uint16_t subchannel_id = run->s390_tsch.subchannel_id; - uint16_t subchannel_nr = run->s390_tsch.subchannel_nr; - uint32_t io_int_parm = run->s390_tsch.io_int_parm; - uint32_t io_int_word = run->s390_tsch.io_int_word; - uint32_t type = ((subchannel_id & 0xff00) << 24) | - ((subchannel_id & 0x00060) << 22) | (subchannel_nr << 16); - - kvm_s390_interrupt_internal(cpu, type, - ((uint32_t)subchannel_id << 16) - | subchannel_nr, - ((uint64_t)io_int_parm << 32) - | io_int_word, 1); + kvm_s390_io_interrupt(run->s390_tsch.subchannel_id, + run->s390_tsch.subchannel_nr, + run->s390_tsch.io_int_parm, + run->s390_tsch.io_int_word); } ret = 0; } @@ -1218,27 +1197,34 @@ int kvm_arch_on_sigbus(int code, void *addr) return 1; } -void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id, +void kvm_s390_io_interrupt(uint16_t subchannel_id, uint16_t subchannel_nr, uint32_t io_int_parm, uint32_t io_int_word) { - uint32_t type; + struct kvm_s390_irq irq = { + .u.io.subchannel_id = subchannel_id, + .u.io.subchannel_nr = subchannel_nr, + .u.io.io_int_parm = io_int_parm, + .u.io.io_int_word = io_int_word, + }; if (io_int_word & IO_INT_WORD_AI) { - type = KVM_S390_INT_IO(1, 0, 0, 0); + irq.type = KVM_S390_INT_IO(1, 0, 0, 0); } else { - type = ((subchannel_id & 0xff00) << 24) | + irq.type = ((subchannel_id & 0xff00) << 24) | ((subchannel_id & 0x00060) << 22) | (subchannel_nr << 16); } - kvm_s390_interrupt_internal(cpu, type, - ((uint32_t)subchannel_id << 16) | subchannel_nr, - ((uint64_t)io_int_parm << 32) | io_int_word, 1); + kvm_s390_floating_interrupt(&irq); } -void kvm_s390_crw_mchk(S390CPU *cpu) +void kvm_s390_crw_mchk(void) { - kvm_s390_interrupt_internal(cpu, KVM_S390_MCHK, 1 << 28, - 0x00400f1d40330000, 1); + struct kvm_s390_irq irq = { + .type = KVM_S390_MCHK, + .u.mchk.cr14 = 1 << 28, + .u.mchk.mcic = 0x00400f1d40330000, + }; + kvm_s390_floating_interrupt(&irq); } void kvm_s390_enable_css_support(S390CPU *cpu) diff --git a/target-s390x/misc_helper.c b/target-s390x/misc_helper.c index 519edb8..0b62582 100644 --- a/target-s390x/misc_helper.c +++ b/target-s390x/misc_helper.c @@ -85,7 +85,12 @@ void program_interrupt(CPUS390XState *env, uint32_t code, int ilen) if (kvm_enabled()) { #ifdef CONFIG_KVM - kvm_s390_interrupt(cpu, KVM_S390_PROGRAM_INT, code); + struct kvm_s390_irq irq = { + .type = KVM_S390_PROGRAM_INT, + .u.pgm.code = code, + }; + + kvm_s390_vcpu_interrupt(cpu, &irq); #endif } else { CPUState *cs = CPU(cpu); -- cgit v1.1 From bbd8bb8e3245cf6fc6d12b10b3320ab183adb866 Mon Sep 17 00:00:00 2001 From: Cornelia Huck Date: Wed, 12 Mar 2014 12:40:31 +0100 Subject: s390x/kvm: inject via flic Try to inject floating interrupts via the flic if it is available. This allows us to inject the full range of floating interrupts. Reviewed-by: Jens Freimann Signed-off-by: Cornelia Huck --- target-s390x/cpu.h | 1 + target-s390x/kvm.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'target-s390x') diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h index 9982c35..b13761d 100644 --- a/target-s390x/cpu.h +++ b/target-s390x/cpu.h @@ -365,6 +365,7 @@ void kvm_s390_virtio_irq(int config_change, uint64_t token); void kvm_s390_service_interrupt(uint32_t parm); void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq); void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq); +int kvm_s390_inject_flic(struct kvm_s390_irq *irq); #else static inline void kvm_s390_reset_vcpu(S390CPU *cpu) { diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index a2133ff..a1a4cc2 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -623,7 +623,7 @@ void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq) } } -void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) +static void __kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) { struct kvm_s390_interrupt kvmint = {}; int r; @@ -641,6 +641,23 @@ void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) } } +void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq) +{ + static bool use_flic = true; + int r; + + if (use_flic) { + r = kvm_s390_inject_flic(irq); + if (r == -ENOSYS) { + use_flic = false; + } + if (!r) { + return; + } + } + __kvm_s390_floating_interrupt(irq); +} + void kvm_s390_virtio_irq(int config_change, uint64_t token) { struct kvm_s390_irq irq = { -- cgit v1.1