From nobody Tue Apr 7 05:41:10 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A4C234DB7E for ; Sun, 15 Mar 2026 19:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604188; cv=pass; b=O0/dY73FQWK4TAi6rb2+3784mo//7PNVRJAxl6WFI/tsfwZRq7xXzApFgqf7dCYp7hV03P5o5Sbt28DuePbRqdtGUpAGBB8HHWAWUaPsqOA9Vo8q955xzUoI4Z85up6pUSZqMo4+3o+cB5Tg10SKorgbxT14VqacuP8dTl8bM1U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604188; c=relaxed/simple; bh=xFD5P1+tpNL46pqEf5qsQVrgFdcnBmrl4/ErncUESJI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iSqIPMKZxL8tNLrAJbjxe+cPLlqhtcX7pI4aLXEWK1pOM6UBKHGU82WS/PlIbnlGxIWF/aGTihE2r2wrI76wXv84vcjArU+OkFIEIVnGSArvoZPrF2qKrCU3zYp7PSZN08tPFIa0o7hxp5eARY71Sh4slUruXBoSp4+ousxX1pQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=fv532EsX; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="fv532EsX" ARC-Seal: i=1; a=rsa-sha256; t=1773604183; cv=none; d=zohomail.eu; s=zohoarc; b=Vq7HPeEF/ti2OTQwPQcRya/828cP5qkwYGmtGjZR1Kz2btVpMNu9+/+yEMvIYPTZhBkHUQpCW279Kt4uGviKJOBItb3Md6tiwfT/B2zA1pGg9SLjYVtuvXGwluie/3watfEN9o/aySjaorSAdtn2MGaA02qMbKHjALNxL+J/ktU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773604183; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=soJiT+wuPoOk0Vq2USNg5BuzIP78RwRfNPkF/XuwJmQ=; b=Fl7wd6g2/5BT31+2BivM9rRvqt69FZC7FvVWn/jSfqAxOk/WsAa57anYd+qOvuKOQqXhhu2v9fIeld/HAwuB9CiCCVIAMxL05xy5f6Cg+L67JoadQdSXWSS2D/Ide7LTE2+ix4RpHo5n0h9GiZvi2hJMYSfy2wxpJ8JICVrKxGQ= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773604183; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=soJiT+wuPoOk0Vq2USNg5BuzIP78RwRfNPkF/XuwJmQ=; b=fv532EsXuBlkX2GUylurFgxkMZeVyeRWnk2DYDik5W6FkvM32ewzukf3c6fl0BaR Jg9iEn5D4huZBmpNYJjPLCiJP9V2AgyXylo/SJdznunHtjVWNUOI0o/t51yfWARWKiJ qy/BnFtDX0wGQlI7zG8AvezF0x3yji6NotoVl1Do= Received: by mx.zoho.eu with SMTPS id 1773604181959146.8462308732344; Sun, 15 Mar 2026 20:49:41 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/3] lib/bug: annotate concurrent access to bug->flags with READ_ONCE/WRITE_ONCE Date: Sun, 15 Mar 2026 19:49:37 +0000 Message-Id: <20260315194939.328612-2-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315194939.328612-1-objecting@objecting.org> References: <20260315194939.328612-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Multiple CPUs can hit a WARN_ON_ONCE simultaneously, causing concurrent reads and writes to bug->flags without synchronization. In __report_bug(), the flags are read to check BUGFLAG_DONE and then BUGFLAG_DONE is set via a plain read-modify-write. The race is benign since the store is idempotent, but KCSAN will flag this as a data race. Read the flags once with READ_ONCE and reuse the cached value for both the flag checks and the WRITE_ONCE store. Also annotate the concurrent clear in clear_once_table(). Update the misleading comment that claimed concurrency is not an issue. Signed-off-by: Josh Law --- lib/bug.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/bug.c b/lib/bug.c index bbc301097749..037c7370dadf 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -201,6 +201,7 @@ static enum bug_trap_type __report_bug(struct bug_entry= *bug, unsigned long buga { bool warning, once, done, no_cut, has_args; const char *file, *fmt; + unsigned short flags; unsigned line; =20 if (!bug) { @@ -217,20 +218,24 @@ static enum bug_trap_type __report_bug(struct bug_ent= ry *bug, unsigned long buga bug_get_file_line(bug, &file, &line); fmt =3D bug_get_format(bug); =20 - warning =3D bug->flags & BUGFLAG_WARNING; - once =3D bug->flags & BUGFLAG_ONCE; - done =3D bug->flags & BUGFLAG_DONE; - no_cut =3D bug->flags & BUGFLAG_NO_CUT_HERE; - has_args =3D bug->flags & BUGFLAG_ARGS; + flags =3D READ_ONCE(bug->flags); + warning =3D flags & BUGFLAG_WARNING; + once =3D flags & BUGFLAG_ONCE; + done =3D flags & BUGFLAG_DONE; + no_cut =3D flags & BUGFLAG_NO_CUT_HERE; + has_args =3D flags & BUGFLAG_ARGS; =20 if (warning && once) { if (done) return BUG_TRAP_TYPE_WARN; =20 /* - * Since this is the only store, concurrency is not an issue. + * Multiple CPUs can hit a WARN_ON_ONCE at the same time + * and both read done =3D=3D false. The race is benign: setting + * BUGFLAG_DONE is idempotent, and the worst case is that + * the warning prints a few extra times. */ - bug->flags |=3D BUGFLAG_DONE; + WRITE_ONCE(bug->flags, flags | BUGFLAG_DONE); } =20 /* @@ -289,7 +294,7 @@ static void clear_once_table(struct bug_entry *start, s= truct bug_entry *end) struct bug_entry *bug; =20 for (bug =3D start; bug < end; bug++) - bug->flags &=3D ~BUGFLAG_DONE; + WRITE_ONCE(bug->flags, READ_ONCE(bug->flags) & ~BUGFLAG_DONE); } =20 void generic_bug_clear_once(void) --=20 2.34.1 From nobody Tue Apr 7 05:41:10 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEA4137AA87 for ; Sun, 15 Mar 2026 19:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604190; cv=pass; b=aat9BVpqyvqNIUXiRrcjG5y4DtSn0oj2BrPgxE/JVF00Dp9kFVpaC8I9Lg9EgTqN4TW6Hbre2JLAbklq2PwDjLj5Xzdz03yewIo051/hqHNw34BfGV8gdqlyl5jFzAMpdEtiNm6nV1lncTg5lMdpYMoFlCJkYgolwSYKhk7KCvM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604190; c=relaxed/simple; bh=ceHDJrV/Ow1FjsNv2KUJMNvx1wofLpJllq3T11dMCJc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tKtjDXiqR08Jj9J29b3b7NiN2IKA7Gtcofw7fSp+U8rW88GsVCIOhBrFkiDlh+5qUaPMi0w1CzSr9hbNglNbeAZlLaz5Bb8ub5K2NJ9rGBURQMYGHM4GCKgynjD/1siJ2o2H3cQDTSd6ptB1rvhGLTH/JDULsUhm5//nI4YBQWU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=Sl4ie/M5; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="Sl4ie/M5" ARC-Seal: i=1; a=rsa-sha256; t=1773604185; cv=none; d=zohomail.eu; s=zohoarc; b=KLobWLjEUBjtZRFa4F+IiHDM6lSMr879xaIPRjtetiOKOmVb8HP3+YLXfz2bxf425VRwd6+hI7chpYmGPkr9ZFq+0nxF9vj5IghwGgbi/9q7WN7m9WIOJK8lb+rHgyjm9DC6dj7d1bNEjhBXv9PFMssNR9vQ2TML+93BWxB4F2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773604185; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=NqxDRTNV/L3c9CWZ3ELpPehGVlNoCCM9yiNwIrCeCco=; b=Wj0bme2JCWgpo20+mDjaSzDWmkqXh27+rGX2TPJWn6zFRA5TsHO22h6QcEDHAOEQzvnPy6sxtQaiYtGMMZbJXNcFDqkyPZwgZ+nsLQrCp+yRh6s3urFUGLQsbFXZud+8eFd4fHyFI9QoJWaL+YuXOxvCtg4ybacWiHAfwSbF0NI= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773604185; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=NqxDRTNV/L3c9CWZ3ELpPehGVlNoCCM9yiNwIrCeCco=; b=Sl4ie/M5CktE6OjM6le77TSqokpb0O0IdjAxFW7sgSVahkkz1bCKKyra82JuDkE4 3o5bfGyBM/+NLUvOqcQHAJmEFAXO+mVcX8FpuGx4G3WAGMo+y6FUUMhVVWsxJajzN8h NzF+LSHsHYBVkEI/I1Y74+RLRwhMTz9hbukIxcho= Received: by mx.zoho.eu with SMTPS id 1773604182389566.6627430550266; Sun, 15 Mar 2026 20:49:42 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/3] lib/bug: clean up types in bug reporting helpers Date: Sun, 15 Mar 2026 19:49:38 +0000 Message-Id: <20260315194939.328612-3-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315194939.328612-1-objecting@objecting.org> References: <20260315194939.328612-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Add const to the bug_entry parameter of bug_get_file_line() and bug_get_format() since they only read from the structure. Update the declaration in include/linux/bug.h to match. While here, replace bare 'unsigned' with 'unsigned int' for the loop counter in module_find_bug() and the line number in __report_bug(). Signed-off-by: Josh Law --- include/linux/bug.h | 6 +++--- lib/bug.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/bug.h b/include/linux/bug.h index 17a4933c611b..01a996eed8d8 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -36,7 +36,7 @@ static inline int is_warning_bug(const struct bug_entry *= bug) return bug->flags & BUGFLAG_WARNING; } =20 -void bug_get_file_line(struct bug_entry *bug, const char **file, +void bug_get_file_line(const struct bug_entry *bug, const char **file, unsigned int *line); =20 struct bug_entry *find_bug(unsigned long bugaddr); @@ -70,8 +70,8 @@ report_bug_entry(struct bug_entry *bug, struct pt_regs *r= egs) return BUG_TRAP_TYPE_BUG; } =20 -static inline void bug_get_file_line(struct bug_entry *bug, const char **f= ile, - unsigned int *line) +static inline void bug_get_file_line(const struct bug_entry *bug, + const char **file, unsigned int *line) { *file =3D NULL; *line =3D 0; diff --git a/lib/bug.c b/lib/bug.c index 037c7370dadf..9d76703ff7d1 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -71,7 +71,7 @@ static struct bug_entry *module_find_bug(unsigned long bu= gaddr) =20 guard(rcu)(); list_for_each_entry_rcu(mod, &module_bug_list, bug_list) { - unsigned i; + unsigned int i; =20 bug =3D mod->bug_table; for (i =3D 0; i < mod->num_bugs; ++i, ++bug) @@ -123,7 +123,7 @@ static inline struct bug_entry *module_find_bug(unsigne= d long bugaddr) } #endif =20 -void bug_get_file_line(struct bug_entry *bug, const char **file, +void bug_get_file_line(const struct bug_entry *bug, const char **file, unsigned int *line) { #ifdef CONFIG_DEBUG_BUGVERBOSE @@ -139,7 +139,7 @@ void bug_get_file_line(struct bug_entry *bug, const cha= r **file, #endif } =20 -static const char *bug_get_format(struct bug_entry *bug) +static const char *bug_get_format(const struct bug_entry *bug) { const char *format =3D NULL; #ifdef HAVE_ARCH_BUG_FORMAT @@ -202,7 +202,7 @@ static enum bug_trap_type __report_bug(struct bug_entry= *bug, unsigned long buga bool warning, once, done, no_cut, has_args; const char *file, *fmt; unsigned short flags; - unsigned line; + unsigned int line; =20 if (!bug) { if (!is_valid_bugaddr(bugaddr)) --=20 2.34.1 From nobody Tue Apr 7 05:41:10 2026 Received: from sender-of-o57.zoho.eu (sender-of-o57.zoho.eu [136.143.169.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C64CA371D07 for ; Sun, 15 Mar 2026 19:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.169.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604188; cv=pass; b=PKJAfKDJSsgsDUEMDjY3mQCC2AMEhUXdY/6PPHGEE5OQ/LWA3MySboJ7l/W8nGGkllNr26SSpX1M35YksXeP5yhJeVbKnjf+W7ljMStl4fZpDyRwHL1AS5rTXm7JlMrS1eqtQi+mVTyaqjWdMUmEflCnufvHwCKUsNE9osrjgLo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773604188; c=relaxed/simple; bh=BBOQZ7uYXbkZn1hEqJNOJPVr4KqZobF+zb1z7VaY5iw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JtLkI7ahgrOyj0/WuOjlX5i7M5PbKDYTLbjnH+sg9ejwTK/Q+IV6qF3H6UeJhVoXOFdu6xRiUltx/qVekUQqSZhx5bfJi6mIiOfVIyu3VA/w2wX1K0SP4rFkDtzJ/lGa9eI9t314rKpE8TTekNXKIk6EILWDTOTVZYX9BipK5dw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org; spf=pass smtp.mailfrom=objecting.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b=dePFBTm5; arc=pass smtp.client-ip=136.143.169.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=objecting.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=objecting.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=objecting.org header.i=objecting@objecting.org header.b="dePFBTm5" ARC-Seal: i=1; a=rsa-sha256; t=1773604184; cv=none; d=zohomail.eu; s=zohoarc; b=eRK6eZGHbRgPcbNVmsPHgButjmUpLqnJrgyJO8vzcOkt2TSi4CHfXFZUjhycRGuNP8e3ZyoeKO3P4tYI4DM5X4pExTVccwRL5HXSyDoeOrFQY0BdWUGpWsaTWb+gjmJzeNEo+8rKeXoguX/Z5jto5WDUQis6FYTBIY3IG8fFZcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1773604184; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=LXNHmlwozEZ7/B2Ox6/fvQuinccYbS0cEoN/uh1FurQ=; b=LceHM/ypp0lqnwZHa5yLhMSGFwoU8BDhbpvg3jj87Mwawd2f+h5cUVMstVfMEqD+7c+xz33N7f9y+jq5v4O/U1R2mPbCk7eHUeZbO30zC2OMnOEIbH6LjkddSxtzThxZbO3pBFX921dNvTDEXqXEEqG+ir8c70einsDFpK2x8rI= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=objecting.org; spf=pass smtp.mailfrom=objecting@objecting.org; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773604184; s=zmail; d=objecting.org; i=objecting@objecting.org; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=LXNHmlwozEZ7/B2Ox6/fvQuinccYbS0cEoN/uh1FurQ=; b=dePFBTm5+lDHTHaw7GGxNBJdnreSnKmRhg/u5ds/2T8HkjOWm7RHNkkyGXeIH2dv oT7fLn2h2WLp6yab/RZhByfqVKQ0/LMiJiOKRvT7jzD/2jJTsgBbwwFRw0xBrqsOv3s 6Fw4Y2ctsakNkS6UenMsfXmFfxh8KEGXxs9x6hCw= Received: by mx.zoho.eu with SMTPS id 1773604182786489.602244670524; Sun, 15 Mar 2026 20:49:42 +0100 (CET) From: Josh Law To: Andrew Morton , Josh Law Cc: linux-kernel@vger.kernel.org Subject: [PATCH 3/3] lib/bug: add debugfs interface to list all BUG/WARN sites Date: Sun, 15 Mar 2026 19:49:39 +0000 Message-Id: <20260315194939.328612-4-objecting@objecting.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260315194939.328612-1-objecting@objecting.org> References: <20260315194939.328612-1-objecting@objecting.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Currently there is no way to inspect the runtime state of WARN_ONCE sites. The existing clear_warn_once debugfs file lets operators reset them, but there is no counterpart to see which sites exist or which have already fired. On production systems this matters: when a WARN_ONCE fires during a transient event, the only evidence is a single dmesg line that may have already rotated out. Operators investigating later have no way to tell which WARN_ONCE sites have tripped without rebooting or reproducing the issue. Add /sys/kernel/debug/bug_sites which lists every registered BUG() and WARN() site in the kernel, including those from loaded modules. Each line shows the symbolized address, source location (file:line when CONFIG_DEBUG_BUGVERBOSE is enabled), type and state flags, and the module name if applicable. Example output: func+0x10/0x20 kernel/foo.c:123 warn,once,done bar+0x5/0x10 drivers/baz.c:456 warn [baz_mod] The "done" flag indicates that a WARN_ONCE site has fired at least once since boot (or since the last clear_warn_once), giving operators a reliable way to audit warning state on a running system without depending on log retention. Signed-off-by: Josh Law --- lib/bug.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/lib/bug.c b/lib/bug.c index 9d76703ff7d1..ddf4531d6661 100644 --- a/lib/bug.c +++ b/lib/bug.c @@ -48,6 +48,8 @@ #include #include #include +#include +#include =20 extern struct bug_entry __start___bug_table[], __stop___bug_table[]; =20 @@ -311,3 +313,68 @@ void generic_bug_clear_once(void) =20 clear_once_table(__start___bug_table, __stop___bug_table); } + +#ifdef CONFIG_DEBUG_FS +static void bug_show_entry(struct seq_file *m, const struct bug_entry *bug, + const char *modname) +{ + const char *file; + unsigned int line; + unsigned short flags =3D READ_ONCE(bug->flags); + + bug_get_file_line(bug, &file, &line); + + seq_printf(m, "%pS\t", (void *)bug_addr(bug)); + + if (file) + seq_printf(m, "%s:%u\t", file, line); + else + seq_puts(m, "-\t"); + + if (flags & BUGFLAG_WARNING) + seq_puts(m, "warn"); + else + seq_puts(m, "bug"); + if (flags & BUGFLAG_ONCE) + seq_puts(m, ",once"); + if (flags & BUGFLAG_DONE) + seq_puts(m, ",done"); + + if (modname) + seq_printf(m, "\t[%s]", modname); + + seq_putc(m, '\n'); +} + +static int bug_sites_show(struct seq_file *m, void *v) +{ + struct bug_entry *bug; + + for (bug =3D __start___bug_table; bug < __stop___bug_table; bug++) + bug_show_entry(m, bug, NULL); + +#ifdef CONFIG_MODULES + { + struct module *mod; + unsigned int i; + + rcu_read_lock(); + list_for_each_entry_rcu(mod, &module_bug_list, bug_list) + for (i =3D 0; i < mod->num_bugs; i++) + bug_show_entry(m, &mod->bug_table[i], + mod->name); + rcu_read_unlock(); + } +#endif + + return 0; +} +DEFINE_SHOW_ATTRIBUTE(bug_sites); + +static int __init bug_debugfs_init(void) +{ + debugfs_create_file("bug_sites", 0444, NULL, NULL, &bug_sites_fops); + return 0; +} +device_initcall(bug_debugfs_init); +#endif /* CONFIG_DEBUG_FS */ --=20 2.34.1