Skip to content

Commit cae0d23

Browse files
committed
Merge tag 'pstore-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull pstore updates from Kees Cook: - fix ftrace dump when ECC is enabled (Andrey Skvortsov) - fix resource leak when ioremap() fails (Cole Leavitt) - Remove useless memblock header (Guilherme G. Piccoli) - Fix ECC parameter help text (Guilherme G. Piccoli) - Keep ftrace module parameter and debugfs switch in sync (Guilherme G. Piccoli) - Factor KASLR offset in the core kernel instruction addresses (Guilherme G. Piccoli) * tag 'pstore-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: pstore/ftrace: Factor KASLR offset in the core kernel instruction addresses pstore/ftrace: Keep ftrace module parameter and debugfs switch in sync pstore/ram: fix resource leak when ioremap() fails pstore/ramoops: Fix ECC parameter help text pstore/ramoops: Remove useless memblock header pstore: fix ftrace dump, when ECC is enabled
2 parents d142ab3 + 24b8f8d commit cae0d23

5 files changed

Lines changed: 49 additions & 20 deletions

File tree

fs/pstore/ftrace.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,35 @@
1818
#include <linux/cache.h>
1919
#include <linux/slab.h>
2020
#include <asm/barrier.h>
21+
#include <asm/setup.h>
2122
#include "internal.h"
2223

2324
/* This doesn't need to be atomic: speed is chosen over correctness here. */
2425
static u64 pstore_ftrace_stamp;
2526

