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. static void disable_runtime_instr(void)
  19. {
  20. struct pt_regs *regs = task_pt_regs(current);
  21. load_runtime_instr_cb(&runtime_instr_empty_cb);
  22. /*
  23. * Make sure the RI bit is deleted from the PSW. If the user did not
  24. * switch off RI before the system call the process will get a
  25. * specification exception otherwise.
  26. */
  27. regs->psw.mask &= ~PSW_MASK_RI;
  28. }
  29. static void init_runtime_instr_cb(struct runtime_instr_cb *cb)
  30. {
  31. cb->buf_limit = 0xfff;
  32. cb->pstate = 1;
  33. cb->pstate_set_buf = 1;
  34. cb->pstate_sample = 1;
  35. cb->pstate_collect = 1;
  36. cb->key = PAGE_DEFAULT_KEY;
  37. cb->valid = 1;
  38. }
  39. void exit_thread_runtime_instr(void)
  40. {
  41. struct task_struct *task = current;
  42. if (!task->thread.ri_cb)
  43. return;
  44. disable_runtime_instr();
  45. kfree(task->thread.ri_cb);
  46. task->thread.ri_cb = NULL;
  47. }
  48. SYSCALL_DEFINE1(s390_runtime_instr, int, command)
  49. {
  50. struct runtime_instr_cb *cb;
  51. if (!test_facility(64))
  52. return -EOPNOTSUPP;
  53. if (command == S390_RUNTIME_INSTR_STOP) {
  54. preempt_disable();
  55. exit_thread_runtime_instr();
  56. preempt_enable();
  57. return 0;
  58. }
  59. if (command != S390_RUNTIME_INSTR_START)
  60. return -EINVAL;
  61. if (!current->thread.ri_cb) {
  62. cb = kzalloc(sizeof(*cb), GFP_KERNEL);
  63. if (!cb)
  64. return -ENOMEM;
  65. } else {
  66. cb = current->thread.ri_cb;
  67. memset(cb, 0, sizeof(*cb));
  68. }
  69. init_runtime_instr_cb(cb);
  70. /* now load the control block to make it available */
  71. preempt_disable();
  72. current->thread.ri_cb = cb;
  73. load_runtime_instr_cb(cb);
  74. preempt_enable();
  75. return 0;
  76. }