From: Greg Ungerer <gerg@linux-m68k.org>
To: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>,
linux-m68k@lists.linux-m68k.org
Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
rostedt@goodmis.org, Michael Schmitz <schmitzmic@gmail.com>,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: [PATCH RFC 2/2] arch: m68k: Add STACKTRACE support
Date: Tue, 3 Dec 2024 00:41:04 +1000 [thread overview]
Message-ID: <a2efe6f7-4bfe-468b-9512-c60f646281b1@linux-m68k.org> (raw)
In-Reply-To: <501c04d7-1a7d-4000-a948-e9effb281a05@yoseli.org>
Hi JM,
On 27/11/24 21:26, Jean-Michel Hautbois wrote:
> Hi there,
>
> On 21/10/2024 11:44, Jean-Michel Hautbois wrote:
>> In order to use tracing, implement a basic arch_stack_walk() based on
>> the one in PowerPC.
>> Tested on a M54418 coldfire.
>
> Well, I said it was tested, but it was only compile tested basically.
> AFAICT now, I think it is not working as when I use wakeup_rt as a tracer, I don't have the stack trace:
>
> # wakeup_rt latency trace v1.1.5 on 6.12.0-10380-gb66f06337b66-dirty
> # --------------------------------------------------------------------
> # latency: 2000 us, #18/18, CPU#0 | (M:preempt VP:0, KP:0, SP:0 HP:0)
> # -----------------
> # | task: irq/100-enet-fe-118 (uid:0 nice:0 policy:1 rt_prio:50)
> # -----------------
> #
> # _------=> CPU#
> # / _-----=> irqs-off/BH-disabled
> # | / _----=> need-resched
> # || / _---=> hardirq/softirq
> # ||| / _--=> preempt-depth
> # |||| / _-=> migrate-disable
> # ||||| / delay
> # cmd pid |||||| time | caller
> # \ / |||||| \ | /
> kworker/-11 0dnh5. 0us : 11:120:R + [000] 22: 98:R irq_work/0
> kworker/-11 0dnh5. 0us : <stack trace>
> kworker/-11 0dnh5. 0us : 0
> kworker/-11 0d..3. 0us : __schedule
> kworker/-11 0d..3. 0us : 11:120:R ==> [000] 22: 98:R irq_work/0
> kworker/-11 0d..3. 0us : <stack trace>
> telnetd-229 0Dnh4. 0us : 229:120:R + [000] 118: 49:R irq/100-enet-fe
> telnetd-229 0Dnh4. 0us : <stack trace>
> telnetd-229 0Dnh4. 0us : 0
> telnetd-229 0D..3. 0us : __schedule
> telnetd-229 0D..3. 0us : 229:120:R ==> [000] 118: 49:R irq/100-enet-fe
> telnetd-229 0D..3. 0us : <stack trace>
> telnetd-229 0dn.5. 0us : 229:120:R + [000] 118: 49:R irq/100-enet-fe
> telnetd-229 0dn.5. 0us : <stack trace>
> telnetd-229 0dn.5. 0us#: 0
> telnetd-229 0d..3. 2000us : __schedule
> telnetd-229 0d..3. 2000us : 229:120:R ==> [000] 118: 49:R irq/100-enet-fe
> telnetd-229 0d..3. 2000us : <stack trace>
>
> Geert, Greg, and maybe other highly skilled m68k people, could you please help me with this particular function :-) ?
>
> Thanks !
> JM
>
>>
>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
>> ---
>> arch/m68k/Kconfig | 5 ++++
>> arch/m68k/kernel/Makefile | 1 +
>> arch/m68k/kernel/stacktrace.c | 70 +++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 76 insertions(+)
>>
>> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
>> index ab3375475721fa63418c40d4ba6ac76679ebc77d..7142f9759181a90269ae1ba9e682d331ee2ddbf6 100644
>> --- a/arch/m68k/Kconfig
>> +++ b/arch/m68k/Kconfig
>> @@ -40,6 +40,7 @@ config M68K
>> select UACCESS_MEMCPY if !MMU
>> select ZONE_DMA
>> select TRACE_IRQFLAGS_SUPPORT
>> + select ARCH_STACKWALK
>> config CPU_BIG_ENDIAN
>> def_bool y
>> @@ -107,6 +108,10 @@ config BOOTINFO_PROC
>> Say Y to export the bootinfo used to boot the kernel in a
>> "bootinfo" file in procfs. This is useful with kexec.
>> +config STACKTRACE_SUPPORT
>> + bool
>> + default y
>> +
>> menu "Platform setup"
>> source "arch/m68k/Kconfig.cpu"
>> diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile
>> index f335bf3268a108a45bab079fbf0a1c8ead9beb71..4efe92af0b711b19cb1d5129f74e67a739e289b1 100644
>> --- a/arch/m68k/kernel/Makefile
>> +++ b/arch/m68k/kernel/Makefile
>> @@ -31,3 +31,4 @@ obj-$(CONFIG_UBOOT) += uboot.o
>> obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
>> +obj-y += stacktrace.o
>> diff --git a/arch/m68k/kernel/stacktrace.c b/arch/m68k/kernel/stacktrace.c
>> new file mode 100644
>> index 0000000000000000000000000000000000000000..06c7459373bd25b3bb3540cfe2a909259c1db3ce
>> --- /dev/null
>> +++ b/arch/m68k/kernel/stacktrace.c
>> @@ -0,0 +1,70 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +/*
>> + * Stack trace utility functions etc.
>> + *
>> + * Copyright 2024 Jean-Michel Hautbois, Yoseli SAS.
>> + */
>> +
>> +#include <asm/current.h>
>> +#include <asm/ptrace.h>
>> +#include <linux/sched.h>
>> +#include <linux/sched/task_stack.h>
>> +#include <linux/stacktrace.h>
>> +
>> +static inline unsigned long current_stack_frame(void)
>> +{
>> + unsigned long sp;
>> +
>> + asm volatile("movl %%sp, %0" : "=r"(sp));
>> + return sp;
>> +}
If I am understanding what this is intended to do then this is probably not right.
This will be returning the current stack pointer, which will almost certainly not
be the current stack frame pointer. This will be the top of stack at the call site,
which will be after the pushed locals and saved registers at the very least for m68k.
Does your kernel config have CONFIG_FRAME_POINTER enabled?
The default for m68k is usually disabled. Without this there won't be a
chain of frame pointers to follow like the code is trying to do below in
arch_stack_walk().
Regards
Greg
>> +static inline int validate_sp(unsigned long sp, struct task_struct *task)
>> +{
>> + unsigned long stack_start, stack_end;
>> +
>> + if (task == current)
>> + stack_start = (unsigned long)task_stack_page(task);
>> + else
>> + stack_start = (unsigned long)task->thread.esp0;
>> +
>> + stack_end = stack_start + THREAD_SIZE;
>> +
>> + if (sp < stack_start || sp >= stack_end)
>> + return 0;
>> +
>> + return 1;
>> +}
>> +
>> +void __no_sanitize_address arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie,
>> + struct task_struct *task, struct pt_regs *regs)
>> +{
>> + unsigned long sp;
>> +
>> + if (regs && !consume_entry(cookie, regs->pc))
>> + return;
>> +
>> + if (regs)
>> + sp = (unsigned long) regs;
>> + else if (task == current)
>> + sp = current_stack_frame();
>> + else
>> + sp = task->thread.ksp;
>> +
>> + for (;;) {
>> + unsigned long *stack = (unsigned long *) sp;
>> + unsigned long newsp, ip;
>> +
>> + if (!validate_sp(sp, task))
>> + return;
>> +
>> + newsp = stack[0];
>> + ip = stack[1];
>> +
>> + if (!consume_entry(cookie, ip))
>> + return;
>> +
>> + sp = newsp;
>> + }
>> +}
>>
>
next prev parent reply other threads:[~2024-12-02 14:41 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 9:44 [PATCH RFC 0/2] Add basic tracing support for m68k Jean-Michel Hautbois
2024-10-21 9:44 ` [PATCH RFC 1/2] m68k: Add tracirqs Jean-Michel Hautbois
2024-10-22 5:28 ` Steven Rostedt
2024-10-22 5:42 ` Jean-Michel Hautbois
2024-10-22 8:30 ` Steven Rostedt
2024-10-22 9:21 ` Jean-Michel Hautbois
2024-10-23 8:47 ` Steven Rostedt
2024-10-23 9:07 ` Jean-Michel Hautbois
2024-10-23 9:13 ` Geert Uytterhoeven
2024-10-23 9:31 ` Jean-Michel Hautbois
2024-10-23 10:30 ` Jean-Michel Hautbois
2024-10-23 3:53 ` Michael Schmitz
2024-10-23 5:53 ` Jean-Michel Hautbois
2024-10-23 7:30 ` Michael Schmitz
2024-10-23 8:59 ` Jean-Michel Hautbois
2024-10-23 9:27 ` Steven Rostedt
2024-10-23 8:51 ` Eero Tamminen
2024-10-21 9:44 ` [PATCH RFC 2/2] arch: m68k: Add STACKTRACE support Jean-Michel Hautbois
2024-11-27 11:26 ` Jean-Michel Hautbois
2024-12-02 14:41 ` Greg Ungerer [this message]
2024-12-02 14:51 ` Jean-Michel Hautbois
2024-12-02 14:52 ` Jean-Michel Hautbois
2024-12-02 23:01 ` Greg Ungerer
2024-12-03 6:25 ` Jean-Michel Hautbois
2024-12-02 17:53 ` Jean-Michel Hautbois
2024-11-15 8:26 ` [PATCH RFC 0/2] Add basic tracing support for m68k Jean-Michel Hautbois
2024-11-15 15:25 ` Steven Rostedt
2024-11-15 15:33 ` Jean-Michel Hautbois
2024-11-15 19:55 ` Steven Rostedt
2024-11-18 10:11 ` Jean-Michel Hautbois
2024-11-18 20:20 ` Steven Rostedt
2024-11-19 14:24 ` Jean-Michel Hautbois
2024-11-19 15:26 ` Steven Rostedt
2024-11-19 16:28 ` Steven Rostedt
2024-11-19 16:44 ` Steven Rostedt
2024-11-19 18:06 ` Jean-Michel Hautbois
2024-11-19 18:10 ` Steven Rostedt
2024-11-20 11:47 ` Jean-Michel Hautbois
2024-11-20 15:31 ` Steven Rostedt
2024-11-20 15:59 ` Jean-Michel Hautbois
2024-11-20 16:43 ` Steven Rostedt
2024-11-20 16:51 ` Jean-Michel Hautbois
2024-11-19 18:25 ` Michael Schmitz
2024-11-28 15:25 ` Tomas Glozar
2024-12-02 12:53 ` Jean-Michel Hautbois
2024-12-02 14:45 ` Tomas Glozar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a2efe6f7-4bfe-468b-9512-c60f646281b1@linux-m68k.org \
--to=gerg@linux-m68k.org \
--cc=geert@linux-m68k.org \
--cc=jeanmichel.hautbois@yoseli.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=schmitzmic@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®