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; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 487 | int rc = 0; |
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: |
| 512 | case PGM_SPACE_SWITCH: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 513 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 514 | (u64 *)__LC_TRANS_EXC_CODE); |
| 515 | break; |
| 516 | case PGM_ALEN_TRANSLATION: |
| 517 | case PGM_ALE_SEQUENCE: |
| 518 | case PGM_ASTE_INSTANCE: |
| 519 | case PGM_ASTE_SEQUENCE: |
| 520 | case PGM_ASTE_VALIDITY: |
| 521 | case PGM_EXTENDED_AUTHORITY: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 522 | rc = put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 523 | (u8 *)__LC_EXC_ACCESS_ID); |
| 524 | break; |
| 525 | case PGM_ASCE_TYPE: |
| 526 | case PGM_PAGE_TRANSLATION: |
| 527 | case PGM_REGION_FIRST_TRANS: |
| 528 | case PGM_REGION_SECOND_TRANS: |
| 529 | case PGM_REGION_THIRD_TRANS: |
| 530 | case PGM_SEGMENT_TRANSLATION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 531 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 532 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 533 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 534 | (u8 *)__LC_EXC_ACCESS_ID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 535 | rc |= put_guest_lc(vcpu, pgm_info.op_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 536 | (u8 *)__LC_OP_ACCESS_ID); |
| 537 | break; |
| 538 | case PGM_MONITOR: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 539 | rc = put_guest_lc(vcpu, pgm_info.mon_class_nr, |
Thomas Huth | a36c539 | 2014-10-16 14:31:53 +0200 | [diff] [blame] | 540 | (u16 *)__LC_MON_CLASS_NR); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 541 | rc |= put_guest_lc(vcpu, pgm_info.mon_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 542 | (u64 *)__LC_MON_CODE); |
| 543 | break; |
| 544 | case PGM_DATA: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 545 | rc = put_guest_lc(vcpu, pgm_info.data_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 546 | (u32 *)__LC_DATA_EXC_CODE); |
| 547 | break; |
| 548 | case PGM_PROTECTION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 549 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 550 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 551 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 552 | (u8 *)__LC_EXC_ACCESS_ID); |
| 553 | break; |
| 554 | } |
| 555 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 556 | if (pgm_info.code & PGM_PER) { |
| 557 | rc |= put_guest_lc(vcpu, pgm_info.per_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 558 | (u8 *) __LC_PER_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 559 | rc |= put_guest_lc(vcpu, pgm_info.per_atmid, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 560 | (u8 *)__LC_PER_ATMID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 561 | rc |= put_guest_lc(vcpu, pgm_info.per_address, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 562 | (u64 *) __LC_PER_ADDRESS); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 563 | rc |= put_guest_lc(vcpu, pgm_info.per_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 564 | (u8 *) __LC_PER_ACCESS_ID); |
| 565 | } |
| 566 | |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 567 | rc |= put_guest_lc(vcpu, ilc, (u16 *) __LC_PGM_ILC); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 568 | rc |= put_guest_lc(vcpu, pgm_info.code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 569 | (u16 *)__LC_PGM_INT_CODE); |
| 570 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, |
| 571 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 572 | rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, |
| 573 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 574 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 575 | } |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 576 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 577 | static int __must_check __deliver_service(struct kvm_vcpu *vcpu, |
| 578 | struct kvm_s390_interrupt_info *inti) |
| 579 | { |
| 580 | int rc; |
| 581 | |
| 582 | VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x", |
| 583 | inti->ext.ext_params); |
| 584 | vcpu->stat.deliver_service_signal++; |
| 585 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 586 | inti->ext.ext_params, 0); |
| 587 | |
| 588 | 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] | 589 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 590 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 591 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 592 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 593 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 594 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 595 | (u32 *)__LC_EXT_PARAMS); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 596 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu, |
| 600 | struct kvm_s390_interrupt_info *inti) |
| 601 | { |
| 602 | int rc; |
| 603 | |
| 604 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 605 | KVM_S390_INT_PFAULT_DONE, 0, |
| 606 | inti->ext.ext_params2); |
| 607 | |
| 608 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); |
| 609 | rc |= put_guest_lc(vcpu, PFAULT_DONE, (u16 *)__LC_EXT_CPU_ADDR); |
| 610 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 611 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 612 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 613 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 614 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 615 | (u64 *)__LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 616 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu, |
| 620 | struct kvm_s390_interrupt_info *inti) |
| 621 | { |
| 622 | int rc; |
| 623 | |
| 624 | VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx", |
| 625 | inti->ext.ext_params, inti->ext.ext_params2); |
| 626 | vcpu->stat.deliver_virtio_interrupt++; |
| 627 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 628 | inti->ext.ext_params, |
| 629 | inti->ext.ext_params2); |
| 630 | |
| 631 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); |
| 632 | rc |= put_guest_lc(vcpu, VIRTIO_PARAM, (u16 *)__LC_EXT_CPU_ADDR); |
| 633 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 634 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 635 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 636 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 637 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 638 | (u32 *)__LC_EXT_PARAMS); |
| 639 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 640 | (u64 *)__LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 641 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static int __must_check __deliver_io(struct kvm_vcpu *vcpu, |
| 645 | struct kvm_s390_interrupt_info *inti) |
| 646 | { |
| 647 | int rc; |
| 648 | |
| 649 | VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type); |
| 650 | vcpu->stat.deliver_io_int++; |
| 651 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 652 | ((__u32)inti->io.subchannel_id << 16) | |
| 653 | inti->io.subchannel_nr, |
| 654 | ((__u64)inti->io.io_int_parm << 32) | |
| 655 | inti->io.io_int_word); |
| 656 | |
| 657 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, |
| 658 | (u16 *)__LC_SUBCHANNEL_ID); |
| 659 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, |
| 660 | (u16 *)__LC_SUBCHANNEL_NR); |
| 661 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, |
| 662 | (u32 *)__LC_IO_INT_PARM); |
| 663 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, |
| 664 | (u32 *)__LC_IO_INT_WORD); |
| 665 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, |
| 666 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 667 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, |
| 668 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 669 | return rc ? -EFAULT : 0; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 670 | } |
| 671 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 672 | static int __must_check __deliver_mchk_floating(struct kvm_vcpu *vcpu, |
| 673 | struct kvm_s390_interrupt_info *inti) |
| 674 | { |
| 675 | struct kvm_s390_mchk_info *mchk = &inti->mchk; |
| 676 | int rc; |
| 677 | |
| 678 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", |
| 679 | mchk->mcic); |
| 680 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_MCHK, |
| 681 | mchk->cr14, mchk->mcic); |
| 682 | |
| 683 | rc = kvm_s390_vcpu_store_status(vcpu, KVM_S390_STORE_STATUS_PREFIXED); |
| 684 | rc |= put_guest_lc(vcpu, mchk->mcic, |
| 685 | (u64 __user *) __LC_MCCK_CODE); |
| 686 | rc |= put_guest_lc(vcpu, mchk->failing_storage_address, |
| 687 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); |
| 688 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, |
| 689 | &mchk->fixed_logout, sizeof(mchk->fixed_logout)); |
| 690 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, |
| 691 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 692 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, |
| 693 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 694 | return rc ? -EFAULT : 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | typedef int (*deliver_irq_t)(struct kvm_vcpu *vcpu); |
| 698 | |
| 699 | static const deliver_irq_t deliver_irq_funcs[] = { |
| 700 | [IRQ_PEND_MCHK_EX] = __deliver_machine_check, |
| 701 | [IRQ_PEND_PROG] = __deliver_prog, |
| 702 | [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal, |
| 703 | [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call, |
| 704 | [IRQ_PEND_EXT_CLOCK_COMP] = __deliver_ckc, |
| 705 | [IRQ_PEND_EXT_CPU_TIMER] = __deliver_cpu_timer, |
| 706 | [IRQ_PEND_RESTART] = __deliver_restart, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 707 | [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix, |
| 708 | [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init, |
| 709 | }; |
| 710 | |
| 711 | static int __must_check __deliver_floating_interrupt(struct kvm_vcpu *vcpu, |
| 712 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 713 | { |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 714 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 715 | |
| 716 | switch (inti->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 717 | case KVM_S390_INT_SERVICE: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 718 | rc = __deliver_service(vcpu, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 719 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 720 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 721 | rc = __deliver_pfault_done(vcpu, inti); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 722 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 723 | case KVM_S390_INT_VIRTIO: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 724 | rc = __deliver_virtio(vcpu, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 725 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 726 | case KVM_S390_MCHK: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 727 | rc = __deliver_mchk_floating(vcpu, inti); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 728 | break; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 729 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 730 | rc = __deliver_io(vcpu, inti); |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 731 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 732 | default: |
| 733 | BUG(); |
| 734 | } |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 735 | |
| 736 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 737 | } |
| 738 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 739 | /* Check whether an external call is pending (deliverable or not) */ |
| 740 | int kvm_s390_ext_call_pending(struct kvm_vcpu *vcpu) |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 741 | { |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 742 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 743 | 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] | 744 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 745 | if (!sclp_has_sigpif()) |
| 746 | return test_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 747 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 748 | return (sigp_ctrl & SIGP_CTRL_C) && |
| 749 | (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_ECALL_PEND); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 750 | } |
| 751 | |
David Hildenbrand | 9a02206 | 2014-08-05 17:40:47 +0200 | [diff] [blame] | 752 | 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] | 753 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 754 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 755 | struct kvm_s390_interrupt_info *inti; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 756 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 757 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 758 | rc = !!deliverable_local_irqs(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 759 | |
| 760 | if ((!rc) && atomic_read(&fi->active)) { |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 761 | spin_lock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 762 | list_for_each_entry(inti, &fi->list, list) |
| 763 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 764 | rc = 1; |
| 765 | break; |
| 766 | } |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 767 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 768 | } |
| 769 | |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 770 | if (!rc && kvm_cpu_has_pending_timer(vcpu)) |
| 771 | rc = 1; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 772 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 773 | /* external call pending and deliverable */ |
| 774 | if (!rc && kvm_s390_ext_call_pending(vcpu) && |
| 775 | !psw_extint_disabled(vcpu) && |
| 776 | (vcpu->arch.sie_block->gcr[0] & 0x2000ul)) |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 777 | rc = 1; |
| 778 | |
David Hildenbrand | 9a02206 | 2014-08-05 17:40:47 +0200 | [diff] [blame] | 779 | if (!rc && !exclude_stop && kvm_s390_is_stop_irq_pending(vcpu)) |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 780 | rc = 1; |
| 781 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 782 | return rc; |
| 783 | } |
| 784 | |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 785 | int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) |
| 786 | { |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 787 | if (!(vcpu->arch.sie_block->ckc < |
| 788 | get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) |
| 789 | return 0; |
| 790 | if (!ckc_interrupts_enabled(vcpu)) |
| 791 | return 0; |
| 792 | return 1; |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 793 | } |
| 794 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 795 | int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) |
| 796 | { |
| 797 | u64 now, sltime; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 798 | |
| 799 | vcpu->stat.exit_wait_state++; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 800 | |
David Hildenbrand | 0759d06 | 2014-05-13 16:54:32 +0200 | [diff] [blame] | 801 | /* fast path */ |
| 802 | if (kvm_cpu_has_pending_timer(vcpu) || kvm_arch_vcpu_runnable(vcpu)) |
| 803 | return 0; |
Carsten Otte | e52b2af | 2008-05-21 13:37:44 +0200 | [diff] [blame] | 804 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 805 | if (psw_interrupts_disabled(vcpu)) { |
| 806 | VCPU_EVENT(vcpu, 3, "%s", "disabled wait"); |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 807 | return -EOPNOTSUPP; /* disabled wait */ |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 808 | } |
| 809 | |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 810 | if (!ckc_interrupts_enabled(vcpu)) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 811 | VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer"); |
David Hildenbrand | bda343e | 2014-12-12 12:26:40 +0100 | [diff] [blame] | 812 | __set_cpu_idle(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 813 | goto no_timer; |
| 814 | } |
| 815 | |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 816 | now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; |
Heiko Carstens | ed4f209 | 2013-01-14 16:55:55 +0100 | [diff] [blame] | 817 | sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); |
David Hildenbrand | bda343e | 2014-12-12 12:26:40 +0100 | [diff] [blame] | 818 | |
| 819 | /* underflow */ |
| 820 | if (vcpu->arch.sie_block->ckc < now) |
| 821 | return 0; |
| 822 | |
| 823 | __set_cpu_idle(vcpu); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 824 | hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL); |
| 825 | VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 826 | no_timer: |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 827 | srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); |
David Hildenbrand | 0759d06 | 2014-05-13 16:54:32 +0200 | [diff] [blame] | 828 | kvm_vcpu_block(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 829 | __unset_cpu_idle(vcpu); |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 830 | vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 831 | |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 832 | hrtimer_cancel(&vcpu->arch.ckc_timer); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 833 | return 0; |
| 834 | } |
| 835 | |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 836 | void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu) |
| 837 | { |
| 838 | if (waitqueue_active(&vcpu->wq)) { |
| 839 | /* |
| 840 | * The vcpu gave up the cpu voluntarily, mark it as a good |
| 841 | * yield-candidate. |
| 842 | */ |
| 843 | vcpu->preempted = true; |
| 844 | wake_up_interruptible(&vcpu->wq); |
David Hildenbrand | ce2e4f0 | 2014-07-11 10:00:43 +0200 | [diff] [blame] | 845 | vcpu->stat.halt_wakeup++; |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 849 | enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) |
| 850 | { |
| 851 | struct kvm_vcpu *vcpu; |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 852 | u64 now, sltime; |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 853 | |
| 854 | vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 855 | now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; |
| 856 | sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 857 | |
David Hildenbrand | 2d00f75 | 2014-12-11 10:18:01 +0100 | [diff] [blame] | 858 | /* |
| 859 | * If the monotonic clock runs faster than the tod clock we might be |
| 860 | * woken up too early and have to go back to sleep to avoid deadlocks. |
| 861 | */ |
| 862 | if (vcpu->arch.sie_block->ckc > now && |
| 863 | hrtimer_forward_now(timer, ns_to_ktime(sltime))) |
| 864 | return HRTIMER_RESTART; |
| 865 | kvm_s390_vcpu_wakeup(vcpu); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 866 | return HRTIMER_NORESTART; |
| 867 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 868 | |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 869 | void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu) |
| 870 | { |
| 871 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 872 | |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 873 | spin_lock(&li->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 874 | li->pending_irqs = 0; |
| 875 | bitmap_zero(li->sigp_emerg_pending, KVM_MAX_VCPUS); |
| 876 | memset(&li->irq, 0, sizeof(li->irq)); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 877 | spin_unlock(&li->lock); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 878 | |
| 879 | /* clear pending external calls set by sigp interpretation facility */ |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 880 | atomic_clear_mask(CPUSTAT_ECALL_PEND, li->cpuflags); |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 881 | vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sigp_ctrl = 0; |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 882 | } |
| 883 | |
Christian Borntraeger | 614aeab | 2014-08-25 12:27:29 +0200 | [diff] [blame] | 884 | int __must_check kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 885 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 886 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 887 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 888 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 889 | deliver_irq_t func; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 890 | int deliver; |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 891 | int rc = 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 892 | unsigned long irq_type; |
| 893 | unsigned long deliverable_irqs; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 894 | |
| 895 | __reset_intercept_indicators(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 896 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 897 | /* pending ckc conditions might have been invalidated */ |
| 898 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
| 899 | if (kvm_cpu_has_pending_timer(vcpu)) |
| 900 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
| 901 | |
| 902 | do { |
| 903 | deliverable_irqs = deliverable_local_irqs(vcpu); |
| 904 | /* bits are in the order of interrupt priority */ |
| 905 | irq_type = find_first_bit(&deliverable_irqs, IRQ_PEND_COUNT); |
| 906 | if (irq_type == IRQ_PEND_COUNT) |
| 907 | break; |
| 908 | func = deliver_irq_funcs[irq_type]; |
| 909 | if (!func) { |
| 910 | WARN_ON_ONCE(func == NULL); |
| 911 | clear_bit(irq_type, &li->pending_irqs); |
| 912 | continue; |
| 913 | } |
| 914 | rc = func(vcpu); |
| 915 | } while (!rc && irq_type != IRQ_PEND_COUNT); |
| 916 | |
| 917 | set_intercept_indicators_local(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 918 | |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 919 | if (!rc && atomic_read(&fi->active)) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 920 | do { |
| 921 | deliver = 0; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 922 | spin_lock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 923 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 924 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 925 | list_del(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 926 | fi->irq_count--; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 927 | deliver = 1; |
| 928 | break; |
| 929 | } |
| 930 | __set_intercept_indicator(vcpu, inti); |
| 931 | } |
| 932 | if (list_empty(&fi->list)) |
| 933 | atomic_set(&fi->active, 0); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 934 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 935 | if (deliver) { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 936 | rc = __deliver_floating_interrupt(vcpu, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 937 | kfree(inti); |
| 938 | } |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 939 | } while (!rc && deliver); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 940 | } |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 941 | |
| 942 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 943 | } |
| 944 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 945 | 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] | 946 | { |
| 947 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 948 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 949 | li->irq.pgm = irq->u.pgm; |
Jens Freimann | 9185124 | 2014-12-01 16:43:40 +0100 | [diff] [blame] | 950 | set_bit(IRQ_PEND_PROG, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 951 | return 0; |
| 952 | } |
| 953 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 954 | int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) |
| 955 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 956 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 957 | struct kvm_s390_irq irq; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 958 | |
| 959 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 960 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, code, |
| 961 | 0, 1); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 962 | spin_lock(&li->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 963 | irq.u.pgm.code = code; |
| 964 | __inject_prog(vcpu, &irq); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 965 | BUG_ON(waitqueue_active(li->wq)); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 966 | spin_unlock(&li->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 967 | return 0; |
| 968 | } |
| 969 | |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 970 | int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, |
| 971 | struct kvm_s390_pgm_info *pgm_info) |
| 972 | { |
| 973 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 974 | struct kvm_s390_irq irq; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 975 | int rc; |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 976 | |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 977 | VCPU_EVENT(vcpu, 3, "inject: prog irq %d (from kernel)", |
| 978 | pgm_info->code); |
| 979 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, |
| 980 | pgm_info->code, 0, 1); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 981 | spin_lock(&li->lock); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 982 | irq.u.pgm = *pgm_info; |
| 983 | rc = __inject_prog(vcpu, &irq); |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 984 | BUG_ON(waitqueue_active(li->wq)); |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 985 | spin_unlock(&li->lock); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 986 | return rc; |
| 987 | } |
| 988 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 989 | 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] | 990 | { |
| 991 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 992 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 993 | VCPU_EVENT(vcpu, 3, "inject: external irq params:%x, params2:%llx", |
| 994 | irq->u.ext.ext_params, irq->u.ext.ext_params2); |
| 995 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_PFAULT_INIT, |
| 996 | irq->u.ext.ext_params, |
| 997 | irq->u.ext.ext_params2, 2); |
| 998 | |
| 999 | li->irq.ext = irq->u.ext; |
| 1000 | set_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1001 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1005 | static int __inject_extcall_sigpif(struct kvm_vcpu *vcpu, uint16_t src_id) |
| 1006 | { |
| 1007 | unsigned char new_val, old_val; |
| 1008 | uint8_t *sigp_ctrl = &vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sigp_ctrl; |
| 1009 | |
| 1010 | new_val = SIGP_CTRL_C | (src_id & SIGP_CTRL_SCN_MASK); |
| 1011 | old_val = *sigp_ctrl & ~SIGP_CTRL_C; |
| 1012 | if (cmpxchg(sigp_ctrl, old_val, new_val) != old_val) { |
| 1013 | /* another external call is pending */ |
| 1014 | return -EBUSY; |
| 1015 | } |
| 1016 | atomic_set_mask(CPUSTAT_ECALL_PEND, &vcpu->arch.sie_block->cpuflags); |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
Christian Borntraeger | 0675d92 | 2015-01-15 12:40:42 +0100 | [diff] [blame] | 1020 | 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] | 1021 | { |
| 1022 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1023 | struct kvm_s390_extcall_info *extcall = &li->irq.extcall; |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1024 | uint16_t src_id = irq->u.extcall.code; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1025 | |
| 1026 | VCPU_EVENT(vcpu, 3, "inject: external call source-cpu:%u", |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1027 | src_id); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1028 | 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] | 1029 | src_id, 0, 2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1030 | |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 1031 | /* sending vcpu invalid */ |
| 1032 | if (src_id >= KVM_MAX_VCPUS || |
| 1033 | kvm_get_vcpu(vcpu->kvm, src_id) == NULL) |
| 1034 | return -EINVAL; |
| 1035 | |
| 1036 | if (sclp_has_sigpif()) |
| 1037 | return __inject_extcall_sigpif(vcpu, src_id); |
| 1038 | |
| 1039 | if (!test_and_set_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs)) |
| 1040 | return -EBUSY; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1041 | *extcall = irq->u.extcall; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1042 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1046 | 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] | 1047 | { |
| 1048 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1049 | struct kvm_s390_prefix_info *prefix = &li->irq.prefix; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1050 | |
| 1051 | VCPU_EVENT(vcpu, 3, "inject: set prefix to %x (from user)", |
Jens Freimann | 556cc0d | 2014-12-18 15:52:21 +0100 | [diff] [blame] | 1052 | irq->u.prefix.address); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1053 | 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] | 1054 | irq->u.prefix.address, 0, 2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1055 | |
David Hildenbrand | a3a9c59 | 2014-10-14 09:44:55 +0200 | [diff] [blame] | 1056 | if (!is_vcpu_stopped(vcpu)) |
| 1057 | return -EBUSY; |
| 1058 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1059 | *prefix = irq->u.prefix; |
| 1060 | set_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1061 | return 0; |
| 1062 | } |
| 1063 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1064 | #define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1065 | 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] | 1066 | { |
| 1067 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1068 | struct kvm_s390_stop_info *stop = &li->irq.stop; |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1069 | int rc = 0; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1070 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1071 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0, 2); |
| 1072 | |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1073 | if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS) |
| 1074 | return -EINVAL; |
| 1075 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1076 | if (is_vcpu_stopped(vcpu)) { |
| 1077 | if (irq->u.stop.flags & KVM_S390_STOP_FLAG_STORE_STATUS) |
| 1078 | rc = kvm_s390_store_status_unloaded(vcpu, |
| 1079 | KVM_S390_STORE_STATUS_NOADDR); |
| 1080 | return rc; |
| 1081 | } |
| 1082 | |
| 1083 | if (test_and_set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs)) |
| 1084 | return -EBUSY; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1085 | stop->flags = irq->u.stop.flags; |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1086 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static int __inject_sigp_restart(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1091 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1092 | { |
| 1093 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1094 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1095 | VCPU_EVENT(vcpu, 3, "inject: restart type %llx", irq->type); |
| 1096 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0, 2); |
| 1097 | |
| 1098 | set_bit(IRQ_PEND_RESTART, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | static int __inject_sigp_emergency(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1103 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1104 | { |
| 1105 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1106 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1107 | VCPU_EVENT(vcpu, 3, "inject: emergency %u\n", |
| 1108 | irq->u.emerg.code); |
| 1109 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, |
Jens Freimann | 49538d1 | 2014-12-18 15:48:14 +0100 | [diff] [blame] | 1110 | irq->u.emerg.code, 0, 2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1111 | |
Jens Freimann | 49538d1 | 2014-12-18 15:48:14 +0100 | [diff] [blame] | 1112 | set_bit(irq->u.emerg.code, li->sigp_emerg_pending); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1113 | set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1114 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1118 | 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] | 1119 | { |
| 1120 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1121 | struct kvm_s390_mchk_info *mchk = &li->irq.mchk; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1122 | |
| 1123 | VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx", |
Jens Freimann | 556cc0d | 2014-12-18 15:52:21 +0100 | [diff] [blame] | 1124 | irq->u.mchk.mcic); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1125 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0, |
Jens Freimann | 556cc0d | 2014-12-18 15:52:21 +0100 | [diff] [blame] | 1126 | irq->u.mchk.mcic, 2); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1127 | |
| 1128 | /* |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1129 | * Because repressible machine checks can be indicated along with |
| 1130 | * exigent machine checks (PoP, Chapter 11, Interruption action) |
| 1131 | * we need to combine cr14, mcic and external damage code. |
| 1132 | * Failing storage address and the logout area should not be or'ed |
| 1133 | * together, we just indicate the last occurrence of the corresponding |
| 1134 | * machine check |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1135 | */ |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1136 | mchk->cr14 |= irq->u.mchk.cr14; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1137 | mchk->mcic |= irq->u.mchk.mcic; |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1138 | mchk->ext_damage_code |= irq->u.mchk.ext_damage_code; |
| 1139 | mchk->failing_storage_address = irq->u.mchk.failing_storage_address; |
| 1140 | memcpy(&mchk->fixed_logout, &irq->u.mchk.fixed_logout, |
| 1141 | sizeof(mchk->fixed_logout)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1142 | if (mchk->mcic & MCHK_EX_MASK) |
| 1143 | set_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); |
| 1144 | else if (mchk->mcic & MCHK_REP_MASK) |
| 1145 | set_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1146 | return 0; |
| 1147 | } |
| 1148 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1149 | static int __inject_ckc(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1150 | { |
| 1151 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1152 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1153 | VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CLOCK_COMP); |
| 1154 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, |
| 1155 | 0, 0, 2); |
| 1156 | |
| 1157 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1158 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1162 | static int __inject_cpu_timer(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1163 | { |
| 1164 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1165 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1166 | VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CPU_TIMER); |
| 1167 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, |
| 1168 | 0, 0, 2); |
| 1169 | |
| 1170 | set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1171 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 1172 | return 0; |
| 1173 | } |
| 1174 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1175 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1176 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
| 1177 | u64 cr6, u64 schid) |
| 1178 | { |
| 1179 | struct kvm_s390_float_interrupt *fi; |
| 1180 | struct kvm_s390_interrupt_info *inti, *iter; |
| 1181 | |
| 1182 | if ((!schid && !cr6) || (schid && cr6)) |
| 1183 | return NULL; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1184 | fi = &kvm->arch.float_int; |
| 1185 | spin_lock(&fi->lock); |
| 1186 | inti = NULL; |
| 1187 | list_for_each_entry(iter, &fi->list, list) { |
| 1188 | if (!is_ioint(iter->type)) |
| 1189 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1190 | if (cr6 && |
| 1191 | ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0)) |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1192 | continue; |
| 1193 | if (schid) { |
| 1194 | if (((schid & 0x00000000ffff0000) >> 16) != |
| 1195 | iter->io.subchannel_id) |
| 1196 | continue; |
| 1197 | if ((schid & 0x000000000000ffff) != |
| 1198 | iter->io.subchannel_nr) |
| 1199 | continue; |
| 1200 | } |
| 1201 | inti = iter; |
| 1202 | break; |
| 1203 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1204 | if (inti) { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1205 | list_del_init(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1206 | fi->irq_count--; |
| 1207 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1208 | if (list_empty(&fi->list)) |
| 1209 | atomic_set(&fi->active, 0); |
| 1210 | spin_unlock(&fi->lock); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1211 | return inti; |
| 1212 | } |
| 1213 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1214 | 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] | 1215 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 1216 | struct kvm_s390_local_interrupt *li; |
| 1217 | struct kvm_s390_float_interrupt *fi; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1218 | struct kvm_s390_interrupt_info *iter; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1219 | struct kvm_vcpu *dst_vcpu = NULL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1220 | int sigcpu; |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1221 | int rc = 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1222 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1223 | fi = &kvm->arch.float_int; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 1224 | spin_lock(&fi->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1225 | if (fi->irq_count >= KVM_S390_MAX_FLOAT_IRQS) { |
| 1226 | rc = -EINVAL; |
| 1227 | goto unlock_fi; |
| 1228 | } |
| 1229 | fi->irq_count++; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1230 | if (!is_ioint(inti->type)) { |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1231 | list_add_tail(&inti->list, &fi->list); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1232 | } else { |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1233 | u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word); |
| 1234 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1235 | /* Keep I/O interrupts sorted in isc order. */ |
| 1236 | list_for_each_entry(iter, &fi->list, list) { |
| 1237 | if (!is_ioint(iter->type)) |
| 1238 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1239 | if (int_word_to_isc_bits(iter->io.io_int_word) |
| 1240 | <= isc_bits) |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1241 | continue; |
| 1242 | break; |
| 1243 | } |
| 1244 | list_add_tail(&inti->list, &iter->list); |
| 1245 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1246 | atomic_set(&fi->active, 1); |
| 1247 | sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); |
| 1248 | if (sigcpu == KVM_MAX_VCPUS) { |
| 1249 | do { |
| 1250 | sigcpu = fi->next_rr_cpu++; |
| 1251 | if (sigcpu == KVM_MAX_VCPUS) |
| 1252 | sigcpu = fi->next_rr_cpu = 0; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1253 | } while (kvm_get_vcpu(kvm, sigcpu) == NULL); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1254 | } |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1255 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); |
| 1256 | li = &dst_vcpu->arch.local_int; |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1257 | spin_lock(&li->lock); |
Christian Borntraeger | da00fcb | 2014-11-21 09:38:12 +0100 | [diff] [blame] | 1258 | switch (inti->type) { |
| 1259 | case KVM_S390_MCHK: |
| 1260 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
| 1261 | break; |
| 1262 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1263 | atomic_set_mask(CPUSTAT_IO_INT, li->cpuflags); |
| 1264 | break; |
| 1265 | default: |
| 1266 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1267 | break; |
| 1268 | } |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1269 | spin_unlock(&li->lock); |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 1270 | kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu)); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1271 | unlock_fi: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 1272 | spin_unlock(&fi->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1273 | return rc; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | int kvm_s390_inject_vm(struct kvm *kvm, |
| 1277 | struct kvm_s390_interrupt *s390int) |
| 1278 | { |
| 1279 | struct kvm_s390_interrupt_info *inti; |
David Hildenbrand | 428d53b | 2015-01-16 12:58:09 +0100 | [diff] [blame^] | 1280 | int rc; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1281 | |
| 1282 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1283 | if (!inti) |
| 1284 | return -ENOMEM; |
| 1285 | |
| 1286 | inti->type = s390int->type; |
| 1287 | switch (inti->type) { |
| 1288 | case KVM_S390_INT_VIRTIO: |
| 1289 | VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx", |
| 1290 | s390int->parm, s390int->parm64); |
| 1291 | inti->ext.ext_params = s390int->parm; |
| 1292 | inti->ext.ext_params2 = s390int->parm64; |
| 1293 | break; |
| 1294 | case KVM_S390_INT_SERVICE: |
| 1295 | VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm); |
| 1296 | inti->ext.ext_params = s390int->parm; |
| 1297 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1298 | case KVM_S390_INT_PFAULT_DONE: |
| 1299 | inti->type = s390int->type; |
| 1300 | inti->ext.ext_params2 = s390int->parm64; |
| 1301 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1302 | case KVM_S390_MCHK: |
| 1303 | VM_EVENT(kvm, 5, "inject: machine check parm64:%llx", |
| 1304 | s390int->parm64); |
| 1305 | inti->mchk.cr14 = s390int->parm; /* upper bits are not used */ |
| 1306 | inti->mchk.mcic = s390int->parm64; |
| 1307 | break; |
| 1308 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1309 | if (inti->type & IOINT_AI_MASK) |
| 1310 | VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)"); |
| 1311 | else |
| 1312 | VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x", |
| 1313 | s390int->type & IOINT_CSSID_MASK, |
| 1314 | s390int->type & IOINT_SSID_MASK, |
| 1315 | s390int->type & IOINT_SCHID_MASK); |
| 1316 | inti->io.subchannel_id = s390int->parm >> 16; |
| 1317 | inti->io.subchannel_nr = s390int->parm & 0x0000ffffu; |
| 1318 | inti->io.io_int_parm = s390int->parm64 >> 32; |
| 1319 | inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull; |
| 1320 | break; |
| 1321 | default: |
| 1322 | kfree(inti); |
| 1323 | return -EINVAL; |
| 1324 | } |
| 1325 | trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64, |
| 1326 | 2); |
| 1327 | |
David Hildenbrand | 428d53b | 2015-01-16 12:58:09 +0100 | [diff] [blame^] | 1328 | rc = __inject_vm(kvm, inti); |
| 1329 | if (rc) |
| 1330 | kfree(inti); |
| 1331 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
Cornelia Huck | 2f32d4e | 2014-01-08 18:07:54 +0100 | [diff] [blame] | 1334 | void kvm_s390_reinject_io_int(struct kvm *kvm, |
| 1335 | struct kvm_s390_interrupt_info *inti) |
| 1336 | { |
| 1337 | __inject_vm(kvm, inti); |
| 1338 | } |
| 1339 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1340 | int s390int_to_s390irq(struct kvm_s390_interrupt *s390int, |
| 1341 | struct kvm_s390_irq *irq) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1342 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1343 | irq->type = s390int->type; |
| 1344 | switch (irq->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1345 | case KVM_S390_PROGRAM_INT: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1346 | if (s390int->parm & 0xffff0000) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1347 | return -EINVAL; |
| 1348 | irq->u.pgm.code = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1349 | break; |
Christian Borntraeger | b7e6e4d | 2009-01-22 10:29:08 +0100 | [diff] [blame] | 1350 | case KVM_S390_SIGP_SET_PREFIX: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1351 | irq->u.prefix.address = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1352 | break; |
David Hildenbrand | 2822545 | 2014-10-15 16:48:16 +0200 | [diff] [blame] | 1353 | case KVM_S390_SIGP_STOP: |
| 1354 | irq->u.stop.flags = s390int->parm; |
| 1355 | break; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1356 | case KVM_S390_INT_EXTERNAL_CALL: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1357 | if (irq->u.extcall.code & 0xffff0000) |
| 1358 | return -EINVAL; |
| 1359 | irq->u.extcall.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1360 | break; |
| 1361 | case KVM_S390_INT_EMERGENCY: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1362 | if (irq->u.emerg.code & 0xffff0000) |
| 1363 | return -EINVAL; |
| 1364 | irq->u.emerg.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1365 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1366 | case KVM_S390_MCHK: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1367 | irq->u.mchk.mcic = s390int->parm64; |
| 1368 | break; |
| 1369 | } |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 1373 | int kvm_s390_is_stop_irq_pending(struct kvm_vcpu *vcpu) |
| 1374 | { |
| 1375 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1376 | |
| 1377 | return test_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); |
| 1378 | } |
| 1379 | |
| 1380 | void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu) |
| 1381 | { |
| 1382 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1383 | |
| 1384 | spin_lock(&li->lock); |
| 1385 | li->irq.stop.flags = 0; |
| 1386 | clear_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); |
| 1387 | spin_unlock(&li->lock); |
| 1388 | } |
| 1389 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1390 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
| 1391 | { |
| 1392 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1393 | int rc; |
| 1394 | |
| 1395 | spin_lock(&li->lock); |
| 1396 | switch (irq->type) { |
| 1397 | case KVM_S390_PROGRAM_INT: |
| 1398 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)", |
| 1399 | irq->u.pgm.code); |
| 1400 | rc = __inject_prog(vcpu, irq); |
| 1401 | break; |
| 1402 | case KVM_S390_SIGP_SET_PREFIX: |
| 1403 | rc = __inject_set_prefix(vcpu, irq); |
| 1404 | break; |
| 1405 | case KVM_S390_SIGP_STOP: |
| 1406 | rc = __inject_sigp_stop(vcpu, irq); |
| 1407 | break; |
| 1408 | case KVM_S390_RESTART: |
| 1409 | rc = __inject_sigp_restart(vcpu, irq); |
| 1410 | break; |
| 1411 | case KVM_S390_INT_CLOCK_COMP: |
| 1412 | rc = __inject_ckc(vcpu); |
| 1413 | break; |
| 1414 | case KVM_S390_INT_CPU_TIMER: |
| 1415 | rc = __inject_cpu_timer(vcpu); |
| 1416 | break; |
| 1417 | case KVM_S390_INT_EXTERNAL_CALL: |
| 1418 | rc = __inject_extcall(vcpu, irq); |
| 1419 | break; |
| 1420 | case KVM_S390_INT_EMERGENCY: |
| 1421 | rc = __inject_sigp_emergency(vcpu, irq); |
| 1422 | break; |
| 1423 | case KVM_S390_MCHK: |
| 1424 | rc = __inject_mchk(vcpu, irq); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1425 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1426 | case KVM_S390_INT_PFAULT_INIT: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1427 | rc = __inject_pfault_init(vcpu, irq); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1428 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1429 | case KVM_S390_INT_VIRTIO: |
| 1430 | case KVM_S390_INT_SERVICE: |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1431 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1432 | default: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1433 | rc = -EINVAL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1434 | } |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1435 | spin_unlock(&li->lock); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1436 | if (!rc) |
| 1437 | kvm_s390_vcpu_wakeup(vcpu); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1438 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1439 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1440 | |
Christian Borntraeger | 67335e6 | 2014-03-25 17:09:08 +0100 | [diff] [blame] | 1441 | void kvm_s390_clear_float_irqs(struct kvm *kvm) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1442 | { |
| 1443 | struct kvm_s390_float_interrupt *fi; |
| 1444 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
| 1445 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1446 | fi = &kvm->arch.float_int; |
| 1447 | spin_lock(&fi->lock); |
| 1448 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 1449 | list_del(&inti->list); |
| 1450 | kfree(inti); |
| 1451 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1452 | fi->irq_count = 0; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1453 | atomic_set(&fi->active, 0); |
| 1454 | spin_unlock(&fi->lock); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | static inline int copy_irq_to_user(struct kvm_s390_interrupt_info *inti, |
| 1458 | u8 *addr) |
| 1459 | { |
| 1460 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1461 | struct kvm_s390_irq irq = {0}; |
| 1462 | |
| 1463 | irq.type = inti->type; |
| 1464 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1465 | case KVM_S390_INT_PFAULT_INIT: |
| 1466 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1467 | case KVM_S390_INT_VIRTIO: |
| 1468 | case KVM_S390_INT_SERVICE: |
| 1469 | irq.u.ext = inti->ext; |
| 1470 | break; |
| 1471 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1472 | irq.u.io = inti->io; |
| 1473 | break; |
| 1474 | case KVM_S390_MCHK: |
| 1475 | irq.u.mchk = inti->mchk; |
| 1476 | break; |
| 1477 | default: |
| 1478 | return -EINVAL; |
| 1479 | } |
| 1480 | |
| 1481 | if (copy_to_user(uptr, &irq, sizeof(irq))) |
| 1482 | return -EFAULT; |
| 1483 | |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
| 1487 | static int get_all_floating_irqs(struct kvm *kvm, __u8 *buf, __u64 len) |
| 1488 | { |
| 1489 | struct kvm_s390_interrupt_info *inti; |
| 1490 | struct kvm_s390_float_interrupt *fi; |
| 1491 | int ret = 0; |
| 1492 | int n = 0; |
| 1493 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1494 | fi = &kvm->arch.float_int; |
| 1495 | spin_lock(&fi->lock); |
| 1496 | |
| 1497 | list_for_each_entry(inti, &fi->list, list) { |
| 1498 | if (len < sizeof(struct kvm_s390_irq)) { |
| 1499 | /* signal userspace to try again */ |
| 1500 | ret = -ENOMEM; |
| 1501 | break; |
| 1502 | } |
| 1503 | ret = copy_irq_to_user(inti, buf); |
| 1504 | if (ret) |
| 1505 | break; |
| 1506 | buf += sizeof(struct kvm_s390_irq); |
| 1507 | len -= sizeof(struct kvm_s390_irq); |
| 1508 | n++; |
| 1509 | } |
| 1510 | |
| 1511 | spin_unlock(&fi->lock); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1512 | |
| 1513 | return ret < 0 ? ret : n; |
| 1514 | } |
| 1515 | |
| 1516 | static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1517 | { |
| 1518 | int r; |
| 1519 | |
| 1520 | switch (attr->group) { |
| 1521 | case KVM_DEV_FLIC_GET_ALL_IRQS: |
| 1522 | r = get_all_floating_irqs(dev->kvm, (u8 *) attr->addr, |
| 1523 | attr->attr); |
| 1524 | break; |
| 1525 | default: |
| 1526 | r = -EINVAL; |
| 1527 | } |
| 1528 | |
| 1529 | return r; |
| 1530 | } |
| 1531 | |
| 1532 | static inline int copy_irq_from_user(struct kvm_s390_interrupt_info *inti, |
| 1533 | u64 addr) |
| 1534 | { |
| 1535 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1536 | void *target = NULL; |
| 1537 | void __user *source; |
| 1538 | u64 size; |
| 1539 | |
| 1540 | if (get_user(inti->type, (u64 __user *)addr)) |
| 1541 | return -EFAULT; |
| 1542 | |
| 1543 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1544 | case KVM_S390_INT_PFAULT_INIT: |
| 1545 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1546 | case KVM_S390_INT_VIRTIO: |
| 1547 | case KVM_S390_INT_SERVICE: |
| 1548 | target = (void *) &inti->ext; |
| 1549 | source = &uptr->u.ext; |
| 1550 | size = sizeof(inti->ext); |
| 1551 | break; |
| 1552 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1553 | target = (void *) &inti->io; |
| 1554 | source = &uptr->u.io; |
| 1555 | size = sizeof(inti->io); |
| 1556 | break; |
| 1557 | case KVM_S390_MCHK: |
| 1558 | target = (void *) &inti->mchk; |
| 1559 | source = &uptr->u.mchk; |
| 1560 | size = sizeof(inti->mchk); |
| 1561 | break; |
| 1562 | default: |
| 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
| 1566 | if (copy_from_user(target, source, size)) |
| 1567 | return -EFAULT; |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
| 1572 | static int enqueue_floating_irq(struct kvm_device *dev, |
| 1573 | struct kvm_device_attr *attr) |
| 1574 | { |
| 1575 | struct kvm_s390_interrupt_info *inti = NULL; |
| 1576 | int r = 0; |
| 1577 | int len = attr->attr; |
| 1578 | |
| 1579 | if (len % sizeof(struct kvm_s390_irq) != 0) |
| 1580 | return -EINVAL; |
| 1581 | else if (len > KVM_S390_FLIC_MAX_BUFFER) |
| 1582 | return -EINVAL; |
| 1583 | |
| 1584 | while (len >= sizeof(struct kvm_s390_irq)) { |
| 1585 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1586 | if (!inti) |
| 1587 | return -ENOMEM; |
| 1588 | |
| 1589 | r = copy_irq_from_user(inti, attr->addr); |
| 1590 | if (r) { |
| 1591 | kfree(inti); |
| 1592 | return r; |
| 1593 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1594 | r = __inject_vm(dev->kvm, inti); |
| 1595 | if (r) { |
| 1596 | kfree(inti); |
| 1597 | return r; |
| 1598 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1599 | len -= sizeof(struct kvm_s390_irq); |
| 1600 | attr->addr += sizeof(struct kvm_s390_irq); |
| 1601 | } |
| 1602 | |
| 1603 | return r; |
| 1604 | } |
| 1605 | |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1606 | static struct s390_io_adapter *get_io_adapter(struct kvm *kvm, unsigned int id) |
| 1607 | { |
| 1608 | if (id >= MAX_S390_IO_ADAPTERS) |
| 1609 | return NULL; |
| 1610 | return kvm->arch.adapters[id]; |
| 1611 | } |
| 1612 | |
| 1613 | static int register_io_adapter(struct kvm_device *dev, |
| 1614 | struct kvm_device_attr *attr) |
| 1615 | { |
| 1616 | struct s390_io_adapter *adapter; |
| 1617 | struct kvm_s390_io_adapter adapter_info; |
| 1618 | |
| 1619 | if (copy_from_user(&adapter_info, |
| 1620 | (void __user *)attr->addr, sizeof(adapter_info))) |
| 1621 | return -EFAULT; |
| 1622 | |
| 1623 | if ((adapter_info.id >= MAX_S390_IO_ADAPTERS) || |
| 1624 | (dev->kvm->arch.adapters[adapter_info.id] != NULL)) |
| 1625 | return -EINVAL; |
| 1626 | |
| 1627 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 1628 | if (!adapter) |
| 1629 | return -ENOMEM; |
| 1630 | |
| 1631 | INIT_LIST_HEAD(&adapter->maps); |
| 1632 | init_rwsem(&adapter->maps_lock); |
| 1633 | atomic_set(&adapter->nr_maps, 0); |
| 1634 | adapter->id = adapter_info.id; |
| 1635 | adapter->isc = adapter_info.isc; |
| 1636 | adapter->maskable = adapter_info.maskable; |
| 1637 | adapter->masked = false; |
| 1638 | adapter->swap = adapter_info.swap; |
| 1639 | dev->kvm->arch.adapters[adapter->id] = adapter; |
| 1640 | |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
| 1644 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked) |
| 1645 | { |
| 1646 | int ret; |
| 1647 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1648 | |
| 1649 | if (!adapter || !adapter->maskable) |
| 1650 | return -EINVAL; |
| 1651 | ret = adapter->masked; |
| 1652 | adapter->masked = masked; |
| 1653 | return ret; |
| 1654 | } |
| 1655 | |
| 1656 | static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1657 | { |
| 1658 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1659 | struct s390_map_info *map; |
| 1660 | int ret; |
| 1661 | |
| 1662 | if (!adapter || !addr) |
| 1663 | return -EINVAL; |
| 1664 | |
| 1665 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 1666 | if (!map) { |
| 1667 | ret = -ENOMEM; |
| 1668 | goto out; |
| 1669 | } |
| 1670 | INIT_LIST_HEAD(&map->list); |
| 1671 | map->guest_addr = addr; |
Martin Schwidefsky | 6e0a043 | 2014-04-29 09:34:41 +0200 | [diff] [blame] | 1672 | map->addr = gmap_translate(kvm->arch.gmap, addr); |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1673 | if (map->addr == -EFAULT) { |
| 1674 | ret = -EFAULT; |
| 1675 | goto out; |
| 1676 | } |
| 1677 | ret = get_user_pages_fast(map->addr, 1, 1, &map->page); |
| 1678 | if (ret < 0) |
| 1679 | goto out; |
| 1680 | BUG_ON(ret != 1); |
| 1681 | down_write(&adapter->maps_lock); |
| 1682 | if (atomic_inc_return(&adapter->nr_maps) < MAX_S390_ADAPTER_MAPS) { |
| 1683 | list_add_tail(&map->list, &adapter->maps); |
| 1684 | ret = 0; |
| 1685 | } else { |
| 1686 | put_page(map->page); |
| 1687 | ret = -EINVAL; |
| 1688 | } |
| 1689 | up_write(&adapter->maps_lock); |
| 1690 | out: |
| 1691 | if (ret) |
| 1692 | kfree(map); |
| 1693 | return ret; |
| 1694 | } |
| 1695 | |
| 1696 | static int kvm_s390_adapter_unmap(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1697 | { |
| 1698 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1699 | struct s390_map_info *map, *tmp; |
| 1700 | int found = 0; |
| 1701 | |
| 1702 | if (!adapter || !addr) |
| 1703 | return -EINVAL; |
| 1704 | |
| 1705 | down_write(&adapter->maps_lock); |
| 1706 | list_for_each_entry_safe(map, tmp, &adapter->maps, list) { |
| 1707 | if (map->guest_addr == addr) { |
| 1708 | found = 1; |
| 1709 | atomic_dec(&adapter->nr_maps); |
| 1710 | list_del(&map->list); |
| 1711 | put_page(map->page); |
| 1712 | kfree(map); |
| 1713 | break; |
| 1714 | } |
| 1715 | } |
| 1716 | up_write(&adapter->maps_lock); |
| 1717 | |
| 1718 | return found ? 0 : -EINVAL; |
| 1719 | } |
| 1720 | |
| 1721 | void kvm_s390_destroy_adapters(struct kvm *kvm) |
| 1722 | { |
| 1723 | int i; |
| 1724 | struct s390_map_info *map, *tmp; |
| 1725 | |
| 1726 | for (i = 0; i < MAX_S390_IO_ADAPTERS; i++) { |
| 1727 | if (!kvm->arch.adapters[i]) |
| 1728 | continue; |
| 1729 | list_for_each_entry_safe(map, tmp, |
| 1730 | &kvm->arch.adapters[i]->maps, list) { |
| 1731 | list_del(&map->list); |
| 1732 | put_page(map->page); |
| 1733 | kfree(map); |
| 1734 | } |
| 1735 | kfree(kvm->arch.adapters[i]); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | static int modify_io_adapter(struct kvm_device *dev, |
| 1740 | struct kvm_device_attr *attr) |
| 1741 | { |
| 1742 | struct kvm_s390_io_adapter_req req; |
| 1743 | struct s390_io_adapter *adapter; |
| 1744 | int ret; |
| 1745 | |
| 1746 | if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) |
| 1747 | return -EFAULT; |
| 1748 | |
| 1749 | adapter = get_io_adapter(dev->kvm, req.id); |
| 1750 | if (!adapter) |
| 1751 | return -EINVAL; |
| 1752 | switch (req.type) { |
| 1753 | case KVM_S390_IO_ADAPTER_MASK: |
| 1754 | ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask); |
| 1755 | if (ret > 0) |
| 1756 | ret = 0; |
| 1757 | break; |
| 1758 | case KVM_S390_IO_ADAPTER_MAP: |
| 1759 | ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); |
| 1760 | break; |
| 1761 | case KVM_S390_IO_ADAPTER_UNMAP: |
| 1762 | ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); |
| 1763 | break; |
| 1764 | default: |
| 1765 | ret = -EINVAL; |
| 1766 | } |
| 1767 | |
| 1768 | return ret; |
| 1769 | } |
| 1770 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1771 | static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1772 | { |
| 1773 | int r = 0; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1774 | unsigned int i; |
| 1775 | struct kvm_vcpu *vcpu; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1776 | |
| 1777 | switch (attr->group) { |
| 1778 | case KVM_DEV_FLIC_ENQUEUE: |
| 1779 | r = enqueue_floating_irq(dev, attr); |
| 1780 | break; |
| 1781 | case KVM_DEV_FLIC_CLEAR_IRQS: |
Christian Borntraeger | 67335e6 | 2014-03-25 17:09:08 +0100 | [diff] [blame] | 1782 | kvm_s390_clear_float_irqs(dev->kvm); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1783 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1784 | case KVM_DEV_FLIC_APF_ENABLE: |
| 1785 | dev->kvm->arch.gmap->pfault_enabled = 1; |
| 1786 | break; |
| 1787 | case KVM_DEV_FLIC_APF_DISABLE_WAIT: |
| 1788 | dev->kvm->arch.gmap->pfault_enabled = 0; |
| 1789 | /* |
| 1790 | * Make sure no async faults are in transition when |
| 1791 | * clearing the queues. So we don't need to worry |
| 1792 | * about late coming workers. |
| 1793 | */ |
| 1794 | synchronize_srcu(&dev->kvm->srcu); |
| 1795 | kvm_for_each_vcpu(i, vcpu, dev->kvm) |
| 1796 | kvm_clear_async_pf_completion_queue(vcpu); |
| 1797 | break; |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1798 | case KVM_DEV_FLIC_ADAPTER_REGISTER: |
| 1799 | r = register_io_adapter(dev, attr); |
| 1800 | break; |
| 1801 | case KVM_DEV_FLIC_ADAPTER_MODIFY: |
| 1802 | r = modify_io_adapter(dev, attr); |
| 1803 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1804 | default: |
| 1805 | r = -EINVAL; |
| 1806 | } |
| 1807 | |
| 1808 | return r; |
| 1809 | } |
| 1810 | |
| 1811 | static int flic_create(struct kvm_device *dev, u32 type) |
| 1812 | { |
| 1813 | if (!dev) |
| 1814 | return -EINVAL; |
| 1815 | if (dev->kvm->arch.flic) |
| 1816 | return -EINVAL; |
| 1817 | dev->kvm->arch.flic = dev; |
| 1818 | return 0; |
| 1819 | } |
| 1820 | |
| 1821 | static void flic_destroy(struct kvm_device *dev) |
| 1822 | { |
| 1823 | dev->kvm->arch.flic = NULL; |
| 1824 | kfree(dev); |
| 1825 | } |
| 1826 | |
| 1827 | /* s390 floating irq controller (flic) */ |
| 1828 | struct kvm_device_ops kvm_flic_ops = { |
| 1829 | .name = "kvm-flic", |
| 1830 | .get_attr = flic_get_attr, |
| 1831 | .set_attr = flic_set_attr, |
| 1832 | .create = flic_create, |
| 1833 | .destroy = flic_destroy, |
| 1834 | }; |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1835 | |
| 1836 | static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) |
| 1837 | { |
| 1838 | unsigned long bit; |
| 1839 | |
| 1840 | bit = bit_nr + (addr % PAGE_SIZE) * 8; |
| 1841 | |
| 1842 | return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; |
| 1843 | } |
| 1844 | |
| 1845 | static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, |
| 1846 | u64 addr) |
| 1847 | { |
| 1848 | struct s390_map_info *map; |
| 1849 | |
| 1850 | if (!adapter) |
| 1851 | return NULL; |
| 1852 | |
| 1853 | list_for_each_entry(map, &adapter->maps, list) { |
| 1854 | if (map->guest_addr == addr) |
| 1855 | return map; |
| 1856 | } |
| 1857 | return NULL; |
| 1858 | } |
| 1859 | |
| 1860 | static int adapter_indicators_set(struct kvm *kvm, |
| 1861 | struct s390_io_adapter *adapter, |
| 1862 | struct kvm_s390_adapter_int *adapter_int) |
| 1863 | { |
| 1864 | unsigned long bit; |
| 1865 | int summary_set, idx; |
| 1866 | struct s390_map_info *info; |
| 1867 | void *map; |
| 1868 | |
| 1869 | info = get_map_info(adapter, adapter_int->ind_addr); |
| 1870 | if (!info) |
| 1871 | return -1; |
| 1872 | map = page_address(info->page); |
| 1873 | bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); |
| 1874 | set_bit(bit, map); |
| 1875 | idx = srcu_read_lock(&kvm->srcu); |
| 1876 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1877 | set_page_dirty_lock(info->page); |
| 1878 | info = get_map_info(adapter, adapter_int->summary_addr); |
| 1879 | if (!info) { |
| 1880 | srcu_read_unlock(&kvm->srcu, idx); |
| 1881 | return -1; |
| 1882 | } |
| 1883 | map = page_address(info->page); |
| 1884 | bit = get_ind_bit(info->addr, adapter_int->summary_offset, |
| 1885 | adapter->swap); |
| 1886 | summary_set = test_and_set_bit(bit, map); |
| 1887 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1888 | set_page_dirty_lock(info->page); |
| 1889 | srcu_read_unlock(&kvm->srcu, idx); |
| 1890 | return summary_set ? 0 : 1; |
| 1891 | } |
| 1892 | |
| 1893 | /* |
| 1894 | * < 0 - not injected due to error |
| 1895 | * = 0 - coalesced, summary indicator already active |
| 1896 | * > 0 - injected interrupt |
| 1897 | */ |
| 1898 | static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, |
| 1899 | struct kvm *kvm, int irq_source_id, int level, |
| 1900 | bool line_status) |
| 1901 | { |
| 1902 | int ret; |
| 1903 | struct s390_io_adapter *adapter; |
| 1904 | |
| 1905 | /* We're only interested in the 0->1 transition. */ |
| 1906 | if (!level) |
| 1907 | return 0; |
| 1908 | adapter = get_io_adapter(kvm, e->adapter.adapter_id); |
| 1909 | if (!adapter) |
| 1910 | return -1; |
| 1911 | down_read(&adapter->maps_lock); |
| 1912 | ret = adapter_indicators_set(kvm, adapter, &e->adapter); |
| 1913 | up_read(&adapter->maps_lock); |
| 1914 | if ((ret > 0) && !adapter->masked) { |
| 1915 | struct kvm_s390_interrupt s390int = { |
| 1916 | .type = KVM_S390_INT_IO(1, 0, 0, 0), |
| 1917 | .parm = 0, |
| 1918 | .parm64 = (adapter->isc << 27) | 0x80000000, |
| 1919 | }; |
| 1920 | ret = kvm_s390_inject_vm(kvm, &s390int); |
| 1921 | if (ret == 0) |
| 1922 | ret = 1; |
| 1923 | } |
| 1924 | return ret; |
| 1925 | } |
| 1926 | |
Paul Mackerras | 8ba918d | 2014-06-30 20:51:10 +1000 | [diff] [blame] | 1927 | int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1928 | const struct kvm_irq_routing_entry *ue) |
| 1929 | { |
| 1930 | int ret; |
| 1931 | |
| 1932 | switch (ue->type) { |
| 1933 | case KVM_IRQ_ROUTING_S390_ADAPTER: |
| 1934 | e->set = set_adapter_int; |
| 1935 | e->adapter.summary_addr = ue->u.adapter.summary_addr; |
| 1936 | e->adapter.ind_addr = ue->u.adapter.ind_addr; |
| 1937 | e->adapter.summary_offset = ue->u.adapter.summary_offset; |
| 1938 | e->adapter.ind_offset = ue->u.adapter.ind_offset; |
| 1939 | e->adapter.adapter_id = ue->u.adapter.adapter_id; |
| 1940 | ret = 0; |
| 1941 | break; |
| 1942 | default: |
| 1943 | ret = -EINVAL; |
| 1944 | } |
| 1945 | |
| 1946 | return ret; |
| 1947 | } |
| 1948 | |
| 1949 | int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, |
| 1950 | int irq_source_id, int level, bool line_status) |
| 1951 | { |
| 1952 | return -EINVAL; |
| 1953 | } |