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