Skip to contentSkip to conversation

pstore: pass reason to backend write callback

PATCH Superseded Kees Cook 2 participants 3 messages Nov 14, 2011 – Nov 16, 2011

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 pstore: pass reason to backend write callback

This allows a backend to filter on the dmesg reason as well as the pstore reason. When ramoops is switched to pstore, this is needed since it has no interest in storing non-crash dmesg details.

---
 drivers/acpi/apei/erst.c   |    6 ++++--
 drivers/firmware/efivars.c |    8 +++++---
 fs/pstore/platform.c       |    9 +++++----
 include/linux/pstore.h     |   12 +++++++++---
 4 files changed, 23 insertions(+), 12 deletions(-)
drivers/acpi/apei/erst.c +4 -2
index b8b97d6..76d0f84 100644
@@ -934,7 +934,8 @@ static int erst_close_pstore(struct pstore_info *psi);
 static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
 			   struct timespec *time, char **buf,
 			   struct pstore_info *psi);
-static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
+static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		       u64 *id, unsigned int part,
 		       size_t size, struct pstore_info *psi);
 static int erst_clearer(enum pstore_type_id type, u64 id,
 			struct pstore_info *psi);
@@ -1051,7 +1052,8 @@ out:
 	return (rc < 0) ? rc : (len - sizeof(*rcd));
 }
 
-static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
+static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		       u64 *id, unsigned int part,
 		       size_t size, struct pstore_info *psi)
 {
 	struct cper_pstore_record *rcd = (struct cper_pstore_record *)
drivers/firmware/efivars.c +5 -3
index a54a6b9..0a53a05 100644
@@ -495,7 +495,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
 	return 0;
 }
 
