Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp80273pxf; Tue, 30 Mar 2021 20:10:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ozWpHnurWNgIqAybPggcOnh+UGWV241Ld4HVXyagV/GuDbYzZAX7RJBrZEnBrwiejaE4 X-Received: by 2002:a05:6402:26ce:: with SMTP id x14mr1009714edd.359.1617160241757; Tue, 30 Mar 2021 20:10:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617160241; cv=none; d=google.com; s=arc-20160816; b=I7aIvbEy19SgbWOlTdRVUQgnUR6AzkdrKna7mACeOBW1wvHb+kxYHoDMxk1yTeUesO SC1asrZ10BIUM+/zy+73dGmZFutvB0c9acYiObPkvj1F3EYG4+JFDumuxKiiVFjlVKZj r9SzozsVfAp+uRDJd968PZJwPRahkdk1FtSqpoMZCWEm4z4F21xUQNKeVywum7GuKe2s nYiykUes2q5cJeNFKoImYhR6EIqvLChD2juYRKEFHz/0hpenN8b7ImjIsOO3xpPeUuGA 928sn1Y7m4zDZd7ciAtCRMcFPwH9f9r0n2K+yuErErMZ1Pi7G1ZQSNktGqJbQ50fSz2R BskQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9wsTLIIw7+y8v2jyNC2LbraKjpJpaIpFe+dOzwsLwG8=; b=G7H2/nHfTFMflHgl5KL0PEq4Kvsg8/iWafO+c9Dpn9zW960HIVzCd/yvBcn1NQnGWX tW+k7zpd2fB+jJcihZDkKuuXgZ5pGVgEi4CDu0xxD4s6/xefpGmm4/KCdvl7xmJgbQcj hu7wKBRwQZGHN8BCMtKpcUNOsMEkOpHvTAWfYu7L0OWQ5eN50hoIqNa1dWE6uGEhhwKp oeAC/aDJlTldcRob/j+H0mkAQVUESNcL82zvP792Ya/yCNPia9ItAknad3r7fBh1Oxan C0BobUTeKzqzQkgQfWGhe7pc1n6mgs3ZSuBC/ddYqso6vHNbrsqufz8zfZl04kQTGQE4 bvHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JHkKnhv3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b1si611770ejb.714.2021.03.30.20.10.19; Tue, 30 Mar 2021 20:10:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JHkKnhv3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233533AbhCaDFn (ORCPT + 99 others); Tue, 30 Mar 2021 23:05:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233448AbhCaDF1 (ORCPT ); Tue, 30 Mar 2021 23:05:27 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E8ECC061574 for ; Tue, 30 Mar 2021 20:05:27 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id w8so8766439pjf.4 for ; Tue, 30 Mar 2021 20:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9wsTLIIw7+y8v2jyNC2LbraKjpJpaIpFe+dOzwsLwG8=; b=JHkKnhv3JhlznRU5kOoHXkmpF/Li1MYxBu3jCLLOeAN7/lY8HJ/46oFCBFIg4C2UF3 0bAHlTInztl+pWcWG2p+gQBxroNI/EDjRTAAKkG1/Sx0ZFP963ge2pmwVPYlz4gsk1Ma FYJqQpfUSej9mjPQuLlDedbjOka7y0vuyvfm0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9wsTLIIw7+y8v2jyNC2LbraKjpJpaIpFe+dOzwsLwG8=; b=KD//1LDD3PXd2dkoIk2BPq62TMURdAON+1ytMp+0nIwMZus68oZ9gDWonJ7YeY1GCz qwIMelKjKXmPOiGrWuvlR0yUyBwCyGaHM8ejF73QmThh6GDh6EFu39sQlC5MZvPN08bJ r+o8+wsqdbiO7CgmO/DoxtPqzoKoQa4OppBc2/Y72IE5YZNuPR/1POcD0WEDQITq9Yu3 fQ9A9U6BuRK0Tv0iJVijrSRVc0bsVoV1oX1hwzLQ7CtpAC0v9D7QSlwhhFbjSAVLR1Sx mjr/MTtvbwcP0s3U3x5NNAtwjJdsCeDME+dSGcAh5/s67cTbYVt2fpcG7MmZs3GNEACu SVgw== X-Gm-Message-State: AOAM5336QI8DsWTkkybKs27mHbEvjrG1XUZfGp/viIOlitI/PngEDMTw 0hodr5pApCYGLxIc1ucNCwE4iA== X-Received: by 2002:a17:90a:5284:: with SMTP id w4mr1332898pjh.29.1617159927057; Tue, 30 Mar 2021 20:05:27 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:c8c2:b814:df0f:253f]) by smtp.gmail.com with ESMTPSA id c6sm389024pfj.99.2021.03.30.20.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 20:05:26 -0700 (PDT) From: Stephen Boyd To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Alexei Starovoitov , Jessica Yu , Evan Green , Hsin-Yi Wang , Petr Mladek , Steven Rostedt , Andy Shevchenko , Matthew Wilcox Subject: [PATCH v3 03/12] dump_stack: Add vmlinux build ID to stack traces Date: Tue, 30 Mar 2021 20:05:11 -0700 Message-Id: <20210331030520.3816265-4-swboyd@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210331030520.3816265-1-swboyd@chromium.org> References: <20210331030520.3816265-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the running kernel's build ID[1] to the stacktrace information header. This makes it simpler for developers to locate the vmlinux with full debuginfo for a particular kernel stacktrace. Combined with scripts/decode_stracktrace.sh, a developer can download the correct vmlinux from a debuginfod[2] server and find the exact file and line number for the functions plus offsets in a stacktrace. This is especially useful for pstore crash debugging where the kernel crashes are recorded in the pstore logs and the recovery kernel is different or the debuginfo doesn't exist on the device due to space concerns (the data can be large and a security concern). The stacktrace can be analyzed after the crash by using the build ID to find the matching vmlinux and understand where in the function something went wrong. Example stacktrace from lkdtm: WARNING: CPU: 4 PID: 3255 at drivers/misc/lkdtm/bugs.c:83 lkdtm_WARNING+0x28/0x30 [lkdtm] Modules linked in: lkdtm rfcomm algif_hash algif_skcipher af_alg xt_cgroup uinput xt_MASQUERADE CPU: 4 PID: 3255 Comm: bash Not tainted 5.11 #3 aa23f7a1231c229de205662d5a9e0d4c580f19a1 Hardware name: Google Lazor (rev3+) with KB Backlight (DT) pstate: 00400009 (nzcv daif +PAN -UAO -TCO BTYPE=--) pc : lkdtm_WARNING+0x28/0x30 [lkdtm] The hex string aa23f7a1231c229de205662d5a9e0d4c580f19a1 is the build ID, following the kernel version number. Put it all behind a config option, STACKTRACE_BUILD_ID, so that kernel developers can remove this information if they decide it is too much. Cc: Jiri Olsa Cc: Alexei Starovoitov Cc: Jessica Yu Cc: Evan Green Cc: Hsin-Yi Wang Cc: Petr Mladek Cc: Steven Rostedt Cc: Andy Shevchenko Cc: Matthew Wilcox Link: https://fedoraproject.org/wiki/Releases/FeatureBuildId [1] Link: https://sourceware.org/elfutils/Debuginfod.html [2] Signed-off-by: Stephen Boyd --- lib/Kconfig.debug | 11 +++++++++++ lib/dump_stack.c | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 2779c29d9981..5f883e50f406 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -35,6 +35,17 @@ config PRINTK_CALLER no option to enable/disable at the kernel command line parameter or sysfs interface. +config STACKTRACE_BUILD_ID + bool "Show build ID information in stacktraces" + depends on PRINTK + help + Selecting this option adds build ID information for symbols in + stacktraces printed with the printk format '%p[SR]b'. + + This option is intended for distros where debuginfo is not easily + accessible but can be downloaded given the build ID of the vmlinux or + kernel module where the function is located. + config CONSOLE_LOGLEVEL_DEFAULT int "Default console loglevel (1-15)" range 1 15 diff --git a/lib/dump_stack.c b/lib/dump_stack.c index f5a33b6f773f..07e0214c2d4d 100644 --- a/lib/dump_stack.c +++ b/lib/dump_stack.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -36,6 +37,12 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...) va_end(args); } +#if IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) +#define BUILD_ID_STR " %20phN" +#else +#define BUILD_ID_STR "%s" +#endif + /** * dump_stack_print_info - print generic debug info for dump_stack() * @log_lvl: log level @@ -45,13 +52,14 @@ void __init dump_stack_set_arch_desc(const char *fmt, ...) */ void dump_stack_print_info(const char *log_lvl) { - printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s\n", + printk("%sCPU: %d PID: %d Comm: %.20s %s%s %s %.*s" BUILD_ID_STR "\n", log_lvl, raw_smp_processor_id(), current->pid, current->comm, kexec_crash_loaded() ? "Kdump: loaded " : "", print_tainted(), init_utsname()->release, (int)strcspn(init_utsname()->version, " "), - init_utsname()->version); + init_utsname()->version, + IS_ENABLED(CONFIG_STACKTRACE_BUILD_ID) ? vmlinux_build_id : ""); if (dump_stack_arch_desc_str[0] != '\0') printk("%sHardware name: %s\n", -- https://chromeos.dev