mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] alpha: cleanup obsolete stack debugging code from lib/
@ 2026-12-05  2:11 Julian Braha
  2026-12-05 13:34 ` Magnus Lindholm
  0 siblings, 1 reply; 2+ messages in thread
From: Julian Braha @ 2026-12-05  2:11 UTC (permalink / raw)
  To: richard.henderson, mattst88, linmag7
  Cc: linux-alpha, linux-kernel, Julian Braha

The 3 files stacktrace.c, dbg_stackkill.S, and dbg_stackcheck.S are
currently dead code. No Makefile references them, no other C file
includes them, and they can't be built manually.

stacktrace.c has failed to build since commit ec2212088c42 ("Disintegrate
asm/system.h for Alpha") moved START_ADDR from <asm/system.h> to
<asm/setup.h>, and stackcheck.S failed to assemble and stackkill.S failed
to link since pre-git commit 374eeee8a8a5 ("Update Alpha UP for
thread_info and scheduler changes.") [1] because the offset generator
stopped emitting TASK_SIZE and STACK_SIZE.

Let's clean up this dead code.

Link: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=374eeee8a8a50e12278dfa37021df7b6efe506c3 [1]
Signed-off-by: Julian Braha <julianbraha@gmail.com>
---
 arch/alpha/lib/dbg_stackcheck.S |  28 ---------
 arch/alpha/lib/dbg_stackkill.S  |  36 -----------
 arch/alpha/lib/stacktrace.c     | 103 --------------------------------
 3 files changed, 167 deletions(-)
 delete mode 100644 arch/alpha/lib/dbg_stackcheck.S
 delete mode 100644 arch/alpha/lib/dbg_stackkill.S
 delete mode 100644 arch/alpha/lib/stacktrace.c

diff --git a/arch/alpha/lib/dbg_stackcheck.S b/arch/alpha/lib/dbg_stackcheck.S
deleted file mode 100644
index b3b6fc94f7f3..000000000000
--- a/arch/alpha/lib/dbg_stackcheck.S
+++ /dev/null
@@ -1,28 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * arch/alpha/lib/dbg_stackcheck.S
- * Contributed by Richard Henderson (rth@tamu.edu)
- *
- * Verify that we have not overflowed the stack.  Oops if we have.
- */
-
-#include <asm/asm-offsets.h>
-
-	.text
-	.set noat
-
-	.align 3
-	.globl _mcount
-	.ent _mcount
-_mcount:
-	.frame $30, 0, $28, 0
-	.prologue 0
-
-	lda	$0, TASK_SIZE($8)
-	cmpult	$30, $0, $0
-	bne	$0, 1f
-	ret	($28)
-1:	stq	$31, -8($31)	# oops me, damn it.
-	br	1b
-
-	.end _mcount
diff --git a/arch/alpha/lib/dbg_stackkill.S b/arch/alpha/lib/dbg_stackkill.S
deleted file mode 100644
index 6d9197e52a42..000000000000
--- a/arch/alpha/lib/dbg_stackkill.S
+++ /dev/null
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * arch/alpha/lib/dbg_stackkill.S
- * Contributed by Richard Henderson (rth@cygnus.com)
- *
- * Clobber the balance of the kernel stack, hoping to catch
- * uninitialized local variables in the act.
- */
-
-#include <asm/asm-offsets.h>
-
-	.text
-	.set noat
-
-	.align 5
-	.globl _mcount
-	.ent _mcount
-_mcount:
-	.frame $30, 0, $28, 0
-	.prologue 0
-
-	ldi	$0, 0xdeadbeef
-	lda	$2, -STACK_SIZE
-	sll	$0, 32, $1
-	and	$30, $2, $2
-	or	$0, $1, $0
-	lda	$2, TASK_SIZE($2)
-	cmpult	$2, $30, $1
-	beq	$1, 2f
-1:	stq	$0, 0($2)
-	addq	$2, 8, $2
-	cmpult	$2, $30, $1
-	bne	$1, 1b
-2:	ret	($28)
-
-	.end _mcount
diff --git a/arch/alpha/lib/stacktrace.c b/arch/alpha/lib/stacktrace.c
deleted file mode 100644
index 2b1176dd5174..000000000000
--- a/arch/alpha/lib/stacktrace.c
+++ /dev/null
@@ -1,103 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <linux/kernel.h>
-
-typedef unsigned int instr;
-
-#define MAJOR_OP	0xfc000000
-#define LDA_OP		0x20000000
-#define STQ_OP		0xb4000000
-#define BR_OP		0xc0000000
-
-#define STK_ALLOC_1	0x23de8000 /* lda $30,-X($30) */
-#define STK_ALLOC_1M	0xffff8000
-#define STK_ALLOC_2	0x43c0153e /* subq $30,X,$30 */
-#define STK_ALLOC_2M	0xffe01fff
-
-#define MEM_REG		0x03e00000
-#define MEM_BASE	0x001f0000
-#define MEM_OFF		0x0000ffff
-#define MEM_OFF_SIGN	0x00008000
-#define	BASE_SP		0x001e0000
-
-#define STK_ALLOC_MATCH(INSTR)			\
-  (((INSTR) & STK_ALLOC_1M) == STK_ALLOC_1	\
-   || ((INSTR) & STK_ALLOC_2M) == STK_ALLOC_2)
-#define STK_PUSH_MATCH(INSTR) \
-  (((INSTR) & (MAJOR_OP | MEM_BASE | MEM_OFF_SIGN)) == (STQ_OP | BASE_SP))
-#define MEM_OP_OFFSET(INSTR) \
-  (((long)((INSTR) & MEM_OFF) << 48) >> 48)
-#define MEM_OP_REG(INSTR) \
-  (((INSTR) & MEM_REG) >> 22)
-
-/* Branches, jumps, PAL calls, and illegal opcodes end a basic block. */
-#define BB_END(INSTR)						\
-  (((instr)(INSTR) >= BR_OP) | ((instr)(INSTR) < LDA_OP) |	\
-   ((((instr)(INSTR) ^ 0x60000000) < 0x20000000) &		\
-    (((instr)(INSTR) & 0x0c000000) != 0)))
-
-#define IS_KERNEL_TEXT(PC) ((unsigned long)(PC) > START_ADDR)
-
-static char reg_name[][4] = {
-	"v0 ", "t0 ", "t1 ", "t2 ", "t3 ", "t4 ", "t5 ", "t6 ", "t7 ",
-	"s0 ", "s1 ", "s2 ", "s3 ", "s4 ", "s5 ", "s6 ", "a0 ", "a1 ",
-	"a2 ", "a3 ", "a4 ", "a5 ", "t8 ", "t9 ", "t10", "t11", "ra ",
-	"pv ", "at ", "gp ", "sp ", "0"
-};
-
-
-static instr *
-display_stored_regs(instr * pro_pc, unsigned char * sp)
-{
-	instr * ret_pc = 0;
-	int reg;
-	unsigned long value;
-
-	printk("Prologue [<%p>], Frame %p:\n", pro_pc, sp);
-	while (!BB_END(*pro_pc))
-		if (STK_PUSH_MATCH(*pro_pc)) {
-			reg = (*pro_pc & MEM_REG) >> 21;
-			value = *(unsigned long *)(sp + (*pro_pc & MEM_OFF));
-			if (reg == 26)
-				ret_pc = (instr *)value;
-			printk("\t\t%s / 0x%016lx\n", reg_name[reg], value);
-		}
-	return ret_pc;
-}
-
-static instr *
-seek_prologue(instr * pc)
-{
-	while (!STK_ALLOC_MATCH(*pc))
-		--pc;
-	while (!BB_END(*(pc - 1)))
-		--pc;
-	return pc;
-}
-
-static long
-stack_increment(instr * prologue_pc)
-{
-	while (!STK_ALLOC_MATCH(*prologue_pc))
-		++prologue_pc;
-
-	/* Count the bytes allocated. */
-	if ((*prologue_pc & STK_ALLOC_1M) == STK_ALLOC_1M)
-		return -(((long)(*prologue_pc) << 48) >> 48);
-	else
-		return (*prologue_pc >> 13) & 0xff;
-}
-
-void
-stacktrace(void)
-{
-	instr * ret_pc;
-	instr * prologue = (instr *)stacktrace;
-	unsigned char *sp = (unsigned char *)current_stack_pointer;
-
-	printk("\tstack trace:\n");
-	do {
-		ret_pc = display_stored_regs(prologue, sp);
-		sp += stack_increment(prologue);
-		prologue = seek_prologue(ret_pc);
-	} while (IS_KERNEL_TEXT(ret_pc));
-}
-- 
2.56.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] alpha: cleanup obsolete stack debugging code from lib/
  2026-12-05  2:11 [PATCH] alpha: cleanup obsolete stack debugging code from lib/ Julian Braha
@ 2026-12-05 13:34 ` Magnus Lindholm
  0 siblings, 0 replies; 2+ messages in thread
