Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling privileged instructions |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 3 | * |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2013 |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License (version 2 only) |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 11 | * Christian Borntraeger <borntraeger@de.ibm.com> |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kvm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/gfp.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 16 | #include <linux/errno.h> |
Heiko Carstens | b13b5dc | 2013-03-25 17:22:55 +0100 | [diff] [blame] | 17 | #include <linux/compat.h> |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 18 | #include <asm/asm-offsets.h> |
Heiko Carstens | e769ece | 2013-07-26 15:04:01 +0200 | [diff] [blame] | 19 | #include <asm/facility.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 20 | #include <asm/current.h> |
| 21 | #include <asm/debug.h> |
| 22 | #include <asm/ebcdic.h> |
| 23 | #include <asm/sysinfo.h> |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 24 | #include <asm/pgtable.h> |
| 25 | #include <asm/pgalloc.h> |
| 26 | #include <asm/io.h> |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 27 | #include <asm/ptrace.h> |
| 28 | #include <asm/compat.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 29 | #include "gaccess.h" |
| 30 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 31 | #include "trace.h" |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 32 | |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 33 | /* Handle SCK (SET CLOCK) interception */ |
| 34 | static int handle_set_clock(struct kvm_vcpu *vcpu) |
| 35 | { |
| 36 | struct kvm_vcpu *cpup; |
| 37 | s64 hostclk, val; |
Heiko Carstens | 0e7a3f9 | 2014-01-01 16:50:11 +0100 | [diff] [blame] | 38 | int i, rc; |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 39 | u64 op2; |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 40 | |
| 41 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 42 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 43 | |
| 44 | op2 = kvm_s390_get_base_disp_s(vcpu); |
| 45 | if (op2 & 7) /* Operand must be on a doubleword boundary */ |
| 46 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 0e7a3f9 | 2014-01-01 16:50:11 +0100 | [diff] [blame] | 47 | rc = read_guest(vcpu, op2, &val, sizeof(val)); |
| 48 | if (rc) |
| 49 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 50 | |
| 51 | if (store_tod_clock(&hostclk)) { |
| 52 | kvm_s390_set_psw_cc(vcpu, 3); |
| 53 | return 0; |
| 54 | } |
| 55 | val = (val - hostclk) & ~0x3fUL; |
| 56 | |
| 57 | mutex_lock(&vcpu->kvm->lock); |
| 58 | kvm_for_each_vcpu(i, cpup, vcpu->kvm) |
| 59 | cpup->arch.sie_block->epoch = val; |
| 60 | mutex_unlock(&vcpu->kvm->lock); |
| 61 | |
| 62 | kvm_s390_set_psw_cc(vcpu, 0); |
| 63 | return 0; |
| 64 | } |
| 65 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 66 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
| 67 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 68 | u64 operand2; |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 69 | u32 address; |
| 70 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 71 | |
| 72 | vcpu->stat.instruction_spx++; |
| 73 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 74 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 75 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 76 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 77 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 78 | |
| 79 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 80 | if (operand2 & 3) |
| 81 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 82 | |
| 83 | /* get the value */ |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 84 | rc = read_guest(vcpu, operand2, &address, sizeof(address)); |
| 85 | if (rc) |
| 86 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 87 | |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 88 | address &= 0x7fffe000u; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 89 | |
Heiko Carstens | 665170c | 2014-01-01 16:47:12 +0100 | [diff] [blame] | 90 | /* |
| 91 | * Make sure the new value is valid memory. We only need to check the |
| 92 | * first page, since address is 8k aligned and memory pieces are always |
| 93 | * at least 1MB aligned and have at least a size of 1MB. |
| 94 | */ |
| 95 | if (kvm_is_error_gpa(vcpu->kvm, address)) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 96 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 97 | |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 98 | kvm_s390_set_prefix(vcpu, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 99 | |
| 100 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 101 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | static int handle_store_prefix(struct kvm_vcpu *vcpu) |
| 106 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 107 | u64 operand2; |
| 108 | u32 address; |
Heiko Carstens | f748f4a | 2014-01-01 16:52:47 +0100 | [diff] [blame] | 109 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 110 | |
| 111 | vcpu->stat.instruction_stpx++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 112 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 113 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 114 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 115 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 116 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 117 | |
| 118 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 119 | if (operand2 & 3) |
| 120 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 121 | |
| 122 | address = vcpu->arch.sie_block->prefix; |
| 123 | address = address & 0x7fffe000u; |
| 124 | |
| 125 | /* get the value */ |
Heiko Carstens | f748f4a | 2014-01-01 16:52:47 +0100 | [diff] [blame] | 126 | rc = write_guest(vcpu, operand2, &address, sizeof(address)); |
| 127 | if (rc) |
| 128 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 129 | |
| 130 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 131 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) |
| 136 | { |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame^] | 137 | u16 vcpu_id = vcpu->vcpu_id; |
| 138 | u64 ga; |
| 139 | int rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 140 | |
| 141 | vcpu->stat.instruction_stap++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 142 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 143 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 144 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 145 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame^] | 146 | ga = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 147 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame^] | 148 | if (ga & 1) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 149 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 150 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame^] | 151 | rc = write_guest(vcpu, ga, &vcpu_id, sizeof(vcpu_id)); |
| 152 | if (rc) |
| 153 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 154 | |
Heiko Carstens | 8b96de0 | 2014-01-01 16:53:27 +0100 | [diff] [blame^] | 155 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", ga); |
| 156 | trace_kvm_s390_handle_stap(vcpu, ga); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 160 | static void __skey_check_enable(struct kvm_vcpu *vcpu) |
| 161 | { |
| 162 | if (!(vcpu->arch.sie_block->ictl & (ICTL_ISKE | ICTL_SSKE | ICTL_RRBE))) |
| 163 | return; |
| 164 | |
| 165 | s390_enable_skey(); |
| 166 | trace_kvm_s390_skey_related_inst(vcpu); |
| 167 | vcpu->arch.sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE | ICTL_RRBE); |
| 168 | } |
| 169 | |
| 170 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 171 | static int handle_skey(struct kvm_vcpu *vcpu) |
| 172 | { |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 173 | __skey_check_enable(vcpu); |
| 174 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 175 | vcpu->stat.instruction_storage_key++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 176 | |
| 177 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 178 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 179 | |
Martin Schwidefsky | dfcf7dc | 2013-05-17 14:41:32 +0200 | [diff] [blame] | 180 | vcpu->arch.sie_block->gpsw.addr = |
| 181 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 182 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
| 183 | return 0; |
| 184 | } |
| 185 | |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 186 | static int handle_ipte_interlock(struct kvm_vcpu *vcpu) |
| 187 | { |
| 188 | psw_t *psw = &vcpu->arch.sie_block->gpsw; |
| 189 | |
| 190 | vcpu->stat.instruction_ipte_interlock++; |
| 191 | if (psw_bits(*psw).p) |
| 192 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 193 | wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu)); |
| 194 | psw->addr = __rewind_psw(*psw, 4); |
| 195 | VCPU_EVENT(vcpu, 4, "%s", "retrying ipte interlock operation"); |
| 196 | return 0; |
| 197 | } |
| 198 | |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 199 | static int handle_test_block(struct kvm_vcpu *vcpu) |
| 200 | { |
| 201 | unsigned long hva; |
| 202 | gpa_t addr; |
| 203 | int reg2; |
| 204 | |
| 205 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 206 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 207 | |
| 208 | kvm_s390_get_regs_rre(vcpu, NULL, ®2); |
| 209 | addr = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 210 | addr = kvm_s390_real_to_abs(vcpu, addr); |
| 211 | |
| 212 | hva = gfn_to_hva(vcpu->kvm, gpa_to_gfn(addr)); |
| 213 | if (kvm_is_error_hva(hva)) |
| 214 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 215 | /* |
| 216 | * We don't expect errors on modern systems, and do not care |
| 217 | * about storage keys (yet), so let's just clear the page. |
| 218 | */ |
| 219 | if (clear_user((void __user *)hva, PAGE_SIZE) != 0) |
| 220 | return -EFAULT; |
| 221 | kvm_s390_set_psw_cc(vcpu, 0); |
| 222 | vcpu->run->s.regs.gprs[0] = 0; |
| 223 | return 0; |
| 224 | } |
| 225 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 226 | static int handle_tpi(struct kvm_vcpu *vcpu) |
| 227 | { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 228 | struct kvm_s390_interrupt_info *inti; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 229 | u64 addr; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 230 | int cc; |
| 231 | |
| 232 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 233 | if (addr & 3) |
| 234 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 235 | cc = 0; |
Thomas Huth | f092669 | 2013-10-09 14:15:54 +0200 | [diff] [blame] | 236 | inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->arch.sie_block->gcr[6], 0); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 237 | if (!inti) |
| 238 | goto no_interrupt; |
| 239 | cc = 1; |
| 240 | if (addr) { |
| 241 | /* |
| 242 | * Store the two-word I/O interruption code into the |
| 243 | * provided area. |
| 244 | */ |
Thomas Huth | 133608f | 2013-06-20 17:22:03 +0200 | [diff] [blame] | 245 | if (put_guest(vcpu, inti->io.subchannel_id, (u16 __user *)addr) |
| 246 | || put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *)(addr + 2)) |
| 247 | || put_guest(vcpu, inti->io.io_int_parm, (u32 __user *)(addr + 4))) |
| 248 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 249 | } else { |
| 250 | /* |
| 251 | * Store the three-word I/O interruption code into |
| 252 | * the appropriate lowcore area. |
| 253 | */ |
Heiko Carstens | 0a75ca2 | 2013-03-05 13:14:47 +0100 | [diff] [blame] | 254 | put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID); |
| 255 | put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR); |
| 256 | put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM); |
| 257 | put_guest(vcpu, inti->io.io_int_word, (u32 __user *) __LC_IO_INT_WORD); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 258 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 259 | kfree(inti); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 260 | no_interrupt: |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 261 | /* Set condition code and we're done. */ |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 262 | kvm_s390_set_psw_cc(vcpu, cc); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | static int handle_tsch(struct kvm_vcpu *vcpu) |
| 267 | { |
| 268 | struct kvm_s390_interrupt_info *inti; |
| 269 | |
| 270 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, |
| 271 | vcpu->run->s.regs.gprs[1]); |
| 272 | |
| 273 | /* |
| 274 | * Prepare exit to userspace. |
| 275 | * We indicate whether we dequeued a pending I/O interrupt |
| 276 | * so that userspace can re-inject it if the instruction gets |
| 277 | * a program check. While this may re-order the pending I/O |
| 278 | * interrupts, this is no problem since the priority is kept |
| 279 | * intact. |
| 280 | */ |
| 281 | vcpu->run->exit_reason = KVM_EXIT_S390_TSCH; |
| 282 | vcpu->run->s390_tsch.dequeued = !!inti; |
| 283 | if (inti) { |
| 284 | vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id; |
| 285 | vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr; |
| 286 | vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm; |
| 287 | vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word; |
| 288 | } |
| 289 | vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb; |
| 290 | kfree(inti); |
| 291 | return -EREMOTE; |
| 292 | } |
| 293 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 294 | static int handle_io_inst(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 295 | { |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 296 | VCPU_EVENT(vcpu, 4, "%s", "I/O instruction"); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 297 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 298 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 299 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 300 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 301 | if (vcpu->kvm->arch.css_support) { |
| 302 | /* |
| 303 | * Most I/O instructions will be handled by userspace. |
| 304 | * Exceptions are tpi and the interrupt portion of tsch. |
| 305 | */ |
| 306 | if (vcpu->arch.sie_block->ipa == 0xb236) |
| 307 | return handle_tpi(vcpu); |
| 308 | if (vcpu->arch.sie_block->ipa == 0xb235) |
| 309 | return handle_tsch(vcpu); |
| 310 | /* Handle in userspace. */ |
| 311 | return -EOPNOTSUPP; |
| 312 | } else { |
| 313 | /* |
Hendrik Brueckner | b4a9601 | 2013-12-13 12:53:42 +0100 | [diff] [blame] | 314 | * Set condition code 3 to stop the guest from issuing channel |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 315 | * I/O instructions. |
| 316 | */ |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 317 | kvm_s390_set_psw_cc(vcpu, 3); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 318 | return 0; |
| 319 | } |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 320 | } |
| 321 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 322 | static int handle_stfl(struct kvm_vcpu *vcpu) |
| 323 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 324 | int rc; |
| 325 | |
| 326 | vcpu->stat.instruction_stfl++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 327 | |
| 328 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 329 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 330 | |
Heiko Carstens | 0f9701c | 2014-01-01 16:56:41 +0100 | [diff] [blame] | 331 | rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
| 332 | vfacilities, 4); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 333 | if (rc) |
Heiko Carstens | 0f9701c | 2014-01-01 16:56:41 +0100 | [diff] [blame] | 334 | return rc; |
Michael Mueller | 78c4b59 | 2013-07-26 15:04:04 +0200 | [diff] [blame] | 335 | VCPU_EVENT(vcpu, 5, "store facility list value %x", |
| 336 | *(unsigned int *) vfacilities); |
| 337 | trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 338 | return 0; |
| 339 | } |
| 340 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 341 | static void handle_new_psw(struct kvm_vcpu *vcpu) |
| 342 | { |
| 343 | /* Check whether the new psw is enabled for machine checks. */ |
| 344 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK) |
| 345 | kvm_s390_deliver_pending_machine_checks(vcpu); |
| 346 | } |
| 347 | |
| 348 | #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA) |
| 349 | #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL |
Heiko Carstens | d21683e | 2013-03-25 17:22:49 +0100 | [diff] [blame] | 350 | #define PSW_ADDR_24 0x0000000000ffffffUL |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 351 | #define PSW_ADDR_31 0x000000007fffffffUL |
| 352 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 353 | static int is_valid_psw(psw_t *psw) { |
| 354 | if (psw->mask & PSW_MASK_UNASSIGNED) |
| 355 | return 0; |
| 356 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) { |
| 357 | if (psw->addr & ~PSW_ADDR_31) |
| 358 | return 0; |
| 359 | } |
| 360 | if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24)) |
| 361 | return 0; |
| 362 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA) |
| 363 | return 0; |
| 364 | return 1; |
| 365 | } |
| 366 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 367 | int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) |
| 368 | { |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 369 | psw_t *gpsw = &vcpu->arch.sie_block->gpsw; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 370 | psw_compat_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 371 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 372 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 373 | if (gpsw->mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 374 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 375 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 376 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 377 | if (addr & 7) |
| 378 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 379 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 380 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 381 | if (!(new_psw.mask & PSW32_MASK_BASE)) |
| 382 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 383 | gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32; |
| 384 | gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE; |
| 385 | gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE; |
| 386 | if (!is_valid_psw(gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 387 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 388 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
| 392 | static int handle_lpswe(struct kvm_vcpu *vcpu) |
| 393 | { |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 394 | psw_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 395 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 396 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 397 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 398 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 399 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 400 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 401 | if (addr & 7) |
| 402 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 403 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 404 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 405 | vcpu->arch.sie_block->gpsw = new_psw; |
| 406 | if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 407 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 408 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 409 | return 0; |
| 410 | } |
| 411 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 412 | static int handle_stidp(struct kvm_vcpu *vcpu) |
| 413 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 414 | u64 operand2; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 415 | |
| 416 | vcpu->stat.instruction_stidp++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 417 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 418 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 419 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 420 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 421 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 422 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 423 | if (operand2 & 7) |
| 424 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 425 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 426 | if (put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2)) |
| 427 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 428 | |
| 429 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) |
| 434 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 435 | int cpus = 0; |
| 436 | int n; |
| 437 | |
Jens Freimann | ff520a6 | 2014-02-24 10:11:41 +0100 | [diff] [blame] | 438 | cpus = atomic_read(&vcpu->kvm->online_vcpus); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 439 | |
| 440 | /* deal with other level 3 hypervisors */ |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 441 | if (stsi(mem, 3, 2, 2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 442 | mem->count = 0; |
| 443 | if (mem->count < 8) |
| 444 | mem->count++; |
| 445 | for (n = mem->count - 1; n > 0 ; n--) |
| 446 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); |
| 447 | |
| 448 | mem->vm[0].cpus_total = cpus; |
| 449 | mem->vm[0].cpus_configured = cpus; |
| 450 | mem->vm[0].cpus_standby = 0; |
| 451 | mem->vm[0].cpus_reserved = 0; |
| 452 | mem->vm[0].caf = 1000; |
| 453 | memcpy(mem->vm[0].name, "KVMguest", 8); |
| 454 | ASCEBC(mem->vm[0].name, 8); |
| 455 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); |
| 456 | ASCEBC(mem->vm[0].cpi, 16); |
| 457 | } |
| 458 | |
| 459 | static int handle_stsi(struct kvm_vcpu *vcpu) |
| 460 | { |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 461 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
| 462 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; |
| 463 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 464 | unsigned long mem = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 465 | u64 operand2; |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 466 | int rc = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 467 | |
| 468 | vcpu->stat.instruction_stsi++; |
| 469 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); |
| 470 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 471 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 472 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 473 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 474 | if (fc > 3) { |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 475 | kvm_s390_set_psw_cc(vcpu, 3); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | if (vcpu->run->s.regs.gprs[0] & 0x0fffff00 |
| 480 | || vcpu->run->s.regs.gprs[1] & 0xffff0000) |
| 481 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 482 | |
| 483 | if (fc == 0) { |
| 484 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 485 | kvm_s390_set_psw_cc(vcpu, 0); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 486 | return 0; |
| 487 | } |
| 488 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 489 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 490 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 491 | if (operand2 & 0xfff) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 492 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 493 | |
| 494 | switch (fc) { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 495 | case 1: /* same handling for 1 and 2 */ |
| 496 | case 2: |
| 497 | mem = get_zeroed_page(GFP_KERNEL); |
| 498 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 499 | goto out_no_data; |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 500 | if (stsi((void *) mem, fc, sel1, sel2)) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 501 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 502 | break; |
| 503 | case 3: |
| 504 | if (sel1 != 2 || sel2 != 2) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 505 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 506 | mem = get_zeroed_page(GFP_KERNEL); |
| 507 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 508 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 509 | handle_stsi_3_2_2(vcpu, (void *) mem); |
| 510 | break; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) { |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 514 | rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 515 | goto out_exception; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 516 | } |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 517 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 518 | free_page(mem); |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 519 | kvm_s390_set_psw_cc(vcpu, 0); |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 520 | vcpu->run->s.regs.gprs[0] = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 521 | return 0; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 522 | out_no_data: |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame] | 523 | kvm_s390_set_psw_cc(vcpu, 3); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 524 | out_exception: |
| 525 | free_page(mem); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 526 | return rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 527 | } |
| 528 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 529 | static const intercept_handler_t b2_handlers[256] = { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 530 | [0x02] = handle_stidp, |
Thomas Huth | 6a3f95a | 2013-09-12 10:33:49 +0200 | [diff] [blame] | 531 | [0x04] = handle_set_clock, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 532 | [0x10] = handle_set_prefix, |
| 533 | [0x11] = handle_store_prefix, |
| 534 | [0x12] = handle_store_cpu_address, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 535 | [0x21] = handle_ipte_interlock, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 536 | [0x29] = handle_skey, |
| 537 | [0x2a] = handle_skey, |
| 538 | [0x2b] = handle_skey, |
Thomas Huth | aca8424 | 2013-09-12 10:33:48 +0200 | [diff] [blame] | 539 | [0x2c] = handle_test_block, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 540 | [0x30] = handle_io_inst, |
| 541 | [0x31] = handle_io_inst, |
| 542 | [0x32] = handle_io_inst, |
| 543 | [0x33] = handle_io_inst, |
| 544 | [0x34] = handle_io_inst, |
| 545 | [0x35] = handle_io_inst, |
| 546 | [0x36] = handle_io_inst, |
| 547 | [0x37] = handle_io_inst, |
| 548 | [0x38] = handle_io_inst, |
| 549 | [0x39] = handle_io_inst, |
| 550 | [0x3a] = handle_io_inst, |
| 551 | [0x3b] = handle_io_inst, |
| 552 | [0x3c] = handle_io_inst, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 553 | [0x50] = handle_ipte_interlock, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 554 | [0x5f] = handle_io_inst, |
| 555 | [0x74] = handle_io_inst, |
| 556 | [0x76] = handle_io_inst, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 557 | [0x7d] = handle_stsi, |
| 558 | [0xb1] = handle_stfl, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 559 | [0xb2] = handle_lpswe, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 560 | }; |
| 561 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 562 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 563 | { |
| 564 | intercept_handler_t handler; |
| 565 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 566 | /* |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 567 | * A lot of B2 instructions are priviledged. Here we check for |
| 568 | * the privileged ones, that we can handle in the kernel. |
| 569 | * Anything else goes to userspace. |
| 570 | */ |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 571 | handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 572 | if (handler) |
| 573 | return handler(vcpu); |
| 574 | |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 575 | return -EOPNOTSUPP; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 576 | } |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 577 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 578 | static int handle_epsw(struct kvm_vcpu *vcpu) |
| 579 | { |
| 580 | int reg1, reg2; |
| 581 | |
Thomas Huth | aeb87c3 | 2013-06-12 13:54:57 +0200 | [diff] [blame] | 582 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 583 | |
| 584 | /* This basically extracts the mask half of the psw. */ |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 585 | vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 586 | vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32; |
| 587 | if (reg2) { |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 588 | vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 589 | vcpu->run->s.regs.gprs[reg2] |= |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 590 | vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffffUL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 595 | #define PFMF_RESERVED 0xfffc0101UL |
| 596 | #define PFMF_SK 0x00020000UL |
| 597 | #define PFMF_CF 0x00010000UL |
| 598 | #define PFMF_UI 0x00008000UL |
| 599 | #define PFMF_FSC 0x00007000UL |
| 600 | #define PFMF_NQ 0x00000800UL |
| 601 | #define PFMF_MR 0x00000400UL |
| 602 | #define PFMF_MC 0x00000200UL |
| 603 | #define PFMF_KEY 0x000000feUL |
| 604 | |
| 605 | static int handle_pfmf(struct kvm_vcpu *vcpu) |
| 606 | { |
| 607 | int reg1, reg2; |
| 608 | unsigned long start, end; |
| 609 | |
| 610 | vcpu->stat.instruction_pfmf++; |
| 611 | |
| 612 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
| 613 | |
| 614 | if (!MACHINE_HAS_PFMF) |
| 615 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 616 | |
| 617 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 618 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 619 | |
| 620 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED) |
| 621 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 622 | |
| 623 | /* Only provide non-quiescing support if the host supports it */ |
Heiko Carstens | e769ece | 2013-07-26 15:04:01 +0200 | [diff] [blame] | 624 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && !test_facility(14)) |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 625 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 626 | |
| 627 | /* No support for conditional-SSKE */ |
| 628 | if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC)) |
| 629 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 630 | |
| 631 | start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 632 | switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { |
| 633 | case 0x00000000: |
| 634 | end = (start + (1UL << 12)) & ~((1UL << 12) - 1); |
| 635 | break; |
| 636 | case 0x00001000: |
| 637 | end = (start + (1UL << 20)) & ~((1UL << 20) - 1); |
| 638 | break; |
| 639 | /* We dont support EDAT2 |
| 640 | case 0x00002000: |
| 641 | end = (start + (1UL << 31)) & ~((1UL << 31) - 1); |
| 642 | break;*/ |
| 643 | default: |
| 644 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 645 | } |
| 646 | while (start < end) { |
| 647 | unsigned long useraddr; |
| 648 | |
| 649 | useraddr = gmap_translate(start, vcpu->arch.gmap); |
| 650 | if (IS_ERR((void *)useraddr)) |
| 651 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 652 | |
| 653 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) { |
| 654 | if (clear_user((void __user *)useraddr, PAGE_SIZE)) |
| 655 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 656 | } |
| 657 | |
| 658 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) { |
Dominik Dingel | 693ffc0 | 2014-01-14 18:11:14 +0100 | [diff] [blame] | 659 | __skey_check_enable(vcpu); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 660 | if (set_guest_storage_key(current->mm, useraddr, |
| 661 | vcpu->run->s.regs.gprs[reg1] & PFMF_KEY, |
| 662 | vcpu->run->s.regs.gprs[reg1] & PFMF_NQ)) |
| 663 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 664 | } |
| 665 | |
| 666 | start += PAGE_SIZE; |
| 667 | } |
| 668 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) |
| 669 | vcpu->run->s.regs.gprs[reg2] = end; |
| 670 | return 0; |
| 671 | } |
| 672 | |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 673 | static int handle_essa(struct kvm_vcpu *vcpu) |
| 674 | { |
| 675 | /* entries expected to be 1FF */ |
| 676 | int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3; |
| 677 | unsigned long *cbrlo, cbrle; |
| 678 | struct gmap *gmap; |
| 679 | int i; |
| 680 | |
| 681 | VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries); |
| 682 | gmap = vcpu->arch.gmap; |
| 683 | vcpu->stat.instruction_essa++; |
Dominik Dingel | b31605c | 2014-03-25 13:47:11 +0100 | [diff] [blame] | 684 | if (!kvm_s390_cmma_enabled(vcpu->kvm)) |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 685 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 686 | |
| 687 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 688 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 689 | |
| 690 | if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6) |
| 691 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 692 | |
| 693 | /* Rewind PSW to repeat the ESSA instruction */ |
| 694 | vcpu->arch.sie_block->gpsw.addr = |
| 695 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
| 696 | vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */ |
| 697 | cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo); |
| 698 | down_read(&gmap->mm->mmap_sem); |
| 699 | for (i = 0; i < entries; ++i) { |
| 700 | cbrle = cbrlo[i]; |
| 701 | if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE)) |
| 702 | /* invalid entry */ |
| 703 | break; |
| 704 | /* try to free backing */ |
| 705 | __gmap_zap(cbrle, gmap); |
| 706 | } |
| 707 | up_read(&gmap->mm->mmap_sem); |
| 708 | if (i < entries) |
| 709 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 710 | return 0; |
| 711 | } |
| 712 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 713 | static const intercept_handler_t b9_handlers[256] = { |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 714 | [0x8a] = handle_ipte_interlock, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 715 | [0x8d] = handle_epsw, |
Heiko Carstens | 8a242234 | 2014-01-10 14:33:28 +0100 | [diff] [blame] | 716 | [0x8e] = handle_ipte_interlock, |
| 717 | [0x8f] = handle_ipte_interlock, |
Konstantin Weitz | b31288f | 2013-04-17 17:36:29 +0200 | [diff] [blame] | 718 | [0xab] = handle_essa, |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 719 | [0xaf] = handle_pfmf, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 720 | }; |
| 721 | |
| 722 | int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) |
| 723 | { |
| 724 | intercept_handler_t handler; |
| 725 | |
| 726 | /* This is handled just as for the B2 instructions. */ |
| 727 | handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 728 | if (handler) |
| 729 | return handler(vcpu); |
| 730 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 731 | return -EOPNOTSUPP; |
| 732 | } |
| 733 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 734 | int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) |
| 735 | { |
| 736 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 737 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 738 | u64 useraddr; |
| 739 | u32 val = 0; |
| 740 | int reg, rc; |
| 741 | |
| 742 | vcpu->stat.instruction_lctl++; |
| 743 | |
| 744 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 745 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 746 | |
| 747 | useraddr = kvm_s390_get_base_disp_rs(vcpu); |
| 748 | |
| 749 | if (useraddr & 3) |
| 750 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 751 | |
| 752 | VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 753 | useraddr); |
| 754 | trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr); |
| 755 | |
| 756 | reg = reg1; |
| 757 | do { |
| 758 | rc = get_guest(vcpu, val, (u32 __user *) useraddr); |
| 759 | if (rc) |
| 760 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 761 | vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul; |
| 762 | vcpu->arch.sie_block->gcr[reg] |= val; |
| 763 | useraddr += 4; |
| 764 | if (reg == reg3) |
| 765 | break; |
| 766 | reg = (reg + 1) % 16; |
| 767 | } while (1); |
| 768 | |
| 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | static int handle_lctlg(struct kvm_vcpu *vcpu) |
| 773 | { |
| 774 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 775 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 776 | u64 useraddr; |
| 777 | int reg, rc; |
| 778 | |
| 779 | vcpu->stat.instruction_lctlg++; |
| 780 | |
| 781 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 782 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 783 | |
| 784 | useraddr = kvm_s390_get_base_disp_rsy(vcpu); |
| 785 | |
| 786 | if (useraddr & 7) |
| 787 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 788 | |
| 789 | reg = reg1; |
| 790 | |
| 791 | VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 792 | useraddr); |
| 793 | trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr); |
| 794 | |
| 795 | do { |
| 796 | rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg], |
| 797 | (u64 __user *) useraddr); |
| 798 | if (rc) |
| 799 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 800 | useraddr += 8; |
| 801 | if (reg == reg3) |
| 802 | break; |
| 803 | reg = (reg + 1) % 16; |
| 804 | } while (1); |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 809 | static const intercept_handler_t eb_handlers[256] = { |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 810 | [0x2f] = handle_lctlg, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 811 | }; |
| 812 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 813 | int kvm_s390_handle_eb(struct kvm_vcpu *vcpu) |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 814 | { |
| 815 | intercept_handler_t handler; |
| 816 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 817 | handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; |
| 818 | if (handler) |
| 819 | return handler(vcpu); |
| 820 | return -EOPNOTSUPP; |
| 821 | } |
| 822 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 823 | static int handle_tprot(struct kvm_vcpu *vcpu) |
| 824 | { |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 825 | u64 address1, address2; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 826 | struct vm_area_struct *vma; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 827 | unsigned long user_address; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 828 | |
| 829 | vcpu->stat.instruction_tprot++; |
| 830 | |
Thomas Huth | f9f6bbc | 2013-06-20 17:22:00 +0200 | [diff] [blame] | 831 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 832 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 833 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 834 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
| 835 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 836 | /* we only handle the Linux memory detection case: |
| 837 | * access key == 0 |
| 838 | * guest DAT == off |
| 839 | * everything else goes to userspace. */ |
| 840 | if (address2 & 0xf0) |
| 841 | return -EOPNOTSUPP; |
| 842 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) |
| 843 | return -EOPNOTSUPP; |
| 844 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 845 | down_read(¤t->mm->mmap_sem); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 846 | user_address = __gmap_translate(address1, vcpu->arch.gmap); |
| 847 | if (IS_ERR_VALUE(user_address)) |
| 848 | goto out_inject; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 849 | vma = find_vma(current->mm, user_address); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 850 | if (!vma) |
| 851 | goto out_inject; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 852 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 853 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) |
| 854 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); |
| 855 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) |
| 856 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); |
| 857 | |
| 858 | up_read(¤t->mm->mmap_sem); |
| 859 | return 0; |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 860 | |
| 861 | out_inject: |
| 862 | up_read(¤t->mm->mmap_sem); |
| 863 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) |
| 867 | { |
| 868 | /* For e5xx... instructions we only handle TPROT */ |
| 869 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) |
| 870 | return handle_tprot(vcpu); |
| 871 | return -EOPNOTSUPP; |
| 872 | } |
| 873 | |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 874 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
| 875 | { |
| 876 | u32 value; |
| 877 | |
| 878 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 879 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 880 | |
| 881 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) |
| 882 | return kvm_s390_inject_program_int(vcpu, |
| 883 | PGM_SPECIFICATION); |
| 884 | |
| 885 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; |
| 886 | vcpu->arch.sie_block->todpr = value; |
| 887 | |
| 888 | return 0; |
| 889 | } |
| 890 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 891 | static const intercept_handler_t x01_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 892 | [0x07] = handle_sckpf, |
| 893 | }; |
| 894 | |
| 895 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) |
| 896 | { |
| 897 | intercept_handler_t handler; |
| 898 | |
| 899 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 900 | if (handler) |
| 901 | return handler(vcpu); |
| 902 | return -EOPNOTSUPP; |
| 903 | } |