Greg Kroah-Hartman | d809aa2 | 2017-11-24 15:00:33 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 2 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 3 | * handling diagnose instructions |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 4 | * |
Janosch Frank | fe28c786 | 2019-05-15 13:24:30 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 2008, 2020 |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 6 | * |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 7 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 8 | * Christian Borntraeger <borntraeger@de.ibm.com> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/kvm.h> |
| 12 | #include <linux/kvm_host.h> |
Martin Schwidefsky | 1e133ab | 2016-03-08 11:49:57 +0100 | [diff] [blame] | 13 | #include <asm/gmap.h> |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 14 | #include <asm/virtio-ccw.h> |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 15 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 16 | #include "trace.h" |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 17 | #include "trace-s390.h" |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 18 | #include "gaccess.h" |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 19 | |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 20 | static int diag_release_pages(struct kvm_vcpu *vcpu) |
| 21 | { |
| 22 | unsigned long start, end; |
Michael Mueller | fda902c | 2014-05-13 16:58:30 +0200 | [diff] [blame] | 23 | unsigned long prefix = kvm_s390_get_prefix(vcpu); |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 24 | |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 25 | start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4]; |
Heiko Carstens | 58cdf5e | 2017-07-05 07:37:14 +0200 | [diff] [blame] | 26 | end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + PAGE_SIZE; |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 27 | vcpu->stat.instruction_diagnose_10++; |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 28 | |
Christian Borntraeger | f7a960a | 2014-09-03 21:23:13 +0200 | [diff] [blame] | 29 | if (start & ~PAGE_MASK || end & ~PAGE_MASK || start >= end |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 30 | || start < 2 * PAGE_SIZE) |
| 31 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 32 | |
| 33 | VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end); |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 34 | |
Christian Borntraeger | f7a960a | 2014-09-03 21:23:13 +0200 | [diff] [blame] | 35 | /* |
| 36 | * We checked for start >= end above, so lets check for the |
| 37 | * fast path (no prefix swap page involved) |
| 38 | */ |
| 39 | if (end <= prefix || start >= prefix + 2 * PAGE_SIZE) { |
Martin Schwidefsky | 6e0a043 | 2014-04-29 09:34:41 +0200 | [diff] [blame] | 40 | gmap_discard(vcpu->arch.gmap, start, end); |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 41 | } else { |
Christian Borntraeger | f7a960a | 2014-09-03 21:23:13 +0200 | [diff] [blame] | 42 | /* |
| 43 | * This is slow path. gmap_discard will check for start |
| 44 | * so lets split this into before prefix, prefix, after |
| 45 | * prefix and let gmap_discard make some of these calls |
| 46 | * NOPs. |
| 47 | */ |
| 48 | gmap_discard(vcpu->arch.gmap, start, prefix); |
| 49 | if (start <= prefix) |
Heiko Carstens | 58cdf5e | 2017-07-05 07:37:14 +0200 | [diff] [blame] | 50 | gmap_discard(vcpu->arch.gmap, 0, PAGE_SIZE); |
| 51 | if (end > prefix + PAGE_SIZE) |
| 52 | gmap_discard(vcpu->arch.gmap, PAGE_SIZE, 2 * PAGE_SIZE); |
Christian Borntraeger | f7a960a | 2014-09-03 21:23:13 +0200 | [diff] [blame] | 53 | gmap_discard(vcpu->arch.gmap, prefix + 2 * PAGE_SIZE, end); |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 54 | } |
| 55 | return 0; |
| 56 | } |
| 57 | |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 58 | static int __diag_page_ref_service(struct kvm_vcpu *vcpu) |
| 59 | { |
| 60 | struct prs_parm { |
| 61 | u16 code; |
| 62 | u16 subcode; |
| 63 | u16 parm_len; |
| 64 | u16 parm_version; |
| 65 | u64 token_addr; |
| 66 | u64 select_mask; |
| 67 | u64 compare_mask; |
| 68 | u64 zarch; |
| 69 | }; |
| 70 | struct prs_parm parm; |
| 71 | int rc; |
| 72 | u16 rx = (vcpu->arch.sie_block->ipa & 0xf0) >> 4; |
| 73 | u16 ry = (vcpu->arch.sie_block->ipa & 0x0f); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 74 | |
Christian Borntraeger | 15e8b5d | 2015-07-09 13:43:41 +0200 | [diff] [blame] | 75 | VCPU_EVENT(vcpu, 3, "diag page reference parameter block at 0x%llx", |
| 76 | vcpu->run->s.regs.gprs[rx]); |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 77 | vcpu->stat.instruction_diagnose_258++; |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 78 | if (vcpu->run->s.regs.gprs[rx] & 7) |
| 79 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Alexander Yarygin | 8ae04b8 | 2015-01-19 13:24:51 +0300 | [diff] [blame] | 80 | rc = read_guest(vcpu, vcpu->run->s.regs.gprs[rx], rx, &parm, sizeof(parm)); |
Heiko Carstens | 81480cc | 2014-01-01 16:36:07 +0100 | [diff] [blame] | 81 | if (rc) |
| 82 | return kvm_s390_inject_prog_cond(vcpu, rc); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 83 | if (parm.parm_version != 2 || parm.parm_len < 5 || parm.code != 0x258) |
| 84 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 85 | |
| 86 | switch (parm.subcode) { |
| 87 | case 0: /* TOKEN */ |
Christian Borntraeger | ab7090a | 2015-07-16 10:24:07 +0200 | [diff] [blame] | 88 | VCPU_EVENT(vcpu, 3, "pageref token addr 0x%llx " |
| 89 | "select mask 0x%llx compare mask 0x%llx", |
| 90 | parm.token_addr, parm.select_mask, parm.compare_mask); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 91 | if (vcpu->arch.pfault_token != KVM_S390_PFAULT_TOKEN_INVALID) { |
| 92 | /* |
| 93 | * If the pagefault handshake is already activated, |
| 94 | * the token must not be changed. We have to return |
| 95 | * decimal 8 instead, as mandated in SC24-6084. |
| 96 | */ |
| 97 | vcpu->run->s.regs.gprs[ry] = 8; |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | if ((parm.compare_mask & parm.select_mask) != parm.compare_mask || |
| 102 | parm.token_addr & 7 || parm.zarch != 0x8000000000000000ULL) |
| 103 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 104 | |
Sean Christopherson | 9e7325a | 2024-02-15 15:29:03 +0000 | [diff] [blame] | 105 | if (!kvm_is_gpa_in_memslot(vcpu->kvm, parm.token_addr)) |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 106 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 107 | |
| 108 | vcpu->arch.pfault_token = parm.token_addr; |
| 109 | vcpu->arch.pfault_select = parm.select_mask; |
| 110 | vcpu->arch.pfault_compare = parm.compare_mask; |
| 111 | vcpu->run->s.regs.gprs[ry] = 0; |
| 112 | rc = 0; |
| 113 | break; |
| 114 | case 1: /* |
| 115 | * CANCEL |
| 116 | * Specification allows to let already pending tokens survive |
| 117 | * the cancel, therefore to reduce code complexity, we assume |
| 118 | * all outstanding tokens are already pending. |
| 119 | */ |
Christian Borntraeger | ab7090a | 2015-07-16 10:24:07 +0200 | [diff] [blame] | 120 | VCPU_EVENT(vcpu, 3, "pageref cancel addr 0x%llx", parm.token_addr); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 121 | if (parm.token_addr || parm.select_mask || |
| 122 | parm.compare_mask || parm.zarch) |
| 123 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 124 | |
| 125 | vcpu->run->s.regs.gprs[ry] = 0; |
| 126 | /* |
| 127 | * If the pfault handling was not established or is already |
| 128 | * canceled SC24-6084 requests to return decimal 4. |
| 129 | */ |
| 130 | if (vcpu->arch.pfault_token == KVM_S390_PFAULT_TOKEN_INVALID) |
| 131 | vcpu->run->s.regs.gprs[ry] = 4; |
| 132 | else |
| 133 | vcpu->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID; |
| 134 | |
| 135 | rc = 0; |
| 136 | break; |
| 137 | default: |
| 138 | rc = -EOPNOTSUPP; |
| 139 | break; |
| 140 | } |
| 141 | |
| 142 | return rc; |
| 143 | } |
| 144 | |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 145 | static int __diag_time_slice_end(struct kvm_vcpu *vcpu) |
| 146 | { |
| 147 | VCPU_EVENT(vcpu, 5, "%s", "diag time slice end"); |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 148 | vcpu->stat.instruction_diagnose_44++; |
Longpeng(Mike) | 0546c63 | 2017-08-08 12:05:34 +0800 | [diff] [blame] | 149 | kvm_vcpu_on_spin(vcpu, true); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 153 | static int forward_cnt; |
| 154 | static unsigned long cur_slice; |
| 155 | |
| 156 | static int diag9c_forwarding_overrun(void) |
| 157 | { |
| 158 | /* Reset the count on a new slice */ |
| 159 | if (time_after(jiffies, cur_slice)) { |
| 160 | cur_slice = jiffies; |
| 161 | forward_cnt = diag9c_forwarding_hz / HZ; |
| 162 | } |
| 163 | return forward_cnt-- <= 0 ? 1 : 0; |
| 164 | } |
| 165 | |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 166 | static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu) |
| 167 | { |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 168 | struct kvm_vcpu *tcpu; |
Christian Borntraeger | 0bc380b | 2023-05-15 10:42:34 +0200 | [diff] [blame] | 169 | int tcpu_cpu; |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 170 | int tid; |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 171 | |
| 172 | tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4]; |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 173 | vcpu->stat.instruction_diagnose_9c++; |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 174 | |
Christian Borntraeger | 8474e5c | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 175 | /* yield to self */ |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 176 | if (tid == vcpu->vcpu_id) |
Christian Borntraeger | 8474e5c | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 177 | goto no_yield; |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 178 | |
Christian Borntraeger | 8474e5c | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 179 | /* yield to invalid */ |
David Hildenbrand | e09fefd | 2015-11-05 09:03:50 +0100 | [diff] [blame] | 180 | tcpu = kvm_get_vcpu_by_id(vcpu->kvm, tid); |
Christian Borntraeger | 8474e5c | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 181 | if (!tcpu) |
| 182 | goto no_yield; |
| 183 | |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 184 | /* target guest VCPU already running */ |
Christian Borntraeger | 0bc380b | 2023-05-15 10:42:34 +0200 | [diff] [blame] | 185 | tcpu_cpu = READ_ONCE(tcpu->cpu); |
| 186 | if (tcpu_cpu >= 0) { |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 187 | if (!diag9c_forwarding_hz || diag9c_forwarding_overrun()) |
| 188 | goto no_yield; |
| 189 | |
| 190 | /* target host CPU already running */ |
Christian Borntraeger | 0bc380b | 2023-05-15 10:42:34 +0200 | [diff] [blame] | 191 | if (!vcpu_is_preempted(tcpu_cpu)) |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 192 | goto no_yield; |
Christian Borntraeger | 0bc380b | 2023-05-15 10:42:34 +0200 | [diff] [blame] | 193 | smp_yield_cpu(tcpu_cpu); |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 194 | VCPU_EVENT(vcpu, 5, |
| 195 | "diag time slice end directed to %d: yield forwarded", |
| 196 | tid); |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 197 | vcpu->stat.diag_9c_forward++; |
Pierre Morel | 87e28a1 | 2020-09-07 15:26:07 +0200 | [diff] [blame] | 198 | return 0; |
| 199 | } |
Christian Borntraeger | c7b7de6 | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 200 | |
Christian Borntraeger | 8474e5c | 2019-02-15 13:47:20 +0100 | [diff] [blame] | 201 | if (kvm_vcpu_yield_to(tcpu) <= 0) |
| 202 | goto no_yield; |
| 203 | |
| 204 | VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: done", tid); |
| 205 | return 0; |
| 206 | no_yield: |
| 207 | VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d: ignored", tid); |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 208 | vcpu->stat.diag_9c_ignored++; |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 212 | static int __diag_ipl_functions(struct kvm_vcpu *vcpu) |
| 213 | { |
| 214 | unsigned int reg = vcpu->arch.sie_block->ipa & 0xf; |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 215 | unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 216 | |
Christian Borntraeger | 15e8b5d | 2015-07-09 13:43:41 +0200 | [diff] [blame] | 217 | VCPU_EVENT(vcpu, 3, "diag ipl functions, subcode %lx", subcode); |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 218 | vcpu->stat.instruction_diagnose_308++; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 219 | switch (subcode) { |
| 220 | case 3: |
| 221 | vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR; |
| 222 | break; |
| 223 | case 4: |
| 224 | vcpu->run->s390_reset_flags = 0; |
| 225 | break; |
| 226 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 227 | return -EOPNOTSUPP; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 228 | } |
| 229 | |
Janosch Frank | fe28c786 | 2019-05-15 13:24:30 +0200 | [diff] [blame] | 230 | /* |
| 231 | * no need to check the return value of vcpu_stop as it can only have |
| 232 | * an error for protvirt, but protvirt means user cpu state |
| 233 | */ |
David Hildenbrand | 6352e4d | 2014-04-10 17:35:00 +0200 | [diff] [blame] | 234 | if (!kvm_s390_user_cpu_state_ctrl(vcpu->kvm)) |
| 235 | kvm_s390_vcpu_stop(vcpu); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 236 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM; |
| 237 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL; |
| 238 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT; |
| 239 | vcpu->run->exit_reason = KVM_EXIT_S390_RESET; |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 240 | VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx", |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 241 | vcpu->run->s390_reset_flags); |
Cornelia Huck | ade38c3 | 2012-07-23 17:20:30 +0200 | [diff] [blame] | 242 | trace_kvm_s390_request_resets(vcpu->run->s390_reset_flags); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 243 | return -EREMOTE; |
| 244 | } |
| 245 | |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 246 | static int __diag_virtio_hypercall(struct kvm_vcpu *vcpu) |
| 247 | { |
Thomas Huth | 800c106 | 2013-09-12 10:33:45 +0200 | [diff] [blame] | 248 | int ret; |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 249 | |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 250 | vcpu->stat.instruction_diagnose_500++; |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 251 | /* No virtio-ccw notification? Get out quickly. */ |
| 252 | if (!vcpu->kvm->arch.css_support || |
| 253 | (vcpu->run->s.regs.gprs[1] != KVM_S390_VIRTIO_CCW_NOTIFY)) |
| 254 | return -EOPNOTSUPP; |
| 255 | |
Christian Borntraeger | 1bb78d1 | 2016-06-07 09:57:08 +0200 | [diff] [blame] | 256 | VCPU_EVENT(vcpu, 4, "diag 0x500 schid 0x%8.8x queue 0x%x cookie 0x%llx", |
| 257 | (u32) vcpu->run->s.regs.gprs[2], |
| 258 | (u32) vcpu->run->s.regs.gprs[3], |
| 259 | vcpu->run->s.regs.gprs[4]); |
| 260 | |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 261 | /* |
| 262 | * The layout is as follows: |
| 263 | * - gpr 2 contains the subchannel id (passed as addr) |
| 264 | * - gpr 3 contains the virtqueue index (passed as datamatch) |
Cornelia Huck | 85dfe87 | 2013-07-03 16:30:54 +0200 | [diff] [blame] | 265 | * - gpr 4 contains the index on the bus (optionally) |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 266 | */ |
Nikolay Nikolaev | e32edf4 | 2015-03-26 14:39:28 +0000 | [diff] [blame] | 267 | ret = kvm_io_bus_write_cookie(vcpu, KVM_VIRTIO_CCW_NOTIFY_BUS, |
Dominik Dingel | ff1f3cb | 2013-12-09 18:30:01 +0100 | [diff] [blame] | 268 | vcpu->run->s.regs.gprs[2] & 0xffffffff, |
Cornelia Huck | 85dfe87 | 2013-07-03 16:30:54 +0200 | [diff] [blame] | 269 | 8, &vcpu->run->s.regs.gprs[3], |
| 270 | vcpu->run->s.regs.gprs[4]); |
Cornelia Huck | 85dfe87 | 2013-07-03 16:30:54 +0200 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * Return cookie in gpr 2, but don't overwrite the register if the |
| 274 | * diagnose will be handled by userspace. |
| 275 | */ |
| 276 | if (ret != -EOPNOTSUPP) |
| 277 | vcpu->run->s.regs.gprs[2] = ret; |
| 278 | /* kvm_io_bus_write_cookie returns -EOPNOTSUPP if it found no match. */ |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 279 | return ret < 0 ? ret : 0; |
| 280 | } |
| 281 | |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 282 | int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) |
| 283 | { |
Alexander Yarygin | 8ae04b8 | 2015-01-19 13:24:51 +0300 | [diff] [blame] | 284 | int code = kvm_s390_get_base_disp_rs(vcpu, NULL) & 0xffff; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 285 | |
Thomas Huth | 93e1750 | 2013-06-20 17:22:02 +0200 | [diff] [blame] | 286 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 287 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 288 | |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 289 | trace_kvm_s390_handle_diag(vcpu, code); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 290 | switch (code) { |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 291 | case 0x10: |
| 292 | return diag_release_pages(vcpu); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 293 | case 0x44: |
| 294 | return __diag_time_slice_end(vcpu); |
Konstantin Weitz | 41628d3 | 2012-04-25 15:30:38 +0200 | [diff] [blame] | 295 | case 0x9c: |
| 296 | return __diag_time_slice_end_directed(vcpu); |
Dominik Dingel | 3c038e6 | 2013-10-07 17:11:48 +0200 | [diff] [blame] | 297 | case 0x258: |
| 298 | return __diag_page_ref_service(vcpu); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 299 | case 0x308: |
| 300 | return __diag_ipl_functions(vcpu); |
Cornelia Huck | 10ccaa1 | 2013-02-28 12:33:21 +0100 | [diff] [blame] | 301 | case 0x500: |
| 302 | return __diag_virtio_hypercall(vcpu); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 303 | default: |
Christian Borntraeger | bb000f64 | 2021-07-26 17:01:08 +0200 | [diff] [blame] | 304 | vcpu->stat.instruction_diagnose_other++; |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 305 | return -EOPNOTSUPP; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 306 | } |
| 307 | } |