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 | |
| 162 | return active_mask; |
| 163 | } |
| 164 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 165 | static void __set_cpu_idle(struct kvm_vcpu *vcpu) |
| 166 | { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 167 | atomic_set_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
| 168 | set_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 169 | } |
| 170 | |
| 171 | static void __unset_cpu_idle(struct kvm_vcpu *vcpu) |
| 172 | { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 173 | atomic_clear_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
| 174 | clear_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 175 | } |
| 176 | |
| 177 | static void __reset_intercept_indicators(struct kvm_vcpu *vcpu) |
| 178 | { |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 179 | atomic_clear_mask(CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT, |
| 180 | &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 181 | vcpu->arch.sie_block->lctl = 0x0000; |
David Hildenbrand | 27291e2 | 2014-01-23 12:26:52 +0100 | [diff] [blame] | 182 | vcpu->arch.sie_block->ictl &= ~(ICTL_LPSW | ICTL_STCTL | ICTL_PINT); |
| 183 | |
| 184 | if (guestdbg_enabled(vcpu)) { |
| 185 | vcpu->arch.sie_block->lctl |= (LCTL_CR0 | LCTL_CR9 | |
| 186 | LCTL_CR10 | LCTL_CR11); |
| 187 | vcpu->arch.sie_block->ictl |= (ICTL_STCTL | ICTL_PINT); |
| 188 | } |
David Hildenbrand | db37386 | 2014-07-28 14:05:41 +0200 | [diff] [blame] | 189 | |
| 190 | if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) |
| 191 | atomic_set_mask(CPUSTAT_STOP_INT, &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) |
| 195 | { |
| 196 | atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags); |
| 197 | } |
| 198 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 199 | static void set_intercept_indicators_ext(struct kvm_vcpu *vcpu) |
| 200 | { |
| 201 | if (!(pending_local_irqs(vcpu) & IRQ_PEND_EXT_MASK)) |
| 202 | return; |
| 203 | if (psw_extint_disabled(vcpu)) |
| 204 | __set_cpuflag(vcpu, CPUSTAT_EXT_INT); |
| 205 | else |
| 206 | vcpu->arch.sie_block->lctl |= LCTL_CR0; |
| 207 | } |
| 208 | |
| 209 | static void set_intercept_indicators_mchk(struct kvm_vcpu *vcpu) |
| 210 | { |
| 211 | if (!(pending_local_irqs(vcpu) & IRQ_PEND_MCHK_MASK)) |
| 212 | return; |
| 213 | if (psw_mchk_disabled(vcpu)) |
| 214 | vcpu->arch.sie_block->ictl |= ICTL_LPSW; |
| 215 | else |
| 216 | vcpu->arch.sie_block->lctl |= LCTL_CR14; |
| 217 | } |
| 218 | |
| 219 | /* Set interception request for non-deliverable local interrupts */ |
| 220 | static void set_intercept_indicators_local(struct kvm_vcpu *vcpu) |
| 221 | { |
| 222 | set_intercept_indicators_ext(vcpu); |
| 223 | set_intercept_indicators_mchk(vcpu); |
| 224 | } |
| 225 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 226 | static void __set_intercept_indicator(struct kvm_vcpu *vcpu, |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 227 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 228 | { |
| 229 | switch (inti->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 230 | case KVM_S390_INT_SERVICE: |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 231 | case KVM_S390_INT_PFAULT_DONE: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 232 | case KVM_S390_INT_VIRTIO: |
| 233 | if (psw_extint_disabled(vcpu)) |
| 234 | __set_cpuflag(vcpu, CPUSTAT_EXT_INT); |
| 235 | else |
| 236 | vcpu->arch.sie_block->lctl |= LCTL_CR0; |
| 237 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 238 | case KVM_S390_MCHK: |
| 239 | if (psw_mchk_disabled(vcpu)) |
| 240 | vcpu->arch.sie_block->ictl |= ICTL_LPSW; |
| 241 | else |
| 242 | vcpu->arch.sie_block->lctl |= LCTL_CR14; |
| 243 | break; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 244 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 245 | if (psw_ioint_disabled(vcpu)) |
| 246 | __set_cpuflag(vcpu, CPUSTAT_IO_INT); |
| 247 | else |
| 248 | vcpu->arch.sie_block->lctl |= LCTL_CR6; |
| 249 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 250 | default: |
| 251 | BUG(); |
| 252 | } |
| 253 | } |
| 254 | |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 255 | static u16 get_ilc(struct kvm_vcpu *vcpu) |
| 256 | { |
| 257 | const unsigned short table[] = { 2, 4, 4, 6 }; |
| 258 | |
| 259 | switch (vcpu->arch.sie_block->icptcode) { |
| 260 | case ICPT_INST: |
| 261 | case ICPT_INSTPROGI: |
| 262 | case ICPT_OPEREXC: |
| 263 | case ICPT_PARTEXEC: |
| 264 | case ICPT_IOINST: |
| 265 | /* last instruction only stored for these icptcodes */ |
| 266 | return table[vcpu->arch.sie_block->ipa >> 14]; |
| 267 | case ICPT_PROGI: |
| 268 | return vcpu->arch.sie_block->pgmilc; |
| 269 | default: |
| 270 | return 0; |
| 271 | } |
| 272 | } |
| 273 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 274 | static int __must_check __deliver_cpu_timer(struct kvm_vcpu *vcpu) |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 275 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 276 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 277 | int rc; |
| 278 | |
| 279 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, |
| 280 | 0, 0); |
| 281 | |
| 282 | rc = put_guest_lc(vcpu, EXT_IRQ_CPU_TIMER, |
| 283 | (u16 *)__LC_EXT_INT_CODE); |
David Hildenbrand | 467fc29 | 2014-12-01 12:02:44 +0100 | [diff] [blame] | 284 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 285 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 286 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 287 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 288 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 289 | clear_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 290 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static int __must_check __deliver_ckc(struct kvm_vcpu *vcpu) |
| 294 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 295 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 296 | int rc; |
| 297 | |
| 298 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, |
| 299 | 0, 0); |
| 300 | |
| 301 | rc = put_guest_lc(vcpu, EXT_IRQ_CLK_COMP, |
| 302 | (u16 __user *)__LC_EXT_INT_CODE); |
David Hildenbrand | 467fc29 | 2014-12-01 12:02:44 +0100 | [diff] [blame] | 303 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 304 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 305 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 306 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 307 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 308 | clear_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 309 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 312 | static int __must_check __deliver_pfault_init(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 313 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 314 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 315 | struct kvm_s390_ext_info ext; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 316 | int rc; |
| 317 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 318 | spin_lock(&li->lock); |
| 319 | ext = li->irq.ext; |
| 320 | clear_bit(IRQ_PEND_PFAULT_INIT, &li->pending_irqs); |
| 321 | li->irq.ext.ext_params2 = 0; |
| 322 | spin_unlock(&li->lock); |
| 323 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 324 | VCPU_EVENT(vcpu, 4, "interrupt: pfault init parm:%x,parm64:%llx", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 325 | 0, ext.ext_params2); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 326 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 327 | KVM_S390_INT_PFAULT_INIT, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 328 | 0, ext.ext_params2); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 329 | |
| 330 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *) __LC_EXT_INT_CODE); |
| 331 | rc |= put_guest_lc(vcpu, PFAULT_INIT, (u16 *) __LC_EXT_CPU_ADDR); |
| 332 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 333 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 334 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 335 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 336 | rc |= put_guest_lc(vcpu, ext.ext_params2, (u64 *) __LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 337 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 340 | static int __must_check __deliver_machine_check(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 341 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 342 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 343 | struct kvm_s390_mchk_info mchk; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 344 | int rc; |
| 345 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 346 | spin_lock(&li->lock); |
| 347 | mchk = li->irq.mchk; |
| 348 | /* |
| 349 | * If there was an exigent machine check pending, then any repressible |
| 350 | * machine checks that might have been pending are indicated along |
| 351 | * with it, so always clear both bits |
| 352 | */ |
| 353 | clear_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); |
| 354 | clear_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); |
| 355 | memset(&li->irq.mchk, 0, sizeof(mchk)); |
| 356 | spin_unlock(&li->lock); |
| 357 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 358 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 359 | mchk.mcic); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 360 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_MCHK, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 361 | mchk.cr14, mchk.mcic); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 362 | |
| 363 | rc = kvm_s390_vcpu_store_status(vcpu, KVM_S390_STORE_STATUS_PREFIXED); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 364 | rc |= put_guest_lc(vcpu, mchk.mcic, |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 365 | (u64 __user *) __LC_MCCK_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 366 | rc |= put_guest_lc(vcpu, mchk.failing_storage_address, |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 367 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); |
| 368 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 369 | &mchk.fixed_logout, sizeof(mchk.fixed_logout)); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 370 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, |
| 371 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 372 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, |
| 373 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 374 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static int __must_check __deliver_restart(struct kvm_vcpu *vcpu) |
| 378 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 379 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 380 | int rc; |
| 381 | |
| 382 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart"); |
| 383 | vcpu->stat.deliver_restart_signal++; |
| 384 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0); |
| 385 | |
| 386 | rc = write_guest_lc(vcpu, |
| 387 | offsetof(struct _lowcore, restart_old_psw), |
| 388 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 389 | rc |= read_guest_lc(vcpu, offsetof(struct _lowcore, restart_psw), |
| 390 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 391 | clear_bit(IRQ_PEND_RESTART, &li->pending_irqs); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 392 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static int __must_check __deliver_stop(struct kvm_vcpu *vcpu) |
| 396 | { |
| 397 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu stop"); |
| 398 | vcpu->stat.deliver_stop_signal++; |
| 399 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_SIGP_STOP, |
| 400 | 0, 0); |
| 401 | |
| 402 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 403 | clear_bit(IRQ_PEND_SIGP_STOP, &vcpu->arch.local_int.pending_irqs); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 407 | static int __must_check __deliver_set_prefix(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 408 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 409 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 410 | struct kvm_s390_prefix_info prefix; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 411 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 412 | spin_lock(&li->lock); |
| 413 | prefix = li->irq.prefix; |
| 414 | li->irq.prefix.address = 0; |
| 415 | clear_bit(IRQ_PEND_SET_PREFIX, &li->pending_irqs); |
| 416 | spin_unlock(&li->lock); |
| 417 | |
| 418 | VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x", prefix.address); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 419 | vcpu->stat.deliver_prefix_signal++; |
| 420 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 421 | KVM_S390_SIGP_SET_PREFIX, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 422 | prefix.address, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 423 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 424 | kvm_s390_set_prefix(vcpu, prefix.address); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 428 | static int __must_check __deliver_emergency_signal(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 429 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 430 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 431 | int rc; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 432 | int cpu_addr; |
| 433 | |
| 434 | spin_lock(&li->lock); |
| 435 | cpu_addr = find_first_bit(li->sigp_emerg_pending, KVM_MAX_VCPUS); |
| 436 | clear_bit(cpu_addr, li->sigp_emerg_pending); |
| 437 | if (bitmap_empty(li->sigp_emerg_pending, KVM_MAX_VCPUS)) |
| 438 | clear_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); |
| 439 | spin_unlock(&li->lock); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 440 | |
| 441 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp emerg"); |
| 442 | vcpu->stat.deliver_emergency_signal++; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 443 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, |
| 444 | cpu_addr, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 445 | |
| 446 | rc = put_guest_lc(vcpu, EXT_IRQ_EMERGENCY_SIG, |
| 447 | (u16 *)__LC_EXT_INT_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 448 | rc |= put_guest_lc(vcpu, cpu_addr, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 449 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 450 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 451 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 452 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 453 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 454 | } |
| 455 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 456 | static int __must_check __deliver_external_call(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 457 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 458 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 459 | struct kvm_s390_extcall_info extcall; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 460 | int rc; |
| 461 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 462 | spin_lock(&li->lock); |
| 463 | extcall = li->irq.extcall; |
| 464 | li->irq.extcall.code = 0; |
| 465 | clear_bit(IRQ_PEND_EXT_EXTERNAL, &li->pending_irqs); |
| 466 | spin_unlock(&li->lock); |
| 467 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 468 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call"); |
| 469 | vcpu->stat.deliver_external_call++; |
| 470 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 471 | KVM_S390_INT_EXTERNAL_CALL, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 472 | extcall.code, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 473 | |
| 474 | rc = put_guest_lc(vcpu, EXT_IRQ_EXTERNAL_CALL, |
| 475 | (u16 *)__LC_EXT_INT_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 476 | rc |= put_guest_lc(vcpu, extcall.code, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 477 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 478 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 479 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &vcpu->arch.sie_block->gpsw, |
| 480 | sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 481 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 482 | } |
| 483 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 484 | static int __must_check __deliver_prog(struct kvm_vcpu *vcpu) |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 485 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 486 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 487 | struct kvm_s390_pgm_info pgm_info; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 488 | int rc = 0; |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 489 | u16 ilc = get_ilc(vcpu); |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 490 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 491 | spin_lock(&li->lock); |
| 492 | pgm_info = li->irq.pgm; |
| 493 | clear_bit(IRQ_PEND_PROG, &li->pending_irqs); |
| 494 | memset(&li->irq.pgm, 0, sizeof(pgm_info)); |
| 495 | spin_unlock(&li->lock); |
| 496 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 497 | VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 498 | pgm_info.code, ilc); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 499 | vcpu->stat.deliver_program_int++; |
| 500 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 501 | pgm_info.code, 0); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 502 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 503 | switch (pgm_info.code & ~PGM_PER) { |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 504 | case PGM_AFX_TRANSLATION: |
| 505 | case PGM_ASX_TRANSLATION: |
| 506 | case PGM_EX_TRANSLATION: |
| 507 | case PGM_LFX_TRANSLATION: |
| 508 | case PGM_LSTE_SEQUENCE: |
| 509 | case PGM_LSX_TRANSLATION: |
| 510 | case PGM_LX_TRANSLATION: |
| 511 | case PGM_PRIMARY_AUTHORITY: |
| 512 | case PGM_SECONDARY_AUTHORITY: |
| 513 | case PGM_SPACE_SWITCH: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 514 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 515 | (u64 *)__LC_TRANS_EXC_CODE); |
| 516 | break; |
| 517 | case PGM_ALEN_TRANSLATION: |
| 518 | case PGM_ALE_SEQUENCE: |
| 519 | case PGM_ASTE_INSTANCE: |
| 520 | case PGM_ASTE_SEQUENCE: |
| 521 | case PGM_ASTE_VALIDITY: |
| 522 | case PGM_EXTENDED_AUTHORITY: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 523 | rc = put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 524 | (u8 *)__LC_EXC_ACCESS_ID); |
| 525 | break; |
| 526 | case PGM_ASCE_TYPE: |
| 527 | case PGM_PAGE_TRANSLATION: |
| 528 | case PGM_REGION_FIRST_TRANS: |
| 529 | case PGM_REGION_SECOND_TRANS: |
| 530 | case PGM_REGION_THIRD_TRANS: |
| 531 | case PGM_SEGMENT_TRANSLATION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 532 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 533 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 534 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 535 | (u8 *)__LC_EXC_ACCESS_ID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 536 | rc |= put_guest_lc(vcpu, pgm_info.op_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 537 | (u8 *)__LC_OP_ACCESS_ID); |
| 538 | break; |
| 539 | case PGM_MONITOR: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 540 | rc = put_guest_lc(vcpu, pgm_info.mon_class_nr, |
Thomas Huth | a36c539 | 2014-10-16 14:31:53 +0200 | [diff] [blame] | 541 | (u16 *)__LC_MON_CLASS_NR); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 542 | rc |= put_guest_lc(vcpu, pgm_info.mon_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 543 | (u64 *)__LC_MON_CODE); |
| 544 | break; |
| 545 | case PGM_DATA: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 546 | rc = put_guest_lc(vcpu, pgm_info.data_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 547 | (u32 *)__LC_DATA_EXC_CODE); |
| 548 | break; |
| 549 | case PGM_PROTECTION: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 550 | rc = put_guest_lc(vcpu, pgm_info.trans_exc_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 551 | (u64 *)__LC_TRANS_EXC_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 552 | rc |= put_guest_lc(vcpu, pgm_info.exc_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 553 | (u8 *)__LC_EXC_ACCESS_ID); |
| 554 | break; |
| 555 | } |
| 556 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 557 | if (pgm_info.code & PGM_PER) { |
| 558 | rc |= put_guest_lc(vcpu, pgm_info.per_code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 559 | (u8 *) __LC_PER_CODE); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 560 | rc |= put_guest_lc(vcpu, pgm_info.per_atmid, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 561 | (u8 *)__LC_PER_ATMID); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 562 | rc |= put_guest_lc(vcpu, pgm_info.per_address, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 563 | (u64 *) __LC_PER_ADDRESS); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 564 | rc |= put_guest_lc(vcpu, pgm_info.per_access_id, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 565 | (u8 *) __LC_PER_ACCESS_ID); |
| 566 | } |
| 567 | |
Jens Freimann | 8a2ef71 | 2014-07-23 16:36:06 +0200 | [diff] [blame] | 568 | rc |= put_guest_lc(vcpu, ilc, (u16 *) __LC_PGM_ILC); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 569 | rc |= put_guest_lc(vcpu, pgm_info.code, |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 570 | (u16 *)__LC_PGM_INT_CODE); |
| 571 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, |
| 572 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 573 | rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, |
| 574 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 575 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 576 | } |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 577 | |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 578 | static int __must_check __deliver_service(struct kvm_vcpu *vcpu, |
| 579 | struct kvm_s390_interrupt_info *inti) |
| 580 | { |
| 581 | int rc; |
| 582 | |
| 583 | VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x", |
| 584 | inti->ext.ext_params); |
| 585 | vcpu->stat.deliver_service_signal++; |
| 586 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 587 | inti->ext.ext_params, 0); |
| 588 | |
| 589 | 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] | 590 | rc |= put_guest_lc(vcpu, 0, (u16 *)__LC_EXT_CPU_ADDR); |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 591 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 592 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 593 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 594 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 595 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 596 | (u32 *)__LC_EXT_PARAMS); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 597 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | static int __must_check __deliver_pfault_done(struct kvm_vcpu *vcpu, |
| 601 | struct kvm_s390_interrupt_info *inti) |
| 602 | { |
| 603 | int rc; |
| 604 | |
| 605 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, |
| 606 | KVM_S390_INT_PFAULT_DONE, 0, |
| 607 | inti->ext.ext_params2); |
| 608 | |
| 609 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); |
| 610 | rc |= put_guest_lc(vcpu, PFAULT_DONE, (u16 *)__LC_EXT_CPU_ADDR); |
| 611 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 612 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 613 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 614 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 615 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 616 | (u64 *)__LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 617 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | static int __must_check __deliver_virtio(struct kvm_vcpu *vcpu, |
| 621 | struct kvm_s390_interrupt_info *inti) |
| 622 | { |
| 623 | int rc; |
| 624 | |
| 625 | VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx", |
| 626 | inti->ext.ext_params, inti->ext.ext_params2); |
| 627 | vcpu->stat.deliver_virtio_interrupt++; |
| 628 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 629 | inti->ext.ext_params, |
| 630 | inti->ext.ext_params2); |
| 631 | |
| 632 | rc = put_guest_lc(vcpu, EXT_IRQ_CP_SERVICE, (u16 *)__LC_EXT_INT_CODE); |
| 633 | rc |= put_guest_lc(vcpu, VIRTIO_PARAM, (u16 *)__LC_EXT_CPU_ADDR); |
| 634 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 635 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 636 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 637 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 638 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 639 | (u32 *)__LC_EXT_PARAMS); |
| 640 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 641 | (u64 *)__LC_EXT_PARAMS2); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 642 | return rc ? -EFAULT : 0; |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | static int __must_check __deliver_io(struct kvm_vcpu *vcpu, |
| 646 | struct kvm_s390_interrupt_info *inti) |
| 647 | { |
| 648 | int rc; |
| 649 | |
| 650 | VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type); |
| 651 | vcpu->stat.deliver_io_int++; |
| 652 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 653 | ((__u32)inti->io.subchannel_id << 16) | |
| 654 | inti->io.subchannel_nr, |
| 655 | ((__u64)inti->io.io_int_parm << 32) | |
| 656 | inti->io.io_int_word); |
| 657 | |
| 658 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, |
| 659 | (u16 *)__LC_SUBCHANNEL_ID); |
| 660 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, |
| 661 | (u16 *)__LC_SUBCHANNEL_NR); |
| 662 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, |
| 663 | (u32 *)__LC_IO_INT_PARM); |
| 664 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, |
| 665 | (u32 *)__LC_IO_INT_WORD); |
| 666 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, |
| 667 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 668 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, |
| 669 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 670 | return rc ? -EFAULT : 0; |
David Hildenbrand | 8712836 | 2014-03-03 10:55:13 +0100 | [diff] [blame] | 671 | } |
| 672 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 673 | static int __must_check __deliver_mchk_floating(struct kvm_vcpu *vcpu, |
| 674 | struct kvm_s390_interrupt_info *inti) |
| 675 | { |
| 676 | struct kvm_s390_mchk_info *mchk = &inti->mchk; |
| 677 | int rc; |
| 678 | |
| 679 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", |
| 680 | mchk->mcic); |
| 681 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, KVM_S390_MCHK, |
| 682 | mchk->cr14, mchk->mcic); |
| 683 | |
| 684 | rc = kvm_s390_vcpu_store_status(vcpu, KVM_S390_STORE_STATUS_PREFIXED); |
| 685 | rc |= put_guest_lc(vcpu, mchk->mcic, |
| 686 | (u64 __user *) __LC_MCCK_CODE); |
| 687 | rc |= put_guest_lc(vcpu, mchk->failing_storage_address, |
| 688 | (u64 __user *) __LC_MCCK_FAIL_STOR_ADDR); |
| 689 | rc |= write_guest_lc(vcpu, __LC_PSW_SAVE_AREA, |
| 690 | &mchk->fixed_logout, sizeof(mchk->fixed_logout)); |
| 691 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, |
| 692 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 693 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, |
| 694 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 99e2000 | 2014-12-01 17:05:39 +0100 | [diff] [blame] | 695 | return rc ? -EFAULT : 0; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | typedef int (*deliver_irq_t)(struct kvm_vcpu *vcpu); |
| 699 | |
| 700 | static const deliver_irq_t deliver_irq_funcs[] = { |
| 701 | [IRQ_PEND_MCHK_EX] = __deliver_machine_check, |
| 702 | [IRQ_PEND_PROG] = __deliver_prog, |
| 703 | [IRQ_PEND_EXT_EMERGENCY] = __deliver_emergency_signal, |
| 704 | [IRQ_PEND_EXT_EXTERNAL] = __deliver_external_call, |
| 705 | [IRQ_PEND_EXT_CLOCK_COMP] = __deliver_ckc, |
| 706 | [IRQ_PEND_EXT_CPU_TIMER] = __deliver_cpu_timer, |
| 707 | [IRQ_PEND_RESTART] = __deliver_restart, |
| 708 | [IRQ_PEND_SIGP_STOP] = __deliver_stop, |
| 709 | [IRQ_PEND_SET_PREFIX] = __deliver_set_prefix, |
| 710 | [IRQ_PEND_PFAULT_INIT] = __deliver_pfault_init, |
| 711 | }; |
| 712 | |
| 713 | static int __must_check __deliver_floating_interrupt(struct kvm_vcpu *vcpu, |
| 714 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 715 | { |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 716 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 717 | |
| 718 | switch (inti->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 719 | case KVM_S390_INT_SERVICE: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 720 | rc = __deliver_service(vcpu, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 721 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 722 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 723 | rc = __deliver_pfault_done(vcpu, inti); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 724 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 725 | case KVM_S390_INT_VIRTIO: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 726 | rc = __deliver_virtio(vcpu, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 727 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 728 | case KVM_S390_MCHK: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 729 | rc = __deliver_mchk_floating(vcpu, inti); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 730 | break; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 731 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Jens Freimann | 0fb97ab | 2014-07-29 13:45:21 +0200 | [diff] [blame] | 732 | rc = __deliver_io(vcpu, inti); |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 733 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 734 | default: |
| 735 | BUG(); |
| 736 | } |
Jens Freimann | 7939503 | 2014-04-17 10:10:30 +0200 | [diff] [blame] | 737 | |
| 738 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 739 | } |
| 740 | |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 741 | /* Check whether SIGP interpretation facility has an external call pending */ |
| 742 | int kvm_s390_si_ext_call_pending(struct kvm_vcpu *vcpu) |
| 743 | { |
| 744 | atomic_t *sigp_ctrl = &vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].ctrl; |
| 745 | |
| 746 | if (!psw_extint_disabled(vcpu) && |
| 747 | (vcpu->arch.sie_block->gcr[0] & 0x2000ul) && |
| 748 | (atomic_read(sigp_ctrl) & SIGP_CTRL_C) && |
| 749 | (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_ECALL_PEND)) |
| 750 | return 1; |
| 751 | |
| 752 | return 0; |
| 753 | } |
| 754 | |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 755 | int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 756 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 757 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 758 | struct kvm_s390_interrupt_info *inti; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 759 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 760 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 761 | rc = !!deliverable_local_irqs(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 762 | |
| 763 | if ((!rc) && atomic_read(&fi->active)) { |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 764 | spin_lock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 765 | list_for_each_entry(inti, &fi->list, list) |
| 766 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 767 | rc = 1; |
| 768 | break; |
| 769 | } |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 770 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 771 | } |
| 772 | |
David Hildenbrand | bb78c5e | 2014-03-18 10:03:26 +0100 | [diff] [blame] | 773 | if (!rc && kvm_cpu_has_pending_timer(vcpu)) |
| 774 | rc = 1; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 775 | |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 776 | if (!rc && kvm_s390_si_ext_call_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 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1034 | 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] | 1035 | { |
| 1036 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1037 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1038 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_SIGP_STOP, 0, 0, 2); |
| 1039 | |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1040 | li->action_bits |= ACTION_STOP_ON_STOP; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1041 | set_bit(IRQ_PEND_SIGP_STOP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int __inject_sigp_restart(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1046 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1047 | { |
| 1048 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1049 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1050 | VCPU_EVENT(vcpu, 3, "inject: restart type %llx", irq->type); |
| 1051 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_RESTART, 0, 0, 2); |
| 1052 | |
| 1053 | set_bit(IRQ_PEND_RESTART, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | static int __inject_sigp_emergency(struct kvm_vcpu *vcpu, |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1058 | struct kvm_s390_irq *irq) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1059 | { |
| 1060 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1061 | struct kvm_s390_emerg_info *emerg = &li->irq.emerg; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1062 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1063 | VCPU_EVENT(vcpu, 3, "inject: emergency %u\n", |
| 1064 | irq->u.emerg.code); |
| 1065 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_EMERGENCY, |
| 1066 | emerg->code, 0, 2); |
| 1067 | |
| 1068 | set_bit(emerg->code, li->sigp_emerg_pending); |
| 1069 | set_bit(IRQ_PEND_EXT_EMERGENCY, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1070 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1074 | 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] | 1075 | { |
| 1076 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1077 | struct kvm_s390_mchk_info *mchk = &li->irq.mchk; |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1078 | |
| 1079 | VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx", |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1080 | mchk->mcic); |
| 1081 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_MCHK, 0, |
| 1082 | mchk->mcic, 2); |
| 1083 | |
| 1084 | /* |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1085 | * Because repressible machine checks can be indicated along with |
| 1086 | * exigent machine checks (PoP, Chapter 11, Interruption action) |
| 1087 | * we need to combine cr14, mcic and external damage code. |
| 1088 | * Failing storage address and the logout area should not be or'ed |
| 1089 | * together, we just indicate the last occurrence of the corresponding |
| 1090 | * machine check |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1091 | */ |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1092 | mchk->cr14 |= irq->u.mchk.cr14; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1093 | mchk->mcic |= irq->u.mchk.mcic; |
Jens Freimann | fc2020c | 2014-08-13 10:09:04 +0200 | [diff] [blame] | 1094 | mchk->ext_damage_code |= irq->u.mchk.ext_damage_code; |
| 1095 | mchk->failing_storage_address = irq->u.mchk.failing_storage_address; |
| 1096 | memcpy(&mchk->fixed_logout, &irq->u.mchk.fixed_logout, |
| 1097 | sizeof(mchk->fixed_logout)); |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1098 | if (mchk->mcic & MCHK_EX_MASK) |
| 1099 | set_bit(IRQ_PEND_MCHK_EX, &li->pending_irqs); |
| 1100 | else if (mchk->mcic & MCHK_REP_MASK) |
| 1101 | set_bit(IRQ_PEND_MCHK_REP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1102 | return 0; |
| 1103 | } |
| 1104 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1105 | static int __inject_ckc(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1106 | { |
| 1107 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1108 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1109 | VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CLOCK_COMP); |
| 1110 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CLOCK_COMP, |
| 1111 | 0, 0, 2); |
| 1112 | |
| 1113 | set_bit(IRQ_PEND_EXT_CLOCK_COMP, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1114 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1118 | static int __inject_cpu_timer(struct kvm_vcpu *vcpu) |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1119 | { |
| 1120 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1121 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1122 | VCPU_EVENT(vcpu, 3, "inject: type %x", KVM_S390_INT_CPU_TIMER); |
| 1123 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_INT_CPU_TIMER, |
| 1124 | 0, 0, 2); |
| 1125 | |
| 1126 | set_bit(IRQ_PEND_EXT_CPU_TIMER, &li->pending_irqs); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1127 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 1128 | return 0; |
| 1129 | } |
| 1130 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1131 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1132 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
| 1133 | u64 cr6, u64 schid) |
| 1134 | { |
| 1135 | struct kvm_s390_float_interrupt *fi; |
| 1136 | struct kvm_s390_interrupt_info *inti, *iter; |
| 1137 | |
| 1138 | if ((!schid && !cr6) || (schid && cr6)) |
| 1139 | return NULL; |
| 1140 | mutex_lock(&kvm->lock); |
| 1141 | fi = &kvm->arch.float_int; |
| 1142 | spin_lock(&fi->lock); |
| 1143 | inti = NULL; |
| 1144 | list_for_each_entry(iter, &fi->list, list) { |
| 1145 | if (!is_ioint(iter->type)) |
| 1146 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1147 | if (cr6 && |
| 1148 | ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0)) |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1149 | continue; |
| 1150 | if (schid) { |
| 1151 | if (((schid & 0x00000000ffff0000) >> 16) != |
| 1152 | iter->io.subchannel_id) |
| 1153 | continue; |
| 1154 | if ((schid & 0x000000000000ffff) != |
| 1155 | iter->io.subchannel_nr) |
| 1156 | continue; |
| 1157 | } |
| 1158 | inti = iter; |
| 1159 | break; |
| 1160 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1161 | if (inti) { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1162 | list_del_init(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1163 | fi->irq_count--; |
| 1164 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 1165 | if (list_empty(&fi->list)) |
| 1166 | atomic_set(&fi->active, 0); |
| 1167 | spin_unlock(&fi->lock); |
| 1168 | mutex_unlock(&kvm->lock); |
| 1169 | return inti; |
| 1170 | } |
| 1171 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1172 | 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] | 1173 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 1174 | struct kvm_s390_local_interrupt *li; |
| 1175 | struct kvm_s390_float_interrupt *fi; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1176 | struct kvm_s390_interrupt_info *iter; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1177 | struct kvm_vcpu *dst_vcpu = NULL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1178 | int sigcpu; |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1179 | int rc = 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1180 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1181 | mutex_lock(&kvm->lock); |
| 1182 | fi = &kvm->arch.float_int; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 1183 | spin_lock(&fi->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1184 | if (fi->irq_count >= KVM_S390_MAX_FLOAT_IRQS) { |
| 1185 | rc = -EINVAL; |
| 1186 | goto unlock_fi; |
| 1187 | } |
| 1188 | fi->irq_count++; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1189 | if (!is_ioint(inti->type)) { |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1190 | list_add_tail(&inti->list, &fi->list); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1191 | } else { |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1192 | u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word); |
| 1193 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1194 | /* Keep I/O interrupts sorted in isc order. */ |
| 1195 | list_for_each_entry(iter, &fi->list, list) { |
| 1196 | if (!is_ioint(iter->type)) |
| 1197 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 1198 | if (int_word_to_isc_bits(iter->io.io_int_word) |
| 1199 | <= isc_bits) |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1200 | continue; |
| 1201 | break; |
| 1202 | } |
| 1203 | list_add_tail(&inti->list, &iter->list); |
| 1204 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1205 | atomic_set(&fi->active, 1); |
| 1206 | sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); |
| 1207 | if (sigcpu == KVM_MAX_VCPUS) { |
| 1208 | do { |
| 1209 | sigcpu = fi->next_rr_cpu++; |
| 1210 | if (sigcpu == KVM_MAX_VCPUS) |
| 1211 | sigcpu = fi->next_rr_cpu = 0; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1212 | } while (kvm_get_vcpu(kvm, sigcpu) == NULL); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1213 | } |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 1214 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); |
| 1215 | li = &dst_vcpu->arch.local_int; |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1216 | spin_lock(&li->lock); |
Christian Borntraeger | da00fcb | 2014-11-21 09:38:12 +0100 | [diff] [blame] | 1217 | switch (inti->type) { |
| 1218 | case KVM_S390_MCHK: |
| 1219 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
| 1220 | break; |
| 1221 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1222 | atomic_set_mask(CPUSTAT_IO_INT, li->cpuflags); |
| 1223 | break; |
| 1224 | default: |
| 1225 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 1226 | break; |
| 1227 | } |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1228 | spin_unlock(&li->lock); |
David Hildenbrand | 0e9c85a | 2014-05-16 11:59:46 +0200 | [diff] [blame] | 1229 | kvm_s390_vcpu_wakeup(kvm_get_vcpu(kvm, sigcpu)); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1230 | unlock_fi: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 1231 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1232 | mutex_unlock(&kvm->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1233 | return rc; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | int kvm_s390_inject_vm(struct kvm *kvm, |
| 1237 | struct kvm_s390_interrupt *s390int) |
| 1238 | { |
| 1239 | struct kvm_s390_interrupt_info *inti; |
| 1240 | |
| 1241 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1242 | if (!inti) |
| 1243 | return -ENOMEM; |
| 1244 | |
| 1245 | inti->type = s390int->type; |
| 1246 | switch (inti->type) { |
| 1247 | case KVM_S390_INT_VIRTIO: |
| 1248 | VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx", |
| 1249 | s390int->parm, s390int->parm64); |
| 1250 | inti->ext.ext_params = s390int->parm; |
| 1251 | inti->ext.ext_params2 = s390int->parm64; |
| 1252 | break; |
| 1253 | case KVM_S390_INT_SERVICE: |
| 1254 | VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm); |
| 1255 | inti->ext.ext_params = s390int->parm; |
| 1256 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1257 | case KVM_S390_INT_PFAULT_DONE: |
| 1258 | inti->type = s390int->type; |
| 1259 | inti->ext.ext_params2 = s390int->parm64; |
| 1260 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1261 | case KVM_S390_MCHK: |
| 1262 | VM_EVENT(kvm, 5, "inject: machine check parm64:%llx", |
| 1263 | s390int->parm64); |
| 1264 | inti->mchk.cr14 = s390int->parm; /* upper bits are not used */ |
| 1265 | inti->mchk.mcic = s390int->parm64; |
| 1266 | break; |
| 1267 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1268 | if (inti->type & IOINT_AI_MASK) |
| 1269 | VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)"); |
| 1270 | else |
| 1271 | VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x", |
| 1272 | s390int->type & IOINT_CSSID_MASK, |
| 1273 | s390int->type & IOINT_SSID_MASK, |
| 1274 | s390int->type & IOINT_SCHID_MASK); |
| 1275 | inti->io.subchannel_id = s390int->parm >> 16; |
| 1276 | inti->io.subchannel_nr = s390int->parm & 0x0000ffffu; |
| 1277 | inti->io.io_int_parm = s390int->parm64 >> 32; |
| 1278 | inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull; |
| 1279 | break; |
| 1280 | default: |
| 1281 | kfree(inti); |
| 1282 | return -EINVAL; |
| 1283 | } |
| 1284 | trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64, |
| 1285 | 2); |
| 1286 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1287 | return __inject_vm(kvm, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
Cornelia Huck | 2f32d4e | 2014-01-08 18:07:54 +0100 | [diff] [blame] | 1290 | void kvm_s390_reinject_io_int(struct kvm *kvm, |
| 1291 | struct kvm_s390_interrupt_info *inti) |
| 1292 | { |
| 1293 | __inject_vm(kvm, inti); |
| 1294 | } |
| 1295 | |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1296 | int s390int_to_s390irq(struct kvm_s390_interrupt *s390int, |
| 1297 | struct kvm_s390_irq *irq) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1298 | { |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1299 | irq->type = s390int->type; |
| 1300 | switch (irq->type) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1301 | case KVM_S390_PROGRAM_INT: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1302 | if (s390int->parm & 0xffff0000) |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1303 | return -EINVAL; |
| 1304 | irq->u.pgm.code = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1305 | break; |
Christian Borntraeger | b7e6e4d | 2009-01-22 10:29:08 +0100 | [diff] [blame] | 1306 | case KVM_S390_SIGP_SET_PREFIX: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1307 | irq->u.prefix.address = s390int->parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1308 | break; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1309 | case KVM_S390_INT_EXTERNAL_CALL: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1310 | if (irq->u.extcall.code & 0xffff0000) |
| 1311 | return -EINVAL; |
| 1312 | irq->u.extcall.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1313 | break; |
| 1314 | case KVM_S390_INT_EMERGENCY: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1315 | if (irq->u.emerg.code & 0xffff0000) |
| 1316 | return -EINVAL; |
| 1317 | irq->u.emerg.code = s390int->parm; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 1318 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1319 | case KVM_S390_MCHK: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1320 | irq->u.mchk.mcic = s390int->parm64; |
| 1321 | break; |
| 1322 | } |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) |
| 1327 | { |
| 1328 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 1329 | int rc; |
| 1330 | |
| 1331 | spin_lock(&li->lock); |
| 1332 | switch (irq->type) { |
| 1333 | case KVM_S390_PROGRAM_INT: |
| 1334 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)", |
| 1335 | irq->u.pgm.code); |
| 1336 | rc = __inject_prog(vcpu, irq); |
| 1337 | break; |
| 1338 | case KVM_S390_SIGP_SET_PREFIX: |
| 1339 | rc = __inject_set_prefix(vcpu, irq); |
| 1340 | break; |
| 1341 | case KVM_S390_SIGP_STOP: |
| 1342 | rc = __inject_sigp_stop(vcpu, irq); |
| 1343 | break; |
| 1344 | case KVM_S390_RESTART: |
| 1345 | rc = __inject_sigp_restart(vcpu, irq); |
| 1346 | break; |
| 1347 | case KVM_S390_INT_CLOCK_COMP: |
| 1348 | rc = __inject_ckc(vcpu); |
| 1349 | break; |
| 1350 | case KVM_S390_INT_CPU_TIMER: |
| 1351 | rc = __inject_cpu_timer(vcpu); |
| 1352 | break; |
| 1353 | case KVM_S390_INT_EXTERNAL_CALL: |
| 1354 | rc = __inject_extcall(vcpu, irq); |
| 1355 | break; |
| 1356 | case KVM_S390_INT_EMERGENCY: |
| 1357 | rc = __inject_sigp_emergency(vcpu, irq); |
| 1358 | break; |
| 1359 | case KVM_S390_MCHK: |
| 1360 | rc = __inject_mchk(vcpu, irq); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 1361 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1362 | case KVM_S390_INT_PFAULT_INIT: |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 1363 | rc = __inject_pfault_init(vcpu, irq); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1364 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1365 | case KVM_S390_INT_VIRTIO: |
| 1366 | case KVM_S390_INT_SERVICE: |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 1367 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1368 | default: |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1369 | rc = -EINVAL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1370 | } |
David Hildenbrand | 4ae3c08 | 2014-05-16 10:23:53 +0200 | [diff] [blame] | 1371 | spin_unlock(&li->lock); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1372 | if (!rc) |
| 1373 | kvm_s390_vcpu_wakeup(vcpu); |
Jens Freimann | 0146a7b | 2014-07-28 15:37:58 +0200 | [diff] [blame] | 1374 | return rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1375 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1376 | |
Christian Borntraeger | 67335e6 | 2014-03-25 17:09:08 +0100 | [diff] [blame] | 1377 | void kvm_s390_clear_float_irqs(struct kvm *kvm) |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1378 | { |
| 1379 | struct kvm_s390_float_interrupt *fi; |
| 1380 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
| 1381 | |
| 1382 | mutex_lock(&kvm->lock); |
| 1383 | fi = &kvm->arch.float_int; |
| 1384 | spin_lock(&fi->lock); |
| 1385 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 1386 | list_del(&inti->list); |
| 1387 | kfree(inti); |
| 1388 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1389 | fi->irq_count = 0; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1390 | atomic_set(&fi->active, 0); |
| 1391 | spin_unlock(&fi->lock); |
| 1392 | mutex_unlock(&kvm->lock); |
| 1393 | } |
| 1394 | |
| 1395 | static inline int copy_irq_to_user(struct kvm_s390_interrupt_info *inti, |
| 1396 | u8 *addr) |
| 1397 | { |
| 1398 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1399 | struct kvm_s390_irq irq = {0}; |
| 1400 | |
| 1401 | irq.type = inti->type; |
| 1402 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1403 | case KVM_S390_INT_PFAULT_INIT: |
| 1404 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1405 | case KVM_S390_INT_VIRTIO: |
| 1406 | case KVM_S390_INT_SERVICE: |
| 1407 | irq.u.ext = inti->ext; |
| 1408 | break; |
| 1409 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1410 | irq.u.io = inti->io; |
| 1411 | break; |
| 1412 | case KVM_S390_MCHK: |
| 1413 | irq.u.mchk = inti->mchk; |
| 1414 | break; |
| 1415 | default: |
| 1416 | return -EINVAL; |
| 1417 | } |
| 1418 | |
| 1419 | if (copy_to_user(uptr, &irq, sizeof(irq))) |
| 1420 | return -EFAULT; |
| 1421 | |
| 1422 | return 0; |
| 1423 | } |
| 1424 | |
| 1425 | static int get_all_floating_irqs(struct kvm *kvm, __u8 *buf, __u64 len) |
| 1426 | { |
| 1427 | struct kvm_s390_interrupt_info *inti; |
| 1428 | struct kvm_s390_float_interrupt *fi; |
| 1429 | int ret = 0; |
| 1430 | int n = 0; |
| 1431 | |
| 1432 | mutex_lock(&kvm->lock); |
| 1433 | fi = &kvm->arch.float_int; |
| 1434 | spin_lock(&fi->lock); |
| 1435 | |
| 1436 | list_for_each_entry(inti, &fi->list, list) { |
| 1437 | if (len < sizeof(struct kvm_s390_irq)) { |
| 1438 | /* signal userspace to try again */ |
| 1439 | ret = -ENOMEM; |
| 1440 | break; |
| 1441 | } |
| 1442 | ret = copy_irq_to_user(inti, buf); |
| 1443 | if (ret) |
| 1444 | break; |
| 1445 | buf += sizeof(struct kvm_s390_irq); |
| 1446 | len -= sizeof(struct kvm_s390_irq); |
| 1447 | n++; |
| 1448 | } |
| 1449 | |
| 1450 | spin_unlock(&fi->lock); |
| 1451 | mutex_unlock(&kvm->lock); |
| 1452 | |
| 1453 | return ret < 0 ? ret : n; |
| 1454 | } |
| 1455 | |
| 1456 | static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1457 | { |
| 1458 | int r; |
| 1459 | |
| 1460 | switch (attr->group) { |
| 1461 | case KVM_DEV_FLIC_GET_ALL_IRQS: |
| 1462 | r = get_all_floating_irqs(dev->kvm, (u8 *) attr->addr, |
| 1463 | attr->attr); |
| 1464 | break; |
| 1465 | default: |
| 1466 | r = -EINVAL; |
| 1467 | } |
| 1468 | |
| 1469 | return r; |
| 1470 | } |
| 1471 | |
| 1472 | static inline int copy_irq_from_user(struct kvm_s390_interrupt_info *inti, |
| 1473 | u64 addr) |
| 1474 | { |
| 1475 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1476 | void *target = NULL; |
| 1477 | void __user *source; |
| 1478 | u64 size; |
| 1479 | |
| 1480 | if (get_user(inti->type, (u64 __user *)addr)) |
| 1481 | return -EFAULT; |
| 1482 | |
| 1483 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1484 | case KVM_S390_INT_PFAULT_INIT: |
| 1485 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1486 | case KVM_S390_INT_VIRTIO: |
| 1487 | case KVM_S390_INT_SERVICE: |
| 1488 | target = (void *) &inti->ext; |
| 1489 | source = &uptr->u.ext; |
| 1490 | size = sizeof(inti->ext); |
| 1491 | break; |
| 1492 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1493 | target = (void *) &inti->io; |
| 1494 | source = &uptr->u.io; |
| 1495 | size = sizeof(inti->io); |
| 1496 | break; |
| 1497 | case KVM_S390_MCHK: |
| 1498 | target = (void *) &inti->mchk; |
| 1499 | source = &uptr->u.mchk; |
| 1500 | size = sizeof(inti->mchk); |
| 1501 | break; |
| 1502 | default: |
| 1503 | return -EINVAL; |
| 1504 | } |
| 1505 | |
| 1506 | if (copy_from_user(target, source, size)) |
| 1507 | return -EFAULT; |
| 1508 | |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | static int enqueue_floating_irq(struct kvm_device *dev, |
| 1513 | struct kvm_device_attr *attr) |
| 1514 | { |
| 1515 | struct kvm_s390_interrupt_info *inti = NULL; |
| 1516 | int r = 0; |
| 1517 | int len = attr->attr; |
| 1518 | |
| 1519 | if (len % sizeof(struct kvm_s390_irq) != 0) |
| 1520 | return -EINVAL; |
| 1521 | else if (len > KVM_S390_FLIC_MAX_BUFFER) |
| 1522 | return -EINVAL; |
| 1523 | |
| 1524 | while (len >= sizeof(struct kvm_s390_irq)) { |
| 1525 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1526 | if (!inti) |
| 1527 | return -ENOMEM; |
| 1528 | |
| 1529 | r = copy_irq_from_user(inti, attr->addr); |
| 1530 | if (r) { |
| 1531 | kfree(inti); |
| 1532 | return r; |
| 1533 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1534 | r = __inject_vm(dev->kvm, inti); |
| 1535 | if (r) { |
| 1536 | kfree(inti); |
| 1537 | return r; |
| 1538 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1539 | len -= sizeof(struct kvm_s390_irq); |
| 1540 | attr->addr += sizeof(struct kvm_s390_irq); |
| 1541 | } |
| 1542 | |
| 1543 | return r; |
| 1544 | } |
| 1545 | |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1546 | static struct s390_io_adapter *get_io_adapter(struct kvm *kvm, unsigned int id) |
| 1547 | { |
| 1548 | if (id >= MAX_S390_IO_ADAPTERS) |
| 1549 | return NULL; |
| 1550 | return kvm->arch.adapters[id]; |
| 1551 | } |
| 1552 | |
| 1553 | static int register_io_adapter(struct kvm_device *dev, |
| 1554 | struct kvm_device_attr *attr) |
| 1555 | { |
| 1556 | struct s390_io_adapter *adapter; |
| 1557 | struct kvm_s390_io_adapter adapter_info; |
| 1558 | |
| 1559 | if (copy_from_user(&adapter_info, |
| 1560 | (void __user *)attr->addr, sizeof(adapter_info))) |
| 1561 | return -EFAULT; |
| 1562 | |
| 1563 | if ((adapter_info.id >= MAX_S390_IO_ADAPTERS) || |
| 1564 | (dev->kvm->arch.adapters[adapter_info.id] != NULL)) |
| 1565 | return -EINVAL; |
| 1566 | |
| 1567 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 1568 | if (!adapter) |
| 1569 | return -ENOMEM; |
| 1570 | |
| 1571 | INIT_LIST_HEAD(&adapter->maps); |
| 1572 | init_rwsem(&adapter->maps_lock); |
| 1573 | atomic_set(&adapter->nr_maps, 0); |
| 1574 | adapter->id = adapter_info.id; |
| 1575 | adapter->isc = adapter_info.isc; |
| 1576 | adapter->maskable = adapter_info.maskable; |
| 1577 | adapter->masked = false; |
| 1578 | adapter->swap = adapter_info.swap; |
| 1579 | dev->kvm->arch.adapters[adapter->id] = adapter; |
| 1580 | |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked) |
| 1585 | { |
| 1586 | int ret; |
| 1587 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1588 | |
| 1589 | if (!adapter || !adapter->maskable) |
| 1590 | return -EINVAL; |
| 1591 | ret = adapter->masked; |
| 1592 | adapter->masked = masked; |
| 1593 | return ret; |
| 1594 | } |
| 1595 | |
| 1596 | static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1597 | { |
| 1598 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1599 | struct s390_map_info *map; |
| 1600 | int ret; |
| 1601 | |
| 1602 | if (!adapter || !addr) |
| 1603 | return -EINVAL; |
| 1604 | |
| 1605 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 1606 | if (!map) { |
| 1607 | ret = -ENOMEM; |
| 1608 | goto out; |
| 1609 | } |
| 1610 | INIT_LIST_HEAD(&map->list); |
| 1611 | map->guest_addr = addr; |
Martin Schwidefsky | 6e0a043 | 2014-04-29 09:34:41 +0200 | [diff] [blame] | 1612 | map->addr = gmap_translate(kvm->arch.gmap, addr); |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1613 | if (map->addr == -EFAULT) { |
| 1614 | ret = -EFAULT; |
| 1615 | goto out; |
| 1616 | } |
| 1617 | ret = get_user_pages_fast(map->addr, 1, 1, &map->page); |
| 1618 | if (ret < 0) |
| 1619 | goto out; |
| 1620 | BUG_ON(ret != 1); |
| 1621 | down_write(&adapter->maps_lock); |
| 1622 | if (atomic_inc_return(&adapter->nr_maps) < MAX_S390_ADAPTER_MAPS) { |
| 1623 | list_add_tail(&map->list, &adapter->maps); |
| 1624 | ret = 0; |
| 1625 | } else { |
| 1626 | put_page(map->page); |
| 1627 | ret = -EINVAL; |
| 1628 | } |
| 1629 | up_write(&adapter->maps_lock); |
| 1630 | out: |
| 1631 | if (ret) |
| 1632 | kfree(map); |
| 1633 | return ret; |
| 1634 | } |
| 1635 | |
| 1636 | static int kvm_s390_adapter_unmap(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1637 | { |
| 1638 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1639 | struct s390_map_info *map, *tmp; |
| 1640 | int found = 0; |
| 1641 | |
| 1642 | if (!adapter || !addr) |
| 1643 | return -EINVAL; |
| 1644 | |
| 1645 | down_write(&adapter->maps_lock); |
| 1646 | list_for_each_entry_safe(map, tmp, &adapter->maps, list) { |
| 1647 | if (map->guest_addr == addr) { |
| 1648 | found = 1; |
| 1649 | atomic_dec(&adapter->nr_maps); |
| 1650 | list_del(&map->list); |
| 1651 | put_page(map->page); |
| 1652 | kfree(map); |
| 1653 | break; |
| 1654 | } |
| 1655 | } |
| 1656 | up_write(&adapter->maps_lock); |
| 1657 | |
| 1658 | return found ? 0 : -EINVAL; |
| 1659 | } |
| 1660 | |
| 1661 | void kvm_s390_destroy_adapters(struct kvm *kvm) |
| 1662 | { |
| 1663 | int i; |
| 1664 | struct s390_map_info *map, *tmp; |
| 1665 | |
| 1666 | for (i = 0; i < MAX_S390_IO_ADAPTERS; i++) { |
| 1667 | if (!kvm->arch.adapters[i]) |
| 1668 | continue; |
| 1669 | list_for_each_entry_safe(map, tmp, |
| 1670 | &kvm->arch.adapters[i]->maps, list) { |
| 1671 | list_del(&map->list); |
| 1672 | put_page(map->page); |
| 1673 | kfree(map); |
| 1674 | } |
| 1675 | kfree(kvm->arch.adapters[i]); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | static int modify_io_adapter(struct kvm_device *dev, |
| 1680 | struct kvm_device_attr *attr) |
| 1681 | { |
| 1682 | struct kvm_s390_io_adapter_req req; |
| 1683 | struct s390_io_adapter *adapter; |
| 1684 | int ret; |
| 1685 | |
| 1686 | if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) |
| 1687 | return -EFAULT; |
| 1688 | |
| 1689 | adapter = get_io_adapter(dev->kvm, req.id); |
| 1690 | if (!adapter) |
| 1691 | return -EINVAL; |
| 1692 | switch (req.type) { |
| 1693 | case KVM_S390_IO_ADAPTER_MASK: |
| 1694 | ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask); |
| 1695 | if (ret > 0) |
| 1696 | ret = 0; |
| 1697 | break; |
| 1698 | case KVM_S390_IO_ADAPTER_MAP: |
| 1699 | ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); |
| 1700 | break; |
| 1701 | case KVM_S390_IO_ADAPTER_UNMAP: |
| 1702 | ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); |
| 1703 | break; |
| 1704 | default: |
| 1705 | ret = -EINVAL; |
| 1706 | } |
| 1707 | |
| 1708 | return ret; |
| 1709 | } |
| 1710 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1711 | static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1712 | { |
| 1713 | int r = 0; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1714 | unsigned int i; |
| 1715 | struct kvm_vcpu *vcpu; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1716 | |
| 1717 | switch (attr->group) { |
| 1718 | case KVM_DEV_FLIC_ENQUEUE: |
| 1719 | r = enqueue_floating_irq(dev, attr); |
| 1720 | break; |
| 1721 | case KVM_DEV_FLIC_CLEAR_IRQS: |
Christian Borntraeger | 67335e6 | 2014-03-25 17:09:08 +0100 | [diff] [blame] | 1722 | kvm_s390_clear_float_irqs(dev->kvm); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1723 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1724 | case KVM_DEV_FLIC_APF_ENABLE: |
| 1725 | dev->kvm->arch.gmap->pfault_enabled = 1; |
| 1726 | break; |
| 1727 | case KVM_DEV_FLIC_APF_DISABLE_WAIT: |
| 1728 | dev->kvm->arch.gmap->pfault_enabled = 0; |
| 1729 | /* |
| 1730 | * Make sure no async faults are in transition when |
| 1731 | * clearing the queues. So we don't need to worry |
| 1732 | * about late coming workers. |
| 1733 | */ |
| 1734 | synchronize_srcu(&dev->kvm->srcu); |
| 1735 | kvm_for_each_vcpu(i, vcpu, dev->kvm) |
| 1736 | kvm_clear_async_pf_completion_queue(vcpu); |
| 1737 | break; |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1738 | case KVM_DEV_FLIC_ADAPTER_REGISTER: |
| 1739 | r = register_io_adapter(dev, attr); |
| 1740 | break; |
| 1741 | case KVM_DEV_FLIC_ADAPTER_MODIFY: |
| 1742 | r = modify_io_adapter(dev, attr); |
| 1743 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1744 | default: |
| 1745 | r = -EINVAL; |
| 1746 | } |
| 1747 | |
| 1748 | return r; |
| 1749 | } |
| 1750 | |
| 1751 | static int flic_create(struct kvm_device *dev, u32 type) |
| 1752 | { |
| 1753 | if (!dev) |
| 1754 | return -EINVAL; |
| 1755 | if (dev->kvm->arch.flic) |
| 1756 | return -EINVAL; |
| 1757 | dev->kvm->arch.flic = dev; |
| 1758 | return 0; |
| 1759 | } |
| 1760 | |
| 1761 | static void flic_destroy(struct kvm_device *dev) |
| 1762 | { |
| 1763 | dev->kvm->arch.flic = NULL; |
| 1764 | kfree(dev); |
| 1765 | } |
| 1766 | |
| 1767 | /* s390 floating irq controller (flic) */ |
| 1768 | struct kvm_device_ops kvm_flic_ops = { |
| 1769 | .name = "kvm-flic", |
| 1770 | .get_attr = flic_get_attr, |
| 1771 | .set_attr = flic_set_attr, |
| 1772 | .create = flic_create, |
| 1773 | .destroy = flic_destroy, |
| 1774 | }; |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1775 | |
| 1776 | static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) |
| 1777 | { |
| 1778 | unsigned long bit; |
| 1779 | |
| 1780 | bit = bit_nr + (addr % PAGE_SIZE) * 8; |
| 1781 | |
| 1782 | return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; |
| 1783 | } |
| 1784 | |
| 1785 | static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, |
| 1786 | u64 addr) |
| 1787 | { |
| 1788 | struct s390_map_info *map; |
| 1789 | |
| 1790 | if (!adapter) |
| 1791 | return NULL; |
| 1792 | |
| 1793 | list_for_each_entry(map, &adapter->maps, list) { |
| 1794 | if (map->guest_addr == addr) |
| 1795 | return map; |
| 1796 | } |
| 1797 | return NULL; |
| 1798 | } |
| 1799 | |
| 1800 | static int adapter_indicators_set(struct kvm *kvm, |
| 1801 | struct s390_io_adapter *adapter, |
| 1802 | struct kvm_s390_adapter_int *adapter_int) |
| 1803 | { |
| 1804 | unsigned long bit; |
| 1805 | int summary_set, idx; |
| 1806 | struct s390_map_info *info; |
| 1807 | void *map; |
| 1808 | |
| 1809 | info = get_map_info(adapter, adapter_int->ind_addr); |
| 1810 | if (!info) |
| 1811 | return -1; |
| 1812 | map = page_address(info->page); |
| 1813 | bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); |
| 1814 | set_bit(bit, map); |
| 1815 | idx = srcu_read_lock(&kvm->srcu); |
| 1816 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1817 | set_page_dirty_lock(info->page); |
| 1818 | info = get_map_info(adapter, adapter_int->summary_addr); |
| 1819 | if (!info) { |
| 1820 | srcu_read_unlock(&kvm->srcu, idx); |
| 1821 | return -1; |
| 1822 | } |
| 1823 | map = page_address(info->page); |
| 1824 | bit = get_ind_bit(info->addr, adapter_int->summary_offset, |
| 1825 | adapter->swap); |
| 1826 | summary_set = test_and_set_bit(bit, map); |
| 1827 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1828 | set_page_dirty_lock(info->page); |
| 1829 | srcu_read_unlock(&kvm->srcu, idx); |
| 1830 | return summary_set ? 0 : 1; |
| 1831 | } |
| 1832 | |
| 1833 | /* |
| 1834 | * < 0 - not injected due to error |
| 1835 | * = 0 - coalesced, summary indicator already active |
| 1836 | * > 0 - injected interrupt |
| 1837 | */ |
| 1838 | static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, |
| 1839 | struct kvm *kvm, int irq_source_id, int level, |
| 1840 | bool line_status) |
| 1841 | { |
| 1842 | int ret; |
| 1843 | struct s390_io_adapter *adapter; |
| 1844 | |
| 1845 | /* We're only interested in the 0->1 transition. */ |
| 1846 | if (!level) |
| 1847 | return 0; |
| 1848 | adapter = get_io_adapter(kvm, e->adapter.adapter_id); |
| 1849 | if (!adapter) |
| 1850 | return -1; |
| 1851 | down_read(&adapter->maps_lock); |
| 1852 | ret = adapter_indicators_set(kvm, adapter, &e->adapter); |
| 1853 | up_read(&adapter->maps_lock); |
| 1854 | if ((ret > 0) && !adapter->masked) { |
| 1855 | struct kvm_s390_interrupt s390int = { |
| 1856 | .type = KVM_S390_INT_IO(1, 0, 0, 0), |
| 1857 | .parm = 0, |
| 1858 | .parm64 = (adapter->isc << 27) | 0x80000000, |
| 1859 | }; |
| 1860 | ret = kvm_s390_inject_vm(kvm, &s390int); |
| 1861 | if (ret == 0) |
| 1862 | ret = 1; |
| 1863 | } |
| 1864 | return ret; |
| 1865 | } |
| 1866 | |
Paul Mackerras | 8ba918d | 2014-06-30 20:51:10 +1000 | [diff] [blame] | 1867 | int kvm_set_routing_entry(struct kvm_kernel_irq_routing_entry *e, |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1868 | const struct kvm_irq_routing_entry *ue) |
| 1869 | { |
| 1870 | int ret; |
| 1871 | |
| 1872 | switch (ue->type) { |
| 1873 | case KVM_IRQ_ROUTING_S390_ADAPTER: |
| 1874 | e->set = set_adapter_int; |
| 1875 | e->adapter.summary_addr = ue->u.adapter.summary_addr; |
| 1876 | e->adapter.ind_addr = ue->u.adapter.ind_addr; |
| 1877 | e->adapter.summary_offset = ue->u.adapter.summary_offset; |
| 1878 | e->adapter.ind_offset = ue->u.adapter.ind_offset; |
| 1879 | e->adapter.adapter_id = ue->u.adapter.adapter_id; |
| 1880 | ret = 0; |
| 1881 | break; |
| 1882 | default: |
| 1883 | ret = -EINVAL; |
| 1884 | } |
| 1885 | |
| 1886 | return ret; |
| 1887 | } |
| 1888 | |
| 1889 | int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, |
| 1890 | int irq_source_id, int level, bool line_status) |
| 1891 | { |
| 1892 | return -EINVAL; |
| 1893 | } |