Skip to content

Commit f0f23e5

Browse files
joelagnelkees
authored andcommitted
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>
1 parent 4af62a6 commit f0f23e5

File tree

6 files changed

+62
-52
lines changed

6 files changed

+62
-52
lines changed

drivers/acpi/apei/erst.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ static ssize_t erst_reader(struct pstore_record *record)
10351035
CPER_SECTION_TYPE_MCE) == 0)
10361036
record->type = PSTORE_TYPE_MCE;
10371037
else
1038-
record->type = PSTORE_TYPE_UNKNOWN;
1038+
record->type = PSTORE_TYPE_MAX;
10391039

10401040
if (rcd->hdr.validation_bits & CPER_VALID_TIMESTAMP)
10411041
record->time.tv_sec = rcd->hdr.timestamp;

fs/pstore/inode.c

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -335,53 +335,10 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
335335
goto fail_alloc;
336336
private->record = record;
337337

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" : "");
385342

386343
dentry = d_alloc_name(root, name);
387344
if (!dentry)

fs/pstore/platform.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content "
5959
"enabling this option is not safe, it may lead to further "
6060
"corruption on Oopses)");
6161

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+
6275
static int pstore_new_entry;
6376

6477
static void pstore_timefunc(struct timer_list *);
@@ -104,6 +117,30 @@ void pstore_set_kmsg_bytes(int bytes)
104117
/* Tag each group of saved records with a sequence number */
105118
static int oopscount;
106119

120+
const char *pstore_type_to_name(enum pstore_type_id type)
121+
{
122+
BUILD_BUG_ON(ARRAY_SIZE(pstore_type_names) != PSTORE_TYPE_MAX);
123+
124+
if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX))
125+
return "unknown";
126+
127+
return pstore_type_names[type];
128+
}
129+
EXPORT_SYMBOL_GPL(pstore_type_to_name);
130+
131+
enum pstore_type_id pstore_name_to_type(const char *name)
132+
{
133+
int i;
134+
135+
for (i = 0; i < PSTORE_TYPE_MAX; i++) {
136+
if (!strcmp(pstore_type_names[i], name))
137+
return i;
138+
}
139+
140+
return PSTORE_TYPE_MAX;
141+
}
142+
EXPORT_SYMBOL_GPL(pstore_name_to_type);
143+
107144
static const char *get_reason_str(enum kmsg_dump_reason reason)
108145
{
109146
switch (reason) {

fs/pstore/ram.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ static int ramoops_init_przs(const char *name,
611611
goto fail;
612612
}
613613
*paddr += zone_sz;
614+
prz_ar[i]->type = pstore_name_to_type(name);
614615
}
615616

616617
*przs = prz_ar;
@@ -650,6 +651,7 @@ static int ramoops_init_prz(const char *name,
650651
}
651652

652653
*paddr += sz;
654+
(*prz)->type = pstore_name_to_type(name);
653655

654656
return 0;
655657
}
@@ -785,7 +787,7 @@ static int ramoops_probe(struct platform_device *pdev)
785787

786788
dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size
787789
- cxt->pmsg_size;
788-
err = ramoops_init_przs("dump", dev, cxt, &cxt->dprzs, &paddr,
790+
err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr,
789791
dump_mem_sz, cxt->record_size,
790792
&cxt->max_dump_cnt, 0, 0);
791793
if (err)

include/linux/pstore.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,32 @@
3232

3333
struct module;
3434

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+
*/
3640
enum pstore_type_id {
41+
/* Frontend storage types */
3742
PSTORE_TYPE_DMESG = 0,
3843
PSTORE_TYPE_MCE = 1,
3944
PSTORE_TYPE_CONSOLE = 2,
4045
PSTORE_TYPE_FTRACE = 3,
41-
/* PPC64 partition types */
46+
47+
/* PPC64-specific partition types */
4248
PSTORE_TYPE_PPC_RTAS = 4,
4349
PSTORE_TYPE_PPC_OF = 5,
4450
PSTORE_TYPE_PPC_COMMON = 6,
4551
PSTORE_TYPE_PMSG = 7,
4652
PSTORE_TYPE_PPC_OPAL = 8,
47-
PSTORE_TYPE_UNKNOWN = 255
53+
54+
/* End of the list */
55+
PSTORE_TYPE_MAX
4856
};
4957

58+
const char *pstore_type_to_name(enum pstore_type_id type);
59+
enum pstore_type_id pstore_name_to_type(const char *name);
60+
5061
struct pstore_info;
5162
/**
5263
* struct pstore_record - details of a pstore record entry

include/linux/pstore_ram.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/init.h>
2323
#include <linux/kernel.h>
2424
#include <linux/list.h>
25+
#include <linux/pstore.h>
2526
#include <linux/types.h>
2627

2728
/*
@@ -54,6 +55,7 @@ struct persistent_ram_ecc_info {
5455
* @paddr: physical address of the mapped RAM area
5556
* @size: size of mapping
5657
* @label: unique name of this PRZ
58+
* @type: frontend type for this PRZ
5759
* @flags: holds PRZ_FLAGS_* bits
5860
*
5961
* @buffer_lock:
@@ -88,6 +90,7 @@ struct persistent_ram_zone {
8890
size_t size;
8991
void *vaddr;
9092
char *label;
93+
enum pstore_type_id type;
9194
u32 flags;
9295

9396
raw_spinlock_t buffer_lock;

0 commit comments

Comments
 (0)