27+
static inline unsigned long adjust_ip(unsigned long ip)
28+
{
29+
#if defined(CONFIG_RANDOMIZE_BASE) && !defined(PSTORE_CPU_IN_IP) && IS_BUILTIN(CONFIG_PSTORE)
30+
if (core_kernel_text(ip))
31+
return ip - kaslr_offset();
32+
33+
__clear_bit(BITS_PER_LONG - 1, &ip);
34+
#endif
35+
return ip;
36+
}
37+
38+
inline unsigned long decode_ip(unsigned long ip)
39+
{
40+
#if defined(CONFIG_RANDOMIZE_BASE) && !defined(PSTORE_CPU_IN_IP) && IS_BUILTIN(CONFIG_PSTORE)
41+
if (test_bit(BITS_PER_LONG - 1, &ip))
42+
return ip + kaslr_offset();
43+
44+
__set_bit(BITS_PER_LONG - 1, &ip);
45+
46+
#endif
47+
return ip;
48+
}
49+
2650
static void notrace pstore_ftrace_call(unsigned long ip,
2751
unsigned long parent_ip,
2852
struct ftrace_ops *op,
@@ -47,8 +71,8 @@ static void notrace pstore_ftrace_call(unsigned long ip,
4771

4872
local_irq_save(flags);
4973

50-
rec.ip = ip;
51-
rec.parent_ip = parent_ip;
74+
rec.ip = adjust_ip(ip);
75+
rec.parent_ip = adjust_ip(parent_ip);
5276
pstore_ftrace_write_timestamp(&rec, pstore_ftrace_stamp++);
5377
pstore_ftrace_encode_cpu(&rec, raw_smp_processor_id());
5478
psinfo->write(&record);
@@ -62,13 +86,16 @@ static struct ftrace_ops pstore_ftrace_ops __read_mostly = {
6286
};
6387

6488
static DEFINE_MUTEX(pstore_ftrace_lock);
65-
static bool pstore_ftrace_enabled;
89+
static bool record_ftrace;
90+
module_param(record_ftrace, bool, 0400);
91+
MODULE_PARM_DESC(record_ftrace,
92+
"enable ftrace recording immediately (default: off)");
6693

6794
static int pstore_set_ftrace_enabled(bool on)
6895
{
6996
ssize_t ret;
7097

71-
if (on == pstore_ftrace_enabled)
98+
if (on == record_ftrace)
7299
return 0;
73100

74101
if (on) {
@@ -82,7 +109,7 @@ static int pstore_set_ftrace_enabled(bool on)
82109
pr_err("%s: unable to %sregister ftrace ops: %zd\n",
83110
__func__, on ? "" : "un", ret);
84111
} else {
85-
pstore_ftrace_enabled = on;
112+
record_ftrace = on;
86113
}
87114

88115
return ret;
@@ -111,7 +138,7 @@ static ssize_t pstore_ftrace_knob_write(struct file *f, const char __user *buf,
111138
static ssize_t pstore_ftrace_knob_read(struct file *f, char __user *buf,
112139
size_t count, loff_t *ppos)
113140
{
114-
char val[] = { '0' + pstore_ftrace_enabled, '\n' };
141+
char val[] = { '0' + record_ftrace, '\n' };
115142

116143
return simple_read_from_buffer(buf, count, ppos, val, sizeof(val));
117144
}
@@ -124,11 +151,6 @@ static const struct file_operations pstore_knob_fops = {
124151

125152
static struct dentry *pstore_ftrace_dir;
126153

127-
static bool record_ftrace;
128-
module_param(record_ftrace, bool, 0400);
129-
MODULE_PARM_DESC(record_ftrace,
130-
"enable ftrace recording immediately (default: off)");
131-
132154
void pstore_register_ftrace(void)
133155
{
134156
if (!psinfo->write)
@@ -145,9 +167,9 @@ void pstore_register_ftrace(void)
145167
void pstore_unregister_ftrace(void)
146168
{
147169
mutex_lock(&pstore_ftrace_lock);
148-
if (pstore_ftrace_enabled) {
170+
if (record_ftrace) {
149171
unregister_ftrace_function(&pstore_ftrace_ops);
150-
pstore_ftrace_enabled = false;
172+
record_ftrace = false;
151173
}
152174
mutex_unlock(&pstore_ftrace_lock);
153175

fs/pstore/inode.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
7474
if (!data)
7575
return NULL;
7676

77-
data->off = ps->total_size % REC_SIZE;
77+
data->off = ps->record->size % REC_SIZE;
7878
data->off += *pos * REC_SIZE;
79-
if (data->off + REC_SIZE > ps->total_size)
79+
if (data->off + REC_SIZE > ps->record->size)
8080
return NULL;
8181

8282
return_ptr(data);
@@ -94,7 +94,7 @@ static void *pstore_ftrace_seq_next(struct seq_file *s, void *v, loff_t *pos)
9494

9595
(*pos)++;
9696
data->off += REC_SIZE;
97-
if (data->off + REC_SIZE > ps->total_size)
97+
if (data->off + REC_SIZE > ps->record->size)
9898
return NULL;
9999

100100
return data;
@@ -105,17 +105,19 @@ static int pstore_ftrace_seq_show(struct seq_file *s, void *v)
105105
struct pstore_private *ps = s->private;
106106
struct pstore_ftrace_seq_data *data = v;
107107
struct pstore_ftrace_record *rec;
108+
unsigned long ip, parent_ip;
108109

109110
if (!data)
110111
return 0;
111112

112113
rec = (struct pstore_ftrace_record *)(ps->record->buf + data->off);
113114

115+
ip = decode_ip(rec->ip);
116+
parent_ip = decode_ip(rec->parent_ip);
114117
seq_printf(s, "CPU:%d ts:%llu %08lx %08lx %ps <- %pS\n",
115118
pstore_ftrace_decode_cpu(rec),
116119
pstore_ftrace_read_timestamp(rec),
117-
rec->ip, rec->parent_ip, (void *)rec->ip,
118-
(void *)rec->parent_ip);
120+
ip, parent_ip, (void *)ip, (void *)parent_ip);
119121

120122
return 0;
121123
}

fs/pstore/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
extern unsigned int kmsg_bytes;
1010

1111
#ifdef CONFIG_PSTORE_FTRACE
12+
extern unsigned long decode_ip(unsigned long ip);
1213
extern void pstore_register_ftrace(void);
1314
extern void pstore_unregister_ftrace(void);
1415
ssize_t pstore_ftrace_combine_log(char **dest_log, size_t *dest_log_size,
1516
const char *src_log, size_t src_log_size);
1617
#else
1718
static inline void pstore_register_ftrace(void) {}
1819
static inline void pstore_unregister_ftrace(void) {}
20+
static inline unsigned long decode_ip(unsigned long ip) { return ip; }
1921
static inline ssize_t
2022
pstore_ftrace_combine_log(char **dest_log, size_t *dest_log_size,
2123
const char *src_log, size_t src_log_size)

fs/pstore/ram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ MODULE_PARM_DESC(max_reason,
7171

7272
static int ramoops_ecc;
7373
module_param_named(ecc, ramoops_ecc, int, 0400);
74-
MODULE_PARM_DESC(ramoops_ecc,
74+
MODULE_PARM_DESC(ecc,
7575
"if non-zero, the option enables ECC support and specifies "
7676
"ECC buffer size in bytes (1 is a special value, means 16 "
7777
"bytes ECC)");

fs/pstore/ram_core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/io.h>
1313
#include <linux/kernel.h>
1414
#include <linux/list.h>
15-
#include <linux/memblock.h>
1615
#include <linux/rslib.h>
1716
#include <linux/slab.h>
1817
#include <linux/uaccess.h>
@@ -488,6 +487,10 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
488487
else
489488
va = ioremap_wc(start, size);
490489

490+
/* We must release the mem region if ioremap fails. */
491+
if (!va)
492+
release_mem_region(start, size);
493+
491494
/*
492495
* Since request_mem_region() and ioremap() are byte-granularity
493496
* there is no need handle anything special like we do when the

0 commit comments

Comments
 (0)