-static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+static int efi_pstore_write(enum pstore_type_id type,
+		enum kmsg_dump_reason reason, u64 *id,
 		unsigned int part, size_t size, struct pstore_info *psi)
 {
 	char name[DUMP_NAME_LEN];
@@ -565,7 +566,7 @@ static int efi_pstore_write(enum pstore_type_id type, u64 *id,
 static int efi_pstore_erase(enum pstore_type_id type, u64 id,
 			    struct pstore_info *psi)
 {
-	efi_pstore_write(type, &id, (unsigned int)id, 0, psi);
+	efi_pstore_write(type, 0, &id, (unsigned int)id, 0, psi);
 
 	return 0;
 }
@@ -586,7 +587,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
 	return -1;
 }
 
-static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+static int efi_pstore_write(enum pstore_type_id type,
+		enum kmsg_dump_reason reason, u64 *id,
 		unsigned int part, size_t size, struct pstore_info *psi)
 {
 	return 0;
fs/pstore/platform.c +5 -4
index c09cbb4..2454dbe 100644
@@ -122,7 +122,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 		memcpy(dst, s1 + s1_start, l1_cpy);
 		memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
 
-		ret = psinfo->write(PSTORE_TYPE_DMESG, &id, part,
+		ret = psinfo->write(PSTORE_TYPE_DMESG, reason, &id, part,
 				   hsize + l1_cpy + l2_cpy, psinfo);
 		if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted())
 			pstore_new_entry = 1;
@@ -244,7 +244,8 @@ static void pstore_timefunc(unsigned long dummy)
  * Call platform driver to write a record to the
  * persistent store.
  */
-int pstore_write(enum pstore_type_id type, char *buf, size_t size)
+int pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		 char *buf, size_t size)
 {
 	u64		id;
 	int		ret;
@@ -258,10 +259,10 @@ int pstore_write(enum pstore_type_id type, char *buf, size_t size)
 
 	spin_lock_irqsave(&psinfo->buf_lock, flags);
 	memcpy(psinfo->buf, buf, size);
-	ret = psinfo->write(type, &id, 0, size, psinfo);
+	ret = psinfo->write(type, reason, &id, 0, size, psinfo);
 	spin_unlock_irqrestore(&psinfo->buf_lock, flags);
 	if (ret == 0 && pstore_is_mounted())
-		pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, buf,
+		pstore_mkfile(type, psinfo->name, id, buf,
 			      size, CURRENT_TIME, psinfo);
 
 	return 0;
include/linux/pstore.h +9 -3
index 781cf43..dabf5eb 100644
@@ -22,6 +22,9 @@
 #ifndef _LINUX_PSTORE_H
 #define _LINUX_PSTORE_H
 
+#include <linux/time.h>
+#include <linux/kmsg_dump.h>
+
 /* types */
 enum pstore_type_id {
 	PSTORE_TYPE_DMESG	= 0,
@@ -40,7 +43,8 @@ struct pstore_info {
 	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
 			struct timespec *time, char **buf,
 			struct pstore_info *psi);
-	int		(*write)(enum pstore_type_id type, u64 *id,
+	int		(*write)(enum pstore_type_id type,
+			enum kmsg_dump_reason reason, u64 *id,
 			unsigned int part, size_t size, struct pstore_info *psi);
 	int		(*erase)(enum pstore_type_id type, u64 id,
 			struct pstore_info *psi);
@@ -49,7 +53,8 @@ struct pstore_info {
 
 #ifdef CONFIG_PSTORE
 extern int pstore_register(struct pstore_info *);
-extern int pstore_write(enum pstore_type_id type, char *buf, size_t size);
+extern int pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+			char *buf, size_t size);
 #else
 static inline int
 pstore_register(struct pstore_info *psi)
@@ -57,7 +62,8 @@ pstore_register(struct pstore_info *psi)
 	return -ENODEV;
 }
 static inline int
-pstore_write(enum pstore_type_id type, char *buf, size_t size)
+pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+	     char *buf, size_t size)
 {
 	return -ENODEV;
 }
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 140 lines · Kees Cook

This allows a backend to filter on the dmesg reason as well as the pstore reason. When ramoops is switched to pstore, this is needed since it has no interest in storing non-crash dmesg details.

---
  drivers/acpi/apei/erst.c   |    6 ++++--
  drivers/firmware/efivars.c |    8 +++++---
  fs/pstore/platform.c       |    9 +++++----
  include/linux/pstore.h     |   12 +++++++++---
  4 files changed, 23 insertions(+), 12 deletions(-)
drivers/acpi/apei/erst.c +4 -2
index b8b97d6..76d0f84 100644
@@ -934,7 +934,8 @@ static int erst_close_pstore(struct pstore_info *psi);
  static ssize_t erst_reader(u64 *id, enum pstore_type_id *type,
  			   struct timespec *time, char **buf,
  			   struct pstore_info *psi);
-static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
+static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		       u64 *id, unsigned int part,
  		       size_t size, struct pstore_info *psi);
  static int erst_clearer(enum pstore_type_id type, u64 id,
  			struct pstore_info *psi);
@@ -1051,7 +1052,8 @@ out:
  	return (rc<  0) ? rc : (len - sizeof(*rcd));
  }
 
-static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part,
+static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		       u64 *id, unsigned int part,
  		       size_t size, struct pstore_info *psi)
  {
  	struct cper_pstore_record *rcd = (struct cper_pstore_record *)
drivers/firmware/efivars.c +5 -3
index a54a6b9..0a53a05 100644
@@ -495,7 +495,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
  	return 0;
  }
 
