From patchwork Thu Mar 16 17:01:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13178090 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08F5DC6FD1F for ; Thu, 16 Mar 2023 17:02:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BEE8940007; Thu, 16 Mar 2023 13:02:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 56E7E900002; Thu, 16 Mar 2023 13:02:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43638940007; Thu, 16 Mar 2023 13:02:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 30D39900002 for ; Thu, 16 Mar 2023 13:02:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id DA2251A14AD for ; Thu, 16 Mar 2023 17:02:38 +0000 (UTC) X-FDA: 80575380396.26.5B7CBFE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 91DF2180006 for ; Thu, 16 Mar 2023 17:02:36 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZhtVj376; spf=pass (imf16.hostedemail.com: domain of jolsa@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jolsa@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678986156; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PYLTagl4kcd8Qk0UixYM5D7mbmPPquB72eQ1gp+sMic=; b=3cisClnsHxnx0RNFLGS3SDU61keMT5cnH6w+m/Xx91bUDA79dB3KD+DSFvZayKP726cpx5 PAxqvMr4LA/52WRHdAgnH8ZSDZuQXpYNQMepllubmFstfXugBEPdCDKdTmYphxtus0kayq aw2Pjovg49BgAvxK+1pPpSCg6J99oHo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZhtVj376; spf=pass (imf16.hostedemail.com: domain of jolsa@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=jolsa@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678986156; a=rsa-sha256; cv=none; b=S64gN9CdZzNYXtVwAHOL15LE26fVDxjJeLpkYng/er38p0iN+EIOditZnDhdw0WdtLUpro /ocfA3Z50HCLMv2D9LpYJPFVfZ+e492/yuAFrdziQwEFKf2CEaI5F5x5msPxEXt8tThnTm QkjhmAC6lsFn3BSrqna5qsa2QOUWi1E= 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 dfw.source.kernel.org (Postfix) with ESMTPS id 99000620AC; Thu, 16 Mar 2023 17:02:35 +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 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 91DF2180006 X-Stat-Signature: 6ro7ijb7ajm7xbgrodothqyb9g65mdop X-HE-Tag: 1678986156-745281 X-HE-Meta: U2FsdGVkX18DcH3jRbig9brEstRVDmwc9e592uPryAtZpvtObQGrkYuPDB2VELazogvW1UK8BCvt6dfmT9HwGu2ECNSczjtepfuZ5PVCOpou8QDtR8vxTELtKYX5sY22mt8CLULPcFM3qerrq8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mfTBPHS14yPnSfV47ElHTKPe6eOOEzJR/DgqcnlT6CX3iYUN5XcoHowJd2hgOFxOsUuj9UKNWhzs+q17n2GCBR40x6Sel206VAcEcnVyM+l5Y3bcAzABxOSQeZ2QskG5r65cIzDrEsr5NBfm8eME2Dn2pWH8nxQ7o5RPLEUdjbn8n2vQuImeaajf8KlsrQYYiUopFH7Zh4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Acked-by: Andrii Nakryiko --- 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];