Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 1 | /* |
| 2 | * diag.c - handling diagnose instructions |
| 3 | * |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008,2011 |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +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> |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kvm.h> |
| 15 | #include <linux/kvm_host.h> |
| 16 | #include "kvm-s390.h" |
| 17 | |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 18 | static int diag_release_pages(struct kvm_vcpu *vcpu) |
| 19 | { |
| 20 | unsigned long start, end; |
| 21 | unsigned long prefix = vcpu->arch.sie_block->prefix; |
| 22 | |
| 23 | start = vcpu->arch.guest_gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4]; |
| 24 | end = vcpu->arch.guest_gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096; |
| 25 | |
| 26 | if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end |
| 27 | || start < 2 * PAGE_SIZE) |
| 28 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 29 | |
| 30 | VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end); |
| 31 | vcpu->stat.diagnose_10++; |
| 32 | |
| 33 | /* we checked for start > end above */ |
| 34 | if (end < prefix || start >= prefix + 2 * PAGE_SIZE) { |
| 35 | gmap_discard(start, end, vcpu->arch.gmap); |
| 36 | } else { |
| 37 | if (start < prefix) |
| 38 | gmap_discard(start, prefix, vcpu->arch.gmap); |
| 39 | if (end >= prefix) |
| 40 | gmap_discard(prefix + 2 * PAGE_SIZE, |
| 41 | end, vcpu->arch.gmap); |
| 42 | } |
| 43 | return 0; |
| 44 | } |
| 45 | |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 46 | static int __diag_time_slice_end(struct kvm_vcpu *vcpu) |
| 47 | { |
| 48 | VCPU_EVENT(vcpu, 5, "%s", "diag time slice end"); |
| 49 | vcpu->stat.diagnose_44++; |
| 50 | vcpu_put(vcpu); |
Christian Borntraeger | b8cee18 | 2008-05-21 13:37:16 +0200 | [diff] [blame] | 51 | yield(); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 52 | vcpu_load(vcpu); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static int __diag_ipl_functions(struct kvm_vcpu *vcpu) |
| 57 | { |
| 58 | unsigned int reg = vcpu->arch.sie_block->ipa & 0xf; |
| 59 | unsigned long subcode = vcpu->arch.guest_gprs[reg] & 0xffff; |
| 60 | |
| 61 | VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode); |
| 62 | switch (subcode) { |
| 63 | case 3: |
| 64 | vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR; |
| 65 | break; |
| 66 | case 4: |
| 67 | vcpu->run->s390_reset_flags = 0; |
| 68 | break; |
| 69 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 70 | return -EOPNOTSUPP; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Cornelia Huck | 9e6dabe | 2011-11-17 11:00:41 +0100 | [diff] [blame] | 73 | atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 74 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM; |
| 75 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL; |
| 76 | vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT; |
| 77 | vcpu->run->exit_reason = KVM_EXIT_S390_RESET; |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 78 | VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx", |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 79 | vcpu->run->s390_reset_flags); |
| 80 | return -EREMOTE; |
| 81 | } |
| 82 | |
| 83 | int kvm_s390_handle_diag(struct kvm_vcpu *vcpu) |
| 84 | { |
| 85 | int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16; |
| 86 | |
| 87 | switch (code) { |
Christian Borntraeger | 388186b | 2011-10-30 15:17:03 +0100 | [diff] [blame] | 88 | case 0x10: |
| 89 | return diag_release_pages(vcpu); |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 90 | case 0x44: |
| 91 | return __diag_time_slice_end(vcpu); |
| 92 | case 0x308: |
| 93 | return __diag_ipl_functions(vcpu); |
| 94 | default: |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 95 | return -EOPNOTSUPP; |
Christian Borntraeger | e28acfe | 2008-03-25 18:47:34 +0100 | [diff] [blame] | 96 | } |
| 97 | } |