.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * RAM Oops/Panic logger |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com> |
---|
5 | 6 | * Copyright (C) 2011 Kees Cook <keescook@chromium.org> |
---|
6 | | - * |
---|
7 | | - * This program is free software; you can redistribute it and/or |
---|
8 | | - * modify it under the terms of the GNU General Public License |
---|
9 | | - * version 2 as published by the Free Software Foundation. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, but |
---|
12 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | | - * General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License |
---|
17 | | - * along with this program; if not, write to the Free Software |
---|
18 | | - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
---|
19 | | - * 02110-1301 USA |
---|
20 | | - * |
---|
21 | 7 | */ |
---|
22 | 8 | |
---|
23 | 9 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
---|
.. | .. |
---|
35 | 21 | #include <linux/pstore_ram.h> |
---|
36 | 22 | #include <linux/of.h> |
---|
37 | 23 | #include <linux/of_address.h> |
---|
| 24 | +#include <linux/of_reserved_mem.h> |
---|
| 25 | +#include "internal.h" |
---|
| 26 | + |
---|
| 27 | +#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP) |
---|
| 28 | +#include <soc/rockchip/rk_minidump.h> |
---|
| 29 | +#endif |
---|
38 | 30 | |
---|
39 | 31 | #define RAMOOPS_KERNMSG_HDR "====" |
---|
40 | 32 | #define MIN_MEM_SIZE 4096UL |
---|
.. | .. |
---|
67 | 59 | "size of reserved RAM used to store oops/panic logs"); |
---|
68 | 60 | |
---|
69 | 61 | static unsigned int mem_type; |
---|
70 | | -module_param(mem_type, uint, 0600); |
---|
| 62 | +module_param(mem_type, uint, 0400); |
---|
71 | 63 | MODULE_PARM_DESC(mem_type, |
---|
72 | | - "set to 1 to try to use unbuffered memory (default 0)"); |
---|
| 64 | + "memory type: 0=write-combined (default), 1=unbuffered, 2=cached"); |
---|
73 | 65 | |
---|
74 | | -static int dump_oops = 1; |
---|
75 | | -module_param(dump_oops, int, 0600); |
---|
76 | | -MODULE_PARM_DESC(dump_oops, |
---|
77 | | - "set to 1 to dump oopses, 0 to only dump panics (default 1)"); |
---|
| 66 | +static int ramoops_max_reason = -1; |
---|
| 67 | +module_param_named(max_reason, ramoops_max_reason, int, 0400); |
---|
| 68 | +MODULE_PARM_DESC(max_reason, |
---|
| 69 | + "maximum reason for kmsg dump (default 2: Oops and Panic) "); |
---|
78 | 70 | |
---|
79 | 71 | static int ramoops_ecc; |
---|
80 | | -module_param_named(ecc, ramoops_ecc, int, 0600); |
---|
| 72 | +module_param_named(ecc, ramoops_ecc, int, 0400); |
---|
81 | 73 | MODULE_PARM_DESC(ramoops_ecc, |
---|
82 | 74 | "if non-zero, the option enables ECC support and specifies " |
---|
83 | 75 | "ECC buffer size in bytes (1 is a special value, means 16 " |
---|
84 | 76 | "bytes ECC)"); |
---|
85 | 77 | |
---|
| 78 | +static int ramoops_dump_oops = -1; |
---|
| 79 | +module_param_named(dump_oops, ramoops_dump_oops, int, 0400); |
---|
| 80 | +MODULE_PARM_DESC(dump_oops, |
---|
| 81 | + "(deprecated: use max_reason instead) set to 1 to dump oopses & panics, 0 to only dump panics"); |
---|
| 82 | + |
---|
| 83 | +struct ramoops_context { |
---|
| 84 | + struct persistent_ram_zone **dprzs; /* Oops dump zones */ |
---|
| 85 | + struct persistent_ram_zone *cprz; /* Console zone */ |
---|
| 86 | + struct persistent_ram_zone **fprzs; /* Ftrace zones */ |
---|
| 87 | + struct persistent_ram_zone *mprz; /* PMSG zone */ |
---|
| 88 | +#ifdef CONFIG_PSTORE_BOOT_LOG |
---|
| 89 | + struct persistent_ram_zone **boot_przs; /* BOOT log zones */ |
---|
| 90 | +#endif |
---|
| 91 | + phys_addr_t phys_addr; |
---|
| 92 | + unsigned long size; |
---|
| 93 | + unsigned int memtype; |
---|
| 94 | + size_t record_size; |
---|
| 95 | + size_t console_size; |
---|
| 96 | + size_t ftrace_size; |
---|
| 97 | + size_t pmsg_size; |
---|
| 98 | +#ifdef CONFIG_PSTORE_BOOT_LOG |
---|
| 99 | + size_t boot_log_size; |
---|
| 100 | +#endif |
---|
| 101 | + u32 flags; |
---|
| 102 | + struct persistent_ram_ecc_info ecc_info; |
---|
| 103 | + unsigned int max_dump_cnt; |
---|
| 104 | + unsigned int dump_write_cnt; |
---|
| 105 | + /* _read_cnt need clear on ramoops_pstore_open */ |
---|
| 106 | + unsigned int dump_read_cnt; |
---|
| 107 | + unsigned int console_read_cnt; |
---|
| 108 | + unsigned int max_ftrace_cnt; |
---|
| 109 | + unsigned int ftrace_read_cnt; |
---|
| 110 | + unsigned int pmsg_read_cnt; |
---|
| 111 | +#ifdef CONFIG_PSTORE_BOOT_LOG |
---|
| 112 | + unsigned int boot_log_read_cnt; |
---|
| 113 | + unsigned int max_boot_log_cnt; |
---|
| 114 | +#endif |
---|
| 115 | + struct pstore_info pstore; |
---|
| 116 | +}; |
---|
| 117 | + |
---|
86 | 118 | static struct platform_device *dummy; |
---|
87 | | -static struct ramoops_platform_data *dummy_data; |
---|
88 | 119 | |
---|
89 | 120 | static int ramoops_pstore_open(struct pstore_info *psi) |
---|
90 | 121 | { |
---|
.. | .. |
---|
98 | 129 | } |
---|
99 | 130 | |
---|
100 | 131 | static struct persistent_ram_zone * |
---|
101 | | -ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, |
---|
102 | | - u64 *id, |
---|
103 | | - enum pstore_type_id *typep, enum pstore_type_id type, |
---|
104 | | - bool update) |
---|
| 132 | +ramoops_get_next_prz(struct persistent_ram_zone *przs[], int id, |
---|
| 133 | + struct pstore_record *record) |
---|
105 | 134 | { |
---|
106 | 135 | struct persistent_ram_zone *prz; |
---|
107 | | - int i = (*c)++; |
---|
108 | 136 | |
---|
109 | 137 | /* Give up if we never existed or have hit the end. */ |
---|
110 | | - if (!przs || i >= max) |
---|
| 138 | + if (!przs) |
---|
111 | 139 | return NULL; |
---|
112 | 140 | |
---|
113 | | - prz = przs[i]; |
---|
| 141 | + prz = przs[id]; |
---|
114 | 142 | if (!prz) |
---|
115 | 143 | return NULL; |
---|
116 | 144 | |
---|
117 | 145 | /* Update old/shadowed buffer. */ |
---|
118 | | - if (update) |
---|
| 146 | + if (prz->type == PSTORE_TYPE_DMESG) |
---|
119 | 147 | persistent_ram_save_old(prz); |
---|
120 | 148 | |
---|
121 | 149 | if (!persistent_ram_old_size(prz)) |
---|
122 | 150 | return NULL; |
---|
123 | 151 | |
---|
124 | | - *typep = type; |
---|
125 | | - *id = i; |
---|
| 152 | + record->type = prz->type; |
---|
| 153 | + record->id = id; |
---|
126 | 154 | |
---|
127 | 155 | return prz; |
---|
128 | 156 | } |
---|
.. | .. |
---|
160 | 188 | persistent_ram_ecc_string(prz, NULL, 0)); |
---|
161 | 189 | } |
---|
162 | 190 | |
---|
163 | | -static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest, |
---|
164 | | - struct persistent_ram_zone *src) |
---|
| 191 | +#ifdef CONFIG_PSTORE_BOOT_LOG |
---|
| 192 | +ssize_t ramoops_pstore_read_for_boot_log(struct pstore_record *record) |
---|
165 | 193 | { |
---|
166 | | - size_t dest_size, src_size, total, dest_off, src_off; |
---|
167 | | - size_t dest_idx = 0, src_idx = 0, merged_idx = 0; |
---|
168 | | - void *merged_buf; |
---|
169 | | - struct pstore_ftrace_record *drec, *srec, *mrec; |
---|
170 | | - size_t record_size = sizeof(struct pstore_ftrace_record); |
---|
| 194 | + struct ramoops_context *cxt = record->psi->data; |
---|
| 195 | + struct persistent_ram_zone *prz; |
---|
171 | 196 | |
---|
172 | | - dest_off = dest->old_log_size % record_size; |
---|
173 | | - dest_size = dest->old_log_size - dest_off; |
---|
| 197 | + if (!cxt) |
---|
| 198 | + return 0; |
---|
174 | 199 | |
---|
175 | | - src_off = src->old_log_size % record_size; |
---|
176 | | - src_size = src->old_log_size - src_off; |
---|
| 200 | + prz = cxt->boot_przs[record->id]; |
---|
177 | 201 | |
---|
178 | | - total = dest_size + src_size; |
---|
179 | | - merged_buf = kmalloc(total, GFP_KERNEL); |
---|
180 | | - if (!merged_buf) |
---|
181 | | - return -ENOMEM; |
---|
| 202 | + if (!prz) |
---|
| 203 | + return 0; |
---|
182 | 204 | |
---|
183 | | - drec = (struct pstore_ftrace_record *)(dest->old_log + dest_off); |
---|
184 | | - srec = (struct pstore_ftrace_record *)(src->old_log + src_off); |
---|
185 | | - mrec = (struct pstore_ftrace_record *)(merged_buf); |
---|
186 | | - |
---|
187 | | - while (dest_size > 0 && src_size > 0) { |
---|
188 | | - if (pstore_ftrace_read_timestamp(&drec[dest_idx]) < |
---|
189 | | - pstore_ftrace_read_timestamp(&srec[src_idx])) { |
---|
190 | | - mrec[merged_idx++] = drec[dest_idx++]; |
---|
191 | | - dest_size -= record_size; |
---|
192 | | - } else { |
---|
193 | | - mrec[merged_idx++] = srec[src_idx++]; |
---|
194 | | - src_size -= record_size; |
---|
195 | | - } |
---|
196 | | - } |
---|
197 | | - |
---|
198 | | - while (dest_size > 0) { |
---|
199 | | - mrec[merged_idx++] = drec[dest_idx++]; |
---|
200 | | - dest_size -= record_size; |
---|
201 | | - } |
---|
202 | | - |
---|
203 | | - while (src_size > 0) { |
---|
204 | | - mrec[merged_idx++] = srec[src_idx++]; |
---|
205 | | - src_size -= record_size; |
---|
206 | | - } |
---|
207 | | - |
---|
208 | | - kfree(dest->old_log); |
---|
209 | | - dest->old_log = merged_buf; |
---|
210 | | - dest->old_log_size = total; |
---|
211 | | - |
---|
212 | | - return 0; |
---|
| 205 | + persistent_ram_free_old(prz); |
---|
| 206 | + persistent_ram_save_old(prz); |
---|
| 207 | + record->buf = prz->old_log; |
---|
| 208 | + record->size = prz->old_log_size; |
---|
| 209 | + return record->size; |
---|
213 | 210 | } |
---|
| 211 | +#endif |
---|
214 | 212 | |
---|
215 | 213 | static ssize_t ramoops_pstore_read(struct pstore_record *record) |
---|
216 | 214 | { |
---|
.. | .. |
---|
231 | 229 | |
---|
232 | 230 | /* Find the next valid persistent_ram_zone for DMESG */ |
---|
233 | 231 | while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { |
---|
234 | | - prz = ramoops_get_next_prz(cxt->dprzs, &cxt->dump_read_cnt, |
---|
235 | | - cxt->max_dump_cnt, &record->id, |
---|
236 | | - &record->type, |
---|
237 | | - PSTORE_TYPE_DMESG, 1); |
---|
| 232 | + prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++, |
---|
| 233 | + record); |
---|
238 | 234 | if (!prz_ok(prz)) |
---|
239 | 235 | continue; |
---|
240 | 236 | header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz), |
---|
.. | .. |
---|
248 | 244 | } |
---|
249 | 245 | } |
---|
250 | 246 | |
---|
251 | | - if (!prz_ok(prz)) |
---|
252 | | - prz = ramoops_get_next_prz(&cxt->cprz, &cxt->console_read_cnt, |
---|
253 | | - 1, &record->id, &record->type, |
---|
254 | | - PSTORE_TYPE_CONSOLE, 0); |
---|
| 247 | + if (!prz_ok(prz) && !cxt->console_read_cnt++) |
---|
| 248 | + prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record); |
---|
255 | 249 | |
---|
256 | | - if (!prz_ok(prz)) |
---|
257 | | - prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt, |
---|
258 | | - 1, &record->id, &record->type, |
---|
259 | | - PSTORE_TYPE_PMSG, 0); |
---|
| 250 | + if (!prz_ok(prz) && !cxt->pmsg_read_cnt++) |
---|
| 251 | + prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record); |
---|
260 | 252 | |
---|
261 | 253 | /* ftrace is last since it may want to dynamically allocate memory. */ |
---|
262 | 254 | if (!prz_ok(prz)) { |
---|
263 | | - if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)) { |
---|
264 | | - prz = ramoops_get_next_prz(cxt->fprzs, |
---|
265 | | - &cxt->ftrace_read_cnt, 1, &record->id, |
---|
266 | | - &record->type, PSTORE_TYPE_FTRACE, 0); |
---|
| 255 | + if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) && |
---|
| 256 | + !cxt->ftrace_read_cnt++) { |
---|
| 257 | + prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */, |
---|
| 258 | + record); |
---|
267 | 259 | } else { |
---|
268 | 260 | /* |
---|
269 | 261 | * Build a new dummy record which combines all the |
---|
.. | .. |
---|
280 | 272 | |
---|
281 | 273 | while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { |
---|
282 | 274 | prz_next = ramoops_get_next_prz(cxt->fprzs, |
---|
283 | | - &cxt->ftrace_read_cnt, |
---|
284 | | - cxt->max_ftrace_cnt, |
---|
285 | | - &record->id, |
---|
286 | | - &record->type, |
---|
287 | | - PSTORE_TYPE_FTRACE, 0); |
---|
| 275 | + cxt->ftrace_read_cnt++, record); |
---|
288 | 276 | |
---|
289 | 277 | if (!prz_ok(prz_next)) |
---|
290 | 278 | continue; |
---|
.. | .. |
---|
293 | 281 | tmp_prz->corrected_bytes += |
---|
294 | 282 | prz_next->corrected_bytes; |
---|
295 | 283 | tmp_prz->bad_blocks += prz_next->bad_blocks; |
---|
296 | | - size = ftrace_log_combine(tmp_prz, prz_next); |
---|
| 284 | + |
---|
| 285 | + size = pstore_ftrace_combine_log( |
---|
| 286 | + &tmp_prz->old_log, |
---|
| 287 | + &tmp_prz->old_log_size, |
---|
| 288 | + prz_next->old_log, |
---|
| 289 | + prz_next->old_log_size); |
---|
297 | 290 | if (size) |
---|
298 | 291 | goto out; |
---|
299 | 292 | } |
---|
.. | .. |
---|
304 | 297 | #ifdef CONFIG_PSTORE_BOOT_LOG |
---|
305 | 298 | if (!prz_ok(prz)) { |
---|
306 | 299 | while (cxt->boot_log_read_cnt < cxt->max_boot_log_cnt && !prz) { |
---|
307 | | - prz = ramoops_get_next_prz(cxt->boot_przs, &cxt->boot_log_read_cnt, |
---|
308 | | - cxt->max_boot_log_cnt, &record->id, |
---|
309 | | - &record->type, |
---|
310 | | - PSTORE_TYPE_BOOT_LOG, 0); |
---|
| 300 | + prz = ramoops_get_next_prz(cxt->boot_przs, cxt->boot_log_read_cnt++, record); |
---|
311 | 301 | if (!prz_ok(prz)) |
---|
312 | 302 | continue; |
---|
313 | 303 | } |
---|
.. | .. |
---|
319 | 309 | goto out; |
---|
320 | 310 | } |
---|
321 | 311 | |
---|
322 | | - size = persistent_ram_old_size(prz) - header_length; |
---|
323 | 312 | #ifdef CONFIG_PSTORE_BOOT_LOG |
---|
324 | | - /* don't copy boot log */ |
---|
325 | | - if (record->type == PSTORE_TYPE_BOOT_LOG) |
---|
326 | | - goto out; |
---|
| 313 | + if (record->type == PSTORE_TYPE_BOOT_LOG) { |
---|
| 314 | + persistent_ram_free_old(prz); |
---|
| 315 | + persistent_ram_save_old(prz); |
---|
| 316 | + } |
---|
327 | 317 | #endif |
---|
| 318 | + |
---|
| 319 | + size = persistent_ram_old_size(prz) - header_length; |
---|
| 320 | + |
---|
328 | 321 | /* ECC correction notice */ |
---|
329 | 322 | record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0); |
---|
330 | 323 | |
---|
.. | .. |
---|
352 | 345 | static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, |
---|
353 | 346 | struct pstore_record *record) |
---|
354 | 347 | { |
---|
355 | | - char *hdr; |
---|
| 348 | + char hdr[36]; /* "===="(4), %lld(20), "."(1), %06lu(6), "-%c\n"(3) */ |
---|
356 | 349 | size_t len; |
---|
357 | 350 | |
---|
358 | | - hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", |
---|
| 351 | + len = scnprintf(hdr, sizeof(hdr), |
---|
| 352 | + RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n", |
---|
359 | 353 | (time64_t)record->time.tv_sec, |
---|
360 | 354 | record->time.tv_nsec / 1000, |
---|
361 | 355 | record->compressed ? 'C' : 'D'); |
---|
362 | | - WARN_ON_ONCE(!hdr); |
---|
363 | | - len = hdr ? strlen(hdr) : 0; |
---|
364 | 356 | persistent_ram_write(prz, hdr, len); |
---|
365 | | - kfree(hdr); |
---|
366 | 357 | |
---|
367 | 358 | return len; |
---|
368 | 359 | } |
---|
.. | .. |
---|
403 | 394 | return -EINVAL; |
---|
404 | 395 | |
---|
405 | 396 | /* |
---|
406 | | - * Out of the various dmesg dump types, ramoops is currently designed |
---|
407 | | - * to only store crash logs, rather than storing general kernel logs. |
---|
| 397 | + * We could filter on record->reason here if we wanted to (which |
---|
| 398 | + * would duplicate what happened before the "max_reason" setting |
---|
| 399 | + * was added), but that would defeat the purpose of a system |
---|
| 400 | + * changing printk.always_kmsg_dump, so instead log everything that |
---|
| 401 | + * the kmsg dumper sends us, since it should be doing the filtering |
---|
| 402 | + * based on the combination of printk.always_kmsg_dump and our |
---|
| 403 | + * requested "max_reason". |
---|
408 | 404 | */ |
---|
409 | | - if (record->reason != KMSG_DUMP_OOPS && |
---|
410 | | - record->reason != KMSG_DUMP_PANIC) |
---|
411 | | - return -EINVAL; |
---|
412 | | - |
---|
413 | | - /* Skip Oopes when configured to do so. */ |
---|
414 | | - if (record->reason == KMSG_DUMP_OOPS && !cxt->dump_oops) |
---|
415 | | - return -EINVAL; |
---|
416 | 405 | |
---|
417 | 406 | /* |
---|
418 | 407 | * Explicitly only take the first part of any new crash. |
---|
.. | .. |
---|
441 | 430 | |
---|
442 | 431 | /* Build header and append record contents. */ |
---|
443 | 432 | hlen = ramoops_write_kmsg_hdr(prz, record); |
---|
| 433 | + if (!hlen) |
---|
| 434 | + return -ENOMEM; |
---|
| 435 | + |
---|
444 | 436 | size = record->size; |
---|
445 | 437 | if (size + hlen > prz->buffer_size) |
---|
446 | 438 | size = prz->buffer_size - hlen; |
---|
.. | .. |
---|
600 | 592 | goto fail; |
---|
601 | 593 | |
---|
602 | 594 | for (i = 0; i < *cnt; i++) { |
---|
| 595 | + char *label; |
---|
| 596 | + |
---|
| 597 | + if (*cnt == 1) |
---|
| 598 | + label = kasprintf(GFP_KERNEL, "ramoops:%s", name); |
---|
| 599 | + else |
---|
| 600 | + label = kasprintf(GFP_KERNEL, "ramoops:%s(%d/%d)", |
---|
| 601 | + name, i, *cnt - 1); |
---|
603 | 602 | prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig, |
---|
604 | | - &cxt->ecc_info, |
---|
605 | | - cxt->memtype, flags); |
---|
| 603 | + &cxt->ecc_info, |
---|
| 604 | + cxt->memtype, flags, label); |
---|
| 605 | + kfree(label); |
---|
606 | 606 | if (IS_ERR(prz_ar[i])) { |
---|
607 | 607 | err = PTR_ERR(prz_ar[i]); |
---|
608 | 608 | dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n", |
---|
.. | .. |
---|
617 | 617 | goto fail; |
---|
618 | 618 | } |
---|
619 | 619 | *paddr += zone_sz; |
---|
| 620 | + prz_ar[i]->type = pstore_name_to_type(name); |
---|
620 | 621 | } |
---|
621 | 622 | |
---|
622 | 623 | *przs = prz_ar; |
---|
.. | .. |
---|
632 | 633 | struct persistent_ram_zone **prz, |
---|
633 | 634 | phys_addr_t *paddr, size_t sz, u32 sig) |
---|
634 | 635 | { |
---|
| 636 | + char *label; |
---|
| 637 | + |
---|
635 | 638 | if (!sz) |
---|
636 | 639 | return 0; |
---|
637 | 640 | |
---|
.. | .. |
---|
642 | 645 | return -ENOMEM; |
---|
643 | 646 | } |
---|
644 | 647 | |
---|
| 648 | + label = kasprintf(GFP_KERNEL, "ramoops:%s", name); |
---|
645 | 649 | *prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, |
---|
646 | | - cxt->memtype, 0); |
---|
| 650 | + cxt->memtype, PRZ_FLAG_ZAP_OLD, label); |
---|
| 651 | + kfree(label); |
---|
647 | 652 | if (IS_ERR(*prz)) { |
---|
648 | 653 | int err = PTR_ERR(*prz); |
---|
649 | 654 | |
---|
.. | .. |
---|
652 | 657 | return err; |
---|
653 | 658 | } |
---|
654 | 659 | |
---|
655 | | - persistent_ram_zap(*prz); |
---|
656 | | - |
---|
657 | 660 | *paddr += sz; |
---|
| 661 | + (*prz)->type = pstore_name_to_type(name); |
---|
658 | 662 | |
---|
659 | 663 | return 0; |
---|
660 | 664 | } |
---|
661 | 665 | |
---|
662 | | -static int ramoops_parse_dt_size(struct platform_device *pdev, |
---|
663 | | - const char *propname, u32 *value) |
---|
| 666 | +/* Read a u32 from a dt property and make sure it's safe for an int. */ |
---|
| 667 | +static int ramoops_parse_dt_u32(struct platform_device *pdev, |
---|
| 668 | + const char *propname, |
---|
| 669 | + u32 default_value, u32 *value) |
---|
664 | 670 | { |
---|
665 | 671 | u32 val32 = 0; |
---|
666 | 672 | int ret; |
---|
667 | 673 | |
---|
668 | 674 | ret = of_property_read_u32(pdev->dev.of_node, propname, &val32); |
---|
669 | | - if (ret < 0 && ret != -EINVAL) { |
---|
| 675 | + if (ret == -EINVAL) { |
---|
| 676 | + /* field is missing, use default value. */ |
---|
| 677 | + val32 = default_value; |
---|
| 678 | + } else if (ret < 0) { |
---|
670 | 679 | dev_err(&pdev->dev, "failed to parse property %s: %d\n", |
---|
671 | 680 | propname, ret); |
---|
672 | 681 | return ret; |
---|
673 | 682 | } |
---|
674 | 683 | |
---|
| 684 | + /* Sanity check our results. */ |
---|
675 | 685 | if (val32 > INT_MAX) { |
---|
676 | 686 | dev_err(&pdev->dev, "%s %u > INT_MAX\n", propname, val32); |
---|
677 | 687 | return -EOVERFLOW; |
---|
.. | .. |
---|
685 | 695 | struct ramoops_platform_data *pdata) |
---|
686 | 696 | { |
---|
687 | 697 | struct device_node *of_node = pdev->dev.of_node; |
---|
| 698 | + struct device_node *parent_node; |
---|
| 699 | + struct reserved_mem *rmem; |
---|
688 | 700 | struct resource *res; |
---|
689 | 701 | u32 value; |
---|
690 | 702 | int ret; |
---|
.. | .. |
---|
693 | 705 | |
---|
694 | 706 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
695 | 707 | if (!res) { |
---|
696 | | - dev_err(&pdev->dev, |
---|
697 | | - "failed to locate DT /reserved-memory resource\n"); |
---|
698 | | - return -EINVAL; |
---|
| 708 | + rmem = of_reserved_mem_lookup(of_node); |
---|
| 709 | + if (rmem) { |
---|
| 710 | + pdata->mem_size = rmem->size; |
---|
| 711 | + pdata->mem_address = rmem->base; |
---|
| 712 | + } else { |
---|
| 713 | + dev_err(&pdev->dev, |
---|
| 714 | + "failed to locate DT /reserved-memory resource\n"); |
---|
| 715 | + return -EINVAL; |
---|
| 716 | + } |
---|
| 717 | + } else { |
---|
| 718 | + pdata->mem_size = resource_size(res); |
---|
| 719 | + pdata->mem_address = res->start; |
---|
699 | 720 | } |
---|
700 | 721 | |
---|
701 | | - pdata->mem_size = resource_size(res); |
---|
702 | | - pdata->mem_address = res->start; |
---|
| 722 | + /* |
---|
| 723 | + * Setting "unbuffered" is deprecated and will be ignored if |
---|
| 724 | + * "mem_type" is also specified. |
---|
| 725 | + */ |
---|
703 | 726 | pdata->mem_type = of_property_read_bool(of_node, "unbuffered"); |
---|
704 | | - pdata->dump_oops = !of_property_read_bool(of_node, "no-dump-oops"); |
---|
| 727 | + /* |
---|
| 728 | + * Setting "no-dump-oops" is deprecated and will be ignored if |
---|
| 729 | + * "max_reason" is also specified. |
---|
| 730 | + */ |
---|
| 731 | + if (of_property_read_bool(of_node, "no-dump-oops")) |
---|
| 732 | + pdata->max_reason = KMSG_DUMP_PANIC; |
---|
| 733 | + else |
---|
| 734 | + pdata->max_reason = KMSG_DUMP_OOPS; |
---|
705 | 735 | |
---|
706 | | -#define parse_size(name, field) { \ |
---|
707 | | - ret = ramoops_parse_dt_size(pdev, name, &value); \ |
---|
| 736 | +#define parse_u32(name, field, default_value) { \ |
---|
| 737 | + ret = ramoops_parse_dt_u32(pdev, name, default_value, \ |
---|
| 738 | + &value); \ |
---|
708 | 739 | if (ret < 0) \ |
---|
709 | 740 | return ret; \ |
---|
710 | 741 | field = value; \ |
---|
711 | 742 | } |
---|
712 | 743 | |
---|
713 | | - parse_size("record-size", pdata->record_size); |
---|
714 | | - parse_size("console-size", pdata->console_size); |
---|
715 | | - parse_size("ftrace-size", pdata->ftrace_size); |
---|
716 | | - parse_size("pmsg-size", pdata->pmsg_size); |
---|
717 | | - parse_size("ecc-size", pdata->ecc_info.ecc_size); |
---|
718 | | - parse_size("flags", pdata->flags); |
---|
| 744 | + parse_u32("mem-type", pdata->mem_type, pdata->mem_type); |
---|
| 745 | + parse_u32("record-size", pdata->record_size, 0); |
---|
| 746 | + parse_u32("console-size", pdata->console_size, 0); |
---|
| 747 | + parse_u32("ftrace-size", pdata->ftrace_size, 0); |
---|
| 748 | + parse_u32("pmsg-size", pdata->pmsg_size, 0); |
---|
| 749 | + parse_u32("ecc-size", pdata->ecc_info.ecc_size, 0); |
---|
| 750 | + parse_u32("flags", pdata->flags, 0); |
---|
| 751 | + parse_u32("max-reason", pdata->max_reason, pdata->max_reason); |
---|
719 | 752 | #ifdef CONFIG_PSTORE_BOOT_LOG |
---|
720 | | - parse_size("boot-log-size", pdata->boot_log_size); |
---|
721 | | - parse_size("boot-log-count", pdata->max_boot_log_cnt); |
---|
| 753 | + parse_u32("boot-log-size", pdata->boot_log_size, 0); |
---|
| 754 | + parse_u32("boot-log-count", pdata->max_boot_log_cnt, 0); |
---|
722 | 755 | #endif |
---|
723 | | -#undef parse_size |
---|
| 756 | + |
---|
| 757 | +#undef parse_u32 |
---|
| 758 | + |
---|
| 759 | + /* |
---|
| 760 | + * Some old Chromebooks relied on the kernel setting the |
---|
| 761 | + * console_size and pmsg_size to the record size since that's |
---|
| 762 | + * what the downstream kernel did. These same Chromebooks had |
---|
| 763 | + * "ramoops" straight under the root node which isn't |
---|
| 764 | + * according to the current upstream bindings (though it was |
---|
| 765 | + * arguably acceptable under a prior version of the bindings). |
---|
| 766 | + * Let's make those old Chromebooks work by detecting that |
---|
| 767 | + * we're not a child of "reserved-memory" and mimicking the |
---|
| 768 | + * expected behavior. |
---|
| 769 | + */ |
---|
| 770 | + parent_node = of_get_parent(of_node); |
---|
| 771 | + if (!of_node_name_eq(parent_node, "reserved-memory") && |
---|
| 772 | + !pdata->console_size && !pdata->ftrace_size && |
---|
| 773 | + !pdata->pmsg_size && !pdata->ecc_info.ecc_size) { |
---|
| 774 | + pdata->console_size = pdata->record_size; |
---|
| 775 | + pdata->pmsg_size = pdata->record_size; |
---|
| 776 | + } |
---|
| 777 | + of_node_put(parent_node); |
---|
724 | 778 | |
---|
725 | 779 | return 0; |
---|
726 | 780 | } |
---|
| 781 | + |
---|
| 782 | +#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP) |
---|
| 783 | +static void _ramoops_register_ram_zone_info_to_minidump(struct persistent_ram_zone *prz) |
---|
| 784 | +{ |
---|
| 785 | + struct md_region md_entry = {}; |
---|
| 786 | + |
---|
| 787 | + strscpy(md_entry.name, prz->label, sizeof(md_entry.name)); |
---|
| 788 | + |
---|
| 789 | + md_entry.virt_addr = (u64)prz->vaddr; |
---|
| 790 | + md_entry.phys_addr = prz->paddr; |
---|
| 791 | + md_entry.size = prz->size; |
---|
| 792 | + |
---|
| 793 | + if (rk_minidump_add_region(&md_entry) < 0) |
---|
| 794 | + pr_err("Failed to add %s in Minidump\n", prz->label); |
---|
| 795 | +} |
---|
| 796 | + |
---|
| 797 | +static void ramoops_register_ram_zone_info_to_minidump(struct ramoops_context *cxt) |
---|
| 798 | +{ |
---|
| 799 | + int i = 0; |
---|
| 800 | + struct persistent_ram_zone *prz = NULL; |
---|
| 801 | + |
---|
| 802 | +#ifdef CONFIG_PSTORE_BOOT_LOG |
---|
| 803 | + for (i = 0; i < cxt->max_boot_log_cnt; i++) { |
---|
| 804 | + prz = cxt->boot_przs[i]; |
---|
| 805 | + _ramoops_register_ram_zone_info_to_minidump(prz); |
---|
| 806 | + } |
---|
| 807 | +#endif |
---|
| 808 | + |
---|
| 809 | + for (i = 0; i < cxt->max_dump_cnt; i++) { |
---|
| 810 | + prz = cxt->dprzs[i]; |
---|
| 811 | + _ramoops_register_ram_zone_info_to_minidump(prz); |
---|
| 812 | + } |
---|
| 813 | + |
---|
| 814 | + for (i = 0; i < cxt->max_ftrace_cnt; i++) { |
---|
| 815 | + prz = cxt->fprzs[i]; |
---|
| 816 | + _ramoops_register_ram_zone_info_to_minidump(prz); |
---|
| 817 | + } |
---|
| 818 | + |
---|
| 819 | + prz = cxt->cprz; |
---|
| 820 | + _ramoops_register_ram_zone_info_to_minidump(prz); |
---|
| 821 | + |
---|
| 822 | + prz = cxt->mprz; |
---|
| 823 | + _ramoops_register_ram_zone_info_to_minidump(prz); |
---|
| 824 | +} |
---|
| 825 | +#endif |
---|
727 | 826 | |
---|
728 | 827 | static int ramoops_probe(struct platform_device *pdev) |
---|
729 | 828 | { |
---|
.. | .. |
---|
736 | 835 | int err = -EINVAL; |
---|
737 | 836 | int i = 0; |
---|
738 | 837 | |
---|
739 | | - if (dev_of_node(dev) && !pdata) { |
---|
740 | | - pdata = &pdata_local; |
---|
741 | | - memset(pdata, 0, sizeof(*pdata)); |
---|
742 | | - |
---|
743 | | - err = ramoops_parse_dt(pdev, pdata); |
---|
744 | | - if (err < 0) |
---|
745 | | - goto fail_out; |
---|
746 | | - } |
---|
747 | | - |
---|
748 | 838 | /* |
---|
749 | 839 | * Only a single ramoops area allowed at a time, so fail extra |
---|
750 | 840 | * probes. |
---|
.. | .. |
---|
754 | 844 | goto fail_out; |
---|
755 | 845 | } |
---|
756 | 846 | |
---|
| 847 | + if (dev_of_node(dev) && !pdata) { |
---|
| 848 | + pdata = &pdata_local; |
---|
| 849 | + memset(pdata, 0, sizeof(*pdata)); |
---|
| 850 | + |
---|
| 851 | + err = ramoops_parse_dt(pdev, pdata); |
---|
| 852 | + if (err < 0) |
---|
| 853 | + goto fail_out; |
---|
| 854 | + } |
---|
| 855 | + |
---|
757 | 856 | /* Make sure we didn't get bogus platform data pointer. */ |
---|
758 | 857 | if (!pdata) { |
---|
759 | 858 | pr_err("NULL platform data\n"); |
---|
| 859 | + err = -EINVAL; |
---|
760 | 860 | goto fail_out; |
---|
761 | 861 | } |
---|
762 | 862 | |
---|
.. | .. |
---|
772 | 872 | !pdata->ftrace_size && !pdata->pmsg_size)) { |
---|
773 | 873 | pr_err("The memory size and the record/console size must be " |
---|
774 | 874 | "non-zero\n"); |
---|
| 875 | + err = -EINVAL; |
---|
775 | 876 | goto fail_out; |
---|
776 | 877 | } |
---|
777 | 878 | #endif |
---|
.. | .. |
---|
794 | 895 | cxt->console_size = pdata->console_size; |
---|
795 | 896 | cxt->ftrace_size = pdata->ftrace_size; |
---|
796 | 897 | cxt->pmsg_size = pdata->pmsg_size; |
---|
797 | | - cxt->dump_oops = pdata->dump_oops; |
---|
798 | 898 | cxt->flags = pdata->flags; |
---|
799 | 899 | cxt->ecc_info = pdata->ecc_info; |
---|
800 | 900 | #ifdef CONFIG_PSTORE_BOOT_LOG |
---|
.. | .. |
---|
811 | 911 | #endif |
---|
812 | 912 | |
---|
813 | 913 | #ifdef CONFIG_PSTORE_BOOT_LOG |
---|
814 | | - err = ramoops_init_przs("boot_log", dev, cxt, &cxt->boot_przs, &paddr, |
---|
| 914 | + err = ramoops_init_przs("boot-log", dev, cxt, &cxt->boot_przs, &paddr, |
---|
815 | 915 | cxt->boot_log_size, -1, |
---|
816 | 916 | &cxt->max_boot_log_cnt, 0, 0); |
---|
817 | 917 | if (err) |
---|
.. | .. |
---|
821 | 921 | pr_info("boot-log-%d\t0x%zx@%pa\n", i, cxt->boot_przs[i]->size, &cxt->boot_przs[i]->paddr); |
---|
822 | 922 | #endif |
---|
823 | 923 | |
---|
824 | | - err = ramoops_init_przs("dump", dev, cxt, &cxt->dprzs, &paddr, |
---|
| 924 | + err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr, |
---|
825 | 925 | dump_mem_sz, cxt->record_size, |
---|
826 | 926 | &cxt->max_dump_cnt, 0, 0); |
---|
827 | 927 | if (err) |
---|
.. | .. |
---|
855 | 955 | cxt->pmsg_size, 0); |
---|
856 | 956 | if (err) |
---|
857 | 957 | goto fail_init_mprz; |
---|
858 | | - |
---|
859 | 958 | if (cxt->pmsg_size > 0) |
---|
860 | 959 | pr_info("pmsg\t0x%zx@%pa\n", cxt->mprz->size, &cxt->mprz->paddr); |
---|
861 | 960 | |
---|
.. | .. |
---|
867 | 966 | * the single region size is how to check. |
---|
868 | 967 | */ |
---|
869 | 968 | cxt->pstore.flags = 0; |
---|
870 | | - if (cxt->max_dump_cnt) |
---|
| 969 | + if (cxt->max_dump_cnt) { |
---|
871 | 970 | cxt->pstore.flags |= PSTORE_FLAGS_DMESG; |
---|
| 971 | + cxt->pstore.max_reason = pdata->max_reason; |
---|
| 972 | + } |
---|
872 | 973 | if (cxt->console_size) |
---|
873 | 974 | cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE; |
---|
874 | 975 | if (cxt->max_ftrace_cnt) |
---|
.. | .. |
---|
908 | 1009 | mem_size = pdata->mem_size; |
---|
909 | 1010 | mem_address = pdata->mem_address; |
---|
910 | 1011 | record_size = pdata->record_size; |
---|
911 | | - dump_oops = pdata->dump_oops; |
---|
| 1012 | + ramoops_max_reason = pdata->max_reason; |
---|
912 | 1013 | ramoops_console_size = pdata->console_size; |
---|
913 | 1014 | ramoops_pmsg_size = pdata->pmsg_size; |
---|
914 | 1015 | ramoops_ftrace_size = pdata->ftrace_size; |
---|
915 | | - |
---|
916 | | - pr_info("attached 0x%lx@0x%llx, ecc: %d/%d\n", |
---|
| 1016 | +#if IS_REACHABLE(CONFIG_ROCKCHIP_MINIDUMP) |
---|
| 1017 | + ramoops_register_ram_zone_info_to_minidump(cxt); |
---|
| 1018 | +#endif |
---|
| 1019 | + pr_info("using 0x%lx@0x%llx, ecc: %d\n", |
---|
917 | 1020 | cxt->size, (unsigned long long)cxt->phys_addr, |
---|
918 | | - cxt->ecc_info.ecc_size, cxt->ecc_info.block_size); |
---|
| 1021 | + cxt->ecc_info.ecc_size); |
---|
919 | 1022 | |
---|
920 | 1023 | return 0; |
---|
921 | 1024 | |
---|
.. | .. |
---|
967 | 1070 | { |
---|
968 | 1071 | platform_device_unregister(dummy); |
---|
969 | 1072 | dummy = NULL; |
---|
970 | | - |
---|
971 | | - kfree(dummy_data); |
---|
972 | | - dummy_data = NULL; |
---|
973 | 1073 | } |
---|
974 | 1074 | |
---|
975 | 1075 | static void __init ramoops_register_dummy(void) |
---|
976 | 1076 | { |
---|
| 1077 | + struct ramoops_platform_data pdata; |
---|
| 1078 | + |
---|
977 | 1079 | /* |
---|
978 | 1080 | * Prepare a dummy platform data structure to carry the module |
---|
979 | 1081 | * parameters. If mem_size isn't set, then there are no module |
---|
.. | .. |
---|
984 | 1086 | |
---|
985 | 1087 | pr_info("using module parameters\n"); |
---|
986 | 1088 | |
---|
987 | | - dummy_data = kzalloc(sizeof(*dummy_data), GFP_KERNEL); |
---|
988 | | - if (!dummy_data) { |
---|
989 | | - pr_info("could not allocate pdata\n"); |
---|
990 | | - return; |
---|
991 | | - } |
---|
992 | | - |
---|
993 | | - dummy_data->mem_size = mem_size; |
---|
994 | | - dummy_data->mem_address = mem_address; |
---|
995 | | - dummy_data->mem_type = mem_type; |
---|
996 | | - dummy_data->record_size = record_size; |
---|
997 | | - dummy_data->console_size = ramoops_console_size; |
---|
998 | | - dummy_data->ftrace_size = ramoops_ftrace_size; |
---|
999 | | - dummy_data->pmsg_size = ramoops_pmsg_size; |
---|
1000 | | - dummy_data->dump_oops = dump_oops; |
---|
1001 | | - dummy_data->flags = RAMOOPS_FLAG_FTRACE_PER_CPU; |
---|
| 1089 | + memset(&pdata, 0, sizeof(pdata)); |
---|
| 1090 | + pdata.mem_size = mem_size; |
---|
| 1091 | + pdata.mem_address = mem_address; |
---|
| 1092 | + pdata.mem_type = mem_type; |
---|
| 1093 | + pdata.record_size = record_size; |
---|
| 1094 | + pdata.console_size = ramoops_console_size; |
---|
| 1095 | + pdata.ftrace_size = ramoops_ftrace_size; |
---|
| 1096 | + pdata.pmsg_size = ramoops_pmsg_size; |
---|
| 1097 | + /* If "max_reason" is set, its value has priority over "dump_oops". */ |
---|
| 1098 | + if (ramoops_max_reason >= 0) |
---|
| 1099 | + pdata.max_reason = ramoops_max_reason; |
---|
| 1100 | + /* Otherwise, if "dump_oops" is set, parse it into "max_reason". */ |
---|
| 1101 | + else if (ramoops_dump_oops != -1) |
---|
| 1102 | + pdata.max_reason = ramoops_dump_oops ? KMSG_DUMP_OOPS |
---|
| 1103 | + : KMSG_DUMP_PANIC; |
---|
| 1104 | + /* And if neither are explicitly set, use the default. */ |
---|
| 1105 | + else |
---|
| 1106 | + pdata.max_reason = KMSG_DUMP_OOPS; |
---|
| 1107 | + pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU; |
---|
1002 | 1108 | |
---|
1003 | 1109 | /* |
---|
1004 | 1110 | * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC |
---|
1005 | 1111 | * (using 1 byte for ECC isn't much of use anyway). |
---|
1006 | 1112 | */ |
---|
1007 | | - dummy_data->ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; |
---|
| 1113 | + pdata.ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc; |
---|
1008 | 1114 | |
---|
1009 | 1115 | dummy = platform_device_register_data(NULL, "ramoops", -1, |
---|
1010 | | - dummy_data, sizeof(struct ramoops_platform_data)); |
---|
| 1116 | + &pdata, sizeof(pdata)); |
---|
1011 | 1117 | if (IS_ERR(dummy)) { |
---|
1012 | 1118 | pr_info("could not create platform device: %ld\n", |
---|
1013 | 1119 | PTR_ERR(dummy)); |
---|
1014 | 1120 | dummy = NULL; |
---|
1015 | | - ramoops_unregister_dummy(); |
---|
1016 | 1121 | } |
---|
1017 | 1122 | } |
---|
1018 | 1123 | |
---|