Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3623919pxb; Mon, 1 Mar 2021 15:24:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyv2ppSSdw3VKZajZUFnq9R9XRBWCCmdrJuxeTjNQS4zdT16X0Y2J144ugaEPKL53Fc7Iq8 X-Received: by 2002:a17:906:5295:: with SMTP id c21mr9730799ejm.67.1614641092202; Mon, 01 Mar 2021 15:24:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614641092; cv=none; d=google.com; s=arc-20160816; b=lOeikvXXjMZeI9DrYu7CIm7Vg4v+RdqHsLuMnQkCfco1XKpvusppynxIaKnSugwT5c PLfDiExXh6AnzQ5me/7oLW9RiA5phH2yCCzgCfFRTnz9kVvpIQiaFewZ0kqJQlqjEv35 AylRMv60LRSQt3gBb0PH499AX+Ka5pTAGJWNvMWr4GeWacAO5n5o//mEWZtHDc5aCPOC DFlDYJjIAVzP7xztPae6xxH+1KglYfEW/LC0oBXqowez7nrJGQkrmG90w4+TUpYY2J0/ URX/pxQfRABQx+2qPd9AudsgQ22NsAWOuq/zYgDuisvOTVZ1lgXDqed1lIT05iV9VXFD FVGw== 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=IgIqE4zqLLzQAgN/XnF9qZIt9tT1A/2XToO9EAjimLU=; b=MpgMnAxFM/ltjnwkL69MnWS5ZQYgCm8gS4tAlgYNtJmbwNpZghkAsY6dIiwP4qDctR OH2cRSY8KjE4yWO07BK8n78uQL1wGGSL9X/67s8gHOS/RzU2lnHJxBMcr2ofYOlErQlK 6BwXt9sFwfly+DXske0+WsDgNkfHeNAfLQo/+A/fe6VTZ5szalQd7q6V+3jpLpEDqqgy HgyzeBRSoUBmYQjWEvJ4iqzJETn6+36H2FPZnUPrmT4RP9hn6lX4xqT2GQX8IUv36ld3 25RzfSebEg0bNt6y5w/kRzVRSLFPULND+1b3lcrD71ajxPAPGOXjVpo7Zb4h9BMham26 1s6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VfHyF2nE; 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 y21si9102750edo.16.2021.03.01.15.24.29; Mon, 01 Mar 2021 15:24:52 -0800 (PST) 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=VfHyF2nE; 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 S1344635AbhCAXBV (ORCPT + 99 others); Mon, 1 Mar 2021 18:01:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238915AbhCARv1 (ORCPT ); Mon, 1 Mar 2021 12:51:27 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F298C061223 for ; Mon, 1 Mar 2021 09:48:00 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id q204so10950456pfq.10 for ; Mon, 01 Mar 2021 09:48:00 -0800 (PST) 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=IgIqE4zqLLzQAgN/XnF9qZIt9tT1A/2XToO9EAjimLU=; b=VfHyF2nE1SnOgwI5Uql6AynW2ttrEoJiik3YsgU7Lqu9nf6lKI51JNaQtRIXXQuCEY rduQvXX7/Sss8fYkbvL0dwSw/qkqMjqwYmUJKWOL/lb4qo8Srv9+gvBgjgwtlGOuf8XM h3Ol8EzA/Tc4XT26dgl/vpJBfizhk3tTedPao= 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=IgIqE4zqLLzQAgN/XnF9qZIt9tT1A/2XToO9EAjimLU=; b=tO50p1CWP09aH8Rh+28H52XvRolCwN2YMmnJZs6VD3o1MHf18ZUjgkG1GIBw/tWyPi tnUsZ1nKMUyQYpzIpSPk8PZeXWBuLaflZ7VTY2+3FhgPuARIVb4BrsSePo8iDMkV3Da0 o6CoxNLabv4idcgKbcIMiakMpJd8z+s1oY7dNeAWugFOIINxwWBEEMOQqY5Y4bT8KDVQ n61Mnngv5fXKdi18eAX2xNKs1zKmNESNxOJigCIOXM28ct4HFBCneuvatCi2TRE+O4Fl A5rCsLrJRWv5GcYTMF4xa7wjQtPPrVEKMiaoyEteR2HaH/3/l5kIv9Mar7L5/9MraSZm VObA== X-Gm-Message-State: AOAM533wi6uPGQGdFaHQrtLaMGMKDTLwYz/O4vMLjqLdaAIEyHu7V9UP lgtIxY0n1hSvgf/z0HsfjoCxCcFaKSa62w== X-Received: by 2002:a65:4288:: with SMTP id j8mr11064519pgp.231.1614620880253; Mon, 01 Mar 2021 09:48:00 -0800 (PST) Received: from smtp.gmail.com ([2620:15c:202:201:3c20:df33:e36:93df]) by smtp.gmail.com with ESMTPSA id y202sm19071325pfb.153.2021.03.01.09.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 09:47:59 -0800 (PST) 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 7/7] kdump: Use vmlinux_build_id() to simplify Date: Mon, 1 Mar 2021 09:47:49 -0800 Message-Id: <20210301174749.1269154-8-swboyd@chromium.org> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog In-Reply-To: <20210301174749.1269154-1-swboyd@chromium.org> References: <20210301174749.1269154-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() helper here now instead of open coding it. This consolidates code and possibly avoids calculating the build ID twice in the case of a crash with a stacktrace. 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 --- kernel/crash_core.c | 46 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index 825284baaf46..07d3e1109a8c 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,51 +379,20 @@ 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); + const char *build_id = vmlinux_build_id(); + + if (build_id[0] == '\0') { + pr_warn("Build ID cannot be included in vmcoreinfo\n"); + return; } + + VMCOREINFO_BUILD_ID(build_id); } static int __init crash_save_vmcoreinfo_init(void) -- https://chromeos.dev