cper.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. * UEFI Common Platform Error Record (CPER) support
  3. *
  4. * Copyright (C) 2010, Intel Corp.
  5. * Author: Huang Ying <ying.huang@intel.com>
  6. *
  7. * CPER is the format used to describe platform hardware error by
  8. * various tables, such as ERST, BERT and HEST etc.
  9. *
  10. * For more information about CPER, please refer to Appendix N of UEFI
  11. * Specification version 2.4.
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License version
  15. * 2 as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/time.h>
  29. #include <linux/cper.h>
  30. #include <linux/dmi.h>
  31. #include <linux/acpi.h>
  32. #include <linux/pci.h>
  33. #include <linux/aer.h>
  34. #include <linux/printk.h>
  35. #include <linux/bcd.h>
  36. #include <acpi/ghes.h>
  37. #include <ras/ras_event.h>
  38. static char rcd_decode_str[CPER_REC_LEN];
  39. /*
  40. * CPER record ID need to be unique even after reboot, because record
  41. * ID is used as index for ERST storage, while CPER records from
  42. * multiple boot may co-exist in ERST.
  43. */
  44. u64 cper_next_record_id(void)
  45. {
  46. static atomic64_t seq;
  47. if (!atomic64_read(&seq)) {
  48. time64_t time = ktime_get_real_seconds();
  49. /*
  50. * This code is unlikely to still be needed in year 2106,
  51. * but just in case, let's use a few more bits for timestamps
  52. * after y2038 to be sure they keep increasing monotonically
  53. * for the next few hundred years...
  54. */
  55. if (time < 0x80000000)
  56. atomic64_set(&seq, (ktime_get_real_seconds()) << 32);
  57. else
  58. atomic64_set(&seq, 0x8000000000000000ull |
  59. ktime_get_real_seconds() << 24);
  60. }
  61. return atomic64_inc_return(&seq);
  62. }
  63. EXPORT_SYMBOL_GPL(cper_next_record_id);
  64. static const char * const severity_strs[] = {
  65. "recoverable",
  66. "fatal",
  67. "corrected",
  68. "info",
  69. };
  70. const char *cper_severity_str(unsigned int severity)
  71. {
  72. return severity < ARRAY_SIZE(severity_strs) ?
  73. severity_strs[severity] : "unknown";
  74. }
  75. EXPORT_SYMBOL_GPL(cper_severity_str);
  76. /*
  77. * cper_print_bits - print strings for set bits
  78. * @pfx: prefix for each line, including log level and prefix string
  79. * @bits: bit mask
  80. * @strs: string array, indexed by bit position
  81. * @strs_size: size of the string array: @strs
  82. *
  83. * For each set bit in @bits, print the corresponding string in @strs.
  84. * If the output length is longer than 80, multiple line will be
  85. * printed, with @pfx is printed at the beginning of each line.
  86. */
  87. void cper_print_bits(const char *pfx, unsigned int bits,
  88. const char * const strs[], unsigned int strs_size)
  89. {
  90. int i, len = 0;
  91. const char *str;
  92. char buf[84];
  93. for (i = 0; i < strs_size; i++) {
  94. if (!(bits & (1U << i)))
  95. continue;
  96. str = strs[i];
  97. if (!str)
  98. continue;
  99. if (len && len + strlen(str) + 2 > 80) {
  100. printk("%s\n", buf);
  101. len = 0;
  102. }
  103. if (!len)
  104. len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
  105. else
  106. len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
  107. }
  108. if (len)
  109. printk("%s\n", buf);
  110. }
  111. static const char * const proc_type_strs[] = {
  112. "IA32/X64",
  113. "IA64",
  114. "ARM",
  115. };
  116. static const char * const proc_isa_strs[] = {
  117. "IA32",
  118. "IA64",
  119. "X64",
  120. "ARM A32/T32",
  121. "ARM A64",
  122. };
  123. const char * const cper_proc_error_type_strs[] = {
  124. "cache error",
  125. "TLB error",
  126. "bus error",
  127. "micro-architectural error",
  128. };
  129. static const char * const proc_op_strs[] = {
  130. "unknown or generic",
  131. "data read",
  132. "data write",
  133. "instruction execution",
  134. };
  135. static const char * const proc_flag_strs[] = {
  136. "restartable",
  137. "precise IP",
  138. "overflow",
  139. "corrected",
  140. };
  141. static void cper_print_proc_generic(const char *pfx,
  142. const struct cper_sec_proc_generic *proc)
  143. {
  144. if (proc->validation_bits & CPER_PROC_VALID_TYPE)
  145. printk("%s""processor_type: %d, %s\n", pfx, proc->proc_type,
  146. proc->proc_type < ARRAY_SIZE(proc_type_strs) ?
  147. proc_type_strs[proc->proc_type] : "unknown");
  148. if (proc->validation_bits & CPER_PROC_VALID_ISA)
  149. printk("%s""processor_isa: %d, %s\n", pfx, proc->proc_isa,
  150. proc->proc_isa < ARRAY_SIZE(proc_isa_strs) ?
  151. proc_isa_strs[proc->proc_isa] : "unknown");
  152. if (proc->validation_bits & CPER_PROC_VALID_ERROR_TYPE) {
  153. printk("%s""error_type: 0x%02x\n", pfx, proc->proc_error_type);
  154. cper_print_bits(pfx, proc->proc_error_type,
  155. cper_proc_error_type_strs,
  156. ARRAY_SIZE(cper_proc_error_type_strs));
  157. }
  158. if (proc->validation_bits & CPER_PROC_VALID_OPERATION)
  159. printk("%s""operation: %d, %s\n", pfx, proc->operation,
  160. proc->operation < ARRAY_SIZE(proc_op_strs) ?
  161. proc_op_strs[proc->operation] : "unknown");
  162. if (proc->validation_bits & CPER_PROC_VALID_FLAGS) {
  163. printk("%s""flags: 0x%02x\n", pfx, proc->flags);
  164. cper_print_bits(pfx, proc->flags, proc_flag_strs,
  165. ARRAY_SIZE(proc_flag_strs));
  166. }
  167. if (proc->validation_bits & CPER_PROC_VALID_LEVEL)
  168. printk("%s""level: %d\n", pfx, proc->level);
  169. if (proc->validation_bits & CPER_PROC_VALID_VERSION)
  170. printk("%s""version_info: 0x%016llx\n", pfx, proc->cpu_version);
  171. if (proc->validation_bits & CPER_PROC_VALID_ID)
  172. printk("%s""processor_id: 0x%016llx\n", pfx, proc->proc_id);
  173. if (proc->validation_bits & CPER_PROC_VALID_TARGET_ADDRESS)
  174. printk("%s""target_address: 0x%016llx\n",
  175. pfx, proc->target_addr);
  176. if (proc->validation_bits & CPER_PROC_VALID_REQUESTOR_ID)
  177. printk("%s""requestor_id: 0x%016llx\n",
  178. pfx, proc->requestor_id);
  179. if (proc->validation_bits & CPER_PROC_VALID_RESPONDER_ID)
  180. printk("%s""responder_id: 0x%016llx\n",
  181. pfx, proc->responder_id);
  182. if (proc->validation_bits & CPER_PROC_VALID_IP)
  183. printk("%s""IP: 0x%016llx\n", pfx, proc->ip);
  184. }
  185. static const char * const mem_err_type_strs[] = {
  186. "unknown",
  187. "no error",
  188. "single-bit ECC",
  189. "multi-bit ECC",
  190. "single-symbol chipkill ECC",
  191. "multi-symbol chipkill ECC",
  192. "master abort",
  193. "target abort",
  194. "parity error",
  195. "watchdog timeout",
  196. "invalid address",
  197. "mirror Broken",
  198. "memory sparing",
  199. "scrub corrected error",
  200. "scrub uncorrected error",
  201. "physical memory map-out event",
  202. };
  203. const char *cper_mem_err_type_str(unsigned int etype)
  204. {
  205. return etype < ARRAY_SIZE(mem_err_type_strs) ?
  206. mem_err_type_strs[etype] : "unknown";
  207. }
  208. EXPORT_SYMBOL_GPL(cper_mem_err_type_str);
  209. static int cper_mem_err_location(struct cper_mem_err_compact *mem, char *msg)
  210. {
  211. u32 len, n;
  212. if (!msg)
  213. return 0;
  214. n = 0;
  215. len = CPER_REC_LEN - 1;
  216. if (mem->validation_bits & CPER_MEM_VALID_NODE)
  217. n += scnprintf(msg + n, len - n, "node: %d ", mem->node);
  218. if (mem->validation_bits & CPER_MEM_VALID_CARD)
  219. n += scnprintf(msg + n, len - n, "card: %d ", mem->card);
  220. if (mem->validation_bits & CPER_MEM_VALID_MODULE)
  221. n += scnprintf(msg + n, len - n, "module: %d ", mem->module);
  222. if (mem->validation_bits & CPER_MEM_VALID_RANK_NUMBER)
  223. n += scnprintf(msg + n, len - n, "rank: %d ", mem->rank);
  224. if (mem->validation_bits & CPER_MEM_VALID_BANK)
  225. n += scnprintf(msg + n, len - n, "bank: %d ", mem->bank);
  226. if (mem->validation_bits & CPER_MEM_VALID_DEVICE)
  227. n += scnprintf(msg + n, len - n, "device: %d ", mem->device);
  228. if (mem->validation_bits & CPER_MEM_VALID_ROW)
  229. n += scnprintf(msg + n, len - n, "row: %d ", mem->row);
  230. if (mem->validation_bits & CPER_MEM_VALID_COLUMN)
  231. n += scnprintf(msg + n, len - n, "column: %d ", mem->column);
  232. if (mem->validation_bits & CPER_MEM_VALID_BIT_POSITION)
  233. n += scnprintf(msg + n, len - n, "bit_position: %d ",
  234. mem->bit_pos);
  235. if (mem->validation_bits & CPER_MEM_VALID_REQUESTOR_ID)
  236. n += scnprintf(msg + n, len - n, "requestor_id: 0x%016llx ",
  237. mem->requestor_id);
  238. if (mem->validation_bits & CPER_MEM_VALID_RESPONDER_ID)
  239. n += scnprintf(msg + n, len - n, "responder_id: 0x%016llx ",
  240. mem->responder_id);
  241. if (mem->validation_bits & CPER_MEM_VALID_TARGET_ID)
  242. scnprintf(msg + n, len - n, "target_id: 0x%016llx ",
  243. mem->target_id);
  244. msg[n] = '\0';
  245. return n;
  246. }
  247. static int cper_dimm_err_location(struct cper_mem_err_compact *mem, char *msg)
  248. {
  249. u32 len, n;
  250. const char *bank = NULL, *device = NULL;
  251. if (!msg || !(mem->validation_bits & CPER_MEM_VALID_MODULE_HANDLE))
  252. return 0;
  253. n = 0;
  254. len = CPER_REC_LEN - 1;
  255. dmi_memdev_name(mem->mem_dev_handle, &bank, &device);
  256. if (bank && device)
  257. n = snprintf(msg, len, "DIMM location: %s %s ", bank, device);
  258. else
  259. n = snprintf(msg, len,
  260. "DIMM location: not present. DMI handle: 0x%.4x ",
  261. mem->mem_dev_handle);
  262. msg[n] = '\0';
  263. return n;
  264. }
  265. void cper_mem_err_pack(const struct cper_sec_mem_err *mem,
  266. struct cper_mem_err_compact *cmem)
  267. {
  268. cmem->validation_bits = mem->validation_bits;
  269. cmem->node = mem->node;
  270. cmem->card = mem->card;
  271. cmem->module = mem->module;
  272. cmem->bank = mem->bank;
  273. cmem->device = mem->device;
  274. cmem->row = mem->row;
  275. cmem->column = mem->column;
  276. cmem->bit_pos = mem->bit_pos;
  277. cmem->requestor_id = mem->requestor_id;
  278. cmem->responder_id = mem->responder_id;
  279. cmem->target_id = mem->target_id;
  280. cmem->rank = mem->rank;
  281. cmem->mem_array_handle = mem->mem_array_handle;
  282. cmem->mem_dev_handle = mem->mem_dev_handle;
  283. }
  284. const char *cper_mem_err_unpack(struct trace_seq *p,
  285. struct cper_mem_err_compact *cmem)
  286. {
  287. const char *ret = trace_seq_buffer_ptr(p);
  288. if (cper_mem_err_location(cmem, rcd_decode_str))
  289. trace_seq_printf(p, "%s", rcd_decode_str);
  290. if (cper_dimm_err_location(cmem, rcd_decode_str))
  291. trace_seq_printf(p, "%s", rcd_decode_str);
  292. trace_seq_putc(p, '\0');
  293. return ret;
  294. }
  295. static void cper_print_mem(const char *pfx, const struct cper_sec_mem_err *mem,
  296. int len)
  297. {
  298. struct cper_mem_err_compact cmem;
  299. /* Don't trust UEFI 2.1/2.2 structure with bad validation bits */
  300. if (len == sizeof(struct cper_sec_mem_err_old) &&
  301. (mem->validation_bits & ~(CPER_MEM_VALID_RANK_NUMBER - 1))) {
  302. pr_err(FW_WARN "valid bits set for fields beyond structure\n");
  303. return;
  304. }
  305. if (mem->validation_bits & CPER_MEM_VALID_ERROR_STATUS)
  306. printk("%s""error_status: 0x%016llx\n", pfx, mem->error_status);
  307. if (mem->validation_bits & CPER_MEM_VALID_PA)
  308. printk("%s""physical_address: 0x%016llx\n",
  309. pfx, mem->physical_addr);
  310. if (mem->validation_bits & CPER_MEM_VALID_PA_MASK)
  311. printk("%s""physical_address_mask: 0x%016llx\n",
  312. pfx, mem->physical_addr_mask);
  313. cper_mem_err_pack(mem, &cmem);
  314. if (cper_mem_err_location(&cmem, rcd_decode_str))
  315. printk("%s%s\n", pfx, rcd_decode_str);
  316. if (mem->validation_bits & CPER_MEM_VALID_ERROR_TYPE) {
  317. u8 etype = mem->error_type;
  318. printk("%s""error_type: %d, %s\n", pfx, etype,
  319. cper_mem_err_type_str(etype));
  320. }
  321. if (cper_dimm_err_location(&cmem, rcd_decode_str))
  322. printk("%s%s\n", pfx, rcd_decode_str);
  323. }
  324. static const char * const pcie_port_type_strs[] = {
  325. "PCIe end point",
  326. "legacy PCI end point",
  327. "unknown",
  328. "unknown",
  329. "root port",
  330. "upstream switch port",
  331. "downstream switch port",
  332. "PCIe to PCI/PCI-X bridge",
  333. "PCI/PCI-X to PCIe bridge",
  334. "root complex integrated endpoint device",
  335. "root complex event collector",
  336. };
  337. static void cper_print_pcie(const char *pfx, const struct cper_sec_pcie *pcie,
  338. const struct acpi_hest_generic_data *gdata)
  339. {
  340. if (pcie->validation_bits & CPER_PCIE_VALID_PORT_TYPE)
  341. printk("%s""port_type: %d, %s\n", pfx, pcie->port_type,
  342. pcie->port_type < ARRAY_SIZE(pcie_port_type_strs) ?
  343. pcie_port_type_strs[pcie->port_type] : "unknown");
  344. if (pcie->validation_bits & CPER_PCIE_VALID_VERSION)
  345. printk("%s""version: %d.%d\n", pfx,
  346. pcie->version.major, pcie->version.minor);
  347. if (pcie->validation_bits & CPER_PCIE_VALID_COMMAND_STATUS)
  348. printk("%s""command: 0x%04x, status: 0x%04x\n", pfx,
  349. pcie->command, pcie->status);
  350. if (pcie->validation_bits & CPER_PCIE_VALID_DEVICE_ID) {
  351. const __u8 *p;
  352. printk("%s""device_id: %04x:%02x:%02x.%x\n", pfx,
  353. pcie->device_id.segment, pcie->device_id.bus,
  354. pcie->device_id.device, pcie->device_id.function);
  355. printk("%s""slot: %d\n", pfx,
  356. pcie->device_id.slot >> CPER_PCIE_SLOT_SHIFT);
  357. printk("%s""secondary_bus: 0x%02x\n", pfx,
  358. pcie->device_id.secondary_bus);
  359. printk("%s""vendor_id: 0x%04x, device_id: 0x%04x\n", pfx,
  360. pcie->device_id.vendor_id, pcie->device_id.device_id);
  361. p = pcie->device_id.class_code;
  362. printk("%s""class_code: %02x%02x%02x\n", pfx, p[2], p[1], p[0]);
  363. }
  364. if (pcie->validation_bits & CPER_PCIE_VALID_SERIAL_NUMBER)
  365. printk("%s""serial number: 0x%04x, 0x%04x\n", pfx,
  366. pcie->serial_number.lower, pcie->serial_number.upper);
  367. if (pcie->validation_bits & CPER_PCIE_VALID_BRIDGE_CONTROL_STATUS)
  368. printk(
  369. "%s""bridge: secondary_status: 0x%04x, control: 0x%04x\n",
  370. pfx, pcie->bridge.secondary_status, pcie->bridge.control);
  371. /* Fatal errors call __ghes_panic() before AER handler prints this */
  372. if ((pcie->validation_bits & CPER_PCIE_VALID_AER_INFO) &&
  373. (gdata->error_severity & CPER_SEV_FATAL)) {
  374. struct aer_capability_regs *aer;
  375. aer = (struct aer_capability_regs *)pcie->aer_info;
  376. printk("%saer_uncor_status: 0x%08x, aer_uncor_mask: 0x%08x\n",
  377. pfx, aer->uncor_status, aer->uncor_mask);
  378. printk("%saer_uncor_severity: 0x%08x\n",
  379. pfx, aer->uncor_severity);
  380. printk("%sTLP Header: %08x %08x %08x %08x\n", pfx,
  381. aer->header_log.dw0, aer->header_log.dw1,
  382. aer->header_log.dw2, aer->header_log.dw3);
  383. }
  384. }
  385. static void cper_print_tstamp(const char *pfx,
  386. struct acpi_hest_generic_data_v300 *gdata)
  387. {
  388. __u8 hour, min, sec, day, mon, year, century, *timestamp;
  389. if (gdata->validation_bits & ACPI_HEST_GEN_VALID_TIMESTAMP) {
  390. timestamp = (__u8 *)&(gdata->time_stamp);
  391. sec = bcd2bin(timestamp[0]);
  392. min = bcd2bin(timestamp[1]);
  393. hour = bcd2bin(timestamp[2]);
  394. day = bcd2bin(timestamp[4]);
  395. mon = bcd2bin(timestamp[5]);
  396. year = bcd2bin(timestamp[6]);
  397. century = bcd2bin(timestamp[7]);
  398. printk("%s%ststamp: %02d%02d-%02d-%02d %02d:%02d:%02d\n", pfx,
  399. (timestamp[3] & 0x1 ? "precise " : "imprecise "),
  400. century, year, mon, day, hour, min, sec);
  401. }
  402. }
  403. static void
  404. cper_estatus_print_section(const char *pfx, struct acpi_hest_generic_data *gdata,
  405. int sec_no)
  406. {
  407. guid_t *sec_type = (guid_t *)gdata->section_type;
  408. __u16 severity;
  409. char newpfx[64];
  410. if (acpi_hest_get_version(gdata) >= 3)
  411. cper_print_tstamp(pfx, (struct acpi_hest_generic_data_v300 *)gdata);
  412. severity = gdata->error_severity;
  413. printk("%s""Error %d, type: %s\n", pfx, sec_no,
  414. cper_severity_str(severity));
  415. if (gdata->validation_bits & CPER_SEC_VALID_FRU_ID)
  416. printk("%s""fru_id: %pUl\n", pfx, gdata->fru_id);
  417. if (gdata->validation_bits & CPER_SEC_VALID_FRU_TEXT)
  418. printk("%s""fru_text: %.20s\n", pfx, gdata->fru_text);
  419. snprintf(newpfx, sizeof(newpfx), "%s ", pfx);
  420. if (guid_equal(sec_type, &CPER_SEC_PROC_GENERIC)) {
  421. struct cper_sec_proc_generic *proc_err = acpi_hest_get_payload(gdata);
  422. printk("%s""section_type: general processor error\n", newpfx);
  423. if (gdata->error_data_length >= sizeof(*proc_err))
  424. cper_print_proc_generic(newpfx, proc_err);
  425. else
  426. goto err_section_too_small;
  427. } else if (guid_equal(sec_type, &CPER_SEC_PLATFORM_MEM)) {
  428. struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata);
  429. printk("%s""section_type: memory error\n", newpfx);
  430. if (gdata->error_data_length >=
  431. sizeof(struct cper_sec_mem_err_old))
  432. cper_print_mem(newpfx, mem_err,
  433. gdata->error_data_length);
  434. else
  435. goto err_section_too_small;
  436. } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) {
  437. struct cper_sec_pcie *pcie = acpi_hest_get_payload(gdata);
  438. printk("%s""section_type: PCIe error\n", newpfx);
  439. if (gdata->error_data_length >= sizeof(*pcie))
  440. cper_print_pcie(newpfx, pcie, gdata);
  441. else
  442. goto err_section_too_small;
  443. #if defined(CONFIG_ARM64) || defined(CONFIG_ARM)
  444. } else if (guid_equal(sec_type, &CPER_SEC_PROC_ARM)) {
  445. struct cper_sec_proc_arm *arm_err = acpi_hest_get_payload(gdata);
  446. printk("%ssection_type: ARM processor error\n", newpfx);
  447. if (gdata->error_data_length >= sizeof(*arm_err))
  448. cper_print_proc_arm(newpfx, arm_err);
  449. else
  450. goto err_section_too_small;
  451. #endif
  452. #if defined(CONFIG_UEFI_CPER_X86)
  453. } else if (guid_equal(sec_type, &CPER_SEC_PROC_IA)) {
  454. struct cper_sec_proc_ia *ia_err = acpi_hest_get_payload(gdata);
  455. printk("%ssection_type: IA32/X64 processor error\n", newpfx);
  456. if (gdata->error_data_length >= sizeof(*ia_err))
  457. cper_print_proc_ia(newpfx, ia_err);
  458. else
  459. goto err_section_too_small;
  460. #endif
  461. } else {
  462. const void *err = acpi_hest_get_payload(gdata);
  463. printk("%ssection type: unknown, %pUl\n", newpfx, sec_type);
  464. printk("%ssection length: %#x\n", newpfx,
  465. gdata->error_data_length);
  466. print_hex_dump(newpfx, "", DUMP_PREFIX_OFFSET, 16, 4, err,
  467. gdata->error_data_length, true);
  468. }
  469. return;
  470. err_section_too_small:
  471. pr_err(FW_WARN "error section length is too small\n");
  472. }
  473. void cper_estatus_print(const char *pfx,
  474. const struct acpi_hest_generic_status *estatus)
  475. {
  476. struct acpi_hest_generic_data *gdata;
  477. int sec_no = 0;
  478. char newpfx[64];
  479. __u16 severity;
  480. severity = estatus->error_severity;
  481. if (severity == CPER_SEV_CORRECTED)
  482. printk("%s%s\n", pfx,
  483. "It has been corrected by h/w "
  484. "and requires no further action");
  485. printk("%s""event severity: %s\n", pfx, cper_severity_str(severity));
  486. snprintf(newpfx, sizeof(newpfx), "%s ", pfx);
  487. apei_estatus_for_each_section(estatus, gdata) {
  488. cper_estatus_print_section(newpfx, gdata, sec_no);
  489. sec_no++;
  490. }
  491. }
  492. EXPORT_SYMBOL_GPL(cper_estatus_print);
  493. int cper_estatus_check_header(const struct acpi_hest_generic_status *estatus)
  494. {
  495. if (estatus->data_length &&
  496. estatus->data_length < sizeof(struct acpi_hest_generic_data))
  497. return -EINVAL;
  498. if (estatus->raw_data_length &&
  499. estatus->raw_data_offset < sizeof(*estatus) + estatus->data_length)
  500. return -EINVAL;
  501. return 0;
  502. }
  503. EXPORT_SYMBOL_GPL(cper_estatus_check_header);
  504. int cper_estatus_check(const struct acpi_hest_generic_status *estatus)
  505. {
  506. struct acpi_hest_generic_data *gdata;
  507. unsigned int data_len, record_size;
  508. int rc;
  509. rc = cper_estatus_check_header(estatus);
  510. if (rc)
  511. return rc;
  512. data_len = estatus->data_length;
  513. apei_estatus_for_each_section(estatus, gdata) {
  514. if (sizeof(struct acpi_hest_generic_data) > data_len)
  515. return -EINVAL;
  516. record_size = acpi_hest_get_record_size(gdata);
  517. if (record_size > data_len)
  518. return -EINVAL;
  519. data_len -= record_size;
  520. }
  521. if (data_len)
  522. return -EINVAL;
  523. return 0;
  524. }
  525. EXPORT_SYMBOL_GPL(cper_estatus_check);