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