From patchwork Tue Sep 24 07:43:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 13810452 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E224CF9C6B for ; Tue, 24 Sep 2024 07:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=EBOy5gHyOhd9AM3jz7ucr3vlokWJoL7EJVNAm9AjtjA=; b=19OXy4R16wR1qfQbw53pR159Q6 6htxEVX5D+Tbxto00CGRN1b15kAPuWi9+akejCJ9NXFlo7A/sbFqfg61BznjmZPngm2wobBYycgdw VT1hwKlX0X93+rziBhfQ1G3+wF9HuCY2n4QD7xNivhUk7X6lRqdoo0fiXQNhXM+KbIduzxx8G7+F2 5br9ihZI7ElYELJlx+n3Aa+NO5Pk91yZp+el6xhQS2nNv8imTFE3iiDznT33bp63jCo3llSgVd4Ck 4oq2SV2wqVsEa8lmf/vqJQbEK/pzCGr5R+KJFURfSA8/Fhv0+Vx5a+nOHUUN68ieoY3p7WJgvhXzZ 7RQBaGhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1st0Ld-00000001Uet-2XsL; Tue, 24 Sep 2024 07:52:37 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1st0DA-00000001T4Z-3BUW for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 07:43:54 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-27b7a1480bdso2358978fac.2 for ; Tue, 24 Sep 2024 00:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727163831; x=1727768631; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EBOy5gHyOhd9AM3jz7ucr3vlokWJoL7EJVNAm9AjtjA=; b=MCLdZalwB4ZphpK43+PZ8YLnpWd+onchBsCE5Bg3ZsPMAkL97W+lkF/yjOZsGTYSfC +h8BbDkD+oXIqWWtjMcizjjyQ418kbdadDIyQA9BWVjQ1M3uz7wTEvCS8oT42pUFnqVs 3ebexQcY8UtKwDKqgorqwW2KFW+ZrydKskiF3NM5cTIKeSQzAlCIB8D2Tcyc6Sx3B4sx VVJ1DKMCO3FStbMNCn7nvCKnQqjrFgB14t9KVIMVcF0M35dD864ZPv+urv0ka2VAJIRs A2sAa5d9yk1ei2VWZKDkjXEjNmu8Ysp6XpnJTMcQiKGVfPZtB/LYSRZZZ7JhIM0JrZdz ytzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727163831; x=1727768631; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EBOy5gHyOhd9AM3jz7ucr3vlokWJoL7EJVNAm9AjtjA=; b=JCDiR+dJZHq7dq76KEjLLHXQAwnRmJV9lonOd67NOAuasCoyYS35bXE0TeSLQBVVxj orFzGLgPHHBJa3XyRjBbPR0mKkACowoj0JBdeDjQJUFeaKoBjgLPnB24VG/IQqTBIWzc /dUFmL2B9pUvUmldC6of2A5KLFX5fSAT9DmsH36rWZ45eFRtMtpOcqYhwv20cEFpPTG9 /I+dPtMEQ7rB3q08fqPDxpZy2KNdkcOYrUyW0vrlGzzpGQbDlyo98Ra7fryMzx3Kdn/3 EKvIhT4QBcWPxqlM7N7RilWZy1Y+Z2hANChm0YYHUWQyrB5fUbvRy4qRxGgwnnkrQ2XG zOzQ== X-Gm-Message-State: AOJu0YyXPJ+KZEUP5d1TP03G/I5ZZTOqBZ18M6yuL3aVwZbQa0u7mMuf Ujj4cn9joVQeq1KtcL+qWXICyuYbk7YaapzO1uxWlpV2QjrYMs1B X-Google-Smtp-Source: AGHT+IEwmYtWB4OJ9uArL7Pv98Nt18qw/HYsz/16ZW/TpgqyPm3+JqwY23fcghDaSlU60D/3uBKENw== X-Received: by 2002:a05:6870:468e:b0:277:f2d5:7834 with SMTP id 586e51a60fabf-2803a5d85a6mr9223888fac.14.1727163827396; Tue, 24 Sep 2024 00:43:47 -0700 (PDT) Received: from localhost ([183.226.245.34]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71afc97c17fsm690074b3a.152.2024.09.24.00.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 00:43:46 -0700 (PDT) From: "qiwu.chen" X-Google-Original-From: "qiwu.chen" To: corbet@lwn.net, oleg@redhat.com, catalin.marinas@arm.com, will@kernel.org, paulmck@kernel.org, akpm@linux-foundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, "qiwu.chen" Subject: [PATCH v4 1/2] panic: add option to dump task maps info in panic_print Date: Tue, 24 Sep 2024 15:43:40 +0800 Message-Id: <20240924074341.37272-1-qiwu.chen@transsion.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240924_004352_821984_2ADC459B X-CRM114-Status: GOOD ( 20.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, it's hard to debug panic issues caused by kill init, since there is no debug info from user mode in current panic msg such as the user_regs and maps info. This patch adds an option to dump task maps info in panic_print. - changes history: v3: https://lore.kernel.org/all/20240922095504.7182-1-qiwu.chen@transsion.com/ https://lore.kernel.org/all/20240922095504.7182-2-qiwu.chen@transsion.com/ v2: https://lore.kernel.org/all/20231110031553.33186-1-qiwu.chen@transsion.com/ v1: https://lore.kernel.org/all/20231110022720.GA3087@rlk/ Signed-off-by: qiwu.chen --- .../admin-guide/kernel-parameters.txt | 1 + Documentation/admin-guide/sysctl/kernel.rst | 1 + fs/proc/task_mmu.c | 3 +- include/linux/mm.h | 4 ++ kernel/panic.c | 52 +++++++++++++++++++ 5 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index 8337d0fed311..f76709deef6c 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4253,6 +4253,7 @@ bit 5: print all printk messages in buffer bit 6: print all CPUs backtrace (if available in the arch) bit 7: print only tasks in uninterruptible (blocked) state + bit 8: print task maps info *Be aware* that this option may print a _lot_ of lines, so there are risks of losing older messages in the log. Use this option carefully, maybe worth to setup a diff --git a/Documentation/admin-guide/sysctl/kernel.rst b/Documentation/admin-guide/sysctl/kernel.rst index f8bc1630eba0..558e365b76a9 100644 --- a/Documentation/admin-guide/sysctl/kernel.rst +++ b/Documentation/admin-guide/sysctl/kernel.rst @@ -872,6 +872,7 @@ bit 4 print ftrace buffer bit 5 print all printk messages in buffer bit 6 print all CPUs backtrace (if available in the arch) bit 7 print only tasks in uninterruptible (blocked) state +bit 8 print task maps info ===== ============================================ So for example to print tasks and memory info on panic, user can:: diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index ade74a396968..37169ae36542 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -240,7 +240,7 @@ static int do_maps_open(struct inode *inode, struct file *file, sizeof(struct proc_maps_private)); } -static void get_vma_name(struct vm_area_struct *vma, +void get_vma_name(struct vm_area_struct *vma, const struct path **path, const char **name, const char **name_fmt) @@ -300,6 +300,7 @@ static void get_vma_name(struct vm_area_struct *vma, return; } } +EXPORT_SYMBOL(get_vma_name); static void show_vma_header_prefix(struct seq_file *m, unsigned long start, unsigned long end, diff --git a/include/linux/mm.h b/include/linux/mm.h index 13bff7cf03b7..2fa403aae1de 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3566,6 +3566,10 @@ static inline bool range_in_vma(struct vm_area_struct *vma, #ifdef CONFIG_MMU pgprot_t vm_get_page_prot(unsigned long vm_flags); void vma_set_page_prot(struct vm_area_struct *vma); +void get_vma_name(struct vm_area_struct *vma, + const struct path **path, + const char **name, + const char **name_fmt); #else static inline pgprot_t vm_get_page_prot(unsigned long vm_flags) { diff --git a/kernel/panic.c b/kernel/panic.c index 753d12f4dc8f..2217e1d0ad44 100644 --- a/kernel/panic.c +++ b/kernel/panic.c @@ -77,6 +77,8 @@ EXPORT_SYMBOL_GPL(panic_timeout); #define PANIC_PRINT_ALL_PRINTK_MSG 0x00000020 #define PANIC_PRINT_ALL_CPU_BT 0x00000040 #define PANIC_PRINT_BLOCKED_TASKS 0x00000080 +#define PANIC_PRINT_TASK_MAPS_INFO 0x00000100 + unsigned long panic_print; ATOMIC_NOTIFIER_HEAD(panic_notifier_list); @@ -208,6 +210,53 @@ void nmi_panic(struct pt_regs *regs, const char *msg) } EXPORT_SYMBOL(nmi_panic); +/* + * This function is called in panic proccess if the PANIC_PRINT_TASK_MAPS_INFO + * flag is specified in panic_print, which is helpful to debug panic issues due + * to an unhandled falut in user mode such as kill init. + */ +static void dump_task_maps_info(struct task_struct *tsk) +{ + struct pt_regs *user_ret = task_pt_regs(tsk); + struct mm_struct *mm = tsk->mm; + struct vm_area_struct *vma; + + if (!mm || !user_mode(user_ret)) + return; + + pr_info("Dump task %s:%d maps start\n", tsk->comm, task_pid_nr(tsk)); + mmap_read_lock(mm); + VMA_ITERATOR(vmi, mm, 0); + for_each_vma(vmi, vma) { + int flags = vma->vm_flags; + unsigned long long pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; + const struct path *path; + const char *name_fmt, *name; + char name_buf[SZ_256]; + + get_vma_name(vma, &path, &name, &name_fmt); + if (path) { + name = d_path(path, name_buf, sizeof(name_buf)); + name = IS_ERR(name) ? "?" : name; + } else if (name || name_fmt) { + snprintf(name_buf, sizeof(name_buf), name_fmt ?: "%s", name); + name = name_buf; + } + + if (name) + pr_info("%08lx-%08lx %c%c%c%c %08llx %s\n", + vma->vm_start, vma->vm_end, + flags & VM_READ ? 'r' : '-', + flags & VM_WRITE ? 'w' : '-', + flags & VM_EXEC ? 'x' : '-', + flags & VM_MAYSHARE ? 's' : 'p', + pgoff, name); + + } + mmap_read_unlock(mm); + pr_info("Dump task %s:%d maps end\n", tsk->comm, task_pid_nr(tsk)); +} + static void panic_print_sys_info(bool console_flush) { if (console_flush) { @@ -233,6 +282,9 @@ static void panic_print_sys_info(bool console_flush) if (panic_print & PANIC_PRINT_BLOCKED_TASKS) show_state_filter(TASK_UNINTERRUPTIBLE); + + if (panic_print & PANIC_PRINT_TASK_MAPS_INFO) + dump_task_maps_info(current); } void check_panic_on_warn(const char *origin) From patchwork Tue Sep 24 07:43:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 13810453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6DCBCF9C71 for ; Tue, 24 Sep 2024 07:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sveNCmO55zA73Cq65R0Q3qE+br1KOMYEKyeAeW0hpMA=; b=YKXBvkEg4Er+3YSmVFmVcTb1Tb ZCeiuuJcjFwvVGok2WTtOI63UxzGxhu8wQeCl5nQQhQq78sRiT8jQdTxxLzJYu9Gy+qBmaZBfrluY WAo/iqV7AYf4ltYjCF5k6B7J2Lx/tkExQbj7/K5yvbxK6M2ZrhgmFb2NJ2IXZFjN8LQBs5+9ipDTv bRXNondyiOiegRwrHqP1pzGV9tB3CXaxgV2+N/pRYv8B3VpDYMGmy/tp3cpshouw6LHTrL7kgsw+l NWNNTmr1uuNeBUOEG7bXBzKxOUH+rRgjJYtiyMbLBZpASP+5HZfLhhBJ5XavfYK1jzx4W2nZFbNI+ 33WwYKdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1st0Mj-00000001Utp-4BGq; Tue, 24 Sep 2024 07:53:46 +0000 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1st0DD-00000001T6R-2Q2w for linux-arm-kernel@lists.infradead.org; Tue, 24 Sep 2024 07:43:57 +0000 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-20688fbaeafso55220765ad.0 for ; Tue, 24 Sep 2024 00:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727163835; x=1727768635; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sveNCmO55zA73Cq65R0Q3qE+br1KOMYEKyeAeW0hpMA=; b=JBAauxVgS+HOXALjPg02+Jjtbwv9MQrSt9Q/MLXYVl+MOjo7iohHs8g108MYsKfV7t REjLbRQVpyu/5UU6X5SJlDei6axQqBeOV4LGdTBdlckK+Kqi30TU4s/authARDOEDbOQ R9xoo0akgKdgMIrwaGKp4IMyv6VuqZEehYPk4cxjZ7kT7qUDtMEhBLjbL9rMQ0Ruoh+t RWs2ybpQAr7CuGqNGaMISFvGyj5unbutmBaOTl68KLiDQtytiaM9YvVdsrgBOdYfFjuR CmwGT582o94iBt6sDgRjY9GeOvL1bs0/CCiZG9nNFSs36WjD7uCUoSAbdKa9S+I6H02a Mnog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727163835; x=1727768635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sveNCmO55zA73Cq65R0Q3qE+br1KOMYEKyeAeW0hpMA=; b=SQyTz7HRfbQkcIog6KzG8LLvFxOE2qaIZrzCdPYPx514ONL6sTNRgm96yne1NiQiav PwH/JV2KthTZM0heocGDNSuGnsetXTuPAmMuoELi73V6kU7n3h9VjhXh9cGJKtiFKygy 7cvvh01x4JBqItRzb8AjOAQMsxvATiHreyzVDwMdPwvsVrRmGtjNAciMKI1CPSQLAYZu Lgam+zO3yCn9gADmKJnPmZClmFYv6Kdf5quUce34KZFtlmaCVsc3CTdR7JLribbPOjjU xi/XUOSF94o/TvaUGfbieUZ8COEtTKUpqLX6+qkqFvIxRqQgkq4oejz4zg7JA+vI1zoE nd+A== X-Gm-Message-State: AOJu0YxcDfLu58SgZmuB+6FBxehk7HbOVjRT3JEanS8uk5y84ed5ZsAZ xEDqRshLC3h4fLI8CW6hBSUL2mQHKXLnGa9Z63i8nolPOn+I0o48 X-Google-Smtp-Source: AGHT+IGkboJEphLTV+FMa306u2HDfgQ+BFBgzuEmyLxUgIiH1SucNTTRvao0wYxNex2p4+02OD3TWg== X-Received: by 2002:a17:903:1c9:b0:206:99a8:525f with SMTP id d9443c01a7336-208d8338b2dmr265597905ad.4.1727163834623; Tue, 24 Sep 2024 00:43:54 -0700 (PDT) Received: from localhost ([183.226.245.34]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20af1819289sm5672595ad.214.2024.09.24.00.43.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 00:43:54 -0700 (PDT) From: "qiwu.chen" X-Google-Original-From: "qiwu.chen" To: corbet@lwn.net, oleg@redhat.com, catalin.marinas@arm.com, will@kernel.org, paulmck@kernel.org, akpm@linux-foundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, "qiwu.chen" Subject: [PATCH v4 2/2] arm64: show signal info for global init Date: Tue, 24 Sep 2024 15:43:41 +0800 Message-Id: <20240924074341.37272-2-qiwu.chen@transsion.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240924074341.37272-1-qiwu.chen@transsion.com> References: <20240924074341.37272-1-qiwu.chen@transsion.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240924_004355_705120_88AA3E01 X-CRM114-Status: GOOD ( 14.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, it's hard to debug panic issues caused by kill init on arm64, since there is no debug info from user mode in current panic msg such as the user_regs and maps info. This patch shows signal info sent to the global init, which will be helpful for debugging kill init issue caused by unhandled exception from user mode. - changes history: v3: https://lore.kernel.org/all/20240922095504.7182-1-qiwu.chen@transsion.com/ https://lore.kernel.org/all/20240922095504.7182-2-qiwu.chen@transsion.com/ v2: https://lore.kernel.org/all/20231110031553.33186-1-qiwu.chen@transsion.com/ v1: https://lore.kernel.org/all/20231110022720.GA3087@rlk/ Signed-off-by: qiwu.chen --- arch/arm64/kernel/traps.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 563cbce11126..3150fb84195f 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -247,12 +247,20 @@ static void arm64_show_signal(int signo, const char *str) unsigned long esr = tsk->thread.fault_code; struct pt_regs *regs = task_pt_regs(tsk); + /* + * The signal sent to the global init needs to be shown, + * which is useful for debugging kill init issue. + */ + if (unlikely(is_global_init(tsk))) + goto dump; + /* Leave if the signal won't be shown */ if (!show_unhandled_signals || !unhandled_signal(tsk, signo) || !__ratelimit(&rs)) return; +dump: pr_info("%s[%d]: unhandled exception: ", tsk->comm, task_pid_nr(tsk)); if (esr) pr_cont("%s, ESR 0x%016lx, ", esr_get_class_string(esr), esr);