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

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.

Drop pstore_write() as it has no users, and handling the "reason" here
has no obviously correct value.

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Tony Luck <tony.luck@intel.com>

authored by

Kees Cook and committed by
Tony Luck
3d6d8d20 f6f82851

+15 -41
+4 -2
drivers/acpi/apei/erst.c
··· 934 934 static ssize_t erst_reader(u64 *id, enum pstore_type_id *type, 935 935 struct timespec *time, char **buf, 936 936 struct pstore_info *psi); 937 - static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part, 937 + static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason, 938 + u64 *id, unsigned int part, 938 939 size_t size, struct pstore_info *psi); 939 940 static int erst_clearer(enum pstore_type_id type, u64 id, 940 941 struct pstore_info *psi); ··· 1054 1053 return (rc < 0) ? rc : (len - sizeof(*rcd)); 1055 1054 } 1056 1055 1057 - static int erst_writer(enum pstore_type_id type, u64 *id, unsigned int part, 1056 + static int erst_writer(enum pstore_type_id type, enum kmsg_dump_reason reason, 1057 + u64 *id, unsigned int part, 1058 1058 size_t size, struct pstore_info *psi) 1059 1059 { 1060 1060 struct cper_pstore_record *rcd = (struct cper_pstore_record *)
+5 -3
drivers/firmware/efivars.c
··· 495 495 return 0; 496 496 } 497 497 498 - static int efi_pstore_write(enum pstore_type_id type, u64 *id, 498 + static int efi_pstore_write(enum pstore_type_id type, 499 + enum kmsg_dump_reason reason, u64 *id, 499 500 unsigned int part, size_t size, struct pstore_info *psi) 500 501 { 501 502 char name[DUMP_NAME_LEN]; ··· 566 565 static int efi_pstore_erase(enum pstore_type_id type, u64 id, 567 566 struct pstore_info *psi) 568 567 { 569 - efi_pstore_write(type, &id, (unsigned int)id, 0, psi); 568 + efi_pstore_write(type, 0, &id, (unsigned int)id, 0, psi); 570 569 571 570 return 0; 572 571 } ··· 587 586 return -1; 588 587 } 589 588 590 - static int efi_pstore_write(enum pstore_type_id type, u64 *id, 589 + static int efi_pstore_write(enum pstore_type_id type, 590 + enum kmsg_dump_reason reason, u64 *id, 591 591 unsigned int part, size_t size, struct pstore_info *psi) 592 592 { 593 593 return 0;
+1 -29
fs/pstore/platform.c
··· 122 122 memcpy(dst, s1 + s1_start, l1_cpy); 123 123 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy); 124 124 125 - ret = psinfo->write(PSTORE_TYPE_DMESG, &id, part, 125 + ret = psinfo->write(PSTORE_TYPE_DMESG, reason, &id, part, 126 126 hsize + l1_cpy + l2_cpy, psinfo); 127 127 if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted()) 128 128 pstore_new_entry = 1; ··· 242 242 243 243 mod_timer(&pstore_timer, jiffies + PSTORE_INTERVAL); 244 244 } 245 - 246 - /* 247 - * Call platform driver to write a record to the 248 - * persistent store. 249 - */ 250 - int pstore_write(enum pstore_type_id type, char *buf, size_t size) 251 - { 252 - u64 id; 253 - int ret; 254 - unsigned long flags; 255 - 256 - if (!psinfo) 257 - return -ENODEV; 258 - 259 - if (size > psinfo->bufsize) 260 - return -EFBIG; 261 - 262 - spin_lock_irqsave(&psinfo->buf_lock, flags); 263 - memcpy(psinfo->buf, buf, size); 264 - ret = psinfo->write(type, &id, 0, size, psinfo); 265 - if (ret == 0 && pstore_is_mounted()) 266 - pstore_mkfile(PSTORE_TYPE_DMESG, psinfo->name, id, psinfo->buf, 267 - size, CURRENT_TIME, psinfo); 268 - spin_unlock_irqrestore(&psinfo->buf_lock, flags); 269 - 270 - return 0; 271 - } 272 - EXPORT_SYMBOL_GPL(pstore_write); 273 245 274 246 module_param(backend, charp, 0444); 275 247 MODULE_PARM_DESC(backend, "Pstore backend to use");
+5 -7
include/linux/pstore.h
··· 22 22 #ifndef _LINUX_PSTORE_H 23 23 #define _LINUX_PSTORE_H 24 24 25 + #include <linux/time.h> 26 + #include <linux/kmsg_dump.h> 27 + 25 28 /* types */ 26 29 enum pstore_type_id { 27 30 PSTORE_TYPE_DMESG = 0, ··· 44 41 ssize_t (*read)(u64 *id, enum pstore_type_id *type, 45 42 struct timespec *time, char **buf, 46 43 struct pstore_info *psi); 47 - int (*write)(enum pstore_type_id type, u64 *id, 44 + int (*write)(enum pstore_type_id type, 45 + enum kmsg_dump_reason reason, u64 *id, 48 46 unsigned int part, size_t size, struct pstore_info *psi); 49 47 int (*erase)(enum pstore_type_id type, u64 id, 50 48 struct pstore_info *psi); ··· 54 50 55 51 #ifdef CONFIG_PSTORE 56 52 extern int pstore_register(struct pstore_info *); 57 - extern int pstore_write(enum pstore_type_id type, char *buf, size_t size); 58 53 #else 59 54 static inline int 60 55 pstore_register(struct pstore_info *psi) 61 - { 62 - return -ENODEV; 63 - } 64 - static inline int 65 - pstore_write(enum pstore_type_id type, char *buf, size_t size) 66 56 { 67 57 return -ENODEV; 68 58 }