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