Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 338BDC76196 for ; Thu, 16 Mar 2023 17:02:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbjCPRCw (ORCPT ); Thu, 16 Mar 2023 13:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229870AbjCPRCt (ORCPT ); Thu, 16 Mar 2023 13:02:49 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20889E7EF4; Thu, 16 Mar 2023 10:02:38 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 92B11B8227B; Thu, 16 Mar 2023 17:02:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04ED5C433D2; Thu, 16 Mar 2023 17:02:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678986155; bh=GA8tXS4Mul2elWYsjsHoBsAbirrUGLhRxbF2Iayc8rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZhtVj376qlPRWZ1voHqasur/pICqPh2D1iv3o8cqWfD6Tqwvn3vzB/NHNzr5q2zvc Du2DgVvnZu67X8HekIq3/BB471wLGP+xMh44yTpxdsA6MJ4i52t9Npw6fiUxKq79AZ BVAKBWemUcdBpEcTGD1w7L96mTMWWbvInC9HuwInR990nvhl2XzxnJL/fE2VLgeg3z M1me3mgk3ZFsAMmRYmy1tCPnFvQsZ8E0lS7EnHJoajef6uFHZoErIYZA4oTQ5C+GUn /zyUjx1ODsI4xjPqeOEyO5tNqStX53VCPmBS3mjJtL3+81scbzKF/Kf3q+8KkHUC9A CKaZl7dtXKDTg== From: Jiri Olsa To: Alexei Starovoitov , Andrii Nakryiko , Hao Luo , Andrew Morton , Alexander Viro , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Matthew Wilcox Cc: bpf@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Daniel Borkmann , Namhyung Kim , Dave Chinner Subject: [PATCHv3 bpf-next 3/9] bpf: Use file object build id in stackmap Date: Thu, 16 Mar 2023 18:01:43 +0100 Message-Id: <20230316170149.4106586-4-jolsa@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230316170149.4106586-1-jolsa@kernel.org> References: <20230316170149.4106586-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use build id from file object in stackmap if it's available. The file's f_build_id is available (for CONFIG_FILE_BUILD_ID option) when the file is mmap-ed, so it will be available (if present) when used by stackmap. Signed-off-by: Jiri Olsa --- kernel/bpf/stackmap.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 0f1d8dced933..14d27bd83081 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -124,6 +124,28 @@ static struct bpf_map *stack_map_alloc(union bpf_attr *attr) return ERR_PTR(err); } +#ifdef CONFIG_FILE_BUILD_ID +static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id) +{ + struct build_id *bid; + + if (!vma->vm_file) + return -EINVAL; + bid = vma->vm_file->f_build_id; + if (IS_ERR_OR_NULL(bid)) + return bid ? PTR_ERR(bid) : -ENOENT; + if (bid->sz > BUILD_ID_SIZE_MAX) + return -EINVAL; + memcpy(build_id, bid->data, bid->sz); + return 0; +} +#else +static int vma_get_build_id(struct vm_area_struct *vma, unsigned char *build_id) +{ + return build_id_parse(vma, build_id, NULL); +} +#endif + static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, u64 *ips, u32 trace_nr, bool user) { @@ -156,7 +178,7 @@ static void stack_map_get_build_id_offset(struct bpf_stack_build_id *id_offs, goto build_id_valid; } vma = find_vma(current->mm, ips[i]); - if (!vma || build_id_parse(vma, id_offs[i].build_id, NULL)) { + if (!vma || vma_get_build_id(vma, id_offs[i].build_id)) { /* per entry fall back to ips */ id_offs[i].status = BPF_STACK_BUILD_ID_IP; id_offs[i].ip = ips[i]; -- 2.39.2