extable.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/bitfield.h>
  3. #include <linux/extable.h>
  4. #include <linux/string.h>
  5. #include <linux/errno.h>
  6. #include <linux/panic.h>
  7. #include <asm/asm-extable.h>
  8. #include <asm/extable.h>
  9. const struct exception_table_entry *s390_search_extables(unsigned long addr)
  10. {
  11. const struct exception_table_entry *fixup;
  12. size_t num;
  13. fixup = search_exception_tables(addr);
  14. if (fixup)
  15. return fixup;
  16. num = __stop_amode31_ex_table - __start_amode31_ex_table;
  17. return search_extable(__start_amode31_ex_table, num, addr);
  18. }
  19. static bool ex_handler_fixup(const struct exception_table_entry *ex, struct pt_regs *regs)
  20. {
  21. regs->psw.addr = extable_fixup(ex);
  22. return true;
  23. }
  24. static bool ex_handler_ua_store(const struct exception_table_entry *ex, struct pt_regs *regs)
  25. {
  26. unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
  27. regs->gprs[reg_err] = -EFAULT;
  28. regs->psw.addr = extable_fixup(ex);
  29. return true;
  30. }
  31. static bool ex_handler_ua_load_mem(const struct exception_table_entry *ex, struct pt_regs *regs)
  32. {
  33. unsigned int reg_addr = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
  34. unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
  35. size_t len = FIELD_GET(EX_DATA_LEN, ex->data);
  36. regs->gprs[reg_err] = -EFAULT;
  37. memset((void *)regs->gprs[reg_addr], 0, len);
  38. regs->psw.addr = extable_fixup(ex);
  39. return true;
  40. }
  41. static bool ex_handler_ua_load_reg(const struct exception_table_entry *ex, struct pt_regs *regs)
  42. {
  43. unsigned int reg_zero = FIELD_GET(EX_DATA_REG_ADDR, ex->data);
  44. unsigned int reg_err = FIELD_GET(EX_DATA_REG_ERR, ex->data);
  45. regs->gprs[reg_err] = -EFAULT;
  46. regs->gprs[reg_zero] = 0;
  47. regs->psw.addr = extable_fixup(ex);
  48. return true;
  49. }
  50. bool fixup_exception(struct pt_regs *regs)
  51. {
  52. const struct exception_table_entry *ex;
  53. ex = s390_search_extables(instruction_pointer(regs));
  54. if (!ex)
  55. return false;
  56. switch (ex->type) {
  57. case EX_TYPE_FIXUP:
  58. return ex_handler_fixup(ex, regs);
  59. case EX_TYPE_BPF:
  60. return ex_handler_bpf(ex, regs);
  61. case EX_TYPE_UA_STORE:
  62. return ex_handler_ua_store(ex, regs);
  63. case EX_TYPE_UA_LOAD_MEM:
  64. return ex_handler_ua_load_mem(ex, regs);
  65. case EX_TYPE_UA_LOAD_REG:
  66. return ex_handler_ua_load_reg(ex, regs);
  67. }
  68. panic("invalid exception table entry");
  69. }