linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v2 0/3] cleanups for pstore and ramoops
@ 2018-11-03 23:38 Joel Fernandes (Google)
  2018-11-03 23:38 ` [PATCH RFC v2 1/3] pstore: map pstore types to names Joel Fernandes (Google)
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Joel Fernandes (Google) @ 2018-11-03 23:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Joel Fernandes (Google),
	Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck

Here are some simple cleanups and fixes for ramoops in pstore. Let me know
what you think, thanks.

Joel Fernandes (Google) (3):
pstore: map pstore types to names
pstore: simplify ramoops_get_next_prz arguments
pstore: donot treat empty buffers as valid

fs/pstore/inode.c          | 53 +++++---------------------------------
fs/pstore/ram.c            | 52 +++++++++++++++----------------------
fs/pstore/ram_core.c       |  2 +-
include/linux/pstore.h     | 37 ++++++++++++++++++++++++++
include/linux/pstore_ram.h |  2 ++
5 files changed, 67 insertions(+), 79 deletions(-)

--
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH RFC v2 1/3] pstore: map pstore types to names
  2018-11-03 23:38 [PATCH RFC v2 0/3] cleanups for pstore and ramoops Joel Fernandes (Google)
@ 2018-11-03 23:38 ` Joel Fernandes (Google)
  2018-11-05  4:46   ` Joel Fernandes
  2018-11-03 23:38 ` [PATCH RFC v2 2/3] pstore: simplify ramoops_get_next_prz arguments Joel Fernandes (Google)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Joel Fernandes (Google) @ 2018-11-03 23:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Joel Fernandes (Google),
	Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck

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.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 fs/pstore/inode.c          | 53 +++++---------------------------------
 fs/pstore/ram.c            |  4 ++-
 include/linux/pstore.h     | 37 ++++++++++++++++++++++++++
 include/linux/pstore_ram.h |  2 ++
 4 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 8cf2218b46a7..c5c6b8b4b70a 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -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,53 +336,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
 		goto fail_alloc;
 	private->record = record;
 
