Skip to contentSkip to conversation

ia64: Depend on non-static printk for cmpxchg debug

PATCH In review Chris Down 2 participants 6 messages Feb 13, 2021 – Feb 26, 2021 Memory management

lore
Share & tools
lore

Chris Down

author
#0 lore raw

PATCH 1/1 ia64: Depend on non-static printk for cmpxchg debug

With !CONFIG_PRINTK, printk() is static in the header, but ia64's cmpxchg.h with CONFIG_IA64_DEBUG_CMPXCHG doesn't take this into account before trying to use it as extern, resulting in a compiler error:

    ./include/linux/printk.h:219:5: error: static declaration of 'printk' follows non-static declaration
    219 | int printk(const char *s, ...)
	|     ^~~~~~
    ./arch/ia64/include/uapi/asm/cmpxchg.h:142:14: note: previous declaration of 'printk' was here
    142 |   extern int printk(const char *fmt, ...);  \
	|              ^~~~~~

Make CONFIG_IA64_DEBUG_CMPXCHG dependent on CONFIG_PRINTK to avoid this.

---
 arch/ia64/Kconfig.debug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/Kconfig.debug +1 -1
index 40ca23bd228d..2ce008e2d164 100644
@@ -39,7 +39,7 @@ config DISABLE_VHPT
 
 config IA64_DEBUG_CMPXCHG
 	bool "Turn on compare-and-exchange bug checking (slow!)"
-	depends on DEBUG_KERNEL
+	depends on DEBUG_KERNEL && PRINTK
 	help
 	  Selecting this option turns on bug checking for the IA-64
 	  compare-and-exchange instructions.  This is slow!  Itaniums
Signature · 1 line
2.30.1
author
#1 lore raw

+ akpm, linux-mm

Hey folks,

Quoted 11 lines · Chris Down

With !CONFIG_PRINTK, printk() is static in the header, but ia64's cmpxchg.h with CONFIG_IA64_DEBUG_CMPXCHG doesn't take this into account before trying to use it as extern, resulting in a compiler error:

   ./include/linux/printk.h:219:5: error: static declaration of 'printk' follows non-static declaration
   219 | int printk(const char *s, ...)
	|     ^~~~~~
   ./arch/ia64/include/uapi/asm/cmpxchg.h:142:14: note: previous declaration of 'printk' was here
   142 |   extern int printk(const char *fmt, ...);  \
	|              ^~~~~~
Quoted 7 lines

Make CONFIG_IA64_DEBUG_CMPXCHG dependent on CONFIG_PRINTK to avoid this.

I now see that last month ia64 was marked as orphaned, so I'm going to send this over to Andrew/-mm.

Andrew, any chance you can take this in your tree? It's causing spurious LKP noise for some recent work on printk and would be great to have in -next.

Thanks,

Chris

Quoted 20 lines

---
arch/ia64/Kconfig.debug | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/Kconfig.debug +0 -0
index 40ca23bd228d..2ce008e2d164 100644
@@ -39,7 +39,7 @@ config DISABLE_VHPT
 

config IA64_DEBUG_CMPXCHG
bool "Turn on compare-and-exchange bug checking (slow!)"

arch/ia64/Kconfig.debug +1 -1
-	depends on DEBUG_KERNEL
+	depends on DEBUG_KERNEL && PRINTK

help
Selecting this option turns on bug checking for the IA-64 compare-and-exchange instructions. This is slow! Itaniums

Signature · 1 line
2.30.1
#2 lore raw
Quoted 8 lines · Chris Down
Quoted 8 lines
   ./include/linux/printk.h:219:5: error: static declaration of 'printk' follows non-static declaration
   219 | int printk(const char *s, ...)
	|     ^~~~~~
   ./arch/ia64/include/uapi/asm/cmpxchg.h:142:14: note: previous declaration of 'printk' was here
   142 |   extern int printk(const char *fmt, ...);  \
	|              ^~~~~~

Make CONFIG_IA64_DEBUG_CMPXCHG dependent on CONFIG_PRINTK to avoid this.

Why not just fix it?

arch/ia64/include/uapi/asm/cmpxchg.h +1 -1
index 5d90307fd6e0..d955a8e3ebde 100644
@@ -139,7 +139,7 @@ extern long ia64_cmpxchg_called_with_bad_pointer(void);
 do {									\
 	if (_cmpxchg_bugcheck_count-- <= 0) {				\
 		void *ip;						\
-		extern int printk(const char *fmt, ...);		\
+		int printk(const char *fmt, ...);			\
 		ip = (void *) ia64_getreg(_IA64_REG_IP);		\
 		printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));\
 		break;							\
author
#3 lore raw
Quoted 7 lines · Matthew Wilcox

Why not just fix it?

arch/ia64/include/uapi/asm/cmpxchg.h +0 -0
index 5d90307fd6e0..d955a8e3ebde 100644

arch/ia64/include/uapi/asm/cmpxchg.h extern long ia64_cmpxchg_called_with_bad_pointer(void); · line 145

Quoted 8 lines
arch/ia64/include/uapi/asm/cmpxchg.h +1 -1
@@ -139,7 +139,7 @@ extern long ia64_cmpxchg_called_with_bad_pointer(void);
 do {									\
 	if (_cmpxchg_bugcheck_count-- <= 0) {				\
 		void *ip;						\
-		extern int printk(const char *fmt, ...);		\
+		int printk(const char *fmt, ...);			\
 		ip = (void *) ia64_getreg(_IA64_REG_IP);		\
 		printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v));\
 		break;							\

I must confess I have no idea of the history of why it was extern int in the first place -- my fear was somehow we use cmpxchg.h from a different context. Do you have any idea? :-)

author
#4 lore raw
Quoted 3 lines · Chris Down

I must confess I have no idea of the history of why it was extern int in the first place -- my fear was somehow we use cmpxchg.h from a different context. Do you have any idea? :-)

Ok, found where it's introduced in the pre-git archives: "New file asm-ia64/intrinsics.h." from David Mosberger <[email protected]>, Dec 9 2002. No indication why it's extern, but it's been there since the dawn of ia64.

#5 lore raw
Quoted 9 lines · Chris Down
Quoted 3 lines · Chris Down

I must confess I have no idea of the history of why it was extern int in the first place -- my fear was somehow we use cmpxchg.h from a different context. Do you have any idea? :-)

Ok, found where it's introduced in the pre-git archives: "New file asm-ia64/intrinsics.h." from David Mosberger <[email protected]>, Dec 9 2002. No indication why it's extern, but it's been there since the dawn of ia64.

It's just a quirk of C. 'extern' is only meaningful when applied to variables. In the context of functions,

extern int printk(char *fmt);
int printk(char *fmt);

are completely equivalent. Unless (as you've seen) there's then a static definition following the extern declaration.