-static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+static int efi_pstore_write(enum pstore_type_id type,
+		enum kmsg_dump_reason reason, u64 *id,
  		unsigned int part, size_t size, struct pstore_info *psi)
  {
  	char name[DUMP_NAME_LEN];
@@ -565,7 +566,7 @@ static int efi_pstore_write(enum pstore_type_id type, u64 *id,
  static int efi_pstore_erase(enum pstore_type_id type, u64 id,
  			    struct pstore_info *psi)
  {
-	efi_pstore_write(type,&id, (unsigned int)id, 0, psi);
+	efi_pstore_write(type, 0,&id, (unsigned int)id, 0, psi);
 
  	return 0;
  }
@@ -586,7 +587,8 @@ static ssize_t efi_pstore_read(u64 *id, enum pstore_type_id *type,
  	return -1;
  }
 
-static int efi_pstore_write(enum pstore_type_id type, u64 *id,
+static int efi_pstore_write(enum pstore_type_id type,
+		enum kmsg_dump_reason reason, u64 *id,
  		unsigned int part, size_t size, struct pstore_info *psi)
  {
  	return 0;
fs/pstore/platform.c +5 -4
index c09cbb4..2454dbe 100644
@@ -122,7 +122,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
  		memcpy(dst, s1 + s1_start, l1_cpy);
  		memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
 
-		ret = psinfo->write(PSTORE_TYPE_DMESG,&id, part,
+		ret = psinfo->write(PSTORE_TYPE_DMESG, reason,&id, part,
  				   hsize + l1_cpy + l2_cpy, psinfo);
  		if (ret == 0&&  reason == KMSG_DUMP_OOPS&&  pstore_is_mounted())
  			pstore_new_entry = 1;
@@ -244,7 +244,8 @@ static void pstore_timefunc(unsigned long dummy)
   * Call platform driver to write a record to the
   * persistent store.
   */
-int pstore_write(enum pstore_type_id type, char *buf, size_t size)
+int pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+		 char *buf, size_t size)
  {
  	u64		id;
  	int		ret;
@@ -258,10 +259,10 @@ int pstore_write(enum pstore_type_id type, char *buf, size_t size)
 
  	spin_lock_irqsave(&psinfo->buf_lock, flags);
  	memcpy(psinfo->buf, buf, size);
-	ret = psinfo->write(type,&id, 0, size, psinfo);
+	ret = psinfo->write(type, reason,&id, 0, size, psinfo);
  	spin_unlock_irqrestore(&psinfo->buf_lock, flags);
  	if (ret == 0&&  pstore_is_mounted())
-		pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, buf,
+		pstore_mkfile(type, psinfo->name, id, buf,
  			      size, CURRENT_TIME, psinfo);
 
  	return 0;
include/linux/pstore.h +7 -2
index 781cf43..dabf5eb 100644
@@ -22,6 +22,9 @@
  #ifndef _LINUX_PSTORE_H
  #define _LINUX_PSTORE_H
 
+#include<linux/time.h>
+#include<linux/kmsg_dump.h>
+
  /* types */
  enum pstore_type_id {
  	PSTORE_TYPE_DMESG	= 0,
@@ -40,7 +43,8 @@ struct pstore_info {
  	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
  			struct timespec *time, char **buf,
  			struct pstore_info *psi);
-	int		(*write)(enum pstore_type_id type, u64 *id,
+	int		(*write)(enum pstore_type_id type,
+			enum kmsg_dump_reason reason, u64 *id,
  			unsigned int part, size_t size, struct pstore_info *psi);
  	int		(*erase)(enum pstore_type_id type, u64 id,
  			struct pstore_info *psi);
@@ -49,7 +53,8 @@ struct pstore_info {
 
  #ifdef CONFIG_PSTORE
  extern int pstore_register(struct pstore_info *);
-extern int pstore_write(enum pstore_type_id type, char *buf, size_t size);
+extern int pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+			char *buf, size_t size);
  #else
  static inline int
  pstore_register(struct pstore_info *psi)

include/linux/pstore.h pstore_register(struct pstore_info *psi) · line 69

Quoted 9 lines
include/linux/pstore.h +2 -1
@@ -57,7 +62,8 @@ pstore_register(struct pstore_info *psi)
  	return -ENODEV;
  }
  static inline int
-pstore_write(enum pstore_type_id type, char *buf, size_t size)
+pstore_write(enum pstore_type_id type, enum kmsg_dump_reason reason,
+	     char *buf, size_t size)
  {
  	return -ENODEV;
  }

We ever talked about it here: https://lkml.org/lkml/2011/9/20/468.
Matthew's patch is good enough if pstore_write can be cleaned.

author
#2 lore raw
Quoted 6 lines · Chen Gong
Quoted 3 lines · Kees Cook

This allows a backend to filter on the dmesg reason as well as the pstore reason. When ramoops is switched to pstore, this is needed since it has no interest in storing non-crash dmesg details.

We ever talked about it here: https://lkml.org/lkml/2011/9/20/468.
Matthew's patch is good enough if pstore_write can be cleaned.

Ah, thanks for the URL. Yeah, it looks like it would be sane to just remove pstore_write completely. I will send an updated patch.

Thanks!

-Kees

Signature · 2 lines
Kees Cook
ChromeOS Security