-	switch (record->type) {
-	case PSTORE_TYPE_DMESG:
-		scnprintf(name, sizeof(name), "dmesg-%s-%llu%s",
-			  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);
-		break;
-	case PSTORE_TYPE_FTRACE:
-		scnprintf(name, sizeof(name), "ftrace-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_MCE:
-		scnprintf(name, sizeof(name), "mce-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_RTAS:
-		scnprintf(name, sizeof(name), "rtas-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_OF:
-		scnprintf(name, sizeof(name), "powerpc-ofw-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_COMMON:
-		scnprintf(name, sizeof(name), "powerpc-common-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PMSG:
-		scnprintf(name, sizeof(name), "pmsg-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_OPAL:
-		scnprintf(name, sizeof(name), "powerpc-opal-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_UNKNOWN:
-		scnprintf(name, sizeof(name), "unknown-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	default:
-		scnprintf(name, sizeof(name), "type%d-%s-%llu",
-			  record->type, record->psi->name, record->id);
-		break;
-	}
+	scnprintf(name, sizeof(name), "%s-%s-%llu%s",
+			pstore_type_to_name(record->type),
+			record->psi->name, record->id,
+			(record->type == PSTORE_TYPE_DMESG
+			 && record->compressed) ? ".enc.z" : "");
 
 	dentry = d_alloc_name(root, name);
 	if (!dentry)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 10ac4d23c423..b174d0fc009f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -611,6 +611,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;
@@ -650,6 +651,7 @@ static int ramoops_init_prz(const char *name,
 	}
 
 	*paddr += sz;
+	(*prz)->type = pstore_name_to_type(name);
 
 	return 0;
 }
@@ -785,7 +787,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)
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index f46e5df76b58..caeeda0bbab3 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -44,9 +44,46 @@ enum pstore_type_id {
 	PSTORE_TYPE_PPC_COMMON	= 6,
 	PSTORE_TYPE_PMSG	= 7,
 	PSTORE_TYPE_PPC_OPAL	= 8,
+	PSTORE_TYPE_MAX		= 9,
+	/* UNKNOWN returned from pstore_name_to_type if no type found */
 	PSTORE_TYPE_UNKNOWN	= 255
 };
 
+/* names should be in the same order as the above table */
+static const char __maybe_unused *__pstore_type_names[] = {
+	"dmesg",
+	"mce",
+	"console",
+	"ftrace",
+	"rtas",
+	"powerpc-ofw",
+	"powerpc-common",
+	"pmsg",
+	"powerpc-opal",
+	"event",
+};
+
+static const char *pstore_type_to_name(enum pstore_type_id type)
+{
+	if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX))
+		return "unknown";
+
+	return __pstore_type_names[type];
+}
+
+static inline enum pstore_type_id pstore_name_to_type(const char *name)
+{
+	int i;
+
+	for (i = 0; i < PSTORE_TYPE_MAX; i++) {
+		const char *str = pstore_type_to_name(i);
+		if (!strcmp(str, name))
+			return i;
+	}
+
+	return PSTORE_TYPE_UNKNOWN;
+}
+
 struct pstore_info;
 /**
  * struct pstore_record - details of a pstore record entry
diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h
index 5d10ad51c1c4..5af72b155ad8 100644
--- a/include/linux/pstore_ram.h
+++ b/include/linux/pstore_ram.h
@@ -22,6 +22,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/pstore.h>
 #include <linux/types.h>
 
 /*
@@ -92,6 +93,7 @@ struct persistent_ram_zone {
 
 	raw_spinlock_t buffer_lock;
 	struct persistent_ram_buffer *buffer;
+	enum pstore_type_id type;
 	size_t buffer_size;
 
 	char *par_buffer;
-- 
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH RFC v2 2/3] pstore: simplify ramoops_get_next_prz arguments
  2018-11-03 23:38 [PATCH RFC v2 0/3] cleanups for pstore and ramoops Joel Fernandes (Google)
  2018-11-03 23:38 ` [PATCH RFC v2 1/3] pstore: map pstore types to names Joel Fernandes (Google)
@ 2018-11-03 23:38 ` Joel Fernandes (Google)
  2018-11-03 23:38 ` [PATCH RFC v2 3/3] pstore: donot treat empty buffers as valid Joel Fernandes (Google)
  2018-11-14  7:14 ` [PATCH RFC v2 0/3] cleanups for pstore and ramoops Kees Cook
  3 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes (Google) @ 2018-11-03 23:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Joel Fernandes (Google),
	Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck

(1) 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.

(2) remove max argument from ramoops_get_next_prz

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.

(3) further reduce ramoops_get_next_prz arguments by passing record

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.

In addition lets also remove the 'update' argument since we can detect
that. Changes are squashed into a single patch to reduce fixup conflicts.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 fs/pstore/ram.c | 48 ++++++++++++++++++------------------------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index b174d0fc009f..202eaa82bcc6 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -124,19 +124,17 @@ 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)
+ramoops_get_next_prz(struct persistent_ram_zone *przs[], int id,
+		     struct pstore_record *record)
 {
 	struct persistent_ram_zone *prz;
-	int i = (*c)++;
+	bool update = (record->type == PSTORE_TYPE_DMESG);
 
 	/* Give up if we never existed or have hit the end. */
-	if (!przs || i >= max)
+	if (!przs)
 		return NULL;
 
-	prz = przs[i];
+	prz = przs[id];
 	if (!prz)
 		return NULL;
 
@@ -147,8 +145,8 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max,
 	if (!persistent_ram_old_size(prz))
 		return NULL;
 
-	*typep = type;
-	*id = i;
+	record->type = prz->type;
+	record->id = id;
 
 	return prz;
 }
@@ -255,10 +253,8 @@ 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,
-					   PSTORE_TYPE_DMESG, 1);
+		prz = ramoops_get_next_prz(cxt->dprzs, cxt->dump_read_cnt++,
+					   record);
 		if (!prz_ok(prz))
 			continue;
 		header_length = ramoops_read_kmsg_hdr(persistent_ram_old(prz),
@@ -272,22 +268,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);
+	if (!prz_ok(prz) && !cxt->console_read_cnt++)
+		prz = ramoops_get_next_prz(&cxt->cprz, 0 /* single */, record);
 
-	if (!prz_ok(prz))
-		prz = ramoops_get_next_prz(&cxt->mprz, &cxt->pmsg_read_cnt,
-					   1, &record->id, &record->type,
-					   PSTORE_TYPE_PMSG, 0);
+	if (!prz_ok(prz) && !cxt->pmsg_read_cnt++)
+		prz = ramoops_get_next_prz(&cxt->mprz, 0 /* single */, record);
 
 	/* 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);
+		if (!(cxt->flags & RAMOOPS_FLAG_FTRACE_PER_CPU) &&
+		    !cxt->ftrace_read_cnt++) {
+			prz = ramoops_get_next_prz(cxt->fprzs, 0 /* single */,
+						   record);
 		} else {
 			/*
 			 * Build a new dummy record which combines all the
@@ -303,11 +295,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,
-						cxt->max_ftrace_cnt,
-						&record->id,
-						&record->type,
-						PSTORE_TYPE_FTRACE, 0);
+						cxt->ftrace_read_cnt++, record);
 
 				if (!prz_ok(prz_next))
 					continue;
-- 
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH RFC v2 3/3] pstore: donot treat empty buffers as valid
  2018-11-03 23:38 [PATCH RFC v2 0/3] cleanups for pstore and ramoops Joel Fernandes (Google)
  2018-11-03 23:38 ` [PATCH RFC v2 1/3] pstore: map pstore types to names Joel Fernandes (Google)
  2018-11-03 23:38 ` [PATCH RFC v2 2/3] pstore: simplify ramoops_get_next_prz arguments Joel Fernandes (Google)
@ 2018-11-03 23:38 ` Joel Fernandes (Google)
  2018-11-14  7:14 ` [PATCH RFC v2 0/3] cleanups for pstore and ramoops Kees Cook
  3 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes (Google) @ 2018-11-03 23:38 UTC (permalink / raw)
  To: linux-kernel
  Cc: Joel Fernandes (Google),
	Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck

pstore currently calls persistent_ram_save_old even if a buffer is
empty. While this appears to work, it is does not seem like the right
thing to do and could lead to future bugs so lets avoid that. It also
prevent misleading prints in the logs which claim the buffer is valid.

I got something like:
found existing buffer, size 0, start 0

When I was expecting:
no valid data in buffer (sig = ...)

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
Note that if you feel this patch is not necessary, then feel free to
drop it. I would say it is harmless and is a good clean up.

 fs/pstore/ram_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index e6375439c5ac..196e4fd7ba8c 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -510,7 +510,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.930.g4563a0d9d0-goog

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH RFC v2 1/3] pstore: map pstore types to names
  2018-11-03 23:38 ` [PATCH RFC v2 1/3] pstore: map pstore types to names Joel Fernandes (Google)
@ 2018-11-05  4:46   ` Joel Fernandes
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes @ 2018-11-05  4:46 UTC (permalink / raw)
  To: linux-kernel; +Cc: Anton Vorontsov, Colin Cross, Kees Cook, Tony Luck

On Sat, Nov 03, 2018 at 04:38:16PM -0700, Joel Fernandes (Google) wrote:
> 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.
> 
> Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
> ---
>  fs/pstore/inode.c          | 53 +++++---------------------------------
>  fs/pstore/ram.c            |  4 ++-
>  include/linux/pstore.h     | 37 ++++++++++++++++++++++++++
>  include/linux/pstore_ram.h |  2 ++
>  4 files changed, 48 insertions(+), 48 deletions(-)

The original patch had an unused variable warning, below is the updated one.
Sorry about that and thanks!

---8<-----------------------

From de981d893c5c09c62c7c6d5fc9fe73cfd99ffa48 Mon Sep 17 00:00:00 2001
From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
Date: Sat, 3 Nov 2018 16:10:12 -0700
Subject: [PATCH RFC v3 1/3] 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.

Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 fs/pstore/inode.c          | 52 ++++----------------------------------
 fs/pstore/ram.c            |  4 ++-
 include/linux/pstore.h     | 37 +++++++++++++++++++++++++++
 include/linux/pstore_ram.h |  2 ++
 4 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 8cf2218b46a7..4a259fd22df0 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -335,53 +335,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
 		goto fail_alloc;
 	private->record = record;
 
-	switch (record->type) {
-	case PSTORE_TYPE_DMESG:
-		scnprintf(name, sizeof(name), "dmesg-%s-%llu%s",
-			  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);
-		break;
-	case PSTORE_TYPE_FTRACE:
-		scnprintf(name, sizeof(name), "ftrace-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_MCE:
-		scnprintf(name, sizeof(name), "mce-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_RTAS:
-		scnprintf(name, sizeof(name), "rtas-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_OF:
-		scnprintf(name, sizeof(name), "powerpc-ofw-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_COMMON:
-		scnprintf(name, sizeof(name), "powerpc-common-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PMSG:
-		scnprintf(name, sizeof(name), "pmsg-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_PPC_OPAL:
-		scnprintf(name, sizeof(name), "powerpc-opal-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	case PSTORE_TYPE_UNKNOWN:
-		scnprintf(name, sizeof(name), "unknown-%s-%llu",
-			  record->psi->name, record->id);
-		break;
-	default:
-		scnprintf(name, sizeof(name), "type%d-%s-%llu",
-			  record->type, record->psi->name, record->id);
-		break;
-	}
+	scnprintf(name, sizeof(name), "%s-%s-%llu%s",
+			pstore_type_to_name(record->type),
+			record->psi->name, record->id,
+			(record->type == PSTORE_TYPE_DMESG
+			 && record->compressed) ? ".enc.z" : "");
 
 	dentry = d_alloc_name(root, name);
 	if (!dentry)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 10ac4d23c423..b174d0fc009f 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -611,6 +611,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;
@@ -650,6 +651,7 @@ static int ramoops_init_prz(const char *name,
 	}
 
 	*paddr += sz;
+	(*prz)->type = pstore_name_to_type(name);
 
 	return 0;
 }
@@ -785,7 +787,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)
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index f46e5df76b58..caeeda0bbab3 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -44,9 +44,46 @@ enum pstore_type_id {
 	PSTORE_TYPE_PPC_COMMON	= 6,
 	PSTORE_TYPE_PMSG	= 7,
 	PSTORE_TYPE_PPC_OPAL	= 8,
+	PSTORE_TYPE_MAX		= 9,
+	/* UNKNOWN returned from pstore_name_to_type if no type found */
 	PSTORE_TYPE_UNKNOWN	= 255
 };
 
