From b530a30789513e19ea097ccd3a09f8e5b6449dd9 Mon Sep 17 00:00:00 2001 From: Syed Rameez Mustafa Date: Mon, 15 Jul 2013 11:52:09 -0700 Subject: [PATCH 1/3] kernel/lib: add additional debug capabilities for data corruption Data corruptions in the kernel often end up in system crashes that are easier to debug closer to the time of detection. Specifically, if we do not panic immediately after lock or list corruptions have been detected, the problem context is lost in the ensuing system mayhem. Add support for BUG_ON immediately after such corruptions are detected. The CONFIG option controls the enabling/disabling of the feature. Change-Id: I9b2eb62da506a13007acff63e85e9515145909ff Signed-off-by: Syed Rameez Mustafa Signed-off-by: Patrick Daly Signed-off-by: Isaac J. Manjarres --- include/linux/bug.h | 5 +++++ lib/Kconfig.debug | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/bug.h b/include/linux/bug.h index da4231c905c8..e170bda4db9f 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -71,4 +71,9 @@ static inline __must_check bool check_data_corruption(bool v) { return v; } corruption; \ })) +#ifdef CONFIG_PANIC_ON_DATA_CORRUPTION +#define PANIC_CORRUPTION 1 +#else +#define PANIC_CORRUPTION 0 +#endif /* CONFIG_PANIC_ON_DATA_CORRUPTION */ #endif /* _LINUX_BUG_H */ diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d87c2fa56ed5..7d0fa2f9f431 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -2061,6 +2061,13 @@ config BUG_ON_DATA_CORRUPTION If unsure, say N. +config PANIC_ON_DATA_CORRUPTION + bool "Cause a Kernel Panic When Data Corruption is detected" + help + Select this option to upgrade warnings for potentially + recoverable data corruption scenarios to system-halting panics, + for easier detection and debug. + source "samples/Kconfig" source "lib/Kconfig.kgdb" From 6bb52e3a37d89468cea093a596885c05f302937c Mon Sep 17 00:00:00 2001 From: Prasad Sodagudi Date: Thu, 25 Feb 2016 12:57:06 +0530 Subject: [PATCH 2/3] debug-pagealloc: Panic on pagealloc corruption Currently, we just print the pagealloc corruption warnings and proceed. Sometimes, we are getting multiple errors printed down the line. It will be good to get the device state as early as possible when we get the first pagealloc error. Change-Id: I79155ac8a039b30a3a98d5dd1384d3923082712f Signed-off-by: Subbaraman Narayanamurthy Signed-off-by: Prasad Sodagudi Signed-off-by: Patrick Daly Signed-off-by: Sudarshan Rajagopalan Signed-off-by: Isaac J. Manjarres --- mm/page_poison.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/page_poison.c b/mm/page_poison.c index 02e57748caf4..6d3c7418fbd1 100644 --- a/mm/page_poison.c +++ b/mm/page_poison.c @@ -84,6 +84,7 @@ static void check_poison_mem(struct page *page, print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 16, 1, start, end - start + 1, 1); + BUG_ON(PANIC_CORRUPTION); dump_stack(); } From 03ba34e0f7ae4e6cfc9e7bca588a42bec2a03635 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Tue, 13 Nov 2018 10:59:01 -0800 Subject: [PATCH 3/3] defconfig: Enable PANIC_ON_DATA_CORRUPTION on SM8150 Ensure that a panic occurs on SM8150 when data corruption is detected. Change-Id: Idf4a93db85087fefa4f572cce81143ee5e99c0fa Signed-off-by: Isaac J. Manjarres --- arch/arm64/configs/vendor/sm8150_defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/vendor/sm8150_defconfig b/arch/arm64/configs/vendor/sm8150_defconfig index 0b23036e2361..55f38e5c4b68 100644 --- a/arch/arm64/configs/vendor/sm8150_defconfig +++ b/arch/arm64/configs/vendor/sm8150_defconfig @@ -725,6 +725,7 @@ CONFIG_ATOMIC64_SELFTEST=m CONFIG_TEST_USER_COPY=m CONFIG_MEMTEST=y CONFIG_BUG_ON_DATA_CORRUPTION=y +CONFIG_PANIC_ON_DATA_CORRUPTION=y CONFIG_PID_IN_CONTEXTIDR=y CONFIG_ARM64_STRICT_BREAK_BEFORE_MAKE=y CONFIG_CORESIGHT=y