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 | * |
Thomas Huth | b13d358 | 2013-11-21 16:01:48 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2013 |
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 | { |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 26 | struct kvm_s390_local_interrupt *li; |
| 27 | struct kvm_vcpu *dst_vcpu = NULL; |
| 28 | int cpuflags; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 29 | int rc; |
| 30 | |
| 31 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 32 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 33 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 34 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 35 | if (!dst_vcpu) |
| 36 | return SIGP_CC_NOT_OPERATIONAL; |
| 37 | li = &dst_vcpu->arch.local_int; |
| 38 | |
| 39 | cpuflags = atomic_read(li->cpuflags); |
| 40 | if (!(cpuflags & (CPUSTAT_ECALL_PEND | CPUSTAT_STOPPED))) |
Cornelia Huck | 21b26c0 | 2012-06-26 16:06:41 +0200 | [diff] [blame] | 41 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
| 42 | else { |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 43 | *reg &= 0xffffffff00000000UL; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 44 | if (cpuflags & CPUSTAT_ECALL_PEND) |
Cornelia Huck | 21b26c0 | 2012-06-26 16:06:41 +0200 | [diff] [blame] | 45 | *reg |= SIGP_STATUS_EXT_CALL_PENDING; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 46 | if (cpuflags & CPUSTAT_STOPPED) |
Cornelia Huck | 21b26c0 | 2012-06-26 16:06:41 +0200 | [diff] [blame] | 47 | *reg |= SIGP_STATUS_STOPPED; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 48 | rc = SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 49 | } |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 50 | |
| 51 | VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc); |
| 52 | return rc; |
| 53 | } |
| 54 | |
| 55 | static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr) |
| 56 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 57 | struct kvm_s390_local_interrupt *li; |
| 58 | struct kvm_s390_interrupt_info *inti; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 59 | struct kvm_vcpu *dst_vcpu = NULL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 60 | |
Thomas Huth | 91880d0 | 2014-03-20 13:20:46 +0100 | [diff] [blame] | 61 | if (cpu_addr < KVM_MAX_VCPUS) |
| 62 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 63 | if (!dst_vcpu) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 64 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 65 | |
| 66 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 67 | if (!inti) |
| 68 | return -ENOMEM; |
| 69 | |
| 70 | inti->type = KVM_S390_INT_EMERGENCY; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 71 | inti->emerg.code = vcpu->vcpu_id; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 72 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 73 | li = &dst_vcpu->arch.local_int; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 74 | spin_lock_bh(&li->lock); |
| 75 | list_add_tail(&inti->list, &li->list); |
| 76 | atomic_set(&li->active, 1); |
| 77 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 78 | if (waitqueue_active(li->wq)) |
| 79 | wake_up_interruptible(li->wq); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 80 | spin_unlock_bh(&li->lock); |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 81 | VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr); |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 82 | |
| 83 | return SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Thomas Huth | b13d358 | 2013-11-21 16:01:48 +0100 | [diff] [blame] | 86 | static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr, |
| 87 | u16 asn, u64 *reg) |
| 88 | { |
| 89 | struct kvm_vcpu *dst_vcpu = NULL; |
| 90 | const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT; |
| 91 | u16 p_asn, s_asn; |
| 92 | psw_t *psw; |
| 93 | u32 flags; |
| 94 | |
| 95 | if (cpu_addr < KVM_MAX_VCPUS) |
| 96 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 97 | if (!dst_vcpu) |
| 98 | return SIGP_CC_NOT_OPERATIONAL; |
| 99 | flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags); |
| 100 | psw = &dst_vcpu->arch.sie_block->gpsw; |
| 101 | p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff; /* Primary ASN */ |
| 102 | s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff; /* Secondary ASN */ |
| 103 | |
| 104 | /* Deliver the emergency signal? */ |
| 105 | if (!(flags & CPUSTAT_STOPPED) |
| 106 | || (psw->mask & psw_int_mask) != psw_int_mask |
| 107 | || ((flags & CPUSTAT_WAIT) && psw->addr != 0) |
| 108 | || (!(flags & CPUSTAT_WAIT) && (asn == p_asn || asn == s_asn))) { |
| 109 | return __sigp_emergency(vcpu, cpu_addr); |
| 110 | } else { |
| 111 | *reg &= 0xffffffff00000000UL; |
| 112 | *reg |= SIGP_STATUS_INCORRECT_STATE; |
| 113 | return SIGP_CC_STATUS_STORED; |
| 114 | } |
| 115 | } |
| 116 | |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 117 | static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr) |
| 118 | { |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 119 | struct kvm_s390_local_interrupt *li; |
| 120 | struct kvm_s390_interrupt_info *inti; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 121 | struct kvm_vcpu *dst_vcpu = NULL; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 122 | |
Thomas Huth | 91880d0 | 2014-03-20 13:20:46 +0100 | [diff] [blame] | 123 | if (cpu_addr < KVM_MAX_VCPUS) |
| 124 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 125 | if (!dst_vcpu) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 126 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 127 | |
| 128 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 129 | if (!inti) |
| 130 | return -ENOMEM; |
| 131 | |
| 132 | inti->type = KVM_S390_INT_EXTERNAL_CALL; |
| 133 | inti->extcall.code = vcpu->vcpu_id; |
| 134 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 135 | li = &dst_vcpu->arch.local_int; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 136 | spin_lock_bh(&li->lock); |
| 137 | list_add_tail(&inti->list, &li->list); |
| 138 | atomic_set(&li->active, 1); |
| 139 | atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 140 | if (waitqueue_active(li->wq)) |
| 141 | wake_up_interruptible(li->wq); |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 142 | spin_unlock_bh(&li->lock); |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 143 | VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", cpu_addr); |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 144 | |
| 145 | return SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 148 | static int __inject_sigp_stop(struct kvm_s390_local_interrupt *li, int action) |
| 149 | { |
| 150 | struct kvm_s390_interrupt_info *inti; |
Thomas Huth | e879892 | 2013-11-06 15:46:33 +0100 | [diff] [blame] | 151 | int rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 152 | |
Julia Lawall | 9940fa8 | 2010-06-08 18:58:11 +0200 | [diff] [blame] | 153 | inti = kzalloc(sizeof(*inti), GFP_ATOMIC); |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 154 | if (!inti) |
| 155 | return -ENOMEM; |
| 156 | inti->type = KVM_S390_SIGP_STOP; |
| 157 | |
| 158 | spin_lock_bh(&li->lock); |
Cong Ding | a046b81 | 2013-01-15 11:17:29 +0100 | [diff] [blame] | 159 | if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { |
| 160 | kfree(inti); |
Thomas Huth | e879892 | 2013-11-06 15:46:33 +0100 | [diff] [blame] | 161 | if ((action & ACTION_STORE_ON_STOP) != 0) |
| 162 | rc = -ESHUTDOWN; |
Jens Freimann | 24a1304 | 2012-02-06 10:59:05 +0100 | [diff] [blame] | 163 | goto out; |
Cong Ding | a046b81 | 2013-01-15 11:17:29 +0100 | [diff] [blame] | 164 | } |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 165 | list_add_tail(&inti->list, &li->list); |
| 166 | atomic_set(&li->active, 1); |
| 167 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
| 168 | li->action_bits |= action; |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 169 | if (waitqueue_active(li->wq)) |
| 170 | wake_up_interruptible(li->wq); |
Jens Freimann | 24a1304 | 2012-02-06 10:59:05 +0100 | [diff] [blame] | 171 | out: |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 172 | spin_unlock_bh(&li->lock); |
| 173 | |
Thomas Huth | e879892 | 2013-11-06 15:46:33 +0100 | [diff] [blame] | 174 | return rc; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | 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] | 178 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 179 | struct kvm_s390_local_interrupt *li; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 180 | struct kvm_vcpu *dst_vcpu = NULL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 181 | int rc; |
| 182 | |
| 183 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 184 | return SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 185 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 186 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 187 | if (!dst_vcpu) |
| 188 | return SIGP_CC_NOT_OPERATIONAL; |
| 189 | li = &dst_vcpu->arch.local_int; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 190 | |
| 191 | rc = __inject_sigp_stop(li, action); |
| 192 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 193 | VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr); |
Thomas Huth | e879892 | 2013-11-06 15:46:33 +0100 | [diff] [blame] | 194 | |
| 195 | if ((action & ACTION_STORE_ON_STOP) != 0 && rc == -ESHUTDOWN) { |
| 196 | /* If the CPU has already been stopped, we still have |
| 197 | * to save the status when doing stop-and-store. This |
| 198 | * has to be done after unlocking all spinlocks. */ |
Thomas Huth | e879892 | 2013-11-06 15:46:33 +0100 | [diff] [blame] | 199 | rc = kvm_s390_store_status_unloaded(dst_vcpu, |
| 200 | KVM_S390_STORE_STATUS_NOADDR); |
| 201 | } |
| 202 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 203 | return rc; |
| 204 | } |
| 205 | |
| 206 | static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter) |
| 207 | { |
| 208 | int rc; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 209 | unsigned int i; |
| 210 | struct kvm_vcpu *v; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 211 | |
| 212 | switch (parameter & 0xff) { |
| 213 | case 0: |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 214 | rc = SIGP_CC_NOT_OPERATIONAL; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 215 | break; |
| 216 | case 1: |
| 217 | case 2: |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 218 | kvm_for_each_vcpu(i, v, vcpu->kvm) { |
| 219 | v->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID; |
| 220 | kvm_clear_async_pf_completion_queue(v); |
| 221 | } |
| 222 | |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 223 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 224 | break; |
| 225 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 226 | rc = -EOPNOTSUPP; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 227 | } |
| 228 | return rc; |
| 229 | } |
| 230 | |
| 231 | 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] | 232 | u64 *reg) |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 233 | { |
Thomas Huth | 13b191a | 2014-01-27 12:06:19 +0100 | [diff] [blame] | 234 | struct kvm_s390_local_interrupt *li; |
| 235 | struct kvm_vcpu *dst_vcpu = NULL; |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 236 | struct kvm_s390_interrupt_info *inti; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 237 | int rc; |
| 238 | u8 tmp; |
| 239 | |
Thomas Huth | 13b191a | 2014-01-27 12:06:19 +0100 | [diff] [blame] | 240 | if (cpu_addr < KVM_MAX_VCPUS) |
| 241 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 242 | if (!dst_vcpu) |
| 243 | return SIGP_CC_NOT_OPERATIONAL; |
| 244 | li = &dst_vcpu->arch.local_int; |
| 245 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 246 | /* make sure that the new value is valid memory */ |
| 247 | address = address & 0x7fffe000u; |
Carsten Otte | 092670c | 2011-07-24 10:48:22 +0200 | [diff] [blame] | 248 | if (copy_from_guest_absolute(vcpu, &tmp, address, 1) || |
| 249 | copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1)) { |
Heiko Carstens | 0744426 | 2012-06-26 16:06:39 +0200 | [diff] [blame] | 250 | *reg &= 0xffffffff00000000UL; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 251 | *reg |= SIGP_STATUS_INVALID_PARAMETER; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 252 | return SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); |
| 256 | if (!inti) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 257 | return SIGP_CC_BUSY; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 258 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 259 | spin_lock_bh(&li->lock); |
| 260 | /* cpu must be in stopped state */ |
Cornelia Huck | 9e6dabe | 2011-11-17 11:00:41 +0100 | [diff] [blame] | 261 | if (!(atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { |
Heiko Carstens | 0744426 | 2012-06-26 16:06:39 +0200 | [diff] [blame] | 262 | *reg &= 0xffffffff00000000UL; |
| 263 | *reg |= SIGP_STATUS_INCORRECT_STATE; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 264 | rc = SIGP_CC_STATUS_STORED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 265 | kfree(inti); |
| 266 | goto out_li; |
| 267 | } |
| 268 | |
| 269 | inti->type = KVM_S390_SIGP_SET_PREFIX; |
| 270 | inti->prefix.address = address; |
| 271 | |
| 272 | list_add_tail(&inti->list, &li->list); |
| 273 | atomic_set(&li->active, 1); |
Christian Borntraeger | d0321a2 | 2013-06-12 13:54:55 +0200 | [diff] [blame] | 274 | if (waitqueue_active(li->wq)) |
| 275 | wake_up_interruptible(li->wq); |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 276 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 277 | |
| 278 | VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x", cpu_addr, address); |
| 279 | out_li: |
| 280 | spin_unlock_bh(&li->lock); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 281 | return rc; |
| 282 | } |
| 283 | |
Thomas Huth | 00e9e43 | 2013-11-13 20:48:51 +0100 | [diff] [blame] | 284 | static int __sigp_store_status_at_addr(struct kvm_vcpu *vcpu, u16 cpu_id, |
| 285 | u32 addr, u64 *reg) |
| 286 | { |
| 287 | struct kvm_vcpu *dst_vcpu = NULL; |
| 288 | int flags; |
| 289 | int rc; |
| 290 | |
| 291 | if (cpu_id < KVM_MAX_VCPUS) |
| 292 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_id); |
| 293 | if (!dst_vcpu) |
| 294 | return SIGP_CC_NOT_OPERATIONAL; |
| 295 | |
| 296 | spin_lock_bh(&dst_vcpu->arch.local_int.lock); |
| 297 | flags = atomic_read(dst_vcpu->arch.local_int.cpuflags); |
| 298 | spin_unlock_bh(&dst_vcpu->arch.local_int.lock); |
| 299 | if (!(flags & CPUSTAT_STOPPED)) { |
| 300 | *reg &= 0xffffffff00000000UL; |
| 301 | *reg |= SIGP_STATUS_INCORRECT_STATE; |
| 302 | return SIGP_CC_STATUS_STORED; |
| 303 | } |
| 304 | |
| 305 | addr &= 0x7ffffe00; |
| 306 | rc = kvm_s390_store_status_unloaded(dst_vcpu, addr); |
| 307 | if (rc == -EFAULT) { |
| 308 | *reg &= 0xffffffff00000000UL; |
| 309 | *reg |= SIGP_STATUS_INVALID_PARAMETER; |
| 310 | rc = SIGP_CC_STATUS_STORED; |
| 311 | } |
| 312 | return rc; |
| 313 | } |
| 314 | |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 315 | static int __sigp_sense_running(struct kvm_vcpu *vcpu, u16 cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 316 | u64 *reg) |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 317 | { |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 318 | struct kvm_s390_local_interrupt *li; |
| 319 | struct kvm_vcpu *dst_vcpu = NULL; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 320 | int rc; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 321 | |
| 322 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 323 | return SIGP_CC_NOT_OPERATIONAL; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 324 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 325 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 326 | if (!dst_vcpu) |
| 327 | return SIGP_CC_NOT_OPERATIONAL; |
| 328 | li = &dst_vcpu->arch.local_int; |
| 329 | if (atomic_read(li->cpuflags) & CPUSTAT_RUNNING) { |
| 330 | /* running */ |
| 331 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
| 332 | } else { |
| 333 | /* not running */ |
| 334 | *reg &= 0xffffffff00000000UL; |
| 335 | *reg |= SIGP_STATUS_NOT_RUNNING; |
| 336 | rc = SIGP_CC_STATUS_STORED; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 337 | } |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 338 | |
| 339 | VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x", cpu_addr, |
| 340 | rc); |
| 341 | |
| 342 | return rc; |
| 343 | } |
| 344 | |
Thomas Huth | cc92d6d | 2013-11-27 11:47:10 +0100 | [diff] [blame] | 345 | /* Test whether the destination CPU is available and not busy */ |
| 346 | static int sigp_check_callable(struct kvm_vcpu *vcpu, u16 cpu_addr) |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 347 | { |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 348 | struct kvm_s390_local_interrupt *li; |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 349 | int rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 350 | struct kvm_vcpu *dst_vcpu = NULL; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 351 | |
| 352 | if (cpu_addr >= KVM_MAX_VCPUS) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 353 | return SIGP_CC_NOT_OPERATIONAL; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 354 | |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 355 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
| 356 | if (!dst_vcpu) |
| 357 | return SIGP_CC_NOT_OPERATIONAL; |
| 358 | li = &dst_vcpu->arch.local_int; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 359 | spin_lock_bh(&li->lock); |
| 360 | if (li->action_bits & ACTION_STOP_ON_STOP) |
Heiko Carstens | ea1918d | 2012-06-26 16:06:40 +0200 | [diff] [blame] | 361 | rc = SIGP_CC_BUSY; |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 362 | spin_unlock_bh(&li->lock); |
Jens Freimann | 1ee0bc5 | 2014-02-25 15:36:45 +0100 | [diff] [blame] | 363 | |
Jens Freimann | 151104a | 2012-02-08 08:28:29 +0100 | [diff] [blame] | 364 | return rc; |
| 365 | } |
| 366 | |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 367 | int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu) |
| 368 | { |
| 369 | int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 370 | int r3 = vcpu->arch.sie_block->ipa & 0x000f; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 371 | u32 parameter; |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 372 | u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 373 | u8 order_code; |
| 374 | int rc; |
| 375 | |
Christian Borntraeger | 3eb77d5 | 2008-11-17 14:50:35 +0100 | [diff] [blame] | 376 | /* sigp in userspace can exit */ |
| 377 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 378 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Christian Borntraeger | 3eb77d5 | 2008-11-17 14:50:35 +0100 | [diff] [blame] | 379 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 380 | order_code = kvm_s390_get_base_disp_rs(vcpu); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 381 | |
| 382 | if (r1 % 2) |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 383 | parameter = vcpu->run->s.regs.gprs[r1]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 384 | else |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 385 | parameter = vcpu->run->s.regs.gprs[r1 + 1]; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 386 | |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 387 | trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 388 | switch (order_code) { |
| 389 | case SIGP_SENSE: |
| 390 | vcpu->stat.instruction_sigp_sense++; |
| 391 | rc = __sigp_sense(vcpu, cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 392 | &vcpu->run->s.regs.gprs[r1]); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 393 | break; |
Christian Ehrhardt | 7697e71f | 2011-10-18 12:27:15 +0200 | [diff] [blame] | 394 | case SIGP_EXTERNAL_CALL: |
| 395 | vcpu->stat.instruction_sigp_external_call++; |
| 396 | rc = __sigp_external_call(vcpu, cpu_addr); |
| 397 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 398 | case SIGP_EMERGENCY_SIGNAL: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 399 | vcpu->stat.instruction_sigp_emergency++; |
| 400 | rc = __sigp_emergency(vcpu, cpu_addr); |
| 401 | break; |
| 402 | case SIGP_STOP: |
| 403 | vcpu->stat.instruction_sigp_stop++; |
Christian Ehrhardt | 9ace903 | 2009-05-20 15:34:55 +0200 | [diff] [blame] | 404 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STOP_ON_STOP); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 405 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 406 | case SIGP_STOP_AND_STORE_STATUS: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 407 | vcpu->stat.instruction_sigp_stop++; |
Jens Freimann | 9ec2d6d | 2012-02-06 10:59:06 +0100 | [diff] [blame] | 408 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STORE_ON_STOP | |
| 409 | ACTION_STOP_ON_STOP); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 410 | break; |
Thomas Huth | 00e9e43 | 2013-11-13 20:48:51 +0100 | [diff] [blame] | 411 | case SIGP_STORE_STATUS_AT_ADDRESS: |
| 412 | rc = __sigp_store_status_at_addr(vcpu, cpu_addr, parameter, |
| 413 | &vcpu->run->s.regs.gprs[r1]); |
| 414 | break; |
Heiko Carstens | a9ae32c | 2012-06-04 12:55:15 +0200 | [diff] [blame] | 415 | case SIGP_SET_ARCHITECTURE: |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 416 | vcpu->stat.instruction_sigp_arch++; |
| 417 | rc = __sigp_set_arch(vcpu, parameter); |
| 418 | break; |
| 419 | case SIGP_SET_PREFIX: |
| 420 | vcpu->stat.instruction_sigp_prefix++; |
| 421 | rc = __sigp_set_prefix(vcpu, cpu_addr, parameter, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 422 | &vcpu->run->s.regs.gprs[r1]); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 423 | break; |
Thomas Huth | b13d358 | 2013-11-21 16:01:48 +0100 | [diff] [blame] | 424 | case SIGP_COND_EMERGENCY_SIGNAL: |
| 425 | rc = __sigp_conditional_emergency(vcpu, cpu_addr, parameter, |
| 426 | &vcpu->run->s.regs.gprs[r1]); |
| 427 | break; |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 428 | case SIGP_SENSE_RUNNING: |
| 429 | vcpu->stat.instruction_sigp_sense_running++; |
| 430 | rc = __sigp_sense_running(vcpu, cpu_addr, |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 431 | &vcpu->run->s.regs.gprs[r1]); |
Cornelia Huck | bd59d3a | 2011-11-17 11:00:42 +0100 | [diff] [blame] | 432 | break; |
Thomas Huth | 58bc33b | 2013-12-03 12:54:55 +0100 | [diff] [blame] | 433 | case SIGP_START: |
| 434 | rc = sigp_check_callable(vcpu, cpu_addr); |
| 435 | if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) |
| 436 | rc = -EOPNOTSUPP; /* Handle START in user space */ |
| 437 | break; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 438 | case SIGP_RESTART: |
| 439 | vcpu->stat.instruction_sigp_restart++; |
Thomas Huth | cc92d6d | 2013-11-27 11:47:10 +0100 | [diff] [blame] | 440 | rc = sigp_check_callable(vcpu, cpu_addr); |
| 441 | if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) { |
| 442 | VCPU_EVENT(vcpu, 4, |
| 443 | "sigp restart %x to handle userspace", |
| 444 | cpu_addr); |
| 445 | /* user space must know about restart */ |
| 446 | rc = -EOPNOTSUPP; |
| 447 | } |
| 448 | break; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 449 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 450 | return -EOPNOTSUPP; |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | if (rc < 0) |
| 454 | return rc; |
| 455 | |
Thomas Huth | 949c007 | 2013-11-26 12:27:16 +0100 | [diff] [blame] | 456 | kvm_s390_set_psw_cc(vcpu, rc); |
Christian Borntraeger | 5288fbf | 2008-03-25 18:47:31 +0100 | [diff] [blame] | 457 | return 0; |
| 458 | } |