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