From: Magnus Lindholm @ 2026-12-05 13:34 UTC (permalink / raw)
  To: Julian Braha; +Cc: richard.henderson, mattst88, linux-alpha, linux-kernel

Hi Julian,

On Sat, Dec 5, 2026 at 3:12 AM Julian Braha <julianbraha@gmail.com> wrote:
>
> The 3 files stacktrace.c, dbg_stackkill.S, and dbg_stackcheck.S are
> currently dead code. No Makefile references them, no other C file
> includes them, and they can't be built manually.
>
> stacktrace.c has failed to build since commit ec2212088c42 ("Disintegrate
> asm/system.h for Alpha") moved START_ADDR from <asm/system.h> to
> <asm/setup.h>, and stackcheck.S failed to assemble and stackkill.S failed
> to link since pre-git commit 374eeee8a8a5 ("Update Alpha UP for
> thread_info and scheduler changes.") [1] because the offset generator
> stopped emitting TASK_SIZE and STACK_SIZE.
>
> Let's clean up this dead code.
>
> Link: https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git/commit/?id=374eeee8a8a50e12278dfa37021df7b6efe506c3 [1]
> Signed-off-by: Julian Braha <julianbraha@gmail.com>
> ---
>  arch/alpha/lib/dbg_stackcheck.S |  28 ---------
>  arch/alpha/lib/dbg_stackkill.S  |  36 -----------
>  arch/alpha/lib/stacktrace.c     | 103 --------------------------------
>  3 files changed, 167 deletions(-)
>  delete mode 100644 arch/alpha/lib/dbg_stackcheck.S
>  delete mode 100644 arch/alpha/lib/dbg_stackkill.S
>  delete mode 100644 arch/alpha/lib/stacktrace.c
>
> diff --git a/arch/alpha/lib/dbg_stackcheck.S b/arch/alpha/lib/dbg_stackcheck.S
> deleted file mode 100644
> index b3b6fc94f7f3..000000000000
> --- a/arch/alpha/lib/dbg_stackcheck.S
> +++ /dev/null
> @@ -1,28 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -/*
> - * arch/alpha/lib/dbg_stackcheck.S
> - * Contributed by Richard Henderson (rth@tamu.edu)
> - *
> - * Verify that we have not overflowed the stack.  Oops if we have.
> - */
> -
> -#include <asm/asm-offsets.h>
> -
> -       .text
> -       .set noat
> -
> -       .align 3
> -       .globl _mcount
> -       .ent _mcount
> -_mcount:
> -       .frame $30, 0, $28, 0
> -       .prologue 0
> -
> -       lda     $0, TASK_SIZE($8)
> -       cmpult  $30, $0, $0
> -       bne     $0, 1f
> -       ret     ($28)
> -1:     stq     $31, -8($31)    # oops me, damn it.
> -       br      1b
> -
> -       .end _mcount
> diff --git a/arch/alpha/lib/dbg_stackkill.S b/arch/alpha/lib/dbg_stackkill.S
> deleted file mode 100644
> index 6d9197e52a42..000000000000
> --- a/arch/alpha/lib/dbg_stackkill.S
> +++ /dev/null
> @@ -1,36 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0 */
> -/*
> - * arch/alpha/lib/dbg_stackkill.S
> - * Contributed by Richard Henderson (rth@cygnus.com)
> - *
> - * Clobber the balance of the kernel stack, hoping to catch
> - * uninitialized local variables in the act.
> - */
> -
> -#include <asm/asm-offsets.h>
> -
> -       .text
> -       .set noat
> -
> -       .align 5
> -       .globl _mcount
> -       .ent _mcount
> -_mcount:
> -       .frame $30, 0, $28, 0
> -       .prologue 0
> -
> -       ldi     $0, 0xdeadbeef
> -       lda     $2, -STACK_SIZE
> -       sll     $0, 32, $1
> -       and     $30, $2, $2
> -       or      $0, $1, $0
> -       lda     $2, TASK_SIZE($2)
> -       cmpult  $2, $30, $1
> -       beq     $1, 2f
> -1:     stq     $0, 0($2)
> -       addq    $2, 8, $2
> -       cmpult  $2, $30, $1
> -       bne     $1, 1b
> -2:     ret     ($28)
> -
> -       .end _mcount
> diff --git a/arch/alpha/lib/stacktrace.c b/arch/alpha/lib/stacktrace.c
> deleted file mode 100644
> index 2b1176dd5174..000000000000
> --- a/arch/alpha/lib/stacktrace.c
> +++ /dev/null
> @@ -1,103 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -#include <linux/kernel.h>
> -
> -typedef unsigned int instr;
> -
> -#define MAJOR_OP       0xfc000000
> -#define LDA_OP         0x20000000
> -#define STQ_OP         0xb4000000
> -#define BR_OP          0xc0000000
> -
> -#define STK_ALLOC_1    0x23de8000 /* lda $30,-X($30) */
> -#define STK_ALLOC_1M   0xffff8000
> -#define STK_ALLOC_2    0x43c0153e /* subq $30,X,$30 */
> -#define STK_ALLOC_2M   0xffe01fff
> -
> -#define MEM_REG                0x03e00000
> -#define MEM_BASE       0x001f0000
> -#define MEM_OFF                0x0000ffff
> -#define MEM_OFF_SIGN   0x00008000
> -#define        BASE_SP         0x001e0000
> -
> -#define STK_ALLOC_MATCH(INSTR)                 \
> -  (((INSTR) & STK_ALLOC_1M) == STK_ALLOC_1     \
> -   || ((INSTR) & STK_ALLOC_2M) == STK_ALLOC_2)
> -#define STK_PUSH_MATCH(INSTR) \
> -  (((INSTR) & (MAJOR_OP | MEM_BASE | MEM_OFF_SIGN)) == (STQ_OP | BASE_SP))
> -#define MEM_OP_OFFSET(INSTR) \
> -  (((long)((INSTR) & MEM_OFF) << 48) >> 48)
> -#define MEM_OP_REG(INSTR) \
> -  (((INSTR) & MEM_REG) >> 22)
> -
> -/* Branches, jumps, PAL calls, and illegal opcodes end a basic block. */
> -#define BB_END(INSTR)                                          \
> -  (((instr)(INSTR) >= BR_OP) | ((instr)(INSTR) < LDA_OP) |     \
> -   ((((instr)(INSTR) ^ 0x60000000) < 0x20000000) &             \
> -    (((instr)(INSTR) & 0x0c000000) != 0)))
> -
> -#define IS_KERNEL_TEXT(PC) ((unsigned long)(PC) > START_ADDR)
> -
> -static char reg_name[][4] = {
> -       "v0 ", "t0 ", "t1 ", "t2 ", "t3 ", "t4 ", "t5 ", "t6 ", "t7 ",
> -       "s0 ", "s1 ", "s2 ", "s3 ", "s4 ", "s5 ", "s6 ", "a0 ", "a1 ",
> -       "a2 ", "a3 ", "a4 ", "a5 ", "t8 ", "t9 ", "t10", "t11", "ra ",
> -       "pv ", "at ", "gp ", "sp ", "0"
> -};
> -
> -
> -static instr *
> -display_stored_regs(instr * pro_pc, unsigned char * sp)
> -{
> -       instr * ret_pc = 0;
> -       int reg;
> -       unsigned long value;
> -
> -       printk("Prologue [<%p>], Frame %p:\n", pro_pc, sp);
> -       while (!BB_END(*pro_pc))
> -               if (STK_PUSH_MATCH(*pro_pc)) {
> -                       reg = (*pro_pc & MEM_REG) >> 21;
> -                       value = *(unsigned long *)(sp + (*pro_pc & MEM_OFF));
> -                       if (reg == 26)
> -                               ret_pc = (instr *)value;
> -                       printk("\t\t%s / 0x%016lx\n", reg_name[reg], value);
> -               }
> -       return ret_pc;
> -}
> -
> -static instr *
> -seek_prologue(instr * pc)
> -{
> -       while (!STK_ALLOC_MATCH(*pc))
> -               --pc;
> -       while (!BB_END(*(pc - 1)))
> -               --pc;
> -       return pc;
> -}
> -
> -static long
> -stack_increment(instr * prologue_pc)
> -{
> -       while (!STK_ALLOC_MATCH(*prologue_pc))
> -               ++prologue_pc;
> -
> -       /* Count the bytes allocated. */
> -       if ((*prologue_pc & STK_ALLOC_1M) == STK_ALLOC_1M)
> -               return -(((long)(*prologue_pc) << 48) >> 48);
> -       else
> -               return (*prologue_pc >> 13) & 0xff;
> -}
> -
> -void
> -stacktrace(void)
> -{
> -       instr * ret_pc;
> -       instr * prologue = (instr *)stacktrace;
> -       unsigned char *sp = (unsigned char *)current_stack_pointer;
> -
> -       printk("\tstack trace:\n");
> -       do {
> -               ret_pc = display_stored_regs(prologue, sp);
> -               sp += stack_increment(prologue);
> -               prologue = seek_prologue(ret_pc);
> -       } while (IS_KERNEL_TEXT(ret_pc));
> -}
> --
> 2.56.1
>

I checked this against my for-next. None of the three files is built,
and the active Alpha stack trace code lives in arch/alpha/kernel/.
Nice cleanup, thanks!

One small nit in the changelog: the filenames in the second paragraph
are dbg_stackcheck.S and dbg_stackkill.S.

Reviewed-by: Magnus Lindholm <linmag7@gmail.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 13:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-05  2:11 [PATCH] alpha: cleanup obsolete stack debugging code from lib/ Julian Braha
2026-12-05 13:34 ` Magnus Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®