git: 8ababf739aa9 - stable/13 - LinuxKPI: Add sysctl(8) knob to control verbosity of WARN_ON's.

From: Hans Petter Selasky <hselasky_at_FreeBSD.org>
Date: Fri, 12 Nov 2021 14:36:56 UTC
The branch stable/13 has been updated by hselasky:

URL: https://cgit.FreeBSD.org/src/commit/?id=8ababf739aa903934a1b85c10fa7bee59eb57369

commit 8ababf739aa903934a1b85c10fa7bee59eb57369
Author:     Hans Petter Selasky <hselasky@FreeBSD.org>
AuthorDate: 2021-11-02 15:52:46 +0000
Commit:     Hans Petter Selasky <hselasky@FreeBSD.org>
CommitDate: 2021-11-12 14:31:24 +0000

    LinuxKPI: Add sysctl(8) knob to control verbosity of WARN_ON's.
    
    The purpose of this change is to reduce the amount of dmesg(8) noise when
    VT switching after a panic.
    
    Submitted by:   Greg V <greg@unrelenting.technology>
    Differential Revision:  https://reviews.freebsd.org/D30174
    Sponsored by:   NVIDIA Networking
    
    (cherry picked from commit 2390a1441effaba0e3d0f2f447f448aaf20428f1)
---
 sys/compat/linuxkpi/common/include/linux/kernel.h | 25 +++++++++++++----------
 sys/compat/linuxkpi/common/src/linux_compat.c     |  5 +++++
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/kernel.h b/sys/compat/linuxkpi/common/include/linux/kernel.h
index aba5896111f7..0909e7fb78f3 100644
--- a/sys/compat/linuxkpi/common/include/linux/kernel.h
+++ b/sys/compat/linuxkpi/common/include/linux/kernel.h
@@ -121,28 +121,31 @@ extern const volatile int lkpi_build_bug_on_zero;
 	}							\
 } while (0)
 
+extern int linuxkpi_warn_dump_stack;
 #define	WARN_ON(cond) ({					\
-      bool __ret = (cond);					\
-      if (__ret) {						\
+	bool __ret = (cond);					\
+	if (__ret) {						\
 		printf("WARNING %s failed at %s:%d\n",		\
 		    __stringify(cond), __FILE__, __LINE__);	\
-		linux_dump_stack();				\
-      }								\
-      unlikely(__ret);						\
+		if (linuxkpi_warn_dump_stack)				\
+			linux_dump_stack();				\
+	}								\
+	unlikely(__ret);						\
 })
 
 #define	WARN_ON_SMP(cond)	WARN_ON(cond)
 
 #define	WARN_ON_ONCE(cond) ({					\
-      static bool __warn_on_once;				\
-      bool __ret = (cond);					\
-      if (__ret && !__warn_on_once) {				\
+	static bool __warn_on_once;				\
+	bool __ret = (cond);					\
+	if (__ret && !__warn_on_once) {				\
 		__warn_on_once = 1;				\
 		printf("WARNING %s failed at %s:%d\n",		\
 		    __stringify(cond), __FILE__, __LINE__);	\
-		linux_dump_stack();				\
-      }								\
-      unlikely(__ret);						\
+		if (linuxkpi_warn_dump_stack)				\
+			linux_dump_stack();				\
+	}								\
+	unlikely(__ret);						\
 })
 
 #define	oops_in_progress	SCHEDULER_STOPPED()
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index a1462c6a7010..45b149a08ae8 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -102,6 +102,11 @@ int linuxkpi_debug;
 SYSCTL_INT(_compat_linuxkpi, OID_AUTO, debug, CTLFLAG_RWTUN,
     &linuxkpi_debug, 0, "Set to enable pr_debug() prints. Clear to disable.");
 
+int linuxkpi_warn_dump_stack = 0;
+SYSCTL_INT(_compat_linuxkpi, OID_AUTO, warn_dump_stack, CTLFLAG_RWTUN,
+    &linuxkpi_warn_dump_stack, 0,
+    "Set to enable stack traces from WARN_ON(). Clear to disable.");
+
 static struct timeval lkpi_net_lastlog;
 static int lkpi_net_curpps;
 static int lkpi_net_maxpps = 99;