From patchwork Wed Feb 1 13:57:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13124345 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 52994C05027 for ; Wed, 1 Feb 2023 13:58:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C83A36B0078; Wed, 1 Feb 2023 08:58:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C33FB6B007B; Wed, 1 Feb 2023 08:58:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFC406B007D; Wed, 1 Feb 2023 08:58:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A1D986B0078 for ; Wed, 1 Feb 2023 08:58:26 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7BBFC80DE0 for ; Wed, 1 Feb 2023 13:58:26 +0000 (UTC) X-FDA: 80418877812.13.15AF932 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf17.hostedemail.com (Postfix) with ESMTP id 8EDDF40015 for ; Wed, 1 Feb 2023 13:58:24 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rvH85aZN; spf=pass (imf17.hostedemail.com: domain of jolsa@kernel.org designates 145.40.68.75 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=1675259904; 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=8FCui8WL491QoBd3thR5w+VKt0dx+TMQh95kNOjhXdM=; b=SHAaaIKMGpKtWusqHw2PZTFUtB3neMgERx14xqEhYDLti+/VbM4wGGJ62nbzkRM7mL7icD 1Ob3TRpixk+P66nDPVkeZcgSZZVaCPghNh2Qr3nHPD5JbE9PhY5BxwZCScM7JiSuEqL8Ib DQruNyfUc83R3kBdapL8R8DOv1lrEgg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=rvH85aZN; spf=pass (imf17.hostedemail.com: domain of jolsa@kernel.org designates 145.40.68.75 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=1675259904; a=rsa-sha256; cv=none; b=VFGMJEg8mcVJwYZrYXoOLGT9L38iJKjsKgxQa2sYy6i7Xg+YvMkTZDzzMtSV+WWhS3LHMc Yi/zj1W7jBMU2m0iXrwvZHkkVeePzhfKQy5NhY9SozPZIIg6o4l4WnC68yr/xXxlSDOqJA /t5Ko41RKC5y47bvW36KVSv5Dvq3ze0= 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 2CB9DB821A4; Wed, 1 Feb 2023 13:58:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 325E2C4339B; Wed, 1 Feb 2023 13:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675259901; bh=aLPnAbPHT8a02PSgEV9wcJJL8dIRbp5TcW8HLfo0WbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rvH85aZNkyrEZQUXF6LXPZDUhDCIneD+wlLL8wRJAzoq7xdGsbZ4t9y4SSe7WIaYV ZsVEfIlDeihAbZRx2dqyt4yynUmxQ742B/1VsTqAN3o/+tb8MjpZujt1pnkTLeX9Is FpMyWfOOKcWUCpcAeCuz0mVsDgqyctFbWxB6UIGy7MexEJ1ExskMh4Sm6yQTli7XLu DBNcNlbqf9PNhhpjpP7jDzCBD8dT6rTWEbaPDJMy1b2Noh+HdZ23q0LBZ0wnUrzSg/ y3F7rfav54xFq/3hGRpV/VFwWAnwAH2T2XgZDoyB/yvAcZuh5vrUqO2XiROuOwbTU9 Uecjvuc+qafkA== From: Jiri Olsa To: Alexei Starovoitov , Andrii Nakryiko , Hao Luo , Andrew Morton , Alexander Viro , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo 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 Subject: [PATCH RFC 3/5] perf: Use file object build id in perf_event_mmap_event Date: Wed, 1 Feb 2023 14:57:35 +0100 Message-Id: <20230201135737.800527-4-jolsa@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230201135737.800527-1-jolsa@kernel.org> References: <20230201135737.800527-1-jolsa@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8EDDF40015 X-Stat-Signature: abqk1ffithzn5pf7nhjcndoe3caemkxn X-Rspam-User: X-HE-Tag: 1675259904-15985 X-HE-Meta: U2FsdGVkX19z/L3KfDntx0LkUIHfQNkwaby3Y0Q+Y01EYtfszkmjwmBo4gTxnfkbRTFTG0BociDhrTLcx4q9zpCZNqbXTt0icMf3Q2bVP8aHIV2DwTNbUBiHJ+u8f2IZ2XCmq7/7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4oCRadLG4VEN0eO47qwbfd+sPs2NVijzkutWLCxwJzN5vg89y8t/o4E8T3D/srzOU/7NolUdzOOJfUk5pNfumfOdvmd1h+2jiOMuAFZnwwNj16xrnuamd1OofuGew/7o3+HP6j1Rlr+nNdVrU83gGJ5pPEnP8hvTkDGg9aUIRu2OyjR3KvCaxDIPtDEPrx0Lu6Cf/Qf8IQZFsjmQ4B8330ZeWIJ5uREKNaiuAubPGrtXBLQBBjAuEzsOfSY 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 when available for perf's MMAP2 event build id data. Signed-off-by: Jiri Olsa --- kernel/events/core.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index d56328e5080e..44001fc7edb7 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8508,6 +8508,9 @@ struct perf_mmap_event { u32 prot, flags; u8 build_id[BUILD_ID_SIZE_MAX]; u32 build_id_size; +#ifdef CONFIG_FILE_BUILD_ID + struct build_id *f_bid; +#endif struct { struct perf_event_header header; @@ -8520,6 +8523,38 @@ struct perf_mmap_event { } event_id; }; +#ifdef CONFIG_FILE_BUILD_ID +static void build_id_read(struct perf_mmap_event *mmap_event) +{ + struct vm_area_struct *vma = mmap_event->vma; + + mmap_event->f_bid = vma->vm_file ? vma->vm_file->f_bid : NULL; +} + +static bool has_build_id(struct perf_mmap_event *mmap_event) +{ + return mmap_event->f_bid; +} + +#define build_id_data mmap_event->f_bid->data +#define build_id_size mmap_event->f_bid->sz +#else +static void build_id_read(struct perf_mmap_event *mmap_event) +{ + struct vm_area_struct *vma = mmap_event->vma; + + build_id_parse(vma, mmap_event->build_id, &mmap_event->build_id_size); +} + +static bool has_build_id(struct perf_mmap_event *mmap_event) +{ + return mmap_event->build_id_size; +} + +#define build_id_data mmap_event->build_id +#define build_id_size mmap_event->build_id_size +#endif + static int perf_event_mmap_match(struct perf_event *event, void *data) { @@ -8564,7 +8599,7 @@ static void perf_event_mmap_output(struct perf_event *event, mmap_event->event_id.pid = perf_event_pid(event, current); mmap_event->event_id.tid = perf_event_tid(event, current); - use_build_id = event->attr.build_id && mmap_event->build_id_size; + use_build_id = event->attr.build_id && has_build_id(mmap_event); if (event->attr.mmap2 && use_build_id) mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_BUILD_ID; @@ -8573,10 +8608,10 @@ static void perf_event_mmap_output(struct perf_event *event, if (event->attr.mmap2) { if (use_build_id) { - u8 size[4] = { (u8) mmap_event->build_id_size, 0, 0, 0 }; + u8 size[4] = { (u8) build_id_size, 0, 0, 0 }; __output_copy(&handle, size, 4); - __output_copy(&handle, mmap_event->build_id, BUILD_ID_SIZE_MAX); + __output_copy(&handle, build_id_data, BUILD_ID_SIZE_MAX); } else { perf_output_put(&handle, mmap_event->maj); perf_output_put(&handle, mmap_event->min); @@ -8708,7 +8743,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event) mmap_event->event_id.header.size = sizeof(mmap_event->event_id) + size; if (atomic_read(&nr_build_id_events)) - build_id_parse(vma, mmap_event->build_id, &mmap_event->build_id_size); + build_id_read(mmap_event); perf_iterate_sb(perf_event_mmap_output, mmap_event,