+/* names should be in the same order as the above table */
+static const char __maybe_unused *__pstore_type_names[] = {
+	"dmesg",
+	"mce",
+	"console",
+	"ftrace",
+	"rtas",
+	"powerpc-ofw",
+	"powerpc-common",
+	"pmsg",
+	"powerpc-opal",
+	"event",
+};
+
+static const char *pstore_type_to_name(enum pstore_type_id type)
+{
+	if (WARN_ON_ONCE(type >= PSTORE_TYPE_MAX))
+		return "unknown";
+
+	return __pstore_type_names[type];
+}
+
+static inline enum pstore_type_id pstore_name_to_type(const char *name)
+{
+	int i;
+
+	for (i = 0; i < PSTORE_TYPE_MAX; i++) {
+		const char *str = pstore_type_to_name(i);
+		if (!strcmp(str, name))
+			return i;
+	}
+
+	return PSTORE_TYPE_UNKNOWN;
+}
+
 struct pstore_info;
 /**
  * struct pstore_record - details of a pstore record entry
diff --git a/include/linux/pstore_ram.h b/include/linux/pstore_ram.h
index 5d10ad51c1c4..5af72b155ad8 100644
--- a/include/linux/pstore_ram.h
+++ b/include/linux/pstore_ram.h
@@ -22,6 +22,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/pstore.h>
 #include <linux/types.h>
 
 /*
@@ -92,6 +93,7 @@ struct persistent_ram_zone {
 
 	raw_spinlock_t buffer_lock;
 	struct persistent_ram_buffer *buffer;
+	enum pstore_type_id type;
 	size_t buffer_size;
 
 	char *par_buffer;
-- 
2.19.1.930.g4563a0d9d0-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH RFC v2 0/3] cleanups for pstore and ramoops
  2018-11-03 23:38 [PATCH RFC v2 0/3] cleanups for pstore and ramoops Joel Fernandes (Google)
                   ` (2 preceding siblings ...)
  2018-11-03 23:38 ` [PATCH RFC v2 3/3] pstore: donot treat empty buffers as valid Joel Fernandes (Google)
@ 2018-11-14  7:14 ` Kees Cook
  2018-11-15  2:20   ` Joel Fernandes
  3 siblings, 1 reply; 7+ messages in thread
From: Kees Cook @ 2018-11-14  7:14 UTC (permalink / raw)
  To: Joel Fernandes (Google); +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck

On Sat, Nov 3, 2018 at 6:38 PM, Joel Fernandes (Google)
<joel@joelfernandes.org> wrote:
> Here are some simple cleanups and fixes for ramoops in pstore. Let me know
> what you think, thanks.

I took these and slightly tweaked code locations for the first one.
I'll send out the series for review when I'm back from Plumber's.

-Kees

>
> Joel Fernandes (Google) (3):
> pstore: map pstore types to names
> pstore: simplify ramoops_get_next_prz arguments
> pstore: donot treat empty buffers as valid
>
> fs/pstore/inode.c          | 53 +++++---------------------------------
> fs/pstore/ram.c            | 52 +++++++++++++++----------------------
> fs/pstore/ram_core.c       |  2 +-
> include/linux/pstore.h     | 37 ++++++++++++++++++++++++++
> include/linux/pstore_ram.h |  2 ++
> 5 files changed, 67 insertions(+), 79 deletions(-)
>
> --
> 2.19.1.930.g4563a0d9d0-goog
>



-- 
Kees Cook

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH RFC v2 0/3] cleanups for pstore and ramoops
  2018-11-14  7:14 ` [PATCH RFC v2 0/3] cleanups for pstore and ramoops Kees Cook
@ 2018-11-15  2:20   ` Joel Fernandes
  0 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes @ 2018-11-15  2:20 UTC (permalink / raw)
  To: Kees Cook; +Cc: LKML, Anton Vorontsov, Colin Cross, Tony Luck

On Wed, Nov 14, 2018 at 01:14:57AM -0600, Kees Cook wrote:
> On Sat, Nov 3, 2018 at 6:38 PM, Joel Fernandes (Google)
> <joel@joelfernandes.org> wrote:
> > Here are some simple cleanups and fixes for ramoops in pstore. Let me know
> > what you think, thanks.
> 
> I took these and slightly tweaked code locations for the first one.
> I'll send out the series for review when I'm back from Plumber's.

Cool, thanks!

 - Joel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-11-15  2:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-03 23:38 [PATCH RFC v2 0/3] cleanups for pstore and ramoops Joel Fernandes (Google)
2018-11-03 23:38 ` [PATCH RFC v2 1/3] pstore: map pstore types to names Joel Fernandes (Google)
2018-11-05  4:46   ` Joel Fernandes
2018-11-03 23:38 ` [PATCH RFC v2 2/3] pstore: simplify ramoops_get_next_prz arguments Joel Fernandes (Google)
2018-11-03 23:38 ` [PATCH RFC v2 3/3] pstore: donot treat empty buffers as valid Joel Fernandes (Google)
2018-11-14  7:14 ` [PATCH RFC v2 0/3] cleanups for pstore and ramoops Kees Cook
2018-11-15  2:20   ` Joel Fernandes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).