Thread (45 messages) 45 messages, 15 authors, 2025-04-26

Re: [PATCH v4 07/14] arm64: Add support for suppressing warning backtraces

From: Christophe Leroy <hidden>
Date: 2025-03-19 08:20:04
Also in: dri-devel, linux-arch, linux-arm-kernel, linux-doc, linux-kselftest, linux-riscv, linux-s390, linux-sh, lkml, loongarch


Le 18/03/2025 à 16:59, Will Deacon a écrit :
On Thu, Mar 13, 2025 at 05:40:59PM +0100, Alessandro Carminati wrote:
quoted
On Thu, Mar 13, 2025 at 1:25 PM Will Deacon [off-list ref] wrote:
quoted
On Thu, Mar 13, 2025 at 11:43:22AM +0000, Alessandro Carminati wrote:
quoted
diff --git a/arch/arm64/include/asm/bug.h b/arch/arm64/include/asm/bug.h
index 28be048db3f6..044c5e24a17d 100644
--- a/arch/arm64/include/asm/bug.h
+++ b/arch/arm64/include/asm/bug.h
@@ -11,8 +11,14 @@

  #include <asm/asm-bug.h>

+#ifdef HAVE_BUG_FUNCTION
+# define __BUG_FUNC  __func__
+#else
+# define __BUG_FUNC  NULL
+#endif
+
  #define __BUG_FLAGS(flags)                           \
-     asm volatile (__stringify(ASM_BUG_FLAGS(flags)));
+     asm volatile (__stringify(ASM_BUG_FLAGS(flags, %c0)) : : "i" (__BUG_FUNC));
Why is 'i' the right asm constraint to use here? It seems a bit odd to
use that for a pointer.
I received this code as legacy from a previous version.
In my review, I considered the case when HAVE_BUG_FUNCTION is defined:
Here, __BUG_FUNC is defined as __func__, which is the name of the
current function as a string literal.
Using the constraint "i" seems appropriate to me in this case.

However, when HAVE_BUG_FUNCTION is not defined:
__BUG_FUNC is defined as NULL. Initially, I considered it literal 0,
but after investigating your concern, I found:
$ echo -E "#include <stdio.h>\n#include <stddef.h>\nint main()
{\nreturn 0;\n}" | aarch64-linux-gnu-gcc -E -dM - | grep NULL
#define NULL ((void *)0)
I realized that NULL is actually a pointer that is not a link time
symbol, and using the "i" constraint with NULL may result in undefined
behavior.

Would the following alternative definition for __BUG_FUNC be more convincing?
#ifdef HAVE_BUG_FUNCTION
     #define __BUG_FUNC __func__
#else
     #define __BUG_FUNC (uintptr_t)0
#endif
Let me know your thoughts.
Thanks for the analysis; I hadn't noticed this specific issue, it just
smelled a bit fishy. Anyway, the diff above looks better, thanks.
That propably deserves a comment.

Doesn't sparse and/or checkpatch complain about 0 being used in lieu of 
NULL ?

By the way I had similar problem in the past with GCC not seeing NULL as 
a __builtin_constant_p(), refer commit 1d8f739b07bd ("powerpc/kuap: Fix 
set direction in allow/prevent_user_access()")

Christophe
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help