powerpc/pstore: Add pstore support for nvram partitions
Subsystems (2)
v5 cover powerpc/pstore: Add pstore support for nvram partitions
This patch series adds pstore support on powernv platform to read different nvram partitions and write compressed data to oops-log nvram partition. As pseries platform already has pstore support, this series moves most of the common code for pseries and powernv platforms to a common file. Tested the patches successfully on both pseries and powernv platforms. Also, tested the patches successfully, on a kernel compiled with both CONFIG_PPC_PSERIES=y & CONFIG_PPC_POWERNV=y.
Changes from v4:
1. Added a patch for y2038-safe code changes
---
Hari Bathini (4):
powerpc/nvram: move generic code for nvram and pstore
pstore: Add pstore type id for PPC64 opal nvram partition
pstore: add pstore support on powernv
powerpc: make timestamp related code y2038-safe
arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 5 arch/powerpc/kernel/nvram_64.c | 677 +++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-nvram.c | 10 arch/powerpc/platforms/pseries/nvram.c | 673 --------------------------- fs/pstore/inode.c | 3 include/linux/pstore.h | 1 7 files changed, 754 insertions(+), 665 deletions(-)
--
-Hari
PATCH v5 1/4 powerpc/nvram: move generic code for nvram and pstore
With minor checks, we can move most of the code for nvram under pseries to a common place to be re-used by other powerpc platforms like powernv. This patch moves such common code to arch/powerpc/kernel/nvram_64.c file.
--- arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 4 arch/powerpc/kernel/nvram_64.c | 656 ++++++++++++++++++++++++++++++++ arch/powerpc/platforms/pseries/nvram.c | 665 -------------------------------- 4 files changed, 714 insertions(+), 661 deletions(-)
arch/powerpc/include/asm/nvram.h +49 -1
@@ -9,12 +9,43 @@#ifndef _ASM_POWERPC_NVRAM_H#define _ASM_POWERPC_NVRAM_H - +#include <linux/types.h> #include <linux/errno.h> #include <linux/list.h> #include <uapi/asm/nvram.h> +/* +* Set oops header version to distinguish between old and new format header. +* lnx,oops-log partition max size is 4000, header version > 4000 will +* help in identifying new header. +*/ +#define OOPS_HDR_VERSION 5000 + +struct err_log_info { +__be32 error_type; +__be32 seq_num; +}; + +struct nvram_os_partition { +const char *name; +int req_size;/* desired size, in bytes */ +int min_size;/* minimum acceptable size (0 means req_size) */ +long size;/* size of data portion (excluding err_log_info) */ +long index;/* offset of data portion of partition */ +bool os_partition;/* partition initialized by OS, not FW */ +}; + +struct oops_log_info { +__be16 version; +__be16 report_length; +__be64 timestamp; +} __attribute__((packed)); + +extern struct nvram_os_partition oops_log_partition; +#ifdef CONFIG_PPC_PSERIES +extern struct nvram_os_partition rtas_log_partition; +extern int nvram_write_error_log (char * buff,int length,unsigned int err_type,unsigned int err_seq); extern int nvram_read_error_log(char * buff, int length,
@@ -50,6 +81,23 @@ extern void pmac_xpram_write(int xpaddr, u8 data);/* Synchronize NVRAM */ extern void nvram_sync (void ); +/* Initialize NVRAM OS partition */ +extern int __init nvram_init_os_partition (struct nvram_os_partition *part); + +/* Initialize NVRAM oops partition */ +extern void __init nvram_init_oops_partition (int rtas_partition_exists); + +/* Read a NVRAM partition */ +extern int nvram_read_partition (struct nvram_os_partition *part,char *buff, +int length,unsigned int *err_type, +unsigned int *error_log_cnt); + +/* Write to NVRAM OS partition */ +extern int nvram_write_os_partition (struct nvram_os_partition *part, +char *buff,int length, +unsigned int err_type, +unsigned int error_log_cnt); +/* Determine NVRAM size */ extern ssize_t nvram_get_size (void );
arch/powerpc/include/asm/rtas.h +4 -0
@@ -343,8 +343,12 @@ extern int early_init_dt_scan_rtas(unsigned long node,extern void pSeries_log_error (char *buf,unsigned int err_type,int fatal);#ifdef CONFIG_PPC_PSERIES +extern unsigned long last_rtas_event; +extern int clobbering_unread_rtas_event (void );extern int pseries_devicetree_update (s32 scope);extern void post_mobility_fixup (void ); +#else +static inline int clobbering_unread_rtas_event (void ) {return 0 ; }#endif #ifdef CONFIG_PPC_RTAS_DAEMON
arch/powerpc/kernel/nvram_64.c +656 -0
668 lines not on this page · raw message
arch/powerpc/platforms/pseries/nvram.c +5 -660
723 lines not on this page · raw message
Michael Ellerman
reviewerRe: [v5,1/4] powerpc/nvram: move generic code for nvram and pstore
Quoted 18 lines · Hari Bathini
With minor checks, we can move most of the code for nvram under pseries to a common place to be re-used by other powerpc platforms like powernv. This patch moves such common code to
arch/powerpc/kernel/nvram_64.cfile.Signed-off-by Hari Bathini <[email protected]>--- arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 4 arch/powerpc/kernel/nvram_64.c | 656 ++++++++++++++++++++++++++++++++ arch/powerpc/platforms/pseries/nvram.c | 665 -------------------------------- 4 files changed, 714 insertions(+), 661 deletions(-)arch/powerpc/kernel/nvram_64.c +0
-0@@ -26,6 +26,9 @@
...
arch/powerpc/kernel/nvram_64.c struct nvram_partition { · line 333
Quoted 11 lines
arch/powerpc/kernel/nvram_64.c +11
-0+/* Derived from logfs_compress() */ +static int nvram_compress (const void *in,void *out,size_t inlen, +size_t outlen) +{ +int err, ret; + + ret = -EIO ; + err =zlib_deflateInit2 (&stream,COMPR_LEVEL ,Z_DEFLATED ,WINDOW_BITS , +MEM_LEVEL ,Z_DEFAULT_STRATEGY ); +if (err !=Z_OK ) + goto error;
This fails the build for ppc64e_defconfig:
arch/powerpc/kernel/built-in.o: In function `.oops_to_nvram':
nvram_64.c:(.text+0x12148): undefined reference to .zlib_deflateInit2' nvram_64.c:(.text+0x12178): undefined reference to .zlib_deflate' nvram_64.c:(.text+0x1218c): undefined reference to .zlib_deflateEnd' arch/powerpc/kernel/built-in.o: In function .nvram_init_oops_partition':
(.init.text+0x41e0): undefined reference to `.zlib_deflate_workspacesize'
make: *** [vmlinux] Error 1
It used to be OK because PSERIES selects ZLIB_DEFLATE.
I decided to just force ZLIB_DEFLATE on for PPC64. That will add ~22K to the ppc64e kernel image.
Scott, if you guys are bothered by that let me know and we can add some #ifdefs to avoid it.
cheers
PATCH v5 2/4 pstore: Add pstore type id for PPC64 opal nvram partition
In reply to Hari BathiniThis patch adds a new PPC64 partition type to be used for opal specific nvram partition. A new partition type is needed as none of the existing type matches this partition type.
--- fs/pstore/inode.c | 3 +++ include/linux/pstore.h | 1 + 2 files changed, 4 insertions(+)
fs/pstore/inode.c +3 -0
@@ -359,6 +359,9 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,case PSTORE_TYPE_PPC_COMMON :sprintf (name,"powerpc-common-%s-%lld" , psname, id);break ; +case PSTORE_TYPE_PPC_OPAL : +sprintf (name,"powerpc-opal-%s-%lld" , psname, id); +break ;case PSTORE_TYPE_UNKNOWN :sprintf (name,"unknown-%s-%lld" , psname, id);break ;
include/linux/pstore.h +1 -0
@@ -39,6 +39,7 @@ enum pstore_type_id {PSTORE_TYPE_PPC_RTAS =4 ,PSTORE_TYPE_PPC_OF =5 ,PSTORE_TYPE_PPC_COMMON =6 , +PSTORE_TYPE_PPC_OPAL =7 , PSTORE_TYPE_UNKNOWN = 255 };
Re: [PATCH v5 2/4] pstore: Add pstore type id for PPC64 opal nvram partition
Quoted 5 lines · Hari Bathini
This patch adds a new PPC64 partition type to be used for opal specific nvram partition. A new partition type is needed as none of the existing type matches this partition type.
Signed-off-by Hari Bathini <[email protected]>
This patch series is reviewed by Kees. Reference link: https://lkml.org/lkml/2015/2/5/651
Thanks
Hari
Quoted 36 lines
--- fs/pstore/inode.c | 3 +++ include/linux/pstore.h | 1 + 2 files changed, 4 insertions(+)fs/pstore/inode.c +3
-0@@ -359,6 +359,9 @@ int pstore_mkfile(enum pstore_type_id type, char *psname, u64 id, int count,case PSTORE_TYPE_PPC_COMMON :sprintf (name,"powerpc-common-%s-%lld" , psname, id);break ; +case PSTORE_TYPE_PPC_OPAL : +sprintf (name,"powerpc-opal-%s-%lld" , psname, id); +break ;case PSTORE_TYPE_UNKNOWN :sprintf (name,"unknown-%s-%lld" , psname, id);break ;include/linux/pstore.h +1
-0@@ -39,6 +39,7 @@ enum pstore_type_id {PSTORE_TYPE_PPC_RTAS =4 ,PSTORE_TYPE_PPC_OF =5 ,PSTORE_TYPE_PPC_COMMON =6 , +PSTORE_TYPE_PPC_OPAL =7 , PSTORE_TYPE_UNKNOWN = 255 };_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
PATCH v5 3/4 pstore: add pstore support on powernv
In reply to Hari BathiniThis patch extends pstore, a generic interface to platform dependent persistent storage, support for powernv platform to capture certain useful information, during dying moments. Such support is already in place for pseries platform. This patch re-uses most of that code.
It is a common practice to compile kernels with both CONFIG_PPC_PSERIES=y and CONFIG_PPC_POWERNV=y. The code in nvram_init_oops_partition() routine still works as intended, as the caller is platform specific code which passes the appropriate value for "rtas_partition_exists" parameter. In all other places, where CONFIG_PPC_PSERIES or CONFIG_PPC_POWERNV flag is used in this patchset, it is to reduce the kernel size in cases where this flag is not set and doesn't have any impact logic wise.
--- arch/powerpc/kernel/nvram_64.c | 25 +++++++++++++++++++++++-- arch/powerpc/platforms/powernv/opal-nvram.c | 10 ++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-)
arch/powerpc/kernel/nvram_64.c +23 -2
@@ -127,6 +127,14 @@ static size_t oops_data_sz;static struct z_stream_s stream;#ifdef CONFIG_PSTORE +#ifdef CONFIG_PPC_POWERNV +static struct nvram_os_partition skiboot_partition = { + .name ="ibm,skiboot" , + .index =-1 , + .os_partition = false +}; +#endif +#ifdef CONFIG_PPC_PSERIES static struct nvram_os_partition of_config_partition = { .name = "of-config",
@@ -477,6 +485,16 @@ static ssize_t nvram_pstore_read(u64 *id, enum pstore_type_id *type, time->tv_nsec =0 ;break ;#endif +#ifdef CONFIG_PPC_POWERNV +case PSTORE_TYPE_PPC_OPAL : + sig =NVRAM_SIG_FW ; + part = &skiboot_partition; + *type =PSTORE_TYPE_PPC_OPAL ; + *id =PSTORE_TYPE_PPC_OPAL ; + time->tv_sec =0 ; + time->tv_nsec =0 ; +break ; +#endif default :return 0 ; }
@@ -552,8 +570,11 @@ static int nvram_pstore_init(void) {int rc =0 ; - nvram_type_ids[2 ] =PSTORE_TYPE_PPC_RTAS ; - nvram_type_ids[3 ] =PSTORE_TYPE_PPC_OF ; +if (machine_is (pseries)) { + nvram_type_ids[2 ] =PSTORE_TYPE_PPC_RTAS ; + nvram_type_ids[3 ] =PSTORE_TYPE_PPC_OF ; + }else + nvram_type_ids[2 ] =PSTORE_TYPE_PPC_OPAL ; nvram_pstore_info.buf = oops_data; nvram_pstore_info.bufsize = oops_data_sz;
arch/powerpc/platforms/powernv/opal-nvram.c +10 -0
@@ -16,6 +16,7 @@#include <linux/of.h> #include <asm/opal.h> +#include <asm/nvram.h> #include <asm/machdep.h> static unsigned int nvram_size;
@@ -62,6 +63,15 @@ static ssize_t opal_nvram_write(char *buf, size_t count, loff_t *index)return count; } +static int __init opal_nvram_init_log_partitions (void ) +{ +/* Scan nvram for partitions */ +nvram_scan_partitions (); +nvram_init_oops_partition (0 ); +return 0 ; +} +machine_arch_initcall (powernv, opal_nvram_init_log_partitions); +void __init opal_nvram_init (void ) {struct device_node *np;
PATCH v5 4/4 powerpc: make timestamp related code y2038-safe
In reply to Hari BathiniWhile we are here, let us make timestamp related code y2038-safe.
--- arch/powerpc/include/asm/rtas.h | 3 ++- arch/powerpc/kernel/nvram_64.c | 6 +++--- arch/powerpc/platforms/pseries/nvram.c | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/rtas.h +2 -1
@@ -4,6 +4,7 @@#include <linux/spinlock.h> #include <asm/page.h> +#include <linux/time.h> /* * Definitions for talking to the RTAS on CHRP machines.
@@ -343,7 +344,7 @@ extern int early_init_dt_scan_rtas(unsigned long node,extern void pSeries_log_error (char *buf,unsigned int err_type,int fatal);#ifdef CONFIG_PPC_PSERIES -extern unsigned long last_rtas_event; +extern time64_t last_rtas_event;extern int clobbering_unread_rtas_event (void );extern int pseries_devicetree_update (s32 scope);extern void post_mobility_fixup (void );
arch/powerpc/kernel/nvram_64.c +3 -3
@@ -376,7 +376,7 @@ static int zip_oops(size_t text_len) } oops_hdr->version =cpu_to_be16 (OOPS_HDR_VERSION ); oops_hdr->report_length =cpu_to_be16 (zipped_len); - oops_hdr->timestamp =cpu_to_be64 (get_seconds ()); + oops_hdr->timestamp =cpu_to_be64 (ktime_get_real_seconds ());return 0 ; }
@@ -423,7 +423,7 @@ static int nvram_pstore_write(enum pstore_type_id type, oops_hdr->version =cpu_to_be16 (OOPS_HDR_VERSION ); oops_hdr->report_length =cpu_to_be16 (size); - oops_hdr->timestamp =cpu_to_be64 (get_seconds ()); + oops_hdr->timestamp =cpu_to_be64 (ktime_get_real_seconds ());if (compressed) err_type =ERR_TYPE_KERNEL_PANIC_GZ ;
@@ -721,7 +721,7 @@ static void oops_to_nvram(struct kmsg_dumper *dumper, err_type =ERR_TYPE_KERNEL_PANIC ; oops_hdr->version =cpu_to_be16 (OOPS_HDR_VERSION ); oops_hdr->report_length =cpu_to_be16 (text_len); - oops_hdr->timestamp =cpu_to_be64 (get_seconds ()); + oops_hdr->timestamp =cpu_to_be64 (ktime_get_real_seconds ()); } (void) nvram_write_os_partition(&oops_log_partition, oops_buf,
arch/powerpc/platforms/pseries/nvram.c +5 -5
@@ -37,10 +37,10 @@ static DEFINE_SPINLOCK(nvram_lock);/* See clobbering_unread_rtas_event() */ #define NVRAM_RTAS_READ_TIMEOUT 5/* seconds */ -static unsigned long last_unread_rtas_event;/* timestamp */ +static time64_t last_unread_rtas_event;/* timestamp */ #ifdef CONFIG_PSTORE -unsigned long last_rtas_event; +time64_t last_rtas_event;#endif static ssize_t pSeries_nvram_read (char *buf,size_t count,loff_t *index)
@@ -145,9 +145,9 @@ int nvram_write_error_log(char * buff, int length,int rc =nvram_write_os_partition (&rtas_log_partition, buff, length, err_type, error_log_cnt);if (!rc) { - last_unread_rtas_event =get_seconds (); + last_unread_rtas_event =ktime_get_real_seconds ();#ifdef CONFIG_PSTORE - last_rtas_event =get_seconds (); + last_rtas_event =ktime_get_real_seconds ();#endif }
@@ -201,7 +201,7 @@ int clobbering_unread_rtas_event(void) {return (oops_log_partition.index == rtas_log_partition.index && last_unread_rtas_event - &&get_seconds () - last_unread_rtas_event <= + &&ktime_get_real_seconds () - last_unread_rtas_event <=NVRAM_RTAS_READ_TIMEOUT ); }
Quoted 12 lines · Hari Bathini
This patch series adds pstore support on powernv platform to read different nvram partitions and write compressed data to oops-log nvram partition. As pseries platform already has pstore support, this series moves most of the common code for pseries and powernv platforms to a common file. Tested the patches successfully on both pseries and powernv platforms. Also, tested the patches successfully, on a kernel compiled with both
CONFIG_PPC_PSERIES=y&CONFIG_PPC_POWERNV=y.Changes from v4:
1. Added a patch for y2038-safe code changes
Quoted 7 lines
---
Hari Bathini (4):
powerpc/nvram: move generic code for nvram and pstore
pstore: Add pstore type id for PPC64 opal nvram partition
pstore: add pstore support on powernv
powerpc: make timestamp related code y2038-safe
Thanks! I skimmed this, and it looks good to me.
-Kees
Quoted 14 lines
arch/powerpc/include/asm/nvram.h | 50 ++ arch/powerpc/include/asm/rtas.h | 5 arch/powerpc/kernel/nvram_64.c | 677 +++++++++++++++++++++++++++ arch/powerpc/platforms/powernv/opal-nvram.c | 10 arch/powerpc/platforms/pseries/nvram.c | 673 --------------------------- fs/pstore/inode.c | 3 include/linux/pstore.h | 1 7 files changed, 754 insertions(+), 665 deletions(-)--
-Hari
Signature · 2 lines
Kees Cook Chrome OS Security