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