Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * in-kernel handling for sie intercepts |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 3 | * |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2014 |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +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 | * Christian Borntraeger <borntraeger@de.ibm.com> |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kvm_host.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/pagemap.h> |
| 17 | |
| 18 | #include <asm/kvm_host.h> |
Michael Mueller | a86dcc24 | 2014-03-13 19:29:09 +0100 | [diff] [blame] | 19 | #include <asm/asm-offsets.h> |
Thomas Huth | f14d82e | 2014-01-15 16:46:07 +0100 | [diff] [blame] | 20 | #include <asm/irq.h> |
QingFeng Hao | b7c92f1 | 2017-09-29 12:41:50 +0200 | [diff] [blame] | 21 | #include <asm/sysinfo.h> |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 22 | |
| 23 | #include "kvm-s390.h" |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 24 | #include "gaccess.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 25 | #include "trace.h" |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 26 | #include "trace-s390.h" |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 27 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 28 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 29 | static const intercept_handler_t instruction_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 30 | [0x01] = kvm_s390_handle_01, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 31 | [0x82] = kvm_s390_handle_lpsw, |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 32 | [0x83] = kvm_s390_handle_diag, |
Fan Zhang | 80cd876 | 2016-08-15 04:53:22 +0200 | [diff] [blame] | 33 | [0xaa] = kvm_s390_handle_aa, |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 34 | [0xae] = kvm_s390_handle_sigp, |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 35 | [0xb2] = kvm_s390_handle_b2, |
David Hildenbrand | aba0750 | 2014-01-23 10:47:13 +0100 | [diff] [blame] | 36 | [0xb6] = kvm_s390_handle_stctl, |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 37 | [0xb7] = kvm_s390_handle_lctl, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 38 | [0xb9] = kvm_s390_handle_b9, |
Fan Zhang | 4e0b1ab | 2016-11-29 07:17:55 +0100 | [diff] [blame] | 39 | [0xe3] = kvm_s390_handle_e3, |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 40 | [0xe5] = kvm_s390_handle_e5, |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 41 | [0xeb] = kvm_s390_handle_eb, |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 42 | }; |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 43 | |
David Hildenbrand | 0e8bc06 | 2015-11-04 13:47:58 +0100 | [diff] [blame] | 44 | u8 kvm_s390_get_ilen(struct kvm_vcpu *vcpu) |
Thomas Huth | 04b41ac | 2014-11-12 17:13:29 +0100 | [diff] [blame] | 45 | { |
| 46 | struct kvm_s390_sie_block *sie_block = vcpu->arch.sie_block; |
David Hildenbrand | 0e8bc06 | 2015-11-04 13:47:58 +0100 | [diff] [blame] | 47 | u8 ilen = 0; |
Thomas Huth | 04b41ac | 2014-11-12 17:13:29 +0100 | [diff] [blame] | 48 | |
David Hildenbrand | 0e8bc06 | 2015-11-04 13:47:58 +0100 | [diff] [blame] | 49 | switch (vcpu->arch.sie_block->icptcode) { |
| 50 | case ICPT_INST: |
| 51 | case ICPT_INSTPROGI: |
| 52 | case ICPT_OPEREXC: |
| 53 | case ICPT_PARTEXEC: |
| 54 | case ICPT_IOINST: |
| 55 | /* instruction only stored for these icptcodes */ |
| 56 | ilen = insn_length(vcpu->arch.sie_block->ipa >> 8); |
| 57 | /* Use the length of the EXECUTE instruction if necessary */ |
| 58 | if (sie_block->icptstatus & 1) { |
| 59 | ilen = (sie_block->icptstatus >> 4) & 0x6; |
| 60 | if (!ilen) |
| 61 | ilen = 4; |
| 62 | } |
| 63 | break; |
| 64 | case ICPT_PROGI: |
| 65 | /* bit 1+2 of pgmilc are the ilc, so we directly get ilen */ |
| 66 | ilen = vcpu->arch.sie_block->pgmilc & 0x6; |
| 67 | break; |
Thomas Huth | 04b41ac | 2014-11-12 17:13:29 +0100 | [diff] [blame] | 68 | } |
David Hildenbrand | 0e8bc06 | 2015-11-04 13:47:58 +0100 | [diff] [blame] | 69 | return ilen; |
Thomas Huth | 04b41ac | 2014-11-12 17:13:29 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 72 | static int handle_noop(struct kvm_vcpu *vcpu) |
| 73 | { |
| 74 | switch (vcpu->arch.sie_block->icptcode) { |
| 75 | case 0x10: |
| 76 | vcpu->stat.exit_external_request++; |
| 77 | break; |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 78 | default: |
| 79 | break; /* nothing */ |
| 80 | } |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int handle_stop(struct kvm_vcpu *vcpu) |
| 85 | { |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 86 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 87 | int rc = 0; |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 88 | uint8_t flags, stop_pending; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 89 | |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 90 | vcpu->stat.exit_stop_request++; |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 91 | |
David Hildenbrand | 9a02206 | 2014-08-05 17:40:47 +0200 | [diff] [blame] | 92 | /* delay the stop if any non-stop irq is pending */ |
| 93 | if (kvm_s390_vcpu_has_irq(vcpu, 1)) |
| 94 | return 0; |
| 95 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 96 | /* avoid races with the injection/SIGP STOP code */ |
| 97 | spin_lock(&li->lock); |
| 98 | flags = li->irq.stop.flags; |
| 99 | stop_pending = kvm_s390_is_stop_irq_pending(vcpu); |
| 100 | spin_unlock(&li->lock); |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 101 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 102 | trace_kvm_s390_stop_request(stop_pending, flags); |
| 103 | if (!stop_pending) |
David Hildenbrand | 32f5ff63 | 2014-04-14 12:40:03 +0200 | [diff] [blame] | 104 | return 0; |
| 105 | |
David Hildenbrand | 6cddd43 | 2014-10-15 16:48:53 +0200 | [diff] [blame] | 106 | if (flags & KVM_S390_STOP_FLAG_STORE_STATUS) { |
Jens Freimann | 9e0d547 | 2012-02-06 10:59:03 +0100 | [diff] [blame] | 107 | rc = kvm_s390_vcpu_store_status(vcpu, |
| 108 | KVM_S390_STORE_STATUS_NOADDR); |
David Hildenbrand | 32f5ff63 | 2014-04-14 12:40:03 +0200 | [diff] [blame] | 109 | if (rc) |
| 110 | return rc; |
| 111 | } |
| 112 | |
David Hildenbrand | 6352e4d | 2014-04-10 17:35:00 +0200 | [diff] [blame] | 113 | if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) |
| 114 | kvm_s390_vcpu_stop(vcpu); |
David Hildenbrand | 32f5ff63 | 2014-04-14 12:40:03 +0200 | [diff] [blame] | 115 | return -EOPNOTSUPP; |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int handle_validity(struct kvm_vcpu *vcpu) |
| 119 | { |
| 120 | int viwhy = vcpu->arch.sie_block->ipb >> 16; |
Carsten Otte | 3edbcff | 2009-05-12 17:21:52 +0200 | [diff] [blame] | 121 | |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 122 | vcpu->stat.exit_validity++; |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 123 | trace_kvm_s390_intercept_validity(vcpu, viwhy); |
Christian Borntraeger | a5efb6b | 2016-09-28 16:18:47 +0200 | [diff] [blame] | 124 | KVM_EVENT(3, "validity intercept 0x%x for pid %u (kvm 0x%pK)", viwhy, |
| 125 | current->pid, vcpu->kvm); |
| 126 | |
| 127 | /* do not warn on invalid runtime instrumentation mode */ |
| 128 | WARN_ONCE(viwhy != 0x44, "kvm: unhandled validity intercept 0x%x\n", |
| 129 | viwhy); |
| 130 | return -EINVAL; |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 133 | static int handle_instruction(struct kvm_vcpu *vcpu) |
| 134 | { |
| 135 | intercept_handler_t handler; |
| 136 | |
| 137 | vcpu->stat.exit_instruction++; |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 138 | trace_kvm_s390_intercept_instruction(vcpu, |
| 139 | vcpu->arch.sie_block->ipa, |
| 140 | vcpu->arch.sie_block->ipb); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 141 | handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8]; |
| 142 | if (handler) |
| 143 | return handler(vcpu); |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 144 | return -EOPNOTSUPP; |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 145 | } |
| 146 | |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 147 | static int inject_prog_on_prog_intercept(struct kvm_vcpu *vcpu) |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 148 | { |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 149 | struct kvm_s390_pgm_info pgm_info = { |
| 150 | .code = vcpu->arch.sie_block->iprcc, |
David Hildenbrand | eaa4f41 | 2015-11-04 16:46:55 +0100 | [diff] [blame] | 151 | /* the PSW has already been rewound */ |
| 152 | .flags = KVM_S390_PGM_FLAGS_NO_REWIND, |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 153 | }; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 154 | |
| 155 | switch (vcpu->arch.sie_block->iprcc & ~PGM_PER) { |
| 156 | case PGM_AFX_TRANSLATION: |
| 157 | case PGM_ASX_TRANSLATION: |
| 158 | case PGM_EX_TRANSLATION: |
| 159 | case PGM_LFX_TRANSLATION: |
| 160 | case PGM_LSTE_SEQUENCE: |
| 161 | case PGM_LSX_TRANSLATION: |
| 162 | case PGM_LX_TRANSLATION: |
| 163 | case PGM_PRIMARY_AUTHORITY: |
| 164 | case PGM_SECONDARY_AUTHORITY: |
| 165 | case PGM_SPACE_SWITCH: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 166 | pgm_info.trans_exc_code = vcpu->arch.sie_block->tecmc; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 167 | break; |
| 168 | case PGM_ALEN_TRANSLATION: |
| 169 | case PGM_ALE_SEQUENCE: |
| 170 | case PGM_ASTE_INSTANCE: |
| 171 | case PGM_ASTE_SEQUENCE: |
| 172 | case PGM_ASTE_VALIDITY: |
| 173 | case PGM_EXTENDED_AUTHORITY: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 174 | pgm_info.exc_access_id = vcpu->arch.sie_block->eai; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 175 | break; |
| 176 | case PGM_ASCE_TYPE: |
| 177 | case PGM_PAGE_TRANSLATION: |
| 178 | case PGM_REGION_FIRST_TRANS: |
| 179 | case PGM_REGION_SECOND_TRANS: |
| 180 | case PGM_REGION_THIRD_TRANS: |
| 181 | case PGM_SEGMENT_TRANSLATION: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 182 | pgm_info.trans_exc_code = vcpu->arch.sie_block->tecmc; |
| 183 | pgm_info.exc_access_id = vcpu->arch.sie_block->eai; |
| 184 | pgm_info.op_access_id = vcpu->arch.sie_block->oai; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 185 | break; |
| 186 | case PGM_MONITOR: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 187 | pgm_info.mon_class_nr = vcpu->arch.sie_block->mcn; |
| 188 | pgm_info.mon_code = vcpu->arch.sie_block->tecmc; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 189 | break; |
Eric Farman | 403c864 | 2015-02-02 15:01:06 -0500 | [diff] [blame] | 190 | case PGM_VECTOR_PROCESSING: |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 191 | case PGM_DATA: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 192 | pgm_info.data_exc_code = vcpu->arch.sie_block->dxc; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 193 | break; |
| 194 | case PGM_PROTECTION: |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 195 | pgm_info.trans_exc_code = vcpu->arch.sie_block->tecmc; |
| 196 | pgm_info.exc_access_id = vcpu->arch.sie_block->eai; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 197 | break; |
| 198 | default: |
| 199 | break; |
| 200 | } |
| 201 | |
| 202 | if (vcpu->arch.sie_block->iprcc & PGM_PER) { |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 203 | pgm_info.per_code = vcpu->arch.sie_block->perc; |
| 204 | pgm_info.per_atmid = vcpu->arch.sie_block->peratmid; |
| 205 | pgm_info.per_address = vcpu->arch.sie_block->peraddr; |
| 206 | pgm_info.per_access_id = vcpu->arch.sie_block->peraid; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 207 | } |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 208 | return kvm_s390_inject_prog_irq(vcpu, &pgm_info); |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Michael Mueller | e325fe6 | 2014-03-13 12:16:45 +0100 | [diff] [blame] | 211 | /* |
| 212 | * restore ITDB to program-interruption TDB in guest lowcore |
| 213 | * and set TX abort indication if required |
| 214 | */ |
| 215 | static int handle_itdb(struct kvm_vcpu *vcpu) |
| 216 | { |
| 217 | struct kvm_s390_itdb *itdb; |
| 218 | int rc; |
| 219 | |
| 220 | if (!IS_TE_ENABLED(vcpu) || !IS_ITDB_VALID(vcpu)) |
| 221 | return 0; |
| 222 | if (current->thread.per_flags & PER_FLAG_NO_TE) |
| 223 | return 0; |
| 224 | itdb = (struct kvm_s390_itdb *)vcpu->arch.sie_block->itdba; |
| 225 | rc = write_guest_lc(vcpu, __LC_PGM_TDB, itdb, sizeof(*itdb)); |
| 226 | if (rc) |
| 227 | return rc; |
| 228 | memset(itdb, 0, sizeof(*itdb)); |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
David Hildenbrand | 27291e2 | 2014-01-23 12:26:52 +0100 | [diff] [blame] | 233 | #define per_event(vcpu) (vcpu->arch.sie_block->iprcc & PGM_PER) |
| 234 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 235 | static int handle_prog(struct kvm_vcpu *vcpu) |
| 236 | { |
Thomas Huth | 684135e | 2014-04-17 09:57:10 +0200 | [diff] [blame] | 237 | psw_t psw; |
Heiko Carstens | 0040e7d | 2014-01-01 16:37:47 +0100 | [diff] [blame] | 238 | int rc; |
| 239 | |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 240 | vcpu->stat.exit_program_interruption++; |
Michael Mueller | 7feb6bb | 2013-06-28 13:30:24 +0200 | [diff] [blame] | 241 | |
David Hildenbrand | 27291e2 | 2014-01-23 12:26:52 +0100 | [diff] [blame] | 242 | if (guestdbg_enabled(vcpu) && per_event(vcpu)) { |
David Hildenbrand | a69cbe8 | 2016-05-24 12:40:11 +0200 | [diff] [blame] | 243 | rc = kvm_s390_handle_per_event(vcpu); |
| 244 | if (rc) |
| 245 | return rc; |
David Hildenbrand | 27291e2 | 2014-01-23 12:26:52 +0100 | [diff] [blame] | 246 | /* the interrupt might have been filtered out completely */ |
| 247 | if (vcpu->arch.sie_block->iprcc == 0) |
| 248 | return 0; |
| 249 | } |
| 250 | |
Michael Mueller | e325fe6 | 2014-03-13 12:16:45 +0100 | [diff] [blame] | 251 | trace_kvm_s390_intercept_prog(vcpu, vcpu->arch.sie_block->iprcc); |
Thomas Huth | 684135e | 2014-04-17 09:57:10 +0200 | [diff] [blame] | 252 | if (vcpu->arch.sie_block->iprcc == PGM_SPECIFICATION) { |
| 253 | rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &psw, sizeof(psw_t)); |
| 254 | if (rc) |
| 255 | return rc; |
| 256 | /* Avoid endless loops of specification exceptions */ |
| 257 | if (!is_valid_psw(&psw)) |
| 258 | return -EOPNOTSUPP; |
| 259 | } |
Michael Mueller | e325fe6 | 2014-03-13 12:16:45 +0100 | [diff] [blame] | 260 | rc = handle_itdb(vcpu); |
Heiko Carstens | 0040e7d | 2014-01-01 16:37:47 +0100 | [diff] [blame] | 261 | if (rc) |
| 262 | return rc; |
David Hildenbrand | 439716a | 2014-03-03 10:54:33 +0100 | [diff] [blame] | 263 | |
David Hildenbrand | f6af84e | 2015-11-04 16:22:19 +0100 | [diff] [blame] | 264 | return inject_prog_on_prog_intercept(vcpu); |
Carsten Otte | ba5c1e9 | 2008-03-25 18:47:26 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 267 | /** |
Thomas Huth | f14d82e | 2014-01-15 16:46:07 +0100 | [diff] [blame] | 268 | * handle_external_interrupt - used for external interruption interceptions |
| 269 | * |
| 270 | * This interception only occurs if the CPUSTAT_EXT_INT bit was set, or if |
| 271 | * the new PSW does not have external interrupts disabled. In the first case, |
| 272 | * we've got to deliver the interrupt manually, and in the second case, we |
| 273 | * drop to userspace to handle the situation there. |
| 274 | */ |
| 275 | static int handle_external_interrupt(struct kvm_vcpu *vcpu) |
| 276 | { |
| 277 | u16 eic = vcpu->arch.sie_block->eic; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 278 | struct kvm_s390_irq irq; |
Thomas Huth | f14d82e | 2014-01-15 16:46:07 +0100 | [diff] [blame] | 279 | psw_t newpsw; |
| 280 | int rc; |
| 281 | |
| 282 | vcpu->stat.exit_external_interrupt++; |
| 283 | |
| 284 | rc = read_guest_lc(vcpu, __LC_EXT_NEW_PSW, &newpsw, sizeof(psw_t)); |
| 285 | if (rc) |
| 286 | return rc; |
| 287 | /* We can not handle clock comparator or timer interrupt with bad PSW */ |
| 288 | if ((eic == EXT_IRQ_CLK_COMP || eic == EXT_IRQ_CPU_TIMER) && |
| 289 | (newpsw.mask & PSW_MASK_EXT)) |
| 290 | return -EOPNOTSUPP; |
| 291 | |
| 292 | switch (eic) { |
| 293 | case EXT_IRQ_CLK_COMP: |
| 294 | irq.type = KVM_S390_INT_CLOCK_COMP; |
| 295 | break; |
| 296 | case EXT_IRQ_CPU_TIMER: |
| 297 | irq.type = KVM_S390_INT_CPU_TIMER; |
| 298 | break; |
| 299 | case EXT_IRQ_EXTERNAL_CALL: |
| 300 | irq.type = KVM_S390_INT_EXTERNAL_CALL; |
Jens Freimann | 383d0b0 | 2014-07-29 15:11:49 +0200 | [diff] [blame] | 301 | irq.u.extcall.code = vcpu->arch.sie_block->extcpuaddr; |
David Hildenbrand | ea5f496 | 2014-10-14 15:29:30 +0200 | [diff] [blame] | 302 | rc = kvm_s390_inject_vcpu(vcpu, &irq); |
| 303 | /* ignore if another external call is already pending */ |
| 304 | if (rc == -EBUSY) |
| 305 | return 0; |
| 306 | return rc; |
Thomas Huth | f14d82e | 2014-01-15 16:46:07 +0100 | [diff] [blame] | 307 | default: |
| 308 | return -EOPNOTSUPP; |
| 309 | } |
| 310 | |
| 311 | return kvm_s390_inject_vcpu(vcpu, &irq); |
| 312 | } |
| 313 | |
| 314 | /** |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 315 | * Handle MOVE PAGE partial execution interception. |
| 316 | * |
| 317 | * This interception can only happen for guests with DAT disabled and |
| 318 | * addresses that are currently not mapped in the host. Thus we try to |
| 319 | * set up the mappings for the corresponding user pages here (or throw |
| 320 | * addressing exceptions in case of illegal guest addresses). |
| 321 | */ |
| 322 | static int handle_mvpg_pei(struct kvm_vcpu *vcpu) |
| 323 | { |
Thomas Huth | f22166d | 2014-05-07 11:44:17 +0200 | [diff] [blame] | 324 | unsigned long srcaddr, dstaddr; |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 325 | int reg1, reg2, rc; |
| 326 | |
| 327 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 328 | |
| 329 | /* Make sure that the source is paged-in */ |
Thomas Huth | 3cfad02 | 2015-01-07 16:27:02 +0100 | [diff] [blame] | 330 | rc = guest_translate_address(vcpu, vcpu->run->s.regs.gprs[reg2], |
David Hildenbrand | 92c9632 | 2015-11-16 15:42:11 +0100 | [diff] [blame] | 331 | reg2, &srcaddr, GACC_FETCH); |
Thomas Huth | 3cfad02 | 2015-01-07 16:27:02 +0100 | [diff] [blame] | 332 | if (rc) |
| 333 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Thomas Huth | f22166d | 2014-05-07 11:44:17 +0200 | [diff] [blame] | 334 | rc = kvm_arch_fault_in_page(vcpu, srcaddr, 0); |
| 335 | if (rc != 0) |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 336 | return rc; |
| 337 | |
| 338 | /* Make sure that the destination is paged-in */ |
Thomas Huth | 3cfad02 | 2015-01-07 16:27:02 +0100 | [diff] [blame] | 339 | rc = guest_translate_address(vcpu, vcpu->run->s.regs.gprs[reg1], |
David Hildenbrand | 92c9632 | 2015-11-16 15:42:11 +0100 | [diff] [blame] | 340 | reg1, &dstaddr, GACC_STORE); |
Thomas Huth | 3cfad02 | 2015-01-07 16:27:02 +0100 | [diff] [blame] | 341 | if (rc) |
| 342 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Thomas Huth | f22166d | 2014-05-07 11:44:17 +0200 | [diff] [blame] | 343 | rc = kvm_arch_fault_in_page(vcpu, dstaddr, 1); |
| 344 | if (rc != 0) |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 345 | return rc; |
| 346 | |
David Hildenbrand | 0e8bc06 | 2015-11-04 13:47:58 +0100 | [diff] [blame] | 347 | kvm_s390_retry_instr(vcpu); |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int handle_partial_execution(struct kvm_vcpu *vcpu) |
| 353 | { |
Alexander Yarygin | 9ec6de1 | 2016-05-06 16:33:06 +0300 | [diff] [blame] | 354 | vcpu->stat.exit_pei++; |
| 355 | |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 356 | if (vcpu->arch.sie_block->ipa == 0xb254) /* MVPG */ |
| 357 | return handle_mvpg_pei(vcpu); |
David Hildenbrand | 4953919 | 2014-02-21 08:59:59 +0100 | [diff] [blame] | 358 | if (vcpu->arch.sie_block->ipa >> 8 == 0xae) /* SIGP */ |
| 359 | return kvm_s390_handle_sigp_pei(vcpu); |
Thomas Huth | 9a558ee | 2014-02-03 10:42:30 +0100 | [diff] [blame] | 360 | |
| 361 | return -EOPNOTSUPP; |
| 362 | } |
| 363 | |
QingFeng Hao | b7c92f1 | 2017-09-29 12:41:50 +0200 | [diff] [blame] | 364 | /* |
| 365 | * Handle the sthyi instruction that provides the guest with system |
| 366 | * information, like current CPU resources available at each level of |
| 367 | * the machine. |
| 368 | */ |
| 369 | int handle_sthyi(struct kvm_vcpu *vcpu) |
| 370 | { |
| 371 | int reg1, reg2, r = 0; |
| 372 | u64 code, addr, cc = 0, rc = 0; |
| 373 | struct sthyi_sctns *sctns = NULL; |
| 374 | |
| 375 | if (!test_kvm_facility(vcpu->kvm, 74)) |
| 376 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 377 | |
QingFeng Hao | b7c92f1 | 2017-09-29 12:41:50 +0200 | [diff] [blame] | 378 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
| 379 | code = vcpu->run->s.regs.gprs[reg1]; |
| 380 | addr = vcpu->run->s.regs.gprs[reg2]; |
| 381 | |
| 382 | vcpu->stat.instruction_sthyi++; |
| 383 | VCPU_EVENT(vcpu, 3, "STHYI: fc: %llu addr: 0x%016llx", code, addr); |
| 384 | trace_kvm_s390_handle_sthyi(vcpu, code, addr); |
| 385 | |
| 386 | if (reg1 == reg2 || reg1 & 1 || reg2 & 1) |
| 387 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 388 | |
| 389 | if (code & 0xffff) { |
| 390 | cc = 3; |
| 391 | rc = 4; |
| 392 | goto out; |
| 393 | } |
| 394 | |
| 395 | if (addr & ~PAGE_MASK) |
| 396 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 397 | |
| 398 | sctns = (void *)get_zeroed_page(GFP_KERNEL); |
| 399 | if (!sctns) |
| 400 | return -ENOMEM; |
| 401 | |
| 402 | cc = sthyi_fill(sctns, &rc); |
| 403 | |
| 404 | out: |
| 405 | if (!cc) { |
| 406 | r = write_guest(vcpu, addr, reg2, sctns, PAGE_SIZE); |
| 407 | if (r) { |
| 408 | free_page((unsigned long)sctns); |
| 409 | return kvm_s390_inject_prog_cond(vcpu, r); |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | free_page((unsigned long)sctns); |
| 414 | vcpu->run->s.regs.gprs[reg2 + 1] = rc; |
| 415 | kvm_s390_set_psw_cc(vcpu, cc); |
| 416 | return r; |
| 417 | } |
| 418 | |
Janosch Frank | a011eeb | 2016-05-09 14:14:01 +0200 | [diff] [blame] | 419 | static int handle_operexc(struct kvm_vcpu *vcpu) |
| 420 | { |
Christian Borntraeger | fb7dc1d | 2017-01-26 20:45:33 +0100 | [diff] [blame] | 421 | psw_t oldpsw, newpsw; |
| 422 | int rc; |
| 423 | |
Janosch Frank | a011eeb | 2016-05-09 14:14:01 +0200 | [diff] [blame] | 424 | vcpu->stat.exit_operation_exception++; |
| 425 | trace_kvm_s390_handle_operexc(vcpu, vcpu->arch.sie_block->ipa, |
| 426 | vcpu->arch.sie_block->ipb); |
| 427 | |
Christian Borntraeger | c0a6bfd | 2017-02-27 21:14:47 +0100 | [diff] [blame] | 428 | if (vcpu->arch.sie_block->ipa == 0xb256) |
Janosch Frank | 95ca2cb | 2016-05-23 15:11:58 +0200 | [diff] [blame] | 429 | return handle_sthyi(vcpu); |
| 430 | |
David Hildenbrand | 6502a34 | 2016-06-21 14:19:51 +0200 | [diff] [blame] | 431 | if (vcpu->arch.sie_block->ipa == 0 && vcpu->kvm->arch.user_instr0) |
| 432 | return -EOPNOTSUPP; |
Christian Borntraeger | fb7dc1d | 2017-01-26 20:45:33 +0100 | [diff] [blame] | 433 | rc = read_guest_lc(vcpu, __LC_PGM_NEW_PSW, &newpsw, sizeof(psw_t)); |
| 434 | if (rc) |
| 435 | return rc; |
| 436 | /* |
| 437 | * Avoid endless loops of operation exceptions, if the pgm new |
| 438 | * PSW will cause a new operation exception. |
| 439 | * The heuristic checks if the pgm new psw is within 6 bytes before |
| 440 | * the faulting psw address (with same DAT, AS settings) and the |
| 441 | * new psw is not a wait psw and the fault was not triggered by |
| 442 | * problem state. |
| 443 | */ |
| 444 | oldpsw = vcpu->arch.sie_block->gpsw; |
| 445 | if (oldpsw.addr - newpsw.addr <= 6 && |
| 446 | !(newpsw.mask & PSW_MASK_WAIT) && |
| 447 | !(oldpsw.mask & PSW_MASK_PSTATE) && |
| 448 | (newpsw.mask & PSW_MASK_ASC) == (oldpsw.mask & PSW_MASK_ASC) && |
| 449 | (newpsw.mask & PSW_MASK_DAT) == (oldpsw.mask & PSW_MASK_DAT)) |
| 450 | return -EOPNOTSUPP; |
David Hildenbrand | 6502a34 | 2016-06-21 14:19:51 +0200 | [diff] [blame] | 451 | |
Janosch Frank | a011eeb | 2016-05-09 14:14:01 +0200 | [diff] [blame] | 452 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 453 | } |
| 454 | |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 455 | int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu) |
| 456 | { |
David Hildenbrand | 5ffe466 | 2016-05-24 12:10:27 +0200 | [diff] [blame] | 457 | int rc, per_rc = 0; |
| 458 | |
David Hildenbrand | 71f116b | 2015-10-19 16:24:28 +0200 | [diff] [blame] | 459 | if (kvm_is_ucontrol(vcpu->kvm)) |
| 460 | return -EOPNOTSUPP; |
| 461 | |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 462 | switch (vcpu->arch.sie_block->icptcode) { |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 463 | case ICPT_EXTREQ: |
| 464 | case ICPT_IOREQ: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 465 | return handle_noop(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 466 | case ICPT_INST: |
David Hildenbrand | 5ffe466 | 2016-05-24 12:10:27 +0200 | [diff] [blame] | 467 | rc = handle_instruction(vcpu); |
| 468 | break; |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 469 | case ICPT_PROGI: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 470 | return handle_prog(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 471 | case ICPT_EXTINT: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 472 | return handle_external_interrupt(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 473 | case ICPT_WAIT: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 474 | return kvm_s390_handle_wait(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 475 | case ICPT_VALIDITY: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 476 | return handle_validity(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 477 | case ICPT_STOP: |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 478 | return handle_stop(vcpu); |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 479 | case ICPT_OPEREXC: |
David Hildenbrand | 5ffe466 | 2016-05-24 12:10:27 +0200 | [diff] [blame] | 480 | rc = handle_operexc(vcpu); |
| 481 | break; |
Farhan Ali | 947b897 | 2017-03-17 09:59:32 -0400 | [diff] [blame] | 482 | case ICPT_PARTEXEC: |
David Hildenbrand | 5ffe466 | 2016-05-24 12:10:27 +0200 | [diff] [blame] | 483 | rc = handle_partial_execution(vcpu); |
| 484 | break; |
Farhan Ali | 730cd63 | 2017-02-24 16:12:56 -0500 | [diff] [blame] | 485 | case ICPT_KSS: |
| 486 | rc = kvm_s390_skey_check_enable(vcpu); |
| 487 | break; |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 488 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 489 | return -EOPNOTSUPP; |
Christian Borntraeger | 46b708e | 2015-07-23 15:24:03 +0200 | [diff] [blame] | 490 | } |
David Hildenbrand | 5ffe466 | 2016-05-24 12:10:27 +0200 | [diff] [blame] | 491 | |
| 492 | /* process PER, also if the instrution is processed in user space */ |
| 493 | if (vcpu->arch.sie_block->icptstatus & 0x02 && |
| 494 | (!rc || rc == -EOPNOTSUPP)) |
| 495 | per_rc = kvm_s390_handle_per_ifetch_icpt(vcpu); |
| 496 | return per_rc ? per_rc : rc; |
Christian Borntraeger | 8f2abe6 | 2008-03-25 18:47:23 +0100 | [diff] [blame] | 497 | } |