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