Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling kvm guest interrupts |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 3 | * |
Thomas Huth | 33b412a | 2015-02-11 10:38:46 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2015 |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License (version 2 only) |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 11 | */ |
| 12 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 14 | #include <linux/kvm_host.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 15 | #include <linux/hrtimer.h> |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 16 | #include <linux/mmu_context.h> |
Christian Borntraeger | 3cd6129 | 2008-07-25 15:51:54 +0200 | [diff] [blame] | 17 | #include <linux/signal.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 19 | #include <linux/bitmap.h> |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 20 | #include <linux/vmalloc.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 21 | #include <asm/asm-offsets.h> |
Thomas Huth | 33b412a | 2015-02-11 10:38:46 +0100 | [diff] [blame] | 22 | #include <asm/dis.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 23 | #include <asm/uaccess.h> |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 24 | #include <asm/sclp.h> |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 25 | #include <asm/isc.h> |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 26 | #include "kvm-s390.h" |
| 27 | #include "gaccess.h" |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 28 | #include "trace-s390.h" |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 29 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 30 | #define IOINT_SCHID_MASK 0x0000ffff |
| 31 | #define IOINT_SSID_MASK 0x00030000 |
| 32 | #define IOINT_CSSID_MASK 0x03fc0000 |
Jens Freimann | 44c6ca3 | 2014-04-16 13:57:18 +0200 | [diff] [blame] | 33 | #define PFAULT_INIT 0x0600 |
Jens Freimann | 60f90a1 | 2014-11-10 17:20:07 +0100 | [diff] [blame] | 34 | #define PFAULT_DONE 0x0680 |
| 35 | #define VIRTIO_PARAM 0x0d00 |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 36 | |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 37 | /* handle external calls via sigp interpretation facility */ |
| 38 | static int sca_ext_call_pending(struct kvm_vcpu *vcpu, int *src_id) |
| 39 | { |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 40 | struct bsca_block *sca = vcpu->kvm->arch.sca; |
| 41 | union bsca_sigp_ctrl sigp_ctrl = sca->cpu[vcpu->vcpu_id].sigp_ctrl; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 42 | |
| 43 | if (src_id) |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 44 | *src_id = sigp_ctrl.scn; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 45 | |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 46 | return sigp_ctrl.c && |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 47 | atomic_read(&vcpu->arch.sie_block->cpuflags) & |
| 48 | CPUSTAT_ECALL_PEND; |
| 49 | } |
| 50 | |
| 51 | static int sca_inject_ext_call(struct kvm_vcpu *vcpu, int src_id) |
| 52 | { |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 53 | int expect, rc; |
| 54 | struct bsca_block *sca = vcpu->kvm->arch.sca; |
| 55 | union bsca_sigp_ctrl *sigp_ctrl = &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); |
| 56 | union bsca_sigp_ctrl new_val = {0}, old_val = *sigp_ctrl; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 57 | |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 58 | new_val.scn = src_id; |
| 59 | new_val.c = 1; |
| 60 | old_val.c = 0; |
| 61 | |
| 62 | expect = old_val.value; |
| 63 | rc = cmpxchg(&sigp_ctrl->value, old_val.value, new_val.value); |
| 64 | |
| 65 | if (rc != expect) { |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 66 | /* another external call is pending */ |
| 67 | return -EBUSY; |
| 68 | } |
| 69 | atomic_or(CPUSTAT_ECALL_PEND, &vcpu->arch.sie_block->cpuflags); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static void sca_clear_ext_call(struct kvm_vcpu *vcpu) |
| 74 | { |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 75 | struct bsca_block *sca = vcpu->kvm->arch.sca; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 76 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 77 | union bsca_sigp_ctrl *sigp_ctrl = &(sca->cpu[vcpu->vcpu_id].sigp_ctrl); |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 78 | |
| 79 | atomic_andnot(CPUSTAT_ECALL_PEND, li->cpuflags); |
Eugene (jno) Dvurechenski | bc784cc | 2015-04-23 16:09:06 +0200 | [diff] [blame^] | 80 | sigp_ctrl->value = 0; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 83 | int psw_extint_disabled(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 84 | { |
| 85 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT); |
| 86 | } |
| 87 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 88 | static int psw_ioint_disabled(struct kvm_vcpu *vcpu) |
| 89 | { |
| 90 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO); |
| 91 | } |
| 92 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 93 | static int psw_mchk_disabled(struct kvm_vcpu *vcpu) |
| 94 | { |
| 95 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK); |
| 96 | } |
| 97 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 98 | static int psw_interrupts_disabled(struct kvm_vcpu *vcpu) |
| 99 | { |
David Hildenbrand | fee0e0fd | 2015-09-28 13:32:38 +0200 | [diff] [blame] | 100 | return psw_extint_disabled(vcpu) && |
| 101 | psw_ioint_disabled(vcpu) && |
| 102 | psw_mchk_disabled(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 103 | } |
| 104 | |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 105 | static int ckc_interrupts_enabled(struct kvm_vcpu *vcpu) |
| 106 | { |
| 107 | if (psw_extint_disabled(vcpu) || |
| 108 | !(vcpu->arch.sie_block->gcr[0] & 0x800ul)) |
| 109 | return 0; |
David Hildenbrand | f71d0dc | 2014-03-18 10:06:14 +0100 | [diff] [blame] | 110 | if (guestdbg_enabled(vcpu) && guestdbg_sstep_enabled(vcpu)) |
| 111 | /* No timer interrupts when single stepping */ |
| 112 | return 0; |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 113 | return 1; |
| 114 | } |
| 115 | |
David Hildenbrand | b4aec92 | 2014-12-01 15:55:42 +0100 | [diff] [blame] | 116 | static int ckc_irq_pending(struct kvm_vcpu *vcpu) |
| 117 | { |
David Hildenbrand | 60417fc | 2015-09-29 16:20:36 +0200 | [diff] [blame] | 118 | if (vcpu->arch.sie_block->ckc >= kvm_s390_get_tod_clock_fast(vcpu->kvm)) |
David Hildenbrand | b4aec92 | 2014-12-01 15:55:42 +0100 | [diff] [blame] | 119 | return 0; |
| 120 | return ckc_interrupts_enabled(vcpu); |
| 121 | } |
| 122 | |
| 123 | static int cpu_timer_interrupts_enabled(struct kvm_vcpu *vcpu) |
| 124 | { |
| 125 | return !psw_extint_disabled(vcpu) && |
| 126 | (vcpu->arch.sie_block->gcr[0] & 0x400ul); |
| 127 | } |
| 128 | |
| 129 | static int cpu_timer_irq_pending(struct kvm_vcpu *vcpu) |
| 130 | { |
| 131 | return (vcpu->arch.sie_block->cputm >> 63) && |
| 132 | cpu_timer_interrupts_enabled(vcpu); |
| 133 | } |
| 134 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 135 | static inline int is_ioirq(unsigned long irq_type) |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 136 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 137 | return ((irq_type >= IRQ_PEND_IO_ISC_0) && |
| 138 | (irq_type <= IRQ_PEND_IO_ISC_7)); |
| 139 | } |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 140 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 141 | static uint64_t isc_to_isc_bits(int isc) |
| 142 | { |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 143 | return (0x80 >> isc) << 24; |
| 144 | } |
| 145 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 146 | static inline u8 int_word_to_isc(u32 int_word) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 147 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 148 | return (int_word & 0x38000000) >> 27; |
| 149 | } |
| 150 | |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 151 | static inline unsigned long pending_irqs(struct kvm_vcpu *vcpu) |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 152 | { |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 153 | return vcpu->kvm->arch.float_int.pending_irqs | |
| 154 | vcpu->arch.local_int.pending_irqs; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 157 | static unsigned long disable_iscs(struct kvm_vcpu *vcpu, |
| 158 | unsigned long active_mask) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 159 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 160 | int i; |
| 161 | |
| 162 | for (i = 0; i <= MAX_ISC; i++) |
| 163 | if (!(vcpu->arch.sie_block->gcr[6] & isc_to_isc_bits(i))) |
| 164 | active_mask &= ~(1UL << (IRQ_PEND_IO_ISC_0 + i)); |
| 165 | |
| 166 | return active_mask; |
| 167 | } |
| 168 | |
| 169 | static unsigned long deliverable_irqs(struct kvm_vcpu *vcpu) |
| 170 | { |
| 171 | unsigned long active_mask; |
| 172 | |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 173 | active_mask = pending_irqs(vcpu); |
Jens Freimann | ffeca0a | 2015-04-17 10:21:04 +0200 | [diff] [blame] | 174 | if (!active_mask) |
| 175 | return 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 176 | |
| 177 | if (psw_extint_disabled(vcpu)) |
| 178 | active_mask &= ~IRQ_PEND_EXT_MASK; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 179 | if (psw_ioint_disabled(vcpu)) |
| 180 | active_mask &= ~IRQ_PEND_IO_MASK; |
| 181 | else |
| 182 | active_mask = disable_iscs(vcpu, active_mask); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 183 | if (!(vcpu->arch.sie_block->gcr[0] & 0x2000ul)) |
| 184 | __clear_bit(IRQ_PEND_EXT_EXTERNAL, &active_mask); |
| 185 | if (!(vcpu->arch.sie_block->gcr[0] & 0x4000ul)) |
| 186 | __clear_bit(IRQ_PEND_EXT_EMERGENCY, &active_mask); |
| 187 | if (!(vcpu->arch.sie_block->gcr[0] & 0x800ul)) |
| 188 | __clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &active_mask); |
| 189 | if (!(vcpu->arch.sie_block->gcr[0] & 0x400ul)) |
| 190 | __clear_bit(IRQ_PEND_EXT_CPU_TIMER, &active_mask); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 191 | if (!(vcpu->arch.sie_block->gcr[0] & 0x200ul)) |
| 192 | __clear_bit(IRQ_PEND_EXT_SERVICE, &active_mask); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 193 | if (psw_mchk_disabled(vcpu)) |
| 194 | active_mask &= ~IRQ_PEND_MCHK_MASK; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 195 | if (!(vcpu->arch.sie_block->gcr[14] & |
| 196 | vcpu->kvm->arch.float_int.mchk.cr14)) |
| 197 | __clear_bit(IRQ_PEND_MCHK_REP, &active_mask); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 198 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 199 | /* |
| 200 | * STOP irqs will never be actively delivered. They are triggered via |
| 201 | * intercept requests and cleared when the stop intercept is performed. |
| 202 | */ |
| 203 | __clear_bit(IRQ_PEND_SIGP_STOP, &active_mask); |
| 204 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 205 | return active_mask; |
| 206 | } |
| 207 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 208 | static void __set_cpu_idle(struct kvm_vcpu *vcpu) |
| 209 | { |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 210 | atomic_or(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 211 | set_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 212 | } |
| 213 | |
| 214 | static void __unset_cpu_idle(struct kvm_vcpu *vcpu) |
| 215 | { |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 216 | atomic_andnot(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 217 | clear_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 218 | } |
| 219 | |
| 220 | static void __reset_intercept_indicators(struct kvm_vcpu *vcpu) |
| 221 | { |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 222 | atomic_andnot(CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT, |
| 223 | &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 224 | vcpu->arch.sie_block->lctl = 0x0000; |
David Hildenbrand | 27291e2 | 2014-01-23 12:26:52 +0100 | [diff] [blame] | 225 | vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW | ICTL_STCTL | ICTL_PINT); |
| 226 | |
| 227 | if (guestdbg_enabled(vcpu)) { |
| 228 | vcpu->arch.sie_block->lctl |= (LCTL_CR0 | LCTL_CR9 | |
| 229 | LCTL_CR10 | LCTL_CR11); |
| 230 | vcpu->arch.sie_block->ictl |= (ICTL_STCTL | ICTL_PINT); |
| 231 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) |
| 235 | { |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 236 | atomic_or(flag, &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 239 | static void set_intercept_indicators_io(struct kvm_vcpu *vcpu) |
| 240 | { |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 241 | if (!(pending_irqs(vcpu) & IRQ_PEND_IO_MASK)) |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 242 | return; |
| 243 | else if (psw_ioint_disabled(vcpu)) |
| 244 | __set_cpuflag(vcpu, CPUSTAT_IO_INT); |
| 245 | else |
| 246 | vcpu->arch.sie_block->lctl |= LCTL_CR6; |
| 247 | } |
| 248 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 249 | static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) |
| 250 | { |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 251 | if (!(pending_irqs(vcpu) & IRQ_PEND_EXT_MASK)) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 252 | return; |
| 253 | if (psw_extint_disabled(vcpu)) |
| 254 | __set_cpuflag(vcpu, CPUSTAT_EXT_INT); |
| 255 | else |
| 256 | vcpu->arch.sie_block->lctl |= LCTL_CR0; |
| 257 | } |
| 258 | |
| 259 | static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu) |
| 260 | { |
David Hildenbrand | 5f94c58 | 2015-09-28 14:27:51 +0200 | [diff] [blame] | 261 | if (!(pending_irqs(vcpu) & IRQ_PEND_MCHK_MASK)) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 262 | return; |
| 263 | if (psw_mchk_disabled(vcpu)) |
| 264 | vcpu->arch.sie_block->ictl |= ICTL_LPSW; |
| 265 | else |
| 266 | vcpu->arch.sie_block->lctl |= LCTL_CR14; |
| 267 | } |
| 268 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 269 | static void set_intercept_indicators_stop(struct kvm_vcpu *vcpu) |
| 270 | { |
| 271 | if (kvm_s390_is_stop_irq_pending(vcpu)) |
| 272 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
| 273 | } |
| 274 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 275 | /* Set interception request for non-deliverable interrupts */ |
| 276 | static void set_intercept_indicators(struct kvm_vcpu *vcpu) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 277 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 278 | set_intercept_indicators_io(vcpu); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 279 | set_intercept_indicators_ext(vcpu); |
| 280 | set_intercept_indicators_mchk(vcpu); |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 281 | set_intercept_indicators_stop(vcpu); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 284 | static u16 get_ilc(struct kvm_vcpu *vcpu) |
| 285 | { |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 286 | switch (vcpu->arch.sie_block->icptcode) { |
| 287 | case ICPT_INST: |
| 288 | case ICPT_INSTPROGI: |
| 289 | case ICPT_OPEREXC: |
| 290 | case ICPT_PARTEXEC: |
| 291 | case ICPT_IOINST: |
| 292 | /* last instruction only stored for these icptcodes */ |
Thomas Huth | 33b412a | 2015-02-11 10:38:46 +0100 | [diff] [blame] | 293 | return insn_length(vcpu->arch.sie_block->ipa >> 8); |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 294 | case ICPT_PROGI: |
| 295 | return vcpu->arch.sie_block->pgmilc; |
| 296 | default: |
| 297 | return 0; |
| 298 | } |
| 299 | } |
| 300 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 301 | static int __must_check __deliver_cpu_timer(struct kvm_vcpu *vcpu) |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 302 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 303 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 304 | int rc; |
| 305 | |
| 306 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, |
| 307 | 0, 0); |
| 308 | |
| 309 | rc = put_guest_lc(vcpu, EXT_IRQ_CPU_TIMER, |
| 310 | (u16 *)__LC_EXT_INT_CODE); |
David Hildenbrand | 467fc29 | 2014-12-01 12:02:44 +0100 | [diff] [blame] | 311 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 312 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 313 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 314 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 315 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 316 | clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 317 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static int __must_check __deliver_ckc(struct kvm_vcpu *vcpu) |
| 321 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 322 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 323 | int rc; |
| 324 | |
| 325 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, |
| 326 | 0, 0); |
| 327 | |
| 328 | rc = put_guest_lc(vcpu, EXT_IRQ_CLK_COMP, |
| 329 | (u16 __user *)__LC_EXT_INT_CODE); |
David Hildenbrand | 467fc29 | 2014-12-01 12:02:44 +0100 | [diff] [blame] | 330 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 331 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 332 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 333 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 334 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 335 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 336 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 339 | static int __must_check __deliver_pfault_init(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 340 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 341 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 342 | struct kvm_s390_ext_info ext; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 343 | int rc; |
| 344 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 345 | spin_lock(&li->lock); |
| 346 | ext = li->irq.ext; |
| 347 | clear_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); |
| 348 | li->irq.ext.ext_params2 = 0; |
| 349 | spin_unlock(&li->lock); |
| 350 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 351 | VCPU_EVENT(vcpu, 4, "deliver: pfault init token 0x%llx", |
| 352 | ext.ext_params2); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 353 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 354 | KVM_S390_INT_PFAULT_INIT, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 355 | 0, ext.ext_params2); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 356 | |
| 357 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *) __LC_EXT_INT_CODE); |
| 358 | rc |= put_guest_lc(vcpu, PFAULT_INIT, (u16 *) __LC_EXT_CPU_ADDR); |
| 359 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 360 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 361 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 362 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 363 | rc |= put_guest_lc(vcpu, ext.ext_params2, (u64 *) __LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 364 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 367 | static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 368 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 369 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 370 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 371 | struct kvm_s390_mchk_info mchk = {}; |
Eric Farman | bc17de7 | 2014-04-14 16:01:09 -0400 | [diff] [blame] | 372 | unsigned long adtl_status_addr; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 373 | int deliver = 0; |
| 374 | int rc = 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 375 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 376 | spin_lock(&fi->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 377 | spin_lock(&li->lock); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 378 | if (test_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs) || |
| 379 | test_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs)) { |
| 380 | /* |
| 381 | * If there was an exigent machine check pending, then any |
| 382 | * repressible machine checks that might have been pending |
| 383 | * are indicated along with it, so always clear bits for |
| 384 | * repressible and exigent interrupts |
| 385 | */ |
| 386 | mchk = li->irq.mchk; |
| 387 | clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); |
| 388 | clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); |
| 389 | memset(&li->irq.mchk, 0, sizeof(mchk)); |
| 390 | deliver = 1; |
| 391 | } |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 392 | /* |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 393 | * We indicate floating repressible conditions along with |
| 394 | * other pending conditions. Channel Report Pending and Channel |
| 395 | * Subsystem damage are the only two and and are indicated by |
| 396 | * bits in mcic and masked in cr14. |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 397 | */ |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 398 | if (test_and_clear_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { |
| 399 | mchk.mcic |= fi->mchk.mcic; |
| 400 | mchk.cr14 |= fi->mchk.cr14; |
| 401 | memset(&fi->mchk, 0, sizeof(mchk)); |
| 402 | deliver = 1; |
| 403 | } |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 404 | spin_unlock(&li->lock); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 405 | spin_unlock(&fi->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 406 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 407 | if (deliver) { |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 408 | VCPU_EVENT(vcpu, 3, "deliver: machine check mcic 0x%llx", |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 409 | mchk.mcic); |
| 410 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 411 | KVM_S390_MCHK, |
| 412 | mchk.cr14, mchk.mcic); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 413 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 414 | rc = kvm_s390_vcpu_store_status(vcpu, |
| 415 | KVM_S390_STORE_STATUS_PREFIXED); |
| 416 | rc |= read_guest_lc(vcpu, __LC_VX_SAVE_AREA_ADDR, |
| 417 | &adtl_status_addr, |
| 418 | sizeof(unsigned long)); |
| 419 | rc |= kvm_s390_vcpu_store_adtl_status(vcpu, |
| 420 | adtl_status_addr); |
| 421 | rc |= put_guest_lc(vcpu, mchk.mcic, |
| 422 | (u64 __user *) __LC_MCCK_CODE); |
| 423 | rc |= put_guest_lc(vcpu, mchk.failing_storage_address, |
| 424 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); |
| 425 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, |
| 426 | &mchk.fixed_logout, |
| 427 | sizeof(mchk.fixed_logout)); |
| 428 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, |
| 429 | &vcpu->arch.sie_block->gpsw, |
| 430 | sizeof(psw_t)); |
| 431 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, |
| 432 | &vcpu->arch.sie_block->gpsw, |
| 433 | sizeof(psw_t)); |
| 434 | } |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 435 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static int __must_check __deliver_restart(struct kvm_vcpu *vcpu) |
| 439 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 440 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 441 | int rc; |
| 442 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 443 | VCPU_EVENT(vcpu, 3, "%s", "deliver: cpu restart"); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 444 | vcpu->stat.deliver_restart_signal++; |
| 445 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0); |
| 446 | |
| 447 | rc = write_guest_lc(vcpu, |
| 448 | offsetof(struct _lowcore, restart_old_psw), |
| 449 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 450 | rc |= read_guest_lc(vcpu, offsetof(struct _lowcore, restart_psw), |
| 451 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 452 | clear_bit(IRQ_PEND_RESTART, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 453 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 454 | } |
| 455 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 456 | static int __must_check __deliver_set_prefix(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 457 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 458 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 459 | struct kvm_s390_prefix_info prefix; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 460 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 461 | spin_lock(&li->lock); |
| 462 | prefix = li->irq.prefix; |
| 463 | li->irq.prefix.address = 0; |
| 464 | clear_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); |
| 465 | spin_unlock(&li->lock); |
| 466 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 467 | vcpu->stat.deliver_prefix_signal++; |
| 468 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 469 | KVM_S390_SIGP_SET_PREFIX, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 470 | prefix.address, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 471 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 472 | kvm_s390_set_prefix(vcpu, prefix.address); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 473 | return 0; |
| 474 | } |
| 475 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 476 | static int __must_check __deliver_emergency_signal(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 477 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 478 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 479 | int rc; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 480 | int cpu_addr; |
| 481 | |
| 482 | spin_lock(&li->lock); |
| 483 | cpu_addr = find_first_bit(li->sigp_emerg_pending, KVM_MAX_VCPUS); |
| 484 | clear_bit(cpu_addr, li->sigp_emerg_pending); |
| 485 | if (bitmap_empty(li->sigp_emerg_pending, KVM_MAX_VCPUS)) |
| 486 | clear_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); |
| 487 | spin_unlock(&li->lock); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 488 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 489 | VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp emerg"); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 490 | vcpu->stat.deliver_emergency_signal++; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 491 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, |
| 492 | cpu_addr, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 493 | |
| 494 | rc = put_guest_lc(vcpu, EXT_IRQ_EMERGENCY_SIG, |
| 495 | (u16 *)__LC_EXT_INT_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 496 | rc |= put_guest_lc(vcpu, cpu_addr, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 497 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 498 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 499 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 500 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 501 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 502 | } |
| 503 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 504 | static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 505 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 506 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 507 | struct kvm_s390_extcall_info extcall; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 508 | int rc; |
| 509 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 510 | spin_lock(&li->lock); |
| 511 | extcall = li->irq.extcall; |
| 512 | li->irq.extcall.code = 0; |
| 513 | clear_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); |
| 514 | spin_unlock(&li->lock); |
| 515 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 516 | VCPU_EVENT(vcpu, 4, "%s", "deliver: sigp ext call"); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 517 | vcpu->stat.deliver_external_call++; |
| 518 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 519 | KVM_S390_INT_EXTERNAL_CALL, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 520 | extcall.code, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 521 | |
| 522 | rc = put_guest_lc(vcpu, EXT_IRQ_EXTERNAL_CALL, |
| 523 | (u16 *)__LC_EXT_INT_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 524 | rc |= put_guest_lc(vcpu, extcall.code, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 525 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 526 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 527 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &vcpu->arch.sie_block->gpsw, |
| 528 | sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 529 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 530 | } |
| 531 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 532 | static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 533 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 534 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 535 | struct kvm_s390_pgm_info pgm_info; |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 536 | int rc = 0, nullifying = false; |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 537 | u16 ilc = get_ilc(vcpu); |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 538 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 539 | spin_lock(&li->lock); |
| 540 | pgm_info = li->irq.pgm; |
| 541 | clear_bit(IRQ_PEND_PROG, &li->pending_irqs); |
| 542 | memset(&li->irq.pgm, 0, sizeof(pgm_info)); |
| 543 | spin_unlock(&li->lock); |
| 544 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 545 | VCPU_EVENT(vcpu, 3, "deliver: program irq code 0x%x, ilc:%d", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 546 | pgm_info.code, ilc); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 547 | vcpu->stat.deliver_program_int++; |
| 548 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 549 | pgm_info.code, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 550 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 551 | switch (pgm_info.code & ~PGM_PER) { |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 552 | case PGM_AFX_TRANSLATION: |
| 553 | case PGM_ASX_TRANSLATION: |
| 554 | case PGM_EX_TRANSLATION: |
| 555 | case PGM_LFX_TRANSLATION: |
| 556 | case PGM_LSTE_SEQUENCE: |
| 557 | case PGM_LSX_TRANSLATION: |
| 558 | case PGM_LX_TRANSLATION: |
| 559 | case PGM_PRIMARY_AUTHORITY: |
| 560 | case PGM_SECONDARY_AUTHORITY: |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 561 | nullifying = true; |
| 562 | /* fall through */ |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 563 | case PGM_SPACE_SWITCH: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 564 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 565 | (u64 *)__LC_TRANS_EXC_CODE); |
| 566 | break; |
| 567 | case PGM_ALEN_TRANSLATION: |
| 568 | case PGM_ALE_SEQUENCE: |
| 569 | case PGM_ASTE_INSTANCE: |
| 570 | case PGM_ASTE_SEQUENCE: |
| 571 | case PGM_ASTE_VALIDITY: |
| 572 | case PGM_EXTENDED_AUTHORITY: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 573 | rc = put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 574 | (u8 *)__LC_EXC_ACCESS_ID); |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 575 | nullifying = true; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 576 | break; |
| 577 | case PGM_ASCE_TYPE: |
| 578 | case PGM_PAGE_TRANSLATION: |
| 579 | case PGM_REGION_FIRST_TRANS: |
| 580 | case PGM_REGION_SECOND_TRANS: |
| 581 | case PGM_REGION_THIRD_TRANS: |
| 582 | case PGM_SEGMENT_TRANSLATION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 583 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 584 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 585 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 586 | (u8 *)__LC_EXC_ACCESS_ID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 587 | rc |= put_guest_lc(vcpu, pgm_info.op_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 588 | (u8 *)__LC_OP_ACCESS_ID); |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 589 | nullifying = true; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 590 | break; |
| 591 | case PGM_MONITOR: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 592 | rc = put_guest_lc(vcpu, pgm_info.mon_class_nr, |
Thomas Huth | a36c539 | 2014-10-16 14:31:53 +0200 | [diff] [blame] | 593 | (u16 *)__LC_MON_CLASS_NR); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 594 | rc |= put_guest_lc(vcpu, pgm_info.mon_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 595 | (u64 *)__LC_MON_CODE); |
| 596 | break; |
Eric Farman | 403c864 | 2015-02-02 15:01:06 -0500 | [diff] [blame] | 597 | case PGM_VECTOR_PROCESSING: |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 598 | case PGM_DATA: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 599 | rc = put_guest_lc(vcpu, pgm_info.data_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 600 | (u32 *)__LC_DATA_EXC_CODE); |
| 601 | break; |
| 602 | case PGM_PROTECTION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 603 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 604 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 605 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 606 | (u8 *)__LC_EXC_ACCESS_ID); |
| 607 | break; |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 608 | case PGM_STACK_FULL: |
| 609 | case PGM_STACK_EMPTY: |
| 610 | case PGM_STACK_SPECIFICATION: |
| 611 | case PGM_STACK_TYPE: |
| 612 | case PGM_STACK_OPERATION: |
| 613 | case PGM_TRACE_TABEL: |
| 614 | case PGM_CRYPTO_OPERATION: |
| 615 | nullifying = true; |
| 616 | break; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 617 | } |
| 618 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 619 | if (pgm_info.code & PGM_PER) { |
| 620 | rc |= put_guest_lc(vcpu, pgm_info.per_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 621 | (u8 *) __LC_PER_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 622 | rc |= put_guest_lc(vcpu, pgm_info.per_atmid, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 623 | (u8 *)__LC_PER_ATMID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 624 | rc |= put_guest_lc(vcpu, pgm_info.per_address, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 625 | (u64 *) __LC_PER_ADDRESS); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 626 | rc |= put_guest_lc(vcpu, pgm_info.per_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 627 | (u8 *) __LC_PER_ACCESS_ID); |
| 628 | } |
| 629 | |
Thomas Huth | a9a846fd | 2015-02-05 09:06:56 +0100 | [diff] [blame] | 630 | if (nullifying && vcpu->arch.sie_block->icptcode == ICPT_INST) |
| 631 | kvm_s390_rewind_psw(vcpu, ilc); |
| 632 | |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 633 | rc |= put_guest_lc(vcpu, ilc, (u16 *) __LC_PGM_ILC); |
David Hildenbrand | 2ba4596 | 2015-03-25 13:12:32 +0100 | [diff] [blame] | 634 | rc |= put_guest_lc(vcpu, vcpu->arch.sie_block->gbea, |
| 635 | (u64 *) __LC_LAST_BREAK); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 636 | rc |= put_guest_lc(vcpu, pgm_info.code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 637 | (u16 *)__LC_PGM_INT_CODE); |
| 638 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, |
| 639 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 640 | rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, |
| 641 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 642 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 643 | } |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 644 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 645 | static int __must_check __deliver_service(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 646 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 647 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 648 | struct kvm_s390_ext_info ext; |
| 649 | int rc = 0; |
| 650 | |
| 651 | spin_lock(&fi->lock); |
| 652 | if (!(test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs))) { |
| 653 | spin_unlock(&fi->lock); |
| 654 | return 0; |
| 655 | } |
| 656 | ext = fi->srv_signal; |
| 657 | memset(&fi->srv_signal, 0, sizeof(ext)); |
| 658 | clear_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); |
| 659 | spin_unlock(&fi->lock); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 660 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 661 | VCPU_EVENT(vcpu, 4, "deliver: sclp parameter 0x%x", |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 662 | ext.ext_params); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 663 | vcpu->stat.deliver_service_signal++; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 664 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_SERVICE, |
| 665 | ext.ext_params, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 666 | |
| 667 | rc = put_guest_lc(vcpu, EXT_IRQ_SERVICE_SIG, (u16 *)__LC_EXT_INT_CODE); |
David Hildenbrand | 467fc29 | 2014-12-01 12:02:44 +0100 | [diff] [blame] | 668 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 669 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 670 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 671 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 672 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 673 | rc |= put_guest_lc(vcpu, ext.ext_params, |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 674 | (u32 *)__LC_EXT_PARAMS); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 675 | |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 676 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 679 | static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 680 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 681 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 682 | struct kvm_s390_interrupt_info *inti; |
| 683 | int rc = 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 684 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 685 | spin_lock(&fi->lock); |
| 686 | inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_PFAULT], |
| 687 | struct kvm_s390_interrupt_info, |
| 688 | list); |
| 689 | if (inti) { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 690 | list_del(&inti->list); |
| 691 | fi->counters[FIRQ_CNTR_PFAULT] -= 1; |
| 692 | } |
| 693 | if (list_empty(&fi->lists[FIRQ_LIST_PFAULT])) |
| 694 | clear_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); |
| 695 | spin_unlock(&fi->lock); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 696 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 697 | if (inti) { |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 698 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 699 | KVM_S390_INT_PFAULT_DONE, 0, |
| 700 | inti->ext.ext_params2); |
| 701 | VCPU_EVENT(vcpu, 4, "deliver: pfault done token 0x%llx", |
| 702 | inti->ext.ext_params2); |
| 703 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 704 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, |
| 705 | (u16 *)__LC_EXT_INT_CODE); |
| 706 | rc |= put_guest_lc(vcpu, PFAULT_DONE, |
| 707 | (u16 *)__LC_EXT_CPU_ADDR); |
| 708 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 709 | &vcpu->arch.sie_block->gpsw, |
| 710 | sizeof(psw_t)); |
| 711 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 712 | &vcpu->arch.sie_block->gpsw, |
| 713 | sizeof(psw_t)); |
| 714 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 715 | (u64 *)__LC_EXT_PARAMS2); |
| 716 | kfree(inti); |
| 717 | } |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 718 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 719 | } |
| 720 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 721 | static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 722 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 723 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 724 | struct kvm_s390_interrupt_info *inti; |
| 725 | int rc = 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 726 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 727 | spin_lock(&fi->lock); |
| 728 | inti = list_first_entry_or_null(&fi->lists[FIRQ_LIST_VIRTIO], |
| 729 | struct kvm_s390_interrupt_info, |
| 730 | list); |
| 731 | if (inti) { |
| 732 | VCPU_EVENT(vcpu, 4, |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 733 | "deliver: virtio parm: 0x%x,parm64: 0x%llx", |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 734 | inti->ext.ext_params, inti->ext.ext_params2); |
| 735 | vcpu->stat.deliver_virtio_interrupt++; |
| 736 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 737 | inti->type, |
| 738 | inti->ext.ext_params, |
| 739 | inti->ext.ext_params2); |
| 740 | list_del(&inti->list); |
| 741 | fi->counters[FIRQ_CNTR_VIRTIO] -= 1; |
| 742 | } |
| 743 | if (list_empty(&fi->lists[FIRQ_LIST_VIRTIO])) |
| 744 | clear_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); |
| 745 | spin_unlock(&fi->lock); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 746 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 747 | if (inti) { |
| 748 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, |
| 749 | (u16 *)__LC_EXT_INT_CODE); |
| 750 | rc |= put_guest_lc(vcpu, VIRTIO_PARAM, |
| 751 | (u16 *)__LC_EXT_CPU_ADDR); |
| 752 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 753 | &vcpu->arch.sie_block->gpsw, |
| 754 | sizeof(psw_t)); |
| 755 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 756 | &vcpu->arch.sie_block->gpsw, |
| 757 | sizeof(psw_t)); |
| 758 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 759 | (u32 *)__LC_EXT_PARAMS); |
| 760 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 761 | (u64 *)__LC_EXT_PARAMS2); |
| 762 | kfree(inti); |
| 763 | } |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 764 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | static int __must_check __deliver_io(struct kvm_vcpu *vcpu, |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 768 | unsigned long irq_type) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 769 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 770 | struct list_head *isc_list; |
| 771 | struct kvm_s390_float_interrupt *fi; |
| 772 | struct kvm_s390_interrupt_info *inti = NULL; |
| 773 | int rc = 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 774 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 775 | fi = &vcpu->kvm->arch.float_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 776 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 777 | spin_lock(&fi->lock); |
| 778 | isc_list = &fi->lists[irq_type - IRQ_PEND_IO_ISC_0]; |
| 779 | inti = list_first_entry_or_null(isc_list, |
| 780 | struct kvm_s390_interrupt_info, |
| 781 | list); |
| 782 | if (inti) { |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 783 | VCPU_EVENT(vcpu, 4, "deliver: I/O 0x%llx", inti->type); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 784 | vcpu->stat.deliver_io_int++; |
| 785 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 786 | inti->type, |
| 787 | ((__u32)inti->io.subchannel_id << 16) | |
| 788 | inti->io.subchannel_nr, |
| 789 | ((__u64)inti->io.io_int_parm << 32) | |
| 790 | inti->io.io_int_word); |
| 791 | list_del(&inti->list); |
| 792 | fi->counters[FIRQ_CNTR_IO] -= 1; |
| 793 | } |
| 794 | if (list_empty(isc_list)) |
| 795 | clear_bit(irq_type, &fi->pending_irqs); |
| 796 | spin_unlock(&fi->lock); |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 797 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 798 | if (inti) { |
| 799 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, |
| 800 | (u16 *)__LC_SUBCHANNEL_ID); |
| 801 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, |
| 802 | (u16 *)__LC_SUBCHANNEL_NR); |
| 803 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, |
| 804 | (u32 *)__LC_IO_INT_PARM); |
| 805 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, |
| 806 | (u32 *)__LC_IO_INT_WORD); |
| 807 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, |
| 808 | &vcpu->arch.sie_block->gpsw, |
| 809 | sizeof(psw_t)); |
| 810 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, |
| 811 | &vcpu->arch.sie_block->gpsw, |
| 812 | sizeof(psw_t)); |
| 813 | kfree(inti); |
| 814 | } |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 815 | |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 816 | return rc ? -EFAULT : 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | typedef int (*deliver_irq_t)(struct kvm_vcpu *vcpu); |
| 820 | |
| 821 | static const deliver_irq_t deliver_irq_funcs[] = { |
| 822 | [IRQ_PEND_MCHK_EX] = __deliver_machine_check, |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 823 | [IRQ_PEND_MCHK_REP] = __deliver_machine_check, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 824 | [IRQ_PEND_PROG] = __deliver_prog, |
| 825 | [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal, |
| 826 | [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call, |
| 827 | [IRQ_PEND_EXT_CLOCK_COMP] = __deliver_ckc, |
| 828 | [IRQ_PEND_EXT_CPU_TIMER] = __deliver_cpu_timer, |
| 829 | [IRQ_PEND_RESTART] = __deliver_restart, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 830 | [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix, |
| 831 | [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init, |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 832 | [IRQ_PEND_EXT_SERVICE] = __deliver_service, |
| 833 | [IRQ_PEND_PFAULT_DONE] = __deliver_pfault_done, |
| 834 | [IRQ_PEND_VIRTIO] = __deliver_virtio, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 835 | }; |
| 836 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 837 | /* Check whether an external call is pending (deliverable or not) */ |
| 838 | int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 839 | { |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 840 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 841 | |
David Hildenbrand | 37c5f6c | 2015-05-06 13:18:59 +0200 | [diff] [blame] | 842 | if (!sclp.has_sigpif) |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 843 | return test_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 844 | |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 845 | return sca_ext_call_pending(vcpu, NULL); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 846 | } |
| 847 | |
David Hildenbrand | 9a02206 | 2014-08-05 17:40:47 +0200 | [diff] [blame] | 848 | int kvm_s390_vcpu_has_irq(struct kvm_vcpu *vcpu, int exclude_stop) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 849 | { |
David Hildenbrand | 4d32ad6 | 2015-05-06 13:51:29 +0200 | [diff] [blame] | 850 | if (deliverable_irqs(vcpu)) |
| 851 | return 1; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 852 | |
David Hildenbrand | 4d32ad6 | 2015-05-06 13:51:29 +0200 | [diff] [blame] | 853 | if (kvm_cpu_has_pending_timer(vcpu)) |
| 854 | return 1; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 855 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 856 | /* external call pending and deliverable */ |
David Hildenbrand | 4d32ad6 | 2015-05-06 13:51:29 +0200 | [diff] [blame] | 857 | if (kvm_s390_ext_call_pending(vcpu) && |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 858 | !psw_extint_disabled(vcpu) && |
| 859 | (vcpu->arch.sie_block->gcr[0] & 0x2000ul)) |
David Hildenbrand | 4d32ad6 | 2015-05-06 13:51:29 +0200 | [diff] [blame] | 860 | return 1; |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 861 | |
David Hildenbrand | 4d32ad6 | 2015-05-06 13:51:29 +0200 | [diff] [blame] | 862 | if (!exclude_stop && kvm_s390_is_stop_irq_pending(vcpu)) |
| 863 | return 1; |
| 864 | return 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 867 | int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) |
| 868 | { |
David Hildenbrand | b4aec92 | 2014-12-01 15:55:42 +0100 | [diff] [blame] | 869 | return ckc_irq_pending(vcpu) || cpu_timer_irq_pending(vcpu); |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 870 | } |
| 871 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 872 | int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) |
| 873 | { |
| 874 | u64 now, sltime; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 875 | |
| 876 | vcpu->stat.exit_wait_state++; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 877 | |
David Hildenbrand | 0759d06 | 2014-05-13 16:54:32 +0200 | [diff] [blame] | 878 | /* fast path */ |
David Hildenbrand | 118b862 | 2015-09-23 12:25:15 +0200 | [diff] [blame] | 879 | if (kvm_arch_vcpu_runnable(vcpu)) |
David Hildenbrand | 0759d06 | 2014-05-13 16:54:32 +0200 | [diff] [blame] | 880 | return 0; |
Carsten Otte | e52b2af | 2008-05-21 13:37:44 +0200 | [diff] [blame] | 881 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 882 | if (psw_interrupts_disabled(vcpu)) { |
| 883 | VCPU_EVENT(vcpu, 3, "%s", "disabled wait"); |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 884 | return -EOPNOTSUPP; /* disabled wait */ |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 885 | } |
| 886 | |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 887 | if (!ckc_interrupts_enabled(vcpu)) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 888 | VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer"); |
David Hildenbrand | bda343e | 2014-12-12 12:26:40 +0100 | [diff] [blame] | 889 | __set_cpu_idle(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 890 | goto no_timer; |
| 891 | } |
| 892 | |
David Hildenbrand | 60417fc | 2015-09-29 16:20:36 +0200 | [diff] [blame] | 893 | now = kvm_s390_get_tod_clock_fast(vcpu->kvm); |
Heiko Carstens | ed4f209 | 2013-01-14 16:55:55 +0100 | [diff] [blame] | 894 | sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); |
David Hildenbrand | bda343e | 2014-12-12 12:26:40 +0100 | [diff] [blame] | 895 | |
| 896 | /* underflow */ |
| 897 | if (vcpu->arch.sie_block->ckc < now) |
| 898 | return 0; |
| 899 | |
| 900 | __set_cpu_idle(vcpu); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 901 | hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL); |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 902 | VCPU_EVENT(vcpu, 4, "enabled wait via clock comparator: %llu ns", sltime); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 903 | no_timer: |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 904 | srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); |
David Hildenbrand | 0759d06 | 2014-05-13 16:54:32 +0200 | [diff] [blame] | 905 | kvm_vcpu_block(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 906 | __unset_cpu_idle(vcpu); |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 907 | vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 908 | |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 909 | hrtimer_cancel(&vcpu->arch.ckc_timer); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 910 | return 0; |
| 911 | } |
| 912 | |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 913 | void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu) |
| 914 | { |
| 915 | if (waitqueue_active(&vcpu->wq)) { |
| 916 | /* |
| 917 | * The vcpu gave up the cpu voluntarily, mark it as a good |
| 918 | * yield-candidate. |
| 919 | */ |
| 920 | vcpu->preempted = true; |
| 921 | wake_up_interruptible(&vcpu->wq); |
David Hildenbrand | ce2e4f0 | 2014-07-11 10:00:43 +0200 | [diff] [blame] | 922 | vcpu->stat.halt_wakeup++; |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 923 | } |
| 924 | } |
| 925 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 926 | enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) |
| 927 | { |
| 928 | struct kvm_vcpu *vcpu; |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 929 | u64 now, sltime; |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 930 | |
| 931 | vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); |
David Hildenbrand | 60417fc | 2015-09-29 16:20:36 +0200 | [diff] [blame] | 932 | now = kvm_s390_get_tod_clock_fast(vcpu->kvm); |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 933 | sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 934 | |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 935 | /* |
| 936 | * If the monotonic clock runs faster than the tod clock we might be |
| 937 | * woken up too early and have to go back to sleep to avoid deadlocks. |
| 938 | */ |
| 939 | if (vcpu->arch.sie_block->ckc > now && |
| 940 | hrtimer_forward_now(timer, ns_to_ktime(sltime))) |
| 941 | return HRTIMER_RESTART; |
| 942 | kvm_s390_vcpu_wakeup(vcpu); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 943 | return HRTIMER_NORESTART; |
| 944 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 945 | |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 946 | void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu) |
| 947 | { |
| 948 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 949 | |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 950 | spin_lock(&li->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 951 | li->pending_irqs = 0; |
| 952 | bitmap_zero(li->sigp_emerg_pending, KVM_MAX_VCPUS); |
| 953 | memset(&li->irq, 0, sizeof(li->irq)); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 954 | spin_unlock(&li->lock); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 955 | |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 956 | sca_clear_ext_call(vcpu); |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 957 | } |
| 958 | |
Christian Borntraeger | 614aeab | 2014-08-25 12:27:29 +0200 | [diff] [blame] | 959 | int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 960 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 961 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 962 | deliver_irq_t func; |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 963 | int rc = 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 964 | unsigned long irq_type; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 965 | unsigned long irqs; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 966 | |
| 967 | __reset_intercept_indicators(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 968 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 969 | /* pending ckc conditions might have been invalidated */ |
| 970 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
David Hildenbrand | b4aec92 | 2014-12-01 15:55:42 +0100 | [diff] [blame] | 971 | if (ckc_irq_pending(vcpu)) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 972 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
| 973 | |
David Hildenbrand | b4aec92 | 2014-12-01 15:55:42 +0100 | [diff] [blame] | 974 | /* pending cpu timer conditions might have been invalidated */ |
| 975 | clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
| 976 | if (cpu_timer_irq_pending(vcpu)) |
| 977 | set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
| 978 | |
Jens Freimann | ffeca0a | 2015-04-17 10:21:04 +0200 | [diff] [blame] | 979 | while ((irqs = deliverable_irqs(vcpu)) && !rc) { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 980 | /* bits are in the order of interrupt priority */ |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 981 | irq_type = find_first_bit(&irqs, IRQ_PEND_COUNT); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 982 | if (is_ioirq(irq_type)) { |
| 983 | rc = __deliver_io(vcpu, irq_type); |
| 984 | } else { |
| 985 | func = deliver_irq_funcs[irq_type]; |
| 986 | if (!func) { |
| 987 | WARN_ON_ONCE(func == NULL); |
| 988 | clear_bit(irq_type, &li->pending_irqs); |
| 989 | continue; |
| 990 | } |
| 991 | rc = func(vcpu); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 992 | } |
Jens Freimann | ffeca0a | 2015-04-17 10:21:04 +0200 | [diff] [blame] | 993 | } |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 994 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 995 | set_intercept_indicators(vcpu); |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 996 | |
| 997 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1000 | static int __inject_prog(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1001 | { |
| 1002 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1003 | |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1004 | VCPU_EVENT(vcpu, 3, "inject: program irq code 0x%x", irq->u.pgm.code); |
| 1005 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, |
| 1006 | irq->u.pgm.code, 0); |
| 1007 | |
David Hildenbrand | 238293b | 2015-05-04 12:38:48 +0200 | [diff] [blame] | 1008 | if (irq->u.pgm.code == PGM_PER) { |
| 1009 | li->irq.pgm.code |= PGM_PER; |
| 1010 | /* only modify PER related information */ |
| 1011 | li->irq.pgm.per_address = irq->u.pgm.per_address; |
| 1012 | li->irq.pgm.per_code = irq->u.pgm.per_code; |
| 1013 | li->irq.pgm.per_atmid = irq->u.pgm.per_atmid; |
| 1014 | li->irq.pgm.per_access_id = irq->u.pgm.per_access_id; |
| 1015 | } else if (!(irq->u.pgm.code & PGM_PER)) { |
| 1016 | li->irq.pgm.code = (li->irq.pgm.code & PGM_PER) | |
| 1017 | irq->u.pgm.code; |
| 1018 | /* only modify non-PER information */ |
| 1019 | li->irq.pgm.trans_exc_code = irq->u.pgm.trans_exc_code; |
| 1020 | li->irq.pgm.mon_code = irq->u.pgm.mon_code; |
| 1021 | li->irq.pgm.data_exc_code = irq->u.pgm.data_exc_code; |
| 1022 | li->irq.pgm.mon_class_nr = irq->u.pgm.mon_class_nr; |
| 1023 | li->irq.pgm.exc_access_id = irq->u.pgm.exc_access_id; |
| 1024 | li->irq.pgm.op_access_id = irq->u.pgm.op_access_id; |
| 1025 | } else { |
| 1026 | li->irq.pgm = irq->u.pgm; |
| 1027 | } |
Jens Freimann | 9185124 | 2014-12-01 16:43:40 +0100 | [diff] [blame] | 1028 | set_bit(IRQ_PEND_PROG, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1029 | return 0; |
| 1030 | } |
| 1031 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1032 | static int __inject_pfault_init(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1033 | { |
| 1034 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1035 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1036 | VCPU_EVENT(vcpu, 4, "inject: pfault init parameter block at 0x%llx", |
| 1037 | irq->u.ext.ext_params2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1038 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_PFAULT_INIT, |
| 1039 | irq->u.ext.ext_params, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1040 | irq->u.ext.ext_params2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1041 | |
| 1042 | li->irq.ext = irq->u.ext; |
| 1043 | set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1044 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1045 | return 0; |
| 1046 | } |
| 1047 | |
Christian Borntraeger | 0675d92 | 2015-01-15 12:40:42 +0100 | [diff] [blame] | 1048 | static int __inject_extcall(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1049 | { |
| 1050 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1051 | struct kvm_s390_extcall_info *extcall = &li->irq.extcall; |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1052 | uint16_t src_id = irq->u.extcall.code; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1053 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1054 | VCPU_EVENT(vcpu, 4, "inject: external call source-cpu:%u", |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1055 | src_id); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1056 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EXTERNAL_CALL, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1057 | src_id, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1058 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1059 | /* sending vcpu invalid */ |
David Hildenbrand | 152e9f6 | 2015-11-05 09:06:06 +0100 | [diff] [blame] | 1060 | if (kvm_get_vcpu_by_id(vcpu->kvm, src_id) == NULL) |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1061 | return -EINVAL; |
| 1062 | |
David Hildenbrand | 37c5f6c | 2015-05-06 13:18:59 +0200 | [diff] [blame] | 1063 | if (sclp.has_sigpif) |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 1064 | return sca_inject_ext_call(vcpu, src_id); |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1065 | |
David Hildenbrand | b938eace | 2015-04-30 13:33:59 +0200 | [diff] [blame] | 1066 | if (test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs)) |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1067 | return -EBUSY; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1068 | *extcall = irq->u.extcall; |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1069 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1070 | return 0; |
| 1071 | } |
| 1072 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1073 | static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1074 | { |
| 1075 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1076 | struct kvm_s390_prefix_info *prefix = &li->irq.prefix; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1077 | |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1078 | VCPU_EVENT(vcpu, 3, "inject: set prefix to %x", |
Jens Freimann | 556cc0d | 2014-12-18 15:52:21 +0100 | [diff] [blame] | 1079 | irq->u.prefix.address); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1080 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_SET_PREFIX, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1081 | irq->u.prefix.address, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1082 | |
David Hildenbrand | a3a9c59 | 2014-10-14 09:44:55 +0200 | [diff] [blame] | 1083 | if (!is_vcpu_stopped(vcpu)) |
| 1084 | return -EBUSY; |
| 1085 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1086 | *prefix = irq->u.prefix; |
| 1087 | set_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1088 | return 0; |
| 1089 | } |
| 1090 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1091 | #define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1092 | static int __inject_sigp_stop(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1093 | { |
| 1094 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1095 | struct kvm_s390_stop_info *stop = &li->irq.stop; |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1096 | int rc = 0; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1097 | |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1098 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1099 | |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1100 | if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS) |
| 1101 | return -EINVAL; |
| 1102 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1103 | if (is_vcpu_stopped(vcpu)) { |
| 1104 | if (irq->u.stop.flags & KVM_S390_STOP_FLAG_STORE_STATUS) |
| 1105 | rc = kvm_s390_store_status_unloaded(vcpu, |
| 1106 | KVM_S390_STORE_STATUS_NOADDR); |
| 1107 | return rc; |
| 1108 | } |
| 1109 | |
| 1110 | if (test_and_set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs)) |
| 1111 | return -EBUSY; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1112 | stop->flags = irq->u.stop.flags; |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1113 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | static int __inject_sigp_restart(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1118 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1119 | { |
| 1120 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1121 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1122 | VCPU_EVENT(vcpu, 3, "%s", "inject: restart int"); |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1123 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1124 | |
| 1125 | set_bit(IRQ_PEND_RESTART, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1126 | return 0; |
| 1127 | } |
| 1128 | |
| 1129 | static int __inject_sigp_emergency(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1130 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1131 | { |
| 1132 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1133 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1134 | VCPU_EVENT(vcpu, 4, "inject: emergency from cpu %u", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1135 | irq->u.emerg.code); |
| 1136 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1137 | irq->u.emerg.code, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1138 | |
David Hildenbrand | b85de33 | 2015-11-05 09:38:15 +0100 | [diff] [blame] | 1139 | /* sending vcpu invalid */ |
| 1140 | if (kvm_get_vcpu_by_id(vcpu->kvm, irq->u.emerg.code) == NULL) |
| 1141 | return -EINVAL; |
| 1142 | |
Jens Freimann | 49538d1 | 2014-12-18 15:48:14 +0100 | [diff] [blame] | 1143 | set_bit(irq->u.emerg.code, li->sigp_emerg_pending); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1144 | set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1145 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1146 | return 0; |
| 1147 | } |
| 1148 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1149 | static int __inject_mchk(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1150 | { |
| 1151 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1152 | struct kvm_s390_mchk_info *mchk = &li->irq.mchk; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1153 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1154 | VCPU_EVENT(vcpu, 3, "inject: machine check mcic 0x%llx", |
Jens Freimann | 556cc0d | 2014-12-18 15:52:21 +0100 | [diff] [blame] | 1155 | irq->u.mchk.mcic); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1156 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1157 | irq->u.mchk.mcic); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1158 | |
| 1159 | /* |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1160 | * Because repressible machine checks can be indicated along with |
| 1161 | * exigent machine checks (PoP, Chapter 11, Interruption action) |
| 1162 | * we need to combine cr14, mcic and external damage code. |
| 1163 | * Failing storage address and the logout area should not be or'ed |
| 1164 | * together, we just indicate the last occurrence of the corresponding |
| 1165 | * machine check |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1166 | */ |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1167 | mchk->cr14 |= irq->u.mchk.cr14; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1168 | mchk->mcic |= irq->u.mchk.mcic; |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1169 | mchk->ext_damage_code |= irq->u.mchk.ext_damage_code; |
| 1170 | mchk->failing_storage_address = irq->u.mchk.failing_storage_address; |
| 1171 | memcpy(&mchk->fixed_logout, &irq->u.mchk.fixed_logout, |
| 1172 | sizeof(mchk->fixed_logout)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1173 | if (mchk->mcic & MCHK_EX_MASK) |
| 1174 | set_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); |
| 1175 | else if (mchk->mcic & MCHK_REP_MASK) |
| 1176 | set_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1177 | return 0; |
| 1178 | } |
| 1179 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1180 | static int __inject_ckc(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1181 | { |
| 1182 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1183 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1184 | VCPU_EVENT(vcpu, 3, "%s", "inject: clock comparator external"); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1185 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1186 | 0, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1187 | |
| 1188 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1189 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1190 | return 0; |
| 1191 | } |
| 1192 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1193 | static int __inject_cpu_timer(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1194 | { |
| 1195 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1196 | |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1197 | VCPU_EVENT(vcpu, 3, "%s", "inject: cpu timer external"); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1198 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, |
David Hildenbrand | ed2afcf | 2015-07-20 10:33:03 +0200 | [diff] [blame] | 1199 | 0, 0); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1200 | |
| 1201 | set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1202 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 1203 | return 0; |
| 1204 | } |
| 1205 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1206 | static struct kvm_s390_interrupt_info *get_io_int(struct kvm *kvm, |
| 1207 | int isc, u32 schid) |
| 1208 | { |
| 1209 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1210 | struct list_head *isc_list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; |
| 1211 | struct kvm_s390_interrupt_info *iter; |
| 1212 | u16 id = (schid & 0xffff0000U) >> 16; |
| 1213 | u16 nr = schid & 0x0000ffffU; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1214 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1215 | spin_lock(&fi->lock); |
| 1216 | list_for_each_entry(iter, isc_list, list) { |
| 1217 | if (schid && (id != iter->io.subchannel_id || |
| 1218 | nr != iter->io.subchannel_nr)) |
| 1219 | continue; |
| 1220 | /* found an appropriate entry */ |
| 1221 | list_del_init(&iter->list); |
| 1222 | fi->counters[FIRQ_CNTR_IO] -= 1; |
| 1223 | if (list_empty(isc_list)) |
| 1224 | clear_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs); |
| 1225 | spin_unlock(&fi->lock); |
| 1226 | return iter; |
| 1227 | } |
| 1228 | spin_unlock(&fi->lock); |
| 1229 | return NULL; |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Dequeue and return an I/O interrupt matching any of the interruption |
| 1234 | * subclasses as designated by the isc mask in cr6 and the schid (if != 0). |
| 1235 | */ |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1236 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1237 | u64 isc_mask, u32 schid) |
| 1238 | { |
| 1239 | struct kvm_s390_interrupt_info *inti = NULL; |
| 1240 | int isc; |
| 1241 | |
| 1242 | for (isc = 0; isc <= MAX_ISC && !inti; isc++) { |
| 1243 | if (isc_mask & isc_to_isc_bits(isc)) |
| 1244 | inti = get_io_int(kvm, isc, schid); |
| 1245 | } |
| 1246 | return inti; |
| 1247 | } |
| 1248 | |
| 1249 | #define SCCB_MASK 0xFFFFFFF8 |
| 1250 | #define SCCB_EVENT_PENDING 0x3 |
| 1251 | |
| 1252 | static int __inject_service(struct kvm *kvm, |
| 1253 | struct kvm_s390_interrupt_info *inti) |
| 1254 | { |
| 1255 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1256 | |
| 1257 | spin_lock(&fi->lock); |
| 1258 | fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_EVENT_PENDING; |
| 1259 | /* |
| 1260 | * Early versions of the QEMU s390 bios will inject several |
| 1261 | * service interrupts after another without handling a |
| 1262 | * condition code indicating busy. |
| 1263 | * We will silently ignore those superfluous sccb values. |
| 1264 | * A future version of QEMU will take care of serialization |
| 1265 | * of servc requests |
| 1266 | */ |
| 1267 | if (fi->srv_signal.ext_params & SCCB_MASK) |
| 1268 | goto out; |
| 1269 | fi->srv_signal.ext_params |= inti->ext.ext_params & SCCB_MASK; |
| 1270 | set_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs); |
| 1271 | out: |
| 1272 | spin_unlock(&fi->lock); |
| 1273 | kfree(inti); |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
| 1277 | static int __inject_virtio(struct kvm *kvm, |
| 1278 | struct kvm_s390_interrupt_info *inti) |
| 1279 | { |
| 1280 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1281 | |
| 1282 | spin_lock(&fi->lock); |
| 1283 | if (fi->counters[FIRQ_CNTR_VIRTIO] >= KVM_S390_MAX_VIRTIO_IRQS) { |
| 1284 | spin_unlock(&fi->lock); |
| 1285 | return -EBUSY; |
| 1286 | } |
| 1287 | fi->counters[FIRQ_CNTR_VIRTIO] += 1; |
| 1288 | list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_VIRTIO]); |
| 1289 | set_bit(IRQ_PEND_VIRTIO, &fi->pending_irqs); |
| 1290 | spin_unlock(&fi->lock); |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static int __inject_pfault_done(struct kvm *kvm, |
| 1295 | struct kvm_s390_interrupt_info *inti) |
| 1296 | { |
| 1297 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1298 | |
| 1299 | spin_lock(&fi->lock); |
| 1300 | if (fi->counters[FIRQ_CNTR_PFAULT] >= |
| 1301 | (ASYNC_PF_PER_VCPU * KVM_MAX_VCPUS)) { |
| 1302 | spin_unlock(&fi->lock); |
| 1303 | return -EBUSY; |
| 1304 | } |
| 1305 | fi->counters[FIRQ_CNTR_PFAULT] += 1; |
| 1306 | list_add_tail(&inti->list, &fi->lists[FIRQ_LIST_PFAULT]); |
| 1307 | set_bit(IRQ_PEND_PFAULT_DONE, &fi->pending_irqs); |
| 1308 | spin_unlock(&fi->lock); |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | #define CR_PENDING_SUBCLASS 28 |
| 1313 | static int __inject_float_mchk(struct kvm *kvm, |
| 1314 | struct kvm_s390_interrupt_info *inti) |
| 1315 | { |
| 1316 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1317 | |
| 1318 | spin_lock(&fi->lock); |
| 1319 | fi->mchk.cr14 |= inti->mchk.cr14 & (1UL << CR_PENDING_SUBCLASS); |
| 1320 | fi->mchk.mcic |= inti->mchk.mcic; |
| 1321 | set_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs); |
| 1322 | spin_unlock(&fi->lock); |
| 1323 | kfree(inti); |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static int __inject_io(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1328 | { |
| 1329 | struct kvm_s390_float_interrupt *fi; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1330 | struct list_head *list; |
| 1331 | int isc; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1332 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1333 | fi = &kvm->arch.float_int; |
| 1334 | spin_lock(&fi->lock); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1335 | if (fi->counters[FIRQ_CNTR_IO] >= KVM_S390_MAX_FLOAT_IRQS) { |
| 1336 | spin_unlock(&fi->lock); |
| 1337 | return -EBUSY; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1338 | } |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1339 | fi->counters[FIRQ_CNTR_IO] += 1; |
| 1340 | |
| 1341 | isc = int_word_to_isc(inti->io.io_int_word); |
| 1342 | list = &fi->lists[FIRQ_LIST_IO_ISC_0 + isc]; |
| 1343 | list_add_tail(&inti->list, list); |
| 1344 | set_bit(IRQ_PEND_IO_ISC_0 + isc, &fi->pending_irqs); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1345 | spin_unlock(&fi->lock); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1346 | return 0; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
David Hildenbrand | 96e0ed2 | 2015-01-14 14:08:38 +0100 | [diff] [blame] | 1349 | /* |
| 1350 | * Find a destination VCPU for a floating irq and kick it. |
| 1351 | */ |
| 1352 | static void __floating_irq_kick(struct kvm *kvm, u64 type) |
| 1353 | { |
| 1354 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1355 | struct kvm_s390_local_interrupt *li; |
| 1356 | struct kvm_vcpu *dst_vcpu; |
| 1357 | int sigcpu, online_vcpus, nr_tries = 0; |
| 1358 | |
| 1359 | online_vcpus = atomic_read(&kvm->online_vcpus); |
| 1360 | if (!online_vcpus) |
| 1361 | return; |
| 1362 | |
| 1363 | /* find idle VCPUs first, then round robin */ |
| 1364 | sigcpu = find_first_bit(fi->idle_mask, online_vcpus); |
| 1365 | if (sigcpu == online_vcpus) { |
| 1366 | do { |
| 1367 | sigcpu = fi->next_rr_cpu; |
| 1368 | fi->next_rr_cpu = (fi->next_rr_cpu + 1) % online_vcpus; |
| 1369 | /* avoid endless loops if all vcpus are stopped */ |
| 1370 | if (nr_tries++ >= online_vcpus) |
| 1371 | return; |
| 1372 | } while (is_vcpu_stopped(kvm_get_vcpu(kvm, sigcpu))); |
| 1373 | } |
| 1374 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); |
| 1375 | |
| 1376 | /* make the VCPU drop out of the SIE, or wake it up if sleeping */ |
| 1377 | li = &dst_vcpu->arch.local_int; |
| 1378 | spin_lock(&li->lock); |
| 1379 | switch (type) { |
| 1380 | case KVM_S390_MCHK: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1381 | atomic_or(CPUSTAT_STOP_INT, li->cpuflags); |
David Hildenbrand | 96e0ed2 | 2015-01-14 14:08:38 +0100 | [diff] [blame] | 1382 | break; |
| 1383 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1384 | atomic_or(CPUSTAT_IO_INT, li->cpuflags); |
David Hildenbrand | 96e0ed2 | 2015-01-14 14:08:38 +0100 | [diff] [blame] | 1385 | break; |
| 1386 | default: |
Peter Zijlstra | 805de8f4 | 2015-04-24 01:12:32 +0200 | [diff] [blame] | 1387 | atomic_or(CPUSTAT_EXT_INT, li->cpuflags); |
David Hildenbrand | 96e0ed2 | 2015-01-14 14:08:38 +0100 | [diff] [blame] | 1388 | break; |
| 1389 | } |
| 1390 | spin_unlock(&li->lock); |
| 1391 | kvm_s390_vcpu_wakeup(dst_vcpu); |
| 1392 | } |
| 1393 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1394 | static int __inject_vm(struct kvm *kvm, struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1395 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1396 | u64 type = READ_ONCE(inti->type); |
| 1397 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1398 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1399 | switch (type) { |
| 1400 | case KVM_S390_MCHK: |
| 1401 | rc = __inject_float_mchk(kvm, inti); |
| 1402 | break; |
| 1403 | case KVM_S390_INT_VIRTIO: |
| 1404 | rc = __inject_virtio(kvm, inti); |
| 1405 | break; |
| 1406 | case KVM_S390_INT_SERVICE: |
| 1407 | rc = __inject_service(kvm, inti); |
| 1408 | break; |
| 1409 | case KVM_S390_INT_PFAULT_DONE: |
| 1410 | rc = __inject_pfault_done(kvm, inti); |
| 1411 | break; |
| 1412 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1413 | rc = __inject_io(kvm, inti); |
| 1414 | break; |
| 1415 | default: |
| 1416 | rc = -EINVAL; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1417 | } |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1418 | if (rc) |
| 1419 | return rc; |
| 1420 | |
David Hildenbrand | 96e0ed2 | 2015-01-14 14:08:38 +0100 | [diff] [blame] | 1421 | __floating_irq_kick(kvm, type); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1422 | return 0; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | int kvm_s390_inject_vm(struct kvm *kvm, |
| 1426 | struct kvm_s390_interrupt *s390int) |
| 1427 | { |
| 1428 | struct kvm_s390_interrupt_info *inti; |
David Hildenbrand | 428d53b | 2015-01-16 12:58:09 +0100 | [diff] [blame] | 1429 | int rc; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1430 | |
| 1431 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1432 | if (!inti) |
| 1433 | return -ENOMEM; |
| 1434 | |
| 1435 | inti->type = s390int->type; |
| 1436 | switch (inti->type) { |
| 1437 | case KVM_S390_INT_VIRTIO: |
| 1438 | VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx", |
| 1439 | s390int->parm, s390int->parm64); |
| 1440 | inti->ext.ext_params = s390int->parm; |
| 1441 | inti->ext.ext_params2 = s390int->parm64; |
| 1442 | break; |
| 1443 | case KVM_S390_INT_SERVICE: |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1444 | VM_EVENT(kvm, 4, "inject: sclp parm:%x", s390int->parm); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1445 | inti->ext.ext_params = s390int->parm; |
| 1446 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1447 | case KVM_S390_INT_PFAULT_DONE: |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1448 | inti->ext.ext_params2 = s390int->parm64; |
| 1449 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1450 | case KVM_S390_MCHK: |
Christian Borntraeger | 3f24ba1 | 2015-07-09 14:08:18 +0200 | [diff] [blame] | 1451 | VM_EVENT(kvm, 3, "inject: machine check mcic 0x%llx", |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1452 | s390int->parm64); |
| 1453 | inti->mchk.cr14 = s390int->parm; /* upper bits are not used */ |
| 1454 | inti->mchk.mcic = s390int->parm64; |
| 1455 | break; |
| 1456 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
David Hildenbrand | a37281b | 2014-11-21 13:45:08 +0100 | [diff] [blame] | 1457 | if (inti->type & KVM_S390_INT_IO_AI_MASK) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1458 | VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)"); |
| 1459 | else |
| 1460 | VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x", |
| 1461 | s390int->type & IOINT_CSSID_MASK, |
| 1462 | s390int->type & IOINT_SSID_MASK, |
| 1463 | s390int->type & IOINT_SCHID_MASK); |
| 1464 | inti->io.subchannel_id = s390int->parm >> 16; |
| 1465 | inti->io.subchannel_nr = s390int->parm & 0x0000ffffu; |
| 1466 | inti->io.io_int_parm = s390int->parm64 >> 32; |
| 1467 | inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull; |
| 1468 | break; |
| 1469 | default: |
| 1470 | kfree(inti); |
| 1471 | return -EINVAL; |
| 1472 | } |
| 1473 | trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64, |
| 1474 | 2); |
| 1475 | |
David Hildenbrand | 428d53b | 2015-01-16 12:58:09 +0100 | [diff] [blame] | 1476 | rc = __inject_vm(kvm, inti); |
| 1477 | if (rc) |
| 1478 | kfree(inti); |
| 1479 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
David Hildenbrand | 15462e3 | 2015-02-04 15:59:11 +0100 | [diff] [blame] | 1482 | int kvm_s390_reinject_io_int(struct kvm *kvm, |
Cornelia Huck | 2f32d4e | 2014-01-08 18:07:54 +0100 | [diff] [blame] | 1483 | struct kvm_s390_interrupt_info *inti) |
| 1484 | { |
David Hildenbrand | 15462e3 | 2015-02-04 15:59:11 +0100 | [diff] [blame] | 1485 | return __inject_vm(kvm, inti); |
Cornelia Huck | 2f32d4e | 2014-01-08 18:07:54 +0100 | [diff] [blame] | 1486 | } |
| 1487 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1488 | int s390int_to_s390irq(struct kvm_s390_interrupt *s390int, |
| 1489 | struct kvm_s390_irq *irq) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1490 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1491 | irq->type = s390int->type; |
| 1492 | switch (irq->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1493 | case KVM_S390_PROGRAM_INT: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1494 | if (s390int->parm & 0xffff0000) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1495 | return -EINVAL; |
| 1496 | irq->u.pgm.code = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1497 | break; |
Christian Borntraeger | b7e6e4d | 2009-01-22 10:29:08 +0100 | [diff] [blame] | 1498 | case KVM_S390_SIGP_SET_PREFIX: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1499 | irq->u.prefix.address = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1500 | break; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1501 | case KVM_S390_SIGP_STOP: |
| 1502 | irq->u.stop.flags = s390int->parm; |
| 1503 | break; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1504 | case KVM_S390_INT_EXTERNAL_CALL: |
Jens Freimann | 94d1f56 | 2015-01-15 14:40:34 +0100 | [diff] [blame] | 1505 | if (s390int->parm & 0xffff0000) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1506 | return -EINVAL; |
| 1507 | irq->u.extcall.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1508 | break; |
| 1509 | case KVM_S390_INT_EMERGENCY: |
Jens Freimann | 94d1f56 | 2015-01-15 14:40:34 +0100 | [diff] [blame] | 1510 | if (s390int->parm & 0xffff0000) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1511 | return -EINVAL; |
| 1512 | irq->u.emerg.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1513 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1514 | case KVM_S390_MCHK: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1515 | irq->u.mchk.mcic = s390int->parm64; |
| 1516 | break; |
| 1517 | } |
| 1518 | return 0; |
| 1519 | } |
| 1520 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1521 | int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu) |
| 1522 | { |
| 1523 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1524 | |
| 1525 | return test_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); |
| 1526 | } |
| 1527 | |
| 1528 | void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu) |
| 1529 | { |
| 1530 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1531 | |
| 1532 | spin_lock(&li->lock); |
| 1533 | li->irq.stop.flags = 0; |
| 1534 | clear_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); |
| 1535 | spin_unlock(&li->lock); |
| 1536 | } |
| 1537 | |
Jens Freimann | 79e87a1 | 2015-03-19 15:12:12 +0100 | [diff] [blame] | 1538 | static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1539 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1540 | int rc; |
| 1541 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1542 | switch (irq->type) { |
| 1543 | case KVM_S390_PROGRAM_INT: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1544 | rc = __inject_prog(vcpu, irq); |
| 1545 | break; |
| 1546 | case KVM_S390_SIGP_SET_PREFIX: |
| 1547 | rc = __inject_set_prefix(vcpu, irq); |
| 1548 | break; |
| 1549 | case KVM_S390_SIGP_STOP: |
| 1550 | rc = __inject_sigp_stop(vcpu, irq); |
| 1551 | break; |
| 1552 | case KVM_S390_RESTART: |
| 1553 | rc = __inject_sigp_restart(vcpu, irq); |
| 1554 | break; |
| 1555 | case KVM_S390_INT_CLOCK_COMP: |
| 1556 | rc = __inject_ckc(vcpu); |
| 1557 | break; |
| 1558 | case KVM_S390_INT_CPU_TIMER: |
| 1559 | rc = __inject_cpu_timer(vcpu); |
| 1560 | break; |
| 1561 | case KVM_S390_INT_EXTERNAL_CALL: |
| 1562 | rc = __inject_extcall(vcpu, irq); |
| 1563 | break; |
| 1564 | case KVM_S390_INT_EMERGENCY: |
| 1565 | rc = __inject_sigp_emergency(vcpu, irq); |
| 1566 | break; |
| 1567 | case KVM_S390_MCHK: |
| 1568 | rc = __inject_mchk(vcpu, irq); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1569 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1570 | case KVM_S390_INT_PFAULT_INIT: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1571 | rc = __inject_pfault_init(vcpu, irq); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1572 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1573 | case KVM_S390_INT_VIRTIO: |
| 1574 | case KVM_S390_INT_SERVICE: |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1575 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1576 | default: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1577 | rc = -EINVAL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1578 | } |
Jens Freimann | 79e87a1 | 2015-03-19 15:12:12 +0100 | [diff] [blame] | 1579 | |
| 1580 | return rc; |
| 1581 | } |
| 1582 | |
| 1583 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
| 1584 | { |
| 1585 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1586 | int rc; |
| 1587 | |
| 1588 | spin_lock(&li->lock); |
| 1589 | rc = do_inject_vcpu(vcpu, irq); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1590 | spin_unlock(&li->lock); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1591 | if (!rc) |
| 1592 | kvm_s390_vcpu_wakeup(vcpu); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1593 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1594 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1595 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1596 | static inline void clear_irq_list(struct list_head *_list) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1597 | { |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1598 | struct kvm_s390_interrupt_info *inti, *n; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1599 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1600 | list_for_each_entry_safe(inti, n, _list, list) { |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1601 | list_del(&inti->list); |
| 1602 | kfree(inti); |
| 1603 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1604 | } |
| 1605 | |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1606 | static void inti_to_irq(struct kvm_s390_interrupt_info *inti, |
| 1607 | struct kvm_s390_irq *irq) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1608 | { |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1609 | irq->type = inti->type; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1610 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1611 | case KVM_S390_INT_PFAULT_INIT: |
| 1612 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1613 | case KVM_S390_INT_VIRTIO: |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1614 | irq->u.ext = inti->ext; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1615 | break; |
| 1616 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1617 | irq->u.io = inti->io; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1618 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1619 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1622 | void kvm_s390_clear_float_irqs(struct kvm *kvm) |
| 1623 | { |
| 1624 | struct kvm_s390_float_interrupt *fi = &kvm->arch.float_int; |
| 1625 | int i; |
| 1626 | |
| 1627 | spin_lock(&fi->lock); |
Jens Freimann | f2ae45e | 2015-06-22 13:20:12 +0200 | [diff] [blame] | 1628 | fi->pending_irqs = 0; |
| 1629 | memset(&fi->srv_signal, 0, sizeof(fi->srv_signal)); |
| 1630 | memset(&fi->mchk, 0, sizeof(fi->mchk)); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1631 | for (i = 0; i < FIRQ_LIST_COUNT; i++) |
| 1632 | clear_irq_list(&fi->lists[i]); |
| 1633 | for (i = 0; i < FIRQ_MAX_COUNT; i++) |
| 1634 | fi->counters[i] = 0; |
| 1635 | spin_unlock(&fi->lock); |
| 1636 | }; |
| 1637 | |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1638 | static int get_all_floating_irqs(struct kvm *kvm, u8 __user *usrbuf, u64 len) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1639 | { |
| 1640 | struct kvm_s390_interrupt_info *inti; |
| 1641 | struct kvm_s390_float_interrupt *fi; |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1642 | struct kvm_s390_irq *buf; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1643 | struct kvm_s390_irq *irq; |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1644 | int max_irqs; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1645 | int ret = 0; |
| 1646 | int n = 0; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1647 | int i; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1648 | |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1649 | if (len > KVM_S390_FLIC_MAX_BUFFER || len == 0) |
| 1650 | return -EINVAL; |
| 1651 | |
| 1652 | /* |
| 1653 | * We are already using -ENOMEM to signal |
| 1654 | * userspace it may retry with a bigger buffer, |
| 1655 | * so we need to use something else for this case |
| 1656 | */ |
| 1657 | buf = vzalloc(len); |
| 1658 | if (!buf) |
| 1659 | return -ENOBUFS; |
| 1660 | |
| 1661 | max_irqs = len / sizeof(struct kvm_s390_irq); |
| 1662 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1663 | fi = &kvm->arch.float_int; |
| 1664 | spin_lock(&fi->lock); |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1665 | for (i = 0; i < FIRQ_LIST_COUNT; i++) { |
| 1666 | list_for_each_entry(inti, &fi->lists[i], list) { |
| 1667 | if (n == max_irqs) { |
| 1668 | /* signal userspace to try again */ |
| 1669 | ret = -ENOMEM; |
| 1670 | goto out; |
| 1671 | } |
| 1672 | inti_to_irq(inti, &buf[n]); |
| 1673 | n++; |
| 1674 | } |
| 1675 | } |
| 1676 | if (test_bit(IRQ_PEND_EXT_SERVICE, &fi->pending_irqs)) { |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1677 | if (n == max_irqs) { |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1678 | /* signal userspace to try again */ |
| 1679 | ret = -ENOMEM; |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1680 | goto out; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1681 | } |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1682 | irq = (struct kvm_s390_irq *) &buf[n]; |
| 1683 | irq->type = KVM_S390_INT_SERVICE; |
| 1684 | irq->u.ext = fi->srv_signal; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1685 | n++; |
| 1686 | } |
Jens Freimann | 6d3da24 | 2013-07-03 15:18:35 +0200 | [diff] [blame] | 1687 | if (test_bit(IRQ_PEND_MCHK_REP, &fi->pending_irqs)) { |
| 1688 | if (n == max_irqs) { |
| 1689 | /* signal userspace to try again */ |
| 1690 | ret = -ENOMEM; |
| 1691 | goto out; |
| 1692 | } |
| 1693 | irq = (struct kvm_s390_irq *) &buf[n]; |
| 1694 | irq->type = KVM_S390_MCHK; |
| 1695 | irq->u.mchk = fi->mchk; |
| 1696 | n++; |
| 1697 | } |
| 1698 | |
| 1699 | out: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1700 | spin_unlock(&fi->lock); |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1701 | if (!ret && n > 0) { |
| 1702 | if (copy_to_user(usrbuf, buf, sizeof(struct kvm_s390_irq) * n)) |
| 1703 | ret = -EFAULT; |
| 1704 | } |
| 1705 | vfree(buf); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1706 | |
| 1707 | return ret < 0 ? ret : n; |
| 1708 | } |
| 1709 | |
| 1710 | static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1711 | { |
| 1712 | int r; |
| 1713 | |
| 1714 | switch (attr->group) { |
| 1715 | case KVM_DEV_FLIC_GET_ALL_IRQS: |
Jens Freimann | 94aa033 | 2015-03-16 12:17:13 +0100 | [diff] [blame] | 1716 | r = get_all_floating_irqs(dev->kvm, (u8 __user *) attr->addr, |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1717 | attr->attr); |
| 1718 | break; |
| 1719 | default: |
| 1720 | r = -EINVAL; |
| 1721 | } |
| 1722 | |
| 1723 | return r; |
| 1724 | } |
| 1725 | |
| 1726 | static inline int copy_irq_from_user(struct kvm_s390_interrupt_info *inti, |
| 1727 | u64 addr) |
| 1728 | { |
| 1729 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1730 | void *target = NULL; |
| 1731 | void __user *source; |
| 1732 | u64 size; |
| 1733 | |
| 1734 | if (get_user(inti->type, (u64 __user *)addr)) |
| 1735 | return -EFAULT; |
| 1736 | |
| 1737 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1738 | case KVM_S390_INT_PFAULT_INIT: |
| 1739 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1740 | case KVM_S390_INT_VIRTIO: |
| 1741 | case KVM_S390_INT_SERVICE: |
| 1742 | target = (void *) &inti->ext; |
| 1743 | source = &uptr->u.ext; |
| 1744 | size = sizeof(inti->ext); |
| 1745 | break; |
| 1746 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1747 | target = (void *) &inti->io; |
| 1748 | source = &uptr->u.io; |
| 1749 | size = sizeof(inti->io); |
| 1750 | break; |
| 1751 | case KVM_S390_MCHK: |
| 1752 | target = (void *) &inti->mchk; |
| 1753 | source = &uptr->u.mchk; |
| 1754 | size = sizeof(inti->mchk); |
| 1755 | break; |
| 1756 | default: |
| 1757 | return -EINVAL; |
| 1758 | } |
| 1759 | |
| 1760 | if (copy_from_user(target, source, size)) |
| 1761 | return -EFAULT; |
| 1762 | |
| 1763 | return 0; |
| 1764 | } |
| 1765 | |
| 1766 | static int enqueue_floating_irq(struct kvm_device *dev, |
| 1767 | struct kvm_device_attr *attr) |
| 1768 | { |
| 1769 | struct kvm_s390_interrupt_info *inti = NULL; |
| 1770 | int r = 0; |
| 1771 | int len = attr->attr; |
| 1772 | |
| 1773 | if (len % sizeof(struct kvm_s390_irq) != 0) |
| 1774 | return -EINVAL; |
| 1775 | else if (len > KVM_S390_FLIC_MAX_BUFFER) |
| 1776 | return -EINVAL; |
| 1777 | |
| 1778 | while (len >= sizeof(struct kvm_s390_irq)) { |
| 1779 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1780 | if (!inti) |
| 1781 | return -ENOMEM; |
| 1782 | |
| 1783 | r = copy_irq_from_user(inti, attr->addr); |
| 1784 | if (r) { |
| 1785 | kfree(inti); |
| 1786 | return r; |
| 1787 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1788 | r = __inject_vm(dev->kvm, inti); |
| 1789 | if (r) { |
| 1790 | kfree(inti); |
| 1791 | return r; |
| 1792 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1793 | len -= sizeof(struct kvm_s390_irq); |
| 1794 | attr->addr += sizeof(struct kvm_s390_irq); |
| 1795 | } |
| 1796 | |
| 1797 | return r; |
| 1798 | } |
| 1799 | |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1800 | static struct s390_io_adapter *get_io_adapter(struct kvm *kvm, unsigned int id) |
| 1801 | { |
| 1802 | if (id >= MAX_S390_IO_ADAPTERS) |
| 1803 | return NULL; |
| 1804 | return kvm->arch.adapters[id]; |
| 1805 | } |
| 1806 | |
| 1807 | static int register_io_adapter(struct kvm_device *dev, |
| 1808 | struct kvm_device_attr *attr) |
| 1809 | { |
| 1810 | struct s390_io_adapter *adapter; |
| 1811 | struct kvm_s390_io_adapter adapter_info; |
| 1812 | |
| 1813 | if (copy_from_user(&adapter_info, |
| 1814 | (void __user *)attr->addr, sizeof(adapter_info))) |
| 1815 | return -EFAULT; |
| 1816 | |
| 1817 | if ((adapter_info.id >= MAX_S390_IO_ADAPTERS) || |
| 1818 | (dev->kvm->arch.adapters[adapter_info.id] != NULL)) |
| 1819 | return -EINVAL; |
| 1820 | |
| 1821 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 1822 | if (!adapter) |
| 1823 | return -ENOMEM; |
| 1824 | |
| 1825 | INIT_LIST_HEAD(&adapter->maps); |
| 1826 | init_rwsem(&adapter->maps_lock); |
| 1827 | atomic_set(&adapter->nr_maps, 0); |
| 1828 | adapter->id = adapter_info.id; |
| 1829 | adapter->isc = adapter_info.isc; |
| 1830 | adapter->maskable = adapter_info.maskable; |
| 1831 | adapter->masked = false; |
| 1832 | adapter->swap = adapter_info.swap; |
| 1833 | dev->kvm->arch.adapters[adapter->id] = adapter; |
| 1834 | |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
| 1838 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked) |
| 1839 | { |
| 1840 | int ret; |
| 1841 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1842 | |
| 1843 | if (!adapter || !adapter->maskable) |
| 1844 | return -EINVAL; |
| 1845 | ret = adapter->masked; |
| 1846 | adapter->masked = masked; |
| 1847 | return ret; |
| 1848 | } |
| 1849 | |
| 1850 | static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1851 | { |
| 1852 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1853 | struct s390_map_info *map; |
| 1854 | int ret; |
| 1855 | |
| 1856 | if (!adapter || !addr) |
| 1857 | return -EINVAL; |
| 1858 | |
| 1859 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 1860 | if (!map) { |
| 1861 | ret = -ENOMEM; |
| 1862 | goto out; |
| 1863 | } |
| 1864 | INIT_LIST_HEAD(&map->list); |
| 1865 | map->guest_addr = addr; |
Martin Schwidefsky | 6e0a043 | 2014-04-29 09:34:41 +0200 | [diff] [blame] | 1866 | map->addr = gmap_translate(kvm->arch.gmap, addr); |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1867 | if (map->addr == -EFAULT) { |
| 1868 | ret = -EFAULT; |
| 1869 | goto out; |
| 1870 | } |
| 1871 | ret = get_user_pages_fast(map->addr, 1, 1, &map->page); |
| 1872 | if (ret < 0) |
| 1873 | goto out; |
| 1874 | BUG_ON(ret != 1); |
| 1875 | down_write(&adapter->maps_lock); |
| 1876 | if (atomic_inc_return(&adapter->nr_maps) < MAX_S390_ADAPTER_MAPS) { |
| 1877 | list_add_tail(&map->list, &adapter->maps); |
| 1878 | ret = 0; |
| 1879 | } else { |
| 1880 | put_page(map->page); |
| 1881 | ret = -EINVAL; |
| 1882 | } |
| 1883 | up_write(&adapter->maps_lock); |
| 1884 | out: |
| 1885 | if (ret) |
| 1886 | kfree(map); |
| 1887 | return ret; |
| 1888 | } |
| 1889 | |
| 1890 | static int kvm_s390_adapter_unmap(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1891 | { |
| 1892 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1893 | struct s390_map_info *map, *tmp; |
| 1894 | int found = 0; |
| 1895 | |
| 1896 | if (!adapter || !addr) |
| 1897 | return -EINVAL; |
| 1898 | |
| 1899 | down_write(&adapter->maps_lock); |
| 1900 | list_for_each_entry_safe(map, tmp, &adapter->maps, list) { |
| 1901 | if (map->guest_addr == addr) { |
| 1902 | found = 1; |
| 1903 | atomic_dec(&adapter->nr_maps); |
| 1904 | list_del(&map->list); |
| 1905 | put_page(map->page); |
| 1906 | kfree(map); |
| 1907 | break; |
| 1908 | } |
| 1909 | } |
| 1910 | up_write(&adapter->maps_lock); |
| 1911 | |
| 1912 | return found ? 0 : -EINVAL; |
| 1913 | } |
| 1914 | |
| 1915 | void kvm_s390_destroy_adapters(struct kvm *kvm) |
| 1916 | { |
| 1917 | int i; |
| 1918 | struct s390_map_info *map, *tmp; |
| 1919 | |
| 1920 | for (i = 0; i < MAX_S390_IO_ADAPTERS; i++) { |
| 1921 | if (!kvm->arch.adapters[i]) |
| 1922 | continue; |
| 1923 | list_for_each_entry_safe(map, tmp, |
| 1924 | &kvm->arch.adapters[i]->maps, list) { |
| 1925 | list_del(&map->list); |
| 1926 | put_page(map->page); |
| 1927 | kfree(map); |
| 1928 | } |
| 1929 | kfree(kvm->arch.adapters[i]); |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | static int modify_io_adapter(struct kvm_device *dev, |
| 1934 | struct kvm_device_attr *attr) |
| 1935 | { |
| 1936 | struct kvm_s390_io_adapter_req req; |
| 1937 | struct s390_io_adapter *adapter; |
| 1938 | int ret; |
| 1939 | |
| 1940 | if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) |
| 1941 | return -EFAULT; |
| 1942 | |
| 1943 | adapter = get_io_adapter(dev->kvm, req.id); |
| 1944 | if (!adapter) |
| 1945 | return -EINVAL; |
| 1946 | switch (req.type) { |
| 1947 | case KVM_S390_IO_ADAPTER_MASK: |
| 1948 | ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask); |
| 1949 | if (ret > 0) |
| 1950 | ret = 0; |
| 1951 | break; |
| 1952 | case KVM_S390_IO_ADAPTER_MAP: |
| 1953 | ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); |
| 1954 | break; |
| 1955 | case KVM_S390_IO_ADAPTER_UNMAP: |
| 1956 | ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); |
| 1957 | break; |
| 1958 | default: |
| 1959 | ret = -EINVAL; |
| 1960 | } |
| 1961 | |
| 1962 | return ret; |
| 1963 | } |
| 1964 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1965 | static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1966 | { |
| 1967 | int r = 0; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1968 | unsigned int i; |
| 1969 | struct kvm_vcpu *vcpu; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1970 | |
| 1971 | switch (attr->group) { |
| 1972 | case KVM_DEV_FLIC_ENQUEUE: |
| 1973 | r = enqueue_floating_irq(dev, attr); |
| 1974 | break; |
| 1975 | case KVM_DEV_FLIC_CLEAR_IRQS: |
Christian Borntraeger | 67335e6 | 2014-03-25 17:09:08 +0100 | [diff] [blame] | 1976 | kvm_s390_clear_float_irqs(dev->kvm); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1977 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1978 | case KVM_DEV_FLIC_APF_ENABLE: |
| 1979 | dev->kvm->arch.gmap->pfault_enabled = 1; |
| 1980 | break; |
| 1981 | case KVM_DEV_FLIC_APF_DISABLE_WAIT: |
| 1982 | dev->kvm->arch.gmap->pfault_enabled = 0; |
| 1983 | /* |
| 1984 | * Make sure no async faults are in transition when |
| 1985 | * clearing the queues. So we don't need to worry |
| 1986 | * about late coming workers. |
| 1987 | */ |
| 1988 | synchronize_srcu(&dev->kvm->srcu); |
| 1989 | kvm_for_each_vcpu(i, vcpu, dev->kvm) |
| 1990 | kvm_clear_async_pf_completion_queue(vcpu); |
| 1991 | break; |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1992 | case KVM_DEV_FLIC_ADAPTER_REGISTER: |
| 1993 | r = register_io_adapter(dev, attr); |
| 1994 | break; |
| 1995 | case KVM_DEV_FLIC_ADAPTER_MODIFY: |
| 1996 | r = modify_io_adapter(dev, attr); |
| 1997 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1998 | default: |
| 1999 | r = -EINVAL; |
| 2000 | } |
| 2001 | |
| 2002 | return r; |
| 2003 | } |
| 2004 | |
| 2005 | static int flic_create(struct kvm_device *dev, u32 type) |
| 2006 | { |
| 2007 | if (!dev) |
| 2008 | return -EINVAL; |
| 2009 | if (dev->kvm->arch.flic) |
| 2010 | return -EINVAL; |
| 2011 | dev->kvm->arch.flic = dev; |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | static void flic_destroy(struct kvm_device *dev) |
| 2016 | { |
| 2017 | dev->kvm->arch.flic = NULL; |
| 2018 | kfree(dev); |
| 2019 | } |
| 2020 | |
| 2021 | /* s390 floating irq controller (flic) */ |
| 2022 | struct kvm_device_ops kvm_flic_ops = { |
| 2023 | .name = "kvm-flic", |
| 2024 | .get_attr = flic_get_attr, |
| 2025 | .set_attr = flic_set_attr, |
| 2026 | .create = flic_create, |
| 2027 | .destroy = flic_destroy, |
| 2028 | }; |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 2029 | |
| 2030 | static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) |
| 2031 | { |
| 2032 | unsigned long bit; |
| 2033 | |
| 2034 | bit = bit_nr + (addr % PAGE_SIZE) * 8; |
| 2035 | |
| 2036 | return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; |
| 2037 | } |
| 2038 | |
| 2039 | static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, |
| 2040 | u64 addr) |
| 2041 | { |
| 2042 | struct s390_map_info *map; |
| 2043 | |
| 2044 | if (!adapter) |
| 2045 | return NULL; |
| 2046 | |
| 2047 | list_for_each_entry(map, &adapter->maps, list) { |
| 2048 | if (map->guest_addr == addr) |
| 2049 | return map; |
| 2050 | } |
| 2051 | return NULL; |
| 2052 | } |
| 2053 | |
| 2054 | static int adapter_indicators_set(struct kvm *kvm, |
| 2055 | struct s390_io_adapter *adapter, |
| 2056 | struct kvm_s390_adapter_int *adapter_int) |
| 2057 | { |
| 2058 | unsigned long bit; |
| 2059 | int summary_set, idx; |
| 2060 | struct s390_map_info *info; |
| 2061 | void *map; |
| 2062 | |
| 2063 | info = get_map_info(adapter, adapter_int->ind_addr); |
| 2064 | if (!info) |
| 2065 | return -1; |
| 2066 | map = page_address(info->page); |
| 2067 | bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); |
| 2068 | set_bit(bit, map); |
| 2069 | idx = srcu_read_lock(&kvm->srcu); |
| 2070 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 2071 | set_page_dirty_lock(info->page); |
| 2072 | info = get_map_info(adapter, adapter_int->summary_addr); |
| 2073 | if (!info) { |
| 2074 | srcu_read_unlock(&kvm->srcu, idx); |
| 2075 | return -1; |
| 2076 | } |
| 2077 | map = page_address(info->page); |
| 2078 | bit = get_ind_bit(info->addr, adapter_int->summary_offset, |
| 2079 | adapter->swap); |
| 2080 | summary_set = test_and_set_bit(bit, map); |
| 2081 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 2082 | set_page_dirty_lock(info->page); |
| 2083 | srcu_read_unlock(&kvm->srcu, idx); |
| 2084 | return summary_set ? 0 : 1; |
| 2085 | } |
| 2086 | |
| 2087 | /* |
| 2088 | * < 0 - not injected due to error |
| 2089 | * = 0 - coalesced, summary indicator already active |
| 2090 | * > 0 - injected interrupt |
| 2091 | */ |
| 2092 | static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, |
| 2093 | struct kvm *kvm, int irq_source_id, int level, |
| 2094 | bool line_status) |
| 2095 | { |
| 2096 | int ret; |
| 2097 | struct s390_io_adapter *adapter; |
| 2098 | |
| 2099 | /* We're only interested in the 0->1 transition. */ |
| 2100 | if (!level) |
| 2101 | return 0; |
| 2102 | adapter = get_io_adapter(kvm, e->adapter.adapter_id); |
| 2103 | if (!adapter) |
| 2104 | return -1; |
| 2105 | down_read(&adapter->maps_lock); |
| 2106 | ret = adapter_indicators_set(kvm, adapter, &e->adapter); |
| 2107 | up_read(&adapter->maps_lock); |
| 2108 | if ((ret > 0) && !adapter->masked) { |
| 2109 | struct kvm_s390_interrupt s390int = { |
| 2110 | .type = KVM_S390_INT_IO(1, 0, 0, 0), |
| 2111 | .parm = 0, |
| 2112 | .parm64 = (adapter->isc << 27) | 0x80000000, |
| 2113 | }; |
| 2114 | ret = kvm_s390_inject_vm(kvm, &s390int); |
| 2115 | if (ret == 0) |
| 2116 | ret = 1; |
| 2117 | } |
| 2118 | return ret; |
| 2119 | } |
| 2120 | |
Paul Mackerras | 8ba918d | 2014-06-30 20:51:10 +1000 | [diff] [blame] | 2121 | int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 2122 | const struct kvm_irq_routing_entry *ue) |
| 2123 | { |
| 2124 | int ret; |
| 2125 | |
| 2126 | switch (ue->type) { |
| 2127 | case KVM_IRQ_ROUTING_S390_ADAPTER: |
| 2128 | e->set = set_adapter_int; |
| 2129 | e->adapter.summary_addr = ue->u.adapter.summary_addr; |
| 2130 | e->adapter.ind_addr = ue->u.adapter.ind_addr; |
| 2131 | e->adapter.summary_offset = ue->u.adapter.summary_offset; |
| 2132 | e->adapter.ind_offset = ue->u.adapter.ind_offset; |
| 2133 | e->adapter.adapter_id = ue->u.adapter.adapter_id; |
| 2134 | ret = 0; |
| 2135 | break; |
| 2136 | default: |
| 2137 | ret = -EINVAL; |
| 2138 | } |
| 2139 | |
| 2140 | return ret; |
| 2141 | } |
| 2142 | |
| 2143 | int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, |
| 2144 | int irq_source_id, int level, bool line_status) |
| 2145 | { |
| 2146 | return -EINVAL; |
| 2147 | } |
Jens Freimann | 816c766 | 2014-11-24 17:13:46 +0100 | [diff] [blame] | 2148 | |
| 2149 | int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int len) |
| 2150 | { |
| 2151 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 2152 | struct kvm_s390_irq *buf; |
| 2153 | int r = 0; |
| 2154 | int n; |
| 2155 | |
| 2156 | buf = vmalloc(len); |
| 2157 | if (!buf) |
| 2158 | return -ENOMEM; |
| 2159 | |
| 2160 | if (copy_from_user((void *) buf, irqstate, len)) { |
| 2161 | r = -EFAULT; |
| 2162 | goto out_free; |
| 2163 | } |
| 2164 | |
| 2165 | /* |
| 2166 | * Don't allow setting the interrupt state |
| 2167 | * when there are already interrupts pending |
| 2168 | */ |
| 2169 | spin_lock(&li->lock); |
| 2170 | if (li->pending_irqs) { |
| 2171 | r = -EBUSY; |
| 2172 | goto out_unlock; |
| 2173 | } |
| 2174 | |
| 2175 | for (n = 0; n < len / sizeof(*buf); n++) { |
| 2176 | r = do_inject_vcpu(vcpu, &buf[n]); |
| 2177 | if (r) |
| 2178 | break; |
| 2179 | } |
| 2180 | |
| 2181 | out_unlock: |
| 2182 | spin_unlock(&li->lock); |
| 2183 | out_free: |
| 2184 | vfree(buf); |
| 2185 | |
| 2186 | return r; |
| 2187 | } |
| 2188 | |
| 2189 | static void store_local_irq(struct kvm_s390_local_interrupt *li, |
| 2190 | struct kvm_s390_irq *irq, |
| 2191 | unsigned long irq_type) |
| 2192 | { |
| 2193 | switch (irq_type) { |
| 2194 | case IRQ_PEND_MCHK_EX: |
| 2195 | case IRQ_PEND_MCHK_REP: |
| 2196 | irq->type = KVM_S390_MCHK; |
| 2197 | irq->u.mchk = li->irq.mchk; |
| 2198 | break; |
| 2199 | case IRQ_PEND_PROG: |
| 2200 | irq->type = KVM_S390_PROGRAM_INT; |
| 2201 | irq->u.pgm = li->irq.pgm; |
| 2202 | break; |
| 2203 | case IRQ_PEND_PFAULT_INIT: |
| 2204 | irq->type = KVM_S390_INT_PFAULT_INIT; |
| 2205 | irq->u.ext = li->irq.ext; |
| 2206 | break; |
| 2207 | case IRQ_PEND_EXT_EXTERNAL: |
| 2208 | irq->type = KVM_S390_INT_EXTERNAL_CALL; |
| 2209 | irq->u.extcall = li->irq.extcall; |
| 2210 | break; |
| 2211 | case IRQ_PEND_EXT_CLOCK_COMP: |
| 2212 | irq->type = KVM_S390_INT_CLOCK_COMP; |
| 2213 | break; |
| 2214 | case IRQ_PEND_EXT_CPU_TIMER: |
| 2215 | irq->type = KVM_S390_INT_CPU_TIMER; |
| 2216 | break; |
| 2217 | case IRQ_PEND_SIGP_STOP: |
| 2218 | irq->type = KVM_S390_SIGP_STOP; |
| 2219 | irq->u.stop = li->irq.stop; |
| 2220 | break; |
| 2221 | case IRQ_PEND_RESTART: |
| 2222 | irq->type = KVM_S390_RESTART; |
| 2223 | break; |
| 2224 | case IRQ_PEND_SET_PREFIX: |
| 2225 | irq->type = KVM_S390_SIGP_SET_PREFIX; |
| 2226 | irq->u.prefix = li->irq.prefix; |
| 2227 | break; |
| 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | int kvm_s390_get_irq_state(struct kvm_vcpu *vcpu, __u8 __user *buf, int len) |
| 2232 | { |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 2233 | int scn; |
Jens Freimann | 816c766 | 2014-11-24 17:13:46 +0100 | [diff] [blame] | 2234 | unsigned long sigp_emerg_pending[BITS_TO_LONGS(KVM_MAX_VCPUS)]; |
| 2235 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 2236 | unsigned long pending_irqs; |
| 2237 | struct kvm_s390_irq irq; |
| 2238 | unsigned long irq_type; |
| 2239 | int cpuaddr; |
| 2240 | int n = 0; |
| 2241 | |
| 2242 | spin_lock(&li->lock); |
| 2243 | pending_irqs = li->pending_irqs; |
| 2244 | memcpy(&sigp_emerg_pending, &li->sigp_emerg_pending, |
| 2245 | sizeof(sigp_emerg_pending)); |
| 2246 | spin_unlock(&li->lock); |
| 2247 | |
| 2248 | for_each_set_bit(irq_type, &pending_irqs, IRQ_PEND_COUNT) { |
| 2249 | memset(&irq, 0, sizeof(irq)); |
| 2250 | if (irq_type == IRQ_PEND_EXT_EMERGENCY) |
| 2251 | continue; |
| 2252 | if (n + sizeof(irq) > len) |
| 2253 | return -ENOBUFS; |
| 2254 | store_local_irq(&vcpu->arch.local_int, &irq, irq_type); |
| 2255 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) |
| 2256 | return -EFAULT; |
| 2257 | n += sizeof(irq); |
| 2258 | } |
| 2259 | |
| 2260 | if (test_bit(IRQ_PEND_EXT_EMERGENCY, &pending_irqs)) { |
| 2261 | for_each_set_bit(cpuaddr, sigp_emerg_pending, KVM_MAX_VCPUS) { |
| 2262 | memset(&irq, 0, sizeof(irq)); |
| 2263 | if (n + sizeof(irq) > len) |
| 2264 | return -ENOBUFS; |
| 2265 | irq.type = KVM_S390_INT_EMERGENCY; |
| 2266 | irq.u.emerg.code = cpuaddr; |
| 2267 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) |
| 2268 | return -EFAULT; |
| 2269 | n += sizeof(irq); |
| 2270 | } |
| 2271 | } |
| 2272 | |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 2273 | if (sca_ext_call_pending(vcpu, &scn)) { |
Jens Freimann | 816c766 | 2014-11-24 17:13:46 +0100 | [diff] [blame] | 2274 | if (n + sizeof(irq) > len) |
| 2275 | return -ENOBUFS; |
| 2276 | memset(&irq, 0, sizeof(irq)); |
| 2277 | irq.type = KVM_S390_INT_EXTERNAL_CALL; |
Eugene (jno) Dvurechenski | a5bd764 | 2015-04-21 15:10:10 +0200 | [diff] [blame] | 2278 | irq.u.extcall.code = scn; |
Jens Freimann | 816c766 | 2014-11-24 17:13:46 +0100 | [diff] [blame] | 2279 | if (copy_to_user(&buf[n], &irq, sizeof(irq))) |
| 2280 | return -EFAULT; |
| 2281 | n += sizeof(irq); |
| 2282 | } |
| 2283 | |
| 2284 | return n; |
| 2285 | } |