diag.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * handling diagnose instructions
  3. *
  4. * Copyright IBM Corp. 2008, 2011
  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. #include <linux/kvm.h>
  14. #include <linux/kvm_host.h>
  15. #include "kvm-s390.h"
  16. static int diag_release_pages(struct kvm_vcpu *vcpu)
  17. {
  18. unsigned long start, end;
  19. unsigned long prefix = vcpu->arch.sie_block->prefix;
  20. start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
  21. end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
  22. if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end
  23. || start < 2 * PAGE_SIZE)
  24. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  25. VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
  26. vcpu->stat.diagnose_10++;
  27. /* we checked for start > end above */
  28. if (end < prefix || start >= prefix + 2 * PAGE_SIZE) {
  29. gmap_discard(start, end, vcpu->arch.gmap);
  30. } else {
  31. if (start < prefix)
  32. gmap_discard(start, prefix, vcpu->arch.gmap);
  33. if (end >= prefix)
  34. gmap_discard(prefix + 2 * PAGE_SIZE,
  35. end, vcpu->arch.gmap);
  36. }
  37. return 0;
  38. }
  39. static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
  40. {
  41. VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
  42. vcpu->stat.diagnose_44++;
  43. kvm_vcpu_on_spin(vcpu);
  44. return 0;
  45. }
  46. static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
  47. {
  48. struct kvm *kvm = vcpu->kvm;
  49. struct kvm_vcpu *tcpu;
  50. int tid;
  51. int i;
  52. tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
  53. vcpu->stat.diagnose_9c++;
  54. VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d", tid);
  55. if (tid == vcpu->vcpu_id)
  56. return 0;
  57. kvm_for_each_vcpu(i, tcpu, kvm)
  58. if (tcpu->vcpu_id == tid) {
  59. kvm_vcpu_yield_to(tcpu);
  60. break;
  61. }
  62. return 0;
  63. }
  64. static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
  65. {
  66. unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
  67. unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff;
  68. VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
  69. switch (subcode) {
  70. case 3:
  71. vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
  72. break;
  73. case 4:
  74. vcpu->run->s390_reset_flags = 0;
  75. break;
  76. default:
  77. return -EOPNOTSUPP;
  78. }
  79. atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
  80. vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
  81. vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
  82. vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
  83. vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
  84. VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
  85. vcpu->run->s390_reset_flags);
  86. return -EREMOTE;
  87. }
  88. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
  89. {
  90. int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
  91. switch (code) {
  92. case 0x10:
  93. return diag_release_pages(vcpu);
  94. case 0x44:
  95. return __diag_time_slice_end(vcpu);
  96. case 0x9c:
  97. return __diag_time_slice_end_directed(vcpu);
  98. case 0x308:
  99. return __diag_ipl_functions(vcpu);
  100. default:
  101. return -EOPNOTSUPP;
  102. }
  103. }