From patchwork Wed Dec 4 07:14:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13893275 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B29B18C933; Wed, 4 Dec 2024 07:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733296492; cv=none; b=ens+XX4OxeFMjhxUR8DNr9LHLvF5MhsnfIGzx/0RvvHvItWI1G8NGHVZDopm/t1xWK03YHurVm01dSXglYqnvyhid6oKzUnV1etr2UanUEdq9xZltyX5N8ttNF7e31Wr2a+Dh63x5OCOhCRrGPLaR3RkxPJpcslXwvdHMFklJ58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733296492; c=relaxed/simple; bh=oeN3dOIb3yn5tbkaKmt7PaHQM3+lJCpazwivDl5hcgw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nIoms1rIX+AEzzMMm/cERG0TY3Q6ZTX8BqgXSbFcJEkg1xnNqsyydUbgftOym4PvHbuIZRvO4991GONS93eEvg32/ISFrhFmd3M0r8uuxtLkDmDW3X+PPV/mXK6GS6fsPp8FhpmhnMPE7DSrVB8DP08ibFucN7cWRMinPn6L62o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yoseli.org; spf=none smtp.mailfrom=yoseli.org; dkim=pass (2048-bit key) header.d=yoseli.org header.i=@yoseli.org header.b=KKVpFWHh; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yoseli.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=yoseli.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yoseli.org header.i=@yoseli.org header.b="KKVpFWHh" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9FDA5E0007; Wed, 4 Dec 2024 07:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoseli.org; s=gm1; t=1733296483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j+CoQzNG6j3IQX1IH1EwNYyaraWabx2BrXv+rlkdzLI=; b=KKVpFWHhilSqi6Hs7CLzBflV6J56pKDE1GPg5V3UYCwnuGJ6IqtXAn3ccJOOfCCoDkBqdf CUipjZPJOP+23GjQTQN3mh74kibZQj74sjLSs+pn21f/ciiSVtI7NJh7m6fUJHMw8vCmDc gfHoLjdGkxwXjki2IbXjH9YXZAV+15alQVh43285lY+m73OpXFCnC4ZwLg7M+A0d2C8QiG 95+1SAW/NETOqdF7XmdB6JZKxqDJjChunH+KSJnuf2C0WB4zLEhVsETmwQVXIldvOSSdc9 fCb69mGQCYCpezrCJy8XFvXlfeZ//6nDJvcRyc7LZywtVGp0AQ0KFgOrrw/V0w== From: Jean-Michel Hautbois Date: Wed, 04 Dec 2024 08:14:39 +0100 Subject: [PATCH v4 1/2] m68k: Enable traceirqs Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-add-m68k-tracing-support-v4-1-e24fe5ef3b6b@yoseli.org> References: <20241204-add-m68k-tracing-support-v4-0-e24fe5ef3b6b@yoseli.org> In-Reply-To: <20241204-add-m68k-tracing-support-v4-0-e24fe5ef3b6b@yoseli.org> To: Geert Uytterhoeven Cc: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, rostedt@goodmis.org, Jean-Michel Hautbois X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733296481; l=643; i=jeanmichel.hautbois@yoseli.org; s=20240925; h=from:subject:message-id; bh=oeN3dOIb3yn5tbkaKmt7PaHQM3+lJCpazwivDl5hcgw=; b=e4Q9SllPlX/hCFnyNNLtAnX2FT6x0/n7apTjHRGG6nUaJ1vlZpafawpG2bgiqVD+kVsAaj2KS EKWcOoTj6JYCD1t04F/9828lAzle5Lv7I1K33NB5/Y0E+Eg5sAnQIqs X-Developer-Key: i=jeanmichel.hautbois@yoseli.org; a=ed25519; pk=MsMTVmoV69wLIlSkHlFoACIMVNQFyvJzvsJSQsn/kq4= X-GND-Sasl: jeanmichel.hautbois@yoseli.org As irq_enter() and irq_exit() already are tracing the state, we can safely enable TRACE_IRQFLAGS_SUPPORT. Signed-off-by: Jean-Michel Hautbois --- arch/m68k/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 7c4f7bcc89d76326b9d7280a3bcba79412ead7d2..793ab1e2762609725bbf793f6dffecfa3ecfff0f 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -39,6 +39,7 @@ config M68K select OLD_SIGSUSPEND3 select UACCESS_MEMCPY if !MMU select ZONE_DMA + select TRACE_IRQFLAGS_SUPPORT config CPU_BIG_ENDIAN def_bool y From patchwork Wed Dec 4 07:14:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Michel Hautbois X-Patchwork-Id: 13893276 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D08E1E522; Wed, 4 Dec 2024 07:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733296493; cv=none; b=hZO7JxQBctmciqjTHQNa74jX08YZaYMqGE24ot0E5AV0KWIQgtu7d3FOJDvACpklQcQlEpdomNnf6ENJQ97rXKpTiYtcPRJs5zUbIGAf3h/M9/AtqItoFUOapKMaqw26/bHEUIDd9bXaye+dkP77xbJzOpSD/WwlhM2JGU3Qr34= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733296493; c=relaxed/simple; bh=lATQn35Lh/b3dk+WEOeuwOuK+UJNMeapYBTnIVg3ZVs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NR8Doa1sAYdFodFAmu6m7X7UUu9FoE6uA3HcwUIJyPl89sZhunXxv0KjZ9bXENBJCEpVG1eh23ETi1EHCfsr5eypzxtkMQAP2i2rdI0vEhgL8y+tDK4b26rQftziMRmbcG7Ram1/nTC55ILxavwidhdQM+fxpGNmIHiVCEvFRYE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yoseli.org; spf=none smtp.mailfrom=yoseli.org; dkim=pass (2048-bit key) header.d=yoseli.org header.i=@yoseli.org header.b=Pm0A72fO; arc=none smtp.client-ip=217.70.183.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yoseli.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=yoseli.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=yoseli.org header.i=@yoseli.org header.b="Pm0A72fO" Received: by mail.gandi.net (Postfix) with ESMTPSA id 5343AE0002; Wed, 4 Dec 2024 07:14:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoseli.org; s=gm1; t=1733296483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BFmvl4A54RbX2d0A+Hcc5Q1dzADd/mmBQrsMzEB+NMM=; b=Pm0A72fOex7Xpk4AWwY2C3hkBHOP0yvZSFQ/vreKK8rP+GfP5FHA+ehs6b7f85EAOncn64 eBF+VLkQgiudnnk1p3SHfql0+x6eSjbyuGprVND0Wqa1KkAgeCKtFs2vBl/ZYVN+lwjJsM pQ/03AlpCtwUAVQtk6auSkIwtYj/tO6bg1nwAtYecpox44mNlSC4Z5mum6lUolsW1X5NNq NOhX5MTJV8oxmvntUuqWHV6h4cQCbm6IkzXeP9CDG3XwwtvfmUrj9yk+umeI67BJgSJC5m S+3zyF2RPPlWZ7W3AwFSeTxoxhhY01F4nwgRJRqCKfGCVBK+tms7rPbDcVLe4Q== From: Jean-Michel Hautbois Date: Wed, 04 Dec 2024 08:14:40 +0100 Subject: [PATCH v4 2/2] arch: m68k: Add STACKTRACE support Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241204-add-m68k-tracing-support-v4-2-e24fe5ef3b6b@yoseli.org> References: <20241204-add-m68k-tracing-support-v4-0-e24fe5ef3b6b@yoseli.org> In-Reply-To: <20241204-add-m68k-tracing-support-v4-0-e24fe5ef3b6b@yoseli.org> To: Geert Uytterhoeven Cc: linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, rostedt@goodmis.org, Jean-Michel Hautbois X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733296481; l=3079; i=jeanmichel.hautbois@yoseli.org; s=20240925; h=from:subject:message-id; bh=lATQn35Lh/b3dk+WEOeuwOuK+UJNMeapYBTnIVg3ZVs=; b=N+MC+nVTnN0sMIPNUDszQzACCuIkYM4+P3jwOIkKdVlqpOnChOhLEWY6IO5dO17tbBzB9JHjp 5vILhAjbQ9MD3pQ8LpXrOAAgOiI3nwfmgqR9w5eKNz/mjv7Y9O090hw X-Developer-Key: i=jeanmichel.hautbois@yoseli.org; a=ed25519; pk=MsMTVmoV69wLIlSkHlFoACIMVNQFyvJzvsJSQsn/kq4= X-GND-Sasl: jeanmichel.hautbois@yoseli.org In order to use tracing, implement a basic arch_stack_walk() based on the one in PowerPC. Tested on a M54418 coldfire. Signed-off-by: Jean-Michel Hautbois --- 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 793ab1e2762609725bbf793f6dffecfa3ecfff0f..3ad8596aab71190807f8c11dd5876aa1198760f3 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -106,6 +106,11 @@ 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 + def_bool MMU_COLDFIRE + select ARCH_STACKWALK + select ARCH_WANT_FRAME_POINTERS + menu "Platform setup" source "arch/m68k/Kconfig.cpu" diff --git a/arch/m68k/kernel/Makefile b/arch/m68k/kernel/Makefile index 6c732ed3998b714a4842ee29c977550a61979779..cb02bcfe04c6b265fa97db9237395a262e649989 100644 --- a/arch/m68k/kernel/Makefile +++ b/arch/m68k/kernel/Makefile @@ -23,3 +23,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..4c2fb6b0cf675ee5a3a21393a50603fea98a1b03 --- /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 +#include +#include +#include +#include + +static inline unsigned long current_stack_frame(void) +{ + unsigned long sp; + + asm volatile("movl %%fp, %0" : "=r"(sp)); + return sp; +} + +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; + } +}