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