Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp105470rwd; Mon, 12 Jun 2023 10:41:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XOljFmrJjXydeB8uCGQ0UWX+LNALVnc4wpOhmAmJgrOr4+PjzzA9XoMLHWFyc5jh0X1Vj X-Received: by 2002:a17:907:6e23:b0:958:cc8:bd55 with SMTP id sd35-20020a1709076e2300b009580cc8bd55mr10871784ejc.0.1686591669801; Mon, 12 Jun 2023 10:41:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686591669; cv=none; d=google.com; s=arc-20160816; b=Gs/Bf148GWiev6f83Ism7cmYvPddKQSmNHxShcp+MPAdVdlO3BrgR47Nire+LVdbGd /Sw08At/rqutlfkAGPtCqy8XUjFG7xTaqfIQB0i4DXYLTUtqXga8NcdjFiRCg1VTWvRi hhvRjxGW8K9ogERBkTypIxlfvnWfVSUq9HtdealK4ctiTYadllxT+IXpmWeu5M1lh6u1 e5LkKPmxuD4vlaqIRFcozWgXT7ePmfw7awIR++viidN9KP2uCRBbzwqMmTR4nKwpKese duv86gvkIez2B4cLUckgmAp5q/tsD3wiunZRsFsTMbQfg+jkFaJABPTlsRna7wqlbsJO 3kfg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NrUB9kPq71ytaobANmUCdrefWkVVCGNIpgh81Qo4puY=; b=eCdo+cUny07OSvZuB4ZXuuhtnxQfwwxcFP6mZGzPaYgiy2E+tyBkO8G+SBrjBVMPYd rNCR2lUZZApfT1riflDh7NMoof6CiluYOR8JQhRnt4SsGIPc018tHekGpnzpARVJi/Cc Vqs3AkWK6Fn4euNrOyUkRxGmqMp+StdVgfYOKYWjcZ+rK1pUAf1phMMO8McAuSjIy6br yhe0ao5o2eEZqxDYXEmLGSojZFT2rjZfHX0hCbrDwEcGRYuP0YG361+IOOhbXoTYpQLl vtR7Vb/f9VjITP+XLJuBZZpI+PKb2mquuPVEIPaRcAkogTy51V+A7NmVHnssjkbKJK3p POIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hgXZWmlO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id zb9-20020a17090687c900b0097462d656f8si5276363ejb.581.2023.06.12.10.40.45; Mon, 12 Jun 2023 10:41:09 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hgXZWmlO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231501AbjFLRa2 (ORCPT + 99 others); Mon, 12 Jun 2023 13:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237698AbjFLR3r (ORCPT ); Mon, 12 Jun 2023 13:29:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF519DB; Mon, 12 Jun 2023 10:29:45 -0700 (PDT) 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 8B888620E7; Mon, 12 Jun 2023 17:29:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF4F2C433D2; Mon, 12 Jun 2023 17:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686590985; bh=tVyezW3o2HAblHhWfBLLzXDJWYWq8x5ow1lKCcaOQkI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hgXZWmlOMWS0quDcXThICtAZ+0rkyiTG7asel0q5gUhCktm7Oliwo79T3YUOcWqE8 Q9qPEF4STvIBjwjg9Oa5MJ2tjoIE63DZ3zbk4BTF35APAkJuAYyV71e98NAFYCuG1z ZivboAUfiXLvkTA4hJkyEU7WCGwaFNwtYF669u8uNjxHiqUIk5H19neSf9uc0+HgsK 7LyDMsI+oGuPYVJn3PC0NE3fd892RGzwo96Fcl9wZDfJutPFXH3O3uxffmo+dHUxDa rsFElNU+xRUCKgN+jWlWOAOlH04q3NAil12NAR1cjROimwyHUtMeh/NStJvKjZM8i8 VWhWyhVfikWzA== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 2DC1A40692; Mon, 12 Jun 2023 14:29:42 -0300 (-03) Date: Mon, 12 Jun 2023 14:29:42 -0300 From: Arnaldo Carvalho de Melo To: Ian Rogers Cc: James Clark , linux-perf-users@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf map: Fix refcount errors on Arm with -DREFCNT_CHECKING=1 Message-ID: References: <20230612150424.198914-1-james.clark@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Em Mon, Jun 12, 2023 at 09:32:30AM -0700, Ian Rogers escreveu: > On Mon, Jun 12, 2023 at 8:05 AM James Clark wrote: > > > > When quitting after running a perf report, the refcount checker finds > > some double frees. The issue is that map__put() is called on a function > > argument so it removes the refcount wrapper that someone else was using. > > > > Fix it by only calling map__put() on a reference that is owned by this > > function. > > > > Signed-off-by: James Clark > > Acked-by: Ian Rogers > > > --- > > tools/perf/util/symbol-elf.c | 9 +++++---- > > tools/perf/util/symbol.c | 9 +++++---- > > 2 files changed, 10 insertions(+), 8 deletions(-) > > > > diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c > > index 63882a4db5c7..ec0d7810bbb0 100644 > > --- a/tools/perf/util/symbol-elf.c > > +++ b/tools/perf/util/symbol-elf.c > > @@ -1365,6 +1365,7 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, > > struct dso *curr_dso = *curr_dsop; > > struct map *curr_map; > > char dso_name[PATH_MAX]; > > + struct map *map_ref; > > nit: can we narrow the scope of this by moving it to the scope where it is used. Which is what you did in a patch I already processed, its only in tmp.perf-tools-next as I was going thru the other patches, but this one is there already. I'm checking the tools/perf/util/symbol.c part. - Arnaldo > > > > /* Adjust symbol to map to file offset */ > > if (adjust_kernel_syms) > > @@ -1390,10 +1391,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, > > if (kmaps) { > > int err; > > > > - map__get(map); > > - maps__remove(kmaps, map); > > - err = maps__insert(kmaps, map); > > - map__put(map); > > + map_ref = map__get(map); > > + maps__remove(kmaps, map_ref); > > + err = maps__insert(kmaps, map_ref); > > + map__put(map_ref); > > if (err) > > return err; > > } > > diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c > > index 6b9c55784b56..b3034fd5c0af 100644 > > --- a/tools/perf/util/symbol.c > > +++ b/tools/perf/util/symbol.c > > @@ -1368,6 +1368,7 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > > int err, fd; > > char kcore_filename[PATH_MAX]; > > u64 stext; > > + struct map *map_ref; > > nit: can we narrow the scope of this by moving it to the scope where it is used. > > Thanks, > Ian > > > > > if (!kmaps) > > return -EINVAL; > > @@ -1464,10 +1465,10 @@ static int dso__load_kcore(struct dso *dso, struct map *map, > > map__set_map_ip(map, map__map_ip_ptr(new_map)); > > map__set_unmap_ip(map, map__unmap_ip_ptr(new_map)); > > /* Ensure maps are correctly ordered */ > > - map__get(map); > > - maps__remove(kmaps, map); > > - err = maps__insert(kmaps, map); > > - map__put(map); > > + map_ref = map__get(map); > > + maps__remove(kmaps, map_ref); > > + err = maps__insert(kmaps, map_ref); > > + map__put(map_ref); > > map__put(new_map); > > if (err) > > goto out_err; > > -- > > 2.34.1 > > -- - Arnaldo