pstore: map pstore types to names
RFC 1/6 pstore: map pstore types to names
In later patches we will need to map types to names, so create a table for that which can also be used and reused in different parts of old and new code. Also use it to save the type in the PRZ which will be useful in later patches.
--- fs/pstore/inode.c | 44 ++++++++++++++++++++------------------ fs/pstore/ram.c | 4 +++- include/linux/pstore.h | 29 +++++++++++++++++++++++++ include/linux/pstore_ram.h | 2 ++ 4 files changed, 57 insertions(+), 22 deletions(-)
fs/pstore/inode.c +23 -21
@@ -304,6 +304,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)struct dentry *dentry;struct inode *inode;int rc =0 ; +enum pstore_type_id type;char name[PSTORE_NAMELEN ];struct pstore_private *private, *pos;unsigned long flags;
@@ -335,43 +336,44 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) goto fail_alloc; private->record = record; -switch (record->type) { + type = record->type; +switch (type) {case PSTORE_TYPE_DMESG : -scnprintf (name,sizeof (name),"dmesg-%s-%llu%s" , - record->psi->name, record->id, - record->compressed ?".enc.z" :"" ); +scnprintf (name,sizeof (name),"%s-%s-%llu%s" , + pstore_names[type], record->psi->name, record->id, + record->compressed ?".enc.z" :"" );break ;case PSTORE_TYPE_CONSOLE : -scnprintf (name,sizeof (name),"console-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_FTRACE : -scnprintf (name,sizeof (name),"ftrace-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_MCE : -scnprintf (name,sizeof (name),"mce-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_RTAS : -scnprintf (name,sizeof (name),"rtas-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OF : -scnprintf (name,sizeof (name),"powerpc-ofw-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_COMMON : -scnprintf (name,sizeof (name),"powerpc-common-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PMSG : -scnprintf (name,sizeof (name),"pmsg-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OPAL : -scnprintf (name,sizeof (name),"powerpc-opal-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_UNKNOWN : scnprintf(name, sizeof(name), "unknown-%s-%llu",
@@ -379,7 +381,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)break ;default :scnprintf (name,sizeof (name),"type%d-%s-%llu" , - record->type, record->psi->name, record->id); + type, record->psi->name, record->id);break ; }
fs/pstore/ram.c +3 -1
@@ -604,6 +604,7 @@ static int ramoops_init_przs(const char *name, goto fail; } *paddr += zone_sz; + prz_ar[i]->type =pstore_name_to_type (name); } *przs = prz_ar;
@@ -642,6 +643,7 @@ static int ramoops_init_prz(const char *name,persistent_ram_zap (*prz); *paddr += sz; + (*prz)->type =pstore_name_to_type (name);return 0 ; }
@@ -777,7 +779,7 @@ static int ramoops_probe(struct platform_device *pdev) dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size - cxt->pmsg_size; - err =ramoops_init_przs ("dump" , dev, cxt, &cxt->dprzs, &paddr, + err =ramoops_init_przs ("dmesg" , dev, cxt, &cxt->dprzs, &paddr, dump_mem_sz, cxt->record_size, &cxt->max_dump_cnt,0 ,0 );if (err)
include/linux/pstore.h +29 -0
@@ -47,6 +47,21 @@ enum pstore_type_id { PSTORE_TYPE_UNKNOWN = 255 }; +/* names should be in the same order as the above table */ +static char __maybe_unused *pstore_names[] = { +"dmesg" , +"mce" , +"console" , +"ftrace" , +"rtas" , +"powerpc-ofw" , +"powerpc-common" , +"pmsg" , +"powerpc-opal" , +"event" , +"unknown" ,/* unknown should be the last string */ +}; +struct pstore_info ;/** * struct pstore_record - details of a pstore record entry
@@ -274,4 +289,18 @@ pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) }#endif +static inline enum pstore_type_id pstore_name_to_type (const char *name) +{ +char *str; +int i =0 ; + +for (;strncmp (pstore_names[i],"unknown" ,7 ); i++) { + str = pstore_names[i]; +if (!strncmp (name, str,strlen (str))) +return (enum pstore_type_id )i; + } + +return PSTORE_TYPE_UNKNOWN ; +} +#endif /*_LINUX_PSTORE_H*/
include/linux/pstore_ram.h +2 -0
@@ -22,6 +22,7 @@#include <linux/init.h> #include <linux/kernel.h> #include <linux/list.h> +#include <linux/pstore.h> #include <linux/types.h> /*
@@ -47,6 +48,7 @@ struct persistent_ram_zone {size_t size;void *vaddr;struct persistent_ram_buffer *buffer; +enum pstore_type_id type;size_t buffer_size;u32 flags;raw_spinlock_t buffer_lock;
Signature · 1 line
2.19.1.568.g152ad8e336-goog
RFC 2/6 pstore: remove type argument from ramoops_get_next_prz
Since we store the type of the prz when we initialize it, we no longer need to pass it again in ramoops_get_next_prz since we can just use that to setup the pstore record. So lets remove it from the argument list.
--- fs/pstore/ram.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
fs/pstore/ram.c +7 -13
@@ -125,9 +125,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)static struct persistent_ram_zone *ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, -u64 *id, -enum pstore_type_id *typep,enum pstore_type_id type, -bool update) +u64 *id,enum pstore_type_id *typep,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;
@@ -147,7 +145,7 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,if (!persistent_ram_old_size (prz))return NULL ; - *typep = type; + *typep = prz->type; *id = i;return prz;
@@ -257,8 +255,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, cxt->max_dump_cnt, &record->id, - &record->type, -PSTORE_TYPE_DMESG ,1 ); + &record->type,1 );if (!prz_ok (prz))continue ; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
@@ -274,20 +271,18 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, -1 , &record->id, &record->type, -PSTORE_TYPE_CONSOLE ,0 ); +1 , &record->id, &record->type,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, -1 , &record->id, &record->type, -PSTORE_TYPE_PMSG ,0 ); +1 , &record->id, &record->type,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt,1 , &record->id, - &record->type,PSTORE_TYPE_FTRACE ,0 ); + &record->type,0 ); }else {/* * Build a new dummy record which combines all the
@@ -306,8 +301,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) &cxt->ftrace_read_cnt, cxt->max_ftrace_cnt, &record->id, - &record->type, - PSTORE_TYPE_FTRACE, 0); + &record->type, 0);if (!prz_ok (prz_next))continue ;
Signature · 1 line
2.19.1.568.g152ad8e336-goog
Re: [RFC 2/6] pstore: remove type argument from ramoops_get_next_prz
Quoted 5 lines · Joel Fernandes (Google)
Since we store the type of the prz when we initialize it, we no longer need to pass it again in
ramoops_get_next_przsince we can just use that to setup the pstore record. So lets remove it from the argument list.Signed-off-by Joel Fernandes (Google) <[email protected]>
Yes yes. I like where this is going. :)
-Kees
Quoted 75 lines
--- fs/pstore/ram.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)fs/pstore/ram.c +7
-14@@ -125,9 +125,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)static struct persistent_ram_zone *ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, -u64 *id, -enum pstore_type_id *typep,enum pstore_type_id type, -bool update) +u64 *id,enum pstore_type_id *typep,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;@@ -147,7 +145,7 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,if (!persistent_ram_old_size (prz))return NULL ; - *typep = type; + *typep = prz->type; *id = i;return prz;@@ -257,8 +255,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, cxt->max_dump_cnt, &record->id, - &record->type, -PSTORE_TYPE_DMESG ,1 ); + &record->type,1 );if (!prz_ok (prz))continue ; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),@@ -274,20 +271,18 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, -1 , &record->id, &record->type, -PSTORE_TYPE_CONSOLE ,0 ); +1 , &record->id, &record->type,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, -1 , &record->id, &record->type, -PSTORE_TYPE_PMSG ,0 ); +1 , &record->id, &record->type,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt,1 , &record->id, - &record->type,PSTORE_TYPE_FTRACE ,0 ); + &record->type,0 ); }else {/* * Build a new dummy record which combines all the @@ -306,8 +301,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) &cxt->ftrace_read_cnt, cxt->max_ftrace_cnt, &record->id, - &record->type, - PSTORE_TYPE_FTRACE, 0); + &record->type, 0);if (!prz_ok (prz_next))continue ; --2.19.1.568.g152ad8e336-goog
Signature · 1 line
Kees Cook
RFC 3/6 pstore: remove max argument from ramoops_get_next_prz
In reply to Joel Fernandes (Google)From the code flow, the 'max' checks are already being done on the prz passed to ramoops_get_next_prz. Lets remove it to simplify this function and reduce its arguments.
--- fs/pstore/ram.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
fs/pstore/ram.c +6 -8
@@ -124,14 +124,14 @@ static int ramoops_pstore_open(struct pstore_info *psi) }static struct persistent_ram_zone * -ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, +ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,u64 *id,enum pstore_type_id *typep,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;/* Give up if we never existed or have hit the end. */ -if (!przs || i >= max) +if (!przs)return NULL ; prz = przs[i];
@@ -254,8 +254,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, - cxt->max_dump_cnt, &record->id, - &record->type,1 ); + &record->id, &record->type,1 );if (!prz_ok (prz))continue ; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
@@ -271,17 +270,17 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, -1 , &record->id, &record->type,0 ); + &record->id, &record->type,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, -1 , &record->id, &record->type,0 ); + &record->id, &record->type,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, - &cxt->ftrace_read_cnt,1 , &record->id, + &cxt->ftrace_read_cnt, &record->id, &record->type,0 ); }else {/*
@@ -299,7 +298,6 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { prz_next =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, - cxt->max_ftrace_cnt, &record->id, &record->type,0 );
Signature · 1 line
2.19.1.568.g152ad8e336-goog
Re: [RFC 3/6] pstore: remove max argument from ramoops_get_next_prz
Quoted 20 lines · Joel Fernandes (Google)
From the code flow, the 'max' checks are already being done on the prz passed to
ramoops_get_next_prz. Lets remove it to simplify this function and reduce its arguments.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/pstore/ram.c +1
-1@@ -124,14 +124,14 @@ static int ramoops_pstore_open(struct pstore_info *psi) }static struct persistent_ram_zone * -ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, +ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,u64 *id,enum pstore_type_id *typep,bool update)
fs/pstore/ram.c static int ramoops_pstore_open(struct pstore_info *psi) · line 137
Quoted 10 lines
fs/pstore/ram.c +1
-1{struct persistent_ram_zone *prz;int i = (*c)++;/* Give up if we never existed or have hit the end. */ -if (!przs || i >= max) +if (!przs)return NULL ; prz = przs[i];
Ah, looks like I may have introduced an issue here since 'i' isn't checked by the caller for the single prz case, its only checked for the multiple prz cases, so something like below could be folded in. I still feel its better than passing the max argument.
Another thought is, even better we could have a different function when there's only one prz and not have to pass an array, just pass the first element? Something like...
ramoops_get_next_prz_single(struct persistent_ram_zone *prz, uint *c,
enum pstore_type_id *typep, bool update)
And for the _single case, we also wouldn't need to pass id so that's another argument less.
Let me know what you think, otherwise something like the below will need to be folded in to fix this patch... thanks.
----8<---
fs/pstore/ram.c +5 -3
@@ -268,17 +268,19 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) } } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->console_read_cnt) { prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, record,0 ); + } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->pmsg_read_cnt) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, record,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) { -if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { +if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) && + !cxt->ftrace_read_cnt) { prz =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, record,0 ); }else {
Re: [RFC 3/6] pstore: remove max argument from ramoops_get_next_prz
Quoted 68 lines · Joel Fernandes
Quoted 20 lines · Joel Fernandes (Google)
From the code flow, the 'max' checks are already being done on the prz passed to
ramoops_get_next_prz. Lets remove it to simplify this function and reduce its arguments.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/pstore/ram.c +1
-1@@ -124,14 +124,14 @@ static int ramoops_pstore_open(struct pstore_info *psi) }static struct persistent_ram_zone * -ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, +ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,u64 *id,enum pstore_type_id *typep,bool update)fs/pstore/ram.c static int ramoops_pstore_open(struct pstore_info *psi) · line 137
Quoted 10 lines
fs/pstore/ram.c +1
-1{struct persistent_ram_zone *prz;int i = (*c)++;/* Give up if we never existed or have hit the end. */ -if (!przs || i >= max) +if (!przs)return NULL ; prz = przs[i];Ah, looks like I may have introduced an issue here since 'i' isn't checked by the caller for the single prz case, its only checked for the multiple prz cases, so something like below could be folded in. I still feel its better than passing the max argument.
Another thought is, even better we could have a different function when there's only one prz and not have to pass an array, just pass the first element? Something like...
ramoops_get_next_prz_single(struct
persistent_ram_zone*prz, uint *c,
enumpstore_type_id*typep, bool update)
And for the_singlecase, we also wouldn't need to pass id so that's another argument less.Let me know what you think, otherwise something like the below will need to be folded in to fix this patch... thanks.
----8<---
fs/pstore/ram.c +3
-2@@ -268,17 +268,19 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) } } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->console_read_cnt) { prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, record,0 ); + } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->pmsg_read_cnt) prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,
fs/pstore/ram.c static ssize_t ramoops_pstore_read(struct pstore_record *record) · line 286
Quoted 10 lines
fs/pstore/ram.c +2
-1record, 0);/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) { -if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { +if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) && + !cxt->ftrace_read_cnt) { prz =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, record,0 ); }else {
Ah yeah, good catch! I think your added fix is right. I was pondering asking you to remove the & on the *_read_cnt and having the caller do the increment:
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
&record->id,
&record->type,
PSTORE_TYPE_DMESG, 1);-Kees
Signature · 1 line
Kees Cook
Re: [RFC 3/6] pstore: remove max argument from ramoops_get_next_prz
Quoted 84 lines · Kees Cook
Quoted 68 lines · Joel Fernandes
Quoted 20 lines · Joel Fernandes (Google)
From the code flow, the 'max' checks are already being done on the prz passed to
ramoops_get_next_prz. Lets remove it to simplify this function and reduce its arguments.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/pstore/ram.c +1
-1@@ -124,14 +124,14 @@ static int ramoops_pstore_open(struct pstore_info *psi) }static struct persistent_ram_zone * -ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, +ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,u64 *id,enum pstore_type_id *typep,bool update)fs/pstore/ram.c static int ramoops_pstore_open(struct pstore_info *psi) · line 137
Quoted 10 lines
fs/pstore/ram.c +1
-1{struct persistent_ram_zone *prz;int i = (*c)++;/* Give up if we never existed or have hit the end. */ -if (!przs || i >= max) +if (!przs)return NULL ; prz = przs[i];Ah, looks like I may have introduced an issue here since 'i' isn't checked by the caller for the single prz case, its only checked for the multiple prz cases, so something like below could be folded in. I still feel its better than passing the max argument.
Another thought is, even better we could have a different function when there's only one prz and not have to pass an array, just pass the first element? Something like...
ramoops_get_next_prz_single(struct
persistent_ram_zone*prz, uint *c,
enumpstore_type_id*typep, bool update)
And for the_singlecase, we also wouldn't need to pass id so that's another argument less.Let me know what you think, otherwise something like the below will need to be folded in to fix this patch... thanks.
----8<---
fs/pstore/ram.c +3
-2@@ -268,17 +268,19 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record) } } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->console_read_cnt) { prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, record,0 ); + } -if (!prz_ok (prz)) +if (!prz_ok (prz) && !cxt->pmsg_read_cnt) prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,fs/pstore/ram.c static ssize_t ramoops_pstore_read(struct pstore_record *record) · line 286
Quoted 10 lines
fs/pstore/ram.c +2
-1record, 0);/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) { -if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { +if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU ) && + !cxt->ftrace_read_cnt) { prz =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, record,0 ); }else {Ah yeah, good catch! I think your added fix is right. I was pondering asking you to remove the & on the
*_read_cntand having the caller do the increment:
Quoted 5 lines
while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) {
prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
&record->id,
&record->type,
PSTORE_TYPE_DMESG, 1);Sure, that's better, I'll do that. That we don't have to pass a pointer, the caller knows about the increment, and its a local variable less. thanks!
- Joel
Re: [RFC 3/6] pstore: remove max argument from ramoops_get_next_prz
In reply to Joel Fernandes (Google)Quoted 70 lines · Joel Fernandes (Google)
From the code flow, the 'max' checks are already being done on the prz passed to
ramoops_get_next_prz. Lets remove it to simplify this function and reduce its arguments.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)fs/pstore/ram.c +6
-9@@ -124,14 +124,14 @@ static int ramoops_pstore_open(struct pstore_info *psi) }static struct persistent_ram_zone * -ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,uint max, +ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c,u64 *id,enum pstore_type_id *typep,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;/* Give up if we never existed or have hit the end. */ -if (!przs || i >= max) +if (!przs)return NULL ; prz = przs[i];@@ -254,8 +254,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, - cxt->max_dump_cnt, &record->id, - &record->type,1 ); + &record->id, &record->type,1 );if (!prz_ok (prz))continue ; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),@@ -271,17 +270,17 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, -1 , &record->id, &record->type,0 ); + &record->id, &record->type,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, -1 , &record->id, &record->type,0 ); + &record->id, &record->type,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, - &cxt->ftrace_read_cnt,1 , &record->id, + &cxt->ftrace_read_cnt, &record->id, &record->type,0 ); }else {/* @@ -299,7 +298,6 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { prz_next =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, - cxt->max_ftrace_cnt, &record->id, &record->type,0 ); --
Quoted 2 lines
2.19.1.568.g152ad8e336-goog
Yup, looks good.
Signature · 1 line
Kees Cook
RFC 4/6 pstore: further reduce ramoops_get_next_prz arguments by passing record
In reply to Joel Fernandes (Google)Both the id and type fields of a pstore_record are set by ramoops_get_next_prz. So we can just pass a pointer to the pstore_record instead of passing individual elements. This results in cleaner more readable code and fewer lines.
--- fs/pstore/ram.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
fs/pstore/ram.c +8 -10
@@ -125,7 +125,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)static struct persistent_ram_zone *ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c, -u64 *id,enum pstore_type_id *typep,bool update) +struct pstore_record *record,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;
@@ -145,8 +145,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c,if (!persistent_ram_old_size (prz))return NULL ; - *typep = prz->type; - *id = i; + record->type = prz->type; + record->id = i;return prz; }
@@ -254,7 +254,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, - &record->id, &record->type,1 ); + record,1 );if (!prz_ok (prz))continue ; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
@@ -270,18 +270,17 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, - &record->id, &record->type,0 ); + record,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, - &record->id, &record->type,0 ); + record,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, - &cxt->ftrace_read_cnt, &record->id, - &record->type,0 ); + &cxt->ftrace_read_cnt, record,0 ); }else {/* * Build a new dummy record which combines all the
@@ -298,8 +297,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { prz_next =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, - &record->id, - &record->type,0 ); + record,0 );if (!prz_ok (prz_next))continue ;
Signature · 1 line
2.19.1.568.g152ad8e336-goog
Re: [RFC 4/6] pstore: further reduce ramoops_get_next_prz arguments by passing record
Quoted 24 lines · Joel Fernandes (Google)
Both the id and type fields of a
pstore_recordare set byramoops_get_next_prz. So we can just pass a pointer to thepstore_recordinstead of passing individual elements. This results in cleaner more readable code and fewer lines.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)fs/pstore/ram.c +1
-1@@ -125,7 +125,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)static struct persistent_ram_zone *ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c, -u64 *id,enum pstore_type_id *typep,bool update) +struct pstore_record *record,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;
fs/pstore/ram.c ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, · line 149
Quoted 7 lines
fs/pstore/ram.c +2
-2@@ -145,8 +145,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c,if (!persistent_ram_old_size (prz))return NULL ; - *typep = prz->type; - *id = i; + record->type = prz->type; + record->id = i;
Yes yes. I've been meaning to get all this cleaned up after I refactored everything to actually HAVE record at all. :P
fs/pstore/ram.c static ssize_t ramoops_pstore_read(struct pstore_record *record) · line 257
Quoted 9 lines
fs/pstore/ram.c +1
-1return prz; }@@ -254,7 +254,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, - &record->id, &record->type,1 ); + record,1 );
In another patch, I think you could drop the "update" field too, and use the record->type instead to determine if update is needed. Like:
static struct persistent_ram_zone * ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint c,
struct pstore_record *record)
{
bool update = (record->type == PSTORE_TYPE_DMESG);...
Quoted 38 lines
if (!prz_ok(prz)) continue; header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),fs/pstore/ram.c +4
-7@@ -270,18 +270,17 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->cprz, &cxt->console_read_cnt, - &record->id, &record->type,0 ); + record,0 );if (!prz_ok (prz)) prz =ramoops_get_next_prz (&cxt->mprz, &cxt->pmsg_read_cnt, - &record->id, &record->type,0 ); + record,0 );/* ftrace is last since it may want to dynamically allocate memory. */ if (!prz_ok (prz)) {if (!(cxt->flags &RAMOOPS_FLAG_FTRACE_PER_CPU )) { prz =ramoops_get_next_prz (cxt->fprzs, - &cxt->ftrace_read_cnt, &record->id, - &record->type,0 ); + &cxt->ftrace_read_cnt, record,0 ); }else {/* * Build a new dummy record which combines all the @@ -298,8 +297,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)while (cxt->ftrace_read_cnt < cxt->max_ftrace_cnt) { prz_next =ramoops_get_next_prz (cxt->fprzs, &cxt->ftrace_read_cnt, - &record->id, - &record->type,0 ); + record,0 );if (!prz_ok (prz_next))continue ; --2.19.1.568.g152ad8e336-goog
Signature · 1 line
Kees Cook
Re: [RFC 4/6] pstore: further reduce ramoops_get_next_prz arguments by passing record
Quoted 50 lines · Kees Cook
Quoted 24 lines · Joel Fernandes (Google)
Both the id and type fields of a
pstore_recordare set byramoops_get_next_prz. So we can just pass a pointer to thepstore_recordinstead of passing individual elements. This results in cleaner more readable code and fewer lines.Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)fs/pstore/ram.c +1
-1@@ -125,7 +125,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)static struct persistent_ram_zone *ramoops_get_next_prz (struct persistent_ram_zone *przs[],uint *c, -u64 *id,enum pstore_type_id *typep,bool update) +struct pstore_record *record,bool update) {struct persistent_ram_zone *prz;int i = (*c)++;fs/pstore/ram.c ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, · line 149
Quoted 7 lines
fs/pstore/ram.c +2
-2@@ -145,8 +145,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c,if (!persistent_ram_old_size (prz))return NULL ; - *typep = prz->type; - *id = i; + record->type = prz->type; + record->id = i;Yes yes. I've been meaning to get all this cleaned up after I refactored everything to actually HAVE record at all. :P
fs/pstore/ram.c static ssize_t ramoops_pstore_read(struct pstore_record *record) · line 257
Quoted 9 lines
fs/pstore/ram.c +1
-1return prz; }@@ -254,7 +254,7 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, - &record->id, &record->type,1 ); + record,1 );In another patch, I think you could drop the "update" field too, and use the
record->typeinstead to determine if update is needed. Like:
Quoted 6 lines
static struct
persistent_ram_zone* ramoops_get_next_prz(structpersistent_ram_zone*przs[], uint c,
structpstore_record*record){ bool update = (record->type == PSTORE_TYPE_DMESG);...
Yes, I agree, I'll do that :)
thanks!
- Joel
RFC 5/6 pstore: donot treat empty buffers as valid
In reply to Joel Fernandes (Google)pstore currently calls persistent_ram_save_old even if a buffer is empty. While this appears to work, it is simply not the right thing to do and could lead to bugs so lets avoid that. It also prevent misleading prints in the logs which claim the buffer is valid.
--- fs/pstore/ram_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/pstore/ram_core.c +1 -1
@@ -495,7 +495,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, sig ^=PERSISTENT_RAM_SIG ; -if (prz->buffer->sig == sig) { +if (prz->buffer->sig == sig &&buffer_size (prz)) {if (buffer_size (prz) > prz->buffer_size ||buffer_start (prz) >buffer_size (prz)) pr_info("found existing invalid buffer, size %zu, start %zu\n",
Signature · 1 line
2.19.1.568.g152ad8e336-goog
Re: [RFC 5/6] pstore: donot treat empty buffers as valid
Quoted 4 lines · Joel Fernandes (Google)
pstore currently calls
persistent_ram_save_oldeven if a buffer is empty. While this appears to work, it is simply not the right thing to do and could lead to bugs so lets avoid that. It also prevent misleading prints in the logs which claim the buffer is valid.
I need to be better convinced that a present zero length record is the same as a non-present record. This seems true, but there is potentially still metadata available from a backend. What were the misleading prints in logs?
-Kees
Quoted 22 lines
Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/ram_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/pstore/ram_core.c +1
-2@@ -495,7 +495,7 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig, sig ^=PERSISTENT_RAM_SIG ; -if (prz->buffer->sig == sig) { +if (prz->buffer->sig == sig &&buffer_size (prz)) {if (buffer_size (prz) > prz->buffer_size ||buffer_start (prz) >buffer_size (prz)) pr_info("found existing invalid buffer, size %zu, start %zu\n", --2.19.1.568.g152ad8e336-goog
Signature · 1 line
Kees Cook
Re: [RFC 5/6] pstore: donot treat empty buffers as valid
Quoted 11 lines · Kees Cook
Quoted 4 lines · Joel Fernandes (Google)
pstore currently calls
persistent_ram_save_oldeven if a buffer is empty. While this appears to work, it is simply not the right thing to do and could lead to bugs so lets avoid that. It also prevent misleading prints in the logs which claim the buffer is valid.I need to be better convinced that a present zero length record is the same as a non-present record. This seems true, but there is potentially still metadata available from a backend. What were the misleading prints in logs?
I got something like:
found existing buffer, size 0, start 0
When I was expecting:
no valid data in buffer (sig = ...)
The other thing is a call to persistent_ram_zap is also prevented on the buffer, which prevent zero-initialize prz->ecc_info.par. Since we are dropping patch 6/6, the zap will not happen. But I'm not super familiar with the ecc bits of this code to say that if that's an issue.
About the present zero-length record, I would argue that it should not be "present" at all. When the system first boots, the record is not present but the signatures are initialized, then on reboots because the signatures were initialized, the buffer appears as valid even if it was unused. So for dmesg, all the max_dump_cnt number of buffers would appear as if they are valid which is a bit strange because there was no crash at all so it should be in the same state on reboot, as if there was no crash. That could be a matter of perspective though so I leave it you how you prefer to do it :)
thanks,
- Joel
RFC 6/6 Revert "pstore/ram_core: Do not reset restored zone's position and size"
In reply to Joel Fernandes (Google)This reverts commit 25b63da64708212985c06c7f8b089d356efdd9cf.
Due to the commit which is being reverted here, it is not possible to know if pstore's messages were from a previous boot, or from very old boots. This creates an awkard situation where its unclear if crash or other logs are from the previous boot or from very old boots. Also typically we dump the pstore buffers after one reboot and are interested in only the previous boot's crash so let us reset the buffer after we save them.
Lastly, if we don't zap them, then I think it is possible that part of the buffer will be from this boot and the other parts will be from previous boots. So this revert fixes all of this by calling persistent_ram_zap always.
--- fs/pstore/ram_core.c | 1 - 1 file changed, 1 deletion(-)
fs/pstore/ram_core.c +0 -1
@@ -504,7 +504,6 @@ static int persistent_ram_post_init(struct persistent_ram_zone *prz, u32 sig,pr_debug ("found existing buffer, size %zu, start %zu\n" ,buffer_size (prz),buffer_start (prz));persistent_ram_save_old (prz); -return 0 ; } }else { pr_debug("no valid data in buffer (sig = 0x%08x)\n",
Signature · 1 line
2.19.1.568.g152ad8e336-goog
Re: [RFC 6/6] Revert "pstore/ram_core: Do not reset restored zone's position and size"
Quoted 10 lines · Joel Fernandes (Google)
This reverts commit
25b63da64708212985c06c7f8b089d356efdd9cf.Due to the commit which is being reverted here, it is not possible to know if pstore's messages were from a previous boot, or from very old boots. This creates an awkard situation where its unclear if crash or other logs are from the previous boot or from very old boots. Also typically we dump the pstore buffers after one reboot and are interested in only the previous boot's crash so let us reset the buffer after we save them.
Quoted 4 lines
Lastly, if we don't zap them, then I think it is possible that part of the buffer will be from this boot and the other parts will be from previous boots. So this revert fixes all of this by calling
persistent_ram_zapalways.
I like the other patches (comments coming), but not this one: it's very intentional to keep all crashes around until they're explicitly unlinked from the pstore filesystem from userspace. Especially true for catching chains of kernel crashes, or a failed log collection, etc. Surviving multiple reboots is the expected behavior on Chrome OS too.
Signature · 1 line
Kees Cook
Re: [RFC 6/6] Revert "pstore/ram_core: Do not reset restored zone's position and size"
Quoted 17 lines · Kees Cook
Quoted 10 lines · Joel Fernandes (Google)
This reverts commit
25b63da64708212985c06c7f8b089d356efdd9cf.Due to the commit which is being reverted here, it is not possible to know if pstore's messages were from a previous boot, or from very old boots. This creates an awkard situation where its unclear if crash or other logs are from the previous boot or from very old boots. Also typically we dump the pstore buffers after one reboot and are interested in only the previous boot's crash so let us reset the buffer after we save them.
Quoted 4 lines
Lastly, if we don't zap them, then I think it is possible that part of the buffer will be from this boot and the other parts will be from previous boots. So this revert fixes all of this by calling
persistent_ram_zapalways.
Quoted 6 lines
I like the other patches (comments coming), but not this one: it's very intentional to keep all crashes around until they're explicitly unlinked from the pstore filesystem from userspace. Especially true for catching chains of kernel crashes, or a failed log collection, etc. Surviving multiple reboots is the expected behavior on Chrome OS too.
Oh, ok. Hence the RFC tag ;-) We can drop this one then. I forgot that unlinking was another way to clear the logs.
thanks!
- Joel
Re: [RFC 6/6] Revert "pstore/ram_core: Do not reset restored zone's position and size"
Quoted 25 lines · Joel Fernandes
Quoted 17 lines · Kees Cook
Quoted 10 lines · Joel Fernandes (Google)
This reverts commit
25b63da64708212985c06c7f8b089d356efdd9cf.Due to the commit which is being reverted here, it is not possible to know if pstore's messages were from a previous boot, or from very old boots. This creates an awkard situation where its unclear if crash or other logs are from the previous boot or from very old boots. Also typically we dump the pstore buffers after one reboot and are interested in only the previous boot's crash so let us reset the buffer after we save them.
Quoted 4 lines
Lastly, if we don't zap them, then I think it is possible that part of the buffer will be from this boot and the other parts will be from previous boots. So this revert fixes all of this by calling
persistent_ram_zapalways.Quoted 6 lines
I like the other patches (comments coming), but not this one: it's very intentional to keep all crashes around until they're explicitly unlinked from the pstore filesystem from userspace. Especially true for catching chains of kernel crashes, or a failed log collection, etc. Surviving multiple reboots is the expected behavior on Chrome OS too.
Quoted 2 lines
Oh, ok. Hence the RFC tag ;-) We can drop this one then. I forgot that unlinking was another way to clear the logs.
In another thread I discovered that the "single prz" ones actually _are_ zapped at boot. I didn't realize, but it explains why pmsg would vanish on me sometimes. ;) I always thought I was just doing something wrong with it. (And I wonder if it's actually a bug that pmsg is zapped -- console doesn't matter: it's overwritten every boot by design.)
Signature · 1 line
Kees Cook
Re: [RFC 6/6] Revert "pstore/ram_core: Do not reset restored zone's position and size"
Quoted 29 lines · Kees Cook
Quoted 25 lines · Joel Fernandes
Quoted 17 lines · Kees Cook
Quoted 10 lines · Joel Fernandes (Google)
This reverts commit
25b63da64708212985c06c7f8b089d356efdd9cf.Due to the commit which is being reverted here, it is not possible to know if pstore's messages were from a previous boot, or from very old boots. This creates an awkard situation where its unclear if crash or other logs are from the previous boot or from very old boots. Also typically we dump the pstore buffers after one reboot and are interested in only the previous boot's crash so let us reset the buffer after we save them.
Quoted 4 lines
Lastly, if we don't zap them, then I think it is possible that part of the buffer will be from this boot and the other parts will be from previous boots. So this revert fixes all of this by calling
persistent_ram_zapalways.Quoted 6 lines
I like the other patches (comments coming), but not this one: it's very intentional to keep all crashes around until they're explicitly unlinked from the pstore filesystem from userspace. Especially true for catching chains of kernel crashes, or a failed log collection, etc. Surviving multiple reboots is the expected behavior on Chrome OS too.
Quoted 2 lines
Oh, ok. Hence the RFC tag ;-) We can drop this one then. I forgot that unlinking was another way to clear the logs.
Quoted 6 lines
In another thread I discovered that the "single prz" ones actually _are_ zapped at boot. I didn't realize, but it explains why pmsg would vanish on me sometimes. ;) I always thought I was just doing something wrong with it. (And I wonder if it's actually a bug that pmsg is zapped -- console doesn't matter: it's overwritten every boot by design.)
Oh yeah they are. So seems like some are zapped on boot and some aren't then. Hmm, I would think it makes sense not to boot-zap dmesg ever, since that's crash logs someone may want to see after many reboots. But console and pmsg should be since those just "what happened on the last boot". I guess it should be made clear in some structure or something which types are zapped on boot, and which ones aren't. That'll make it clear when adding a new type about that behavior, instead of relying on the assumption that single prz are zapped and multiple ones aren't. Like for ftrace, since the per-cpu configuration was added, it will now be zapped on boot if it is using a per-cpu configuration and not zapped on boot if it isn't right? That would seem a bit inconsistent.
thanks!
-Joel
Quoted 4 lines · Joel Fernandes (Google)
In later patches we will need to map types to names, so create a table for that which can also be used and reused in different parts of old and new code. Also use it to save the type in the PRZ which will be useful in later patches.
Yes, I like it. :) Comments below...
Quoted 22 lines
Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/inode.c | 44 ++++++++++++++++++++------------------ fs/pstore/ram.c | 4 +++- include/linux/pstore.h | 29 +++++++++++++++++++++++++ include/linux/pstore_ram.h | 2 ++ 4 files changed, 57 insertions(+), 22 deletions(-)fs/pstore/inode.c +1
-0@@ -304,6 +304,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)struct dentry *dentry;struct inode *inode;int rc =0 ; +enum pstore_type_id type;char name[PSTORE_NAMELEN ];struct pstore_private *private, *pos;unsigned long flags;
fs/pstore/inode.c int pstore_mkfile(struct dentry *root, struct pstore_record *record) · line 339
Quoted 5 lines
fs/pstore/inode.c +1
-1@@ -335,43 +336,44 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) goto fail_alloc; private->record = record; -switch (record->type) { + type = record->type;
Let's rename PSTORE_TYPE_UNKNOWN in the enum to be PSTORE_TYPE_MAX and != 255 (just leave it at the end). The value is never exposed to userspace (nor to backend storage), so we can instead use it as the bounds-check for doing type -> name mappings. (The one use in erst can just be renamed.)
Then we can add a function to do the bounds checking and mapping (instead of using a bare array lookup).
Quoted 49 lines
fs/pstore/inode.c +17
-17+switch (type) {case PSTORE_TYPE_DMESG : -scnprintf (name,sizeof (name),"dmesg-%s-%llu%s" , - record->psi->name, record->id, - record->compressed ?".enc.z" :"" ); +scnprintf (name,sizeof (name),"%s-%s-%llu%s" , + pstore_names[type], record->psi->name, record->id, + record->compressed ?".enc.z" :"" );break ;case PSTORE_TYPE_CONSOLE : -scnprintf (name,sizeof (name),"console-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_FTRACE : -scnprintf (name,sizeof (name),"ftrace-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_MCE : -scnprintf (name,sizeof (name),"mce-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_RTAS : -scnprintf (name,sizeof (name),"rtas-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OF : -scnprintf (name,sizeof (name),"powerpc-ofw-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_COMMON : -scnprintf (name,sizeof (name),"powerpc-common-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PMSG : -scnprintf (name,sizeof (name),"pmsg-%s-%llu" , - record->psi->name, record->id); + scnprintf(name, sizeof(name), "%s-%s-%llu",
fs/pstore/inode.c int pstore_mkfile(struct dentry *root, struct pstore_record *record) · line 379
Quoted 10 lines
fs/pstore/inode.c +3
-2+ pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OPAL : -scnprintf (name,sizeof (name),"powerpc-opal-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_UNKNOWN : scnprintf(name, sizeof(name), "unknown-%s-%llu",
All of these, including PSTORE_TYPE_UNKNOWN are now identical (you can include the .enc.z logic in for all of them. I think the entire switch can be dropped, yes?
scnprintf(name, sizeof(name), "%s-%s-%llu%s",
pstore_name(record->type), record->psi->name, record->id,
record->compressed ? ".enc.z" : "")Quoted 30 lines
fs/pstore/inode.c +1
-1@@ -379,7 +381,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)break ;default :scnprintf (name,sizeof (name),"type%d-%s-%llu" , - record->type, record->psi->name, record->id); + type, record->psi->name, record->id);break ; }fs/pstore/ram.c +2
-0@@ -604,6 +604,7 @@ static int ramoops_init_przs(const char *name, goto fail; } *paddr += zone_sz; + prz_ar[i]->type =pstore_name_to_type (name); } *przs = prz_ar;@@ -642,6 +643,7 @@ static int ramoops_init_prz(const char *name,persistent_ram_zap (*prz); *paddr += sz; + (*prz)->type =pstore_name_to_type (name);return 0 ; }
fs/pstore/ram.c static int ramoops_probe(struct platform_device *pdev) · line 782
Quoted 5 lines
fs/pstore/ram.c +1
-1@@ -777,7 +779,7 @@ static int ramoops_probe(struct platform_device *pdev) dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size - cxt->pmsg_size; - err = ramoops_init_przs("dump", dev, cxt, &cxt->dprzs, &paddr, + err = ramoops_init_przs("dmesg", dev, cxt, &cxt->dprzs, &paddr,
Yup. That's a funny mismatch. Not exposed to userspace in a released kernel. ;)
include/linux/pstore.h enum pstore_type_id { · line 51
Quoted 13 lines
fs/pstore/ram.c +0
-0dump_mem_sz, cxt->record_size, &cxt->max_dump_cnt, 0, 0);if (err)include/linux/pstore.h +2
-0@@ -47,6 +47,21 @@ enum pstore_type_id {PSTORE_TYPE_UNKNOWN =255 }; +/* names should be in the same order as the above table */ +static char __maybe_unused *pstore_names[] = {
This should be static const char * const pstore_names[], I think?
include/linux/pstore.h enum pstore_type_id { · line 62
Quoted 11 lines
include/linux/pstore.h +11
-0+"dmesg" , +"mce" , +"console" , +"ftrace" , +"rtas" , +"powerpc-ofw" , +"powerpc-common" , +"pmsg" , +"powerpc-opal" , +"event" , + "unknown", /* unknown should be the last string */
End this with a NULL for a cheaper compare below.
Quoted 6 lines
include/linux/pstore.h +2
-0+}; +struct pstore_info ;/** * struct pstore_record - details of a pstore record entry
include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 297
Quoted 9 lines
include/linux/pstore.h +6
-0@@ -274,4 +289,18 @@ pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) }#endif +static inline enum pstore_type_id pstore_name_to_type (const char *name) +{ +char *str; +int i =0 ; + +for (;strncmp (pstore_names[i],"unknown" ,7 ); i++) {
char **ptr;
for (ptr = pstores_names; *ptr; ptr++) {
include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 299
Quoted 2 lines
include/linux/pstore.h +2
-0+ str = pstore_names[i]; +if (!strncmp (name, str,strlen (str)))
"n" version not needed: the LHS is controlled and we want full matching:
if (!strcmp(*ptr, name))
include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 300
Quoted 1 line
include/linux/pstore.h +1
-0+return (enum pstore_type_id )i;
I don't think this cast is needed?
return (ptr - pstores_names);
Quoted 29 lines
include/linux/pstore.h +5
-0+ } + +return PSTORE_TYPE_UNKNOWN ; +} +#endif /*_LINUX_PSTORE_H*/ include/linux/pstore_ram.h +2
-1@@ -22,6 +22,7 @@#include <linux/init.h> #include <linux/kernel.h> #include <linux/list.h> +#include <linux/pstore.h> #include <linux/types.h> /* @@ -47,6 +48,7 @@ struct persistent_ram_zone {size_t size;void *vaddr;struct persistent_ram_buffer *buffer; +enum pstore_type_id type;size_t buffer_size;u32 flags;raw_spinlock_t buffer_lock; --2.19.1.568.g152ad8e336-goog
Signature · 1 line
Kees Cook
Quoted 8 lines · Kees Cook
Quoted 4 lines · Joel Fernandes (Google)
In later patches we will need to map types to names, so create a table for that which can also be used and reused in different parts of old and new code. Also use it to save the type in the PRZ which will be useful in later patches.
Yes, I like it. :) Comments below...
I'm glad, thanks, my replies are below:
Quoted 96 lines
Quoted 21 lines
Signed-off-by Joel Fernandes (Google) <[email protected]>--- fs/pstore/inode.c | 44 ++++++++++++++++++++------------------ fs/pstore/ram.c | 4 +++- include/linux/pstore.h | 29 +++++++++++++++++++++++++ include/linux/pstore_ram.h | 2 ++ 4 files changed, 57 insertions(+), 22 deletions(-)fs/pstore/inode.c +1
-0@@ -304,6 +304,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)struct dentry *dentry;struct inode *inode;int rc =0 ; +enum pstore_type_id type;char name[PSTORE_NAMELEN ];struct pstore_private *private, *pos;unsigned long flags;fs/pstore/inode.c int pstore_mkfile(struct dentry *root, struct pstore_record *record) · line 339
Quoted 5 lines
fs/pstore/inode.c +1
-1@@ -335,43 +336,44 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) goto fail_alloc; private->record = record; -switch (record->type) { + type = record->type;Let's rename
PSTORE_TYPE_UNKNOWNin the enum to bePSTORE_TYPE_MAXand != 255 (just leave it at the end). The value is never exposed to userspace (nor to backend storage), so we can instead use it as the bounds-check for doing type -> name mappings. (The one use in erst can just be renamed.)Then we can add a function to do the bounds checking and mapping (instead of using a bare array lookup).
Quoted 49 lines
fs/pstore/inode.c +17
-17+switch (type) {case PSTORE_TYPE_DMESG : -scnprintf (name,sizeof (name),"dmesg-%s-%llu%s" , - record->psi->name, record->id, - record->compressed ?".enc.z" :"" ); +scnprintf (name,sizeof (name),"%s-%s-%llu%s" , + pstore_names[type], record->psi->name, record->id, + record->compressed ?".enc.z" :"" );break ;case PSTORE_TYPE_CONSOLE : -scnprintf (name,sizeof (name),"console-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_FTRACE : -scnprintf (name,sizeof (name),"ftrace-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_MCE : -scnprintf (name,sizeof (name),"mce-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_RTAS : -scnprintf (name,sizeof (name),"rtas-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OF : -scnprintf (name,sizeof (name),"powerpc-ofw-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_COMMON : -scnprintf (name,sizeof (name),"powerpc-common-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PMSG : -scnprintf (name,sizeof (name),"pmsg-%s-%llu" , - record->psi->name, record->id); + scnprintf(name, sizeof(name), "%s-%s-%llu",fs/pstore/inode.c int pstore_mkfile(struct dentry *root, struct pstore_record *record) · line 379
Quoted 10 lines
fs/pstore/inode.c +3
-2+ pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_PPC_OPAL : -scnprintf (name,sizeof (name),"powerpc-opal-%s-%llu" , - record->psi->name, record->id); +scnprintf (name,sizeof (name),"%s-%s-%llu" , + pstore_names[type], record->psi->name, record->id);break ;case PSTORE_TYPE_UNKNOWN : scnprintf(name, sizeof(name), "unknown-%s-%llu",
Quoted 7 lines
All of these, including
PSTORE_TYPE_UNKNOWNare now identical (you can include the .enc.z logic in for all of them. I think the entire switch can be dropped, yes?scnprintf(name, sizeof(name), "%s-%s-%llu%s",
pstore_name(record->type), record->psi->name, record->id, record->compressed ? ".enc.z" : "")
True! I'll just do that. Sounds good! The PSTORE_TYPE_UNKNOWN and the below "default:" case could be combined I guessed. Its a great idea and lesser lines, thanks!
Quoted 11 lines
Quoted 11 lines
dump_mem_sz, cxt->record_size, &cxt->max_dump_cnt, 0, 0); if (err)include/linux/pstore.h +0
-0@@ -47,6 +47,21 @@ enum pstore_type_id { PSTORE_TYPE_UNKNOWN = 255 };
Quoted 4 lines
include/linux/pstore.h enum pstore_type_id { · line 51
Quoted 2 lines
include/linux/pstore.h +2
-0+/* names should be in the same order as the above table */ +static char __maybe_unused *pstore_names[] = {This should be static const char * const pstore_names[], I think?
Sure, I'll add the const(s) to it.
Quoted 12 lines
include/linux/pstore.h enum pstore_type_id { · line 62
Quoted 11 lines
include/linux/pstore.h +11
-0+"dmesg" , +"mce" , +"console" , +"ftrace" , +"rtas" , +"powerpc-ofw" , +"powerpc-common" , +"pmsg" , +"powerpc-opal" , +"event" , + "unknown", /* unknown should be the last string */
Quoted 1 line
End this with a NULL for a cheaper compare below.
Agreed, I am wondering if we need the unknown string though if we terminate the type enum table with a MAX. I'll look more into that.
Quoted 17 lines
Quoted 6 lines
include/linux/pstore.h +2
-0+}; +struct pstore_info ;/** * struct pstore_record - details of a pstore record entry include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 297
Quoted 9 lines
include/linux/pstore.h +6
-0@@ -274,4 +289,18 @@ pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) }#endif +static inline enum pstore_type_id pstore_name_to_type (const char *name) +{ +char *str; +int i =0 ; + +for (;strncmp (pstore_names[i],"unknown" ,7 ); i++) {char **ptr;
Quoted 8 lines
for (ptr =
pstores_names; *ptr; ptr++) {include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 299
Quoted 2 lines
include/linux/pstore.h +2
-0+ str = pstore_names[i]; +if (!strncmp (name, str,strlen (str)))"n" version not needed: the LHS is controlled and we want full matching:
if (!strcmp(*ptr, name))
Sounds good, but now that we are adding PSTORE_TYPE_MAX, I think it would be cleaner and safer if I iterated until PSTORE_TYPE_MAX, so I'll use that to terminate the loop?
Quoted 5 lines
include/linux/pstore.h pstore_ftrace_write_timestamp(struct pstore_ftrace_record *rec, u64 val) · line 300
Quoted 1 line
include/linux/pstore.h +1
-0+return (enum pstore_type_id )i;I don't think this cast is needed?
return (ptr - pstores_names);
But I have the index variable, so it would be cleaner to just return that? I believe I can just drop the cast and do that.
thanks,
- Joel
Quoted 2 lines · Joel Fernandes
But I have the index variable, so it would be cleaner to just return that? I believe I can just drop the cast and do that.
Yeah, that should be fine.
Signature · 1 line
Kees Cook