Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1526455lqp; Mon, 15 Apr 2024 08:54:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU0EiaUCzlu3+7Gtt5WhMI8d1W5Xj+P1qrMvIQ8CxMMF5JMRy/bVFoHM7Cojd8gITxq3ssQN2329OYsORPgg/K7vowXNhNouRqOAfsoEw== X-Google-Smtp-Source: AGHT+IENuMccRYBO0ObQQkTf1lXCb+hgq95h61Egw7JVz/obqyVbvYAr+mOWgD4v8XRrRN/BhvG+ X-Received: by 2002:a50:d79c:0:b0:568:aa14:37a9 with SMTP id w28-20020a50d79c000000b00568aa1437a9mr8279191edi.24.1713196482851; Mon, 15 Apr 2024 08:54:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713196482; cv=pass; d=google.com; s=arc-20160816; b=jbSbjBi+L4OA533c6qrwrLrZD6Uz5Ope0XgMqzEc33Q8E/Cq2j8LQmTB18Ep0BIBI+ CmuNAg0HR3vt6+AMgOl3BNyk7zvuJuslg06M11FK/MiJ/yVXf4xImBvgmPC/qiafdvLI 3sLvPXWnw5xpE/eC8MQctzW413xTzoTYZLG0GApry5DqPgWfu0HsjoJtHYWIMeFQj5Zt nILXijvH+Z3inzG4EgRLaS2Rw/nere4GpKOwRDw07L2GByvcMER7Ml56VWgw5pc0HRYT G/jghoro/Mtg9cZQj6PVYzB0R7VLPolf2iR4T7oXXlzmLbCavpqikC3s1KyNpTVUQMWZ DdCQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=hnGXAVtsL1HKk20m0ycQIWWdAoWF/GPzorWAD1i5Gms=; fh=1hzv5ZYaU0FzDF3Hbvx8ESgPivO5lV9bO5Rax3Ke9iA=; b=x4S5nWdx1W59CdVzrPp775EA5YklqeVqSSTXFXCxkXvLW1HScjx1dWZoN4b9G7FcZ+ O1mbKfYlzt4gZH6y9GPWNS9ax9FKzq9u8KXglEQlVeGubY06n9sWXNOwQ/mKvTH0QZwL LA611Hzd2bVBGiDl86GG/gXZ/MPWRDHvnrpvW1g7V6vWvLqrmt6GLMYVb65lKAysi0S0 R07MCvL9zx92vxKccrvFToqIEuBzZCDxa6c6EL7BLgTCO2RvIgRC8lYPC7WkD0nB4cl2 70f1VqIR8Q0ZgJwh0ZpuwGSfxvImlLjKLiIfGjLjGD43VwKiZKqAfpFhdDaIKVovnPX1 TPsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MHA06EKo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g12-20020a0564021ecc00b0057000ee9f9dsi3364635edg.54.2024.04.15.08.54.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Apr 2024 08:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-145488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MHA06EKo; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-145488-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-145488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5EC971F2214F for ; Mon, 15 Apr 2024 15:54:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14E977F495; Mon, 15 Apr 2024 15:54:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MHA06EKo" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E0DB76033; Mon, 15 Apr 2024 15:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713196470; cv=none; b=maqOi8/w8ApRjdUBl7+N+HKnq0fY2pXEZcsiMtmezA5NVKO+bj1qpCi70z41TzePonLoe/LCIpTzvPzNAO/Lz5LYuvCCs1ETiakzrv/bANh4Ft2lUSGHWqSi7ggdP6yqgc89puXlREshQSSPHHjsNNmEVDNagD280GI87zUQw9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713196470; c=relaxed/simple; bh=8c+SYgrvRngaG/lFXqJ0rfeZ6kkSQCqNuwsCJEg3GmQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=MC2nm0WOuAL10p+AZyA3biYsJ+Mj/sTnJYrqoFn7jbxdt8mwbXG9gmyGw27/+TINiNVZmrTsO8r/1Qlple01uz9IMz+Bxr6bcle/Q0jYRJ86vVm1wNeJLDA8bbm9HMo6qQMeZJ9639G5HZH+IXyMOBjbqM7Mk2r+soXB5aKiSNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MHA06EKo; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 969D7C3277B; Mon, 15 Apr 2024 15:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713196469; bh=8c+SYgrvRngaG/lFXqJ0rfeZ6kkSQCqNuwsCJEg3GmQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MHA06EKoO7MrUWj/nPmINQgS9zR3tBDS40OTFTx0FLk61K+OPsdCqMcEDRWwxpJCu OA+irVxOr8jJlbXdqv92CzguA8ij3sqTfVd2CgDaYozOwRvceVaEOwU8CIt0J/PVKr 2eJYxmAJQPiEA9rcsEswDqvghXF2YTwmnmcmUI9IRAcvS8u3i5L3gc/tOxYIvlnD4i aHiFaNHI7fTsDs5BRnPycFMV/MGMf/nYfudMPLRcFVwc0JoJCGugeCPdDKltjfTErL 43M2xaiNyCMlP4oGyigOnL6Paja4n4Sbky7twiPaNylKWIPIrJ7w2F50eI39/Fz73a ZkwaiuyZFpsew== Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2da01cb187cso61492511fa.0; Mon, 15 Apr 2024 08:54:29 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUvC4lH5Hc/fWoOHyF6C7JUKRhZcLWMD7PUK8I8HVevLDpqLfEK2DvcH6qFultkp9I2zBYbg7PSX/po+UmF1Ysxt50ZgjZpHN3jKn7SyMBZ0bcThCrWsPEyWipY1CKL3/A0vqsnptO6aEVVgh72Jg/5edlyEZk0abtO3aninD4dlYTlQHrius8iKiDadhXmttmmxfiOar0oqIrOCA== X-Gm-Message-State: AOJu0YzleusBl0mW3FmR/i0lfDGSmRKgLIpf/byqFJQX7YfjwafFpx+c +X9di7kXFgVT52vJ2ALav8F9iLoxbxcYulJI2w7+PAgN7V4hEYCd4iSOFcULEDV3cUGWsphshv1 mwPcW0Gm74PHnpCBosHnPp1lJniI= X-Received: by 2002:a2e:97d4:0:b0:2d8:41c5:ad64 with SMTP id m20-20020a2e97d4000000b002d841c5ad64mr7041107ljj.13.1713196467919; Mon, 15 Apr 2024 08:54:27 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240415075837.2349766-5-ardb+git@google.com> <20240415075837.2349766-8-ardb+git@google.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 15 Apr 2024 17:54:16 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 3/3] btf: Avoid weak external references To: Masahiro Yamada Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Arnd Bergmann , Martin KaFai Lau , linux-arch@vger.kernel.org, linux-kbuild@vger.kernel.org, bpf@vger.kernel.org, Andrii Nakryiko , Jiri Olsa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 15 Apr 2024 at 17:32, Masahiro Yamada wrote: > > On Mon, Apr 15, 2024 at 11:59=E2=80=AFPM Ard Biesheuvel = wrote: > > > > On Mon, 15 Apr 2024 at 16:55, Masahiro Yamada wr= ote: > > > > > > On Mon, Apr 15, 2024 at 4:58=E2=80=AFPM Ard Biesheuvel wrote: > > > > > > > > From: Ard Biesheuvel > > > > > > > > If the BTF code is enabled in the build configuration, the start/st= op > > > > BTF markers are guaranteed to exist in the final link but not durin= g the > > > > first linker pass. > > > > > > > > Avoid GOT based relocations to these markers in the final executabl= e by > > > > providing preliminary definitions that will be used by the first li= nker > > > > pass, and superseded by the actual definitions in the subsequent on= es. > > > > > > > > Make the preliminary definitions dependent on CONFIG_DEBUG_INFO_BTF= so > > > > that inadvertent references to this section will trigger a link fai= lure > > > > if they occur in code that does not honour CONFIG_DEBUG_INFO_BTF. > > > > > > > > Note that Clang will notice that taking the address of__start_BTF c= annot > > > > yield NULL any longer, so testing for that condition is no longer > > > > needed. > > > > > > > > Acked-by: Andrii Nakryiko > > > > Acked-by: Arnd Bergmann > > > > Signed-off-by: Ard Biesheuvel > > > > --- > > > > include/asm-generic/vmlinux.lds.h | 9 +++++++++ > > > > kernel/bpf/btf.c | 7 +++++-- > > > > kernel/bpf/sysfs_btf.c | 6 +++--- > > > > 3 files changed, 17 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generi= c/vmlinux.lds.h > > > > index e8449be62058..4cb3d88449e5 100644 > > > > --- a/include/asm-generic/vmlinux.lds.h > > > > +++ b/include/asm-generic/vmlinux.lds.h > > > > @@ -456,6 +456,7 @@ > > > > * independent code. > > > > */ > > > > #define PRELIMINARY_SYMBOL_DEFINITIONS = \ > > > > + PRELIMINARY_BTF_DEFINITIONS = \ > > > > PROVIDE(kallsyms_addresses =3D .); = \ > > > > PROVIDE(kallsyms_offsets =3D .); = \ > > > > PROVIDE(kallsyms_names =3D .); = \ > > > > @@ -466,6 +467,14 @@ > > > > PROVIDE(kallsyms_markers =3D .); = \ > > > > PROVIDE(kallsyms_seqs_of_names =3D .); > > > > > > > > +#ifdef CONFIG_DEBUG_INFO_BTF > > > > +#define PRELIMINARY_BTF_DEFINITIONS = \ > > > > + PROVIDE(__start_BTF =3D .); = \ > > > > + PROVIDE(__stop_BTF =3D .); > > > > +#else > > > > +#define PRELIMINARY_BTF_DEFINITIONS > > > > +#endif > > > > + > > > > > > > > > > > > Is this necessary? > > > > > > > I think so. > > > > This actually resulted in Jiri's build failure with v2, and the > > realization that there was dead code in btf_parse_vmlinux() that > > happily tried to load the contents of the BTF section if > > CONFIG_DEBUG_INFO_BTF was not enabled to begin with. > > > > So this is another pitfall with weak references: the symbol may > > unexpectedly be missing altogether rather than only during the first > > linker pass. > > > > > > > > > > > The following code (BOUNDED_SECTION_BY) > > > produces __start_BTF and __stop_BTF symbols > > > under the same condition. > > > > > > > Indeed. So if CONFIG_DEBUG_INFO_BTF=3Dn, code can still link to > > __start_BTF and __stop_BTF even though BTF is not enabled. > > > > I am talking about the case for CONFIG_DEBUG_INFO_BTF=3Dy. > > PROVIDE() is meaningless because __start_BTF and __stop_BTF > are produced by the existing code. > > (The code was a bit clearer before commit > 9b351be25360c5cedfb98b88d6dfd89327849e52) > > > > So, v4 of this patch will look like 2/3, right? > > > Just drop __weak attribute. > > You still need > > if (!IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) > return ERR_PTR(-ENOENT); > > But, you do not need to modify vmlinux.lds.h > OK, I see what you mean now. The PROVIDE() is indeed unnecessary - I'll drop that bit in v4.