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