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