Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp141644pxy; Tue, 20 Apr 2021 14:55:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBjHM+5zwug5d6RahZ5nptWswmS4oEELYmJ3fx2A571BLFa6e6sKHMPZAkVBzlZG5TlQy5 X-Received: by 2002:a17:906:f2c3:: with SMTP id gz3mr6063865ejb.147.1618955750500; Tue, 20 Apr 2021 14:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618955750; cv=none; d=google.com; s=arc-20160816; b=aUHXmyGLXcTgoyQsgJ8lX5te9wFV3mVU6W8nJ+0miO56XecW4FOFR+IDJoz/geguCp eYJ99v7wTkB/hRFtOkQp6wx7uBMGhDnn47mFOp/Fp12RRwLIK2KVrliSXzBqOQLTTM30 CmiEoiwg4oW5YLRwPYioiJASNvizWZhOpunBsOOsRvpS1lkj11LH0ht9eHDYs11A9DlH yl3K/PJdU3u0RuI59rQOfozqYQg8aKdtID+F4gj0DWX94xMNfbFsw+KNlqUj16vEORq0 zZUidu4w5R4NuFij3tfTIuTwil+HH1voSh/cDStsj5v83K3VVMnL4Q1wcyL4KWQRE9XI +aKQ== 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=jo339a9O/xQsdX+NYbQT8mbjTnbUeOsyXpYpAUuwZJo=; b=kNn4CQUqH4+jtIxho0W1F5u7IToAgcnHNo9rq7+ukuxccT/LDq/w4s1ZHan0JlzLQv LaCnaFgBaLtgpjoO+2N7idgukpUyLRS1f5ZOUU9ibESkGKwfPpB6HFeZBx8fq027PLFi VzcuEhexASaFwmAtES5O1EnvGQ2RZ9vxjkbNqU3MKR+6hj8cqzp4MwlmaBiy3wXdndPf Ik8C8D7iQFnGQtoNpsVPpYIhVpPOe9QFuAoD9jKzF56t+7tiGv6SC7JmnFKBpYg6ybbe ZhpzHFH+095B7rHJs8vB/Qt4KRsaM9JPqdAQ7gwz5LZrCnBXoe4Lj2/nCpMF5hVT/71P GPFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=G2x6LkLj; 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 c7si48140ejx.166.2021.04.20.14.55.05; Tue, 20 Apr 2021 14:55:50 -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=G2x6LkLj; 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 S234307AbhDTVvb (ORCPT + 99 others); Tue, 20 Apr 2021 17:51:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234237AbhDTVuv (ORCPT ); Tue, 20 Apr 2021 17:50:51 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99874C061346 for ; Tue, 20 Apr 2021 14:50:15 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id q2so2301572pfk.9 for ; Tue, 20 Apr 2021 14:50:15 -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=jo339a9O/xQsdX+NYbQT8mbjTnbUeOsyXpYpAUuwZJo=; b=G2x6LkLjKgU0qE4ZjA2lHm2dCG+twxxo0HZWcDHZeB6gliC/fIKe/v/ePgRf147lZh wi+eSq4724qu7zLstrLK0QjSxcaIX2Elqf1izNR2fIsj8j+Y7/MDpqpZb1I5u6bhHRAI YtALafB/lkPTjLaqYiZoT1X0SU/tuzLnJ9tfo= 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=jo339a9O/xQsdX+NYbQT8mbjTnbUeOsyXpYpAUuwZJo=; b=JiSNYFD5KTWPFuYubx5/vC4WkxHcaftW0yQFtFYqriBVo/AhKPZEJiRxP17POsZp/r KJDpxDKohXa3NMHl8fs5/LSSX8SrRbealR/cVED/KenVL7cA4kGKqohYDDEM4arLZnpY 695WYgSCoaGiYn5JgLligqZd+0Fy084MKsOzLk8d2CoUZWDoTomBaVBmdg65Y/8Q85Hr NjnyLp3ICp1+WMUVHcjyuE3ZKbjIUezoPjaXPzyy33nEF85SJwe1NdorLT/u7voTnZXb Fn/uc8G/rdf6ENtjRXLo+ucdHo8/94veV4rF4D8BpbMS/spZ4U68zPYbw99yZql6VVdn ncBw== X-Gm-Message-State: AOAM533RwGXG2Rdg7z5hNUYETmA7kKFXPDZEsp+8Wt06Xl0flrxLD+yR YiqDxoJZuWenXjcqFC5wEgLYdQ== X-Received: by 2002:aa7:9e4f:0:b029:25e:cf65:c554 with SMTP id z15-20020aa79e4f0000b029025ecf65c554mr13105127pfq.66.1618955415205; Tue, 20 Apr 2021 14:50:15 -0700 (PDT) Received: from smtp.gmail.com ([2620:15c:202:201:bf8b:4b8b:2315:3719]) by smtp.gmail.com with ESMTPSA id c21sm31481pfo.91.2021.04.20.14.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Apr 2021 14:50:14 -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 , Dave Young , Baoquan He , Vivek Goyal , kexec@lists.infradead.org Subject: [PATCH v5 13/13] kdump: Use vmlinux_build_id to simplify Date: Tue, 20 Apr 2021 14:50:03 -0700 Message-Id: <20210420215003.3510247-14-swboyd@chromium.org> X-Mailer: git-send-email 2.31.1.368.gbe11c130af-goog In-Reply-To: <20210420215003.3510247-1-swboyd@chromium.org> References: <20210420215003.3510247-1-swboyd@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We can use the vmlinux_build_id array here now instead of open coding it. This mostly consolidates code. Cc: Jiri Olsa Cc: Alexei Starovoitov Cc: Jessica Yu Cc: Evan Green Cc: Hsin-Yi Wang Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: Signed-off-by: Stephen Boyd --- include/linux/crash_core.h | 12 ++++----- kernel/crash_core.c | 50 ++------------------------------------ 2 files changed, 8 insertions(+), 54 deletions(-) diff --git a/include/linux/crash_core.h b/include/linux/crash_core.h index 206bde8308b2..de62a722431e 100644 --- a/include/linux/crash_core.h +++ b/include/linux/crash_core.h @@ -38,8 +38,12 @@ phys_addr_t paddr_vmcoreinfo_note(void); #define VMCOREINFO_OSRELEASE(value) \ vmcoreinfo_append_str("OSRELEASE=%s\n", value) -#define VMCOREINFO_BUILD_ID(value) \ - vmcoreinfo_append_str("BUILD-ID=%s\n", value) +#define VMCOREINFO_BUILD_ID() \ + ({ \ + static_assert(sizeof(vmlinux_build_id) == 20); \ + vmcoreinfo_append_str("BUILD-ID=%20phN\n", vmlinux_build_id); \ + }) + #define VMCOREINFO_PAGESIZE(value) \ vmcoreinfo_append_str("PAGESIZE=%ld\n", value) #define VMCOREINFO_SYMBOL(name) \ @@ -69,10 +73,6 @@ extern unsigned char *vmcoreinfo_data; extern size_t vmcoreinfo_size; extern u32 *vmcoreinfo_note; -/* raw contents of kernel .notes section */ -extern const void __start_notes __weak; -extern const void __stop_notes __weak; - Elf_Word *append_elf_note(Elf_Word *buf, char *name, unsigned int type, void *data, size_t data_len); void final_note(Elf_Word *buf); diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 825284baaf46..29cc15398ee4 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -4,6 +4,7 @@ * Copyright (C) 2002-2004 Eric Biederman */ +#include #include #include #include @@ -378,53 +379,6 @@ phys_addr_t __weak paddr_vmcoreinfo_note(void) } EXPORT_SYMBOL(paddr_vmcoreinfo_note); -#define NOTES_SIZE (&__stop_notes - &__start_notes) -#define BUILD_ID_MAX SHA1_DIGEST_SIZE -#define NT_GNU_BUILD_ID 3 - -struct elf_note_section { - struct elf_note n_hdr; - u8 n_data[]; -}; - -/* - * Add build ID from .notes section as generated by the GNU ld(1) - * or LLVM lld(1) --build-id option. - */ -static void add_build_id_vmcoreinfo(void) -{ - char build_id[BUILD_ID_MAX * 2 + 1]; - int n_remain = NOTES_SIZE; - - while (n_remain >= sizeof(struct elf_note)) { - const struct elf_note_section *note_sec = - &__start_notes + NOTES_SIZE - n_remain; - const u32 n_namesz = note_sec->n_hdr.n_namesz; - - if (note_sec->n_hdr.n_type == NT_GNU_BUILD_ID && - n_namesz != 0 && - !strcmp((char *)¬e_sec->n_data[0], "GNU")) { - if (note_sec->n_hdr.n_descsz <= BUILD_ID_MAX) { - const u32 n_descsz = note_sec->n_hdr.n_descsz; - const u8 *s = ¬e_sec->n_data[n_namesz]; - - s = PTR_ALIGN(s, 4); - bin2hex(build_id, s, n_descsz); - build_id[2 * n_descsz] = '\0'; - VMCOREINFO_BUILD_ID(build_id); - return; - } - pr_warn("Build ID is too large to include in vmcoreinfo: %u > %u\n", - note_sec->n_hdr.n_descsz, - BUILD_ID_MAX); - return; - } - n_remain -= sizeof(struct elf_note) + - ALIGN(note_sec->n_hdr.n_namesz, 4) + - ALIGN(note_sec->n_hdr.n_descsz, 4); - } -} - static int __init crash_save_vmcoreinfo_init(void) { vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL); @@ -443,7 +397,7 @@ static int __init crash_save_vmcoreinfo_init(void) } VMCOREINFO_OSRELEASE(init_uts_ns.name.release); - add_build_id_vmcoreinfo(); + VMCOREINFO_BUILD_ID(); VMCOREINFO_PAGESIZE(PAGE_SIZE); VMCOREINFO_SYMBOL(init_uts_ns); -- https://chromeos.dev