Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling kvm guest interrupts |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 3 | * |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008,2014 |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License (version 2 only) |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 11 | */ |
| 12 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 13 | #include <linux/interrupt.h> |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 14 | #include <linux/kvm_host.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 15 | #include <linux/hrtimer.h> |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 16 | #include <linux/mmu_context.h> |
Christian Borntraeger | 3cd6129 | 2008-07-25 15:51:54 +0200 | [diff] [blame] | 17 | #include <linux/signal.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Heiko Carstens | cbb870c | 2010-02-26 22:37:43 +0100 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
| 20 | #include <asm/uaccess.h> |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 21 | #include "kvm-s390.h" |
| 22 | #include "gaccess.h" |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 23 | #include "trace-s390.h" |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 24 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 25 | #define IOINT_SCHID_MASK 0x0000ffff |
| 26 | #define IOINT_SSID_MASK 0x00030000 |
| 27 | #define IOINT_CSSID_MASK 0x03fc0000 |
| 28 | #define IOINT_AI_MASK 0x04000000 |
| 29 | |
| 30 | static int is_ioint(u64 type) |
| 31 | { |
| 32 | return ((type & 0xfffe0000u) != 0xfffe0000u); |
| 33 | } |
| 34 | |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 35 | int psw_extint_disabled(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 36 | { |
| 37 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT); |
| 38 | } |
| 39 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 40 | static int psw_ioint_disabled(struct kvm_vcpu *vcpu) |
| 41 | { |
| 42 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO); |
| 43 | } |
| 44 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 45 | static int psw_mchk_disabled(struct kvm_vcpu *vcpu) |
| 46 | { |
| 47 | return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK); |
| 48 | } |
| 49 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 50 | static int psw_interrupts_disabled(struct kvm_vcpu *vcpu) |
| 51 | { |
| 52 | if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER) || |
| 53 | (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO) || |
| 54 | (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT)) |
| 55 | return 0; |
| 56 | return 1; |
| 57 | } |
| 58 | |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 59 | static u64 int_word_to_isc_bits(u32 int_word) |
| 60 | { |
| 61 | u8 isc = (int_word & 0x38000000) >> 27; |
| 62 | |
| 63 | return (0x80 >> isc) << 24; |
| 64 | } |
| 65 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 66 | static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu, |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 67 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 68 | { |
| 69 | switch (inti->type) { |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 70 | case KVM_S390_INT_EXTERNAL_CALL: |
| 71 | if (psw_extint_disabled(vcpu)) |
| 72 | return 0; |
| 73 | if (vcpu->arch.sie_block->gcr[0] & 0x2000ul) |
| 74 | return 1; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 75 | case KVM_S390_INT_EMERGENCY: |
| 76 | if (psw_extint_disabled(vcpu)) |
| 77 | return 0; |
| 78 | if (vcpu->arch.sie_block->gcr[0] & 0x4000ul) |
| 79 | return 1; |
| 80 | return 0; |
| 81 | case KVM_S390_INT_SERVICE: |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 82 | case KVM_S390_INT_PFAULT_INIT: |
| 83 | case KVM_S390_INT_PFAULT_DONE: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 84 | case KVM_S390_INT_VIRTIO: |
| 85 | if (psw_extint_disabled(vcpu)) |
| 86 | return 0; |
| 87 | if (vcpu->arch.sie_block->gcr[0] & 0x200ul) |
| 88 | return 1; |
| 89 | return 0; |
| 90 | case KVM_S390_PROGRAM_INT: |
| 91 | case KVM_S390_SIGP_STOP: |
| 92 | case KVM_S390_SIGP_SET_PREFIX: |
| 93 | case KVM_S390_RESTART: |
| 94 | return 1; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 95 | case KVM_S390_MCHK: |
| 96 | if (psw_mchk_disabled(vcpu)) |
| 97 | return 0; |
| 98 | if (vcpu->arch.sie_block->gcr[14] & inti->mchk.cr14) |
| 99 | return 1; |
| 100 | return 0; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 101 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 102 | if (psw_ioint_disabled(vcpu)) |
| 103 | return 0; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 104 | if (vcpu->arch.sie_block->gcr[6] & |
| 105 | int_word_to_isc_bits(inti->io.io_int_word)) |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 106 | return 1; |
| 107 | return 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 108 | default: |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 109 | printk(KERN_WARNING "illegal interrupt type %llx\n", |
| 110 | inti->type); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 111 | BUG(); |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static void __set_cpu_idle(struct kvm_vcpu *vcpu) |
| 117 | { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 118 | atomic_set_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
| 119 | set_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 120 | } |
| 121 | |
| 122 | static void __unset_cpu_idle(struct kvm_vcpu *vcpu) |
| 123 | { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 124 | atomic_clear_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags); |
| 125 | clear_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask); |
| 126 | } |
| 127 | |
| 128 | static void __reset_intercept_indicators(struct kvm_vcpu *vcpu) |
| 129 | { |
| 130 | atomic_clear_mask(CPUSTAT_ECALL_PEND | |
| 131 | CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT, |
| 132 | &vcpu->arch.sie_block->cpuflags); |
| 133 | vcpu->arch.sie_block->lctl = 0x0000; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 134 | vcpu->arch.sie_block->ictl &= ~ICTL_LPSW; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag) |
| 138 | { |
| 139 | atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags); |
| 140 | } |
| 141 | |
| 142 | static void __set_intercept_indicator(struct kvm_vcpu *vcpu, |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 143 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 144 | { |
| 145 | switch (inti->type) { |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 146 | case KVM_S390_INT_EXTERNAL_CALL: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 147 | case KVM_S390_INT_EMERGENCY: |
| 148 | case KVM_S390_INT_SERVICE: |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 149 | case KVM_S390_INT_PFAULT_INIT: |
| 150 | case KVM_S390_INT_PFAULT_DONE: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 151 | case KVM_S390_INT_VIRTIO: |
| 152 | if (psw_extint_disabled(vcpu)) |
| 153 | __set_cpuflag(vcpu, CPUSTAT_EXT_INT); |
| 154 | else |
| 155 | vcpu->arch.sie_block->lctl |= LCTL_CR0; |
| 156 | break; |
| 157 | case KVM_S390_SIGP_STOP: |
| 158 | __set_cpuflag(vcpu, CPUSTAT_STOP_INT); |
| 159 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 160 | case KVM_S390_MCHK: |
| 161 | if (psw_mchk_disabled(vcpu)) |
| 162 | vcpu->arch.sie_block->ictl |= ICTL_LPSW; |
| 163 | else |
| 164 | vcpu->arch.sie_block->lctl |= LCTL_CR14; |
| 165 | break; |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 166 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 167 | if (psw_ioint_disabled(vcpu)) |
| 168 | __set_cpuflag(vcpu, CPUSTAT_IO_INT); |
| 169 | else |
| 170 | vcpu->arch.sie_block->lctl |= LCTL_CR6; |
| 171 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 172 | default: |
| 173 | BUG(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | static void __do_deliver_interrupt(struct kvm_vcpu *vcpu, |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 178 | struct kvm_s390_interrupt_info *inti) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 179 | { |
| 180 | const unsigned short table[] = { 2, 4, 4, 6 }; |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 181 | int rc = 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 182 | |
| 183 | switch (inti->type) { |
| 184 | case KVM_S390_INT_EMERGENCY: |
| 185 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp emerg"); |
| 186 | vcpu->stat.deliver_emergency_signal++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 187 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 188 | inti->emerg.code, 0); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 189 | rc = put_guest_lc(vcpu, 0x1201, (u16 *)__LC_EXT_INT_CODE); |
| 190 | rc |= put_guest_lc(vcpu, inti->emerg.code, |
| 191 | (u16 *)__LC_EXT_CPU_ADDR); |
| 192 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 193 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 194 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 195 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 196 | break; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 197 | case KVM_S390_INT_EXTERNAL_CALL: |
| 198 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call"); |
| 199 | vcpu->stat.deliver_external_call++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 200 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 201 | inti->extcall.code, 0); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 202 | rc = put_guest_lc(vcpu, 0x1202, (u16 *)__LC_EXT_INT_CODE); |
| 203 | rc |= put_guest_lc(vcpu, inti->extcall.code, |
| 204 | (u16 *)__LC_EXT_CPU_ADDR); |
| 205 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 206 | &vcpu->arch.sie_block->gpsw, |
| 207 | sizeof(psw_t)); |
| 208 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 209 | &vcpu->arch.sie_block->gpsw, |
| 210 | sizeof(psw_t)); |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 211 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 212 | case KVM_S390_INT_SERVICE: |
| 213 | VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x", |
| 214 | inti->ext.ext_params); |
| 215 | vcpu->stat.deliver_service_signal++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 216 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 217 | inti->ext.ext_params, 0); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 218 | rc = put_guest_lc(vcpu, 0x2401, (u16 *)__LC_EXT_INT_CODE); |
| 219 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 220 | &vcpu->arch.sie_block->gpsw, |
| 221 | sizeof(psw_t)); |
| 222 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 223 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 224 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 225 | (u32 *)__LC_EXT_PARAMS); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 226 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 227 | case KVM_S390_INT_PFAULT_INIT: |
| 228 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, 0, |
| 229 | inti->ext.ext_params2); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 230 | rc = put_guest_lc(vcpu, 0x2603, (u16 *) __LC_EXT_INT_CODE); |
| 231 | rc |= put_guest_lc(vcpu, 0x0600, (u16 *) __LC_EXT_CPU_ADDR); |
| 232 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 233 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 234 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 235 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 236 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 237 | (u64 *) __LC_EXT_PARAMS2); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 238 | break; |
| 239 | case KVM_S390_INT_PFAULT_DONE: |
| 240 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, 0, |
| 241 | inti->ext.ext_params2); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 242 | rc = put_guest_lc(vcpu, 0x2603, (u16 *)__LC_EXT_INT_CODE); |
| 243 | rc |= put_guest_lc(vcpu, 0x0680, (u16 *)__LC_EXT_CPU_ADDR); |
| 244 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 245 | &vcpu->arch.sie_block->gpsw, |
| 246 | sizeof(psw_t)); |
| 247 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 248 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 249 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 250 | (u64 *)__LC_EXT_PARAMS2); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 251 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 252 | case KVM_S390_INT_VIRTIO: |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 253 | VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx", |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 254 | inti->ext.ext_params, inti->ext.ext_params2); |
| 255 | vcpu->stat.deliver_virtio_interrupt++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 256 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 257 | inti->ext.ext_params, |
| 258 | inti->ext.ext_params2); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 259 | rc = put_guest_lc(vcpu, 0x2603, (u16 *)__LC_EXT_INT_CODE); |
| 260 | rc |= put_guest_lc(vcpu, 0x0d00, (u16 *)__LC_EXT_CPU_ADDR); |
| 261 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 262 | &vcpu->arch.sie_block->gpsw, |
| 263 | sizeof(psw_t)); |
| 264 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 265 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 266 | rc |= put_guest_lc(vcpu, inti->ext.ext_params, |
| 267 | (u32 *)__LC_EXT_PARAMS); |
| 268 | rc |= put_guest_lc(vcpu, inti->ext.ext_params2, |
| 269 | (u64 *)__LC_EXT_PARAMS2); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 270 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 271 | case KVM_S390_SIGP_STOP: |
| 272 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu stop"); |
| 273 | vcpu->stat.deliver_stop_signal++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 274 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 275 | 0, 0); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 276 | __set_intercept_indicator(vcpu, inti); |
| 277 | break; |
| 278 | |
| 279 | case KVM_S390_SIGP_SET_PREFIX: |
| 280 | VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x", |
| 281 | inti->prefix.address); |
| 282 | vcpu->stat.deliver_prefix_signal++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 283 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 284 | inti->prefix.address, 0); |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 285 | kvm_s390_set_prefix(vcpu, inti->prefix.address); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 286 | break; |
| 287 | |
| 288 | case KVM_S390_RESTART: |
| 289 | VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart"); |
| 290 | vcpu->stat.deliver_restart_signal++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 291 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 292 | 0, 0); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 293 | rc = write_guest_lc(vcpu, |
| 294 | offsetof(struct _lowcore, restart_old_psw), |
| 295 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 296 | rc |= read_guest_lc(vcpu, offsetof(struct _lowcore, restart_psw), |
| 297 | &vcpu->arch.sie_block->gpsw, |
| 298 | sizeof(psw_t)); |
Cornelia Huck | 9e6dabe | 2011-11-17 11:00:41 +0100 | [diff] [blame] | 299 | atomic_clear_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 300 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 301 | case KVM_S390_PROGRAM_INT: |
| 302 | VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x", |
| 303 | inti->pgm.code, |
| 304 | table[vcpu->arch.sie_block->ipa >> 14]); |
| 305 | vcpu->stat.deliver_program_int++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 306 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 307 | inti->pgm.code, 0); |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 308 | rc = put_guest_lc(vcpu, inti->pgm.code, |
| 309 | (u16 __user *)__LC_PGM_INT_CODE); |
| 310 | rc |= put_guest_lc(vcpu, table[vcpu->arch.sie_block->ipa >> 14], |
| 311 | (u16 __user *)__LC_PGM_ILC); |
| 312 | rc |= write_guest_lc(vcpu, __LC_PGM_OLD_PSW, |
| 313 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 314 | rc |= read_guest_lc(vcpu, __LC_PGM_NEW_PSW, |
| 315 | &vcpu->arch.sie_block->gpsw, |
| 316 | sizeof(psw_t)); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 317 | break; |
| 318 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 319 | case KVM_S390_MCHK: |
| 320 | VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx", |
| 321 | inti->mchk.mcic); |
| 322 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 323 | inti->mchk.cr14, |
| 324 | inti->mchk.mcic); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 325 | rc = kvm_s390_vcpu_store_status(vcpu, |
| 326 | KVM_S390_STORE_STATUS_PREFIXED); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 327 | rc |= put_guest_lc(vcpu, inti->mchk.mcic, (u64 *)__LC_MCCK_CODE); |
| 328 | rc |= write_guest_lc(vcpu, __LC_MCK_OLD_PSW, |
| 329 | &vcpu->arch.sie_block->gpsw, |
| 330 | sizeof(psw_t)); |
| 331 | rc |= read_guest_lc(vcpu, __LC_MCK_NEW_PSW, |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 332 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 333 | break; |
| 334 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 335 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 336 | { |
| 337 | __u32 param0 = ((__u32)inti->io.subchannel_id << 16) | |
| 338 | inti->io.subchannel_nr; |
| 339 | __u64 param1 = ((__u64)inti->io.io_int_parm << 32) | |
| 340 | inti->io.io_int_word; |
| 341 | VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type); |
| 342 | vcpu->stat.deliver_io_int++; |
| 343 | trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type, |
| 344 | param0, param1); |
Heiko Carstens | 7988276 | 2014-01-02 10:59:41 +0100 | [diff] [blame] | 345 | rc = put_guest_lc(vcpu, inti->io.subchannel_id, |
| 346 | (u16 *)__LC_SUBCHANNEL_ID); |
| 347 | rc |= put_guest_lc(vcpu, inti->io.subchannel_nr, |
| 348 | (u16 *)__LC_SUBCHANNEL_NR); |
| 349 | rc |= put_guest_lc(vcpu, inti->io.io_int_parm, |
| 350 | (u32 *)__LC_IO_INT_PARM); |
| 351 | rc |= put_guest_lc(vcpu, inti->io.io_int_word, |
| 352 | (u32 *)__LC_IO_INT_WORD); |
| 353 | rc |= write_guest_lc(vcpu, __LC_IO_OLD_PSW, |
| 354 | &vcpu->arch.sie_block->gpsw, |
| 355 | sizeof(psw_t)); |
| 356 | rc |= read_guest_lc(vcpu, __LC_IO_NEW_PSW, |
| 357 | &vcpu->arch.sie_block->gpsw, |
| 358 | sizeof(psw_t)); |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 359 | break; |
| 360 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 361 | default: |
| 362 | BUG(); |
| 363 | } |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 364 | if (rc) { |
Christian Borntraeger | 3cd6129 | 2008-07-25 15:51:54 +0200 | [diff] [blame] | 365 | printk("kvm: The guest lowcore is not mapped during interrupt " |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 366 | "delivery, killing userspace\n"); |
Christian Borntraeger | 3cd6129 | 2008-07-25 15:51:54 +0200 | [diff] [blame] | 367 | do_exit(SIGKILL); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
| 371 | static int __try_deliver_ckc_interrupt(struct kvm_vcpu *vcpu) |
| 372 | { |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 373 | int rc; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 374 | |
| 375 | if (psw_extint_disabled(vcpu)) |
| 376 | return 0; |
| 377 | if (!(vcpu->arch.sie_block->gcr[0] & 0x800ul)) |
| 378 | return 0; |
Jens Freimann | 1a03b76 | 2014-02-12 14:05:38 +0100 | [diff] [blame^] | 379 | rc = put_guest_lc(vcpu, 0x1004, (u16 __user *)__LC_EXT_INT_CODE); |
| 380 | rc |= write_guest_lc(vcpu, __LC_EXT_OLD_PSW, |
| 381 | &vcpu->arch.sie_block->gpsw, sizeof(psw_t)); |
| 382 | rc |= read_guest_lc(vcpu, __LC_EXT_NEW_PSW, |
| 383 | &vcpu->arch.sie_block->gpsw, |
| 384 | sizeof(psw_t)); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 385 | if (rc) { |
Christian Borntraeger | 3cd6129 | 2008-07-25 15:51:54 +0200 | [diff] [blame] | 386 | printk("kvm: The guest lowcore is not mapped during interrupt " |
| 387 | "delivery, killing userspace\n"); |
| 388 | do_exit(SIGKILL); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 389 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 390 | return 1; |
| 391 | } |
| 392 | |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 393 | int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 394 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 395 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 396 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 397 | struct kvm_s390_interrupt_info *inti; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 398 | int rc = 0; |
| 399 | |
| 400 | if (atomic_read(&li->active)) { |
| 401 | spin_lock_bh(&li->lock); |
| 402 | list_for_each_entry(inti, &li->list, list) |
| 403 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 404 | rc = 1; |
| 405 | break; |
| 406 | } |
| 407 | spin_unlock_bh(&li->lock); |
| 408 | } |
| 409 | |
| 410 | if ((!rc) && atomic_read(&fi->active)) { |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 411 | spin_lock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 412 | list_for_each_entry(inti, &fi->list, list) |
| 413 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 414 | rc = 1; |
| 415 | break; |
| 416 | } |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 417 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | if ((!rc) && (vcpu->arch.sie_block->ckc < |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 421 | get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) { |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 422 | if ((!psw_extint_disabled(vcpu)) && |
| 423 | (vcpu->arch.sie_block->gcr[0] & 0x800ul)) |
| 424 | rc = 1; |
| 425 | } |
| 426 | |
| 427 | return rc; |
| 428 | } |
| 429 | |
Marcelo Tosatti | 3d80840 | 2008-04-11 14:53:26 -0300 | [diff] [blame] | 430 | int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) |
| 431 | { |
| 432 | return 0; |
| 433 | } |
| 434 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 435 | int kvm_s390_handle_wait(struct kvm_vcpu *vcpu) |
| 436 | { |
| 437 | u64 now, sltime; |
| 438 | DECLARE_WAITQUEUE(wait, current); |
| 439 | |
| 440 | vcpu->stat.exit_wait_state++; |
| 441 | if (kvm_cpu_has_interrupt(vcpu)) |
| 442 | return 0; |
| 443 | |
Carsten Otte | e52b2af | 2008-05-21 13:37:44 +0200 | [diff] [blame] | 444 | __set_cpu_idle(vcpu); |
| 445 | spin_lock_bh(&vcpu->arch.local_int.lock); |
| 446 | vcpu->arch.local_int.timer_due = 0; |
| 447 | spin_unlock_bh(&vcpu->arch.local_int.lock); |
| 448 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 449 | if (psw_interrupts_disabled(vcpu)) { |
| 450 | VCPU_EVENT(vcpu, 3, "%s", "disabled wait"); |
| 451 | __unset_cpu_idle(vcpu); |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 452 | return -EOPNOTSUPP; /* disabled wait */ |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | if (psw_extint_disabled(vcpu) || |
| 456 | (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))) { |
| 457 | VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer"); |
| 458 | goto no_timer; |
| 459 | } |
| 460 | |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 461 | now = get_tod_clock_fast() + vcpu->arch.sie_block->epoch; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 462 | if (vcpu->arch.sie_block->ckc < now) { |
| 463 | __unset_cpu_idle(vcpu); |
| 464 | return 0; |
| 465 | } |
| 466 | |
Heiko Carstens | ed4f209 | 2013-01-14 16:55:55 +0100 | [diff] [blame] | 467 | sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 468 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 469 | hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL); |
| 470 | VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 471 | no_timer: |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 472 | srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 473 | spin_lock(&vcpu->arch.local_int.float_int->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 474 | spin_lock_bh(&vcpu->arch.local_int.lock); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 475 | add_wait_queue(&vcpu->wq, &wait); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 476 | while (list_empty(&vcpu->arch.local_int.list) && |
| 477 | list_empty(&vcpu->arch.local_int.float_int->list) && |
| 478 | (!vcpu->arch.local_int.timer_due) && |
| 479 | !signal_pending(current)) { |
| 480 | set_current_state(TASK_INTERRUPTIBLE); |
| 481 | spin_unlock_bh(&vcpu->arch.local_int.lock); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 482 | spin_unlock(&vcpu->arch.local_int.float_int->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 483 | schedule(); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 484 | spin_lock(&vcpu->arch.local_int.float_int->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 485 | spin_lock_bh(&vcpu->arch.local_int.lock); |
| 486 | } |
| 487 | __unset_cpu_idle(vcpu); |
| 488 | __set_current_state(TASK_RUNNING); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 489 | remove_wait_queue(&vcpu->wq, &wait); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 490 | spin_unlock_bh(&vcpu->arch.local_int.lock); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 491 | spin_unlock(&vcpu->arch.local_int.float_int->lock); |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 492 | vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); |
| 493 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 494 | hrtimer_try_to_cancel(&vcpu->arch.ckc_timer); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 498 | void kvm_s390_tasklet(unsigned long parm) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 499 | { |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 500 | struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 501 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 502 | spin_lock(&vcpu->arch.local_int.lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 503 | vcpu->arch.local_int.timer_due = 1; |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 504 | if (waitqueue_active(&vcpu->wq)) |
| 505 | wake_up_interruptible(&vcpu->wq); |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 506 | spin_unlock(&vcpu->arch.local_int.lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 509 | /* |
| 510 | * low level hrtimer wake routine. Because this runs in hardirq context |
| 511 | * we schedule a tasklet to do the real work. |
| 512 | */ |
| 513 | enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer) |
| 514 | { |
| 515 | struct kvm_vcpu *vcpu; |
| 516 | |
| 517 | vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer); |
Michael Mueller | 9cac38d | 2014-02-26 16:14:19 +0100 | [diff] [blame] | 518 | vcpu->preempted = true; |
Christian Borntraeger | ca87230 | 2009-05-12 17:21:49 +0200 | [diff] [blame] | 519 | tasklet_schedule(&vcpu->arch.tasklet); |
| 520 | |
| 521 | return HRTIMER_NORESTART; |
| 522 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 523 | |
Jens Freimann | 2ed10cc | 2014-02-11 13:48:07 +0100 | [diff] [blame] | 524 | void kvm_s390_clear_local_irqs(struct kvm_vcpu *vcpu) |
| 525 | { |
| 526 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 527 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
| 528 | |
| 529 | spin_lock_bh(&li->lock); |
| 530 | list_for_each_entry_safe(inti, n, &li->list, list) { |
| 531 | list_del(&inti->list); |
| 532 | kfree(inti); |
| 533 | } |
| 534 | atomic_set(&li->active, 0); |
| 535 | spin_unlock_bh(&li->lock); |
| 536 | } |
| 537 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 538 | void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) |
| 539 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 540 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 541 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 542 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 543 | int deliver; |
| 544 | |
| 545 | __reset_intercept_indicators(vcpu); |
| 546 | if (atomic_read(&li->active)) { |
| 547 | do { |
| 548 | deliver = 0; |
| 549 | spin_lock_bh(&li->lock); |
| 550 | list_for_each_entry_safe(inti, n, &li->list, list) { |
| 551 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 552 | list_del(&inti->list); |
| 553 | deliver = 1; |
| 554 | break; |
| 555 | } |
| 556 | __set_intercept_indicator(vcpu, inti); |
| 557 | } |
| 558 | if (list_empty(&li->list)) |
| 559 | atomic_set(&li->active, 0); |
| 560 | spin_unlock_bh(&li->lock); |
| 561 | if (deliver) { |
| 562 | __do_deliver_interrupt(vcpu, inti); |
| 563 | kfree(inti); |
| 564 | } |
| 565 | } while (deliver); |
| 566 | } |
| 567 | |
| 568 | if ((vcpu->arch.sie_block->ckc < |
Martin Schwidefsky | 8c071b0 | 2013-10-17 12:38:17 +0200 | [diff] [blame] | 569 | get_tod_clock_fast() + vcpu->arch.sie_block->epoch)) |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 570 | __try_deliver_ckc_interrupt(vcpu); |
| 571 | |
| 572 | if (atomic_read(&fi->active)) { |
| 573 | do { |
| 574 | deliver = 0; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 575 | spin_lock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 576 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 577 | if (__interrupt_is_deliverable(vcpu, inti)) { |
| 578 | list_del(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 579 | fi->irq_count--; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 580 | deliver = 1; |
| 581 | break; |
| 582 | } |
| 583 | __set_intercept_indicator(vcpu, inti); |
| 584 | } |
| 585 | if (list_empty(&fi->list)) |
| 586 | atomic_set(&fi->active, 0); |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 587 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 588 | if (deliver) { |
| 589 | __do_deliver_interrupt(vcpu, inti); |
| 590 | kfree(inti); |
| 591 | } |
| 592 | } while (deliver); |
| 593 | } |
| 594 | } |
| 595 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 596 | void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu) |
| 597 | { |
| 598 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 599 | struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int; |
| 600 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
| 601 | int deliver; |
| 602 | |
| 603 | __reset_intercept_indicators(vcpu); |
| 604 | if (atomic_read(&li->active)) { |
| 605 | do { |
| 606 | deliver = 0; |
| 607 | spin_lock_bh(&li->lock); |
| 608 | list_for_each_entry_safe(inti, n, &li->list, list) { |
| 609 | if ((inti->type == KVM_S390_MCHK) && |
| 610 | __interrupt_is_deliverable(vcpu, inti)) { |
| 611 | list_del(&inti->list); |
| 612 | deliver = 1; |
| 613 | break; |
| 614 | } |
| 615 | __set_intercept_indicator(vcpu, inti); |
| 616 | } |
| 617 | if (list_empty(&li->list)) |
| 618 | atomic_set(&li->active, 0); |
| 619 | spin_unlock_bh(&li->lock); |
| 620 | if (deliver) { |
| 621 | __do_deliver_interrupt(vcpu, inti); |
| 622 | kfree(inti); |
| 623 | } |
| 624 | } while (deliver); |
| 625 | } |
| 626 | |
| 627 | if (atomic_read(&fi->active)) { |
| 628 | do { |
| 629 | deliver = 0; |
| 630 | spin_lock(&fi->lock); |
| 631 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 632 | if ((inti->type == KVM_S390_MCHK) && |
| 633 | __interrupt_is_deliverable(vcpu, inti)) { |
| 634 | list_del(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 635 | fi->irq_count--; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 636 | deliver = 1; |
| 637 | break; |
| 638 | } |
| 639 | __set_intercept_indicator(vcpu, inti); |
| 640 | } |
| 641 | if (list_empty(&fi->list)) |
| 642 | atomic_set(&fi->active, 0); |
| 643 | spin_unlock(&fi->lock); |
| 644 | if (deliver) { |
| 645 | __do_deliver_interrupt(vcpu, inti); |
| 646 | kfree(inti); |
| 647 | } |
| 648 | } while (deliver); |
| 649 | } |
| 650 | } |
| 651 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 652 | int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code) |
| 653 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 654 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 655 | struct kvm_s390_interrupt_info *inti; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 656 | |
| 657 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 658 | if (!inti) |
| 659 | return -ENOMEM; |
| 660 | |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 661 | inti->type = KVM_S390_PROGRAM_INT; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 662 | inti->pgm.code = code; |
| 663 | |
| 664 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code); |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 665 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, inti->type, code, 0, 1); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 666 | spin_lock_bh(&li->lock); |
| 667 | list_add(&inti->list, &li->list); |
| 668 | atomic_set(&li->active, 1); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 669 | BUG_ON(waitqueue_active(li->wq)); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 670 | spin_unlock_bh(&li->lock); |
| 671 | return 0; |
| 672 | } |
| 673 | |
Jens Freimann | bcd8468 | 2014-02-11 11:07:05 +0100 | [diff] [blame] | 674 | int kvm_s390_inject_prog_irq(struct kvm_vcpu *vcpu, |
| 675 | struct kvm_s390_pgm_info *pgm_info) |
| 676 | { |
| 677 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 678 | struct kvm_s390_interrupt_info *inti; |
| 679 | |
| 680 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 681 | if (!inti) |
| 682 | return -ENOMEM; |
| 683 | |
| 684 | VCPU_EVENT(vcpu, 3, "inject: prog irq %d (from kernel)", |
| 685 | pgm_info->code); |
| 686 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, KVM_S390_PROGRAM_INT, |
| 687 | pgm_info->code, 0, 1); |
| 688 | |
| 689 | inti->type = KVM_S390_PROGRAM_INT; |
| 690 | memcpy(&inti->pgm, pgm_info, sizeof(inti->pgm)); |
| 691 | spin_lock_bh(&li->lock); |
| 692 | list_add(&inti->list, &li->list); |
| 693 | atomic_set(&li->active, 1); |
| 694 | BUG_ON(waitqueue_active(li->wq)); |
| 695 | spin_unlock_bh(&li->lock); |
| 696 | return 0; |
| 697 | } |
| 698 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 699 | struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm, |
| 700 | u64 cr6, u64 schid) |
| 701 | { |
| 702 | struct kvm_s390_float_interrupt *fi; |
| 703 | struct kvm_s390_interrupt_info *inti, *iter; |
| 704 | |
| 705 | if ((!schid && !cr6) || (schid && cr6)) |
| 706 | return NULL; |
| 707 | mutex_lock(&kvm->lock); |
| 708 | fi = &kvm->arch.float_int; |
| 709 | spin_lock(&fi->lock); |
| 710 | inti = NULL; |
| 711 | list_for_each_entry(iter, &fi->list, list) { |
| 712 | if (!is_ioint(iter->type)) |
| 713 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 714 | if (cr6 && |
| 715 | ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0)) |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 716 | continue; |
| 717 | if (schid) { |
| 718 | if (((schid & 0x00000000ffff0000) >> 16) != |
| 719 | iter->io.subchannel_id) |
| 720 | continue; |
| 721 | if ((schid & 0x000000000000ffff) != |
| 722 | iter->io.subchannel_nr) |
| 723 | continue; |
| 724 | } |
| 725 | inti = iter; |
| 726 | break; |
| 727 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 728 | if (inti) { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 729 | list_del_init(&inti->list); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 730 | fi->irq_count--; |
| 731 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 732 | if (list_empty(&fi->list)) |
| 733 | atomic_set(&fi->active, 0); |
| 734 | spin_unlock(&fi->lock); |
| 735 | mutex_unlock(&kvm->lock); |
| 736 | return inti; |
| 737 | } |
| 738 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 739 | 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] | 740 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 741 | struct kvm_s390_local_interrupt *li; |
| 742 | struct kvm_s390_float_interrupt *fi; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 743 | struct kvm_s390_interrupt_info *iter; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 744 | struct kvm_vcpu *dst_vcpu = NULL; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 745 | int sigcpu; |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 746 | int rc = 0; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 747 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 748 | mutex_lock(&kvm->lock); |
| 749 | fi = &kvm->arch.float_int; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 750 | spin_lock(&fi->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 751 | if (fi->irq_count >= KVM_S390_MAX_FLOAT_IRQS) { |
| 752 | rc = -EINVAL; |
| 753 | goto unlock_fi; |
| 754 | } |
| 755 | fi->irq_count++; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 756 | if (!is_ioint(inti->type)) { |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 757 | list_add_tail(&inti->list, &fi->list); |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 758 | } else { |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 759 | u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word); |
| 760 | |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 761 | /* Keep I/O interrupts sorted in isc order. */ |
| 762 | list_for_each_entry(iter, &fi->list, list) { |
| 763 | if (!is_ioint(iter->type)) |
| 764 | continue; |
Cornelia Huck | 79fd50c | 2013-02-07 13:20:52 +0100 | [diff] [blame] | 765 | if (int_word_to_isc_bits(iter->io.io_int_word) |
| 766 | <= isc_bits) |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 767 | continue; |
| 768 | break; |
| 769 | } |
| 770 | list_add_tail(&inti->list, &iter->list); |
| 771 | } |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 772 | atomic_set(&fi->active, 1); |
| 773 | sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); |
| 774 | if (sigcpu == KVM_MAX_VCPUS) { |
| 775 | do { |
| 776 | sigcpu = fi->next_rr_cpu++; |
| 777 | if (sigcpu == KVM_MAX_VCPUS) |
| 778 | sigcpu = fi->next_rr_cpu = 0; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 779 | } while (kvm_get_vcpu(kvm, sigcpu) == NULL); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 780 | } |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 781 | dst_vcpu = kvm_get_vcpu(kvm, sigcpu); |
| 782 | li = &dst_vcpu->arch.local_int; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 783 | spin_lock_bh(&li->lock); |
| 784 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 785 | if (waitqueue_active(li->wq)) |
| 786 | wake_up_interruptible(li->wq); |
Michael Mueller | 9cac38d | 2014-02-26 16:14:19 +0100 | [diff] [blame] | 787 | kvm_get_vcpu(kvm, sigcpu)->preempted = true; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 788 | spin_unlock_bh(&li->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 789 | unlock_fi: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 790 | spin_unlock(&fi->lock); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 791 | mutex_unlock(&kvm->lock); |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 792 | return rc; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | int kvm_s390_inject_vm(struct kvm *kvm, |
| 796 | struct kvm_s390_interrupt *s390int) |
| 797 | { |
| 798 | struct kvm_s390_interrupt_info *inti; |
| 799 | |
| 800 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 801 | if (!inti) |
| 802 | return -ENOMEM; |
| 803 | |
| 804 | inti->type = s390int->type; |
| 805 | switch (inti->type) { |
| 806 | case KVM_S390_INT_VIRTIO: |
| 807 | VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx", |
| 808 | s390int->parm, s390int->parm64); |
| 809 | inti->ext.ext_params = s390int->parm; |
| 810 | inti->ext.ext_params2 = s390int->parm64; |
| 811 | break; |
| 812 | case KVM_S390_INT_SERVICE: |
| 813 | VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm); |
| 814 | inti->ext.ext_params = s390int->parm; |
| 815 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 816 | case KVM_S390_INT_PFAULT_DONE: |
| 817 | inti->type = s390int->type; |
| 818 | inti->ext.ext_params2 = s390int->parm64; |
| 819 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 820 | case KVM_S390_MCHK: |
| 821 | VM_EVENT(kvm, 5, "inject: machine check parm64:%llx", |
| 822 | s390int->parm64); |
| 823 | inti->mchk.cr14 = s390int->parm; /* upper bits are not used */ |
| 824 | inti->mchk.mcic = s390int->parm64; |
| 825 | break; |
| 826 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 827 | if (inti->type & IOINT_AI_MASK) |
| 828 | VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)"); |
| 829 | else |
| 830 | VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x", |
| 831 | s390int->type & IOINT_CSSID_MASK, |
| 832 | s390int->type & IOINT_SSID_MASK, |
| 833 | s390int->type & IOINT_SCHID_MASK); |
| 834 | inti->io.subchannel_id = s390int->parm >> 16; |
| 835 | inti->io.subchannel_nr = s390int->parm & 0x0000ffffu; |
| 836 | inti->io.io_int_parm = s390int->parm64 >> 32; |
| 837 | inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull; |
| 838 | break; |
| 839 | default: |
| 840 | kfree(inti); |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64, |
| 844 | 2); |
| 845 | |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 846 | return __inject_vm(kvm, inti); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu, |
| 850 | struct kvm_s390_interrupt *s390int) |
| 851 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 852 | struct kvm_s390_local_interrupt *li; |
| 853 | struct kvm_s390_interrupt_info *inti; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 854 | |
| 855 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 856 | if (!inti) |
| 857 | return -ENOMEM; |
| 858 | |
| 859 | switch (s390int->type) { |
| 860 | case KVM_S390_PROGRAM_INT: |
| 861 | if (s390int->parm & 0xffff0000) { |
| 862 | kfree(inti); |
| 863 | return -EINVAL; |
| 864 | } |
| 865 | inti->type = s390int->type; |
| 866 | inti->pgm.code = s390int->parm; |
| 867 | VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)", |
| 868 | s390int->parm); |
| 869 | break; |
Christian Borntraeger | b7e6e4d | 2009-01-22 10:29:08 +0100 | [diff] [blame] | 870 | case KVM_S390_SIGP_SET_PREFIX: |
| 871 | inti->prefix.address = s390int->parm; |
| 872 | inti->type = s390int->type; |
| 873 | VCPU_EVENT(vcpu, 3, "inject: set prefix to %x (from user)", |
| 874 | s390int->parm); |
| 875 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 876 | case KVM_S390_SIGP_STOP: |
| 877 | case KVM_S390_RESTART: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 878 | VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type); |
| 879 | inti->type = s390int->type; |
| 880 | break; |
Jason J. Herne | 82a1273 | 2012-10-02 16:25:36 +0200 | [diff] [blame] | 881 | case KVM_S390_INT_EXTERNAL_CALL: |
| 882 | if (s390int->parm & 0xffff0000) { |
| 883 | kfree(inti); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | VCPU_EVENT(vcpu, 3, "inject: external call source-cpu:%u", |
| 887 | s390int->parm); |
| 888 | inti->type = s390int->type; |
| 889 | inti->extcall.code = s390int->parm; |
| 890 | break; |
| 891 | case KVM_S390_INT_EMERGENCY: |
| 892 | if (s390int->parm & 0xffff0000) { |
| 893 | kfree(inti); |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | VCPU_EVENT(vcpu, 3, "inject: emergency %u\n", s390int->parm); |
| 897 | inti->type = s390int->type; |
| 898 | inti->emerg.code = s390int->parm; |
| 899 | break; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 900 | case KVM_S390_MCHK: |
| 901 | VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx", |
| 902 | s390int->parm64); |
| 903 | inti->type = s390int->type; |
| 904 | inti->mchk.mcic = s390int->parm64; |
| 905 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 906 | case KVM_S390_INT_PFAULT_INIT: |
| 907 | inti->type = s390int->type; |
| 908 | inti->ext.ext_params2 = s390int->parm64; |
| 909 | break; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 910 | case KVM_S390_INT_VIRTIO: |
| 911 | case KVM_S390_INT_SERVICE: |
Cornelia Huck | d8346b7 | 2012-12-20 15:32:08 +0100 | [diff] [blame] | 912 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 913 | default: |
| 914 | kfree(inti); |
| 915 | return -EINVAL; |
| 916 | } |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 917 | trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, s390int->type, s390int->parm, |
| 918 | s390int->parm64, 2); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 919 | |
| 920 | mutex_lock(&vcpu->kvm->lock); |
| 921 | li = &vcpu->arch.local_int; |
| 922 | spin_lock_bh(&li->lock); |
| 923 | if (inti->type == KVM_S390_PROGRAM_INT) |
| 924 | list_add(&inti->list, &li->list); |
| 925 | else |
| 926 | list_add_tail(&inti->list, &li->list); |
| 927 | atomic_set(&li->active, 1); |
| 928 | if (inti->type == KVM_S390_SIGP_STOP) |
| 929 | li->action_bits |= ACTION_STOP_ON_STOP; |
| 930 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 931 | if (waitqueue_active(&vcpu->wq)) |
| 932 | wake_up_interruptible(&vcpu->wq); |
Michael Mueller | 9cac38d | 2014-02-26 16:14:19 +0100 | [diff] [blame] | 933 | vcpu->preempted = true; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 934 | spin_unlock_bh(&li->lock); |
| 935 | mutex_unlock(&vcpu->kvm->lock); |
| 936 | return 0; |
| 937 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 938 | |
| 939 | static void clear_floating_interrupts(struct kvm *kvm) |
| 940 | { |
| 941 | struct kvm_s390_float_interrupt *fi; |
| 942 | struct kvm_s390_interrupt_info *n, *inti = NULL; |
| 943 | |
| 944 | mutex_lock(&kvm->lock); |
| 945 | fi = &kvm->arch.float_int; |
| 946 | spin_lock(&fi->lock); |
| 947 | list_for_each_entry_safe(inti, n, &fi->list, list) { |
| 948 | list_del(&inti->list); |
| 949 | kfree(inti); |
| 950 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 951 | fi->irq_count = 0; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 952 | atomic_set(&fi->active, 0); |
| 953 | spin_unlock(&fi->lock); |
| 954 | mutex_unlock(&kvm->lock); |
| 955 | } |
| 956 | |
| 957 | static inline int copy_irq_to_user(struct kvm_s390_interrupt_info *inti, |
| 958 | u8 *addr) |
| 959 | { |
| 960 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 961 | struct kvm_s390_irq irq = {0}; |
| 962 | |
| 963 | irq.type = inti->type; |
| 964 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 965 | case KVM_S390_INT_PFAULT_INIT: |
| 966 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 967 | case KVM_S390_INT_VIRTIO: |
| 968 | case KVM_S390_INT_SERVICE: |
| 969 | irq.u.ext = inti->ext; |
| 970 | break; |
| 971 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 972 | irq.u.io = inti->io; |
| 973 | break; |
| 974 | case KVM_S390_MCHK: |
| 975 | irq.u.mchk = inti->mchk; |
| 976 | break; |
| 977 | default: |
| 978 | return -EINVAL; |
| 979 | } |
| 980 | |
| 981 | if (copy_to_user(uptr, &irq, sizeof(irq))) |
| 982 | return -EFAULT; |
| 983 | |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static int get_all_floating_irqs(struct kvm *kvm, __u8 *buf, __u64 len) |
| 988 | { |
| 989 | struct kvm_s390_interrupt_info *inti; |
| 990 | struct kvm_s390_float_interrupt *fi; |
| 991 | int ret = 0; |
| 992 | int n = 0; |
| 993 | |
| 994 | mutex_lock(&kvm->lock); |
| 995 | fi = &kvm->arch.float_int; |
| 996 | spin_lock(&fi->lock); |
| 997 | |
| 998 | list_for_each_entry(inti, &fi->list, list) { |
| 999 | if (len < sizeof(struct kvm_s390_irq)) { |
| 1000 | /* signal userspace to try again */ |
| 1001 | ret = -ENOMEM; |
| 1002 | break; |
| 1003 | } |
| 1004 | ret = copy_irq_to_user(inti, buf); |
| 1005 | if (ret) |
| 1006 | break; |
| 1007 | buf += sizeof(struct kvm_s390_irq); |
| 1008 | len -= sizeof(struct kvm_s390_irq); |
| 1009 | n++; |
| 1010 | } |
| 1011 | |
| 1012 | spin_unlock(&fi->lock); |
| 1013 | mutex_unlock(&kvm->lock); |
| 1014 | |
| 1015 | return ret < 0 ? ret : n; |
| 1016 | } |
| 1017 | |
| 1018 | static int flic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1019 | { |
| 1020 | int r; |
| 1021 | |
| 1022 | switch (attr->group) { |
| 1023 | case KVM_DEV_FLIC_GET_ALL_IRQS: |
| 1024 | r = get_all_floating_irqs(dev->kvm, (u8 *) attr->addr, |
| 1025 | attr->attr); |
| 1026 | break; |
| 1027 | default: |
| 1028 | r = -EINVAL; |
| 1029 | } |
| 1030 | |
| 1031 | return r; |
| 1032 | } |
| 1033 | |
| 1034 | static inline int copy_irq_from_user(struct kvm_s390_interrupt_info *inti, |
| 1035 | u64 addr) |
| 1036 | { |
| 1037 | struct kvm_s390_irq __user *uptr = (struct kvm_s390_irq __user *) addr; |
| 1038 | void *target = NULL; |
| 1039 | void __user *source; |
| 1040 | u64 size; |
| 1041 | |
| 1042 | if (get_user(inti->type, (u64 __user *)addr)) |
| 1043 | return -EFAULT; |
| 1044 | |
| 1045 | switch (inti->type) { |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1046 | case KVM_S390_INT_PFAULT_INIT: |
| 1047 | case KVM_S390_INT_PFAULT_DONE: |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1048 | case KVM_S390_INT_VIRTIO: |
| 1049 | case KVM_S390_INT_SERVICE: |
| 1050 | target = (void *) &inti->ext; |
| 1051 | source = &uptr->u.ext; |
| 1052 | size = sizeof(inti->ext); |
| 1053 | break; |
| 1054 | case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX: |
| 1055 | target = (void *) &inti->io; |
| 1056 | source = &uptr->u.io; |
| 1057 | size = sizeof(inti->io); |
| 1058 | break; |
| 1059 | case KVM_S390_MCHK: |
| 1060 | target = (void *) &inti->mchk; |
| 1061 | source = &uptr->u.mchk; |
| 1062 | size = sizeof(inti->mchk); |
| 1063 | break; |
| 1064 | default: |
| 1065 | return -EINVAL; |
| 1066 | } |
| 1067 | |
| 1068 | if (copy_from_user(target, source, size)) |
| 1069 | return -EFAULT; |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | static int enqueue_floating_irq(struct kvm_device *dev, |
| 1075 | struct kvm_device_attr *attr) |
| 1076 | { |
| 1077 | struct kvm_s390_interrupt_info *inti = NULL; |
| 1078 | int r = 0; |
| 1079 | int len = attr->attr; |
| 1080 | |
| 1081 | if (len % sizeof(struct kvm_s390_irq) != 0) |
| 1082 | return -EINVAL; |
| 1083 | else if (len > KVM_S390_FLIC_MAX_BUFFER) |
| 1084 | return -EINVAL; |
| 1085 | |
| 1086 | while (len >= sizeof(struct kvm_s390_irq)) { |
| 1087 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 1088 | if (!inti) |
| 1089 | return -ENOMEM; |
| 1090 | |
| 1091 | r = copy_irq_from_user(inti, attr->addr); |
| 1092 | if (r) { |
| 1093 | kfree(inti); |
| 1094 | return r; |
| 1095 | } |
Jens Freimann | a91b8eb | 2014-01-30 08:40:23 +0100 | [diff] [blame] | 1096 | r = __inject_vm(dev->kvm, inti); |
| 1097 | if (r) { |
| 1098 | kfree(inti); |
| 1099 | return r; |
| 1100 | } |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1101 | len -= sizeof(struct kvm_s390_irq); |
| 1102 | attr->addr += sizeof(struct kvm_s390_irq); |
| 1103 | } |
| 1104 | |
| 1105 | return r; |
| 1106 | } |
| 1107 | |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1108 | static struct s390_io_adapter *get_io_adapter(struct kvm *kvm, unsigned int id) |
| 1109 | { |
| 1110 | if (id >= MAX_S390_IO_ADAPTERS) |
| 1111 | return NULL; |
| 1112 | return kvm->arch.adapters[id]; |
| 1113 | } |
| 1114 | |
| 1115 | static int register_io_adapter(struct kvm_device *dev, |
| 1116 | struct kvm_device_attr *attr) |
| 1117 | { |
| 1118 | struct s390_io_adapter *adapter; |
| 1119 | struct kvm_s390_io_adapter adapter_info; |
| 1120 | |
| 1121 | if (copy_from_user(&adapter_info, |
| 1122 | (void __user *)attr->addr, sizeof(adapter_info))) |
| 1123 | return -EFAULT; |
| 1124 | |
| 1125 | if ((adapter_info.id >= MAX_S390_IO_ADAPTERS) || |
| 1126 | (dev->kvm->arch.adapters[adapter_info.id] != NULL)) |
| 1127 | return -EINVAL; |
| 1128 | |
| 1129 | adapter = kzalloc(sizeof(*adapter), GFP_KERNEL); |
| 1130 | if (!adapter) |
| 1131 | return -ENOMEM; |
| 1132 | |
| 1133 | INIT_LIST_HEAD(&adapter->maps); |
| 1134 | init_rwsem(&adapter->maps_lock); |
| 1135 | atomic_set(&adapter->nr_maps, 0); |
| 1136 | adapter->id = adapter_info.id; |
| 1137 | adapter->isc = adapter_info.isc; |
| 1138 | adapter->maskable = adapter_info.maskable; |
| 1139 | adapter->masked = false; |
| 1140 | adapter->swap = adapter_info.swap; |
| 1141 | dev->kvm->arch.adapters[adapter->id] = adapter; |
| 1142 | |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | int kvm_s390_mask_adapter(struct kvm *kvm, unsigned int id, bool masked) |
| 1147 | { |
| 1148 | int ret; |
| 1149 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1150 | |
| 1151 | if (!adapter || !adapter->maskable) |
| 1152 | return -EINVAL; |
| 1153 | ret = adapter->masked; |
| 1154 | adapter->masked = masked; |
| 1155 | return ret; |
| 1156 | } |
| 1157 | |
| 1158 | static int kvm_s390_adapter_map(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1159 | { |
| 1160 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1161 | struct s390_map_info *map; |
| 1162 | int ret; |
| 1163 | |
| 1164 | if (!adapter || !addr) |
| 1165 | return -EINVAL; |
| 1166 | |
| 1167 | map = kzalloc(sizeof(*map), GFP_KERNEL); |
| 1168 | if (!map) { |
| 1169 | ret = -ENOMEM; |
| 1170 | goto out; |
| 1171 | } |
| 1172 | INIT_LIST_HEAD(&map->list); |
| 1173 | map->guest_addr = addr; |
| 1174 | map->addr = gmap_translate(addr, kvm->arch.gmap); |
| 1175 | if (map->addr == -EFAULT) { |
| 1176 | ret = -EFAULT; |
| 1177 | goto out; |
| 1178 | } |
| 1179 | ret = get_user_pages_fast(map->addr, 1, 1, &map->page); |
| 1180 | if (ret < 0) |
| 1181 | goto out; |
| 1182 | BUG_ON(ret != 1); |
| 1183 | down_write(&adapter->maps_lock); |
| 1184 | if (atomic_inc_return(&adapter->nr_maps) < MAX_S390_ADAPTER_MAPS) { |
| 1185 | list_add_tail(&map->list, &adapter->maps); |
| 1186 | ret = 0; |
| 1187 | } else { |
| 1188 | put_page(map->page); |
| 1189 | ret = -EINVAL; |
| 1190 | } |
| 1191 | up_write(&adapter->maps_lock); |
| 1192 | out: |
| 1193 | if (ret) |
| 1194 | kfree(map); |
| 1195 | return ret; |
| 1196 | } |
| 1197 | |
| 1198 | static int kvm_s390_adapter_unmap(struct kvm *kvm, unsigned int id, __u64 addr) |
| 1199 | { |
| 1200 | struct s390_io_adapter *adapter = get_io_adapter(kvm, id); |
| 1201 | struct s390_map_info *map, *tmp; |
| 1202 | int found = 0; |
| 1203 | |
| 1204 | if (!adapter || !addr) |
| 1205 | return -EINVAL; |
| 1206 | |
| 1207 | down_write(&adapter->maps_lock); |
| 1208 | list_for_each_entry_safe(map, tmp, &adapter->maps, list) { |
| 1209 | if (map->guest_addr == addr) { |
| 1210 | found = 1; |
| 1211 | atomic_dec(&adapter->nr_maps); |
| 1212 | list_del(&map->list); |
| 1213 | put_page(map->page); |
| 1214 | kfree(map); |
| 1215 | break; |
| 1216 | } |
| 1217 | } |
| 1218 | up_write(&adapter->maps_lock); |
| 1219 | |
| 1220 | return found ? 0 : -EINVAL; |
| 1221 | } |
| 1222 | |
| 1223 | void kvm_s390_destroy_adapters(struct kvm *kvm) |
| 1224 | { |
| 1225 | int i; |
| 1226 | struct s390_map_info *map, *tmp; |
| 1227 | |
| 1228 | for (i = 0; i < MAX_S390_IO_ADAPTERS; i++) { |
| 1229 | if (!kvm->arch.adapters[i]) |
| 1230 | continue; |
| 1231 | list_for_each_entry_safe(map, tmp, |
| 1232 | &kvm->arch.adapters[i]->maps, list) { |
| 1233 | list_del(&map->list); |
| 1234 | put_page(map->page); |
| 1235 | kfree(map); |
| 1236 | } |
| 1237 | kfree(kvm->arch.adapters[i]); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | static int modify_io_adapter(struct kvm_device *dev, |
| 1242 | struct kvm_device_attr *attr) |
| 1243 | { |
| 1244 | struct kvm_s390_io_adapter_req req; |
| 1245 | struct s390_io_adapter *adapter; |
| 1246 | int ret; |
| 1247 | |
| 1248 | if (copy_from_user(&req, (void __user *)attr->addr, sizeof(req))) |
| 1249 | return -EFAULT; |
| 1250 | |
| 1251 | adapter = get_io_adapter(dev->kvm, req.id); |
| 1252 | if (!adapter) |
| 1253 | return -EINVAL; |
| 1254 | switch (req.type) { |
| 1255 | case KVM_S390_IO_ADAPTER_MASK: |
| 1256 | ret = kvm_s390_mask_adapter(dev->kvm, req.id, req.mask); |
| 1257 | if (ret > 0) |
| 1258 | ret = 0; |
| 1259 | break; |
| 1260 | case KVM_S390_IO_ADAPTER_MAP: |
| 1261 | ret = kvm_s390_adapter_map(dev->kvm, req.id, req.addr); |
| 1262 | break; |
| 1263 | case KVM_S390_IO_ADAPTER_UNMAP: |
| 1264 | ret = kvm_s390_adapter_unmap(dev->kvm, req.id, req.addr); |
| 1265 | break; |
| 1266 | default: |
| 1267 | ret = -EINVAL; |
| 1268 | } |
| 1269 | |
| 1270 | return ret; |
| 1271 | } |
| 1272 | |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1273 | static int flic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) |
| 1274 | { |
| 1275 | int r = 0; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1276 | unsigned int i; |
| 1277 | struct kvm_vcpu *vcpu; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1278 | |
| 1279 | switch (attr->group) { |
| 1280 | case KVM_DEV_FLIC_ENQUEUE: |
| 1281 | r = enqueue_floating_irq(dev, attr); |
| 1282 | break; |
| 1283 | case KVM_DEV_FLIC_CLEAR_IRQS: |
| 1284 | r = 0; |
| 1285 | clear_floating_interrupts(dev->kvm); |
| 1286 | break; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 1287 | case KVM_DEV_FLIC_APF_ENABLE: |
| 1288 | dev->kvm->arch.gmap->pfault_enabled = 1; |
| 1289 | break; |
| 1290 | case KVM_DEV_FLIC_APF_DISABLE_WAIT: |
| 1291 | dev->kvm->arch.gmap->pfault_enabled = 0; |
| 1292 | /* |
| 1293 | * Make sure no async faults are in transition when |
| 1294 | * clearing the queues. So we don't need to worry |
| 1295 | * about late coming workers. |
| 1296 | */ |
| 1297 | synchronize_srcu(&dev->kvm->srcu); |
| 1298 | kvm_for_each_vcpu(i, vcpu, dev->kvm) |
| 1299 | kvm_clear_async_pf_completion_queue(vcpu); |
| 1300 | break; |
Cornelia Huck | 841b91c | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1301 | case KVM_DEV_FLIC_ADAPTER_REGISTER: |
| 1302 | r = register_io_adapter(dev, attr); |
| 1303 | break; |
| 1304 | case KVM_DEV_FLIC_ADAPTER_MODIFY: |
| 1305 | r = modify_io_adapter(dev, attr); |
| 1306 | break; |
Jens Freimann | c05c418 | 2013-10-07 16:13:45 +0200 | [diff] [blame] | 1307 | default: |
| 1308 | r = -EINVAL; |
| 1309 | } |
| 1310 | |
| 1311 | return r; |
| 1312 | } |
| 1313 | |
| 1314 | static int flic_create(struct kvm_device *dev, u32 type) |
| 1315 | { |
| 1316 | if (!dev) |
| 1317 | return -EINVAL; |
| 1318 | if (dev->kvm->arch.flic) |
| 1319 | return -EINVAL; |
| 1320 | dev->kvm->arch.flic = dev; |
| 1321 | return 0; |
| 1322 | } |
| 1323 | |
| 1324 | static void flic_destroy(struct kvm_device *dev) |
| 1325 | { |
| 1326 | dev->kvm->arch.flic = NULL; |
| 1327 | kfree(dev); |
| 1328 | } |
| 1329 | |
| 1330 | /* s390 floating irq controller (flic) */ |
| 1331 | struct kvm_device_ops kvm_flic_ops = { |
| 1332 | .name = "kvm-flic", |
| 1333 | .get_attr = flic_get_attr, |
| 1334 | .set_attr = flic_set_attr, |
| 1335 | .create = flic_create, |
| 1336 | .destroy = flic_destroy, |
| 1337 | }; |
Cornelia Huck | 8422359 | 2013-07-15 13:36:01 +0200 | [diff] [blame] | 1338 | |
| 1339 | static unsigned long get_ind_bit(__u64 addr, unsigned long bit_nr, bool swap) |
| 1340 | { |
| 1341 | unsigned long bit; |
| 1342 | |
| 1343 | bit = bit_nr + (addr % PAGE_SIZE) * 8; |
| 1344 | |
| 1345 | return swap ? (bit ^ (BITS_PER_LONG - 1)) : bit; |
| 1346 | } |
| 1347 | |
| 1348 | static struct s390_map_info *get_map_info(struct s390_io_adapter *adapter, |
| 1349 | u64 addr) |
| 1350 | { |
| 1351 | struct s390_map_info *map; |
| 1352 | |
| 1353 | if (!adapter) |
| 1354 | return NULL; |
| 1355 | |
| 1356 | list_for_each_entry(map, &adapter->maps, list) { |
| 1357 | if (map->guest_addr == addr) |
| 1358 | return map; |
| 1359 | } |
| 1360 | return NULL; |
| 1361 | } |
| 1362 | |
| 1363 | static int adapter_indicators_set(struct kvm *kvm, |
| 1364 | struct s390_io_adapter *adapter, |
| 1365 | struct kvm_s390_adapter_int *adapter_int) |
| 1366 | { |
| 1367 | unsigned long bit; |
| 1368 | int summary_set, idx; |
| 1369 | struct s390_map_info *info; |
| 1370 | void *map; |
| 1371 | |
| 1372 | info = get_map_info(adapter, adapter_int->ind_addr); |
| 1373 | if (!info) |
| 1374 | return -1; |
| 1375 | map = page_address(info->page); |
| 1376 | bit = get_ind_bit(info->addr, adapter_int->ind_offset, adapter->swap); |
| 1377 | set_bit(bit, map); |
| 1378 | idx = srcu_read_lock(&kvm->srcu); |
| 1379 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1380 | set_page_dirty_lock(info->page); |
| 1381 | info = get_map_info(adapter, adapter_int->summary_addr); |
| 1382 | if (!info) { |
| 1383 | srcu_read_unlock(&kvm->srcu, idx); |
| 1384 | return -1; |
| 1385 | } |
| 1386 | map = page_address(info->page); |
| 1387 | bit = get_ind_bit(info->addr, adapter_int->summary_offset, |
| 1388 | adapter->swap); |
| 1389 | summary_set = test_and_set_bit(bit, map); |
| 1390 | mark_page_dirty(kvm, info->guest_addr >> PAGE_SHIFT); |
| 1391 | set_page_dirty_lock(info->page); |
| 1392 | srcu_read_unlock(&kvm->srcu, idx); |
| 1393 | return summary_set ? 0 : 1; |
| 1394 | } |
| 1395 | |
| 1396 | /* |
| 1397 | * < 0 - not injected due to error |
| 1398 | * = 0 - coalesced, summary indicator already active |
| 1399 | * > 0 - injected interrupt |
| 1400 | */ |
| 1401 | static int set_adapter_int(struct kvm_kernel_irq_routing_entry *e, |
| 1402 | struct kvm *kvm, int irq_source_id, int level, |
| 1403 | bool line_status) |
| 1404 | { |
| 1405 | int ret; |
| 1406 | struct s390_io_adapter *adapter; |
| 1407 | |
| 1408 | /* We're only interested in the 0->1 transition. */ |
| 1409 | if (!level) |
| 1410 | return 0; |
| 1411 | adapter = get_io_adapter(kvm, e->adapter.adapter_id); |
| 1412 | if (!adapter) |
| 1413 | return -1; |
| 1414 | down_read(&adapter->maps_lock); |
| 1415 | ret = adapter_indicators_set(kvm, adapter, &e->adapter); |
| 1416 | up_read(&adapter->maps_lock); |
| 1417 | if ((ret > 0) && !adapter->masked) { |
| 1418 | struct kvm_s390_interrupt s390int = { |
| 1419 | .type = KVM_S390_INT_IO(1, 0, 0, 0), |
| 1420 | .parm = 0, |
| 1421 | .parm64 = (adapter->isc << 27) | 0x80000000, |
| 1422 | }; |
| 1423 | ret = kvm_s390_inject_vm(kvm, &s390int); |
| 1424 | if (ret == 0) |
| 1425 | ret = 1; |
| 1426 | } |
| 1427 | return ret; |
| 1428 | } |
| 1429 | |
| 1430 | int kvm_set_routing_entry(struct kvm_irq_routing_table *rt, |
| 1431 | struct kvm_kernel_irq_routing_entry *e, |
| 1432 | const struct kvm_irq_routing_entry *ue) |
| 1433 | { |
| 1434 | int ret; |
| 1435 | |
| 1436 | switch (ue->type) { |
| 1437 | case KVM_IRQ_ROUTING_S390_ADAPTER: |
| 1438 | e->set = set_adapter_int; |
| 1439 | e->adapter.summary_addr = ue->u.adapter.summary_addr; |
| 1440 | e->adapter.ind_addr = ue->u.adapter.ind_addr; |
| 1441 | e->adapter.summary_offset = ue->u.adapter.summary_offset; |
| 1442 | e->adapter.ind_offset = ue->u.adapter.ind_offset; |
| 1443 | e->adapter.adapter_id = ue->u.adapter.adapter_id; |
| 1444 | ret = 0; |
| 1445 | break; |
| 1446 | default: |
| 1447 | ret = -EINVAL; |
| 1448 | } |
| 1449 | |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
| 1453 | int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, |
| 1454 | int irq_source_id, int level, bool line_status) |
| 1455 | { |
| 1456 | return -EINVAL; |
| 1457 | } |