diff options
author | Kees Cook <keescook@chromium.org> | 2018-05-14 18:50:52 -0400 |
---|---|---|
committer | Deepa Dinamani <deepa.kernel@gmail.com> | 2018-06-05 19:57:31 -0400 |
commit | 7aaa822ed060719bd4ea012609883b6bc6950508 (patch) | |
tree | 222a4c1d6da343c041f790c0263e9b73296e798c | |
parent | 0220eddac66daa2afdd6cf6d7d5198226d2abf0b (diff) |
pstore: Convert internal records to timespec64
This prepares pstore for converting the VFS layer to timespec64.
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
-rw-r--r-- | drivers/firmware/efi/efi-pstore.c | 27 | ||||
-rw-r--r-- | fs/pstore/inode.c | 3 | ||||
-rw-r--r-- | fs/pstore/platform.c | 2 | ||||
-rw-r--r-- | fs/pstore/ram.c | 21 | ||||
-rw-r--r-- | include/linux/pstore.h | 2 |
5 files changed, 32 insertions, 23 deletions
diff --git a/drivers/firmware/efi/efi-pstore.c b/drivers/firmware/efi/efi-pstore.c index 5a0fa939d70f..cfe87b465819 100644 --- a/drivers/firmware/efi/efi-pstore.c +++ b/drivers/firmware/efi/efi-pstore.c | |||
@@ -28,10 +28,9 @@ static int efi_pstore_close(struct pstore_info *psi) | |||
28 | return 0; | 28 | return 0; |
29 | } | 29 | } |
30 | 30 | ||
31 | static inline u64 generic_id(unsigned long timestamp, | 31 | static inline u64 generic_id(u64 timestamp, unsigned int part, int count) |
32 | unsigned int part, int count) | ||
33 | { | 32 | { |
34 | return ((u64) timestamp * 100 + part) * 1000 + count; | 33 | return (timestamp * 100 + part) * 1000 + count; |
35 | } | 34 | } |
36 | 35 | ||
37 | static int efi_pstore_read_func(struct efivar_entry *entry, | 36 | static int efi_pstore_read_func(struct efivar_entry *entry, |
@@ -42,7 +41,8 @@ static int efi_pstore_read_func(struct efivar_entry *entry, | |||
42 | int i; | 41 | int i; |
43 | int cnt; | 42 | int cnt; |
44 | unsigned int part; | 43 | unsigned int part; |
45 | unsigned long time, size; | 44 | unsigned long size; |
45 | u64 time; | ||
46 | 46 | ||
47 | if (efi_guidcmp(entry->var.VendorGuid, vendor)) | 47 | if (efi_guidcmp(entry->var.VendorGuid, vendor)) |
48 | return 0; | 48 | return 0; |
@@ -50,7 +50,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, | |||
50 | for (i = 0; i < DUMP_NAME_LEN; i++) | 50 | for (i = 0; i < DUMP_NAME_LEN; i++) |
51 | name[i] = entry->var.VariableName[i]; | 51 | name[i] = entry->var.VariableName[i]; |
52 | 52 | ||
53 | if (sscanf(name, "dump-type%u-%u-%d-%lu-%c", | 53 | if (sscanf(name, "dump-type%u-%u-%d-%llu-%c", |
54 | &record->type, &part, &cnt, &time, &data_type) == 5) { | 54 | &record->type, &part, &cnt, &time, &data_type) == 5) { |
55 | record->id = generic_id(time, part, cnt); | 55 | record->id = generic_id(time, part, cnt); |
56 | record->part = part; | 56 | record->part = part; |
@@ -62,7 +62,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, | |||
62 | else | 62 | else |
63 | record->compressed = false; | 63 | record->compressed = false; |
64 | record->ecc_notice_size = 0; | 64 | record->ecc_notice_size = 0; |
65 | } else if (sscanf(name, "dump-type%u-%u-%d-%lu", | 65 | } else if (sscanf(name, "dump-type%u-%u-%d-%llu", |
66 | &record->type, &part, &cnt, &time) == 4) { | 66 | &record->type, &part, &cnt, &time) == 4) { |
67 | record->id = generic_id(time, part, cnt); | 67 | record->id = generic_id(time, part, cnt); |
68 | record->part = part; | 68 | record->part = part; |
@@ -71,7 +71,7 @@ static int efi_pstore_read_func(struct efivar_entry *entry, | |||
71 | record->time.tv_nsec = 0; | 71 | record->time.tv_nsec = 0; |
72 | record->compressed = false; | 72 | record->compressed = false; |
73 | record->ecc_notice_size = 0; | 73 | record->ecc_notice_size = 0; |
74 | } else if (sscanf(name, "dump-type%u-%u-%lu", | 74 | } else if (sscanf(name, "dump-type%u-%u-%llu", |
75 | &record->type, &part, &time) == 3) { | 75 | &record->type, &part, &time) == 3) { |
76 | /* | 76 | /* |
77 | * Check if an old format, | 77 | * Check if an old format, |
@@ -250,9 +250,10 @@ static int efi_pstore_write(struct pstore_record *record) | |||
250 | /* Since we copy the entire length of name, make sure it is wiped. */ | 250 | /* Since we copy the entire length of name, make sure it is wiped. */ |
251 | memset(name, 0, sizeof(name)); | 251 | memset(name, 0, sizeof(name)); |
252 | 252 | ||
253 | snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lu-%c", | 253 | snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lld-%c", |
254 | record->type, record->part, record->count, | 254 | record->type, record->part, record->count, |
255 | record->time.tv_sec, record->compressed ? 'C' : 'D'); | 255 | (long long)record->time.tv_sec, |
256 | record->compressed ? 'C' : 'D'); | ||
256 | 257 | ||
257 | for (i = 0; i < DUMP_NAME_LEN; i++) | 258 | for (i = 0; i < DUMP_NAME_LEN; i++) |
258 | efi_name[i] = name[i]; | 259 | efi_name[i] = name[i]; |
@@ -327,15 +328,15 @@ static int efi_pstore_erase(struct pstore_record *record) | |||
327 | char name[DUMP_NAME_LEN]; | 328 | char name[DUMP_NAME_LEN]; |
328 | int ret; | 329 | int ret; |
329 | 330 | ||
330 | snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lu", | 331 | snprintf(name, sizeof(name), "dump-type%u-%u-%d-%lld", |
331 | record->type, record->part, record->count, | 332 | record->type, record->part, record->count, |
332 | record->time.tv_sec); | 333 | (long long)record->time.tv_sec); |
333 | ret = efi_pstore_erase_name(name); | 334 | ret = efi_pstore_erase_name(name); |
334 | if (ret != -ENOENT) | 335 | if (ret != -ENOENT) |
335 | return ret; | 336 | return ret; |
336 | 337 | ||
337 | snprintf(name, sizeof(name), "dump-type%u-%u-%lu", | 338 | snprintf(name, sizeof(name), "dump-type%u-%u-%lld", |
338 | record->type, record->part, record->time.tv_sec); | 339 | record->type, record->part, (long long)record->time.tv_sec); |
339 | ret = efi_pstore_erase_name(name); | 340 | ret = efi_pstore_erase_name(name); |
340 | 341 | ||
341 | return ret; | 342 | return ret; |
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 5fcb845b9fec..75afe5eb0574 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c | |||
@@ -392,7 +392,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) | |||
392 | inode->i_private = private; | 392 | inode->i_private = private; |
393 | 393 | ||
394 | if (record->time.tv_sec) | 394 | if (record->time.tv_sec) |
395 | inode->i_mtime = inode->i_ctime = record->time; | 395 | inode->i_mtime = inode->i_ctime = |
396 | timespec64_to_timespec(record->time); | ||
396 | 397 | ||
397 | d_add(dentry, inode); | 398 | d_add(dentry, inode); |
398 | 399 | ||
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index dc720573fd53..c238ab8ba31d 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c | |||
@@ -328,7 +328,7 @@ void pstore_record_init(struct pstore_record *record, | |||
328 | record->psi = psinfo; | 328 | record->psi = psinfo; |
329 | 329 | ||
330 | /* Report zeroed timestamp if called before timekeeping has resumed. */ | 330 | /* Report zeroed timestamp if called before timekeeping has resumed. */ |
331 | record->time = ns_to_timespec(ktime_get_real_fast_ns()); | 331 | record->time = ns_to_timespec64(ktime_get_real_fast_ns()); |
332 | } | 332 | } |
333 | 333 | ||
334 | /* | 334 | /* |
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 49b2bc114868..69e893076ab7 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c | |||
@@ -38,6 +38,11 @@ | |||
38 | 38 | ||
39 | #define RAMOOPS_KERNMSG_HDR "====" | 39 | #define RAMOOPS_KERNMSG_HDR "====" |
40 | #define MIN_MEM_SIZE 4096UL | 40 | #define MIN_MEM_SIZE 4096UL |
41 | #if __BITS_PER_LONG == 64 | ||
42 | # define TVSEC_FMT "%ld" | ||
43 | #else | ||
44 | # define TVSEC_FMT "%lld" | ||
45 | #endif | ||
41 | 46 | ||
42 | static ulong record_size = MIN_MEM_SIZE; | 47 | static ulong record_size = MIN_MEM_SIZE; |
43 | module_param(record_size, ulong, 0400); | 48 | module_param(record_size, ulong, 0400); |
@@ -153,21 +158,23 @@ ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, | |||
153 | return prz; | 158 | return prz; |
154 | } | 159 | } |
155 | 160 | ||
156 | static int ramoops_read_kmsg_hdr(char *buffer, struct timespec *time, | 161 | static int ramoops_read_kmsg_hdr(char *buffer, struct timespec64 *time, |
157 | bool *compressed) | 162 | bool *compressed) |
158 | { | 163 | { |
159 | char data_type; | 164 | char data_type; |
160 | int header_length = 0; | 165 | int header_length = 0; |
161 | 166 | ||
162 | if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n%n", &time->tv_sec, | 167 | if (sscanf(buffer, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu-%c\n%n", |
163 | &time->tv_nsec, &data_type, &header_length) == 3) { | 168 | &time->tv_sec, &time->tv_nsec, &data_type, |
169 | &header_length) == 3) { | ||
164 | if (data_type == 'C') | 170 | if (data_type == 'C') |
165 | *compressed = true; | 171 | *compressed = true; |
166 | else | 172 | else |
167 | *compressed = false; | 173 | *compressed = false; |
168 | } else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR "%lu.%lu\n%n", | 174 | } else if (sscanf(buffer, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu\n%n", |
169 | &time->tv_sec, &time->tv_nsec, &header_length) == 2) { | 175 | &time->tv_sec, &time->tv_nsec, |
170 | *compressed = false; | 176 | &header_length) == 2) { |
177 | *compressed = false; | ||
171 | } else { | 178 | } else { |
172 | time->tv_sec = 0; | 179 | time->tv_sec = 0; |
173 | time->tv_nsec = 0; | 180 | time->tv_nsec = 0; |
@@ -360,7 +367,7 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz, | |||
360 | char *hdr; | 367 | char *hdr; |
361 | size_t len; | 368 | size_t len; |
362 | 369 | ||
363 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n", | 370 | hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR TVSEC_FMT ".%lu-%c\n", |
364 | record->time.tv_sec, | 371 | record->time.tv_sec, |
365 | record->time.tv_nsec / 1000, | 372 | record->time.tv_nsec / 1000, |
366 | record->compressed ? 'C' : 'D'); | 373 | record->compressed ? 'C' : 'D'); |
diff --git a/include/linux/pstore.h b/include/linux/pstore.h index 61f806a7fe29..a15bc4d48752 100644 --- a/include/linux/pstore.h +++ b/include/linux/pstore.h | |||
@@ -71,7 +71,7 @@ struct pstore_record { | |||
71 | struct pstore_info *psi; | 71 | struct pstore_info *psi; |
72 | enum pstore_type_id type; | 72 | enum pstore_type_id type; |
73 | u64 id; | 73 | u64 id; |
74 | struct timespec time; | 74 | struct timespec64 time; |
75 | char *buf; | 75 | char *buf; |
76 | ssize_t size; | 76 | ssize_t size; |
77 | ssize_t ecc_notice_size; | 77 | ssize_t ecc_notice_size; |