troubleshoot.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  4. */
  5. #include <linux/ptrace.h>
  6. #include <linux/module.h>
  7. #include <linux/mm.h>
  8. #include <linux/fs.h>
  9. #include <linux/kdev_t.h>
  10. #include <linux/proc_fs.h>
  11. #include <linux/file.h>
  12. #include <linux/sched/mm.h>
  13. #include <linux/sched/debug.h>
  14. #include <asm/arcregs.h>
  15. #include <asm/irqflags.h>
  16. #define ARC_PATH_MAX 256
  17. static noinline void print_regs_scratch(struct pt_regs *regs)
  18. {
  19. pr_cont("BTA: 0x%08lx\n SP: 0x%08lx FP: 0x%08lx BLK: %pS\n",
  20. regs->bta, regs->sp, regs->fp, (void *)regs->blink);
  21. pr_cont("LPS: 0x%08lx\tLPE: 0x%08lx\tLPC: 0x%08lx\n",
  22. regs->lp_start, regs->lp_end, regs->lp_count);
  23. pr_info("r00: 0x%08lx\tr01: 0x%08lx\tr02: 0x%08lx\n" \
  24. "r03: 0x%08lx\tr04: 0x%08lx\tr05: 0x%08lx\n" \
  25. "r06: 0x%08lx\tr07: 0x%08lx\tr08: 0x%08lx\n" \
  26. "r09: 0x%08lx\tr10: 0x%08lx\tr11: 0x%08lx\n" \
  27. "r12: 0x%08lx\t",
  28. regs->r0, regs->r1, regs->r2,
  29. regs->r3, regs->r4, regs->r5,
  30. regs->r6, regs->r7, regs->r8,
  31. regs->r9, regs->r10, regs->r11,
  32. regs->r12);
  33. }
  34. static void print_regs_callee(struct callee_regs *regs)
  35. {
  36. pr_cont("r13: 0x%08lx\tr14: 0x%08lx\n" \
  37. "r15: 0x%08lx\tr16: 0x%08lx\tr17: 0x%08lx\n" \
  38. "r18: 0x%08lx\tr19: 0x%08lx\tr20: 0x%08lx\n" \
  39. "r21: 0x%08lx\tr22: 0x%08lx\tr23: 0x%08lx\n" \
  40. "r24: 0x%08lx\tr25: 0x%08lx\n",
  41. regs->r13, regs->r14,
  42. regs->r15, regs->r16, regs->r17,
  43. regs->r18, regs->r19, regs->r20,
  44. regs->r21, regs->r22, regs->r23,
  45. regs->r24, regs->r25);
  46. }
  47. static void print_task_path_n_nm(struct task_struct *tsk)
  48. {
  49. char *path_nm = NULL;
  50. struct mm_struct *mm;
  51. struct file *exe_file;
  52. char buf[ARC_PATH_MAX];
  53. mm = get_task_mm(tsk);
  54. if (!mm)
  55. goto done;
  56. exe_file = get_mm_exe_file(mm);
  57. mmput(mm);
  58. if (exe_file) {
  59. path_nm = file_path(exe_file, buf, ARC_PATH_MAX-1);
  60. fput(exe_file);
  61. }
  62. done:
  63. pr_info("Path: %s\n", !IS_ERR(path_nm) ? path_nm : "?");
  64. }
  65. static void show_faulting_vma(unsigned long address)
  66. {
  67. struct vm_area_struct *vma;
  68. struct mm_struct *active_mm = current->active_mm;
  69. /* can't use print_vma_addr() yet as it doesn't check for
  70. * non-inclusive vma
  71. */
  72. mmap_read_lock(active_mm);
  73. vma = find_vma(active_mm, address);
  74. /* check against the find_vma( ) behaviour which returns the next VMA
  75. * if the container VMA is not found
  76. */
  77. if (vma && (vma->vm_start <= address)) {
  78. char buf[ARC_PATH_MAX];
  79. char *nm = "?";
  80. if (vma->vm_file) {
  81. nm = file_path(vma->vm_file, buf, ARC_PATH_MAX-1);
  82. if (IS_ERR(nm))
  83. nm = "?";
  84. }
  85. pr_info(" @off 0x%lx in [%s] VMA: 0x%08lx to 0x%08lx\n",
  86. vma->vm_start < TASK_UNMAPPED_BASE ?
  87. address : address - vma->vm_start,
  88. nm, vma->vm_start, vma->vm_end);
  89. } else
  90. pr_info(" @No matching VMA found\n");
  91. mmap_read_unlock(active_mm);
  92. }
  93. static void show_ecr_verbose(struct pt_regs *regs)
  94. {
  95. unsigned int vec, cause_code;
  96. unsigned long address;
  97. /* For Data fault, this is data address not instruction addr */
  98. address = current->thread.fault_address;
  99. vec = regs->ecr_vec;
  100. cause_code = regs->ecr_cause;
  101. /* For DTLB Miss or ProtV, display the memory involved too */
  102. if (vec == ECR_V_DTLB_MISS) {
  103. pr_cont("Invalid %s @ 0x%08lx by insn @ %pS\n",
  104. (cause_code == 0x01) ? "Read" :
  105. ((cause_code == 0x02) ? "Write" : "EX"),
  106. address, (void *)regs->ret);
  107. } else if (vec == ECR_V_ITLB_MISS) {
  108. pr_cont("Insn could not be fetched\n");
  109. } else if (vec == ECR_V_MACH_CHK) {
  110. pr_cont("Machine Check (%s)\n", (cause_code == 0x0) ?
  111. "Double Fault" : "Other Fatal Err");
  112. } else if (vec == ECR_V_PROTV) {
  113. if (cause_code == ECR_C_PROTV_INST_FETCH)
  114. pr_cont("Execute from Non-exec Page\n");
  115. else if (cause_code == ECR_C_PROTV_MISALIG_DATA &&
  116. IS_ENABLED(CONFIG_ISA_ARCOMPACT))
  117. pr_cont("Misaligned r/w from 0x%08lx\n", address);
  118. else
  119. pr_cont("%s access not allowed on page\n",
  120. (cause_code == 0x01) ? "Read" :
  121. ((cause_code == 0x02) ? "Write" : "EX"));
  122. } else if (vec == ECR_V_INSN_ERR) {
  123. pr_cont("Illegal Insn\n");
  124. #ifdef CONFIG_ISA_ARCV2
  125. } else if (vec == ECR_V_MEM_ERR) {
  126. if (cause_code == 0x00)
  127. pr_cont("Bus Error from Insn Mem\n");
  128. else if (cause_code == 0x10)
  129. pr_cont("Bus Error from Data Mem\n");
  130. else
  131. pr_cont("Bus Error, check PRM\n");
  132. } else if (vec == ECR_V_MISALIGN) {
  133. pr_cont("Misaligned r/w from 0x%08lx\n", address);
  134. #endif
  135. } else if (vec == ECR_V_TRAP) {
  136. if (regs->ecr_param == 5)
  137. pr_cont("gcc generated __builtin_trap\n");
  138. } else {
  139. pr_cont("Check Programmer's Manual\n");
  140. }
  141. }
  142. /************************************************************************
  143. * API called by rest of kernel
  144. ***********************************************************************/
  145. void show_regs(struct pt_regs *regs)
  146. {
  147. struct task_struct *tsk = current;
  148. struct callee_regs *cregs = (struct callee_regs *)tsk->thread.callee_reg;
  149. /*
  150. * generic code calls us with preemption disabled, but some calls
  151. * here could sleep, so re-enable to avoid lockdep splat
  152. */
  153. preempt_enable();
  154. print_task_path_n_nm(tsk);
  155. show_regs_print_info(KERN_INFO);
  156. show_ecr_verbose(regs);
  157. if (user_mode(regs))
  158. show_faulting_vma(regs->ret); /* faulting code, not data */
  159. pr_info("ECR: 0x%08lx EFA: 0x%08lx ERET: 0x%08lx\nSTAT: 0x%08lx",
  160. regs->event, current->thread.fault_address, regs->ret,
  161. regs->status32);
  162. #define STS_BIT(r, bit) r->status32 & STATUS_##bit##_MASK ? #bit" " : ""
  163. #ifdef CONFIG_ISA_ARCOMPACT
  164. pr_cont(" [%2s%2s%2s%2s%2s%2s%2s]",
  165. (regs->status32 & STATUS_U_MASK) ? "U " : "K ",
  166. STS_BIT(regs, DE), STS_BIT(regs, AE),
  167. STS_BIT(regs, A2), STS_BIT(regs, A1),
  168. STS_BIT(regs, E2), STS_BIT(regs, E1));
  169. #else
  170. pr_cont(" [%2s%2s%2s%2s] ",
  171. STS_BIT(regs, IE),
  172. (regs->status32 & STATUS_U_MASK) ? "U " : "K ",
  173. STS_BIT(regs, DE), STS_BIT(regs, AE));
  174. #endif
  175. print_regs_scratch(regs);
  176. if (cregs)
  177. print_regs_callee(cregs);
  178. preempt_disable();
  179. }
  180. void show_kernel_fault_diag(const char *str, struct pt_regs *regs,
  181. unsigned long address)
  182. {
  183. current->thread.fault_address = address;
  184. /* Show fault description */
  185. pr_info("\n%s\n", str);
  186. /* Caller and Callee regs */
  187. show_regs(regs);
  188. /* Show stack trace if this Fatality happened in kernel mode */
  189. if (!user_mode(regs))
  190. show_stacktrace(current, regs, KERN_DEFAULT);
  191. }