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