Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4006868pxb; Tue, 25 Jan 2022 01:12:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyY53XQs9Nljz9Fku0pBElzsvZnkHLkWOwrmXSslqHdcDshQz1N3k3usLY6P6KTbmBr/6fv X-Received: by 2002:a17:902:b681:b0:14a:9cc:d9a3 with SMTP id c1-20020a170902b68100b0014a09ccd9a3mr18175231pls.121.1643101928765; Tue, 25 Jan 2022 01:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643101928; cv=none; d=google.com; s=arc-20160816; b=CSfuVSJUbUgN5JLLFqgfOeLCNECqywYoqT2+3gO3M3zFTa03iR0sqzpqsJDZGr/XbP vmcSTGIsuWHnt5guPdSpckovKl5W2mMeR3rxLr5iXUu3bK727dYp3f6QJ5z1rsCuNlyL MFFkgK6CpxxBrl9vqTuq3o+vsGuN/YZ9ZyNQqEfC7H3CARg3zvVcSqK8njlHOeUwrVY1 c9JnyDgRISpUFnGwXUdgbFODYtD5Y7oe0/Q5W5tT2R9pv0hlUtsiVpIUQQ4WHa4jv6T3 So2TIhbVITgqbZnVr4ImKwtrPre59S+xWNKx6S43bVMB9Kte26wVbqSSkq9MOPFqwl3j zavg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u4sZb43o6v9pvDvs7BsPPpiWoB/VBKMPiOOl3tPLaEs=; b=SjwxyCvJm7YOygDalpXCiLjlbWdYI2xKUooiWn4fu2b6QGoYYJrYO9B69X/BkbwlUj Z9ddiZ4jGSEWjJgHh0IxgRUw+Fo4CkRwtIRx+nXULZnf4zFx3ndDxSDU+skwmW+7PFDE qIYHvne2jkDkOsK/ll8gCAR9LnfODvef51aiV5l06sFMBr7b2BlCQfn22bFeGox4yKSo gqCYHbGuKt2Jsb3OKmpTEpC056AnQzydXPKTo3dKr3vVlb/gonGn+JzTzqHZkGleJ+Jz Jv6PVa2TXaN/P8/Ox0oGRiUuBojYi2qWtULlMmjWU+U6w2bt0rxPlSfalTkRoRYMYBmT RRDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GftWM3c1; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si1669150pll.552.2022.01.25.01.11.53; Tue, 25 Jan 2022 01:12:08 -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=@kernel.org header.s=k20201202 header.b=GftWM3c1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442697AbiAYHKj (ORCPT + 99 others); Tue, 25 Jan 2022 02:10:39 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:54032 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442405AbiAYHIP (ORCPT ); Tue, 25 Jan 2022 02:08:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id BFE87CE1764; Tue, 25 Jan 2022 07:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13D93C340E6; Tue, 25 Jan 2022 07:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643094477; bh=u4sZb43o6v9pvDvs7BsPPpiWoB/VBKMPiOOl3tPLaEs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=GftWM3c1oIqLFALD23owKTErEZfdczcMT8uVPxGLP1FOkBmR1KtCfQlDYB8d6riL8 DPO4fVeV5rN4oKIV/NGuFFriOPq0d9MNMXrycCIeRnZtIDSC888/FqYqeJAd1loBtA hXx+UyrWJRWu5z0Liq3idU4Acw4Krc4kyOXxUymIUCtW2CeSt/my0j5CtcpE11hz82 efA+jIDbZ5nwan6om754XfkbxhyZ1x7WanhNeGUoHS6K4izmm/GuBYsh/FFkJyAM+d 4eJsnOwPf+hR2epbDvchWReD02znUZ4KI+EtbSobJIn5nlYbvmni6AuNhx6MRAVv3e 3cd7v/zi0KY/A== Received: by mail-yb1-f169.google.com with SMTP id r65so55267861ybc.11; Mon, 24 Jan 2022 23:07:57 -0800 (PST) X-Gm-Message-State: AOAM532Eymuk8g76qQJeJ6llUNBNDzuA8/8PA7ajb2YILHgMD/VEIpmI 9+2GPoYApt17FypcDiJAlIx31dcZcOAgMwd6Ajk= X-Received: by 2002:a25:fd6:: with SMTP id 205mr29018898ybp.654.1643094475930; Mon, 24 Jan 2022 23:07:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Song Liu Date: Mon, 24 Jan 2022 23:07:45 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [Question] How to reliably get BuildIDs from bpf prog To: Hao Luo Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Song Liu , Yonghong Song , Martin KaFai Lau , KP Singh , bpf , open list , Jiri Olsa , Blake Jones , Alexey Alexandrov , Namhyung Kim , Ian Rogers , "pasha.tatashin@soleen.com" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 24, 2022 at 2:43 PM Hao Luo wrote: > > Dear BPF experts, > > I'm working on collecting some kernel performance data using BPF > tracing prog. Our performance profiling team wants to associate the > data with user stack information. One of the requirements is to > reliably get BuildIDs from bpf_get_stackid() and other similar helpers > [1]. > > As part of an early investigation, we found that there are a couple > issues that make bpf_get_stackid() much less reliable than we'd like > for our use: > > 1. The first page of many binaries (which contains the ELF headers and > thus the BuildID that we need) is often not in memory. The failure of > find_get_page() (called from build_id_parse()) is higher than we would > want. Our top use case of bpf_get_stack() is called from NMI, so there isn't much we can do. Maybe it is possible to improve it by changing the layout of the binary and the libraries? Specifically, if the text is also in the first page, it is likely to stay in memory? > 2. When anonymous huge pages are used to hold some regions of process > text, build_id_parse() also fails to get a BuildID because > vma->vm_file is NULL. How did the text get in anonymous memory? I guess it is NOT from JIT? We had a hack to use transparent huge page for application text. The hack looks like: "At run time, the application creates an 8MB temporary buffer and the hot section of the executable memory is copied to it. The 8MB region in the executable memory is then converted to a huge page (by way of an mmap() to anonymous pages and an madvise() to create a huge page), the data is copied back to it, and it is made executable again using mprotect()." If your case is the same (or similar), it can probably be fixed with CONFIG_READ_ONLY_THP_FOR_FS, and modified user space. Thanks, Song