Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp878009pxb; Thu, 12 Nov 2020 20:32:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNZADdZwoWd0BJczTqbjsrbv4GUWMXMqgn/6lK6okL+q9c4g+KrdAp6cbjwEEO2B7eNZ33 X-Received: by 2002:aa7:c44d:: with SMTP id n13mr706282edr.138.1605241958582; Thu, 12 Nov 2020 20:32:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605241958; cv=none; d=google.com; s=arc-20160816; b=pfAeSLUfKPPLBGUp16xWig/lsDOApXLaPeZwU3slwFqfFxv0agAOm1SY6F+AYgz65k +LP7zihysPMlNgIztKx9DmrO9Ee06ETwm9qeug1uamrfJ0/foHgE21hexJCy6NaxNw43 ePGz3kugnEW+ItEkMBnrOIuOJ6jRX9zA6gQ8NF6Ou4WGSCBzWmoTYSc61u9E4dnAwfPl /fD/BFH+0OQppE7dQbaMsNa6D/Ya8Y2S+RFjPv0XVoGS0l0DXnkZmavHoT7Fsx6kQ4ML PD9LGa9UHueW6yZuZQ38DnADaZAOJYlfUa1jBtglRLKMlh3R9iiPe8sKQp0IP4R8tB/Z 7aCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=j5R1Gx6DzdWHYutq17LijZop4uXlukyTUkfaPDw8Dzo=; b=Q0cfL+g0hEjJliJBGDuC4GGAClM9qZNk+SM6yTFjZEMKEWh00Pz5gI7tAHN0GReSRX +NhkmQFyDwA/w68t1LCvpxrI3/xwYX4v6w/ihL2D5rLRH5moRJi3+w0UKusx65Zc+qkY hg2lu9hK0vs/575W7ClkrXOINesez2Bo25T/B4pnIyqs+tnnQohCT9JdxUKT/c0V4TDS SwedSv1MZZqxFkbM1S4QrktBpRnHKUFj50Aa028EQm2zhOsgwzWMmTVu+rtS7Ly+1ag9 IeQqD5D0tg2WETtwLtjFOq1wJS34zzRl9YsHjfHhBxc02uP3+xMZiKpE4jeoiftNiiXN EjmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JfpMWDCM; 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 t12si5237723ejx.621.2020.11.12.20.32.14; Thu, 12 Nov 2020 20:32:38 -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=@gmail.com header.s=20161025 header.b=JfpMWDCM; 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 S1726112AbgKME35 (ORCPT + 99 others); Thu, 12 Nov 2020 23:29:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726054AbgKME34 (ORCPT ); Thu, 12 Nov 2020 23:29:56 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202DDC0613D1 for ; Thu, 12 Nov 2020 20:29:43 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id h6so6093466pgk.4 for ; Thu, 12 Nov 2020 20:29:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=j5R1Gx6DzdWHYutq17LijZop4uXlukyTUkfaPDw8Dzo=; b=JfpMWDCMd9qJT8GFnOZXnl7Z34D18zR4WazFsntGlQZl4obdrtSKUjl+zznQGKW/V3 1bMxPFUeMKBZPWkqQbz9qEHxFEzMRt8BYLIlxvmC/fYERPizA0rQCJ20R1mktmQZBZmn KVOB+4cBnII60IZ0yOpt0CI9tKYfcxFsxGnpQZktEyZnNLqbKVgaU94Xv8lTaX6zssep EBPqQqNES8gOunhuNDGzEXqbIn/sp85C65+JWkH1i0AzPFo18HwlPvvVwcyZWVLsFR+t guCFsDfNVsl6PtXisvKt/pFfXd3pt5u6wWrrg+Y4oYILtC746Q2CyEHj/RAqqrOgnzpe JeSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=j5R1Gx6DzdWHYutq17LijZop4uXlukyTUkfaPDw8Dzo=; b=n6rI1g9Jw0CF8l8joDz9AImDo32qH/15OcVQuxBAnHY87uBEl3Zzo8Z0ICYfnYAgmD I7PSjsXNtCaZDoJ5/hPMB8hgD0vhs60BJF66aYuRmdDa6GCBe/kR9dsBxT3TlErwZlu3 S6xRZobvcYF0+nzFYh5LgFtQipDolAjObhn7YwK+qwnwyJyQux1R0OAo0w1ntESMUYIM 9B4Y5pkYz3kdDo+gmUN7UkVvG5s6+rmd0PXiyOPAB3iVrCfrBl1klv1N1qLPPLD26MF9 tw9Dzgk8GumYkCWuPQxc4ZIAIdvi3He+eWCFVR9aeQyH0bF41Uik1gJbgtekB7SdMAwF j4Iw== X-Gm-Message-State: AOAM530wvTcS0WPnvlF9emA93WHs+Hk+GOMDz3SrUBasH2mKZgqPcMMU K4u0oa3oUHkYA6qJ6RX3d0w= X-Received: by 2002:a62:7cd3:0:b029:18b:8c56:91eb with SMTP id x202-20020a627cd30000b029018b8c5691ebmr482743pfc.23.1605241782660; Thu, 12 Nov 2020 20:29:42 -0800 (PST) Received: from google.com ([112.159.19.5]) by smtp.gmail.com with ESMTPSA id 21sm8503407pfv.122.2020.11.12.20.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:29:41 -0800 (PST) Sender: Namhyung Kim Date: Fri, 13 Nov 2020 13:29:35 +0900 From: Namhyung Kim To: Jiri Olsa Cc: Arnaldo Carvalho de Melo , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Song Liu , Ian Rogers , Stephane Eranian , Alexey Budankov , Andi Kleen , Adrian Hunter Subject: Re: [PATCH 03/24] perf: Add build id data in mmap2 event Message-ID: <20201113042935.GA167797@google.com> References: <20201109215415.400153-1-jolsa@kernel.org> <20201109215415.400153-4-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20201109215415.400153-4-jolsa@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiri, On Mon, Nov 09, 2020 at 10:53:54PM +0100, Jiri Olsa wrote: > Adding support to carry build id data in mmap2 event. > > The build id data replaces maj/min/ino/ino_generation > fields, whichc are also used to identify map's binary, > so it's ok to replace them with build id data: > > union { > struct { > u32 maj; > u32 min; > u64 ino; > u64 ino_generation; > }; > struct { > u8 build_id[20]; > u8 build_id_size; > u8 __reserved_1; > u16 __reserved_2; > }; > }; > > Replaced maj/min/ino/ino_generation fields give us size > of 24 bytes. We use 20 bytes for build id data, 1 byte > for size and rest is unused. > > There's new misc bit for mmap2 to signal there's build > id data in it: > > #define PERF_RECORD_MISC_BUILD_ID (1 << 14) > > Signed-off-by: Jiri Olsa > --- [SNIP] > diff --git a/kernel/events/core.c b/kernel/events/core.c > index da467e1dd49a..808473b6ce85 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -51,6 +51,7 @@ > #include > #include > #include > +#include > > #include "internal.h" > > @@ -395,6 +396,7 @@ static atomic_t nr_ksymbol_events __read_mostly; > static atomic_t nr_bpf_events __read_mostly; > static atomic_t nr_cgroup_events __read_mostly; > static atomic_t nr_text_poke_events __read_mostly; > +static atomic_t nr_build_id_events __read_mostly; > > static LIST_HEAD(pmus); > static DEFINE_MUTEX(pmus_lock); > @@ -4672,6 +4674,8 @@ static void unaccount_event(struct perf_event *event) > dec = true; > if (event->attr.mmap || event->attr.mmap_data) > atomic_dec(&nr_mmap_events); > + if (event->attr.build_id) > + atomic_dec(&nr_build_id_events); > if (event->attr.comm) > atomic_dec(&nr_comm_events); > if (event->attr.namespaces) > @@ -7942,6 +7946,8 @@ struct perf_mmap_event { > u64 ino; > u64 ino_generation; > u32 prot, flags; > + u8 build_id[BUILD_ID_SIZE]; > + u32 build_id_size; > > struct { > struct perf_event_header header; > @@ -7997,13 +8003,23 @@ 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); > > + if (event->attr.mmap2 && event->attr.build_id) > + mmap_event->event_id.header.misc |= PERF_RECORD_MISC_BUILD_ID; > + > perf_output_put(&handle, mmap_event->event_id); > > if (event->attr.mmap2) { > - perf_output_put(&handle, mmap_event->maj); > - perf_output_put(&handle, mmap_event->min); > - perf_output_put(&handle, mmap_event->ino); > - perf_output_put(&handle, mmap_event->ino_generation); > + if (event->attr.build_id) { > + u8 size[4] = { (u8) mmap_event->build_id_size, 0, 0, 0 }; > + > + __output_copy(&handle, mmap_event->build_id, BUILD_ID_SIZE); > + __output_copy(&handle, size, 4); > + } else { > + perf_output_put(&handle, mmap_event->maj); > + perf_output_put(&handle, mmap_event->min); > + perf_output_put(&handle, mmap_event->ino); > + perf_output_put(&handle, mmap_event->ino_generation); > + } > perf_output_put(&handle, mmap_event->prot); > perf_output_put(&handle, mmap_event->flags); > } > @@ -8132,6 +8148,11 @@ 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_size(vma, mmap_event->build_id, > + &mmap_event->build_id_size); This can fail, right? Then we need to fallback to use dev/ino.. Thanks, Namhyung > + } > + > perf_iterate_sb(perf_event_mmap_output, > mmap_event, > NULL); > @@ -11069,6 +11090,8 @@ static void account_event(struct perf_event *event) > inc = true; > if (event->attr.mmap || event->attr.mmap_data) > atomic_inc(&nr_mmap_events); > + if (event->attr.build_id) > + atomic_inc(&nr_build_id_events); > if (event->attr.comm) > atomic_inc(&nr_comm_events); > if (event->attr.namespaces) > -- > 2.26.2 >