From patchwork Thu Mar 16 17:01:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13178089 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 86D7AC6FD19 for ; Thu, 16 Mar 2023 17:02:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DC31900005; Thu, 16 Mar 2023 13:02:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08CBD900002; Thu, 16 Mar 2023 13:02:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBDCF900005; Thu, 16 Mar 2023 13:02:25 -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 DC504900002 for ; Thu, 16 Mar 2023 13:02:25 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AD9C7161453 for ; Thu, 16 Mar 2023 17:02:25 +0000 (UTC) X-FDA: 80575379850.20.0525F32 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id AB3ECC003A for ; Thu, 16 Mar 2023 17:02:23 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="SNv/7OPw"; spf=pass (imf22.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=1678986143; a=rsa-sha256; cv=none; b=Ow1DyLjuKdwgtWhGprFU6Rfagzpgn3WmCuetdFCoLWGJ73b+dVUi72oI5V8RA3RIoQ2fI/ +XZ9k6Ktl2JXG4uLT+pEq6DpunxxNeXhMdCBZQ1bRvu+NcMpJdk6flYqGrXgvGoyBncAbs +Rj9/Q6IcNl1mUSHoxMbWw/RJGuwFBU= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="SNv/7OPw"; spf=pass (imf22.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=1678986143; 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=Ug1467U48VKjl+qfahaRx91Nx0fu0cxgPdvPI/ITKF8=; b=iKKDLZBeiYXqkXu14lbNNkf2/lncMCE4armHeTkoCrBu0E2feONSfVI0NMBxtTmyb4d2+x 1PJAR7Tp9TAid5O8dNpf30O+XjzVaqqUySmCNISZ5CJKw3j+VkAszVjqe1vKTey6Iig3o0 xSi5gX9NPULyf5z3MiFeGyKG8hAlcTQ= 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 D8910620B9; Thu, 16 Mar 2023 17:02:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A54DC433EF; Thu, 16 Mar 2023 17:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678986142; bh=wPkey4BWxoSwuVm0/JDcphsHh4pWF/uWOFmXxlWLkHg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNv/7OPwD0I0s7lhX5kbFYwqOHQ6BEeVp42wO+mX9PwyPyOWc9aJP8tpSf8pTSmc7 aJUi7ueFyPgrnzibcjii0GIA0zBfQ+oVxp0KrZ6owWC8EKweBWjgHUvuX4bvUsGb7K jRQt6UIxSQ6hmnmM4MFepJHDyU9d2by956YrhOlpGLKvW0kO976LhWUg9lFcytBy2I cOPXJzHAAG6XfhpiPaipKG4qKVWkQ9gVWf3V6V9dmCwMAjG+X0ldhsn8+xIPvtS/NU bs9dvCYweuoj4hon4v1BsbRdkf1cx44ZWcTyojzhvrOzQoSNM8qF+wi+IS6ht9pVT0 jD7VHR0ypnIDw== 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 2/9] perf: Use file object build id in perf_event_mmap_event Date: Thu, 16 Mar 2023 18:01:42 +0100 Message-Id: <20230316170149.4106586-3-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-Queue-Id: AB3ECC003A X-Rspamd-Server: rspam01 X-Stat-Signature: ca6hnu6b9wnh75m6p9k36phc3t9hadpa X-HE-Tag: 1678986143-584375 X-HE-Meta: U2FsdGVkX1+/FbSWlU16mepBy2CptbAZo+ZNeFnvgfxIvuVrr7CPyWfw5fWGkTPe8LXw+mcr/cET5j8yangz6+wRUHgKZ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CLDCsCBucr0DSpx5Fu8w3gOq/sQaT59OazF5/wxdueXQXrIR9PdmMnKHmxMlxTYPDCU/fUaNQ1/sGmwo6cxv0KOIslhTYMfzUku8gVlXZ5lQwjxGR0cffSVmNsApoKreoArdkPBiSocf3H58xHhvdmz27xu4Xt8MT8FyTN2FSag7an7lJG072Dx2i35/DqTLvjWkkt/Nm14fvsOByha/sZnCiZrKsVb+SeRSWLe/20cG6aXzO4v1R/9vAOjUksf/llu7eQvbWXZ7y7IZoTEyC4nQbJTKS33sGhralVUEOoFEBMdyPW 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. The file's f_build_id is available (for CONFIG_FILE_BUILD_ID option) when the file is mmap-ed and before the perf's callback is executed, so we can use it, instead of reading it again. 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 f79fd8b87f75..3a5398dda6f6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -8527,6 +8527,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_build_id; +#endif struct { struct perf_event_header header; @@ -8539,6 +8542,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_build_id = vma->vm_file ? vma->vm_file->f_build_id : NULL; +} + +static bool has_build_id(struct perf_mmap_event *mmap_event) +{ + return !IS_ERR_OR_NULL(mmap_event->f_build_id); +} + +#define build_id_data mmap_event->f_build_id->data +#define build_id_size mmap_event->f_build_id->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) { @@ -8583,7 +8618,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; @@ -8592,10 +8627,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); @@ -8727,7 +8762,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,