diag.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * diag.c - handling diagnose instructions
  3. *
  4. * Copyright IBM Corp. 2008
  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_time_slice_end(struct kvm_vcpu *vcpu)
  17. {
  18. VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
  19. vcpu->stat.diagnose_44++;
  20. vcpu_put(vcpu);
  21. yield();
  22. vcpu_load(vcpu);
  23. return 0;
  24. }
  25. static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
  26. {
  27. unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
  28. unsigned long subcode = vcpu->arch.guest_gprs[reg] & 0xffff;
  29. VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
  30. switch (subcode) {
  31. case 3:
  32. vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
  33. break;
  34. case 4:
  35. vcpu->run->s390_reset_flags = 0;
  36. break;
  37. default:
  38. return -ENOTSUPP;
  39. }
  40. atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
  41. vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
  42. vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
  43. vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
  44. vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
  45. VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
  46. vcpu->run->s390_reset_flags);
  47. return -EREMOTE;
  48. }
  49. int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
  50. {
  51. int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
  52. switch (code) {
  53. case 0x44:
  54. return __diag_time_slice_end(vcpu);
  55. case 0x308:
  56. return __diag_ipl_functions(vcpu);
  57. default:
  58. return -ENOTSUPP;
  59. }
  60. }