Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling privileged instructions |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 3 | * |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2013 |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +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.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/gfp.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 16 | #include <linux/errno.h> |
Heiko Carstens | b13b5dc | 2013-03-25 17:22:55 +0100 | [diff] [blame] | 17 | #include <linux/compat.h> |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 18 | #include <asm/asm-offsets.h> |
Heiko Carstens | e769ece | 2013-07-26 15:04:01 +0200 | [diff] [blame] | 19 | #include <asm/facility.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 20 | #include <asm/current.h> |
| 21 | #include <asm/debug.h> |
| 22 | #include <asm/ebcdic.h> |
| 23 | #include <asm/sysinfo.h> |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/pgalloc.h> |
| 26 | #include <asm/io.h> |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 27 | #include <asm/ptrace.h> |
| 28 | #include <asm/compat.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 29 | #include "gaccess.h" |
| 30 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 31 | #include "trace.h" |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 32 | |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 33 | /* Handle SCK (SET CLOCK) interception */ |
| 34 | static int handle_set_clock(struct kvm_vcpu *vcpu) |
| 35 | { |
| 36 | struct kvm_vcpu *cpup; |
| 37 | s64 hostclk, val; |
Heiko Carstens | 0e7a3f9 | 2014-01-01 16:50:11 +0100 | [diff] [blame] | 38 | int i, rc; |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 39 | u64 op2; |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 40 | |
| 41 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 42 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 43 | |
| 44 | op2 = kvm_s390_get_base_disp_s(vcpu); |
| 45 | if (op2 & 7) /* Operand must be on a doubleword boundary */ |
| 46 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 0e7a3f9 | 2014-01-01 16:50:11 +0100 | [diff] [blame] | 47 | rc = read_guest(vcpu, op2, &val, sizeof(val)); |
| 48 | if (rc) |
| 49 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 50 | |
| 51 | if (store_tod_clock(&hostclk)) { |
| 52 | kvm_s390_set_psw_cc(vcpu, 3); |
| 53 | return 0; |
| 54 | } |
| 55 | val = (val - hostclk) & ~0x3fUL; |
| 56 | |
| 57 | mutex_lock(&vcpu->kvm->lock); |
| 58 | kvm_for_each_vcpu(i, cpup, vcpu->kvm) |
| 59 | cpup->arch.sie_block->epoch = val; |
| 60 | mutex_unlock(&vcpu->kvm->lock); |
| 61 | |
| 62 | kvm_s390_set_psw_cc(vcpu, 0); |
| 63 | return 0; |
| 64 | } |
| 65 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 66 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
| 67 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 68 | u64 operand2; |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 69 | u32 address; |
| 70 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 71 | |
| 72 | vcpu->stat.instruction_spx++; |
| 73 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 74 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 75 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 76 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 77 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 78 | |
| 79 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 80 | if (operand2 & 3) |
| 81 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 82 | |
| 83 | /* get the value */ |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 84 | rc = read_guest(vcpu, operand2, &address, sizeof(address)); |
| 85 | if (rc) |
| 86 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 87 | |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 88 | address &= 0x7fffe000u; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 89 | |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Make sure the new value is valid memory. We only need to check the |
| 92 | * first page, since address is 8k aligned and memory pieces are always |
| 93 | * at least 1MB aligned and have at least a size of 1MB. |
| 94 | */ |
| 95 | if (kvm_is_error_gpa(vcpu->kvm, address)) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 96 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 97 | |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 98 | kvm_s390_set_prefix(vcpu, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 99 | |
| 100 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 101 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int handle_store_prefix(struct kvm_vcpu *vcpu) |
| 106 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 107 | u64 operand2; |
| 108 | u32 address; |
Heiko Carstens | f748f4a | 2014-01-01 16:52:47 +0100 | [diff] [blame] | 109 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 110 | |
| 111 | vcpu->stat.instruction_stpx++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 112 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 113 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 114 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 115 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 116 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 117 | |
| 118 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 119 | if (operand2 & 3) |
| 120 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 121 | |
| 122 | address = vcpu->arch.sie_block->prefix; |
| 123 | address = address & 0x7fffe000u; |
| 124 | |
| 125 | /* get the value */ |
Heiko Carstens | f748f4a | 2014-01-01 16:52:47 +0100 | [diff] [blame] | 126 | rc = write_guest(vcpu, operand2, &address, sizeof(address)); |
| 127 | if (rc) |
| 128 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 129 | |
| 130 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 131 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) |
| 136 | { |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame] | 137 | u16 vcpu_id = vcpu->vcpu_id; |
| 138 | u64 ga; |
| 139 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 140 | |
| 141 | vcpu->stat.instruction_stap++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 142 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 143 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 144 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 145 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame] | 146 | ga = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 147 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame] | 148 | if (ga & 1) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 149 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 150 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame] | 151 | rc = write_guest(vcpu, ga, &vcpu_id, sizeof(vcpu_id)); |
| 152 | if (rc) |
| 153 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 154 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame] | 155 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", ga); |
| 156 | trace_kvm_s390_handle_stap(vcpu, ga); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 160 | static void __skey_check_enable(struct kvm_vcpu *vcpu) |
| 161 | { |
| 162 | if (!(vcpu->arch.sie_block->ictl & (ICTL_ISKE | ICTL_SSKE | ICTL_RRBE))) |
| 163 | return; |
| 164 | |
| 165 | s390_enable_skey(); |
| 166 | trace_kvm_s390_skey_related_inst(vcpu); |
| 167 | vcpu->arch.sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE | ICTL_RRBE); |
| 168 | } |
| 169 | |
| 170 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 171 | static int handle_skey(struct kvm_vcpu *vcpu) |
| 172 | { |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 173 | __skey_check_enable(vcpu); |
| 174 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 175 | vcpu->stat.instruction_storage_key++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 176 | |
| 177 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 178 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 179 | |
Martin Schwidefsky | dfcf7dc | 2013-05-17 14:41:32 +0200 | [diff] [blame] | 180 | vcpu->arch.sie_block->gpsw.addr = |
| 181 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 182 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
| 183 | return 0; |
| 184 | } |
| 185 | |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 186 | static int handle_ipte_interlock(struct kvm_vcpu *vcpu) |
| 187 | { |
| 188 | psw_t *psw = &vcpu->arch.sie_block->gpsw; |
| 189 | |
| 190 | vcpu->stat.instruction_ipte_interlock++; |
| 191 | if (psw_bits(*psw).p) |
| 192 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 193 | wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu)); |
| 194 | psw->addr = __rewind_psw(*psw, 4); |
| 195 | VCPU_EVENT(vcpu, 4, "%s", "retrying ipte interlock operation"); |
| 196 | return 0; |
| 197 | } |
| 198 | |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 199 | static int handle_test_block(struct kvm_vcpu *vcpu) |
| 200 | { |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 201 | gpa_t addr; |
| 202 | int reg2; |
| 203 | |
| 204 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 205 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 206 | |
| 207 | kvm_s390_get_regs_rre(vcpu, NULL, ®2); |
| 208 | addr = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 209 | addr = kvm_s390_real_to_abs(vcpu, addr); |
| 210 | |
Heiko Carstens | ef23e77 | 2014-01-01 16:53:49 +0100 | [diff] [blame] | 211 | if (kvm_is_error_gpa(vcpu->kvm, addr)) |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 212 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 213 | /* |
| 214 | * We don't expect errors on modern systems, and do not care |
| 215 | * about storage keys (yet), so let's just clear the page. |
| 216 | */ |
Heiko Carstens | ef23e77 | 2014-01-01 16:53:49 +0100 | [diff] [blame] | 217 | if (kvm_clear_guest(vcpu->kvm, addr, PAGE_SIZE)) |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 218 | return -EFAULT; |
| 219 | kvm_s390_set_psw_cc(vcpu, 0); |
| 220 | vcpu->run->s.regs.gprs[0] = 0; |
| 221 | return 0; |
| 222 | } |
| 223 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 224 | static int handle_tpi(struct kvm_vcpu *vcpu) |
| 225 | { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 226 | struct kvm_s390_interrupt_info *inti; |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 227 | unsigned long len; |
| 228 | u32 tpi_data[3]; |
| 229 | int cc, rc; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 230 | u64 addr; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 231 | |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 232 | rc = 0; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 233 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 234 | if (addr & 3) |
| 235 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 236 | cc = 0; |
Thomas Huth | f092669 | 2013-10-09 14:15:54 +0200 | [diff] [blame] | 237 | inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->arch.sie_block->gcr[6], 0); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 238 | if (!inti) |
| 239 | goto no_interrupt; |
| 240 | cc = 1; |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 241 | tpi_data[0] = inti->io.subchannel_id << 16 | inti->io.subchannel_nr; |
| 242 | tpi_data[1] = inti->io.io_int_parm; |
| 243 | tpi_data[2] = inti->io.io_int_word; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 244 | if (addr) { |
| 245 | /* |
| 246 | * Store the two-word I/O interruption code into the |
| 247 | * provided area. |
| 248 | */ |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 249 | len = sizeof(tpi_data) - 4; |
| 250 | rc = write_guest(vcpu, addr, &tpi_data, len); |
| 251 | if (rc) |
| 252 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 253 | } else { |
| 254 | /* |
| 255 | * Store the three-word I/O interruption code into |
| 256 | * the appropriate lowcore area. |
| 257 | */ |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 258 | len = sizeof(tpi_data); |
| 259 | if (write_guest_lc(vcpu, __LC_SUBCHANNEL_ID, &tpi_data, len)) |
| 260 | rc = -EFAULT; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 261 | } |
Cornelia Huck | 2f32d4e | 2014-01-08 18:07:54 +0100 | [diff] [blame] | 262 | /* |
| 263 | * If we encounter a problem storing the interruption code, the |
| 264 | * instruction is suppressed from the guest's view: reinject the |
| 265 | * interrupt. |
| 266 | */ |
| 267 | if (!rc) |
| 268 | kfree(inti); |
| 269 | else |
| 270 | kvm_s390_reinject_io_int(vcpu->kvm, inti); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 271 | no_interrupt: |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 272 | /* Set condition code and we're done. */ |
Heiko Carstens | 4799b55 | 2014-01-01 16:55:48 +0100 | [diff] [blame] | 273 | if (!rc) |
| 274 | kvm_s390_set_psw_cc(vcpu, cc); |
| 275 | return rc ? -EFAULT : 0; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | static int handle_tsch(struct kvm_vcpu *vcpu) |
| 279 | { |
| 280 | struct kvm_s390_interrupt_info *inti; |
| 281 | |
| 282 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, |
| 283 | vcpu->run->s.regs.gprs[1]); |
| 284 | |
| 285 | /* |
| 286 | * Prepare exit to userspace. |
| 287 | * We indicate whether we dequeued a pending I/O interrupt |
| 288 | * so that userspace can re-inject it if the instruction gets |
| 289 | * a program check. While this may re-order the pending I/O |
| 290 | * interrupts, this is no problem since the priority is kept |
| 291 | * intact. |
| 292 | */ |
| 293 | vcpu->run->exit_reason = KVM_EXIT_S390_TSCH; |
| 294 | vcpu->run->s390_tsch.dequeued = !!inti; |
| 295 | if (inti) { |
| 296 | vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id; |
| 297 | vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr; |
| 298 | vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm; |
| 299 | vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word; |
| 300 | } |
| 301 | vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb; |
| 302 | kfree(inti); |
| 303 | return -EREMOTE; |
| 304 | } |
| 305 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 306 | static int handle_io_inst(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 307 | { |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 308 | VCPU_EVENT(vcpu, 4, "%s", "I/O instruction"); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 309 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 310 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 311 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 312 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 313 | if (vcpu->kvm->arch.css_support) { |
| 314 | /* |
| 315 | * Most I/O instructions will be handled by userspace. |
| 316 | * Exceptions are tpi and the interrupt portion of tsch. |
| 317 | */ |
| 318 | if (vcpu->arch.sie_block->ipa == 0xb236) |
| 319 | return handle_tpi(vcpu); |
| 320 | if (vcpu->arch.sie_block->ipa == 0xb235) |
| 321 | return handle_tsch(vcpu); |
| 322 | /* Handle in userspace. */ |
| 323 | return -EOPNOTSUPP; |
| 324 | } else { |
| 325 | /* |
Hendrik Brueckner | b4a9601 | 2013-12-13 12:53:42 +0100 | [diff] [blame] | 326 | * Set condition code 3 to stop the guest from issuing channel |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 327 | * I/O instructions. |
| 328 | */ |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 329 | kvm_s390_set_psw_cc(vcpu, 3); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 330 | return 0; |
| 331 | } |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 334 | static int handle_stfl(struct kvm_vcpu *vcpu) |
| 335 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 336 | int rc; |
| 337 | |
| 338 | vcpu->stat.instruction_stfl++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 339 | |
| 340 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 341 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 342 | |
Heiko Carstens | 0f9701c | 2014-01-01 16:56:41 +0100 | [diff] [blame] | 343 | rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
| 344 | vfacilities, 4); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 345 | if (rc) |
Heiko Carstens | 0f9701c | 2014-01-01 16:56:41 +0100 | [diff] [blame] | 346 | return rc; |
Michael Mueller | 78c4b59 | 2013-07-26 15:04:04 +0200 | [diff] [blame] | 347 | VCPU_EVENT(vcpu, 5, "store facility list value %x", |
| 348 | *(unsigned int *) vfacilities); |
| 349 | trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 353 | static void handle_new_psw(struct kvm_vcpu *vcpu) |
| 354 | { |
| 355 | /* Check whether the new psw is enabled for machine checks. */ |
| 356 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK) |
| 357 | kvm_s390_deliver_pending_machine_checks(vcpu); |
| 358 | } |
| 359 | |
| 360 | #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA) |
| 361 | #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL |
Heiko Carstens | d21683e | 2013-03-25 17:22:49 +0100 | [diff] [blame] | 362 | #define PSW_ADDR_24 0x0000000000ffffffUL |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 363 | #define PSW_ADDR_31 0x000000007fffffffUL |
| 364 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 365 | static int is_valid_psw(psw_t *psw) { |
| 366 | if (psw->mask & PSW_MASK_UNASSIGNED) |
| 367 | return 0; |
| 368 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) { |
| 369 | if (psw->addr & ~PSW_ADDR_31) |
| 370 | return 0; |
| 371 | } |
| 372 | if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24)) |
| 373 | return 0; |
| 374 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA) |
| 375 | return 0; |
| 376 | return 1; |
| 377 | } |
| 378 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 379 | int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) |
| 380 | { |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 381 | psw_t *gpsw = &vcpu->arch.sie_block->gpsw; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 382 | psw_compat_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 383 | u64 addr; |
Heiko Carstens | 2d8bcae | 2014-01-01 16:57:42 +0100 | [diff] [blame] | 384 | int rc; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 385 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 386 | if (gpsw->mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 387 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 388 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 389 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 390 | if (addr & 7) |
| 391 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 2d8bcae | 2014-01-01 16:57:42 +0100 | [diff] [blame] | 392 | |
| 393 | rc = read_guest(vcpu, addr, &new_psw, sizeof(new_psw)); |
| 394 | if (rc) |
| 395 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 396 | if (!(new_psw.mask & PSW32_MASK_BASE)) |
| 397 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 398 | gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32; |
| 399 | gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE; |
| 400 | gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE; |
| 401 | if (!is_valid_psw(gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 402 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 403 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int handle_lpswe(struct kvm_vcpu *vcpu) |
| 408 | { |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 409 | psw_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 410 | u64 addr; |
Heiko Carstens | 2d8bcae | 2014-01-01 16:57:42 +0100 | [diff] [blame] | 411 | int rc; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 412 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 413 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 414 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 415 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 416 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 417 | if (addr & 7) |
| 418 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 2d8bcae | 2014-01-01 16:57:42 +0100 | [diff] [blame] | 419 | rc = read_guest(vcpu, addr, &new_psw, sizeof(new_psw)); |
| 420 | if (rc) |
| 421 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 422 | vcpu->arch.sie_block->gpsw = new_psw; |
| 423 | if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 424 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 425 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 426 | return 0; |
| 427 | } |
| 428 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 429 | static int handle_stidp(struct kvm_vcpu *vcpu) |
| 430 | { |
Heiko Carstens | 7d777d7 | 2014-01-01 16:58:16 +0100 | [diff] [blame^] | 431 | u64 stidp_data = vcpu->arch.stidp_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 432 | u64 operand2; |
Heiko Carstens | 7d777d7 | 2014-01-01 16:58:16 +0100 | [diff] [blame^] | 433 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 434 | |
| 435 | vcpu->stat.instruction_stidp++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 436 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 437 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 438 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 439 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 440 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 441 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 442 | if (operand2 & 7) |
| 443 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 444 | |
Heiko Carstens | 7d777d7 | 2014-01-01 16:58:16 +0100 | [diff] [blame^] | 445 | rc = write_guest(vcpu, operand2, &stidp_data, sizeof(stidp_data)); |
| 446 | if (rc) |
| 447 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 448 | |
| 449 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) |
| 454 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 455 | int cpus = 0; |
| 456 | int n; |
| 457 | |
Jens Freimann | ff520a6 | 2014-02-24 10:11:41 +0100 | [diff] [blame] | 458 | cpus = atomic_read(&vcpu->kvm->online_vcpus); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 459 | |
| 460 | /* deal with other level 3 hypervisors */ |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 461 | if (stsi(mem, 3, 2, 2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 462 | mem->count = 0; |
| 463 | if (mem->count < 8) |
| 464 | mem->count++; |
| 465 | for (n = mem->count - 1; n > 0 ; n--) |
| 466 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); |
| 467 | |
| 468 | mem->vm[0].cpus_total = cpus; |
| 469 | mem->vm[0].cpus_configured = cpus; |
| 470 | mem->vm[0].cpus_standby = 0; |
| 471 | mem->vm[0].cpus_reserved = 0; |
| 472 | mem->vm[0].caf = 1000; |
| 473 | memcpy(mem->vm[0].name, "KVMguest", 8); |
| 474 | ASCEBC(mem->vm[0].name, 8); |
| 475 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); |
| 476 | ASCEBC(mem->vm[0].cpi, 16); |
| 477 | } |
| 478 | |
| 479 | static int handle_stsi(struct kvm_vcpu *vcpu) |
| 480 | { |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 481 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
| 482 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; |
| 483 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 484 | unsigned long mem = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 485 | u64 operand2; |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 486 | int rc = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 487 | |
| 488 | vcpu->stat.instruction_stsi++; |
| 489 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); |
| 490 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 491 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 492 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 493 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 494 | if (fc > 3) { |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 495 | kvm_s390_set_psw_cc(vcpu, 3); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | if (vcpu->run->s.regs.gprs[0] & 0x0fffff00 |
| 500 | || vcpu->run->s.regs.gprs[1] & 0xffff0000) |
| 501 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 502 | |
| 503 | if (fc == 0) { |
| 504 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 505 | kvm_s390_set_psw_cc(vcpu, 0); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 506 | return 0; |
| 507 | } |
| 508 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 509 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 510 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 511 | if (operand2 & 0xfff) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 512 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 513 | |
| 514 | switch (fc) { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 515 | case 1: /* same handling for 1 and 2 */ |
| 516 | case 2: |
| 517 | mem = get_zeroed_page(GFP_KERNEL); |
| 518 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 519 | goto out_no_data; |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 520 | if (stsi((void *) mem, fc, sel1, sel2)) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 521 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 522 | break; |
| 523 | case 3: |
| 524 | if (sel1 != 2 || sel2 != 2) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 525 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 526 | mem = get_zeroed_page(GFP_KERNEL); |
| 527 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 528 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 529 | handle_stsi_3_2_2(vcpu, (void *) mem); |
| 530 | break; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) { |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 534 | rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 535 | goto out_exception; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 536 | } |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 537 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 538 | free_page(mem); |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 539 | kvm_s390_set_psw_cc(vcpu, 0); |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 540 | vcpu->run->s.regs.gprs[0] = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 541 | return 0; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 542 | out_no_data: |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 543 | kvm_s390_set_psw_cc(vcpu, 3); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 544 | out_exception: |
| 545 | free_page(mem); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 546 | return rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 549 | static const intercept_handler_t b2_handlers[256] = { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 550 | [0x02] = handle_stidp, |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 551 | [0x04] = handle_set_clock, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 552 | [0x10] = handle_set_prefix, |
| 553 | [0x11] = handle_store_prefix, |
| 554 | [0x12] = handle_store_cpu_address, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 555 | [0x21] = handle_ipte_interlock, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 556 | [0x29] = handle_skey, |
| 557 | [0x2a] = handle_skey, |
| 558 | [0x2b] = handle_skey, |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 559 | [0x2c] = handle_test_block, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 560 | [0x30] = handle_io_inst, |
| 561 | [0x31] = handle_io_inst, |
| 562 | [0x32] = handle_io_inst, |
| 563 | [0x33] = handle_io_inst, |
| 564 | [0x34] = handle_io_inst, |
| 565 | [0x35] = handle_io_inst, |
| 566 | [0x36] = handle_io_inst, |
| 567 | [0x37] = handle_io_inst, |
| 568 | [0x38] = handle_io_inst, |
| 569 | [0x39] = handle_io_inst, |
| 570 | [0x3a] = handle_io_inst, |
| 571 | [0x3b] = handle_io_inst, |
| 572 | [0x3c] = handle_io_inst, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 573 | [0x50] = handle_ipte_interlock, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 574 | [0x5f] = handle_io_inst, |
| 575 | [0x74] = handle_io_inst, |
| 576 | [0x76] = handle_io_inst, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 577 | [0x7d] = handle_stsi, |
| 578 | [0xb1] = handle_stfl, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 579 | [0xb2] = handle_lpswe, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 580 | }; |
| 581 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 582 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 583 | { |
| 584 | intercept_handler_t handler; |
| 585 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 586 | /* |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 587 | * A lot of B2 instructions are priviledged. Here we check for |
| 588 | * the privileged ones, that we can handle in the kernel. |
| 589 | * Anything else goes to userspace. |
| 590 | */ |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 591 | handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 592 | if (handler) |
| 593 | return handler(vcpu); |
| 594 | |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 595 | return -EOPNOTSUPP; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 596 | } |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 597 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 598 | static int handle_epsw(struct kvm_vcpu *vcpu) |
| 599 | { |
| 600 | int reg1, reg2; |
| 601 | |
Thomas Huth | aeb87c3 | 2013-06-12 13:54:57 +0200 | [diff] [blame] | 602 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 603 | |
| 604 | /* This basically extracts the mask half of the psw. */ |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 605 | vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 606 | vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32; |
| 607 | if (reg2) { |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 608 | vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 609 | vcpu->run->s.regs.gprs[reg2] |= |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 610 | vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffffUL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 611 | } |
| 612 | return 0; |
| 613 | } |
| 614 | |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 615 | #define PFMF_RESERVED 0xfffc0101UL |
| 616 | #define PFMF_SK 0x00020000UL |
| 617 | #define PFMF_CF 0x00010000UL |
| 618 | #define PFMF_UI 0x00008000UL |
| 619 | #define PFMF_FSC 0x00007000UL |
| 620 | #define PFMF_NQ 0x00000800UL |
| 621 | #define PFMF_MR 0x00000400UL |
| 622 | #define PFMF_MC 0x00000200UL |
| 623 | #define PFMF_KEY 0x000000feUL |
| 624 | |
| 625 | static int handle_pfmf(struct kvm_vcpu *vcpu) |
| 626 | { |
| 627 | int reg1, reg2; |
| 628 | unsigned long start, end; |
| 629 | |
| 630 | vcpu->stat.instruction_pfmf++; |
| 631 | |
| 632 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
| 633 | |
| 634 | if (!MACHINE_HAS_PFMF) |
| 635 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 636 | |
| 637 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 638 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 639 | |
| 640 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED) |
| 641 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 642 | |
| 643 | /* Only provide non-quiescing support if the host supports it */ |
Heiko Carstens | e769ece | 2013-07-26 15:04:01 +0200 | [diff] [blame] | 644 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && !test_facility(14)) |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 645 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 646 | |
| 647 | /* No support for conditional-SSKE */ |
| 648 | if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC)) |
| 649 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 650 | |
| 651 | start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 652 | switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { |
| 653 | case 0x00000000: |
| 654 | end = (start + (1UL << 12)) & ~((1UL << 12) - 1); |
| 655 | break; |
| 656 | case 0x00001000: |
| 657 | end = (start + (1UL << 20)) & ~((1UL << 20) - 1); |
| 658 | break; |
| 659 | /* We dont support EDAT2 |
| 660 | case 0x00002000: |
| 661 | end = (start + (1UL << 31)) & ~((1UL << 31) - 1); |
| 662 | break;*/ |
| 663 | default: |
| 664 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 665 | } |
| 666 | while (start < end) { |
| 667 | unsigned long useraddr; |
| 668 | |
| 669 | useraddr = gmap_translate(start, vcpu->arch.gmap); |
| 670 | if (IS_ERR((void *)useraddr)) |
| 671 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 672 | |
| 673 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) { |
| 674 | if (clear_user((void __user *)useraddr, PAGE_SIZE)) |
| 675 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 676 | } |
| 677 | |
| 678 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) { |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 679 | __skey_check_enable(vcpu); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 680 | if (set_guest_storage_key(current->mm, useraddr, |
| 681 | vcpu->run->s.regs.gprs[reg1] & PFMF_KEY, |
| 682 | vcpu->run->s.regs.gprs[reg1] & PFMF_NQ)) |
| 683 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 684 | } |
| 685 | |
| 686 | start += PAGE_SIZE; |
| 687 | } |
| 688 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) |
| 689 | vcpu->run->s.regs.gprs[reg2] = end; |
| 690 | return 0; |
| 691 | } |
| 692 | |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 693 | static int handle_essa(struct kvm_vcpu *vcpu) |
| 694 | { |
| 695 | /* entries expected to be 1FF */ |
| 696 | int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3; |
| 697 | unsigned long *cbrlo, cbrle; |
| 698 | struct gmap *gmap; |
| 699 | int i; |
| 700 | |
| 701 | VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries); |
| 702 | gmap = vcpu->arch.gmap; |
| 703 | vcpu->stat.instruction_essa++; |
Dominik Dingel | b31605c | 2014-03-25 13:47:11 +0100 | [diff] [blame] | 704 | if (!kvm_s390_cmma_enabled(vcpu->kvm)) |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 705 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 706 | |
| 707 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 708 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 709 | |
| 710 | if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6) |
| 711 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 712 | |
| 713 | /* Rewind PSW to repeat the ESSA instruction */ |
| 714 | vcpu->arch.sie_block->gpsw.addr = |
| 715 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
| 716 | vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */ |
| 717 | cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo); |
| 718 | down_read(&gmap->mm->mmap_sem); |
| 719 | for (i = 0; i < entries; ++i) { |
| 720 | cbrle = cbrlo[i]; |
| 721 | if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE)) |
| 722 | /* invalid entry */ |
| 723 | break; |
| 724 | /* try to free backing */ |
| 725 | __gmap_zap(cbrle, gmap); |
| 726 | } |
| 727 | up_read(&gmap->mm->mmap_sem); |
| 728 | if (i < entries) |
| 729 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 730 | return 0; |
| 731 | } |
| 732 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 733 | static const intercept_handler_t b9_handlers[256] = { |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 734 | [0x8a] = handle_ipte_interlock, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 735 | [0x8d] = handle_epsw, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 736 | [0x8e] = handle_ipte_interlock, |
| 737 | [0x8f] = handle_ipte_interlock, |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 738 | [0xab] = handle_essa, |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 739 | [0xaf] = handle_pfmf, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 740 | }; |
| 741 | |
| 742 | int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) |
| 743 | { |
| 744 | intercept_handler_t handler; |
| 745 | |
| 746 | /* This is handled just as for the B2 instructions. */ |
| 747 | handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 748 | if (handler) |
| 749 | return handler(vcpu); |
| 750 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 751 | return -EOPNOTSUPP; |
| 752 | } |
| 753 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 754 | int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) |
| 755 | { |
| 756 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 757 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 758 | u64 useraddr; |
| 759 | u32 val = 0; |
| 760 | int reg, rc; |
| 761 | |
| 762 | vcpu->stat.instruction_lctl++; |
| 763 | |
| 764 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 765 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 766 | |
| 767 | useraddr = kvm_s390_get_base_disp_rs(vcpu); |
| 768 | |
| 769 | if (useraddr & 3) |
| 770 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 771 | |
| 772 | VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 773 | useraddr); |
| 774 | trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr); |
| 775 | |
| 776 | reg = reg1; |
| 777 | do { |
| 778 | rc = get_guest(vcpu, val, (u32 __user *) useraddr); |
| 779 | if (rc) |
| 780 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 781 | vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul; |
| 782 | vcpu->arch.sie_block->gcr[reg] |= val; |
| 783 | useraddr += 4; |
| 784 | if (reg == reg3) |
| 785 | break; |
| 786 | reg = (reg + 1) % 16; |
| 787 | } while (1); |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | static int handle_lctlg(struct kvm_vcpu *vcpu) |
| 793 | { |
| 794 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 795 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 796 | u64 useraddr; |
| 797 | int reg, rc; |
| 798 | |
| 799 | vcpu->stat.instruction_lctlg++; |
| 800 | |
| 801 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 802 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 803 | |
| 804 | useraddr = kvm_s390_get_base_disp_rsy(vcpu); |
| 805 | |
| 806 | if (useraddr & 7) |
| 807 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 808 | |
| 809 | reg = reg1; |
| 810 | |
| 811 | VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 812 | useraddr); |
| 813 | trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr); |
| 814 | |
| 815 | do { |
| 816 | rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg], |
| 817 | (u64 __user *) useraddr); |
| 818 | if (rc) |
| 819 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 820 | useraddr += 8; |
| 821 | if (reg == reg3) |
| 822 | break; |
| 823 | reg = (reg + 1) % 16; |
| 824 | } while (1); |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 829 | static const intercept_handler_t eb_handlers[256] = { |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 830 | [0x2f] = handle_lctlg, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 831 | }; |
| 832 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 833 | int kvm_s390_handle_eb(struct kvm_vcpu *vcpu) |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 834 | { |
| 835 | intercept_handler_t handler; |
| 836 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 837 | handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; |
| 838 | if (handler) |
| 839 | return handler(vcpu); |
| 840 | return -EOPNOTSUPP; |
| 841 | } |
| 842 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 843 | static int handle_tprot(struct kvm_vcpu *vcpu) |
| 844 | { |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 845 | u64 address1, address2; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 846 | struct vm_area_struct *vma; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 847 | unsigned long user_address; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 848 | |
| 849 | vcpu->stat.instruction_tprot++; |
| 850 | |
Thomas Huth | f9f6bbc | 2013-06-20 17:22:00 +0200 | [diff] [blame] | 851 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 852 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 853 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 854 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
| 855 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 856 | /* we only handle the Linux memory detection case: |
| 857 | * access key == 0 |
| 858 | * guest DAT == off |
| 859 | * everything else goes to userspace. */ |
| 860 | if (address2 & 0xf0) |
| 861 | return -EOPNOTSUPP; |
| 862 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) |
| 863 | return -EOPNOTSUPP; |
| 864 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 865 | down_read(¤t->mm->mmap_sem); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 866 | user_address = __gmap_translate(address1, vcpu->arch.gmap); |
| 867 | if (IS_ERR_VALUE(user_address)) |
| 868 | goto out_inject; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 869 | vma = find_vma(current->mm, user_address); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 870 | if (!vma) |
| 871 | goto out_inject; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 872 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 873 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) |
| 874 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); |
| 875 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) |
| 876 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); |
| 877 | |
| 878 | up_read(¤t->mm->mmap_sem); |
| 879 | return 0; |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 880 | |
| 881 | out_inject: |
| 882 | up_read(¤t->mm->mmap_sem); |
| 883 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) |
| 887 | { |
| 888 | /* For e5xx... instructions we only handle TPROT */ |
| 889 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) |
| 890 | return handle_tprot(vcpu); |
| 891 | return -EOPNOTSUPP; |
| 892 | } |
| 893 | |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 894 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
| 895 | { |
| 896 | u32 value; |
| 897 | |
| 898 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 899 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 900 | |
| 901 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) |
| 902 | return kvm_s390_inject_program_int(vcpu, |
| 903 | PGM_SPECIFICATION); |
| 904 | |
| 905 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; |
| 906 | vcpu->arch.sie_block->todpr = value; |
| 907 | |
| 908 | return 0; |
| 909 | } |
| 910 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 911 | static const intercept_handler_t x01_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 912 | [0x07] = handle_sckpf, |
| 913 | }; |
| 914 | |
| 915 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) |
| 916 | { |
| 917 | intercept_handler_t handler; |
| 918 | |
| 919 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 920 | if (handler) |
| 921 | return handler(vcpu); |
| 922 | return -EOPNOTSUPP; |
| 923 | } |