Received: by 2002:ac2:5a04:0:0:0:0:0 with SMTP id q4csp380610lfn; Wed, 2 Mar 2022 09:15:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJSBOlwh+oPRTRz+FWwXYs2mlxIVywrzgx5HIK93lhZ1Wy37QnIiIzIFNWe/vbuw67Ep3U X-Received: by 2002:a05:6402:2747:b0:415:c252:f5e7 with SMTP id z7-20020a056402274700b00415c252f5e7mr3010614edd.347.1646241314361; Wed, 02 Mar 2022 09:15:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646241314; cv=none; d=google.com; s=arc-20160816; b=iEsGwfFm2f/rcg2G/Ye07KDp0UBBbxDlGPmZ7mZ7pzHTQ+kCzFx1LsGUg5aNoe3Kfk YlYTJ2KR39Z/iNDLNRrilTiFUVe3l7/1XzrE1yLGJypYE/GKc+JhLdyZ6LbpIIy9ME9X njORIbaJiydczA6ok4FiCENXNDoYtg8Rf/PvLwMUn4cOc+Arn4FEzXyrMyU0m7njgNu/ YKNeFd//QIqC8wkqgpWFXv/HRDwZDaiQsYFVc+9QUqKXSmdVsFKcMrBv0h4WTrl+zQfo GdPod9KTgpOlggvSsiqrtzxMfDOQ/ZOTtQL8so8jNdx1348rYx7ptQVp5whHOElrA6BJ m6iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=vsEheYOjT72hfc6n8EvCoPRXhqaqZEBmGTWHW1gPdcY=; b=NA3/BcIvmz5v+GB9biAD1XBKFP7NUxwzlFVhhYHRZjxSzcG6+z5Bp/98TJz2j8nHYN dnCULjT1L4+iU2ZxEXojMlrg4mJtbp+8IdXU06o5av9eMv3zBQA8lyUmW0vYnsG1Vb7o U6AJTCOM+mvvqytFnIp/eN/jiRFmWWzlBXn8u6VPK6v3+uIWHupfe5L13LVgJmXmj0KX W21JTwSBjb3wTRQYemHM8oXPYId6FyVNC9GztWiRa4ahvhX+Ntso6hB0nf4Wsgw/kBAu qyFZ2T/I1CU/HIuAVBlMMsKelXH+Rx6funyFBYRTJvGeevtuuRe/AshcPp4ZFt7aNCaV fcJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n2-20020a50cc42000000b00413b3f95723si7597685edi.601.2022.03.02.09.14.39; Wed, 02 Mar 2022 09:15:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241781AbiCBQUt (ORCPT + 99 others); Wed, 2 Mar 2022 11:20:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234388AbiCBQUr (ORCPT ); Wed, 2 Mar 2022 11:20:47 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5304511149; Wed, 2 Mar 2022 08:20:04 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1C5F1139F; Wed, 2 Mar 2022 08:20:04 -0800 (PST) Received: from [10.57.42.101] (unknown [10.57.42.101]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ADC4D3F73D; Wed, 2 Mar 2022 08:20:02 -0800 (PST) Message-ID: <3dc14ad9-8ce1-a2e3-3bab-953b79af82be@arm.com> Date: Wed, 2 Mar 2022 16:20:00 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH 1/1] perf: Set build-id using build-id header on new mmap records Content-Language: en-US To: Jiri Olsa Cc: acme@kernel.org, linux-perf-users@vger.kernel.org, coresight@lists.linaro.org, Denis Nikitin , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-kernel@vger.kernel.org References: <20220224171955.862983-1-james.clark@arm.com> <20220224171955.862983-2-james.clark@arm.com> From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/02/2022 22:50, Jiri Olsa wrote: > On Thu, Feb 24, 2022 at 05:19:55PM +0000, James Clark wrote: >> MMAP records that occur after the build-id header is parsed do not have >> their build-id set even if the filename matches an entry from the >> header. Set the build-id on these dsos as long as the MMAP record >> doesn't have its own build-id set. >> >> This fixes an issue with off target analysis where the local version of >> a dso is loaded rather than one from ~/.debug via a build-id. > > nice catch :) > >> >> Reported-by: Denis Nikitin >> Signed-off-by: James Clark >> --- >> tools/perf/util/dso.h | 1 + >> tools/perf/util/header.c | 1 + >> tools/perf/util/map.c | 16 ++++++++++++++-- >> 3 files changed, 16 insertions(+), 2 deletions(-) >> >> diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h >> index 011da3924fc1..3a9fd4d389b5 100644 >> --- a/tools/perf/util/dso.h >> +++ b/tools/perf/util/dso.h >> @@ -167,6 +167,7 @@ struct dso { >> enum dso_load_errno load_errno; >> u8 adjust_symbols:1; >> u8 has_build_id:1; >> + u8 header_build_id:1; >> u8 has_srcline:1; >> u8 hit:1; >> u8 annotate_warned:1; >> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c >> index 6da12e522edc..571d73d4f976 100644 >> --- a/tools/perf/util/header.c >> +++ b/tools/perf/util/header.c >> @@ -2200,6 +2200,7 @@ static int __event_process_build_id(struct perf_record_header_build_id *bev, >> >> build_id__init(&bid, bev->data, size); >> dso__set_build_id(dso, &bid); >> + dso->header_build_id = 1; >> >> if (dso_space != DSO_SPACE__USER) { >> struct kmod_path m = { .name = NULL, }; >> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c >> index 1803d3887afe..4ae91e491e23 100644 >> --- a/tools/perf/util/map.c >> +++ b/tools/perf/util/map.c >> @@ -127,7 +127,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, >> >> if (map != NULL) { >> char newfilename[PATH_MAX]; >> - struct dso *dso; >> + struct dso *dso, *header_bid_dso; >> int anon, no_dso, vdso, android; >> >> android = is_android_lib(filename); >> @@ -185,7 +185,19 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, >> >> if (build_id__is_defined(bid)) >> dso__set_build_id(dso, bid); >> - >> + else { > > nit please add { } to the if clause as well > >> + /* >> + * If the mmap event had no build ID, search for an existing dso from the >> + * build ID header by name. Otherwise only the dso loaded at the time of >> + * reading the header will have the build ID set and all future mmaps will >> + * have it missing. >> + */ >> + header_bid_dso = __dsos__find(&machine->dsos, filename, false); > > is this 'perf top' safe? I think dso should be added in the > same thread, but please check and add comment why we don't > need locking in here Seems like there are multiple synthesize_threads_workers using the same machine->dsos object so I think locking is needed. At first I thought of doing this: diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 4ae91e491e23..b87b81e3d41c 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -192,7 +192,9 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, * reading the header will have the build ID set and all future mmaps will * have it missing. */ + down_read(&machine->dsos.lock); header_bid_dso = __dsos__find(&machine->dsos, filename, false); + up_read(&machine->dsos.lock); if (header_bid_dso && header_bid_dso->header_build_id) { dso__set_build_id(dso, &header_bid_dso->bid); dso->header_build_id = 1; But then I was wondering why it doesn't need a write lock all the way from machine__findnew_dso_id() to dso__put()? At the moment there are writes to the dso like dso__set_loaded(), dso->nsinfo = nsi and dso__set_build_id(), so another thread could find the dso in a partially constructed state. Not sure if this is an issue currently without my patch, but at least with it they would have to be found with header_build_id already set to 1 otherwise it will mess things up. Extending the write lock outside of machine__findnew_dso_id() is difficult because it already releases it before it returns. Does it need to be changed so that machine__findnew_dso_id() takes all the arguments needed to construct it inside the lock? James > > thanks, > jirka > >> + if (header_bid_dso && header_bid_dso->header_build_id) { >> + dso__set_build_id(dso, &header_bid_dso->bid); >> + dso->header_build_id = 1; >> + } >> + } >> dso__put(dso); >> } >> return map; >> -- >> 2.28.0 >>