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