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