pgm_check_info.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/stdarg.h>
  4. #include <linux/string.h>
  5. #include <linux/ctype.h>
  6. #include <asm/stacktrace.h>
  7. #include <asm/boot_data.h>
  8. #include <asm/lowcore.h>
  9. #include <asm/setup.h>
  10. #include <asm/sclp.h>
  11. #include <asm/uv.h>
  12. #include "boot.h"
  13. const char hex_asc[] = "0123456789abcdef";
  14. static char *as_hex(char *dst, unsigned long val, int pad)
  15. {
  16. char *p, *end = p = dst + max(pad, (int)__fls(val | 1) / 4 + 1);
  17. for (*p-- = 0; p >= dst; val >>= 4)
  18. *p-- = hex_asc[val & 0x0f];
  19. return end;
  20. }
  21. static char *symstart(char *p)
  22. {
  23. while (*p)
  24. p--;
  25. return p + 1;
  26. }
  27. static noinline char *findsym(unsigned long ip, unsigned short *off, unsigned short *len)
  28. {
  29. /* symbol entries are in a form "10000 c4 startup\0" */
  30. char *a = _decompressor_syms_start;
  31. char *b = _decompressor_syms_end;
  32. unsigned long start;
  33. unsigned long size;
  34. char *pivot;
  35. char *endp;
  36. while (a < b) {
  37. pivot = symstart(a + (b - a) / 2);
  38. start = simple_strtoull(pivot, &endp, 16);
  39. size = simple_strtoull(endp + 1, &endp, 16);
  40. if (ip < start) {
  41. b = pivot;
  42. continue;
  43. }
  44. if (ip > start + size) {
  45. a = pivot + strlen(pivot) + 1;
  46. continue;
  47. }
  48. *off = ip - start;
  49. *len = size;
  50. return endp + 1;
  51. }
  52. return NULL;
  53. }
  54. static noinline char *strsym(void *ip)
  55. {
  56. static char buf[64];
  57. unsigned short off;
  58. unsigned short len;
  59. char *p;
  60. p = findsym((unsigned long)ip, &off, &len);
  61. if (p) {
  62. strncpy(buf, p, sizeof(buf));
  63. /* reserve 15 bytes for offset/len in symbol+0x1234/0x1234 */
  64. p = buf + strnlen(buf, sizeof(buf) - 15);
  65. strcpy(p, "+0x");
  66. p = as_hex(p + 3, off, 0);
  67. strcpy(p, "/0x");
  68. as_hex(p + 3, len, 0);
  69. } else {
  70. as_hex(buf, (unsigned long)ip, 16);
  71. }
  72. return buf;
  73. }
  74. void decompressor_printk(const char *fmt, ...)
  75. {
  76. char buf[1024] = { 0 };
  77. char *end = buf + sizeof(buf) - 1; /* make sure buf is 0 terminated */
  78. unsigned long pad;
  79. char *p = buf;
  80. va_list args;
  81. va_start(args, fmt);
  82. for (; p < end && *fmt; fmt++) {
  83. if (*fmt != '%') {
  84. *p++ = *fmt;
  85. continue;
  86. }
  87. pad = isdigit(*++fmt) ? simple_strtol(fmt, (char **)&fmt, 10) : 0;
  88. switch (*fmt) {
  89. case 's':
  90. p = buf + strlcat(buf, va_arg(args, char *), sizeof(buf));
  91. break;
  92. case 'p':
  93. if (*++fmt != 'S')
  94. goto out;
  95. p = buf + strlcat(buf, strsym(va_arg(args, void *)), sizeof(buf));
  96. break;
  97. case 'l':
  98. if (*++fmt != 'x' || end - p <= max(sizeof(long) * 2, pad))
  99. goto out;
  100. p = as_hex(p, va_arg(args, unsigned long), pad);
  101. break;
  102. case 'x':
  103. if (end - p <= max(sizeof(int) * 2, pad))
  104. goto out;
  105. p = as_hex(p, va_arg(args, unsigned int), pad);
  106. break;
  107. default:
  108. goto out;
  109. }
  110. }
  111. out:
  112. va_end(args);
  113. sclp_early_printk(buf);
  114. }
  115. static noinline void print_stacktrace(void)
  116. {
  117. struct stack_info boot_stack = { STACK_TYPE_TASK, (unsigned long)_stack_start,
  118. (unsigned long)_stack_end };
  119. unsigned long sp = S390_lowcore.gpregs_save_area[15];
  120. bool first = true;
  121. decompressor_printk("Call Trace:\n");
  122. while (!(sp & 0x7) && on_stack(&boot_stack, sp, sizeof(struct stack_frame))) {
  123. struct stack_frame *sf = (struct stack_frame *)sp;
  124. decompressor_printk(first ? "(sp:%016lx [<%016lx>] %pS)\n" :
  125. " sp:%016lx [<%016lx>] %pS\n",
  126. sp, sf->gprs[8], (void *)sf->gprs[8]);
  127. if (sf->back_chain <= sp)
  128. break;
  129. sp = sf->back_chain;
  130. first = false;
  131. }
  132. }
  133. void print_pgm_check_info(void)
  134. {
  135. unsigned long *gpregs = (unsigned long *)S390_lowcore.gpregs_save_area;
  136. struct psw_bits *psw = &psw_bits(S390_lowcore.psw_save_area);
  137. decompressor_printk("Linux version %s\n", kernel_version);
  138. if (!is_prot_virt_guest() && early_command_line[0])
  139. decompressor_printk("Kernel command line: %s\n", early_command_line);
  140. decompressor_printk("Kernel fault: interruption code %04x ilc:%x\n",
  141. S390_lowcore.pgm_code, S390_lowcore.pgm_ilc >> 1);
  142. if (kaslr_enabled)
  143. decompressor_printk("Kernel random base: %lx\n", __kaslr_offset);
  144. decompressor_printk("PSW : %016lx %016lx (%pS)\n",
  145. S390_lowcore.psw_save_area.mask,
  146. S390_lowcore.psw_save_area.addr,
  147. (void *)S390_lowcore.psw_save_area.addr);
  148. decompressor_printk(
  149. " R:%x T:%x IO:%x EX:%x Key:%x M:%x W:%x P:%x AS:%x CC:%x PM:%x RI:%x EA:%x\n",
  150. psw->per, psw->dat, psw->io, psw->ext, psw->key, psw->mcheck,
  151. psw->wait, psw->pstate, psw->as, psw->cc, psw->pm, psw->ri,
  152. psw->eaba);
  153. decompressor_printk("GPRS: %016lx %016lx %016lx %016lx\n",
  154. gpregs[0], gpregs[1], gpregs[2], gpregs[3]);
  155. decompressor_printk(" %016lx %016lx %016lx %016lx\n",
  156. gpregs[4], gpregs[5], gpregs[6], gpregs[7]);
  157. decompressor_printk(" %016lx %016lx %016lx %016lx\n",
  158. gpregs[8], gpregs[9], gpregs[10], gpregs[11]);
  159. decompressor_printk(" %016lx %016lx %016lx %016lx\n",
  160. gpregs[12], gpregs[13], gpregs[14], gpregs[15]);
  161. print_stacktrace();
  162. decompressor_printk("Last Breaking-Event-Address:\n");
  163. decompressor_printk(" [<%016lx>] %pS\n", (unsigned long)S390_lowcore.pgm_last_break,
  164. (void *)S390_lowcore.pgm_last_break);
  165. }