Lines Matching +full:no +full:- +full:dump +full:- +full:oops
1 // SPDX-License-Identifier: GPL-2.0-only
3 * RAM Oops/Panic logger
34 "size of each dump done on oops/panic");
51 "start of reserved RAM used to store oops/panic logs");
56 "size of reserved RAM used to store oops/panic logs");
61 "memory type: 0=write-combined (default), 1=unbuffered, 2=cached");
63 static int ramoops_max_reason = -1;
66 "maximum reason for kmsg dump (default 2: Oops and Panic) ");
71 "if non-zero, the option enables ECC support and specifies "
75 static int ramoops_dump_oops = -1;
78 "(deprecated: use max_reason instead) set to 1 to dump oopses & panics, 0 to only dump panics");
81 struct persistent_ram_zone **dprzs; /* Oops dump zones */
109 struct ramoops_context *cxt = psi->data; in ramoops_pstore_open()
111 cxt->dump_read_cnt = 0; in ramoops_pstore_open()
112 cxt->console_read_cnt = 0; in ramoops_pstore_open()
113 cxt->ftrace_read_cnt = 0; in ramoops_pstore_open()
114 cxt->pmsg_read_cnt = 0; in ramoops_pstore_open()
133 if (prz->type == PSTORE_TYPE_DMESG) in ramoops_get_next_prz()
139 record->type = prz->type; in ramoops_get_next_prz()
140 record->id = id; in ramoops_get_next_prz()
151 if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lld.%lu-%c\n%n", in ramoops_read_kmsg_hdr()
152 (time64_t *)&time->tv_sec, &time->tv_nsec, &data_type, in ramoops_read_kmsg_hdr()
154 time->tv_nsec *= 1000; in ramoops_read_kmsg_hdr()
160 (time64_t *)&time->tv_sec, &time->tv_nsec, in ramoops_read_kmsg_hdr()
162 time->tv_nsec *= 1000; in ramoops_read_kmsg_hdr()
165 time->tv_sec = 0; in ramoops_read_kmsg_hdr()
166 time->tv_nsec = 0; in ramoops_read_kmsg_hdr()
181 struct ramoops_context *cxt = record->psi->data; in ramoops_pstore_read()
191 record->time.tv_sec = 0; in ramoops_pstore_read()
192 record->time.tv_nsec = 0; in ramoops_pstore_read()
193 record->compressed = false; in ramoops_pstore_read()
196 while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { in ramoops_pstore_read()
197 prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++, in ramoops_pstore_read()
202 &record->time, in ramoops_pstore_read()
203 &record->compressed); in ramoops_pstore_read()
204 /* Clear and skip this DMESG record if it has no valid header */ in ramoops_pstore_read()
212 if (!prz_ok(prz) && !cxt->console_read_cnt++) in ramoops_pstore_read()
213 prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record); in ramoops_pstore_read()
215 if (!prz_ok(prz) && !cxt->pmsg_read_cnt++) in ramoops_pstore_read()
216 prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record); in ramoops_pstore_read()
220 if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) && in ramoops_pstore_read()
221 !cxt->ftrace_read_cnt++) { in ramoops_pstore_read()
222 prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */, in ramoops_pstore_read()
227 * per-cpu records including metadata and ecc info. in ramoops_pstore_read()
234 return -ENOMEM; in ramoops_pstore_read()
238 while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { in ramoops_pstore_read()
239 prz_next = ramoops_get_next_prz(cxt->fprzs, in ramoops_pstore_read()
240 cxt->ftrace_read_cnt++, record); in ramoops_pstore_read()
245 tmp_prz->ecc_info = prz_next->ecc_info; in ramoops_pstore_read()
246 tmp_prz->corrected_bytes += in ramoops_pstore_read()
247 prz_next->corrected_bytes; in ramoops_pstore_read()
248 tmp_prz->bad_blocks += prz_next->bad_blocks; in ramoops_pstore_read()
251 &tmp_prz->old_log, in ramoops_pstore_read()
252 &tmp_prz->old_log_size, in ramoops_pstore_read()
253 prz_next->old_log, in ramoops_pstore_read()
254 prz_next->old_log_size); in ramoops_pstore_read()
258 record->id = 0; in ramoops_pstore_read()
267 size = persistent_ram_old_size(prz) - header_length; in ramoops_pstore_read()
270 record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); in ramoops_pstore_read()
272 record->buf = kvzalloc(size + record->ecc_notice_size + 1, GFP_KERNEL); in ramoops_pstore_read()
273 if (record->buf == NULL) { in ramoops_pstore_read()
274 size = -ENOMEM; in ramoops_pstore_read()
278 memcpy(record->buf, (char *)persistent_ram_old(prz) + header_length, in ramoops_pstore_read()
281 persistent_ram_ecc_string(prz, record->buf + size, in ramoops_pstore_read()
282 record->ecc_notice_size + 1); in ramoops_pstore_read()
286 kvfree(prz->old_log); in ramoops_pstore_read()
296 char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */ in ramoops_write_kmsg_hdr()
300 RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", in ramoops_write_kmsg_hdr()
301 (time64_t)record->time.tv_sec, in ramoops_write_kmsg_hdr()
302 record->time.tv_nsec / 1000, in ramoops_write_kmsg_hdr()
303 record->compressed ? 'C' : 'D'); in ramoops_write_kmsg_hdr()
311 struct ramoops_context *cxt = record->psi->data; in ramoops_pstore_write()
315 if (record->type == PSTORE_TYPE_CONSOLE) { in ramoops_pstore_write()
316 if (!cxt->cprz) in ramoops_pstore_write()
317 return -ENOMEM; in ramoops_pstore_write()
318 persistent_ram_write(cxt->cprz, record->buf, record->size); in ramoops_pstore_write()
320 } else if (record->type == PSTORE_TYPE_FTRACE) { in ramoops_pstore_write()
323 if (!cxt->fprzs) in ramoops_pstore_write()
324 return -ENOMEM; in ramoops_pstore_write()
326 * Choose zone by if we're using per-cpu buffers. in ramoops_pstore_write()
328 if (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) in ramoops_pstore_write()
333 persistent_ram_write(cxt->fprzs[zonenum], record->buf, in ramoops_pstore_write()
334 record->size); in ramoops_pstore_write()
336 } else if (record->type == PSTORE_TYPE_PMSG) { in ramoops_pstore_write()
338 return -EINVAL; in ramoops_pstore_write()
341 if (record->type != PSTORE_TYPE_DMESG) in ramoops_pstore_write()
342 return -EINVAL; in ramoops_pstore_write()
345 * We could filter on record->reason here if we wanted to (which in ramoops_pstore_write()
360 if (record->part != 1) in ramoops_pstore_write()
361 return -ENOSPC; in ramoops_pstore_write()
363 if (!cxt->dprzs) in ramoops_pstore_write()
364 return -ENOSPC; in ramoops_pstore_write()
366 prz = cxt->dprzs[cxt->dump_write_cnt]; in ramoops_pstore_write()
369 * Since this is a new crash dump, we need to reset the buffer in in ramoops_pstore_write()
370 * case it still has an old dump present. Without this, the new dump in ramoops_pstore_write()
372 * to check dump file contents. Specifically, ramoops_read_kmsg_hdr() in ramoops_pstore_write()
373 * expects to find a dump header in the beginning of buffer data, so in ramoops_pstore_write()
382 return -ENOMEM; in ramoops_pstore_write()
384 size = record->size; in ramoops_pstore_write()
385 if (size + hlen > prz->buffer_size) in ramoops_pstore_write()
386 size = prz->buffer_size - hlen; in ramoops_pstore_write()
387 persistent_ram_write(prz, record->buf, size); in ramoops_pstore_write()
389 cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt; in ramoops_pstore_write()
397 if (record->type == PSTORE_TYPE_PMSG) { in ramoops_pstore_write_user()
398 struct ramoops_context *cxt = record->psi->data; in ramoops_pstore_write_user()
400 if (!cxt->mprz) in ramoops_pstore_write_user()
401 return -ENOMEM; in ramoops_pstore_write_user()
402 return persistent_ram_write_user(cxt->mprz, buf, record->size); in ramoops_pstore_write_user()
405 return -EINVAL; in ramoops_pstore_write_user()
410 struct ramoops_context *cxt = record->psi->data; in ramoops_pstore_erase()
413 switch (record->type) { in ramoops_pstore_erase()
415 if (record->id >= cxt->max_dump_cnt) in ramoops_pstore_erase()
416 return -EINVAL; in ramoops_pstore_erase()
417 prz = cxt->dprzs[record->id]; in ramoops_pstore_erase()
420 prz = cxt->cprz; in ramoops_pstore_erase()
423 if (record->id >= cxt->max_ftrace_cnt) in ramoops_pstore_erase()
424 return -EINVAL; in ramoops_pstore_erase()
425 prz = cxt->fprzs[record->id]; in ramoops_pstore_erase()
428 prz = cxt->mprz; in ramoops_pstore_erase()
431 return -EINVAL; in ramoops_pstore_erase()
457 persistent_ram_free(&cxt->mprz); in ramoops_free_przs()
460 persistent_ram_free(&cxt->cprz); in ramoops_free_przs()
462 /* Free dump PRZs */ in ramoops_free_przs()
463 if (cxt->dprzs) { in ramoops_free_przs()
464 for (i = 0; i < cxt->max_dump_cnt; i++) in ramoops_free_przs()
465 persistent_ram_free(&cxt->dprzs[i]); in ramoops_free_przs()
467 kfree(cxt->dprzs); in ramoops_free_przs()
468 cxt->dprzs = NULL; in ramoops_free_przs()
469 cxt->max_dump_cnt = 0; in ramoops_free_przs()
473 if (cxt->fprzs) { in ramoops_free_przs()
474 for (i = 0; i < cxt->max_ftrace_cnt; i++) in ramoops_free_przs()
475 persistent_ram_free(&cxt->fprzs[i]); in ramoops_free_przs()
476 kfree(cxt->fprzs); in ramoops_free_przs()
477 cxt->fprzs = NULL; in ramoops_free_przs()
478 cxt->max_ftrace_cnt = 0; in ramoops_free_przs()
489 int err = -ENOMEM; in ramoops_init_przs()
523 if (*paddr + mem_sz - cxt->phys_addr > cxt->size) { in ramoops_init_przs()
524 dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n", in ramoops_init_przs()
527 cxt->size, (unsigned long long)cxt->phys_addr); in ramoops_init_przs()
548 name, i, *cnt - 1); in ramoops_init_przs()
550 &cxt->ecc_info, in ramoops_init_przs()
551 cxt->memtype, flags, label); in ramoops_init_przs()
560 i--; in ramoops_init_przs()
568 prz_ar[i]->type = pstore_name_to_type(name); in ramoops_init_przs()
589 if (*paddr + sz - cxt->phys_addr > cxt->size) { in ramoops_init_prz()
590 dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n", in ramoops_init_prz()
592 cxt->size, (unsigned long long)cxt->phys_addr); in ramoops_init_prz()
593 return -ENOMEM; in ramoops_init_prz()
597 *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, in ramoops_init_prz()
598 cxt->memtype, PRZ_FLAG_ZAP_OLD, label); in ramoops_init_prz()
609 (*prz)->type = pstore_name_to_type(name); in ramoops_init_prz()
622 ret = of_property_read_u32(pdev->dev.of_node, propname, &val32); in ramoops_parse_dt_u32()
623 if (ret == -EINVAL) { in ramoops_parse_dt_u32()
627 dev_err(&pdev->dev, "failed to parse property %s: %d\n", in ramoops_parse_dt_u32()
634 dev_err(&pdev->dev, "%s %u > INT_MAX\n", propname, val32); in ramoops_parse_dt_u32()
635 return -EOVERFLOW; in ramoops_parse_dt_u32()
645 struct device_node *of_node = pdev->dev.of_node; in ramoops_parse_dt()
651 dev_dbg(&pdev->dev, "using Device Tree\n"); in ramoops_parse_dt()
655 dev_err(&pdev->dev, in ramoops_parse_dt()
656 "failed to locate DT /reserved-memory resource\n"); in ramoops_parse_dt()
657 return -EINVAL; in ramoops_parse_dt()
660 pdata->mem_size = resource_size(res); in ramoops_parse_dt()
661 pdata->mem_address = res->start; in ramoops_parse_dt()
666 pdata->mem_type = of_property_read_bool(of_node, "unbuffered"); in ramoops_parse_dt()
668 * Setting "no-dump-oops" is deprecated and will be ignored if in ramoops_parse_dt()
671 if (of_property_read_bool(of_node, "no-dump-oops")) in ramoops_parse_dt()
672 pdata->max_reason = KMSG_DUMP_PANIC; in ramoops_parse_dt()
674 pdata->max_reason = KMSG_DUMP_OOPS; in ramoops_parse_dt()
684 parse_u32("mem-type", pdata->mem_type, pdata->mem_type); in ramoops_parse_dt()
685 parse_u32("record-size", pdata->record_size, 0); in ramoops_parse_dt()
686 parse_u32("console-size", pdata->console_size, 0); in ramoops_parse_dt()
687 parse_u32("ftrace-size", pdata->ftrace_size, 0); in ramoops_parse_dt()
688 parse_u32("pmsg-size", pdata->pmsg_size, 0); in ramoops_parse_dt()
689 parse_u32("ecc-size", pdata->ecc_info.ecc_size, 0); in ramoops_parse_dt()
690 parse_u32("flags", pdata->flags, 0); in ramoops_parse_dt()
691 parse_u32("max-reason", pdata->max_reason, pdata->max_reason); in ramoops_parse_dt()
703 * we're not a child of "reserved-memory" and mimicking the in ramoops_parse_dt()
707 if (!of_node_name_eq(parent_node, "reserved-memory") && in ramoops_parse_dt()
708 !pdata->console_size && !pdata->ftrace_size && in ramoops_parse_dt()
709 !pdata->pmsg_size && !pdata->ecc_info.ecc_size) { in ramoops_parse_dt()
710 pdata->console_size = pdata->record_size; in ramoops_parse_dt()
711 pdata->pmsg_size = pdata->record_size; in ramoops_parse_dt()
720 struct device *dev = &pdev->dev; in ramoops_probe()
721 struct ramoops_platform_data *pdata = dev->platform_data; in ramoops_probe()
726 int err = -EINVAL; in ramoops_probe()
732 if (cxt->max_dump_cnt) { in ramoops_probe()
749 err = -EINVAL; in ramoops_probe()
753 if (!pdata->mem_size || (!pdata->record_size && !pdata->console_size && in ramoops_probe()
754 !pdata->ftrace_size && !pdata->pmsg_size)) { in ramoops_probe()
756 "non-zero\n"); in ramoops_probe()
757 err = -EINVAL; in ramoops_probe()
761 if (pdata->record_size && !is_power_of_2(pdata->record_size)) in ramoops_probe()
762 pdata->record_size = rounddown_pow_of_two(pdata->record_size); in ramoops_probe()
763 if (pdata->console_size && !is_power_of_2(pdata->console_size)) in ramoops_probe()
764 pdata->console_size = rounddown_pow_of_two(pdata->console_size); in ramoops_probe()
765 if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size)) in ramoops_probe()
766 pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size); in ramoops_probe()
767 if (pdata->pmsg_size && !is_power_of_2(pdata->pmsg_size)) in ramoops_probe()
768 pdata->pmsg_size = rounddown_pow_of_two(pdata->pmsg_size); in ramoops_probe()
770 cxt->size = pdata->mem_size; in ramoops_probe()
771 cxt->phys_addr = pdata->mem_address; in ramoops_probe()
772 cxt->memtype = pdata->mem_type; in ramoops_probe()
773 cxt->record_size = pdata->record_size; in ramoops_probe()
774 cxt->console_size = pdata->console_size; in ramoops_probe()
775 cxt->ftrace_size = pdata->ftrace_size; in ramoops_probe()
776 cxt->pmsg_size = pdata->pmsg_size; in ramoops_probe()
777 cxt->flags = pdata->flags; in ramoops_probe()
778 cxt->ecc_info = pdata->ecc_info; in ramoops_probe()
780 paddr = cxt->phys_addr; in ramoops_probe()
782 dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size in ramoops_probe()
783 - cxt->pmsg_size; in ramoops_probe()
784 err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr, in ramoops_probe()
785 dump_mem_sz, cxt->record_size, in ramoops_probe()
786 &cxt->max_dump_cnt, 0, 0); in ramoops_probe()
790 err = ramoops_init_prz("console", dev, cxt, &cxt->cprz, &paddr, in ramoops_probe()
791 cxt->console_size, 0); in ramoops_probe()
795 err = ramoops_init_prz("pmsg", dev, cxt, &cxt->mprz, &paddr, in ramoops_probe()
796 cxt->pmsg_size, 0); in ramoops_probe()
800 cxt->max_ftrace_cnt = (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) in ramoops_probe()
803 err = ramoops_init_przs("ftrace", dev, cxt, &cxt->fprzs, &paddr, in ramoops_probe()
804 cxt->ftrace_size, -1, in ramoops_probe()
805 &cxt->max_ftrace_cnt, LINUX_VERSION_CODE, in ramoops_probe()
806 (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) in ramoops_probe()
811 cxt->pstore.data = cxt; in ramoops_probe()
818 cxt->pstore.flags = 0; in ramoops_probe()
819 if (cxt->max_dump_cnt) { in ramoops_probe()
820 cxt->pstore.flags |= PSTORE_FLAGS_DMESG; in ramoops_probe()
821 cxt->pstore.max_reason = pdata->max_reason; in ramoops_probe()
823 if (cxt->console_size) in ramoops_probe()
824 cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE; in ramoops_probe()
825 if (cxt->max_ftrace_cnt) in ramoops_probe()
826 cxt->pstore.flags |= PSTORE_FLAGS_FTRACE; in ramoops_probe()
827 if (cxt->pmsg_size) in ramoops_probe()
828 cxt->pstore.flags |= PSTORE_FLAGS_PMSG; in ramoops_probe()
835 if (cxt->pstore.flags & PSTORE_FLAGS_DMESG) { in ramoops_probe()
836 cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size; in ramoops_probe()
837 cxt->pstore.buf = kvzalloc(cxt->pstore.bufsize, GFP_KERNEL); in ramoops_probe()
838 if (!cxt->pstore.buf) { in ramoops_probe()
839 pr_err("cannot allocate pstore crash dump buffer\n"); in ramoops_probe()
840 err = -ENOMEM; in ramoops_probe()
845 err = pstore_register(&cxt->pstore); in ramoops_probe()
855 mem_size = pdata->mem_size; in ramoops_probe()
856 mem_address = pdata->mem_address; in ramoops_probe()
857 record_size = pdata->record_size; in ramoops_probe()
858 ramoops_max_reason = pdata->max_reason; in ramoops_probe()
859 ramoops_console_size = pdata->console_size; in ramoops_probe()
860 ramoops_pmsg_size = pdata->pmsg_size; in ramoops_probe()
861 ramoops_ftrace_size = pdata->ftrace_size; in ramoops_probe()
864 cxt->size, (unsigned long long)cxt->phys_addr, in ramoops_probe()
865 cxt->ecc_info.ecc_size); in ramoops_probe()
870 kvfree(cxt->pstore.buf); in ramoops_probe()
872 cxt->pstore.bufsize = 0; in ramoops_probe()
883 pstore_unregister(&cxt->pstore); in ramoops_remove()
885 kvfree(cxt->pstore.buf); in ramoops_remove()
886 cxt->pstore.bufsize = 0; in ramoops_remove()
917 * parameters. If mem_size isn't set, then there are no module in ramoops_register_dummy()
937 else if (ramoops_dump_oops != -1) in ramoops_register_dummy()
951 dummy = platform_device_register_data(NULL, "ramoops", -1, in ramoops_register_dummy()
982 MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");