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