Thread (6 messages) 6 messages, 3 authors, 2020-11-30

Re: [PATCH] powerpc: Allow relative pointers in bug table entries

From: Christophe Leroy <hidden>
Date: 2020-11-28 19:02:30


Le 27/11/2020 à 04:02, Jordan Niethe a écrit :
quoted hunk ↗ jump to hunk
This enables GENERIC_BUG_RELATIVE_POINTERS on Power so that 32-bit
offsets are stored in the bug entries rather than 64-bit pointers.

Signed-off-by: Jordan Niethe <redacted>
---
  arch/powerpc/Kconfig           |  4 ++++
  arch/powerpc/include/asm/bug.h | 37 ++++++++++++++++++++++++++++++++--
  arch/powerpc/xmon/xmon.c       | 17 ++++++++++++++--
  3 files changed, 54 insertions(+), 4 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index e9f13fe08492..294108e0e5c6 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -311,6 +311,10 @@ config GENERIC_BUG
  	default y
  	depends on BUG
  
+config GENERIC_BUG_RELATIVE_POINTERS
+	def_bool y
+	depends on GENERIC_BUG
+
  config SYS_SUPPORTS_APM_EMULATION
  	default y if PMAC_APM_EMU
  	bool
diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 338f36cd9934..d03d834042a1 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -12,7 +12,11 @@
  #ifdef CONFIG_DEBUG_BUGVERBOSE
  .macro EMIT_BUG_ENTRY addr,file,line,flags
  	 .section __bug_table,"aw"
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
As far as I understand, as soon as CONFIG_BUG is selected, GENERIC_BUG is automatically selected so 
GENERIC_BUG_RELATIVE_POINTERS is selected as well. Therefore this #ifndef is never possible.
quoted hunk ↗ jump to hunk
  5001:	 PPC_LONG \addr, 5002f
+#else
+5001:	 .4byte \addr - 5001b, 5002f - 5001b
+#endif /* CONFIG_GENERIC_BUG_RELATIVE_POINTERS */
  	 .short \line, \flags
  	 .org 5001b+BUG_ENTRY_SIZE
  	 .previous
@@ -23,7 +27,11 @@
  #else
  .macro EMIT_BUG_ENTRY addr,file,line,flags
  	 .section __bug_table,"aw"
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
Same
quoted hunk ↗ jump to hunk
  5001:	 PPC_LONG \addr
+#else
+5001:	 .4byte \addr - 5001b
+#endif /* CONFIG_GENERIC_BUG_RELATIVE_POINTERS */
  	 .short \flags
  	 .org 5001b+BUG_ENTRY_SIZE
  	 .previous
@@ -34,20 +42,45 @@
  /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
     sizeof(struct bug_entry), respectively */
  #ifdef CONFIG_DEBUG_BUGVERBOSE
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
Same
  #define _EMIT_BUG_ENTRY				\
  	".section __bug_table,\"aw\"\n"		\
  	"2:\t" PPC_LONG "1b, %0\n"		\
  	"\t.short %1, %2\n"			\
  	".org 2b+%3\n"				\
  	".previous\n"
-#else
+
+#else /* relative pointers */
+
+#define _EMIT_BUG_ENTRY				\
+	".section __bug_table,\"aw\"\n"		\
+	"2:\t.4byte 1b - 2b, %0 - 2b\n"		\
+	"\t.short %1, %2\n"			\
+	".org 2b+%3\n"				\
+	".previous\n"
+#endif /* relative pointers */
+
+#else /* verbose */
+
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
Same
quoted hunk ↗ jump to hunk
  #define _EMIT_BUG_ENTRY				\
  	".section __bug_table,\"aw\"\n"		\
  	"2:\t" PPC_LONG "1b\n"			\
  	"\t.short %2\n"				\
  	".org 2b+%3\n"				\
  	".previous\n"
-#endif
+
+#else /* relative pointers */
+
+#define _EMIT_BUG_ENTRY				\
+	".section __bug_table,\"aw\"\n"		\
+	"2:\t.4byte 1b - 2b\n"		\
+	"\t.short %2\n"				\
+	".org 2b+%3\n"				\
+	".previous\n"
+
+#endif /* relative pointers */
+#endif /* verbose */
  
  #define BUG_ENTRY(insn, flags, ...)			\
  	__asm__ __volatile__(				\
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index 55c43a6c9111..5f7cf7e95767 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -1731,6 +1731,9 @@ static void print_bug_trap(struct pt_regs *regs)
  #ifdef CONFIG_BUG
  	const struct bug_entry *bug;
  	unsigned long addr;
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+	char *file;
+#endif
  
  	if (regs->msr & MSR_PR)
  		return;		/* not in kernel */
@@ -1744,10 +1747,20 @@ static void print_bug_trap(struct pt_regs *regs)
  		return;
  
  #ifdef CONFIG_DEBUG_BUGVERBOSE
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
Same
+	file = bug->file;
+#else /* relative pointers */
+	file = (char *)bug + bug->file_disp;
+#endif /* relative pointers */
  	printf("kernel BUG at %s:%u!\n",
-	       bug->file, bug->line);
+	       file, bug->line);
  #else
-	printf("kernel BUG at %px!\n", (void *)bug->bug_addr);
+#ifndef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
Same
+	addr = bug->addr;
+#else /* relative pointers */
+	addr = (unsigned long)bug + bug->bug_addr_disp;
+#endif /* relative pointers */
+	printf("kernel BUG at %px!\n", (void *)addr);
  #endif
  #endif /* CONFIG_BUG */
  }
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