runtime_instr.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright IBM Corp. 2012
  3. * Author(s): Jan Glauber <jang@linux.vnet.ibm.com>
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/syscalls.h>
  7. #include <linux/signal.h>
  8. #include <linux/mm.h>
  9. #include <linux/slab.h>
  10. #include <linux/init.h>
  11. #include <linux/errno.h>
  12. #include <linux/kernel_stat.h>
  13. #include <asm/runtime_instr.h>
  14. #include <asm/cpu_mf.h>
  15. #include <asm/irq.h>
  16. /* empty control block to disable RI by loading it */
  17. struct runtime_instr_cb runtime_instr_empty_cb;
  18. void runtime_instr_release(struct task_struct *tsk)
  19. {
  20. kfree(tsk->thread.ri_cb);
  21. }
  22. static void disable_runtime_instr(void)
  23. {
  24. struct task_struct *task = current;
  25. struct pt_regs *regs;
  26. if (!task->thread.ri_cb)
  27. return;
  28. regs = task_pt_regs(task);
  29. preempt_disable();
  30. load_runtime_instr_cb(&runtime_instr_empty_cb);
  31. kfree(task->thread.ri_cb);
  32. task->thread.ri_cb = NULL;
  33. preempt_enable();
  34. /*
  35. * Make sure the RI bit is deleted from the PSW. If the user did not
  36. * switch off RI before the system call the process will get a
  37. * specification exception otherwise.
  38. */
  39. regs->psw.mask &= ~PSW_MASK_RI;
  40. }
  41. static void init_runtime_instr_cb(struct runtime_instr_cb *cb)
  42. {
  43. cb->buf_limit = 0xfff;
  44. cb->pstate = 1;
  45. cb->pstate_set_buf = 1;
  46. cb->pstate_sample = 1;
  47. cb->pstate_collect = 1;
  48. cb->key = PAGE_DEFAULT_KEY;
  49. cb->valid = 1;
  50. }
  51. SYSCALL_DEFINE1(s390_runtime_instr, int, command)
  52. {
  53. struct runtime_instr_cb *cb;
  54. if (!test_facility(64))
  55. return -EOPNOTSUPP;
  56. if (command == S390_RUNTIME_INSTR_STOP) {
  57. disable_runtime_instr();
  58. return 0;
  59. }
  60. if (command != S390_RUNTIME_INSTR_START)
  61. return -EINVAL;
  62. if (!current->thread.ri_cb) {
  63. cb = kzalloc(sizeof(*cb), GFP_KERNEL);
  64. if (!cb)
  65. return -ENOMEM;
  66. } else {
  67. cb = current->thread.ri_cb;
  68. memset(cb, 0, sizeof(*cb));
  69. }
  70. init_runtime_instr_cb(cb);
  71. /* now load the control block to make it available */
  72. preempt_disable();
  73. current->thread.ri_cb = cb;
  74. load_runtime_instr_cb(cb);
  75. preempt_enable();
  76. return 0;
  77. }