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