Skip to contentSkip to conversation

printk: Add function to return log buffer address and size

PATCH Superseded Vasant Hegde 2 participants 3 messages Jul 23, 2014

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 printk: Add function to return log buffer address and size

Platforms like IBM Power Systems supports service processor assisted dump. It provides interface to add memory region to be captured when system is crashed.

During initialization/running we can add kernel memory region to be collected.

Presently we don't have a way to get the log buffer base address and size. This patch adds support to return log buffer address and size.

---
Next patch extends arch specific code to add log buffer to platform dump.

 include/linux/printk.h |    3 +++
 kernel/printk/printk.c |   12 ++++++++++++
 2 files changed, 15 insertions(+)
include/linux/printk.h +3 -0
index 319ff7e..aae82c4 100644
@@ -10,6 +10,9 @@
 extern const char linux_banner[];
 extern const char linux_proc_banner[];
 
+extern void *get_log_buf_addr(void);
+extern u32 get_log_buf_len(void);
+
 static inline int printk_get_level(const char *buffer)
 {
 	if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
kernel/printk/printk.c +12 -0
index 13e839d..4049f7b 100644
@@ -270,6 +270,18 @@ static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
 static char *log_buf = __log_buf;
 static u32 log_buf_len = __LOG_BUF_LEN;
 
+/* Return log buffer address */
+void *get_log_buf_addr(void)
+{
+	return log_buf;
+}
+
+/* Return log buffer size */
+u32 get_log_buf_len(void)
+{
+	return log_buf_len;
+}
+
 /* human readable text of the record */
 static char *log_text(const struct printk_log *msg)
 {
#1 lore raw

PATCH 2/2 powerpc/powernv: Interface to add opal dump region

PowerNV platform is capable of capturing host memory region when system crashes (because of host/firmware). We have new OPAL API to register memory region to be capture when system crashes.

This patch adds support for new API and also registers kernel log buffer.

---
 arch/powerpc/include/asm/opal.h                   |   12 +++++
 arch/powerpc/platforms/powernv/Makefile           |    2 -
 arch/powerpc/platforms/powernv/opal-dump-region.c |   46 +++++++++++++++++++++
 arch/powerpc/platforms/powernv/opal-wrappers.S    |    1 
 arch/powerpc/platforms/powernv/opal.c             |    2 +
 5 files changed, 62 insertions(+), 1 deletion(-)
 create mode 100644 arch/powerpc/platforms/powernv/opal-dump-region.c
arch/powerpc/include/asm/opal.h +12 -0
index 0da1dbd..6b9c01e 100644
@@ -147,6 +147,7 @@ struct opal_sg_list {
 #define OPAL_SET_PARAM				90
 #define OPAL_DUMP_RESEND			91
 #define OPAL_DUMP_INFO2				94
+#define OPAL_REGISTER_DUMP_REGION		98
 
 #ifndef __ASSEMBLY__
 
@@ -860,6 +861,7 @@ int64_t opal_get_param(uint64_t token, uint32_t param_id, uint64_t buffer,
 int64_t opal_set_param(uint64_t token, uint32_t param_id, uint64_t buffer,
 		uint64_t length);
 int64_t opal_sensor_read(uint32_t sensor_hndl, int token, __be32 *sensor_data);
+int64_t opal_register_dump_region(uint32_t id, uint64_t start, uint64_t end);
 
 /* Internal functions */
 extern int early_init_dt_scan_opal(unsigned long node, const char *uname,
@@ -899,6 +901,7 @@ extern int opal_elog_init(void);
 extern void opal_platform_dump_init(void);
 extern void opal_sys_param_init(void);
 extern void opal_msglog_init(void);
+extern void opal_dump_region_init(void);
 
 extern int opal_machine_check(struct pt_regs *regs);
 extern bool opal_mce_check_early_recovery(struct pt_regs *regs);
@@ -912,6 +915,15 @@ struct opal_sg_list *opal_vmalloc_to_sg_list(void *vmalloc_addr,
 					     unsigned long vmalloc_size);
 void opal_free_sg_list(struct opal_sg_list *sg);
 
+/*
+ * Dump regions ids
+ *   0x01 - 0x7F : OPAL
+ *   0x80 - 0xFF : Kernel
+ */
+#define DUMP_REGION_HOST_START		0x80
+#define DUMP_REGION_LOG_BUF		0x80
+#define DUMP_REGION_HOST_END		0xFF
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __OPAL_H */
arch/powerpc/platforms/powernv/Makefile +1 -1
index 4ad227d..e2819aa 100644
@@ -1,7 +1,7 @@
 obj-y			+= setup.o opal-wrappers.o opal.o opal-async.o
 obj-y			+= opal-rtc.o opal-nvram.o opal-lpc.o opal-flash.o
 obj-y			+= rng.o opal-elog.o opal-dump.o opal-sysparam.o opal-sensor.o
-obj-y			+= opal-msglog.o
+obj-y			+= opal-msglog.o opal-dump-region.o
 
 obj-$(CONFIG_SMP)	+= smp.o subcore.o subcore-asm.o
 obj-$(CONFIG_PCI)	+= pci.o pci-p5ioc2.o pci-ioda.o
arch/powerpc/platforms/powernv/opal-dump-region.c new file +46 -0

46 lines not on this page · raw message

arch/powerpc/platforms/powernv/opal-wrappers.S +1 -0
index 4abbff2..935c30a 100644
@@ -146,3 +146,4 @@ OPAL_CALL(opal_sync_host_reboot,		OPAL_SYNC_HOST_REBOOT);
 OPAL_CALL(opal_sensor_read,			OPAL_SENSOR_READ);
 OPAL_CALL(opal_get_param,			OPAL_GET_PARAM);
 OPAL_CALL(opal_set_param,			OPAL_SET_PARAM);
+OPAL_CALL(opal_register_dump_region,		OPAL_REGISTER_DUMP_REGION);
arch/powerpc/platforms/powernv/opal.c +2 -0
index 1999756..2834303 100644
@@ -616,6 +616,8 @@ static int __init opal_init(void)
 	/* Create "opal" kobject under /sys/firmware */
 	rc = opal_sysfs_init();
 	if (rc == 0) {
+		/* Setup dump region interface */
+		opal_dump_region_init();
 		/* Setup error log interface */
 		rc = opal_elog_init();
 		/* Setup code update interface */
#2 lore raw

Re: [PATCH 2/2] powerpc/powernv: Interface to add opal dump region

Quoted 6 lines · Vasant Hegde

PowerNV platform is capable of capturing host memory region when system crashes (because of host/firmware). We have new OPAL API to register memory region to be capture when system crashes.

This patch adds support for new API and also registers kernel log buffer.

I think we do need a way to un-register regions, and I think this may be important around kexec - unless the log buffer is in exactly the same place, there's a window where we could dump some random memory contents as kernel log buffer, probably causing some poor support person to scratch their head for a good long while.

arch/powerpc/platforms/powernv/opal-dump-region.c line 45

Quoted 13 lines
arch/powerpc/platforms/powernv/opal-dump-region.c new file +13 -0
+void __init opal_dump_region_init(void)
+{
+	void *addr;
+	uint64_t size;
+	int rc;
+
+	/* Register kernel log buffer */
+	addr = get_log_buf_addr();
+	size = get_log_buf_len();
+	rc = add_dump_region_entry(DUMP_REGION_LOG_BUF, addr, size);
+	if (rc)
+		pr_warn("DUMP: Failed to register kernel log buffer. "
+			"rc = %d\n", rc);

This is what's going to be printed in kernel log when running on OPAL firmware that doesn't support that call. Does this include the first GA release on POWER8 systems? If so, we probably want a nicer log message pointing to the fact that firmware is too old to support that function.