Skip to contentSkip to conversation

kernel: add support to collect hardware logs in panic

RFC Superseded Rahul Lakkireddy 2 participants 5 messages Mar 2, 2018 – Mar 3, 2018

Subsystems (7)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover kernel: add support to collect hardware logs in panic

On production servers running variety of workloads over time, kernel panic can happen sporadically after days or even months. It is important to collect as much debug logs as possible to root cause and fix the problem, that may not be easy to reproduce. Snapshot of underlying hardware/firmware state (like register dump, firmware logs, adapter memory, etc.), at the time of kernel panic will be very helpful while debugging the culprit device driver.

This series of patches add new generic framework that enable device drivers to collect device specific snapshot of the hardware/firmware state of the underlying device at the time of kernel panic. The collected logs are appended to vmcore along with details, such as start address and length of the logs, which are required for extraction during post-analysis.

Device drivers can use crash_driver_dump_register() to register their callback that collects underlying device specific hardware/firmware logs during kernel panic (i.e. before booting into the second kernel). Drivers can unregister with crash_driver_dump_unregister().

To extract the device specific hardware/firmware logs using crash:

crash> help -D | grep DRIVERDUMP DRIVERDUMP=(cxgb4_0000:02:00.4, ffffb131090bd000, 37782968)

crash> rd ffffb131090bd000 37782968 -r hardware.log 37782968 bytes copied from 0xffffb131090bd000 to hardware.log

Patch 1 adds API to allow drivers to register callback to collect the device specific hardware/firmware logs.

Patch 2 shows a cxgb4 driver example using the API to collect hardware/firmware logs during kernel panic.

Suggestions and feedback will be much appreciated.

Thanks,
Rahul

Rahul Lakkireddy (2):
kernel/crash_core: add API to collect hardware dump in kernel panic
cxgb4: collect hardware dump in kernel panic

 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h       |  6 ++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c | 95 +++++++++++++++++++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h |  4 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c  | 12 +++
 include/linux/crash_core.h                       | 33 ++++++++
 kernel/crash_core.c                              | 83 ++++++++++++++++++++-
 kernel/kexec_core.c                              |  1 +
 7 files changed, 229 insertions(+), 5 deletions(-)
Signature · 1 line
2.14.1
#1 lore raw

RFC 1/2 kernel/crash_core: add API to collect hardware dump in kernel panic

Add API to allow drivers to register callback to collect device specific hardware/firmware dump during kernel panic. The registered callbacks will be invoked during kernel panic before moving to second kernel. Also save the dump location and size in vmcore info.

The dump can be extracted using crash:

crash> help -D | grep DRIVERDUMP DRIVERDUMP=(cxgb4_0000:02:00.4, ffffb131090bd000, 37782968)

crash> rd ffffb131090bd000 37782968 -r hardware.log 37782968 bytes copied from 0xffffb131090bd000 to hardware.log

---
 include/linux/crash_core.h | 33 ++++++++++++++++++
 kernel/crash_core.c        | 83 +++++++++++++++++++++++++++++++++++++++++++++-
 kernel/kexec_core.c        |  1 +
 3 files changed, 116 insertions(+), 1 deletion(-)
