Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pstore: Map PSTORE_TYPE_* to strings

In later patches we will need to map types to names, so create a
constant table for that which can also be used in different parts of
old and new code. This saves the type in the PRZ which will be useful
in later patches.

Instead of having an explicit PSTORE_TYPE_UNKNOWN, just use ..._MAX.

This includes removing the now redundant filename templates which can use
a single format string. Also, there's no reason to limit the "is it still
compressed?" test to only PSTORE_TYPE_DMESG when building the pstorefs
filename. Records are zero-initialized, so a backend would need to have
explicitly set compressed=1.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Co-developed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>

authored by

Joel Fernandes (Google) and committed by
Kees Cook
f0f23e54 4af62a64

+62 -52
+1 -1
drivers/acpi/apei/erst.c
··· 1035 1035 CPER_SECTION_TYPE_MCE) == 0) 1036 1036 record->type = PSTORE_TYPE_MCE; 1037 1037 else 1038 - record->type = PSTORE_TYPE_UNKNOWN; 1038 + record->type = PSTORE_TYPE_MAX; 1039 1039 1040 1040 if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP) 1041 1041 record->time.tv_sec = rcd->hdr.timestamp;
+4 -47
fs/pstore/inode.c
··· 335 335 goto fail_alloc; 336 336 private->record = record; 337 337 338 - switch (record->type) { 339 - case PSTORE_TYPE_DMESG: 340 - scnprintf(name, sizeof(name), "dmesg-%s-%llu%s", 341 - record->psi->name, record->id, 342 - record->compressed ? ".enc.z" : ""); 343 - break; 344 - case PSTORE_TYPE_CONSOLE: 345 - scnprintf(name, sizeof(name), "console-%s-%llu", 346 - record->psi->name, record->id); 347 - break; 348 - case PSTORE_TYPE_FTRACE: 349 - scnprintf(name, sizeof(name), "ftrace-%s-%llu", 350 - record->psi->name, record->id); 351 - break; 352 - case PSTORE_TYPE_MCE: 353 - scnprintf(name, sizeof(name), "mce-%s-%llu", 354 - record->psi->name, record->id); 355 - break; 356 - case PSTORE_TYPE_PPC_RTAS: 357 - scnprintf(name, sizeof(name), "rtas-%s-%llu", 358 - record->psi->name, record->id); 359 - break; 360 - case PSTORE_TYPE_PPC_OF: 361 - scnprintf(name, sizeof(name), "powerpc-ofw-%s-%llu", 362 - record->psi->name, record->id); 363 - break; 364 - case PSTORE_TYPE_PPC_COMMON: 365 - scnprintf(name, sizeof(name), "powerpc-common-%s-%llu", 366 - record->psi->name, record->id); 367 - break; 368 - case PSTORE_TYPE_PMSG: 369 - scnprintf(name, sizeof(name), "pmsg-%s-%llu", 370 - record->psi->name, record->id); 371 - break; 372 - case PSTORE_TYPE_PPC_OPAL: 373 - scnprintf(name, sizeof(name), "powerpc-opal-%s-%llu", 374 - record->psi->name, record->id); 375 - break; 376 - case PSTORE_TYPE_UNKNOWN: 377 - scnprintf(name, sizeof(name), "unknown-%s-%llu", 378 - record->psi->name, record->id); 379 - break; 380 - default: 381 - scnprintf(name, sizeof(name), "type%d-%s-%llu", 382 - record->type, record->psi->name, record->id); 383 - break; 384 - } 338 + scnprintf(name, sizeof(name), "%s-%s-%llu%s", 339 + pstore_type_to_name(record->type), 340 + record->psi->name, record->id, 341 + record->compressed ? ".enc.z" : ""); 385 342 386 343 dentry = d_alloc_name(root, name); 387 344 if (!dentry)
+37
fs/pstore/platform.c
··· 59 59 "enabling this option is not safe, it may lead to further " 60 60 "corruption on Oopses)"); 61 61 62 + /* Names should be in the same order as the enum pstore_type_id */ 63 + static const char * const pstore_type_names[] = { 64 + "dmesg", 65 + "mce", 66 + "console", 67 + "ftrace", 68 + "rtas", 69 + "powerpc-ofw", 70 + "powerpc-common", 71 + "pmsg", 72 + "powerpc-opal", 73 + }; 74 + 62 75 static int pstore_new_entry; 63 76 64 77 static void pstore_timefunc(struct timer_list *); ··· 116 103 117 104 /* Tag each group of saved records with a sequence number */ 118 105 static int oopscount; 106 + 107 + const char *pstore_type_to_name(enum pstore_type_id type) 108 + { 109 + BUILD_BUG_ON(ARRAY_SIZE(pstore_type_names) != PSTORE_TYPE_MAX); 110 + 111 + if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX)) 112 + return "unknown"; 113 + 114 + return pstore_type_names[type]; 115 + } 116 + EXPORT_SYMBOL_GPL(pstore_type_to_name); 117 + 118 + enum pstore_type_id pstore_name_to_type(const char *name) 119 + { 120 + int i; 121 + 122 + for (i = 0; i < PSTORE_TYPE_MAX; i++) { 123 + if (!strcmp(pstore_type_names[i], name)) 124 + return i; 125 + } 126 + 127 + return PSTORE_TYPE_MAX; 128 + } 129 + EXPORT_SYMBOL_GPL(pstore_name_to_type); 119 130 120 131 static const char *get_reason_str(enum kmsg_dump_reason reason) 121 132 {
+3 -1
fs/pstore/ram.c
··· 611 611 goto fail; 612 612 } 613 613 *paddr += zone_sz; 614 + prz_ar[i]->type = pstore_name_to_type(name); 614 615 } 615 616 616 617 *przs = prz_ar; ··· 651 650 } 652 651 653 652 *paddr += sz; 653 + (*prz)->type = pstore_name_to_type(name); 654 654 655 655 return 0; 656 656 } ··· 787 785 788 786 dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size 789 787 - cxt->pmsg_size; 790 - err = ramoops_init_przs("dump", dev, cxt, &cxt->dprzs, &paddr, 788 + err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr, 791 789 dump_mem_sz, cxt->record_size, 792 790 &cxt->max_dump_cnt, 0, 0); 793 791 if (err)
+14 -3
include/linux/pstore.h
··· 32 32 33 33 struct module; 34 34 35 - /* pstore record types (see fs/pstore/inode.c for filename templates) */ 35 + /* 36 + * pstore record types (see fs/pstore/platform.c for pstore_type_names[]) 37 + * These values may be written to storage (see EFI vars backend), so 38 + * they are kind of an ABI. Be careful changing the mappings. 39 + */ 36 40 enum pstore_type_id { 41 + /* Frontend storage types */ 37 42 PSTORE_TYPE_DMESG = 0, 38 43 PSTORE_TYPE_MCE = 1, 39 44 PSTORE_TYPE_CONSOLE = 2, 40 45 PSTORE_TYPE_FTRACE = 3, 41 - /* PPC64 partition types */ 46 + 47 + /* PPC64-specific partition types */ 42 48 PSTORE_TYPE_PPC_RTAS = 4, 43 49 PSTORE_TYPE_PPC_OF = 5, 44 50 PSTORE_TYPE_PPC_COMMON = 6, 45 51 PSTORE_TYPE_PMSG = 7, 46 52 PSTORE_TYPE_PPC_OPAL = 8, 47 - PSTORE_TYPE_UNKNOWN = 255 53 + 54 + /* End of the list */ 55 + PSTORE_TYPE_MAX 48 56 }; 57 + 58 + const char *pstore_type_to_name(enum pstore_type_id type); 59 + enum pstore_type_id pstore_name_to_type(const char *name); 49 60 50 61 struct pstore_info; 51 62 /**
+3
include/linux/pstore_ram.h
··· 22 22 #include <linux/init.h> 23 23 #include <linux/kernel.h> 24 24 #include <linux/list.h> 25 + #include <linux/pstore.h> 25 26 #include <linux/types.h> 26 27 27 28 /* ··· 55 54 * @paddr: physical address of the mapped RAM area 56 55 * @size: size of mapping 57 56 * @label: unique name of this PRZ 57 + * @type: frontend type for this PRZ 58 58 * @flags: holds PRZ_FLAGS_* bits 59 59 * 60 60 * @buffer_lock: ··· 90 88 size_t size; 91 89 void *vaddr; 92 90 char *label; 91 + enum pstore_type_id type; 93 92 u32 flags; 94 93 95 94 raw_spinlock_t buffer_lock;