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