Blame view
fs/pstore/platform.c
18.7 KB
450515395 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
ca01d6dd2 pstore: new files... |
2 3 4 |
/* * Persistent Storage - platform driver interface parts. * |
f29e5956a pstore: Add conso... |
5 |
* Copyright (C) 2007-2008 Google, Inc. |
ca01d6dd2 pstore: new files... |
6 |
* Copyright (C) 2010 Intel Corporation <tony.luck@intel.com> |
ca01d6dd2 pstore: new files... |
7 |
*/ |
ef7488535 fs/pstore: loggin... |
8 |
#define pr_fmt(fmt) "pstore: " fmt |
ca01d6dd2 pstore: new files... |
9 10 11 12 13 |
#include <linux/atomic.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/kmsg_dump.h> |
f29e5956a pstore: Add conso... |
14 |
#include <linux/console.h> |
ca01d6dd2 pstore: new files... |
15 16 |
#include <linux/module.h> #include <linux/pstore.h> |
58eb5b670 pstore: fix crypt... |
17 |
#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) |
8cfc8ddc9 pstore: add lzo/l... |
18 19 |
#include <linux/lzo.h> #endif |
58eb5b670 pstore: fix crypt... |
20 |
#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) |
8cfc8ddc9 pstore: add lzo/l... |
21 22 |
#include <linux/lz4.h> #endif |
1021bcf44 pstore: add zstd ... |
23 24 25 |
#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS) #include <linux/zstd.h> #endif |
cb3bee036 pstore: Use crypt... |
26 |
#include <linux/crypto.h> |
ca01d6dd2 pstore: new files... |
27 |
#include <linux/string.h> |
6dda92669 pstore: defer ins... |
28 |
#include <linux/timer.h> |
ca01d6dd2 pstore: new files... |
29 30 |
#include <linux/slab.h> #include <linux/uaccess.h> |
a3f5f075c pstore/platform: ... |
31 |
#include <linux/jiffies.h> |
6dda92669 pstore: defer ins... |
32 |
#include <linux/workqueue.h> |
ca01d6dd2 pstore: new files... |
33 34 35 36 |
#include "internal.h" /* |
6dda92669 pstore: defer ins... |
37 38 39 40 |
* We defer making "oops" entries appear in pstore - see * whether the system is actually still running well enough * to let someone see the entry */ |
521f7288a pstore/platform: ... |
41 |
static int pstore_update_ms = -1; |
a3f5f075c pstore/platform: ... |
42 43 |
module_param_named(update_ms, pstore_update_ms, int, 0600); MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content " |
521f7288a pstore/platform: ... |
44 |
"(default is -1, which means runtime updates are disabled; " |
78c83c828 pstore: Do not le... |
45 |
"enabling this option may not be safe; it may lead to further " |
521f7288a pstore/platform: ... |
46 |
"corruption on Oopses)"); |
6dda92669 pstore: defer ins... |
47 |
|
f0f23e546 pstore: Map PSTOR... |
48 49 50 51 52 53 54 55 56 57 58 59 |
/* Names should be in the same order as the enum pstore_type_id */ static const char * const pstore_type_names[] = { "dmesg", "mce", "console", "ftrace", "rtas", "powerpc-ofw", "powerpc-common", "pmsg", "powerpc-opal", }; |
6dda92669 pstore: defer ins... |
60 |
static int pstore_new_entry; |
24ed960ab treewide: Switch ... |
61 |
static void pstore_timefunc(struct timer_list *); |
1d27e3e22 timer: Remove exp... |
62 |
static DEFINE_TIMER(pstore_timer, pstore_timefunc); |
6dda92669 pstore: defer ins... |
63 64 65 66 67 |
static void pstore_dowork(struct work_struct *); static DECLARE_WORK(pstore_work, pstore_dowork); /* |
6248a0666 pstore: Add prope... |
68 69 70 |
* psinfo_lock protects "psinfo" during calls to * pstore_register(), pstore_unregister(), and * the filesystem mount/unmount routines. |
ca01d6dd2 pstore: new files... |
71 |
*/ |
cab12fd04 pstore: Convert "... |
72 |
static DEFINE_MUTEX(psinfo_lock); |
060287b8c pstore: Add persi... |
73 |
struct pstore_info *psinfo; |
ca01d6dd2 pstore: new files... |
74 |
|
dee28e72b pstore: Allow the... |
75 |
static char *backend; |
d973f7d83 pstore/platform: ... |
76 77 |
module_param(backend, charp, 0444); MODULE_PARM_DESC(backend, "specific backend to use"); |
fe1d47588 pstore: Select co... |
78 79 80 81 82 83 |
static char *compress = #ifdef CONFIG_PSTORE_COMPRESS_DEFAULT CONFIG_PSTORE_COMPRESS_DEFAULT; #else NULL; #endif |
d973f7d83 pstore/platform: ... |
84 85 |
module_param(compress, charp, 0444); MODULE_PARM_DESC(compress, "compression to use"); |
dee28e72b pstore: Allow the... |
86 |
|
b0aad7a99 pstore: Add compr... |
87 |
/* Compression parameters */ |
cb3bee036 pstore: Use crypt... |
88 |
static struct crypto_comp *tfm; |
8cfc8ddc9 pstore: add lzo/l... |
89 90 |
struct pstore_zbackend { |
cb3bee036 pstore: Use crypt... |
91 |
int (*zbufsize)(size_t size); |
8cfc8ddc9 pstore: add lzo/l... |
92 93 |
const char *name; }; |
b0aad7a99 pstore: Add compr... |
94 95 96 |
static char *big_oops_buf; static size_t big_oops_buf_sz; |
366f7e7a7 pstore: use mount... |
97 |
/* How much of the console log to snapshot */ |
349d74389 pstore: Implement... |
98 |
unsigned long kmsg_bytes = PSTORE_DEFAULT_KMSG_BYTES; |
ca01d6dd2 pstore: new files... |
99 |
|
366f7e7a7 pstore: use mount... |
100 |
void pstore_set_kmsg_bytes(int bytes) |
ca01d6dd2 pstore: new files... |
101 |
{ |
366f7e7a7 pstore: use mount... |
102 |
kmsg_bytes = bytes; |
ca01d6dd2 pstore: new files... |
103 |
} |
ca01d6dd2 pstore: new files... |
104 105 |
/* Tag each group of saved records with a sequence number */ static int oopscount; |
f0f23e546 pstore: Map PSTOR... |
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
const char *pstore_type_to_name(enum pstore_type_id type) { BUILD_BUG_ON(ARRAY_SIZE(pstore_type_names) != PSTORE_TYPE_MAX); if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX)) return "unknown"; return pstore_type_names[type]; } EXPORT_SYMBOL_GPL(pstore_type_to_name); enum pstore_type_id pstore_name_to_type(const char *name) { int i; for (i = 0; i < PSTORE_TYPE_MAX; i++) { if (!strcmp(pstore_type_names[i], name)) return i; } return PSTORE_TYPE_MAX; } EXPORT_SYMBOL_GPL(pstore_name_to_type); |
78c83c828 pstore: Do not le... |
129 130 131 132 133 134 135 |
static void pstore_timer_kick(void) { if (pstore_update_ms < 0) return; mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms)); } |
ea84b580b pstore: Convert b... |
136 137 138 139 140 141 |
/* * Should pstore_dump() wait for a concurrent pstore_dump()? If * not, the current pstore_dump() will report a failure to dump * and return. */ static bool pstore_cannot_wait(enum kmsg_dump_reason reason) |
9f244e9cf pstore: Avoid dea... |
142 |
{ |
ea84b580b pstore: Convert b... |
143 |
/* In NMI path, pstore shouldn't block regardless of reason. */ |
9f244e9cf pstore: Avoid dea... |
144 145 146 147 148 149 |
if (in_nmi()) return true; switch (reason) { /* In panic case, other cpus are stopped by smp_send_stop(). */ case KMSG_DUMP_PANIC: |
ea84b580b pstore: Convert b... |
150 |
/* Emergency restart shouldn't be blocked. */ |
9f244e9cf pstore: Avoid dea... |
151 152 153 154 155 156 |
case KMSG_DUMP_EMERG: return true; default: return false; } } |
9f244e9cf pstore: Avoid dea... |
157 |
|
58eb5b670 pstore: fix crypt... |
158 |
#if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS) |
cb3bee036 pstore: Use crypt... |
159 |
static int zbufsize_deflate(size_t size) |
adb42f5e1 pstore: Add decom... |
160 |
{ |
7de8fe2fa pstore: Adjust bu... |
161 |
size_t cmpr; |
cb3bee036 pstore: Use crypt... |
162 |
switch (size) { |
7de8fe2fa pstore: Adjust bu... |
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
/* buffer range for efivars */ case 1000 ... 2000: cmpr = 56; break; case 2001 ... 3000: cmpr = 54; break; case 3001 ... 3999: cmpr = 52; break; /* buffer range for nvram, erst */ case 4000 ... 10000: cmpr = 45; break; default: cmpr = 60; break; } |
b0aad7a99 pstore: Add compr... |
181 |
|
cb3bee036 pstore: Use crypt... |
182 |
return (size * 100) / cmpr; |
8cfc8ddc9 pstore: add lzo/l... |
183 |
} |
8cfc8ddc9 pstore: add lzo/l... |
184 |
#endif |
58eb5b670 pstore: fix crypt... |
185 |
#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) |
cb3bee036 pstore: Use crypt... |
186 |
static int zbufsize_lzo(size_t size) |
8cfc8ddc9 pstore: add lzo/l... |
187 |
{ |
cb3bee036 pstore: Use crypt... |
188 |
return lzo1x_worst_compress(size); |
8cfc8ddc9 pstore: add lzo/l... |
189 |
} |
8cfc8ddc9 pstore: add lzo/l... |
190 |
#endif |
58eb5b670 pstore: fix crypt... |
191 |
#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) || IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) |
cb3bee036 pstore: Use crypt... |
192 |
static int zbufsize_lz4(size_t size) |
8cfc8ddc9 pstore: add lzo/l... |
193 |
{ |
cb3bee036 pstore: Use crypt... |
194 |
return LZ4_compressBound(size); |
8cfc8ddc9 pstore: add lzo/l... |
195 |
} |
239b71619 pstore: Add lz4hc... |
196 |
#endif |
58eb5b670 pstore: fix crypt... |
197 |
#if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS) |
cb3bee036 pstore: Use crypt... |
198 |
static int zbufsize_842(size_t size) |
239b71619 pstore: Add lz4hc... |
199 |
{ |
555974068 pstore: Avoid siz... |
200 |
return size; |
239b71619 pstore: Add lz4hc... |
201 |
} |
8cfc8ddc9 pstore: add lzo/l... |
202 |
#endif |
1021bcf44 pstore: add zstd ... |
203 204 205 206 207 208 |
#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS) static int zbufsize_zstd(size_t size) { return ZSTD_compressBound(size); } #endif |
fe1d47588 pstore: Select co... |
209 210 211 |
static const struct pstore_zbackend *zbackend __ro_after_init; static const struct pstore_zbackend zbackends[] = { |
58eb5b670 pstore: fix crypt... |
212 |
#if IS_ENABLED(CONFIG_PSTORE_DEFLATE_COMPRESS) |
fe1d47588 pstore: Select co... |
213 |
{ |
cb3bee036 pstore: Use crypt... |
214 215 |
.zbufsize = zbufsize_deflate, .name = "deflate", |
fe1d47588 pstore: Select co... |
216 217 |
}, #endif |
58eb5b670 pstore: fix crypt... |
218 |
#if IS_ENABLED(CONFIG_PSTORE_LZO_COMPRESS) |
fe1d47588 pstore: Select co... |
219 |
{ |
cb3bee036 pstore: Use crypt... |
220 |
.zbufsize = zbufsize_lzo, |
fe1d47588 pstore: Select co... |
221 222 223 |
.name = "lzo", }, #endif |
58eb5b670 pstore: fix crypt... |
224 |
#if IS_ENABLED(CONFIG_PSTORE_LZ4_COMPRESS) |
fe1d47588 pstore: Select co... |
225 |
{ |
cb3bee036 pstore: Use crypt... |
226 |
.zbufsize = zbufsize_lz4, |
fe1d47588 pstore: Select co... |
227 228 229 |
.name = "lz4", }, #endif |
58eb5b670 pstore: fix crypt... |
230 |
#if IS_ENABLED(CONFIG_PSTORE_LZ4HC_COMPRESS) |
fe1d47588 pstore: Select co... |
231 |
{ |
cb3bee036 pstore: Use crypt... |
232 |
.zbufsize = zbufsize_lz4, |
fe1d47588 pstore: Select co... |
233 234 |
.name = "lz4hc", }, |
8cfc8ddc9 pstore: add lzo/l... |
235 |
#endif |
58eb5b670 pstore: fix crypt... |
236 |
#if IS_ENABLED(CONFIG_PSTORE_842_COMPRESS) |
fe1d47588 pstore: Select co... |
237 |
{ |
cb3bee036 pstore: Use crypt... |
238 |
.zbufsize = zbufsize_842, |
fe1d47588 pstore: Select co... |
239 240 241 |
.name = "842", }, #endif |
1021bcf44 pstore: add zstd ... |
242 243 244 245 246 247 |
#if IS_ENABLED(CONFIG_PSTORE_ZSTD_COMPRESS) { .zbufsize = zbufsize_zstd, .name = "zstd", }, #endif |
fe1d47588 pstore: Select co... |
248 249 |
{ } }; |
8cfc8ddc9 pstore: add lzo/l... |
250 251 |
static int pstore_compress(const void *in, void *out, |
cb3bee036 pstore: Use crypt... |
252 |
unsigned int inlen, unsigned int outlen) |
8cfc8ddc9 pstore: add lzo/l... |
253 |
{ |
cb3bee036 pstore: Use crypt... |
254 |
int ret; |
fd49e0328 pstore: Fix linki... |
255 256 |
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESSION)) return -EINVAL; |
cb3bee036 pstore: Use crypt... |
257 258 259 260 261 262 263 264 |
ret = crypto_comp_compress(tfm, in, inlen, out, &outlen); if (ret) { pr_err("crypto_comp_compress failed, ret = %d! ", ret); return ret; } return outlen; |
8cfc8ddc9 pstore: add lzo/l... |
265 |
} |
8cfc8ddc9 pstore: add lzo/l... |
266 267 |
static void allocate_buf_for_compression(void) { |
95047b051 pstore: Refactor ... |
268 269 270 271 272 |
struct crypto_comp *ctx; int size; char *buf; /* Skip if not built-in or compression backend not selected yet. */ |
e698aaf37 pstore: fix crypt... |
273 |
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESS) || !zbackend) |
cb3bee036 pstore: Use crypt... |
274 |
return; |
95047b051 pstore: Refactor ... |
275 276 277 |
/* Skip if no pstore backend yet or compression init already done. */ if (!psinfo || tfm) return; |
cb3bee036 pstore: Use crypt... |
278 |
if (!crypto_has_comp(zbackend->name, 0, 0)) { |
95047b051 pstore: Refactor ... |
279 280 |
pr_err("Unknown compression: %s ", zbackend->name); |
cb3bee036 pstore: Use crypt... |
281 282 |
return; } |
95047b051 pstore: Refactor ... |
283 284 285 286 287 |
size = zbackend->zbufsize(psinfo->bufsize); if (size <= 0) { pr_err("Invalid compression size for %s: %d ", zbackend->name, size); |
cb3bee036 pstore: Use crypt... |
288 |
return; |
95047b051 pstore: Refactor ... |
289 |
} |
cb3bee036 pstore: Use crypt... |
290 |
|
95047b051 pstore: Refactor ... |
291 292 293 294 295 |
buf = kmalloc(size, GFP_KERNEL); if (!buf) { pr_err("Failed %d byte compression buffer allocation for: %s ", size, zbackend->name); |
cb3bee036 pstore: Use crypt... |
296 297 |
return; } |
95047b051 pstore: Refactor ... |
298 299 300 301 302 303 |
ctx = crypto_alloc_comp(zbackend->name, 0, 0); if (IS_ERR_OR_NULL(ctx)) { kfree(buf); pr_err("crypto_alloc_comp('%s') failed: %ld ", zbackend->name, PTR_ERR(ctx)); |
cb3bee036 pstore: Use crypt... |
304 |
return; |
8cfc8ddc9 pstore: add lzo/l... |
305 |
} |
95047b051 pstore: Refactor ... |
306 307 308 309 310 |
/* A non-NULL big_oops_buf indicates compression is available. */ tfm = ctx; big_oops_buf_sz = size; big_oops_buf = buf; |
0eed84ffb pstore: Improve a... |
311 312 |
pr_info("Using crash dump compression: %s ", zbackend->name); |
8cfc8ddc9 pstore: add lzo/l... |
313 314 315 316 |
} static void free_buf_for_compression(void) { |
a9fb94a99 pstore: Set tfm t... |
317 |
if (IS_ENABLED(CONFIG_PSTORE_COMPRESS) && tfm) { |
cb3bee036 pstore: Use crypt... |
318 |
crypto_free_comp(tfm); |
a9fb94a99 pstore: Set tfm t... |
319 320 |
tfm = NULL; } |
cb3bee036 pstore: Use crypt... |
321 322 323 |
kfree(big_oops_buf); big_oops_buf = NULL; big_oops_buf_sz = 0; |
ee1d26742 pstore: add pstor... |
324 |
} |
b0aad7a99 pstore: Add compr... |
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
/* * Called when compression fails, since the printk buffer * would be fetched for compression calling it again when * compression fails would have moved the iterator of * printk buffer which results in fetching old contents. * Copy the recent messages from big_oops_buf to psinfo->buf */ static size_t copy_kmsg_to_buffer(int hsize, size_t len) { size_t total_len; size_t diff; total_len = hsize + len; if (total_len > psinfo->bufsize) { diff = total_len - psinfo->bufsize + hsize; memcpy(psinfo->buf, big_oops_buf, hsize); memcpy(psinfo->buf + hsize, big_oops_buf + diff, psinfo->bufsize - hsize); total_len = psinfo->bufsize; } else memcpy(psinfo->buf, big_oops_buf, total_len); return total_len; } |
e581ca813 pstore: Create co... |
350 351 352 353 354 355 |
void pstore_record_init(struct pstore_record *record, struct pstore_info *psinfo) { memset(record, 0, sizeof(*record)); record->psi = psinfo; |
c7f3c595f pstore: Populate ... |
356 357 |
/* Report zeroed timestamp if called before timekeeping has resumed. */ |
7aaa822ed pstore: Convert i... |
358 |
record->time = ns_to_timespec64(ktime_get_real_fast_ns()); |
e581ca813 pstore: Create co... |
359 |
} |
ca01d6dd2 pstore: new files... |
360 |
/* |
0eed84ffb pstore: Improve a... |
361 362 |
* callback from kmsg_dump. Save as much as we can (up to kmsg_bytes) from the * end of the buffer. |
ca01d6dd2 pstore: new files... |
363 364 |
*/ static void pstore_dump(struct kmsg_dumper *dumper, |
e2ae715d6 kmsg - kmsg_dump(... |
365 |
enum kmsg_dump_reason reason) |
ca01d6dd2 pstore: new files... |
366 |
{ |
e2ae715d6 kmsg - kmsg_dump(... |
367 |
unsigned long total = 0; |
381b872cf pstore: Introduce... |
368 |
const char *why; |
b94fdd077 pstore: Make "par... |
369 |
unsigned int part = 1; |
e2ae715d6 kmsg - kmsg_dump(... |
370 |
int ret; |
ca01d6dd2 pstore: new files... |
371 |
|
fb13cb8a0 printk: Introduce... |
372 |
why = kmsg_dump_reason_str(reason); |
9f6af27fb pstore: cleanups ... |
373 |
|
ea84b580b pstore: Convert b... |
374 375 376 377 378 379 380 381 382 383 384 |
if (down_trylock(&psinfo->buf_lock)) { /* Failed to acquire lock: give up if we cannot wait. */ if (pstore_cannot_wait(reason)) { pr_err("dump skipped in %s path: may corrupt error record ", in_nmi() ? "NMI" : why); return; } if (down_interruptible(&psinfo->buf_lock)) { pr_err("could not grab semaphore?! "); |
959217c84 pstore: Actually ... |
385 |
return; |
9f244e9cf pstore: Avoid dea... |
386 |
} |
98e44fda2 pstore: Enable co... |
387 |
} |
ea84b580b pstore: Convert b... |
388 |
|
ca01d6dd2 pstore: new files... |
389 390 |
oopscount++; while (total < kmsg_bytes) { |
e2ae715d6 kmsg - kmsg_dump(... |
391 |
char *dst; |
76cc9580e pstore: Replace a... |
392 393 |
size_t dst_size; int header_size; |
b0aad7a99 pstore: Add compr... |
394 |
int zipped_len = -1; |
76cc9580e pstore: Replace a... |
395 |
size_t dump_size; |
e581ca813 pstore: Create co... |
396 397 398 399 400 401 402 403 |
struct pstore_record record; pstore_record_init(&record, psinfo); record.type = PSTORE_TYPE_DMESG; record.count = oopscount; record.reason = reason; record.part = part; record.buf = psinfo->buf; |
e2ae715d6 kmsg - kmsg_dump(... |
404 |
|
ea84b580b pstore: Convert b... |
405 |
if (big_oops_buf) { |
b0aad7a99 pstore: Add compr... |
406 |
dst = big_oops_buf; |
76cc9580e pstore: Replace a... |
407 |
dst_size = big_oops_buf_sz; |
235f6d157 pstore: Cleanup p... |
408 409 |
} else { dst = psinfo->buf; |
76cc9580e pstore: Replace a... |
410 |
dst_size = psinfo->bufsize; |
235f6d157 pstore: Cleanup p... |
411 |
} |
76cc9580e pstore: Replace a... |
412 413 414 415 416 |
/* Write dump header. */ header_size = snprintf(dst, dst_size, "%s#%d Part%u ", why, oopscount, part); dst_size -= header_size; |
ca01d6dd2 pstore: new files... |
417 |
|
76cc9580e pstore: Replace a... |
418 419 420 |
/* Write dump contents. */ if (!kmsg_dump_get_buffer(dumper, true, dst + header_size, dst_size, &dump_size)) |
235f6d157 pstore: Cleanup p... |
421 |
break; |
b0aad7a99 pstore: Add compr... |
422 |
|
ea84b580b pstore: Convert b... |
423 |
if (big_oops_buf) { |
b0aad7a99 pstore: Add compr... |
424 |
zipped_len = pstore_compress(dst, psinfo->buf, |
76cc9580e pstore: Replace a... |
425 426 |
header_size + dump_size, psinfo->bufsize); |
b0aad7a99 pstore: Add compr... |
427 428 |
if (zipped_len > 0) { |
76cc9580e pstore: Replace a... |
429 430 |
record.compressed = true; record.size = zipped_len; |
b0aad7a99 pstore: Add compr... |
431 |
} else { |
76cc9580e pstore: Replace a... |
432 433 |
record.size = copy_kmsg_to_buffer(header_size, dump_size); |
b0aad7a99 pstore: Add compr... |
434 435 |
} } else { |
76cc9580e pstore: Replace a... |
436 |
record.size = header_size + dump_size; |
b0aad7a99 pstore: Add compr... |
437 |
} |
ca01d6dd2 pstore: new files... |
438 |
|
76cc9580e pstore: Replace a... |
439 |
ret = psinfo->write(&record); |
78c83c828 pstore: Do not le... |
440 |
if (ret == 0 && reason == KMSG_DUMP_OOPS) { |
6dda92669 pstore: defer ins... |
441 |
pstore_new_entry = 1; |
78c83c828 pstore: Do not le... |
442 443 |
pstore_timer_kick(); } |
e2ae715d6 kmsg - kmsg_dump(... |
444 |
|
76cc9580e pstore: Replace a... |
445 |
total += record.size; |
56280682c pstore: Add extra... |
446 |
part++; |
ca01d6dd2 pstore: new files... |
447 |
} |
ea84b580b pstore: Convert b... |
448 449 |
up(&psinfo->buf_lock); |
ca01d6dd2 pstore: new files... |
450 451 452 453 454 |
} static struct kmsg_dumper pstore_dumper = { .dump = pstore_dump, }; |
306e5c2a3 pstore: fix code ... |
455 456 457 |
/* * Register with kmsg_dump to save last part of console log on panic. */ |
187304115 pstore: add a hel... |
458 459 460 461 |
static void pstore_register_kmsg(void) { kmsg_dump_register(&pstore_dumper); } |
ee1d26742 pstore: add pstor... |
462 463 464 465 |
static void pstore_unregister_kmsg(void) { kmsg_dump_unregister(&pstore_dumper); } |
f29e5956a pstore: Add conso... |
466 467 468 |
#ifdef CONFIG_PSTORE_CONSOLE static void pstore_console_write(struct console *con, const char *s, unsigned c) { |
b77fa617a pstore: Remove ne... |
469 |
struct pstore_record record; |
f29e5956a pstore: Add conso... |
470 |
|
4c6c4d345 pstore: Avoid wri... |
471 472 |
if (!c) return; |
b77fa617a pstore: Remove ne... |
473 474 |
pstore_record_init(&record, psinfo); record.type = PSTORE_TYPE_CONSOLE; |
80c9d03c2 pstore: Avoid rec... |
475 |
|
b77fa617a pstore: Remove ne... |
476 477 478 |
record.buf = (char *)s; record.size = c; psinfo->write(&record); |
f29e5956a pstore: Add conso... |
479 480 481 |
} static struct console pstore_console = { |
f29e5956a pstore: Add conso... |
482 |
.write = pstore_console_write, |
f29e5956a pstore: Add conso... |
483 484 485 486 487 |
.index = -1, }; static void pstore_register_console(void) { |
d195c3905 pstore/platform: ... |
488 489 490 |
/* Show which backend is going to get console writes. */ strscpy(pstore_console.name, psinfo->name, sizeof(pstore_console.name)); |
b7753fc7f pstore: Make sure... |
491 492 493 494 495 |
/* * Always initialize flags here since prior unregister_console() * calls may have changed settings (specifically CON_ENABLED). */ pstore_console.flags = CON_PRINTBUFFER | CON_ENABLED | CON_ANYTIME; |
f29e5956a pstore: Add conso... |
496 497 |
register_console(&pstore_console); } |
ee1d26742 pstore: add pstor... |
498 499 500 501 502 |
static void pstore_unregister_console(void) { unregister_console(&pstore_console); } |
f29e5956a pstore: Add conso... |
503 504 |
#else static void pstore_register_console(void) {} |
ee1d26742 pstore: add pstor... |
505 |
static void pstore_unregister_console(void) {} |
f29e5956a pstore: Add conso... |
506 |
#endif |
4c9ec2197 pstore: Remove wr... |
507 508 |
static int pstore_write_user_compat(struct pstore_record *record, const char __user *buf) |
5bf6d1b92 pstore/pmsg: drop... |
509 |
{ |
30800d997 pstore: simplify ... |
510 511 512 513 |
int ret = 0; if (record->buf) return -EINVAL; |
077090af3 pstore: use memdu... |
514 |
record->buf = memdup_user(buf, record->size); |
dfd6fa39d pstore: remove un... |
515 |
if (IS_ERR(record->buf)) { |
077090af3 pstore: use memdu... |
516 |
ret = PTR_ERR(record->buf); |
30800d997 pstore: simplify ... |
517 |
goto out; |
5bf6d1b92 pstore/pmsg: drop... |
518 |
} |
30800d997 pstore: simplify ... |
519 520 |
ret = record->psi->write(record); |
30800d997 pstore: simplify ... |
521 |
kfree(record->buf); |
077090af3 pstore: use memdu... |
522 |
out: |
30800d997 pstore: simplify ... |
523 524 525 |
record->buf = NULL; return unlikely(ret < 0) ? ret : record->size; |
5bf6d1b92 pstore/pmsg: drop... |
526 |
} |
ca01d6dd2 pstore: new files... |
527 528 529 530 531 532 |
/* * platform specific persistent storage driver registers with * us here. If pstore is already mounted, call the platform * read function right away to populate the file system. If not * then the pstore mount code will call us later to fill out * the file system. |
ca01d6dd2 pstore: new files... |
533 534 535 |
*/ int pstore_register(struct pstore_info *psi) { |
0d7cd09a3 pstore: Improve r... |
536 537 538 |
if (backend && strcmp(backend, psi->name)) { pr_warn("ignoring unexpected backend '%s' ", psi->name); |
8e48b1a8e pstore: Return un... |
539 |
return -EPERM; |
0d7cd09a3 pstore: Improve r... |
540 |
} |
8e48b1a8e pstore: Return un... |
541 |
|
4c9ec2197 pstore: Remove wr... |
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
/* Sanity check flags. */ if (!psi->flags) { pr_warn("backend '%s' must support at least one frontend ", psi->name); return -EINVAL; } /* Check for required functions. */ if (!psi->read || !psi->write) { pr_warn("backend '%s' must implement read() and write() ", psi->name); return -EINVAL; } |
cab12fd04 pstore: Convert "... |
557 |
mutex_lock(&psinfo_lock); |
ca01d6dd2 pstore: new files... |
558 |
if (psinfo) { |
0d7cd09a3 pstore: Improve r... |
559 560 561 |
pr_warn("backend '%s' already loaded: ignoring '%s' ", psinfo->name, psi->name); |
cab12fd04 pstore: Convert "... |
562 |
mutex_unlock(&psinfo_lock); |
ca01d6dd2 pstore: new files... |
563 564 |
return -EBUSY; } |
dee28e72b pstore: Allow the... |
565 |
|
4c9ec2197 pstore: Remove wr... |
566 567 |
if (!psi->write_user) psi->write_user = pstore_write_user_compat; |
ca01d6dd2 pstore: new files... |
568 |
psinfo = psi; |
f6f828513 pstore: pass allo... |
569 |
mutex_init(&psinfo->read_mutex); |
ea84b580b pstore: Convert b... |
570 |
sema_init(&psinfo->buf_lock, 1); |
ca01d6dd2 pstore: new files... |
571 |
|
8880fa32c pstore/ram: Run w... |
572 573 |
if (psi->flags & PSTORE_FLAGS_DMESG) allocate_buf_for_compression(); |
b0aad7a99 pstore: Add compr... |
574 |
|
27e5041a8 pstore: Add locki... |
575 |
pstore_get_records(0); |
ca01d6dd2 pstore: new files... |
576 |
|
3524e688b pstore/platform: ... |
577 578 |
if (psi->flags & PSTORE_FLAGS_DMESG) { pstore_dumper.max_reason = psinfo->max_reason; |
c950fd6f2 pstore: Split pst... |
579 |
pstore_register_kmsg(); |
3524e688b pstore/platform: ... |
580 |
} |
c950fd6f2 pstore: Split pst... |
581 |
if (psi->flags & PSTORE_FLAGS_CONSOLE) |
df36ac1bc pstore: Don't all... |
582 |
pstore_register_console(); |
c950fd6f2 pstore: Split pst... |
583 |
if (psi->flags & PSTORE_FLAGS_FTRACE) |
df36ac1bc pstore: Don't all... |
584 |
pstore_register_ftrace(); |
c950fd6f2 pstore: Split pst... |
585 |
if (psi->flags & PSTORE_FLAGS_PMSG) |
9d5438f46 pstore: Add pmsg ... |
586 |
pstore_register_pmsg(); |
ca01d6dd2 pstore: new files... |
587 |
|
6330d5534 pstore: Shut down... |
588 |
/* Start watching for new records, if desired. */ |
78c83c828 pstore: Do not le... |
589 |
pstore_timer_kick(); |
6dda92669 pstore: defer ins... |
590 |
|
42222c2a5 fs/pstore: update... |
591 592 593 594 |
/* * Update the module parameter backend, so it is visible * through /sys/module/pstore/parameters/backend */ |
563ca40dd pstore/platform: ... |
595 |
backend = kstrdup(psi->name, GFP_KERNEL); |
42222c2a5 fs/pstore: update... |
596 |
|
ef7488535 fs/pstore: loggin... |
597 598 |
pr_info("Registered %s as persistent store backend ", psi->name); |
8e48b1a8e pstore: Return un... |
599 |
|
6248a0666 pstore: Add prope... |
600 |
mutex_unlock(&psinfo_lock); |
ca01d6dd2 pstore: new files... |
601 602 603 |
return 0; } EXPORT_SYMBOL_GPL(pstore_register); |
ee1d26742 pstore: add pstor... |
604 605 |
void pstore_unregister(struct pstore_info *psi) { |
6248a0666 pstore: Add prope... |
606 607 608 609 610 611 612 613 614 615 616 |
/* It's okay to unregister nothing. */ if (!psi) return; mutex_lock(&psinfo_lock); /* Only one backend can be registered at a time. */ if (WARN_ON(psi != psinfo)) { mutex_unlock(&psinfo_lock); return; } |
78c83c828 pstore: Do not le... |
617 |
/* Unregister all callbacks. */ |
c950fd6f2 pstore: Split pst... |
618 |
if (psi->flags & PSTORE_FLAGS_PMSG) |
a1db8060f ramoops: Only unr... |
619 |
pstore_unregister_pmsg(); |
c950fd6f2 pstore: Split pst... |
620 |
if (psi->flags & PSTORE_FLAGS_FTRACE) |
a1db8060f ramoops: Only unr... |
621 |
pstore_unregister_ftrace(); |
c950fd6f2 pstore: Split pst... |
622 |
if (psi->flags & PSTORE_FLAGS_CONSOLE) |
a1db8060f ramoops: Only unr... |
623 |
pstore_unregister_console(); |
c950fd6f2 pstore: Split pst... |
624 625 |
if (psi->flags & PSTORE_FLAGS_DMESG) pstore_unregister_kmsg(); |
ee1d26742 pstore: add pstor... |
626 |
|
78c83c828 pstore: Do not le... |
627 628 629 |
/* Stop timer and make sure all work has finished. */ del_timer_sync(&pstore_timer); flush_work(&pstore_work); |
609e28bb1 pstore: Remove fi... |
630 631 |
/* Remove all backend records from filesystem tree. */ pstore_put_backend_records(psi); |
ee1d26742 pstore: add pstor... |
632 633 634 |
free_buf_for_compression(); psinfo = NULL; |
563ca40dd pstore/platform: ... |
635 |
kfree(backend); |
ee1d26742 pstore: add pstor... |
636 |
backend = NULL; |
6248a0666 pstore: Add prope... |
637 |
mutex_unlock(&psinfo_lock); |
ee1d26742 pstore: add pstor... |
638 639 |
} EXPORT_SYMBOL_GPL(pstore_unregister); |
634f8f516 pstore: Move reco... |
640 641 |
static void decompress_record(struct pstore_record *record) { |
bdabc8e71 pstore: Do not us... |
642 |
int ret; |
634f8f516 pstore: Move reco... |
643 |
int unzipped_len; |
bdabc8e71 pstore: Do not us... |
644 |
char *unzipped, *workspace; |
634f8f516 pstore: Move reco... |
645 |
|
fd49e0328 pstore: Fix linki... |
646 |
if (!IS_ENABLED(CONFIG_PSTORE_COMPRESSION) || !record->compressed) |
4a16d1cb2 pstore: Don't war... |
647 |
return; |
634f8f516 pstore: Move reco... |
648 |
/* Only PSTORE_TYPE_DMESG support compression. */ |
4a16d1cb2 pstore: Don't war... |
649 |
if (record->type != PSTORE_TYPE_DMESG) { |
634f8f516 pstore: Move reco... |
650 651 652 653 |
pr_warn("ignored compressed record type %d ", record->type); return; } |
bdabc8e71 pstore: Do not us... |
654 |
/* Missing compression buffer means compression was not initialized. */ |
634f8f516 pstore: Move reco... |
655 |
if (!big_oops_buf) { |
bdabc8e71 pstore: Do not us... |
656 657 |
pr_warn("no decompression method initialized! "); |
634f8f516 pstore: Move reco... |
658 659 |
return; } |
bdabc8e71 pstore: Do not us... |
660 661 662 663 664 |
/* Allocate enough space to hold max decompression and ECC. */ unzipped_len = big_oops_buf_sz; workspace = kmalloc(unzipped_len + record->ecc_notice_size, GFP_KERNEL); if (!workspace) |
7e8cc8dce pstore: Always al... |
665 |
return; |
7e8cc8dce pstore: Always al... |
666 |
|
bdabc8e71 pstore: Do not us... |
667 668 669 670 671 672 673 |
/* After decompression "unzipped_len" is almost certainly smaller. */ ret = crypto_comp_decompress(tfm, record->buf, record->size, workspace, &unzipped_len); if (ret) { pr_err("crypto_comp_decompress failed, ret = %d! ", ret); kfree(workspace); |
7e8cc8dce pstore: Always al... |
674 675 |
return; } |
7e8cc8dce pstore: Always al... |
676 677 |
/* Append ECC notice to decompressed buffer. */ |
bdabc8e71 pstore: Do not us... |
678 |
memcpy(workspace + unzipped_len, record->buf + record->size, |
7e8cc8dce pstore: Always al... |
679 |
record->ecc_notice_size); |
bdabc8e71 pstore: Do not us... |
680 681 682 683 684 685 686 687 |
/* Copy decompressed contents into an minimum-sized allocation. */ unzipped = kmemdup(workspace, unzipped_len + record->ecc_notice_size, GFP_KERNEL); kfree(workspace); if (!unzipped) return; /* Swap out compressed contents with decompressed contents. */ |
7e8cc8dce pstore: Always al... |
688 |
kfree(record->buf); |
bdabc8e71 pstore: Do not us... |
689 |
record->buf = unzipped; |
7e8cc8dce pstore: Always al... |
690 691 |
record->size = unzipped_len; record->compressed = false; |
634f8f516 pstore: Move reco... |
692 |
} |
ca01d6dd2 pstore: new files... |
693 |
/* |
3a7d2fd16 pstore: Solve loc... |
694 |
* Read all the records from one persistent store backend. Create |
6dda92669 pstore: defer ins... |
695 696 697 |
* files in our filesystem. Don't warn about -EEXIST errors * when we are re-scanning the backing store looking to add new * error records. |
ca01d6dd2 pstore: new files... |
698 |
*/ |
3a7d2fd16 pstore: Solve loc... |
699 700 |
void pstore_get_backend_records(struct pstore_info *psi, struct dentry *root, int quiet) |
ca01d6dd2 pstore: new files... |
701 |
{ |
2a2b0acf7 pstore: Allocate ... |
702 |
int failed = 0; |
656de42e8 pstore: Avoid pot... |
703 |
unsigned int stop_loop = 65536; |
ca01d6dd2 pstore: new files... |
704 |
|
3a7d2fd16 pstore: Solve loc... |
705 |
if (!psi || !root) |
ca01d6dd2 pstore: new files... |
706 |
return; |
f6f828513 pstore: pass allo... |
707 |
mutex_lock(&psi->read_mutex); |
2174f6df7 pstore: gracefull... |
708 |
if (psi->open && psi->open(psi)) |
06cf91b4b pstore: fix pstor... |
709 |
goto out; |
1dfff7dd6 pstore: Pass reco... |
710 711 712 713 714 |
/* * Backend callback read() allocates record.buf. decompress_record() * may reallocate record.buf. On success, pstore_mkfile() will keep * the record.buf, so free it only on failure. */ |
656de42e8 pstore: Avoid pot... |
715 |
for (; stop_loop; stop_loop--) { |
2a2b0acf7 pstore: Allocate ... |
716 717 718 719 720 721 722 723 724 |
struct pstore_record *record; int rc; record = kzalloc(sizeof(*record), GFP_KERNEL); if (!record) { pr_err("out of memory creating record "); break; } |
e581ca813 pstore: Create co... |
725 |
pstore_record_init(record, psi); |
2a2b0acf7 pstore: Allocate ... |
726 727 728 729 |
record->size = psi->read(record); /* No more records left in backend? */ |
f6525b96d pstore: Fix leake... |
730 731 |
if (record->size <= 0) { kfree(record); |
2a2b0acf7 pstore: Allocate ... |
732 |
break; |
f6525b96d pstore: Fix leake... |
733 |
} |
2a2b0acf7 pstore: Allocate ... |
734 735 |
decompress_record(record); |
3a7d2fd16 pstore: Solve loc... |
736 |
rc = pstore_mkfile(root, record); |
1dfff7dd6 pstore: Pass reco... |
737 |
if (rc) { |
83f70f076 pstore: Do not du... |
738 |
/* pstore_mkfile() did not take record, so free it. */ |
2a2b0acf7 pstore: Allocate ... |
739 |
kfree(record->buf); |
83f70f076 pstore: Do not du... |
740 |
kfree(record); |
1dfff7dd6 pstore: Pass reco... |
741 742 743 |
if (rc != -EEXIST || !quiet) failed++; } |
ca01d6dd2 pstore: new files... |
744 |
} |
2174f6df7 pstore: gracefull... |
745 746 |
if (psi->close) psi->close(psi); |
06cf91b4b pstore: fix pstor... |
747 |
out: |
f6f828513 pstore: pass allo... |
748 |
mutex_unlock(&psi->read_mutex); |
ca01d6dd2 pstore: new files... |
749 750 |
if (failed) |
656de42e8 pstore: Avoid pot... |
751 752 |
pr_warn("failed to create %d record(s) from '%s' ", |
ef7488535 fs/pstore: loggin... |
753 |
failed, psi->name); |
656de42e8 pstore: Avoid pot... |
754 755 756 757 |
if (!stop_loop) pr_err("looping? Too many records seen from '%s' ", psi->name); |
ca01d6dd2 pstore: new files... |
758 |
} |
6dda92669 pstore: defer ins... |
759 760 761 762 |
static void pstore_dowork(struct work_struct *work) { pstore_get_records(1); } |
24ed960ab treewide: Switch ... |
763 |
static void pstore_timefunc(struct timer_list *unused) |
6dda92669 pstore: defer ins... |
764 765 766 767 768 |
{ if (pstore_new_entry) { pstore_new_entry = 0; schedule_work(&pstore_work); } |
78c83c828 pstore: Do not le... |
769 |
pstore_timer_kick(); |
6dda92669 pstore: defer ins... |
770 |
} |
8d82cee2f pstore: Make psto... |
771 |
static void __init pstore_choose_compression(void) |
fe1d47588 pstore: Select co... |
772 773 774 775 776 777 778 779 780 |
{ const struct pstore_zbackend *step; if (!compress) return; for (step = zbackends; step->name; step++) { if (!strcmp(compress, step->name)) { zbackend = step; |
fe1d47588 pstore: Select co... |
781 782 783 784 |
return; } } } |
cb095afd4 pstore: Centraliz... |
785 786 787 788 789 |
static int __init pstore_init(void) { int ret; pstore_choose_compression(); |
416031653 pstore: Allocate ... |
790 791 792 793 794 |
/* * Check if any pstore backends registered earlier but did not * initialize compression because crypto was not ready. If so, * initialize compression now. */ |
95047b051 pstore: Refactor ... |
795 |
allocate_buf_for_compression(); |
416031653 pstore: Allocate ... |
796 |
|
cb095afd4 pstore: Centraliz... |
797 798 |
ret = pstore_init_fs(); if (ret) |
8a57d6d4d pstore/platform: ... |
799 |
free_buf_for_compression(); |
cb095afd4 pstore: Centraliz... |
800 |
|
8a57d6d4d pstore/platform: ... |
801 |
return ret; |
cb095afd4 pstore: Centraliz... |
802 |
} |
416031653 pstore: Allocate ... |
803 |
late_initcall(pstore_init); |
cb095afd4 pstore: Centraliz... |
804 805 806 807 808 809 |
static void __exit pstore_exit(void) { pstore_exit_fs(); } module_exit(pstore_exit) |
cb095afd4 pstore: Centraliz... |
810 811 |
MODULE_AUTHOR("Tony Luck <tony.luck@intel.com>"); MODULE_LICENSE("GPL"); |