]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
pstore: Populate pstore record->time field
authorKees Cook <keescook@chromium.org>
Fri, 19 May 2017 22:29:10 +0000 (15:29 -0700)
committerKees Cook <keescook@chromium.org>
Wed, 31 May 2017 17:13:44 +0000 (10:13 -0700)
The current time will be initially available in the record->time field
for all pstore_read() and pstore_write() calls. Backends can either
update the field during read(), or use the field during write() instead
of fetching time themselves.

Signed-off-by: Kees Cook <keescook@chromium.org>
drivers/firmware/efi/efi-pstore.c
fs/pstore/platform.c
fs/pstore/ram.c
include/linux/pstore.h

index d30dc935e20ede22808e26e08a58917be5aee490..5a0fa939d70f961a998317cb88c8ee4705e1065f 100644 (file)
@@ -244,9 +244,6 @@ static int efi_pstore_write(struct pstore_record *record)
        efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
        int i, ret = 0;
 
-       record->time.tv_sec = get_seconds();
-       record->time.tv_nsec = 0;
-
        record->id = generic_id(record->time.tv_sec, record->part,
                                record->count);
 
index 7798041f3fba5a5efd5238faf5859fb17ec93311..96fbff7b87c8f202b8edeb726a9d9bfac2b889ee 100644 (file)
@@ -480,6 +480,12 @@ void pstore_record_init(struct pstore_record *record,
        memset(record, 0, sizeof(*record));
 
        record->psi = psinfo;
+
+       /* Report zeroed timestamp if called before timekeeping has resumed. */
+       if (__getnstimeofday(&record->time)) {
+               record->time.tv_sec = 0;
+               record->time.tv_nsec = 0;
+       }
 }
 
 /*
index 5cb022c8cd33f23b566721627dc25dd0263da3a8..7125b398d312e71714d96d4ed51baeff2e149601 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/pstore.h>
-#include <linux/time.h>
 #include <linux/io.h>
 #include <linux/ioport.h>
 #include <linux/platform_device.h>
@@ -356,20 +355,15 @@ out:
 }
 
 static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
-                                    bool compressed)
+                                    struct pstore_record *record)
 {
        char *hdr;
-       struct timespec timestamp;
        size_t len;
 
-       /* Report zeroed timestamp if called before timekeeping has resumed. */
-       if (__getnstimeofday(&timestamp)) {
-               timestamp.tv_sec = 0;
-               timestamp.tv_nsec = 0;
-       }
        hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
-               (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000),
-               compressed ? 'C' : 'D');
+               record->time.tv_sec,
+               record->time.tv_nsec / 1000,
+               record->compressed ? 'C' : 'D');
        WARN_ON_ONCE(!hdr);
        len = hdr ? strlen(hdr) : 0;
        persistent_ram_write(prz, hdr, len);
@@ -440,7 +434,7 @@ static int notrace ramoops_pstore_write(struct pstore_record *record)
        prz = cxt->dprzs[cxt->dump_write_cnt];
 
        /* Build header and append record contents. */
-       hlen = ramoops_write_kmsg_hdr(prz, record->compressed);
+       hlen = ramoops_write_kmsg_hdr(prz, record);
        size = record->size;
        if (size + hlen > prz->buffer_size)
                size = prz->buffer_size - hlen;
index e2233f50f4284826d2462ea900a2f430c8db8019..61f806a7fe29ec570a1c8f066767ef31c67b3042 100644 (file)
@@ -138,7 +138,10 @@ struct pstore_record {
  *             memory allocation may be broken during an Oops. Regardless,
  *             @buf must be proccesed or copied before returning. The
  *             backend is also expected to write @id with something that
- 8             can help identify this record to a future @erase callback.
+ *             can help identify this record to a future @erase callback.
+ *             The @time field will be prepopulated with the current time,
+ *             when available. The @size field will have the size of data
+ *             in @buf.
  *
  *     Returns 0 on success, and non-zero on error.
  *