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: 13810425 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98FD3CF9C6B for ; Tue, 24 Sep 2024 07:43:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A2C56B00A0; Tue, 24 Sep 2024 03:43:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 251276B00A2; Tue, 24 Sep 2024 03:43:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F2056B00A7; Tue, 24 Sep 2024 03:43:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DA2C66B00A0 for ; Tue, 24 Sep 2024 03:43:51 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 888D11C72A4 for ; Tue, 24 Sep 2024 07:43:51 +0000 (UTC) X-FDA: 82598842662.11.FBED300 Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) by imf03.hostedemail.com (Postfix) with ESMTP id A9A632001C for ; Tue, 24 Sep 2024 07:43:48 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="F+qHHCL/"; spf=pass (imf03.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.160.51 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727163768; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=EBOy5gHyOhd9AM3jz7ucr3vlokWJoL7EJVNAm9AjtjA=; b=5apa6RiCzr8ZatteiNwg0pWHXRYYkMqcJDoFTC7ZVFpPDx1Ui/AoGVGHL48K3pydxiP7ry Dp0GcACkSpTH6KPVMIWhtSIPd4HHwcJQ8ay4+4rn1Nhl9FmfKOC2Jb90Xfq6nnig8FAiNF JLbYcalnSUV+5zhxGMb1D4VpR2J4bmM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="F+qHHCL/"; spf=pass (imf03.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.160.51 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727163768; a=rsa-sha256; cv=none; b=qRZiIvV2+kc2VV1jV71o7JbOuAF9ehfNqchbkGDO3ve60R92zLTVGByNrKxNqk0xldXneT qv1uFVlPXHTxWBlzILilvpIVkzgDJLKqUFNJXXGvvKcuSdIN8ThJF8KZnazpe/ZuZvg+Hd M1OKBw1g0R80DNIEkHjtYw4YC+SNCYc= Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-2689e7a941fso2655040fac.3 for ; Tue, 24 Sep 2024 00:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727163827; x=1727768627; darn=kvack.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=F+qHHCL/fEoQQ5muWVqxIUtgz0Scy/DC7jtaX3DXoqPAtstlIJlLbsNwAy2nJXgAEx hen+4Csgw5vXHs5ZyBrb0mxctKk9kMBgkK24QmJ/uqaXzDcjTe6HivLcCCRD6WmWn4v5 GmJ9AFmVsI4SsRnk0Q4m+xIqG73kwqjEWSk8+7b5QXW3NYbutWkCczDgWrGeS9EaDHLH z0wYOqGGnOne/LQGWRDhXe48HV/++RZBf29+fADGhYgQar4BsfLkXRe76oQ06/I7NHvl 2UEZH9bOXQJd7xOjtuyg5UAddDvmbf2nFUCgDcQpwcYd7a9QrBB0YEDJxL3aoCeQVpGY tpTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727163827; x=1727768627; 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=C1dEgkjNqRF+lDsxnHQNFlUDbugQYFr4RF6MXjORpGHamhBE44DkhHmP7+dUzmbH84 WagrhHYIwRt6dnspGruQ1QWV115cO9RDNW8G4I1wSZTUbI+pm9S6LKnlzihUbd5h2PaD SX3y+YxvFxzziQ6d5II/ndC4qcLw/PJjCfRHHXugTT7vFOog+dqwUUep0FdJUAlus+qf wgzAImvb93NfuXix586kK5vEKVrgXwle2Qz1fgnpn4U/Z0oVSGd/NZ2CFIYfPSgaNTtG yJ9tXKUYWRdBt2CcI76Y51PyDLczh19U4J5DX1vkpQlyr41VD1/EssDVTwJivIcAbIdV ajsA== X-Forwarded-Encrypted: i=1; AJvYcCVeQ5gdSigbm7qbjBfwIDVOtrlMra+4meR2/vPzyowiSnIo1T664g5KQdJgXcjxQUr97IyGBlbHDg==@kvack.org X-Gm-Message-State: AOJu0Yyj1nHGk3WhpmP/p95LC0z7RjZV53o96aurb/CBQZR1RrPRTYL8 5CiAxKofxvaJnqKll4RTG8Eh/q1F0LINbFWSRHyPNoJ2eD3FlHLUImrz+A== 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-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: A9A632001C X-Stat-Signature: bsf91hyn88rstde6re1tiw7hin5gx6kp X-HE-Tag: 1727163828-997577 X-HE-Meta: U2FsdGVkX19JNc5vzalemLlQhe5E4EmtiTOLZR/314osIchzZO+0igkz6nJiFAAX/p1Q0NNcHUGsBkNQrFm8OiqSR5UidpeKtmklx1HReGvib3T+2FFVBH8vpr/vBwXrOEknsAYxNuDk4KuU+OG3y/6Is9o7cWkpdvOINpDEn3CbkvDfALI3KTgMkjzxVW4QBDc1um+0Ph3px0wUbadleRPvJTrdLbEHB4hRcfXmH2s8/r/wg0P++RAamZgWF3TABcawfqY5RalsQ3XaRbQS5i9CS0odfmrhQpioSVngDe6iKsSgnQGVBjtB8LaqB3GrriXTYx3SnpuTJslHqQ8F4NZJmL5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, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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)