include/linux/crash_core.h +33 -0
index b511f6d24b42..d9cc6b3346c7 100644
@@ -59,6 +59,9 @@ phys_addr_t paddr_vmcoreinfo_note(void);
 	vmcoreinfo_append_str("NUMBER(%s)=%ld\n", #name, (long)name)
 #define VMCOREINFO_CONFIG(name) \
 	vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
+#define VMCOREINFO_DRIVER_DUMP(name, buf, size) \
+	vmcoreinfo_append_str("DRIVERDUMP=(%s, %lx, %lu)\n", \
+			      name, (unsigned long)buf, (unsigned long)size)
 
 extern u32 *vmcoreinfo_note;
 
@@ -73,4 +76,34 @@ int parse_crashkernel_high(char *cmdline, unsigned long long system_ram,
 int parse_crashkernel_low(char *cmdline, unsigned long long system_ram,
 		unsigned long long *crash_size, unsigned long long *crash_base);
 
+/* Driver dump collection */
+#define CRASH_DRIVER_DUMP_NAME_LENGTH 32
+
+struct crash_driver_dump_node {
+	struct crash_driver_dump_node __rcu *next;
+	struct crash_driver_dump *data;
+	struct notifier_block *nb;
+};
+
+struct crash_driver_dump_head {
+	struct crash_driver_dump_node __rcu *head;
+};
+
+#define CRASH_DRIVER_DUMP_INIT(name) { \
+	.head = NULL \
+}
+
+#define CRASH_DRIVER_DUMP_HEAD(name) \
+	struct crash_driver_dump_head name = CRASH_DRIVER_DUMP_INIT(name) \
+
+struct crash_driver_dump {
+	char name[CRASH_DRIVER_DUMP_NAME_LENGTH];
+	void *buf;
+	unsigned long size;
+};
+
+void crash_driver_dump_call_handlers(void);
+int crash_driver_dump_register(struct crash_driver_dump *data,
+			       struct notifier_block *nb);
+int crash_driver_dump_unregister(struct crash_driver_dump *data);
 #endif /* LINUX_CRASH_CORE_H */
kernel/crash_core.c +82 -1

101 lines not on this page · raw message

kernel/kexec_core.c +1 -0
index 20fef1a38602..b86ffe24fe09 100644
@@ -938,6 +938,7 @@ void __noclone __crash_kexec(struct pt_regs *regs)
 		if (kexec_crash_image) {
 			struct pt_regs fixed_regs;
 
+			crash_driver_dump_call_handlers();
 			crash_setup_regs(&fixed_regs, regs);
 			crash_save_vmcoreinfo();
 			machine_crash_shutdown(&fixed_regs);
Signature · 1 line
2.14.1
#2 lore raw

RFC 2/2 cxgb4: collect hardware dump in kernel panic

In reply to Rahul Lakkireddy

Pre-allocate dump buffer and register callback to collect hardware/ firmware logs in kernel panic. Free dump buffer on driver unload.

---
 drivers/net/ethernet/chelsio/cxgb4/cxgb4.h       |  6 ++
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c | 95 +++++++++++++++++++++++-
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h |  4 +
 drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c  | 12 +++
 4 files changed, 113 insertions(+), 4 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +6 -0
index d3fa53db61ee..21d095668374 100644
@@ -50,6 +50,7 @@
 #include <linux/net_tstamp.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/ptp_classify.h>
+#include <linux/crash_core.h>
 #include <asm/io.h>
 #include "t4_chip_type.h"
 #include "cxgb4_uld.h"
@@ -568,6 +569,7 @@ enum {                                 /* adapter flags */
 	FW_OFLD_CONN       = (1 << 9),
 	ROOT_NO_RELAXED_ORDERING = (1 << 10),
 	SHUTTING_DOWN	   = (1 << 11),
+	K_CRASH            = (1 << 12),
 };
 
 enum {
@@ -946,6 +948,10 @@ struct adapter {
 
 	/* Ethtool Dump */
 	struct ethtool_dump eth_dump;
+
+	/* Dump buffer for collecting logs in panic */
+	struct crash_driver_dump dump_buf;
+	struct notifier_block panic_nb;
 };
 
 /* Support for "sched-class" command to allow a TX Scheduling Class to be
drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c +91 -4

113 lines not on this page · raw message

drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.h +4 -0
index ce1ac9a1c878..79261313a350 100644
@@ -41,8 +41,12 @@ enum CXGB4_ETHTOOL_DUMP_FLAGS {
 	CXGB4_ETH_DUMP_HW = (1 << 1), /* various FW and HW dumps */
 };
 
+#define CXGB4_ETH_DUMP_ALL (CXGB4_ETH_DUMP_MEM | CXGB4_ETH_DUMP_HW)
+
 u32 cxgb4_get_dump_length(struct adapter *adap, u32 flag);
 int cxgb4_cudbg_collect(struct adapter *adap, void *buf, u32 *buf_size,
 			u32 flag);
 void cxgb4_init_ethtool_dump(struct adapter *adapter);
+int cxgb4_cudbg_register_crash_dump(struct adapter *adap);
+void cxgb4_cudbg_unregister_crash_dump(struct adapter *adap);
 #endif /* __CXGB4_CUDBG_H__ */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +12 -0
index 7b452e85de2a..64eeffe0ba45 100644
@@ -5291,6 +5291,16 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	}
 
 	setup_memwin(adapter);
+
+	/* Register panic notifier */
+	err = cxgb4_cudbg_register_crash_dump(adapter);
+	if (err) {
+		dev_warn(adapter->pdev_dev,
+			 "Fail registering panic notifier, err: %d. Continuing\n",
+			 err);
+		err = 0;
+	}
+
 	err = adap_init0(adapter);
 #ifdef CONFIG_DEBUG_FS
 	bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
@@ -5538,6 +5548,7 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		destroy_workqueue(adapter->workq);
 
 	kfree(adapter->mbox_log);
+	cxgb4_cudbg_unregister_crash_dump(adapter);
 	kfree(adapter);
  out_unmap_bar0:
 	iounmap(regs);
@@ -5617,6 +5628,7 @@ static void remove_one(struct pci_dev *pdev)
 	pci_release_regions(pdev);
 	kfree(adapter->mbox_log);
 	synchronize_rcu();
+	cxgb4_cudbg_unregister_crash_dump(adapter);
 	kfree(adapter);
 }
 
