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> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 19 | #include <asm/current.h> |
| 20 | #include <asm/debug.h> |
| 21 | #include <asm/ebcdic.h> |
| 22 | #include <asm/sysinfo.h> |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 23 | #include <asm/pgtable.h> |
| 24 | #include <asm/pgalloc.h> |
| 25 | #include <asm/io.h> |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 26 | #include <asm/ptrace.h> |
| 27 | #include <asm/compat.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 28 | #include "gaccess.h" |
| 29 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 30 | #include "trace.h" |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 31 | |
| 32 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
| 33 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 34 | u64 operand2; |
| 35 | u32 address = 0; |
| 36 | u8 tmp; |
| 37 | |
| 38 | vcpu->stat.instruction_spx++; |
| 39 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 40 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 41 | |
| 42 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 43 | if (operand2 & 3) |
| 44 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 45 | |
| 46 | /* get the value */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 47 | if (get_guest(vcpu, address, (u32 __user *) operand2)) |
| 48 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 49 | |
| 50 | address = address & 0x7fffe000u; |
| 51 | |
| 52 | /* make sure that the new value is valid memory */ |
| 53 | if (copy_from_guest_absolute(vcpu, &tmp, address, 1) || |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 54 | (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1))) |
| 55 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 56 | |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 57 | kvm_s390_set_prefix(vcpu, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 58 | |
| 59 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 60 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int handle_store_prefix(struct kvm_vcpu *vcpu) |
| 65 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 66 | u64 operand2; |
| 67 | u32 address; |
| 68 | |
| 69 | vcpu->stat.instruction_stpx++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 70 | |
| 71 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 72 | |
| 73 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 74 | if (operand2 & 3) |
| 75 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 76 | |
| 77 | address = vcpu->arch.sie_block->prefix; |
| 78 | address = address & 0x7fffe000u; |
| 79 | |
| 80 | /* get the value */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 81 | if (put_guest(vcpu, address, (u32 __user *)operand2)) |
| 82 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 83 | |
| 84 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 85 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) |
| 90 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 91 | u64 useraddr; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 92 | |
| 93 | vcpu->stat.instruction_stap++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 94 | |
| 95 | useraddr = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 96 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 97 | if (useraddr & 1) |
| 98 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 99 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 100 | if (put_guest(vcpu, vcpu->vcpu_id, (u16 __user *)useraddr)) |
| 101 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 102 | |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 103 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 104 | trace_kvm_s390_handle_stap(vcpu, useraddr); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static int handle_skey(struct kvm_vcpu *vcpu) |
| 109 | { |
| 110 | vcpu->stat.instruction_storage_key++; |
Martin Schwidefsky | dfcf7dc | 2013-05-17 14:41:32 +0200 | [diff] [blame] | 111 | vcpu->arch.sie_block->gpsw.addr = |
| 112 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 113 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
| 114 | return 0; |
| 115 | } |
| 116 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 117 | static int handle_tpi(struct kvm_vcpu *vcpu) |
| 118 | { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 119 | struct kvm_s390_interrupt_info *inti; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 120 | u64 addr; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 121 | int cc; |
| 122 | |
| 123 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 124 | if (addr & 3) |
| 125 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 126 | cc = 0; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 127 | inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->run->s.regs.crs[6], 0); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 128 | if (!inti) |
| 129 | goto no_interrupt; |
| 130 | cc = 1; |
| 131 | if (addr) { |
| 132 | /* |
| 133 | * Store the two-word I/O interruption code into the |
| 134 | * provided area. |
| 135 | */ |
Heiko Carstens | 0a75ca2 | 2013-03-05 13:14:47 +0100 | [diff] [blame] | 136 | put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) addr); |
| 137 | put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) (addr + 2)); |
| 138 | put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) (addr + 4)); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 139 | } else { |
| 140 | /* |
| 141 | * Store the three-word I/O interruption code into |
| 142 | * the appropriate lowcore area. |
| 143 | */ |
Heiko Carstens | 0a75ca2 | 2013-03-05 13:14:47 +0100 | [diff] [blame] | 144 | put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID); |
| 145 | put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR); |
| 146 | put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM); |
| 147 | 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] | 148 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 149 | kfree(inti); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 150 | no_interrupt: |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 151 | /* Set condition code and we're done. */ |
| 152 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 153 | vcpu->arch.sie_block->gpsw.mask |= (cc & 3ul) << 44; |
| 154 | return 0; |
| 155 | } |
| 156 | |
| 157 | static int handle_tsch(struct kvm_vcpu *vcpu) |
| 158 | { |
| 159 | struct kvm_s390_interrupt_info *inti; |
| 160 | |
| 161 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, |
| 162 | vcpu->run->s.regs.gprs[1]); |
| 163 | |
| 164 | /* |
| 165 | * Prepare exit to userspace. |
| 166 | * We indicate whether we dequeued a pending I/O interrupt |
| 167 | * so that userspace can re-inject it if the instruction gets |
| 168 | * a program check. While this may re-order the pending I/O |
| 169 | * interrupts, this is no problem since the priority is kept |
| 170 | * intact. |
| 171 | */ |
| 172 | vcpu->run->exit_reason = KVM_EXIT_S390_TSCH; |
| 173 | vcpu->run->s390_tsch.dequeued = !!inti; |
| 174 | if (inti) { |
| 175 | vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id; |
| 176 | vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr; |
| 177 | vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm; |
| 178 | vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word; |
| 179 | } |
| 180 | vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb; |
| 181 | kfree(inti); |
| 182 | return -EREMOTE; |
| 183 | } |
| 184 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 185 | static int handle_io_inst(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 186 | { |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 187 | VCPU_EVENT(vcpu, 4, "%s", "I/O instruction"); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 188 | |
| 189 | if (vcpu->kvm->arch.css_support) { |
| 190 | /* |
| 191 | * Most I/O instructions will be handled by userspace. |
| 192 | * Exceptions are tpi and the interrupt portion of tsch. |
| 193 | */ |
| 194 | if (vcpu->arch.sie_block->ipa == 0xb236) |
| 195 | return handle_tpi(vcpu); |
| 196 | if (vcpu->arch.sie_block->ipa == 0xb235) |
| 197 | return handle_tsch(vcpu); |
| 198 | /* Handle in userspace. */ |
| 199 | return -EOPNOTSUPP; |
| 200 | } else { |
| 201 | /* |
| 202 | * Set condition code 3 to stop the guest from issueing channel |
| 203 | * I/O instructions. |
| 204 | */ |
| 205 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 206 | vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44; |
| 207 | return 0; |
| 208 | } |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 211 | static int handle_stfl(struct kvm_vcpu *vcpu) |
| 212 | { |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 213 | unsigned int facility_list; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 214 | int rc; |
| 215 | |
| 216 | vcpu->stat.instruction_stfl++; |
Christian Borntraeger | a0046b6 | 2008-08-29 13:29:45 +0200 | [diff] [blame] | 217 | /* only pass the facility bits, which we can handle */ |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 218 | facility_list = S390_lowcore.stfl_fac_list & 0xff82fff3; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 219 | |
| 220 | rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
| 221 | &facility_list, sizeof(facility_list)); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 222 | if (rc) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 223 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 224 | VCPU_EVENT(vcpu, 5, "store facility list value %x", facility_list); |
| 225 | trace_kvm_s390_handle_stfl(vcpu, facility_list); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 226 | return 0; |
| 227 | } |
| 228 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 229 | static void handle_new_psw(struct kvm_vcpu *vcpu) |
| 230 | { |
| 231 | /* Check whether the new psw is enabled for machine checks. */ |
| 232 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK) |
| 233 | kvm_s390_deliver_pending_machine_checks(vcpu); |
| 234 | } |
| 235 | |
| 236 | #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA) |
| 237 | #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL |
Heiko Carstens | d21683e | 2013-03-25 17:22:49 +0100 | [diff] [blame] | 238 | #define PSW_ADDR_24 0x0000000000ffffffUL |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 239 | #define PSW_ADDR_31 0x000000007fffffffUL |
| 240 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 241 | static int is_valid_psw(psw_t *psw) { |
| 242 | if (psw->mask & PSW_MASK_UNASSIGNED) |
| 243 | return 0; |
| 244 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) { |
| 245 | if (psw->addr & ~PSW_ADDR_31) |
| 246 | return 0; |
| 247 | } |
| 248 | if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24)) |
| 249 | return 0; |
| 250 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA) |
| 251 | return 0; |
| 252 | return 1; |
| 253 | } |
| 254 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 255 | int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) |
| 256 | { |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 257 | psw_t *gpsw = &vcpu->arch.sie_block->gpsw; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 258 | psw_compat_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 259 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 260 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 261 | if (gpsw->mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 262 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 263 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 264 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 265 | if (addr & 7) |
| 266 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 267 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 268 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 269 | if (!(new_psw.mask & PSW32_MASK_BASE)) |
| 270 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 271 | gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32; |
| 272 | gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE; |
| 273 | gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE; |
| 274 | if (!is_valid_psw(gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 275 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 276 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | static int handle_lpswe(struct kvm_vcpu *vcpu) |
| 281 | { |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 282 | psw_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 283 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 284 | |
| 285 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 286 | if (addr & 7) |
| 287 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 288 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 289 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 290 | vcpu->arch.sie_block->gpsw = new_psw; |
| 291 | if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 292 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 293 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 297 | static int handle_stidp(struct kvm_vcpu *vcpu) |
| 298 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 299 | u64 operand2; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 300 | |
| 301 | vcpu->stat.instruction_stidp++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 302 | |
| 303 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 304 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 305 | if (operand2 & 7) |
| 306 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 307 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 308 | if (put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2)) |
| 309 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 310 | |
| 311 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) |
| 316 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 317 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 318 | int cpus = 0; |
| 319 | int n; |
| 320 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 321 | spin_lock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 322 | for (n = 0; n < KVM_MAX_VCPUS; n++) |
| 323 | if (fi->local_int[n]) |
| 324 | cpus++; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 325 | spin_unlock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 326 | |
| 327 | /* deal with other level 3 hypervisors */ |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 328 | if (stsi(mem, 3, 2, 2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 329 | mem->count = 0; |
| 330 | if (mem->count < 8) |
| 331 | mem->count++; |
| 332 | for (n = mem->count - 1; n > 0 ; n--) |
| 333 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); |
| 334 | |
| 335 | mem->vm[0].cpus_total = cpus; |
| 336 | mem->vm[0].cpus_configured = cpus; |
| 337 | mem->vm[0].cpus_standby = 0; |
| 338 | mem->vm[0].cpus_reserved = 0; |
| 339 | mem->vm[0].caf = 1000; |
| 340 | memcpy(mem->vm[0].name, "KVMguest", 8); |
| 341 | ASCEBC(mem->vm[0].name, 8); |
| 342 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); |
| 343 | ASCEBC(mem->vm[0].cpi, 16); |
| 344 | } |
| 345 | |
| 346 | static int handle_stsi(struct kvm_vcpu *vcpu) |
| 347 | { |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 348 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
| 349 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; |
| 350 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 351 | unsigned long mem = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 352 | u64 operand2; |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 353 | int rc = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 354 | |
| 355 | vcpu->stat.instruction_stsi++; |
| 356 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); |
| 357 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 358 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 359 | |
| 360 | if (operand2 & 0xfff && fc > 0) |
| 361 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 362 | |
| 363 | switch (fc) { |
| 364 | case 0: |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 365 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 366 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 367 | return 0; |
| 368 | case 1: /* same handling for 1 and 2 */ |
| 369 | case 2: |
| 370 | mem = get_zeroed_page(GFP_KERNEL); |
| 371 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 372 | goto out_no_data; |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 373 | if (stsi((void *) mem, fc, sel1, sel2)) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 374 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 375 | break; |
| 376 | case 3: |
| 377 | if (sel1 != 2 || sel2 != 2) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 378 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 379 | mem = get_zeroed_page(GFP_KERNEL); |
| 380 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 381 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 382 | handle_stsi_3_2_2(vcpu, (void *) mem); |
| 383 | break; |
| 384 | default: |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 385 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) { |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 389 | rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 390 | goto out_exception; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 391 | } |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 392 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 393 | free_page(mem); |
| 394 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 395 | vcpu->run->s.regs.gprs[0] = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 396 | return 0; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 397 | out_no_data: |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 398 | /* condition code 3 */ |
| 399 | vcpu->arch.sie_block->gpsw.mask |= 3ul << 44; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 400 | out_exception: |
| 401 | free_page(mem); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 402 | return rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 405 | static const intercept_handler_t b2_handlers[256] = { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 406 | [0x02] = handle_stidp, |
| 407 | [0x10] = handle_set_prefix, |
| 408 | [0x11] = handle_store_prefix, |
| 409 | [0x12] = handle_store_cpu_address, |
| 410 | [0x29] = handle_skey, |
| 411 | [0x2a] = handle_skey, |
| 412 | [0x2b] = handle_skey, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 413 | [0x30] = handle_io_inst, |
| 414 | [0x31] = handle_io_inst, |
| 415 | [0x32] = handle_io_inst, |
| 416 | [0x33] = handle_io_inst, |
| 417 | [0x34] = handle_io_inst, |
| 418 | [0x35] = handle_io_inst, |
| 419 | [0x36] = handle_io_inst, |
| 420 | [0x37] = handle_io_inst, |
| 421 | [0x38] = handle_io_inst, |
| 422 | [0x39] = handle_io_inst, |
| 423 | [0x3a] = handle_io_inst, |
| 424 | [0x3b] = handle_io_inst, |
| 425 | [0x3c] = handle_io_inst, |
| 426 | [0x5f] = handle_io_inst, |
| 427 | [0x74] = handle_io_inst, |
| 428 | [0x76] = handle_io_inst, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 429 | [0x7d] = handle_stsi, |
| 430 | [0xb1] = handle_stfl, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 431 | [0xb2] = handle_lpswe, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 432 | }; |
| 433 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 434 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 435 | { |
| 436 | intercept_handler_t handler; |
| 437 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 438 | /* |
| 439 | * a lot of B2 instructions are priviledged. We first check for |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 440 | * the privileged ones, that we can handle in the kernel. If the |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 441 | * kernel can handle this instruction, we check for the problem |
| 442 | * state bit and (a) handle the instruction or (b) send a code 2 |
| 443 | * program check. |
| 444 | * Anything else goes to userspace.*/ |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 445 | handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 446 | if (handler) { |
| 447 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 448 | return kvm_s390_inject_program_int(vcpu, |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 449 | PGM_PRIVILEGED_OP); |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 450 | else |
| 451 | return handler(vcpu); |
| 452 | } |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 453 | return -EOPNOTSUPP; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 454 | } |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 455 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 456 | static int handle_epsw(struct kvm_vcpu *vcpu) |
| 457 | { |
| 458 | int reg1, reg2; |
| 459 | |
Thomas Huth | aeb87c3 | 2013-06-12 13:54:57 +0200 | [diff] [blame] | 460 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 461 | |
| 462 | /* This basically extracts the mask half of the psw. */ |
| 463 | vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000; |
| 464 | vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32; |
| 465 | if (reg2) { |
| 466 | vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000; |
| 467 | vcpu->run->s.regs.gprs[reg2] |= |
| 468 | vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffff; |
| 469 | } |
| 470 | return 0; |
| 471 | } |
| 472 | |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 473 | #define PFMF_RESERVED 0xfffc0101UL |
| 474 | #define PFMF_SK 0x00020000UL |
| 475 | #define PFMF_CF 0x00010000UL |
| 476 | #define PFMF_UI 0x00008000UL |
| 477 | #define PFMF_FSC 0x00007000UL |
| 478 | #define PFMF_NQ 0x00000800UL |
| 479 | #define PFMF_MR 0x00000400UL |
| 480 | #define PFMF_MC 0x00000200UL |
| 481 | #define PFMF_KEY 0x000000feUL |
| 482 | |
| 483 | static int handle_pfmf(struct kvm_vcpu *vcpu) |
| 484 | { |
| 485 | int reg1, reg2; |
| 486 | unsigned long start, end; |
| 487 | |
| 488 | vcpu->stat.instruction_pfmf++; |
| 489 | |
| 490 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
| 491 | |
| 492 | if (!MACHINE_HAS_PFMF) |
| 493 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 494 | |
| 495 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 496 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 497 | |
| 498 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED) |
| 499 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 500 | |
| 501 | /* Only provide non-quiescing support if the host supports it */ |
| 502 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && |
| 503 | S390_lowcore.stfl_fac_list & 0x00020000) |
| 504 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 505 | |
| 506 | /* No support for conditional-SSKE */ |
| 507 | if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC)) |
| 508 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 509 | |
| 510 | start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 511 | switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { |
| 512 | case 0x00000000: |
| 513 | end = (start + (1UL << 12)) & ~((1UL << 12) - 1); |
| 514 | break; |
| 515 | case 0x00001000: |
| 516 | end = (start + (1UL << 20)) & ~((1UL << 20) - 1); |
| 517 | break; |
| 518 | /* We dont support EDAT2 |
| 519 | case 0x00002000: |
| 520 | end = (start + (1UL << 31)) & ~((1UL << 31) - 1); |
| 521 | break;*/ |
| 522 | default: |
| 523 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 524 | } |
| 525 | while (start < end) { |
| 526 | unsigned long useraddr; |
| 527 | |
| 528 | useraddr = gmap_translate(start, vcpu->arch.gmap); |
| 529 | if (IS_ERR((void *)useraddr)) |
| 530 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 531 | |
| 532 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) { |
| 533 | if (clear_user((void __user *)useraddr, PAGE_SIZE)) |
| 534 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 535 | } |
| 536 | |
| 537 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) { |
| 538 | if (set_guest_storage_key(current->mm, useraddr, |
| 539 | vcpu->run->s.regs.gprs[reg1] & PFMF_KEY, |
| 540 | vcpu->run->s.regs.gprs[reg1] & PFMF_NQ)) |
| 541 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 542 | } |
| 543 | |
| 544 | start += PAGE_SIZE; |
| 545 | } |
| 546 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) |
| 547 | vcpu->run->s.regs.gprs[reg2] = end; |
| 548 | return 0; |
| 549 | } |
| 550 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 551 | static const intercept_handler_t b9_handlers[256] = { |
| 552 | [0x8d] = handle_epsw, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 553 | [0x9c] = handle_io_inst, |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 554 | [0xaf] = handle_pfmf, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 555 | }; |
| 556 | |
| 557 | int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) |
| 558 | { |
| 559 | intercept_handler_t handler; |
| 560 | |
| 561 | /* This is handled just as for the B2 instructions. */ |
| 562 | handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 563 | if (handler) { |
| 564 | if ((handler != handle_epsw) && |
| 565 | (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)) |
| 566 | return kvm_s390_inject_program_int(vcpu, |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 567 | PGM_PRIVILEGED_OP); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 568 | else |
| 569 | return handler(vcpu); |
| 570 | } |
| 571 | return -EOPNOTSUPP; |
| 572 | } |
| 573 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 574 | static const intercept_handler_t eb_handlers[256] = { |
| 575 | [0x8a] = handle_io_inst, |
| 576 | }; |
| 577 | |
| 578 | int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu) |
| 579 | { |
| 580 | intercept_handler_t handler; |
| 581 | |
| 582 | /* All eb instructions that end up here are privileged. */ |
| 583 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 584 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 585 | handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; |
| 586 | if (handler) |
| 587 | return handler(vcpu); |
| 588 | return -EOPNOTSUPP; |
| 589 | } |
| 590 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 591 | static int handle_tprot(struct kvm_vcpu *vcpu) |
| 592 | { |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 593 | u64 address1, address2; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 594 | struct vm_area_struct *vma; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 595 | unsigned long user_address; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 596 | |
| 597 | vcpu->stat.instruction_tprot++; |
| 598 | |
Thomas Huth | f9f6bbc | 2013-06-20 17:22:00 +0200 | [diff] [blame^] | 599 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 600 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 601 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 602 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
| 603 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 604 | /* we only handle the Linux memory detection case: |
| 605 | * access key == 0 |
| 606 | * guest DAT == off |
| 607 | * everything else goes to userspace. */ |
| 608 | if (address2 & 0xf0) |
| 609 | return -EOPNOTSUPP; |
| 610 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) |
| 611 | return -EOPNOTSUPP; |
| 612 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 613 | down_read(¤t->mm->mmap_sem); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 614 | user_address = __gmap_translate(address1, vcpu->arch.gmap); |
| 615 | if (IS_ERR_VALUE(user_address)) |
| 616 | goto out_inject; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 617 | vma = find_vma(current->mm, user_address); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 618 | if (!vma) |
| 619 | goto out_inject; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 620 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 621 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) |
| 622 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); |
| 623 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) |
| 624 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); |
| 625 | |
| 626 | up_read(¤t->mm->mmap_sem); |
| 627 | return 0; |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 628 | |
| 629 | out_inject: |
| 630 | up_read(¤t->mm->mmap_sem); |
| 631 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) |
| 635 | { |
| 636 | /* For e5xx... instructions we only handle TPROT */ |
| 637 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) |
| 638 | return handle_tprot(vcpu); |
| 639 | return -EOPNOTSUPP; |
| 640 | } |
| 641 | |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 642 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
| 643 | { |
| 644 | u32 value; |
| 645 | |
| 646 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 647 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 648 | |
| 649 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) |
| 650 | return kvm_s390_inject_program_int(vcpu, |
| 651 | PGM_SPECIFICATION); |
| 652 | |
| 653 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; |
| 654 | vcpu->arch.sie_block->todpr = value; |
| 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 659 | static const intercept_handler_t x01_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 660 | [0x07] = handle_sckpf, |
| 661 | }; |
| 662 | |
| 663 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) |
| 664 | { |
| 665 | intercept_handler_t handler; |
| 666 | |
| 667 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 668 | if (handler) |
| 669 | return handler(vcpu); |
| 670 | return -EOPNOTSUPP; |
| 671 | } |