diff options
author | Anton Blanchard <anton@samba.org> | 2013-12-11 23:59:38 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2013-12-12 23:48:36 -0500 |
commit | 9fa2984d1b5d9736a88c813ae89c160a2f9d5308 (patch) | |
tree | 4fcea94434dbf3b12df2632ee36505bbeaf87804 /arch | |
parent | ca5de4e652ea09c0c18ebbd12dd4c2149271245a (diff) |
powerpc/pseries: Fix endian issues in nvram code
The NVRAM code has a number of endian issues. I noticed a very
confused error log count:
RTAS: 100663330 -------- RTAS event begin --------
100663330 == 0x06000022. 0x6 LE error logs and 0x22 BE error logs.
The pstore code has similar issues - if we write an oops in one
endian and attempt to read it in another we get junk.
Make both of these formats big endian, and byteswap as required.
Signed-off-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/powerpc/platforms/pseries/nvram.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/arch/powerpc/platforms/pseries/nvram.c b/arch/powerpc/platforms/pseries/nvram.c index 7bfaf58d4664..d7096f2f7751 100644 --- a/arch/powerpc/platforms/pseries/nvram.c +++ b/arch/powerpc/platforms/pseries/nvram.c | |||
@@ -43,8 +43,8 @@ static char nvram_buf[NVRW_CNT]; /* assume this is in the first 4GB */ | |||
43 | static DEFINE_SPINLOCK(nvram_lock); | 43 | static DEFINE_SPINLOCK(nvram_lock); |
44 | 44 | ||
45 | struct err_log_info { | 45 | struct err_log_info { |
46 | int error_type; | 46 | __be32 error_type; |
47 | unsigned int seq_num; | 47 | __be32 seq_num; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | struct nvram_os_partition { | 50 | struct nvram_os_partition { |
@@ -79,9 +79,9 @@ static const char *pseries_nvram_os_partitions[] = { | |||
79 | }; | 79 | }; |
80 | 80 | ||
81 | struct oops_log_info { | 81 | struct oops_log_info { |
82 | u16 version; | 82 | __be16 version; |
83 | u16 report_length; | 83 | __be16 report_length; |
84 | u64 timestamp; | 84 | __be64 timestamp; |
85 | } __attribute__((packed)); | 85 | } __attribute__((packed)); |
86 | 86 | ||
87 | static void oops_to_nvram(struct kmsg_dumper *dumper, | 87 | static void oops_to_nvram(struct kmsg_dumper *dumper, |
@@ -291,8 +291,8 @@ int nvram_write_os_partition(struct nvram_os_partition *part, char * buff, | |||
291 | length = part->size; | 291 | length = part->size; |
292 | } | 292 | } |
293 | 293 | ||
294 | info.error_type = err_type; | 294 | info.error_type = cpu_to_be32(err_type); |
295 | info.seq_num = error_log_cnt; | 295 | info.seq_num = cpu_to_be32(error_log_cnt); |
296 | 296 | ||
297 | tmp_index = part->index; | 297 | tmp_index = part->index; |
298 | 298 | ||
@@ -364,8 +364,8 @@ int nvram_read_partition(struct nvram_os_partition *part, char *buff, | |||
364 | } | 364 | } |
365 | 365 | ||
366 | if (part->os_partition) { | 366 | if (part->os_partition) { |
367 | *error_log_cnt = info.seq_num; | 367 | *error_log_cnt = be32_to_cpu(info.seq_num); |
368 | *err_type = info.error_type; | 368 | *err_type = be32_to_cpu(info.error_type); |
369 | } | 369 | } |
370 | 370 | ||
371 | return 0; | 371 | return 0; |
@@ -529,9 +529,9 @@ static int zip_oops(size_t text_len) | |||
529 | pr_err("nvram: logging uncompressed oops/panic report\n"); | 529 | pr_err("nvram: logging uncompressed oops/panic report\n"); |
530 | return -1; | 530 | return -1; |
531 | } | 531 | } |
532 | oops_hdr->version = OOPS_HDR_VERSION; | 532 | oops_hdr->version = cpu_to_be16(OOPS_HDR_VERSION); |
533 | oops_hdr->report_length = (u16) zipped_len; | 533 | oops_hdr->report_length = cpu_to_be16(zipped_len); |
534 | oops_hdr->timestamp = get_seconds(); | 534 | oops_hdr->timestamp = cpu_to_be64(get_seconds()); |
535 | return 0; | 535 | return 0; |
536 | } | 536 | } |
537 | 537 | ||
@@ -574,9 +574,9 @@ static int nvram_pstore_write(enum pstore_type_id type, | |||
574 | clobbering_unread_rtas_event()) | 574 | clobbering_unread_rtas_event()) |
575 | return -1; | 575 | return -1; |
576 | 576 | ||
577 | oops_hdr->version = OOPS_HDR_VERSION; | 577 | oops_hdr->version = cpu_to_be16(OOPS_HDR_VERSION); |
578 | oops_hdr->report_length = (u16) size; | 578 | oops_hdr->report_length = cpu_to_be16(size); |
579 | oops_hdr->timestamp = get_seconds(); | 579 | oops_hdr->timestamp = cpu_to_be64(get_seconds()); |
580 | 580 | ||
581 | if (compressed) | 581 | if (compressed) |
582 | err_type = ERR_TYPE_KERNEL_PANIC_GZ; | 582 | err_type = ERR_TYPE_KERNEL_PANIC_GZ; |
@@ -670,16 +670,16 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, | |||
670 | size_t length, hdr_size; | 670 | size_t length, hdr_size; |
671 | 671 | ||
672 | oops_hdr = (struct oops_log_info *)buff; | 672 | oops_hdr = (struct oops_log_info *)buff; |
673 | if (oops_hdr->version < OOPS_HDR_VERSION) { | 673 | if (be16_to_cpu(oops_hdr->version) < OOPS_HDR_VERSION) { |
674 | /* Old format oops header had 2-byte record size */ | 674 | /* Old format oops header had 2-byte record size */ |
675 | hdr_size = sizeof(u16); | 675 | hdr_size = sizeof(u16); |
676 | length = oops_hdr->version; | 676 | length = be16_to_cpu(oops_hdr->version); |
677 | time->tv_sec = 0; | 677 | time->tv_sec = 0; |
678 | time->tv_nsec = 0; | 678 | time->tv_nsec = 0; |
679 | } else { | 679 | } else { |
680 | hdr_size = sizeof(*oops_hdr); | 680 | hdr_size = sizeof(*oops_hdr); |
681 | length = oops_hdr->report_length; | 681 | length = be16_to_cpu(oops_hdr->report_length); |
682 | time->tv_sec = oops_hdr->timestamp; | 682 | time->tv_sec = be64_to_cpu(oops_hdr->timestamp); |
683 | time->tv_nsec = 0; | 683 | time->tv_nsec = 0; |
684 | } | 684 | } |
685 | *buf = kmalloc(length, GFP_KERNEL); | 685 | *buf = kmalloc(length, GFP_KERNEL); |
@@ -889,13 +889,13 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, | |||
889 | kmsg_dump_get_buffer(dumper, false, | 889 | kmsg_dump_get_buffer(dumper, false, |
890 | oops_data, oops_data_sz, &text_len); | 890 | oops_data, oops_data_sz, &text_len); |
891 | err_type = ERR_TYPE_KERNEL_PANIC; | 891 | err_type = ERR_TYPE_KERNEL_PANIC; |
892 | oops_hdr->version = OOPS_HDR_VERSION; | 892 | oops_hdr->version = cpu_to_be16(OOPS_HDR_VERSION); |
893 | oops_hdr->report_length = (u16) text_len; | 893 | oops_hdr->report_length = cpu_to_be16(text_len); |
894 | oops_hdr->timestamp = get_seconds(); | 894 | oops_hdr->timestamp = cpu_to_be64(get_seconds()); |
895 | } | 895 | } |
896 | 896 | ||
897 | (void) nvram_write_os_partition(&oops_log_partition, oops_buf, | 897 | (void) nvram_write_os_partition(&oops_log_partition, oops_buf, |
898 | (int) (sizeof(*oops_hdr) + oops_hdr->report_length), err_type, | 898 | (int) (sizeof(*oops_hdr) + text_len), err_type, |
899 | ++oops_count); | 899 | ++oops_count); |
900 | 900 | ||
901 | spin_unlock_irqrestore(&lock, flags); | 901 | spin_unlock_irqrestore(&lock, flags); |