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