diag.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * diag.c - 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. vcpu_put(vcpu);
  44. yield();
  45. vcpu_load(vcpu);
  46. return 0;
  47. }
  48. static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
  49. {
  50. unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
  51. unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff;
  52. VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
  53. switch (subcode) {
  54. case 3:
  55. vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
  56. break;
  57. case 4:
  58. vcpu->run->s390_reset_flags = 0;
  59. break;
  60. default:
  61. return -EOPNOTSUPP;
  62. }
  63. atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
  64. vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
  65. vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
  66. vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
  67. vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
  68. VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
  69. vcpu->run->s390_reset_flags);
  70. return -EREMOTE;
  71. }
  72. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
  73. {
  74. int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
  75. switch (code) {
  76. case 0x10:
  77. return diag_release_pages(vcpu);
  78. case 0x44:
  79. return __diag_time_slice_end(vcpu);
  80. case 0x308:
  81. return __diag_ipl_functions(vcpu);
  82. default:
  83. return -EOPNOTSUPP;
  84. }
  85. }