2010-05-27 04:43:54 +07:00
|
|
|
/*
|
|
|
|
* RAM Oops/Panic logger
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Marco Stornelli <marco.stornelli@gmail.com>
|
2012-05-03 12:45:02 +07:00
|
|
|
* Copyright (C) 2011 Kees Cook <keescook@chromium.org>
|
2010-05-27 04:43:54 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-07-27 06:08:57 +07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2010-05-27 04:43:54 +07:00
|
|
|
#include <linux/kernel.h>
|
2011-07-29 20:11:32 +07:00
|
|
|
#include <linux/err.h>
|
2010-05-27 04:43:54 +07:00
|
|
|
#include <linux/module.h>
|
pstore/ram: Make tracing log versioned
Decoding the binary trace w/ a different kernel might be troublesome
since we convert addresses to symbols. For kernels with minimal changes,
the mappings would probably match, but it's not guaranteed at all.
(But still we could convert the addresses by hand, since we do print
raw addresses.)
If we use modules, the symbols could be loaded at different addresses
from the previously booted kernel, and so this would also fail, but
there's nothing we can do about it.
Also, the binary data format that pstore/ram is using in its ringbuffer
may change between the kernels, so here we too must ensure that we're
running the same kernel.
So, there are two questions really:
1. How to compute the unique kernel tag;
2. Where to store it.
In this patch we're using LINUX_VERSION_CODE, just as hibernation
(suspend-to-disk) does. This way we are protecting from the kernel
version mismatch, making sure that we're running the same kernel
version and patch level. We could use CRC of a symbol table (as
suggested by Tony Luck), but for now let's not be that strict.
And as for storing, we are using a small trick here. Instead of
allocating a dedicated buffer for the tag (i.e. another prz), or
hacking ram_core routines to "reserve" some control data in the
buffer, we are just encoding the tag into the buffer signature
(and XOR'ing it with the actual signature value, so that buffers
not needing a tag can just pass zero, which will result into the
plain old PRZ signature).
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Tony Luck <tony.luck@intel.com>
Suggested-by: Colin Cross <ccross@android.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-07-18 02:11:12 +07:00
|
|
|
#include <linux/version.h>
|
2012-05-03 12:45:02 +07:00
|
|
|
#include <linux/pstore.h>
|
2010-05-27 04:43:54 +07:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/ioport.h>
|
2010-10-28 05:34:52 +07:00
|
|
|
#include <linux/platform_device.h>
|
2011-07-27 06:08:57 +07:00
|
|
|
#include <linux/slab.h>
|
2012-07-18 09:49:37 +07:00
|
|
|
#include <linux/compiler.h>
|
2012-05-16 19:43:08 +07:00
|
|
|
#include <linux/pstore_ram.h>
|
2016-01-08 06:40:56 +07:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
2010-05-27 04:43:54 +07:00
|
|
|
|
|
|
|
#define RAMOOPS_KERNMSG_HDR "===="
|
2011-07-27 06:08:59 +07:00
|
|
|
#define MIN_MEM_SIZE 4096UL
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2011-07-27 06:08:59 +07:00
|
|
|
static ulong record_size = MIN_MEM_SIZE;
|
|
|
|
module_param(record_size, ulong, 0400);
|
|
|
|
MODULE_PARM_DESC(record_size,
|
|
|
|
"size of each dump done on oops/panic");
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2012-05-26 20:20:23 +07:00
|
|
|
static ulong ramoops_console_size = MIN_MEM_SIZE;
|
|
|
|
module_param_named(console_size, ramoops_console_size, ulong, 0400);
|
|
|
|
MODULE_PARM_DESC(console_size, "size of kernel console log");
|
|
|
|
|
2012-07-10 07:10:44 +07:00
|
|
|
static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
|
|
|
|
module_param_named(ftrace_size, ramoops_ftrace_size, ulong, 0400);
|
|
|
|
MODULE_PARM_DESC(ftrace_size, "size of ftrace log");
|
|
|
|
|
2015-01-17 07:01:10 +07:00
|
|
|
static ulong ramoops_pmsg_size = MIN_MEM_SIZE;
|
|
|
|
module_param_named(pmsg_size, ramoops_pmsg_size, ulong, 0400);
|
|
|
|
MODULE_PARM_DESC(pmsg_size, "size of user space message log");
|
|
|
|
|
2015-11-13 19:10:05 +07:00
|
|
|
static unsigned long long mem_address;
|
2017-04-04 22:54:29 +07:00
|
|
|
module_param_hw(mem_address, ullong, other, 0400);
|
2010-05-27 04:43:54 +07:00
|
|
|
MODULE_PARM_DESC(mem_address,
|
|
|
|
"start of reserved RAM used to store oops/panic logs");
|
|
|
|
|
|
|
|
static ulong mem_size;
|
|
|
|
module_param(mem_size, ulong, 0400);
|
|
|
|
MODULE_PARM_DESC(mem_size,
|
|
|
|
"size of reserved RAM used to store oops/panic logs");
|
|
|
|
|
2014-09-17 03:50:01 +07:00
|
|
|
static unsigned int mem_type;
|
|
|
|
module_param(mem_type, uint, 0600);
|
|
|
|
MODULE_PARM_DESC(mem_type,
|
|
|
|
"set to 1 to try to use unbuffered memory (default 0)");
|
|
|
|
|
2010-05-27 04:43:54 +07:00
|
|
|
static int dump_oops = 1;
|
|
|
|
module_param(dump_oops, int, 0600);
|
|
|
|
MODULE_PARM_DESC(dump_oops,
|
|
|
|
"set to 1 to dump oopses, 0 to only dump panics (default 1)");
|
|
|
|
|
2012-05-17 14:15:34 +07:00
|
|
|
static int ramoops_ecc;
|
|
|
|
module_param_named(ecc, ramoops_ecc, int, 0600);
|
|
|
|
MODULE_PARM_DESC(ramoops_ecc,
|
2012-07-10 07:03:19 +07:00
|
|
|
"if non-zero, the option enables ECC support and specifies "
|
|
|
|
"ECC buffer size in bytes (1 is a special value, means 16 "
|
|
|
|
"bytes ECC)");
|
2012-05-17 14:15:34 +07:00
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
struct ramoops_context {
|
2016-11-12 05:30:11 +07:00
|
|
|
struct persistent_ram_zone **dprzs; /* Oops dump zones */
|
|
|
|
struct persistent_ram_zone *cprz; /* Console zone */
|
|
|
|
struct persistent_ram_zone **fprzs; /* Ftrace zones */
|
|
|
|
struct persistent_ram_zone *mprz; /* PMSG zone */
|
2010-05-27 04:43:54 +07:00
|
|
|
phys_addr_t phys_addr;
|
|
|
|
unsigned long size;
|
2014-09-17 03:50:01 +07:00
|
|
|
unsigned int memtype;
|
2012-05-03 12:45:02 +07:00
|
|
|
size_t record_size;
|
2012-05-26 20:20:23 +07:00
|
|
|
size_t console_size;
|
2012-07-10 07:10:44 +07:00
|
|
|
size_t ftrace_size;
|
2015-01-17 07:01:10 +07:00
|
|
|
size_t pmsg_size;
|
2011-07-27 06:08:58 +07:00
|
|
|
int dump_oops;
|
2016-10-20 14:34:04 +07:00
|
|
|
u32 flags;
|
2012-05-23 06:33:23 +07:00
|
|
|
struct persistent_ram_ecc_info ecc_info;
|
2012-05-26 20:20:20 +07:00
|
|
|
unsigned int max_dump_cnt;
|
|
|
|
unsigned int dump_write_cnt;
|
2014-03-17 07:24:49 +07:00
|
|
|
/* _read_cnt need clear on ramoops_pstore_open */
|
2012-05-26 20:20:20 +07:00
|
|
|
unsigned int dump_read_cnt;
|
2012-05-26 20:20:23 +07:00
|
|
|
unsigned int console_read_cnt;
|
2016-10-20 14:34:04 +07:00
|
|
|
unsigned int max_ftrace_cnt;
|
2012-07-10 07:10:44 +07:00
|
|
|
unsigned int ftrace_read_cnt;
|
2015-01-17 07:01:10 +07:00
|
|
|
unsigned int pmsg_read_cnt;
|
2012-05-03 12:45:02 +07:00
|
|
|
struct pstore_info pstore;
|
|
|
|
};
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2011-07-27 06:08:57 +07:00
|
|
|
static struct platform_device *dummy;
|
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
static int ramoops_pstore_open(struct pstore_info *psi)
|
|
|
|
{
|
|
|
|
struct ramoops_context *cxt = psi->data;
|
|
|
|
|
2012-05-26 20:20:20 +07:00
|
|
|
cxt->dump_read_cnt = 0;
|
2012-05-26 20:20:23 +07:00
|
|
|
cxt->console_read_cnt = 0;
|
2014-03-17 07:24:49 +07:00
|
|
|
cxt->ftrace_read_cnt = 0;
|
2015-01-17 07:01:10 +07:00
|
|
|
cxt->pmsg_read_cnt = 0;
|
2012-05-03 12:45:02 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-26 20:20:22 +07:00
|
|
|
static struct persistent_ram_zone *
|
2018-11-04 06:38:17 +07:00
|
|
|
ramoops_get_next_prz(struct persistent_ram_zone *przs[], int id,
|
|
|
|
struct pstore_record *record)
|
2012-05-26 20:20:22 +07:00
|
|
|
{
|
|
|
|
struct persistent_ram_zone *prz;
|
|
|
|
|
2017-02-11 01:15:34 +07:00
|
|
|
/* Give up if we never existed or have hit the end. */
|
2018-11-04 06:38:17 +07:00
|
|
|
if (!przs)
|
2012-05-26 20:20:22 +07:00
|
|
|
return NULL;
|
|
|
|
|
2018-11-04 06:38:17 +07:00
|
|
|
prz = przs[id];
|
2014-03-18 03:57:49 +07:00
|
|
|
if (!prz)
|
|
|
|
return NULL;
|
2012-05-26 20:20:22 +07:00
|
|
|
|
2014-03-17 07:24:49 +07:00
|
|
|
/* Update old/shadowed buffer. */
|
2019-01-18 00:09:29 +07:00
|
|
|
if (prz->type == PSTORE_TYPE_DMESG)
|
2012-05-26 20:20:22 +07:00
|
|
|
persistent_ram_save_old(prz);
|
2014-03-17 07:24:49 +07:00
|
|
|
|
|
|
|
if (!persistent_ram_old_size(prz))
|
|
|
|
return NULL;
|
2012-05-26 20:20:22 +07:00
|
|
|
|
2018-11-04 06:38:17 +07:00
|
|
|
record->type = prz->type;
|
|
|
|
record->id = id;
|
2012-05-26 20:20:22 +07:00
|
|
|
|
|
|
|
return prz;
|
|
|
|
}
|
|
|
|
|
2018-05-15 05:50:52 +07:00
|
|
|
static int ramoops_read_kmsg_hdr(char *buffer, struct timespec64 *time,
|
2013-08-17 03:58:00 +07:00
|
|
|
bool *compressed)
|
|
|
|
{
|
|
|
|
char data_type;
|
2014-10-31 07:14:21 +07:00
|
|
|
int header_length = 0;
|
2013-08-17 03:58:00 +07:00
|
|
|
|
2018-05-30 22:24:52 +07:00
|
|
|
if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lld.%lu-%c\n%n",
|
|
|
|
(time64_t *)&time->tv_sec, &time->tv_nsec, &data_type,
|
2018-05-15 05:50:52 +07:00
|
|
|
&header_length) == 3) {
|
2013-08-17 03:58:00 +07:00
|
|
|
if (data_type == 'C')
|
|
|
|
*compressed = true;
|
|
|
|
else
|
|
|
|
*compressed = false;
|
2018-05-30 22:24:52 +07:00
|
|
|
} else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lld.%lu\n%n",
|
|
|
|
(time64_t *)&time->tv_sec, &time->tv_nsec,
|
2018-05-15 05:50:52 +07:00
|
|
|
&header_length) == 2) {
|
|
|
|
*compressed = false;
|
2013-08-17 03:58:00 +07:00
|
|
|
} else {
|
|
|
|
time->tv_sec = 0;
|
|
|
|
time->tv_nsec = 0;
|
|
|
|
*compressed = false;
|
|
|
|
}
|
2014-10-31 07:14:21 +07:00
|
|
|
return header_length;
|
2013-08-17 03:58:00 +07:00
|
|
|
}
|
|
|
|
|
2015-01-14 05:32:50 +07:00
|
|
|
static bool prz_ok(struct persistent_ram_zone *prz)
|
|
|
|
{
|
|
|
|
return !!prz && !!(persistent_ram_old_size(prz) +
|
|
|
|
persistent_ram_ecc_string(prz, NULL, 0));
|
|
|
|
}
|
|
|
|
|
2016-10-20 14:34:06 +07:00
|
|
|
static ssize_t ftrace_log_combine(struct persistent_ram_zone *dest,
|
|
|
|
struct persistent_ram_zone *src)
|
|
|
|
{
|
|
|
|
size_t dest_size, src_size, total, dest_off, src_off;
|
|
|
|
size_t dest_idx = 0, src_idx = 0, merged_idx = 0;
|
|
|
|
void *merged_buf;
|
|
|
|
struct pstore_ftrace_record *drec, *srec, *mrec;
|
|
|
|
size_t record_size = sizeof(struct pstore_ftrace_record);
|
|
|
|
|
|
|
|
dest_off = dest->old_log_size % record_size;
|
|
|
|
dest_size = dest->old_log_size - dest_off;
|
|
|
|
|
|
|
|
src_off = src->old_log_size % record_size;
|
|
|
|
src_size = src->old_log_size - src_off;
|
|
|
|
|
|
|
|
total = dest_size + src_size;
|
|
|
|
merged_buf = kmalloc(total, GFP_KERNEL);
|
|
|
|
if (!merged_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
drec = (struct pstore_ftrace_record *)(dest->old_log + dest_off);
|
|
|
|
srec = (struct pstore_ftrace_record *)(src->old_log + src_off);
|
|
|
|
mrec = (struct pstore_ftrace_record *)(merged_buf);
|
|
|
|
|
|
|
|
while (dest_size > 0 && src_size > 0) {
|
|
|
|
if (pstore_ftrace_read_timestamp(&drec[dest_idx]) <
|
|
|
|
pstore_ftrace_read_timestamp(&srec[src_idx])) {
|
|
|
|
mrec[merged_idx++] = drec[dest_idx++];
|
|
|
|
dest_size -= record_size;
|
|
|
|
} else {
|
|
|
|
mrec[merged_idx++] = srec[src_idx++];
|
|
|
|
src_size -= record_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (dest_size > 0) {
|
|
|
|
mrec[merged_idx++] = drec[dest_idx++];
|
|
|
|
dest_size -= record_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (src_size > 0) {
|
|
|
|
mrec[merged_idx++] = srec[src_idx++];
|
|
|
|
src_size -= record_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dest->old_log);
|
|
|
|
dest->old_log = merged_buf;
|
|
|
|
dest->old_log_size = total;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-04 13:09:18 +07:00
|
|
|
static ssize_t ramoops_pstore_read(struct pstore_record *record)
|
2010-05-27 04:43:54 +07:00
|
|
|
{
|
2016-10-20 14:34:06 +07:00
|
|
|
ssize_t size = 0;
|
2017-03-04 13:09:18 +07:00
|
|
|
struct ramoops_context *cxt = record->psi->data;
|
2015-05-21 23:50:34 +07:00
|
|
|
struct persistent_ram_zone *prz = NULL;
|
|
|
|
int header_length = 0;
|
2016-10-20 14:34:06 +07:00
|
|
|
bool free_prz = false;
|
2015-05-21 23:50:34 +07:00
|
|
|
|
2017-03-04 13:09:18 +07:00
|
|
|
/*
|
|
|
|
* Ramoops headers provide time stamps for PSTORE_TYPE_DMESG, but
|
2015-05-21 23:50:34 +07:00
|
|
|
* PSTORE_TYPE_CONSOLE and PSTORE_TYPE_FTRACE don't currently have
|
|
|
|
* valid time stamps, so it is initialized to zero.
|
|
|
|
*/
|
2017-03-04 13:09:18 +07:00
|
|
|
record->time.tv_sec = 0;
|
|
|
|
record->time.tv_nsec = 0;
|
|
|
|
record->compressed = false;
|
2015-05-21 23:50:34 +07:00
|
|
|
|
|
|
|
/* Find the next valid persistent_ram_zone for DMESG */
|
|
|
|
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
|
2018-11-04 06:38:17 +07:00
|
|
|
prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
|
|
|
|
record);
|
2015-05-21 23:50:34 +07:00
|
|
|
if (!prz_ok(prz))
|
|
|
|
continue;
|
|
|
|
header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
|
2017-03-04 13:09:18 +07:00
|
|
|
&record->time,
|
|
|
|
&record->compressed);
|
2015-05-21 23:50:34 +07:00
|
|
|
/* Clear and skip this DMESG record if it has no valid header */
|
|
|
|
if (!header_length) {
|
|
|
|
persistent_ram_free_old(prz);
|
|
|
|
persistent_ram_zap(prz);
|
|
|
|
prz = NULL;
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2018-11-04 06:38:17 +07:00
|
|
|
if (!prz_ok(prz) && !cxt->console_read_cnt++)
|
|
|
|
prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record);
|
2016-10-20 14:34:06 +07:00
|
|
|
|
2018-11-04 06:38:17 +07:00
|
|
|
if (!prz_ok(prz) && !cxt->pmsg_read_cnt++)
|
|
|
|
prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record);
|
2016-10-20 14:34:06 +07:00
|
|
|
|
|
|
|
/* ftrace is last since it may want to dynamically allocate memory. */
|
2017-02-11 01:15:34 +07:00
|
|
|
if (!prz_ok(prz)) {
|
2018-11-04 06:38:17 +07:00
|
|
|
if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) &&
|
|
|
|
!cxt->ftrace_read_cnt++) {
|
|
|
|
prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */,
|
|
|
|
record);
|
2016-10-20 14:34:06 +07:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Build a new dummy record which combines all the
|
|
|
|
* per-cpu records including metadata and ecc info.
|
|
|
|
*/
|
|
|
|
struct persistent_ram_zone *tmp_prz, *prz_next;
|
|
|
|
|
|
|
|
tmp_prz = kzalloc(sizeof(struct persistent_ram_zone),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!tmp_prz)
|
|
|
|
return -ENOMEM;
|
2018-12-04 07:39:01 +07:00
|
|
|
prz = tmp_prz;
|
2016-10-20 14:34:06 +07:00
|
|
|
free_prz = true;
|
|
|
|
|
|
|
|
while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) {
|
|
|
|
prz_next = ramoops_get_next_prz(cxt->fprzs,
|
2018-11-04 06:38:17 +07:00
|
|
|
cxt->ftrace_read_cnt++, record);
|
2016-10-20 14:34:06 +07:00
|
|
|
|
|
|
|
if (!prz_ok(prz_next))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp_prz->ecc_info = prz_next->ecc_info;
|
|
|
|
tmp_prz->corrected_bytes +=
|
|
|
|
prz_next->corrected_bytes;
|
|
|
|
tmp_prz->bad_blocks += prz_next->bad_blocks;
|
|
|
|
size = ftrace_log_combine(tmp_prz, prz_next);
|
|
|
|
if (size)
|
|
|
|
goto out;
|
|
|
|
}
|
2017-03-04 13:09:18 +07:00
|
|
|
record->id = 0;
|
2016-10-20 14:34:04 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-20 14:34:06 +07:00
|
|
|
if (!prz_ok(prz)) {
|
|
|
|
size = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-17 14:15:18 +07:00
|
|
|
|
2015-05-21 23:50:34 +07:00
|
|
|
size = persistent_ram_old_size(prz) - header_length;
|
2012-12-06 12:19:51 +07:00
|
|
|
|
|
|
|
/* ECC correction notice */
|
2017-03-04 13:09:18 +07:00
|
|
|
record->ecc_notice_size = persistent_ram_ecc_string(prz, NULL, 0);
|
2012-12-06 12:19:51 +07:00
|
|
|
|
2017-03-04 13:09:18 +07:00
|
|
|
record->buf = kmalloc(size + record->ecc_notice_size + 1, GFP_KERNEL);
|
|
|
|
if (record->buf == NULL) {
|
2016-10-20 14:34:06 +07:00
|
|
|
size = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2017-03-04 13:09:18 +07:00
|
|
|
memcpy(record->buf, (char *)persistent_ram_old(prz) + header_length,
|
|
|
|
size);
|
2016-10-20 14:34:06 +07:00
|
|
|
|
2017-03-04 13:09:18 +07:00
|
|
|
persistent_ram_ecc_string(prz, record->buf + size,
|
|
|
|
record->ecc_notice_size + 1);
|
2012-12-06 12:19:51 +07:00
|
|
|
|
2016-10-20 14:34:06 +07:00
|
|
|
out:
|
|
|
|
if (free_prz) {
|
|
|
|
kfree(prz->old_log);
|
|
|
|
kfree(prz);
|
|
|
|
}
|
|
|
|
|
2016-02-18 21:04:22 +07:00
|
|
|
return size;
|
2012-05-03 12:45:02 +07:00
|
|
|
}
|
|
|
|
|
2013-08-17 03:58:00 +07:00
|
|
|
static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
|
2017-05-20 05:29:10 +07:00
|
|
|
struct pstore_record *record)
|
2012-05-17 14:15:18 +07:00
|
|
|
{
|
|
|
|
char *hdr;
|
|
|
|
size_t len;
|
|
|
|
|
2018-05-30 22:24:52 +07:00
|
|
|
hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lld.%06lu-%c\n",
|
|
|
|
(time64_t)record->time.tv_sec,
|
2017-05-20 05:29:10 +07:00
|
|
|
record->time.tv_nsec / 1000,
|
|
|
|
record->compressed ? 'C' : 'D');
|
2012-05-17 14:15:18 +07:00
|
|
|
WARN_ON_ONCE(!hdr);
|
|
|
|
len = hdr ? strlen(hdr) : 0;
|
|
|
|
persistent_ram_write(prz, hdr, len);
|
|
|
|
kfree(hdr);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:41:10 +07:00
|
|
|
static int notrace ramoops_pstore_write(struct pstore_record *record)
|
2012-05-03 12:45:02 +07:00
|
|
|
{
|
2017-03-05 15:27:54 +07:00
|
|
|
struct ramoops_context *cxt = record->psi->data;
|
2012-12-12 08:49:24 +07:00
|
|
|
struct persistent_ram_zone *prz;
|
2017-03-05 15:27:54 +07:00
|
|
|
size_t size, hlen;
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
if (record->type == PSTORE_TYPE_CONSOLE) {
|
2012-05-26 20:20:23 +07:00
|
|
|
if (!cxt->cprz)
|
|
|
|
return -ENOMEM;
|
2017-03-05 15:27:54 +07:00
|
|
|
persistent_ram_write(cxt->cprz, record->buf, record->size);
|
2012-05-26 20:20:23 +07:00
|
|
|
return 0;
|
2017-03-05 15:27:54 +07:00
|
|
|
} else if (record->type == PSTORE_TYPE_FTRACE) {
|
2016-10-20 14:34:04 +07:00
|
|
|
int zonenum;
|
|
|
|
|
|
|
|
if (!cxt->fprzs)
|
2012-07-10 07:10:44 +07:00
|
|
|
return -ENOMEM;
|
2016-10-20 14:34:04 +07:00
|
|
|
/*
|
|
|
|
* Choose zone by if we're using per-cpu buffers.
|
|
|
|
*/
|
|
|
|
if (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)
|
|
|
|
zonenum = smp_processor_id();
|
|
|
|
else
|
|
|
|
zonenum = 0;
|
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
persistent_ram_write(cxt->fprzs[zonenum], record->buf,
|
|
|
|
record->size);
|
2012-07-10 07:10:44 +07:00
|
|
|
return 0;
|
2017-03-05 15:27:54 +07:00
|
|
|
} else if (record->type == PSTORE_TYPE_PMSG) {
|
2016-10-20 14:34:02 +07:00
|
|
|
pr_warn_ratelimited("PMSG shouldn't call %s\n", __func__);
|
|
|
|
return -EINVAL;
|
2012-05-26 20:20:23 +07:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
if (record->type != PSTORE_TYPE_DMESG)
|
2012-05-03 12:45:02 +07:00
|
|
|
return -EINVAL;
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
/*
|
|
|
|
* Out of the various dmesg dump types, ramoops is currently designed
|
2012-05-03 12:45:02 +07:00
|
|
|
* to only store crash logs, rather than storing general kernel logs.
|
|
|
|
*/
|
2017-03-05 15:27:54 +07:00
|
|
|
if (record->reason != KMSG_DUMP_OOPS &&
|
|
|
|
record->reason != KMSG_DUMP_PANIC)
|
2012-05-03 12:45:02 +07:00
|
|
|
return -EINVAL;
|
2011-01-13 07:59:29 +07:00
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
/* Skip Oopes when configured to do so. */
|
2017-03-05 15:27:54 +07:00
|
|
|
if (record->reason == KMSG_DUMP_OOPS && !cxt->dump_oops)
|
2012-05-03 12:45:02 +07:00
|
|
|
return -EINVAL;
|
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
/*
|
|
|
|
* Explicitly only take the first part of any new crash.
|
2012-05-03 12:45:02 +07:00
|
|
|
* If our buffer is larger than kmsg_bytes, this can never happen,
|
|
|
|
* and if our buffer is smaller than kmsg_bytes, we don't want the
|
|
|
|
* report split across multiple records.
|
|
|
|
*/
|
2017-03-05 15:27:54 +07:00
|
|
|
if (record->part != 1)
|
2012-05-03 12:45:02 +07:00
|
|
|
return -ENOSPC;
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2016-11-12 05:30:11 +07:00
|
|
|
if (!cxt->dprzs)
|
2012-12-12 08:49:24 +07:00
|
|
|
return -ENOSPC;
|
|
|
|
|
2016-11-12 05:30:11 +07:00
|
|
|
prz = cxt->dprzs[cxt->dump_write_cnt];
|
2012-12-12 08:49:24 +07:00
|
|
|
|
2017-03-05 15:27:54 +07:00
|
|
|
/* Build header and append record contents. */
|
2017-05-20 05:29:10 +07:00
|
|
|
hlen = ramoops_write_kmsg_hdr(prz, record);
|
2017-03-05 15:27:54 +07:00
|
|
|
size = record->size;
|
2012-05-17 14:15:18 +07:00
|
|
|
if (size + hlen > prz->buffer_size)
|
|
|
|
size = prz->buffer_size - hlen;
|
2017-03-05 15:27:54 +07:00
|
|
|
persistent_ram_write(prz, record->buf, size);
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2012-05-26 20:20:20 +07:00
|
|
|
cxt->dump_write_cnt = (cxt->dump_write_cnt + 1) % cxt->max_dump_cnt;
|
2012-05-03 12:45:02 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-06 13:41:10 +07:00
|
|
|
static int notrace ramoops_pstore_write_user(struct pstore_record *record,
|
|
|
|
const char __user *buf)
|
2016-09-01 22:13:46 +07:00
|
|
|
{
|
2017-03-05 15:56:38 +07:00
|
|
|
if (record->type == PSTORE_TYPE_PMSG) {
|
|
|
|
struct ramoops_context *cxt = record->psi->data;
|
2016-09-01 22:13:46 +07:00
|
|
|
|
|
|
|
if (!cxt->mprz)
|
|
|
|
return -ENOMEM;
|
2017-03-05 15:56:38 +07:00
|
|
|
return persistent_ram_write_user(cxt->mprz, buf, record->size);
|
2016-09-01 22:13:46 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-03-05 14:31:19 +07:00
|
|
|
static int ramoops_pstore_erase(struct pstore_record *record)
|
2012-05-03 12:45:02 +07:00
|
|
|
{
|
2017-03-05 14:31:19 +07:00
|
|
|
struct ramoops_context *cxt = record->psi->data;
|
2012-05-26 20:20:23 +07:00
|
|
|
struct persistent_ram_zone *prz;
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2017-03-05 14:31:19 +07:00
|
|
|
switch (record->type) {
|
2012-05-26 20:20:23 +07:00
|
|
|
case PSTORE_TYPE_DMESG:
|
2017-03-05 14:31:19 +07:00
|
|
|
if (record->id >= cxt->max_dump_cnt)
|
2012-05-26 20:20:23 +07:00
|
|
|
return -EINVAL;
|
2017-03-05 14:31:19 +07:00
|
|
|
prz = cxt->dprzs[record->id];
|
2012-05-26 20:20:23 +07:00
|
|
|
break;
|
|
|
|
case PSTORE_TYPE_CONSOLE:
|
|
|
|
prz = cxt->cprz;
|
|
|
|
break;
|
2012-07-10 07:10:44 +07:00
|
|
|
case PSTORE_TYPE_FTRACE:
|
2017-03-05 14:31:19 +07:00
|
|
|
if (record->id >= cxt->max_ftrace_cnt)
|
2016-10-20 14:34:04 +07:00
|
|
|
return -EINVAL;
|
2017-03-05 14:31:19 +07:00
|
|
|
prz = cxt->fprzs[record->id];
|
2012-07-10 07:10:44 +07:00
|
|
|
break;
|
2015-01-17 07:01:10 +07:00
|
|
|
case PSTORE_TYPE_PMSG:
|
|
|
|
prz = cxt->mprz;
|
|
|
|
break;
|
2012-05-26 20:20:23 +07:00
|
|
|
default:
|
2012-05-03 12:45:02 +07:00
|
|
|
return -EINVAL;
|
2012-05-26 20:20:23 +07:00
|
|
|
}
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2012-05-26 20:20:23 +07:00
|
|
|
persistent_ram_free_old(prz);
|
|
|
|
persistent_ram_zap(prz);
|
2012-05-03 12:45:02 +07:00
|
|
|
|
|
|
|
return 0;
|
2010-05-27 04:43:54 +07:00
|
|
|
}
|
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
static struct ramoops_context oops_cxt = {
|
|
|
|
.pstore = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "ramoops",
|
|
|
|
.open = ramoops_pstore_open,
|
|
|
|
.read = ramoops_pstore_read,
|
2017-03-06 13:41:10 +07:00
|
|
|
.write = ramoops_pstore_write,
|
|
|
|
.write_user = ramoops_pstore_write_user,
|
2012-05-03 12:45:02 +07:00
|
|
|
.erase = ramoops_pstore_erase,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-05-26 20:20:21 +07:00
|
|
|
static void ramoops_free_przs(struct ramoops_context *cxt)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2016-10-20 14:34:04 +07:00
|
|
|
/* Free dump PRZs */
|
2016-11-12 05:30:11 +07:00
|
|
|
if (cxt->dprzs) {
|
2016-10-20 14:34:04 +07:00
|
|
|
for (i = 0; i < cxt->max_dump_cnt; i++)
|
2016-11-12 05:30:11 +07:00
|
|
|
persistent_ram_free(cxt->dprzs[i]);
|
2012-05-26 20:20:21 +07:00
|
|
|
|
2016-11-12 05:30:11 +07:00
|
|
|
kfree(cxt->dprzs);
|
2016-10-20 14:34:04 +07:00
|
|
|
cxt->max_dump_cnt = 0;
|
|
|
|
}
|
2016-09-08 18:48:05 +07:00
|
|
|
|
2016-10-20 14:34:04 +07:00
|
|
|
/* Free ftrace PRZs */
|
|
|
|
if (cxt->fprzs) {
|
|
|
|
for (i = 0; i < cxt->max_ftrace_cnt; i++)
|
|
|
|
persistent_ram_free(cxt->fprzs[i]);
|
|
|
|
kfree(cxt->fprzs);
|
|
|
|
cxt->max_ftrace_cnt = 0;
|
|
|
|
}
|
2012-05-26 20:20:21 +07:00
|
|
|
}
|
|
|
|
|
2016-11-12 05:05:57 +07:00
|
|
|
static int ramoops_init_przs(const char *name,
|
|
|
|
struct device *dev, struct ramoops_context *cxt,
|
2016-11-12 02:48:06 +07:00
|
|
|
struct persistent_ram_zone ***przs,
|
|
|
|
phys_addr_t *paddr, size_t mem_sz,
|
|
|
|
ssize_t record_size,
|
|
|
|
unsigned int *cnt, u32 sig, u32 flags)
|
2012-05-26 20:20:21 +07:00
|
|
|
{
|
|
|
|
int err = -ENOMEM;
|
|
|
|
int i;
|
2016-11-12 02:48:06 +07:00
|
|
|
size_t zone_sz;
|
|
|
|
struct persistent_ram_zone **prz_ar;
|
2012-05-26 20:20:21 +07:00
|
|
|
|
2016-11-12 02:48:06 +07:00
|
|
|
/* Allocate nothing for 0 mem_sz or 0 record_size. */
|
|
|
|
if (mem_sz == 0 || record_size == 0) {
|
|
|
|
*cnt = 0;
|
2012-05-26 20:20:21 +07:00
|
|
|
return 0;
|
2012-12-12 08:49:24 +07:00
|
|
|
}
|
|
|
|
|
2016-11-12 02:48:06 +07:00
|
|
|
/*
|
|
|
|
* If we have a negative record size, calculate it based on
|
|
|
|
* mem_sz / *cnt. If we have a positive record size, calculate
|
|
|
|
* cnt from mem_sz / record_size.
|
|
|
|
*/
|
|
|
|
if (record_size < 0) {
|
|
|
|
if (*cnt == 0)
|
|
|
|
return 0;
|
|
|
|
record_size = mem_sz / *cnt;
|
2016-11-12 05:05:57 +07:00
|
|
|
if (record_size == 0) {
|
|
|
|
dev_err(dev, "%s record size == 0 (%zu / %u)\n",
|
|
|
|
name, mem_sz, *cnt);
|
2016-11-12 02:48:06 +07:00
|
|
|
goto fail;
|
2016-11-12 05:05:57 +07:00
|
|
|
}
|
2016-11-12 02:48:06 +07:00
|
|
|
} else {
|
|
|
|
*cnt = mem_sz / record_size;
|
2016-11-12 05:05:57 +07:00
|
|
|
if (*cnt == 0) {
|
|
|
|
dev_err(dev, "%s record count == 0 (%zu / %zu)\n",
|
|
|
|
name, mem_sz, record_size);
|
2016-11-12 02:48:06 +07:00
|
|
|
goto fail;
|
2016-11-12 05:05:57 +07:00
|
|
|
}
|
2016-11-12 02:48:06 +07:00
|
|
|
}
|
2012-05-26 20:20:21 +07:00
|
|
|
|
2016-11-12 02:48:06 +07:00
|
|
|
if (*paddr + mem_sz - cxt->phys_addr > cxt->size) {
|
2016-11-12 05:05:57 +07:00
|
|
|
dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
|
|
|
|
name,
|
2016-11-12 02:48:06 +07:00
|
|
|
mem_sz, (unsigned long long)*paddr,
|
|
|
|
cxt->size, (unsigned long long)cxt->phys_addr);
|
|
|
|
goto fail;
|
2012-05-26 20:20:21 +07:00
|
|
|
}
|
|
|
|
|
2016-11-12 02:48:06 +07:00
|
|
|
zone_sz = mem_sz / *cnt;
|
2016-11-12 05:05:57 +07:00
|
|
|
if (!zone_sz) {
|
|
|
|
dev_err(dev, "%s zone size == 0\n", name);
|
2016-11-12 02:48:06 +07:00
|
|
|
goto fail;
|
2016-11-12 05:05:57 +07:00
|
|
|
}
|
2016-11-12 02:48:06 +07:00
|
|
|
|
|
|
|
prz_ar = kcalloc(*cnt, sizeof(**przs), GFP_KERNEL);
|
|
|
|
if (!prz_ar)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
for (i = 0; i < *cnt; i++) {
|
2018-10-18 07:20:35 +07:00
|
|
|
char *label;
|
|
|
|
|
|
|
|
if (*cnt == 1)
|
|
|
|
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
|
|
|
|
else
|
|
|
|
label = kasprintf(GFP_KERNEL, "ramoops:%s(%d/%d)",
|
|
|
|
name, i, *cnt - 1);
|
2016-11-12 02:48:06 +07:00
|
|
|
prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig,
|
2018-10-18 07:20:35 +07:00
|
|
|
&cxt->ecc_info,
|
|
|
|
cxt->memtype, flags, label);
|
2016-11-12 02:48:06 +07:00
|
|
|
if (IS_ERR(prz_ar[i])) {
|
|
|
|
err = PTR_ERR(prz_ar[i]);
|
2016-11-12 05:05:57 +07:00
|
|
|
dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
|
|
|
|
name, record_size,
|
|
|
|
(unsigned long long)*paddr, err);
|
2016-09-08 18:48:05 +07:00
|
|
|
|
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
2016-11-12 02:48:06 +07:00
|
|
|
persistent_ram_free(prz_ar[i]);
|
2016-09-08 18:48:05 +07:00
|
|
|
}
|
2016-11-12 02:48:06 +07:00
|
|
|
kfree(prz_ar);
|
|
|
|
goto fail;
|
2012-05-26 20:20:21 +07:00
|
|
|
}
|
2016-11-12 02:48:06 +07:00
|
|
|
*paddr += zone_sz;
|
2018-11-04 06:38:16 +07:00
|
|
|
prz_ar[i]->type = pstore_name_to_type(name);
|
2012-05-26 20:20:21 +07:00
|
|
|
}
|
|
|
|
|
2016-11-12 02:48:06 +07:00
|
|
|
*przs = prz_ar;
|
2012-05-26 20:20:21 +07:00
|
|
|
return 0;
|
2016-11-12 02:48:06 +07:00
|
|
|
|
|
|
|
fail:
|
|
|
|
*cnt = 0;
|
2012-05-26 20:20:21 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-11-12 05:05:57 +07:00
|
|
|
static int ramoops_init_prz(const char *name,
|
|
|
|
struct device *dev, struct ramoops_context *cxt,
|
2012-12-22 06:02:05 +07:00
|
|
|
struct persistent_ram_zone **prz,
|
|
|
|
phys_addr_t *paddr, size_t sz, u32 sig)
|
2012-05-26 20:20:23 +07:00
|
|
|
{
|
2018-10-18 07:20:35 +07:00
|
|
|
char *label;
|
|
|
|
|
2012-05-26 20:20:23 +07:00
|
|
|
if (!sz)
|
|
|
|
return 0;
|
|
|
|
|
2012-12-12 08:49:24 +07:00
|
|
|
if (*paddr + sz - cxt->phys_addr > cxt->size) {
|
2016-11-12 05:05:57 +07:00
|
|
|
dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
|
|
|
|
name, sz, (unsigned long long)*paddr,
|
2012-12-12 08:49:24 +07:00
|
|
|
cxt->size, (unsigned long long)cxt->phys_addr);
|
2012-05-26 20:20:23 +07:00
|
|
|
return -ENOMEM;
|
2012-12-12 08:49:24 +07:00
|
|
|
}
|
2012-05-26 20:20:23 +07:00
|
|
|
|
2018-10-18 07:20:35 +07:00
|
|
|
label = kasprintf(GFP_KERNEL, "ramoops:%s", name);
|
2016-10-20 14:34:01 +07:00
|
|
|
*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
|
2018-10-30 14:52:34 +07:00
|
|
|
cxt->memtype, PRZ_FLAG_ZAP_OLD, label);
|
2012-05-26 20:20:23 +07:00
|
|
|
if (IS_ERR(*prz)) {
|
|
|
|
int err = PTR_ERR(*prz);
|
|
|
|
|
2016-11-12 05:05:57 +07:00
|
|
|
dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
|
|
|
|
name, sz, (unsigned long long)*paddr, err);
|
2012-05-26 20:20:23 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
*paddr += sz;
|
2018-11-04 06:38:16 +07:00
|
|
|
(*prz)->type = pstore_name_to_type(name);
|
2012-05-26 20:20:23 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-08 06:40:56 +07:00
|
|
|
static int ramoops_parse_dt_size(struct platform_device *pdev,
|
|
|
|
const char *propname, u32 *value)
|
|
|
|
{
|
|
|
|
u32 val32 = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(pdev->dev.of_node, propname, &val32);
|
|
|
|
if (ret < 0 && ret != -EINVAL) {
|
|
|
|
dev_err(&pdev->dev, "failed to parse property %s: %d\n",
|
|
|
|
propname, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (val32 > INT_MAX) {
|
|
|
|
dev_err(&pdev->dev, "%s %u > INT_MAX\n", propname, val32);
|
|
|
|
return -EOVERFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
*value = val32;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ramoops_parse_dt(struct platform_device *pdev,
|
|
|
|
struct ramoops_platform_data *pdata)
|
|
|
|
{
|
|
|
|
struct device_node *of_node = pdev->dev.of_node;
|
2016-07-30 08:11:32 +07:00
|
|
|
struct resource *res;
|
2016-01-08 06:40:56 +07:00
|
|
|
u32 value;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(&pdev->dev, "using Device Tree\n");
|
|
|
|
|
2016-07-30 08:11:32 +07:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
2016-01-08 06:40:56 +07:00
|
|
|
dev_err(&pdev->dev,
|
2016-07-30 08:11:32 +07:00
|
|
|
"failed to locate DT /reserved-memory resource\n");
|
|
|
|
return -EINVAL;
|
2016-01-08 06:40:56 +07:00
|
|
|
}
|
|
|
|
|
2016-07-30 08:11:32 +07:00
|
|
|
pdata->mem_size = resource_size(res);
|
|
|
|
pdata->mem_address = res->start;
|
2016-01-08 06:40:56 +07:00
|
|
|
pdata->mem_type = of_property_read_bool(of_node, "unbuffered");
|
|
|
|
pdata->dump_oops = !of_property_read_bool(of_node, "no-dump-oops");
|
|
|
|
|
|
|
|
#define parse_size(name, field) { \
|
|
|
|
ret = ramoops_parse_dt_size(pdev, name, &value); \
|
|
|
|
if (ret < 0) \
|
|
|
|
return ret; \
|
|
|
|
field = value; \
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_size("record-size", pdata->record_size);
|
|
|
|
parse_size("console-size", pdata->console_size);
|
|
|
|
parse_size("ftrace-size", pdata->ftrace_size);
|
|
|
|
parse_size("pmsg-size", pdata->pmsg_size);
|
|
|
|
parse_size("ecc-size", pdata->ecc_info.ecc_size);
|
2016-10-20 14:34:04 +07:00
|
|
|
parse_size("flags", pdata->flags);
|
2016-01-08 06:40:56 +07:00
|
|
|
|
|
|
|
#undef parse_size
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:02:05 +07:00
|
|
|
static int ramoops_probe(struct platform_device *pdev)
|
2010-05-27 04:43:54 +07:00
|
|
|
{
|
2012-05-17 14:15:18 +07:00
|
|
|
struct device *dev = &pdev->dev;
|
2016-01-08 06:40:56 +07:00
|
|
|
struct ramoops_platform_data *pdata = dev->platform_data;
|
2019-01-21 05:33:34 +07:00
|
|
|
struct ramoops_platform_data pdata_local;
|
2010-05-27 04:43:54 +07:00
|
|
|
struct ramoops_context *cxt = &oops_cxt;
|
2012-05-26 20:20:21 +07:00
|
|
|
size_t dump_mem_sz;
|
|
|
|
phys_addr_t paddr;
|
2010-05-27 04:43:54 +07:00
|
|
|
int err = -EINVAL;
|
|
|
|
|
2016-01-08 06:40:56 +07:00
|
|
|
if (dev_of_node(dev) && !pdata) {
|
2019-01-21 05:33:34 +07:00
|
|
|
pdata = &pdata_local;
|
|
|
|
memset(pdata, 0, sizeof(*pdata));
|
2016-01-08 06:40:56 +07:00
|
|
|
|
|
|
|
err = ramoops_parse_dt(pdev, pdata);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail_out;
|
|
|
|
}
|
|
|
|
|
2016-11-16 07:29:40 +07:00
|
|
|
/*
|
|
|
|
* Only a single ramoops area allowed at a time, so fail extra
|
2012-05-03 12:45:02 +07:00
|
|
|
* probes.
|
|
|
|
*/
|
2016-11-16 07:29:40 +07:00
|
|
|
if (cxt->max_dump_cnt) {
|
|
|
|
pr_err("already initialized\n");
|
2012-05-03 12:45:02 +07:00
|
|
|
goto fail_out;
|
2016-11-16 07:29:40 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we didn't get bogus platform data pointer. */
|
|
|
|
if (!pdata) {
|
|
|
|
pr_err("NULL platform data\n");
|
|
|
|
goto fail_out;
|
|
|
|
}
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2012-07-10 07:10:44 +07:00
|
|
|
if (!pdata->mem_size || (!pdata->record_size && !pdata->console_size &&
|
2015-01-17 07:01:10 +07:00
|
|
|
!pdata->ftrace_size && !pdata->pmsg_size)) {
|
2012-05-26 20:20:23 +07:00
|
|
|
pr_err("The memory size and the record/console size must be "
|
2011-07-27 06:08:59 +07:00
|
|
|
"non-zero\n");
|
2012-05-03 12:45:02 +07:00
|
|
|
goto fail_out;
|
2010-05-27 04:43:54 +07:00
|
|
|
}
|
|
|
|
|
2013-08-30 23:06:41 +07:00
|
|
|
if (pdata->record_size && !is_power_of_2(pdata->record_size))
|
2012-10-22 16:19:28 +07:00
|
|
|
pdata->record_size = rounddown_pow_of_two(pdata->record_size);
|
2013-08-30 23:06:41 +07:00
|
|
|
if (pdata->console_size && !is_power_of_2(pdata->console_size))
|
2012-10-22 16:19:28 +07:00
|
|
|
pdata->console_size = rounddown_pow_of_two(pdata->console_size);
|
2013-08-30 23:06:41 +07:00
|
|
|
if (pdata->ftrace_size && !is_power_of_2(pdata->ftrace_size))
|
2012-10-22 16:19:28 +07:00
|
|
|
pdata->ftrace_size = rounddown_pow_of_two(pdata->ftrace_size);
|
2015-01-17 07:01:10 +07:00
|
|
|
if (pdata->pmsg_size && !is_power_of_2(pdata->pmsg_size))
|
|
|
|
pdata->pmsg_size = rounddown_pow_of_two(pdata->pmsg_size);
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2011-07-27 06:08:57 +07:00
|
|
|
cxt->size = pdata->mem_size;
|
|
|
|
cxt->phys_addr = pdata->mem_address;
|
2014-09-17 03:50:01 +07:00
|
|
|
cxt->memtype = pdata->mem_type;
|
2011-07-27 06:08:59 +07:00
|
|
|
cxt->record_size = pdata->record_size;
|
2012-05-26 20:20:23 +07:00
|
|
|
cxt->console_size = pdata->console_size;
|
2012-07-10 07:10:44 +07:00
|
|
|
cxt->ftrace_size = pdata->ftrace_size;
|
2015-01-17 07:01:10 +07:00
|
|
|
cxt->pmsg_size = pdata->pmsg_size;
|
2011-07-27 06:08:58 +07:00
|
|
|
cxt->dump_oops = pdata->dump_oops;
|
2016-10-20 14:34:04 +07:00
|
|
|
cxt->flags = pdata->flags;
|
2012-05-23 06:33:23 +07:00
|
|
|
cxt->ecc_info = pdata->ecc_info;
|
2010-05-27 04:43:54 +07:00
|
|
|
|
2012-05-26 20:20:21 +07:00
|
|
|
paddr = cxt->phys_addr;
|
2012-05-17 14:15:18 +07:00
|
|
|
|
2015-01-17 07:01:10 +07:00
|
|
|
dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size
|
|
|
|
- cxt->pmsg_size;
|
2018-11-04 06:38:16 +07:00
|
|
|
err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr,
|
2016-11-12 05:05:57 +07:00
|
|
|
dump_mem_sz, cxt->record_size,
|
|
|
|
&cxt->max_dump_cnt, 0, 0);
|
2012-05-26 20:20:23 +07:00
|
|
|
if (err)
|
|
|
|
goto fail_out;
|
|
|
|
|
2016-11-12 05:05:57 +07:00
|
|
|
err = ramoops_init_prz("console", dev, cxt, &cxt->cprz, &paddr,
|
pstore/ram: Make tracing log versioned
Decoding the binary trace w/ a different kernel might be troublesome
since we convert addresses to symbols. For kernels with minimal changes,
the mappings would probably match, but it's not guaranteed at all.
(But still we could convert the addresses by hand, since we do print
raw addresses.)
If we use modules, the symbols could be loaded at different addresses
from the previously booted kernel, and so this would also fail, but
there's nothing we can do about it.
Also, the binary data format that pstore/ram is using in its ringbuffer
may change between the kernels, so here we too must ensure that we're
running the same kernel.
So, there are two questions really:
1. How to compute the unique kernel tag;
2. Where to store it.
In this patch we're using LINUX_VERSION_CODE, just as hibernation
(suspend-to-disk) does. This way we are protecting from the kernel
version mismatch, making sure that we're running the same kernel
version and patch level. We could use CRC of a symbol table (as
suggested by Tony Luck), but for now let's not be that strict.
And as for storing, we are using a small trick here. Instead of
allocating a dedicated buffer for the tag (i.e. another prz), or
hacking ram_core routines to "reserve" some control data in the
buffer, we are just encoding the tag into the buffer signature
(and XOR'ing it with the actual signature value, so that buffers
not needing a tag can just pass zero, which will result into the
plain old PRZ signature).
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Suggested-by: Tony Luck <tony.luck@intel.com>
Suggested-by: Colin Cross <ccross@android.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-07-18 02:11:12 +07:00
|
|
|
cxt->console_size, 0);
|
2012-05-26 20:20:23 +07:00
|
|
|
if (err)
|
|
|
|
goto fail_init_cprz;
|
|
|
|
|
2016-10-20 14:34:04 +07:00
|
|
|
cxt->max_ftrace_cnt = (cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)
|
|
|
|
? nr_cpu_ids
|
|
|
|
: 1;
|
2016-11-12 05:05:57 +07:00
|
|
|
err = ramoops_init_przs("ftrace", dev, cxt, &cxt->fprzs, &paddr,
|
|
|
|
cxt->ftrace_size, -1,
|
|
|
|
&cxt->max_ftrace_cnt, LINUX_VERSION_CODE,
|
2016-10-20 14:34:04 +07:00
|
|
|
(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU)
|
|
|
|
? PRZ_FLAG_NO_LOCK : 0);
|
2012-07-10 07:10:44 +07:00
|
|
|
if (err)
|
|
|
|
goto fail_init_fprz;
|
|
|
|
|
2016-11-12 05:05:57 +07:00
|
|
|
err = ramoops_init_prz("pmsg", dev, cxt, &cxt->mprz, &paddr,
|
|
|
|
cxt->pmsg_size, 0);
|
2015-01-17 07:01:10 +07:00
|
|
|
if (err)
|
|
|
|
goto fail_init_mprz;
|
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
cxt->pstore.data = cxt;
|
2012-05-26 20:20:23 +07:00
|
|
|
/*
|
2018-11-02 06:17:22 +07:00
|
|
|
* Since bufsize is only used for dmesg crash dumps, it
|
|
|
|
* must match the size of the dprz record (after PRZ header
|
|
|
|
* and ECC bytes have been accounted for).
|
2012-05-26 20:20:23 +07:00
|
|
|
*/
|
2018-11-02 06:17:22 +07:00
|
|
|
cxt->pstore.bufsize = cxt->dprzs[0]->buffer_size;
|
|
|
|
cxt->pstore.buf = kzalloc(cxt->pstore.bufsize, GFP_KERNEL);
|
2012-05-03 12:45:02 +07:00
|
|
|
if (!cxt->pstore.buf) {
|
2018-11-02 06:17:22 +07:00
|
|
|
pr_err("cannot allocate pstore crash dump buffer\n");
|
2013-05-07 18:39:20 +07:00
|
|
|
err = -ENOMEM;
|
2012-05-03 12:45:02 +07:00
|
|
|
goto fail_clear;
|
|
|
|
}
|
|
|
|
|
2016-07-27 22:08:26 +07:00
|
|
|
cxt->pstore.flags = PSTORE_FLAGS_DMESG;
|
|
|
|
if (cxt->console_size)
|
|
|
|
cxt->pstore.flags |= PSTORE_FLAGS_CONSOLE;
|
|
|
|
if (cxt->ftrace_size)
|
|
|
|
cxt->pstore.flags |= PSTORE_FLAGS_FTRACE;
|
|
|
|
if (cxt->pmsg_size)
|
|
|
|
cxt->pstore.flags |= PSTORE_FLAGS_PMSG;
|
2016-07-27 22:08:25 +07:00
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
err = pstore_register(&cxt->pstore);
|
2010-05-27 04:43:54 +07:00
|
|
|
if (err) {
|
2012-05-03 12:45:02 +07:00
|
|
|
pr_err("registering with pstore failed\n");
|
2012-05-17 14:15:18 +07:00
|
|
|
goto fail_buf;
|
2010-05-27 04:43:54 +07:00
|
|
|
}
|
|
|
|
|
2012-01-13 08:20:59 +07:00
|
|
|
/*
|
|
|
|
* Update the module parameter variables as well so they are visible
|
|
|
|
* through /sys/module/ramoops/parameters/
|
|
|
|
*/
|
|
|
|
mem_size = pdata->mem_size;
|
|
|
|
mem_address = pdata->mem_address;
|
|
|
|
record_size = pdata->record_size;
|
|
|
|
dump_oops = pdata->dump_oops;
|
2015-03-09 14:39:07 +07:00
|
|
|
ramoops_console_size = pdata->console_size;
|
|
|
|
ramoops_pmsg_size = pdata->pmsg_size;
|
|
|
|
ramoops_ftrace_size = pdata->ftrace_size;
|
2012-01-13 08:20:59 +07:00
|
|
|
|
2018-11-02 04:14:47 +07:00
|
|
|
pr_info("using 0x%lx@0x%llx, ecc: %d\n",
|
2012-05-03 12:45:03 +07:00
|
|
|
cxt->size, (unsigned long long)cxt->phys_addr,
|
2018-11-02 04:14:47 +07:00
|
|
|
cxt->ecc_info.ecc_size);
|
2012-05-03 12:45:02 +07:00
|
|
|
|
2010-05-27 04:43:54 +07:00
|
|
|
return 0;
|
|
|
|
|
2012-05-03 12:45:02 +07:00
|
|
|
fail_buf:
|
|
|
|
kfree(cxt->pstore.buf);
|
|
|
|
fail_clear:
|
|
|
|
cxt->pstore.bufsize = 0;
|
2016-07-25 10:56:55 +07:00
|
|
|
persistent_ram_free(cxt->mprz);
|
2015-01-17 07:01:10 +07:00
|
|
|
fail_init_mprz:
|
2012-07-10 07:10:44 +07:00
|
|
|
fail_init_fprz:
|
2016-07-25 10:56:55 +07:00
|
|
|
persistent_ram_free(cxt->cprz);
|
2012-05-26 20:20:23 +07:00
|
|
|
fail_init_cprz:
|
2012-05-26 20:20:21 +07:00
|
|
|
ramoops_free_przs(cxt);
|
2012-05-03 12:45:02 +07:00
|
|
|
fail_out:
|
2010-05-27 04:43:54 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-10-20 14:39:03 +07:00
|
|
|
static int ramoops_remove(struct platform_device *pdev)
|
2010-05-27 04:43:54 +07:00
|
|
|
{
|
|
|
|
struct ramoops_context *cxt = &oops_cxt;
|
|
|
|
|
2015-10-20 14:39:03 +07:00
|
|
|
pstore_unregister(&cxt->pstore);
|
2012-05-03 12:45:02 +07:00
|
|
|
|
|
|
|
kfree(cxt->pstore.buf);
|
|
|
|
cxt->pstore.bufsize = 0;
|
|
|
|
|
2015-10-20 14:39:03 +07:00
|
|
|
persistent_ram_free(cxt->mprz);
|
|
|
|
persistent_ram_free(cxt->cprz);
|
|
|
|
ramoops_free_przs(cxt);
|
|
|
|
|
2010-10-28 05:34:52 +07:00
|
|
|
return 0;
|
2010-05-27 04:43:54 +07:00
|
|
|
}
|
|
|
|
|
2016-01-08 06:40:56 +07:00
|
|
|
static const struct of_device_id dt_match[] = {
|
|
|
|
{ .compatible = "ramoops" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2010-10-28 05:34:52 +07:00
|
|
|
static struct platform_driver ramoops_driver = {
|
2012-06-19 09:15:50 +07:00
|
|
|
.probe = ramoops_probe,
|
2015-10-20 14:39:03 +07:00
|
|
|
.remove = ramoops_remove,
|
2010-10-28 05:34:52 +07:00
|
|
|
.driver = {
|
2016-01-08 06:40:56 +07:00
|
|
|
.name = "ramoops",
|
|
|
|
.of_match_table = dt_match,
|
2010-10-28 05:34:52 +07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-09-29 05:17:50 +07:00
|
|
|
static inline void ramoops_unregister_dummy(void)
|
2010-10-28 05:34:52 +07:00
|
|
|
{
|
2018-09-29 05:17:50 +07:00
|
|
|
platform_device_unregister(dummy);
|
|
|
|
dummy = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init ramoops_register_dummy(void)
|
|
|
|
{
|
2019-01-21 17:20:41 +07:00
|
|
|
struct ramoops_platform_data pdata;
|
|
|
|
|
2018-09-29 05:17:50 +07:00
|
|
|
/*
|
|
|
|
* Prepare a dummy platform data structure to carry the module
|
|
|
|
* parameters. If mem_size isn't set, then there are no module
|
|
|
|
* parameters, and we can skip this.
|
|
|
|
*/
|
2012-06-19 09:15:50 +07:00
|
|
|
if (!mem_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pr_info("using module parameters\n");
|
|
|
|
|
2019-01-21 17:20:41 +07:00
|
|
|
memset(&pdata, 0, sizeof(pdata));
|
|
|
|
pdata.mem_size = mem_size;
|
|
|
|
pdata.mem_address = mem_address;
|
|
|
|
pdata.mem_type = mem_type;
|
|
|
|
pdata.record_size = record_size;
|
|
|
|
pdata.console_size = ramoops_console_size;
|
|
|
|
pdata.ftrace_size = ramoops_ftrace_size;
|
|
|
|
pdata.pmsg_size = ramoops_pmsg_size;
|
|
|
|
pdata.dump_oops = dump_oops;
|
|
|
|
pdata.flags = RAMOOPS_FLAG_FTRACE_PER_CPU;
|
2016-10-20 14:34:04 +07:00
|
|
|
|
2012-07-10 07:03:19 +07:00
|
|
|
/*
|
|
|
|
* For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
|
|
|
|
* (using 1 byte for ECC isn't much of use anyway).
|
|
|
|
*/
|
2019-01-21 17:20:41 +07:00
|
|
|
pdata.ecc_info.ecc_size = ramoops_ecc == 1 ? 16 : ramoops_ecc;
|
2012-06-19 09:15:50 +07:00
|
|
|
|
|
|
|
dummy = platform_device_register_data(NULL, "ramoops", -1,
|
2019-01-21 17:20:41 +07:00
|
|
|
&pdata, sizeof(pdata));
|
2012-06-19 09:15:50 +07:00
|
|
|
if (IS_ERR(dummy)) {
|
|
|
|
pr_info("could not create platform device: %ld\n",
|
|
|
|
PTR_ERR(dummy));
|
2018-09-29 05:17:50 +07:00
|
|
|
dummy = NULL;
|
|
|
|
ramoops_unregister_dummy();
|
2012-06-19 09:15:50 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init ramoops_init(void)
|
|
|
|
{
|
2018-09-29 05:17:50 +07:00
|
|
|
int ret;
|
|
|
|
|
2012-06-19 09:15:50 +07:00
|
|
|
ramoops_register_dummy();
|
2018-09-29 05:17:50 +07:00
|
|
|
ret = platform_driver_register(&ramoops_driver);
|
|
|
|
if (ret != 0)
|
|
|
|
ramoops_unregister_dummy();
|
|
|
|
|
|
|
|
return ret;
|
2010-10-28 05:34:52 +07:00
|
|
|
}
|
2018-10-17 17:13:55 +07:00
|
|
|
postcore_initcall(ramoops_init);
|
2010-10-28 05:34:52 +07:00
|
|
|
|
|
|
|
static void __exit ramoops_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&ramoops_driver);
|
2018-09-29 05:17:50 +07:00
|
|
|
ramoops_unregister_dummy();
|
2010-10-28 05:34:52 +07:00
|
|
|
}
|
2010-05-27 04:43:54 +07:00
|
|
|
module_exit(ramoops_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Marco Stornelli <marco.stornelli@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("RAM Oops/Panic logger/driver");
|