Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp42712pxf; Wed, 24 Mar 2021 20:23:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuDM4Tv0vXPDrYpaR1ZPlvt7qQCsm0yInG0/Rxwd7TWzektZzyGftUd/eu3aYMvK8VMvRX X-Received: by 2002:aa7:dd05:: with SMTP id i5mr6682029edv.300.1616642594175; Wed, 24 Mar 2021 20:23:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616642594; cv=none; d=google.com; s=arc-20160816; b=j1kx3C6q47QFW7y5gRUbZWryedyydkBYN6f7STkRU/ZzVN9NfRBg9tRCE4H7GF68Sd IFBftnBScdsrCXSFldhk1X+1m4urJK4GXdZXa4u1j5GXv6xalJEc6znkwMBdE3uLaAO1 AIDXZRIVc8X/3Q2EKIDyETy1p50H+s1TPzl6m1IxMnXmBDlHSRZ63stpiaoMA4JkBTGT E+uA6vdqUYKHUf6U1+sosdOmim05Vvu5urvrayI7BaCavy/uwM/4t4EqWTr+Z/9lj0WE UkkKzPEfQ+kbxw161D9wxjnukaxpRfIDYvS2QEDb6DdOLr/QUHCk7VC5vPqRed+v3OnB limQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:date:to:cc:from:subject :references:in-reply-to:content-transfer-encoding:mime-version :dkim-signature; bh=jgwTIxb3kQfmGqGhW9clIE4XoyPxtgRgM44bNnHIRJA=; b=0XCiqBbzKmEtbOdrSkgrqrEVT6XONUDE9MaVPbuP9fmAHXfrwdKsffzFGtemAO/tDe ACFpkFwNg5NhFH/JdzR1OQX+7xwMbfMEYzuKf9vUOzbwnE7Ia1afl+dlWMl+9D2dJNaY 9dOxJW350d0vzeV6JEnmench3F55XBeFh45V7kxpjB9grERDXSp/YNsM0+vqBZXtuctR s7mTCzuhcUB8gpw+ZIHAmwUcN1OVJ/nXn8sr/etHQ12N3PLcdJlov6aNYWctJq3LgBaz 6uTMiuXqX64nnBC6PC9tvdZbQfHB2Qcb0FBrkoaeEN2Uj1aehfr/l3pXGMtODPtIBY7p juHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=jtx6m+Xs; 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 gx21si3307975ejc.503.2021.03.24.20.22.51; Wed, 24 Mar 2021 20:23:14 -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=jtx6m+Xs; 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 S237665AbhCXTG3 (ORCPT + 99 others); Wed, 24 Mar 2021 15:06:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237703AbhCXTGW (ORCPT ); Wed, 24 Mar 2021 15:06:22 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7108EC061763 for ; Wed, 24 Mar 2021 12:06:22 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id lr1-20020a17090b4b81b02900ea0a3f38c1so3107359pjb.0 for ; Wed, 24 Mar 2021 12:06:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:content-transfer-encoding:in-reply-to:references :subject:from:cc:to:date:message-id:user-agent; bh=jgwTIxb3kQfmGqGhW9clIE4XoyPxtgRgM44bNnHIRJA=; b=jtx6m+XsWwynK5IrbYLlN/i1szBH5bcX8ipkJybFqKLbyXmDevTO3+5KsJuoCoCI6j TnBWZsNV8EaPOnS5yqKSZpyhdjMxuwp2OYsCyfWnPpSRkU/93S0J/HV4Hh1w++AWSWoL joN8SFKfNFy84lEyN1PVBsZNbBhQP9VRf25qU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding :in-reply-to:references:subject:from:cc:to:date:message-id :user-agent; bh=jgwTIxb3kQfmGqGhW9clIE4XoyPxtgRgM44bNnHIRJA=; b=RpCxApAXTV2TnKxkxiocEDITRhifIVyYtoVocTBXTp8L18RoQwPyzmnHZg7iiqJiiW GweOhB0HkeXzADjNUL5QOGaKDQj65CtoaJ2N4kxlwmrP5mtk3mGVAmTZqHBFYYT2PXUZ aFsKiT1RXdVcmxoIh7wL8yVlynpNaCVsJ8ebXmpClEKRpqCZhUi//IV6IyxPIlm24FJd YLAgTBPe+ylWxvph1HaYOzMEjr8rnhcXWhZgJiMFmK34YB8Dv1c/+pvgMhewK7dSXyRy b0BZyXXmjGK1zOraJk1017cHQlTCNEqoHofx1v1BzSuN2mm4Hw2g3/X8EA2877EFnrkm XsVg== X-Gm-Message-State: AOAM532FO/goCqCn6ArKvPkYFX/MDBOLtu8yrQITnfgD7uBi8BzNG4yu SNGdojobcW5MuxZTsszhGh5jg4LNpntmGw== X-Received: by 2002:a17:90a:c797:: with SMTP id gn23mr4946489pjb.180.1616612781852; Wed, 24 Mar 2021 12:06:21 -0700 (PDT) Received: from chromium.org ([2620:15c:202:201:84ac:62f7:16a8:ccc7]) by smtp.gmail.com with ESMTPSA id e65sm3215857pfe.9.2021.03.24.12.06.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Mar 2021 12:06:21 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <7ef21ff8-8056-3b07-31ac-bc2de89fa7a0@rasmusvillemoes.dk> References: <20210324020443.1815557-1-swboyd@chromium.org> <20210324020443.1815557-3-swboyd@chromium.org> <7ef21ff8-8056-3b07-31ac-bc2de89fa7a0@rasmusvillemoes.dk> Subject: Re: [PATCH v2 02/12] buildid: Add method to get running kernel's build ID From: Stephen Boyd 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 To: Andrew Morton , Rasmus Villemoes Date: Wed, 24 Mar 2021 12:06:17 -0700 Message-ID: <161661277766.3012082.5402015164122526850@swboyd.mtv.corp.google.com> User-Agent: alot/0.9.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Rasmus Villemoes (2021-03-24 02:24:27) > On 24/03/2021 03.04, Stephen Boyd wrote: > > Add vmlinux_build_id() so that callers can print a hex format string > > representation of the running kernel's build ID. This will be used in > > the kdump and dump_stack code so that developers can easily locate the > > vmlinux debug symbols for a crash/stacktrace. > >=20 > > 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/buildid.h | 2 ++ > > lib/buildid.c | 19 +++++++++++++++++++ > > 2 files changed, 21 insertions(+) > >=20 > > diff --git a/include/linux/buildid.h b/include/linux/buildid.h > > index ebce93f26d06..2ff6b1b7cc9b 100644 > > --- a/include/linux/buildid.h > > +++ b/include/linux/buildid.h > > @@ -10,4 +10,6 @@ int build_id_parse(struct vm_area_struct *vma, unsign= ed char *build_id, > > __u32 *size); > > int build_id_parse_buf(const void *buf, unsigned char *build_id, u32 b= uf_size); > > =20 > > +const unsigned char *vmlinux_build_id(void); > > + > > #endif > > diff --git a/lib/buildid.c b/lib/buildid.c > > index 010ab0674cb9..fa1b6466b4b8 100644 > > --- a/lib/buildid.c > > +++ b/lib/buildid.c > > @@ -4,6 +4,7 @@ > > #include > > #include > > #include > > +#include > > =20 > > #define BUILD_ID 3 > > =20 > > @@ -171,3 +172,21 @@ int build_id_parse_buf(const void *buf, unsigned c= har *build_id, u32 buf_size) > > { > > return parse_build_id_buf(build_id, NULL, buf, buf_size); > > } > > + > > +/** > > + * vmlinux_build_id - Get the running kernel's build ID > > + * > > + * Return: Running kernel's build ID > > + */ > > +const unsigned char *vmlinux_build_id(void) > > +{ > > + extern const void __start_notes __weak; > > + extern const void __stop_notes __weak; > > + unsigned int size =3D &__stop_notes - &__start_notes; > > + static unsigned char vmlinux_build_id[BUILD_ID_SIZE_MAX]; > > + > > + if (!memchr_inv(vmlinux_build_id, 0, BUILD_ID_SIZE_MAX)) > > + build_id_parse_buf(&__start_notes, vmlinux_build_id, size= ); > > + > > + return vmlinux_build_id; > > +} > >=20 >=20 > Hm, is there any reason to do that initialization lazily and thus need > an accessor? If the system is coming down hard, there's a (very very > small) risk that one thread starts finding the build id, is in the > middle of the memcpy, another thread also ends up wanting the vmlinux > build id, sees some non-nul byte, and proceeds to using the partially > written vmlinux_build_id. >=20 > Perhaps consider just exposing the vmlinux_build_id[] array itself, > adding a init_vmlinux_build_id() call somewhere early in start_kernel(). >=20 > It could then also be made __ro_after_init. >=20 > In any case, if you decide to keep the current way, please rename the > local variable (just "build_id" is fine) so that it doesn't shadow the > very function it resides in, that's very confusing. >=20 No particular reason to do it this way. I'll take that approach to initialize it early in start_kernel() and then expose the array instead. Thanks!