Signature · 1 line
2.14.1
#3 lore raw
In reply to Rahul Lakkireddy
Quoted 28 lines · Rahul Lakkireddy

On production servers running variety of workloads over time, kernel panic can happen sporadically after days or even months. It is important to collect as much debug logs as possible to root cause and fix the problem, that may not be easy to reproduce. Snapshot of underlying hardware/firmware state (like register dump, firmware logs, adapter memory, etc.), at the time of kernel panic will be very helpful while debugging the culprit device driver.

This series of patches add new generic framework that enable device drivers to collect device specific snapshot of the hardware/firmware state of the underlying device at the time of kernel panic. The collected logs are appended to vmcore along with details, such as start address and length of the logs, which are required for extraction during post-analysis.

Device drivers can use crash_driver_dump_register() to register their callback that collects underlying device specific hardware/firmware logs during kernel panic (i.e. before booting into the second kernel). Drivers can unregister with crash_driver_dump_unregister().

To extract the device specific hardware/firmware logs using crash:

crash> help -D | grep DRIVERDUMP DRIVERDUMP=(cxgb4_0000:02:00.4, ffffb131090bd000, 37782968)

crash> rd ffffb131090bd000 37782968 -r hardware.log 37782968 bytes copied from 0xffffb131090bd000 to hardware.log

Quoted 7 lines

Patch 1 adds API to allow drivers to register callback to collect the device specific hardware/firmware logs.

Patch 2 shows a cxgb4 driver example using the API to collect hardware/firmware logs during kernel panic.

Suggestions and feedback will be much appreciated.

I strongly suggest you figure out how to run this code in the crash recovery kernel before your hardware is initialized. That will give you a known good kernel to perform your collection from.

Every line of code we add to the kexec on panic code path tends to add to it's fragility and increase the chance you won't get any information at all.

When the assumption is it is something wrong with your driver/hardware that caused the crash, calling into your driver is a very bad idea. Especially running code that does callbacks and all kinds of other cute things.

Doing this as the crash recover kernel boots up before much if any hardware is initialized seems like a fine thing to do, and just needs a little coordination with userspace to ensure the information gets saved when a vmcore is computed.

Eric

#4 lore raw
Quoted 51 lines · Eric W. Biederman
Quoted 28 lines · Rahul Lakkireddy

On production servers running variety of workloads over time, kernel panic can happen sporadically after days or even months. It is important to collect as much debug logs as possible to root cause and fix the problem, that may not be easy to reproduce. Snapshot of underlying hardware/firmware state (like register dump, firmware logs, adapter memory, etc.), at the time of kernel panic will be very helpful while debugging the culprit device driver.

This series of patches add new generic framework that enable device drivers to collect device specific snapshot of the hardware/firmware state of the underlying device at the time of kernel panic. The collected logs are appended to vmcore along with details, such as start address and length of the logs, which are required for extraction during post-analysis.

Device drivers can use crash_driver_dump_register() to register their callback that collects underlying device specific hardware/firmware logs during kernel panic (i.e. before booting into the second kernel). Drivers can unregister with crash_driver_dump_unregister().

To extract the device specific hardware/firmware logs using crash:

crash> help -D | grep DRIVERDUMP DRIVERDUMP=(cxgb4_0000:02:00.4, ffffb131090bd000, 37782968)

crash> rd ffffb131090bd000 37782968 -r hardware.log 37782968 bytes copied from 0xffffb131090bd000 to hardware.log

Quoted 7 lines

Patch 1 adds API to allow drivers to register callback to collect the device specific hardware/firmware logs.

Patch 2 shows a cxgb4 driver example using the API to collect hardware/firmware logs during kernel panic.

Suggestions and feedback will be much appreciated.

I strongly suggest you figure out how to run this code in the crash recovery kernel before your hardware is initialized. That will give you a known good kernel to perform your collection from.

Every line of code we add to the kexec on panic code path tends to add to it's fragility and increase the chance you won't get any information at all.

When the assumption is it is something wrong with your driver/hardware that caused the crash, calling into your driver is a very bad idea. Especially running code that does callbacks and all kinds of other cute things.

Quoted 5 lines

Doing this as the crash recover kernel boots up before much if any hardware is initialized seems like a fine thing to do, and just needs a little coordination with userspace to ensure the information gets saved when a vmcore is computed.

Thanks for the feedback and suggestions. I will work on achieving this from the crash recover kernel.

Thanks,
Rahul