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

pstore: Populate pstore record->time field

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>

+15 -15
-3
drivers/firmware/efi/efi-pstore.c
··· 244 244 efi_guid_t vendor = LINUX_EFI_CRASH_GUID; 245 245 int i, ret = 0; 246 246 247 - record->time.tv_sec = get_seconds(); 248 - record->time.tv_nsec = 0; 249 - 250 247 record->id = generic_id(record->time.tv_sec, record->part, 251 248 record->count); 252 249
+6
fs/pstore/platform.c
··· 480 480 memset(record, 0, sizeof(*record)); 481 481 482 482 record->psi = psinfo; 483 + 484 + /* Report zeroed timestamp if called before timekeeping has resumed. */ 485 + if (__getnstimeofday(&record->time)) { 486 + record->time.tv_sec = 0; 487 + record->time.tv_nsec = 0; 488 + } 483 489 } 484 490 485 491 /*
+5 -11
fs/pstore/ram.c
··· 27 27 #include <linux/module.h> 28 28 #include <linux/version.h> 29 29 #include <linux/pstore.h> 30 - #include <linux/time.h> 31 30 #include <linux/io.h> 32 31 #include <linux/ioport.h> 33 32 #include <linux/platform_device.h> ··· 355 356 } 356 357 357 358 static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, 358 - bool compressed) 359 + struct pstore_record *record) 359 360 { 360 361 char *hdr; 361 - struct timespec timestamp; 362 362 size_t len; 363 363 364 - /* Report zeroed timestamp if called before timekeeping has resumed. */ 365 - if (__getnstimeofday(&timestamp)) { 366 - timestamp.tv_sec = 0; 367 - timestamp.tv_nsec = 0; 368 - } 369 364 hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n", 370 - (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000), 371 - compressed ? 'C' : 'D'); 365 + record->time.tv_sec, 366 + record->time.tv_nsec / 1000, 367 + record->compressed ? 'C' : 'D'); 372 368 WARN_ON_ONCE(!hdr); 373 369 len = hdr ? strlen(hdr) : 0; 374 370 persistent_ram_write(prz, hdr, len); ··· 434 440 prz = cxt->dprzs[cxt->dump_write_cnt]; 435 441 436 442 /* Build header and append record contents. */ 437 - hlen = ramoops_write_kmsg_hdr(prz, record->compressed); 443 + hlen = ramoops_write_kmsg_hdr(prz, record); 438 444 size = record->size; 439 445 if (size + hlen > prz->buffer_size) 440 446 size = prz->buffer_size - hlen;
+4 -1
include/linux/pstore.h
··· 138 138 * memory allocation may be broken during an Oops. Regardless, 139 139 * @buf must be proccesed or copied before returning. The 140 140 * backend is also expected to write @id with something that 141 - 8 can help identify this record to a future @erase callback. 141 + * can help identify this record to a future @erase callback. 142 + * The @time field will be prepopulated with the current time, 143 + * when available. The @size field will have the size of data 144 + * in @buf. 142 145 * 143 146 * Returns 0 on success, and non-zero on error. 144 147 *