Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling interprocessor communication |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 3 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2009 |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +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> |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 12 | * Christian Ehrhardt <ehrhardt@de.ibm.com> |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <linux/kvm.h> |
| 16 | #include <linux/kvm_host.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 18 | #include <asm/sigp.h> |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 19 | #include "gaccess.h" |
| 20 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame^] | 21 | #include "trace.h" |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 22 | |
Martin Schwidefsky | 0096369 | 2008-07-25 15:51:00 +0200 | [diff] [blame] | 23 | static int __sigp_sense(struct kvm_vcpu *vcpu, u16 cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 24 | u64 *reg) |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 25 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 26 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 27 | int rc; |
| 28 | |
| 29 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 30 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 31 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 32 | spin_lock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 33 | if (fi->local_int[cpu_addr] == NULL) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 34 | rc = SIGP_CC_NOT_OPERATIONAL; |
Cornelia Huck | 9e6dabe | 2011-11-17 11:00:41 +0100 | [diff] [blame] | 35 | else if (!(atomic_read(fi->local_int[cpu_addr]->cpuflags) |
Cornelia Huck | 21b26c0 | 2012-06-26 16:06:41 +0200 | [diff] [blame] | 36 | & (CPUSTAT_ECALL_PEND | CPUSTAT_STOPPED))) |
| 37 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
| 38 | else { |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 39 | *reg &= 0xffffffff00000000UL; |
Cornelia Huck | 21b26c0 | 2012-06-26 16:06:41 +0200 | [diff] [blame] | 40 | if (atomic_read(fi->local_int[cpu_addr]->cpuflags) |
| 41 | & CPUSTAT_ECALL_PEND) |
| 42 | *reg |= SIGP_STATUS_EXT_CALL_PENDING; |
| 43 | if (atomic_read(fi->local_int[cpu_addr]->cpuflags) |
| 44 | & CPUSTAT_STOPPED) |
| 45 | *reg |= SIGP_STATUS_STOPPED; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 46 | rc = SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 47 | } |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 48 | spin_unlock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 49 | |
| 50 | VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc); |
| 51 | return rc; |
| 52 | } |
| 53 | |
| 54 | static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr) |
| 55 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 56 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 57 | struct kvm_s390_local_interrupt *li; |
| 58 | struct kvm_s390_interrupt_info *inti; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 59 | int rc; |
| 60 | |
| 61 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 62 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 63 | |
| 64 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 65 | if (!inti) |
| 66 | return -ENOMEM; |
| 67 | |
| 68 | inti->type = KVM_S390_INT_EMERGENCY; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 69 | inti->emerg.code = vcpu->vcpu_id; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 70 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 71 | spin_lock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 72 | li = fi->local_int[cpu_addr]; |
| 73 | if (li == NULL) { |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 74 | rc = SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 75 | kfree(inti); |
| 76 | goto unlock; |
| 77 | } |
| 78 | spin_lock_bh(&li->lock); |
| 79 | list_add_tail(&inti->list, &li->list); |
| 80 | atomic_set(&li->active, 1); |
| 81 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 82 | if (waitqueue_active(&li->wq)) |
| 83 | wake_up_interruptible(&li->wq); |
| 84 | spin_unlock_bh(&li->lock); |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 85 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 86 | VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 87 | unlock: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 88 | spin_unlock(&fi->lock); |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 89 | return rc; |
| 90 | } |
| 91 | |
| 92 | static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr) |
| 93 | { |
| 94 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 95 | struct kvm_s390_local_interrupt *li; |
| 96 | struct kvm_s390_interrupt_info *inti; |
| 97 | int rc; |
| 98 | |
| 99 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 100 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 101 | |
| 102 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 103 | if (!inti) |
| 104 | return -ENOMEM; |
| 105 | |
| 106 | inti->type = KVM_S390_INT_EXTERNAL_CALL; |
| 107 | inti->extcall.code = vcpu->vcpu_id; |
| 108 | |
| 109 | spin_lock(&fi->lock); |
| 110 | li = fi->local_int[cpu_addr]; |
| 111 | if (li == NULL) { |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 112 | rc = SIGP_CC_NOT_OPERATIONAL; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 113 | kfree(inti); |
| 114 | goto unlock; |
| 115 | } |
| 116 | spin_lock_bh(&li->lock); |
| 117 | list_add_tail(&inti->list, &li->list); |
| 118 | atomic_set(&li->active, 1); |
| 119 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
| 120 | if (waitqueue_active(&li->wq)) |
| 121 | wake_up_interruptible(&li->wq); |
| 122 | spin_unlock_bh(&li->lock); |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 123 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 124 | VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", cpu_addr); |
| 125 | unlock: |
| 126 | spin_unlock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 127 | return rc; |
| 128 | } |
| 129 | |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 130 | static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action) |
| 131 | { |
| 132 | struct kvm_s390_interrupt_info *inti; |
| 133 | |
Julia Lawall | 9940fa8 | 2010-06-08 18:58:11 +0200 | [diff] [blame] | 134 | inti = kzalloc(sizeof(*inti), GFP_ATOMIC); |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 135 | if (!inti) |
| 136 | return -ENOMEM; |
| 137 | inti->type = KVM_S390_SIGP_STOP; |
| 138 | |
| 139 | spin_lock_bh(&li->lock); |
Jens Freimann | 24a1304 | 2012-02-06 10:59:05 +0100 | [diff] [blame] | 140 | if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) |
| 141 | goto out; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 142 | list_add_tail(&inti->list, &li->list); |
| 143 | atomic_set(&li->active, 1); |
| 144 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
| 145 | li->action_bits |= action; |
| 146 | if (waitqueue_active(&li->wq)) |
| 147 | wake_up_interruptible(&li->wq); |
Jens Freimann | 24a1304 | 2012-02-06 10:59:05 +0100 | [diff] [blame] | 148 | out: |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 149 | spin_unlock_bh(&li->lock); |
| 150 | |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 151 | return SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action) |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 155 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 156 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 157 | struct kvm_s390_local_interrupt *li; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 158 | int rc; |
| 159 | |
| 160 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 161 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 162 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 163 | spin_lock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 164 | li = fi->local_int[cpu_addr]; |
| 165 | if (li == NULL) { |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 166 | rc = SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 167 | goto unlock; |
| 168 | } |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 169 | |
| 170 | rc = __inject_sigp_stop(li, action); |
| 171 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 172 | unlock: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 173 | spin_unlock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 174 | VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr); |
| 175 | return rc; |
| 176 | } |
| 177 | |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 178 | int kvm_s390_inject_sigp_stop(struct kvm_vcpu *vcpu, int action) |
| 179 | { |
| 180 | struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; |
| 181 | return __inject_sigp_stop(li, action); |
| 182 | } |
| 183 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 184 | static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter) |
| 185 | { |
| 186 | int rc; |
| 187 | |
| 188 | switch (parameter & 0xff) { |
| 189 | case 0: |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 190 | rc = SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 191 | break; |
| 192 | case 1: |
| 193 | case 2: |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 194 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 195 | break; |
| 196 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 197 | rc = -EOPNOTSUPP; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 198 | } |
| 199 | return rc; |
| 200 | } |
| 201 | |
| 202 | static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 203 | u64 *reg) |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 204 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 205 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Roel Kluin | 53cb780 | 2009-08-07 10:39:25 +0200 | [diff] [blame] | 206 | struct kvm_s390_local_interrupt *li = NULL; |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 207 | struct kvm_s390_interrupt_info *inti; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 208 | int rc; |
| 209 | u8 tmp; |
| 210 | |
| 211 | /* make sure that the new value is valid memory */ |
| 212 | address = address & 0x7fffe000u; |
Carsten Otte | 092670c | 2011-07-24 10:48:22 +0200 | [diff] [blame] | 213 | if (copy_from_guest_absolute(vcpu, &tmp, address, 1) || |
| 214 | copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1)) { |
Heiko Carstens | 0744426 | 2012-06-26 16:06:39 +0200 | [diff] [blame] | 215 | *reg &= 0xffffffff00000000UL; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 216 | *reg |= SIGP_STATUS_INVALID_PARAMETER; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 217 | return SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 221 | if (!inti) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 222 | return SIGP_CC_BUSY; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 223 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 224 | spin_lock(&fi->lock); |
Roel Kluin | 53cb780 | 2009-08-07 10:39:25 +0200 | [diff] [blame] | 225 | if (cpu_addr < KVM_MAX_VCPUS) |
| 226 | li = fi->local_int[cpu_addr]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 227 | |
Roel Kluin | 53cb780 | 2009-08-07 10:39:25 +0200 | [diff] [blame] | 228 | if (li == NULL) { |
Heiko Carstens | 0744426 | 2012-06-26 16:06:39 +0200 | [diff] [blame] | 229 | *reg &= 0xffffffff00000000UL; |
| 230 | *reg |= SIGP_STATUS_INCORRECT_STATE; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 231 | rc = SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 232 | kfree(inti); |
| 233 | goto out_fi; |
| 234 | } |
| 235 | |
| 236 | spin_lock_bh(&li->lock); |
| 237 | /* cpu must be in stopped state */ |
Cornelia Huck | 9e6dabe | 2011-11-17 11:00:41 +0100 | [diff] [blame] | 238 | if (!(atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { |
Heiko Carstens | 0744426 | 2012-06-26 16:06:39 +0200 | [diff] [blame] | 239 | *reg &= 0xffffffff00000000UL; |
| 240 | *reg |= SIGP_STATUS_INCORRECT_STATE; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 241 | rc = SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 242 | kfree(inti); |
| 243 | goto out_li; |
| 244 | } |
| 245 | |
| 246 | inti->type = KVM_S390_SIGP_SET_PREFIX; |
| 247 | inti->prefix.address = address; |
| 248 | |
| 249 | list_add_tail(&inti->list, &li->list); |
| 250 | atomic_set(&li->active, 1); |
| 251 | if (waitqueue_active(&li->wq)) |
| 252 | wake_up_interruptible(&li->wq); |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 253 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 254 | |
| 255 | VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x", cpu_addr, address); |
| 256 | out_li: |
| 257 | spin_unlock_bh(&li->lock); |
| 258 | out_fi: |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 259 | spin_unlock(&fi->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 260 | return rc; |
| 261 | } |
| 262 | |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 263 | static int __sigp_sense_running(struct kvm_vcpu *vcpu, u16 cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 264 | u64 *reg) |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 265 | { |
| 266 | int rc; |
| 267 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 268 | |
| 269 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 270 | return SIGP_CC_NOT_OPERATIONAL; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 271 | |
| 272 | spin_lock(&fi->lock); |
| 273 | if (fi->local_int[cpu_addr] == NULL) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 274 | rc = SIGP_CC_NOT_OPERATIONAL; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 275 | else { |
| 276 | if (atomic_read(fi->local_int[cpu_addr]->cpuflags) |
| 277 | & CPUSTAT_RUNNING) { |
| 278 | /* running */ |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 279 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 280 | } else { |
| 281 | /* not running */ |
| 282 | *reg &= 0xffffffff00000000UL; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 283 | *reg |= SIGP_STATUS_NOT_RUNNING; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 284 | rc = SIGP_CC_STATUS_STORED; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | spin_unlock(&fi->lock); |
| 288 | |
| 289 | VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x", cpu_addr, |
| 290 | rc); |
| 291 | |
| 292 | return rc; |
| 293 | } |
| 294 | |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 295 | static int __sigp_restart(struct kvm_vcpu *vcpu, u16 cpu_addr) |
| 296 | { |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 297 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
| 298 | struct kvm_s390_local_interrupt *li; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 299 | int rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 300 | |
| 301 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 302 | return SIGP_CC_NOT_OPERATIONAL; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 303 | |
| 304 | spin_lock(&fi->lock); |
| 305 | li = fi->local_int[cpu_addr]; |
| 306 | if (li == NULL) { |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 307 | rc = SIGP_CC_NOT_OPERATIONAL; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 308 | goto out; |
| 309 | } |
| 310 | |
| 311 | spin_lock_bh(&li->lock); |
| 312 | if (li->action_bits & ACTION_STOP_ON_STOP) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 313 | rc = SIGP_CC_BUSY; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 314 | else |
| 315 | VCPU_EVENT(vcpu, 4, "sigp restart %x to handle userspace", |
| 316 | cpu_addr); |
| 317 | spin_unlock_bh(&li->lock); |
| 318 | out: |
| 319 | spin_unlock(&fi->lock); |
| 320 | return rc; |
| 321 | } |
| 322 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 323 | int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu) |
| 324 | { |
| 325 | int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 326 | int r3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 327 | int base2 = vcpu->arch.sie_block->ipb >> 28; |
| 328 | int disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16); |
| 329 | u32 parameter; |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 330 | u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 331 | u8 order_code; |
| 332 | int rc; |
| 333 | |
Christian Borntraeger | 3eb77d5 | 2008-11-17 14:50:35 +0100 | [diff] [blame] | 334 | /* sigp in userspace can exit */ |
| 335 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 336 | return kvm_s390_inject_program_int(vcpu, |
| 337 | PGM_PRIVILEGED_OPERATION); |
| 338 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 339 | order_code = disp2; |
| 340 | if (base2) |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 341 | order_code += vcpu->run->s.regs.gprs[base2]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 342 | |
| 343 | if (r1 % 2) |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 344 | parameter = vcpu->run->s.regs.gprs[r1]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 345 | else |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 346 | parameter = vcpu->run->s.regs.gprs[r1 + 1]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 347 | |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame^] | 348 | trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 349 | switch (order_code) { |
| 350 | case SIGP_SENSE: |
| 351 | vcpu->stat.instruction_sigp_sense++; |
| 352 | rc = __sigp_sense(vcpu, cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 353 | &vcpu->run->s.regs.gprs[r1]); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 354 | break; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 355 | case SIGP_EXTERNAL_CALL: |
| 356 | vcpu->stat.instruction_sigp_external_call++; |
| 357 | rc = __sigp_external_call(vcpu, cpu_addr); |
| 358 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 359 | case SIGP_EMERGENCY_SIGNAL: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 360 | vcpu->stat.instruction_sigp_emergency++; |
| 361 | rc = __sigp_emergency(vcpu, cpu_addr); |
| 362 | break; |
| 363 | case SIGP_STOP: |
| 364 | vcpu->stat.instruction_sigp_stop++; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 365 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STOP_ON_STOP); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 366 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 367 | case SIGP_STOP_AND_STORE_STATUS: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 368 | vcpu->stat.instruction_sigp_stop++; |
Jens Freimann | 9ec2d6d | 2012-02-06 10:59:06 +0100 | [diff] [blame] | 369 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STORE_ON_STOP | |
| 370 | ACTION_STOP_ON_STOP); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 371 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 372 | case SIGP_SET_ARCHITECTURE: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 373 | vcpu->stat.instruction_sigp_arch++; |
| 374 | rc = __sigp_set_arch(vcpu, parameter); |
| 375 | break; |
| 376 | case SIGP_SET_PREFIX: |
| 377 | vcpu->stat.instruction_sigp_prefix++; |
| 378 | rc = __sigp_set_prefix(vcpu, cpu_addr, parameter, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 379 | &vcpu->run->s.regs.gprs[r1]); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 380 | break; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 381 | case SIGP_SENSE_RUNNING: |
| 382 | vcpu->stat.instruction_sigp_sense_running++; |
| 383 | rc = __sigp_sense_running(vcpu, cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 384 | &vcpu->run->s.regs.gprs[r1]); |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 385 | break; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 386 | case SIGP_RESTART: |
| 387 | vcpu->stat.instruction_sigp_restart++; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 388 | rc = __sigp_restart(vcpu, cpu_addr); |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 389 | if (rc == SIGP_CC_BUSY) |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 390 | break; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 391 | /* user space must know about restart */ |
| 392 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 393 | return -EOPNOTSUPP; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | if (rc < 0) |
| 397 | return rc; |
| 398 | |
| 399 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 400 | vcpu->arch.sie_block->gpsw.mask |= (rc & 3ul) << 44; |
| 401 | return 0; |
| 402 | } |