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