From patchwork Thu Nov 2 17:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 161053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp540066vqu; Thu, 2 Nov 2023 11:07:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLN+DLYVrOXnxgua9irpsd2v3z2S11PC4SzLxwG09440Ai6aMWAyMEWvytNPKMJV/WnKog X-Received: by 2002:a17:902:f10a:b0:1cc:4468:f1cf with SMTP id e10-20020a170902f10a00b001cc4468f1cfmr9160762plb.3.1698948442717; Thu, 02 Nov 2023 11:07:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698948442; cv=none; d=google.com; s=arc-20160816; b=pqbP0ykmf6GD4U/5ppv9I+HB8rDY0Rj7cUORift/4x/yf8zyRdHvTDf4MkplHcwk2t xGWFNMmpPmw1g2D66DEyW58lvnuvPGojDuVM8QWJr7I7iNvvkxXTz8nfuA6xpW0qwbpX 3nReCTCfxPpmcDLk2dpnCjPUEThXrl0XpdKMGeNO8/YLqGRczC+nLCv/xddjAxNB4Fks N6Fa0yuYQcZ/J0z6w2Unmv5fVtXTF0XKmIju6vwP8zH+/Q6H4WJGFSXh+SG+DquT3bYJ dztUgb7AJnHgnwZwA/qXD0EStoN9aNql+Lw5kVkexD3b1atdJXRpmhF7OzZ8ZCuW1BuW M/vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=AlT7UeqmlQ8IFDtPogYP/9SjjZolnxzlyo9trNiskvQ=; fh=z1KcSqUpYQ9oC4uLSeIkhAYTnJ2bvP0QbNW2xqV5NqA=; b=aQGwS97DIqkStn6LCnSmeZbj3vCzzsNXEXcUZYuLZGI50u0O5V+BelUGB+RDb4u4vG aBm6bukVxY6EScIWxkYVr3sXrEEyMdpFlQHH7KXsxin37WN2JaIOiPXfEIf/9laCL18l Gs0AshFAvAiGnUWAMu/5clTyViWp2670bqCdfaNyU23Vi9+XLtW6IyPx0ROLC4jo20ip Oz0XDCPUlcBU97cJF+jdPFkzo7KDWnRp/5G+CYpl5CRU9eN1upqT6HsYC6iTkHbFYktW upGzYM6YtUdzIzsR+5FzNLDybsl6fGtSz2UGj8hw810P91kXx6L+FWmo6a3UAyuauI3P ik4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ujyX9Htr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id x1-20020a17090300c100b001c7342b46e4si72461plc.23.2023.11.02.11.07.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Nov 2023 11:07:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ujyX9Htr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B9617807EB10; Thu, 2 Nov 2023 11:07:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235013AbjKBSFX (ORCPT + 35 others); Thu, 2 Nov 2023 14:05:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235011AbjKBSFA (ORCPT ); Thu, 2 Nov 2023 14:05:00 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7691E2729 for ; Thu, 2 Nov 2023 10:59:54 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a7af69a4baso17208857b3.0 for ; Thu, 02 Nov 2023 10:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698947993; x=1699552793; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=AlT7UeqmlQ8IFDtPogYP/9SjjZolnxzlyo9trNiskvQ=; b=ujyX9HtrTDP+MYrlvtdbWd+UXZcoJduMTAOdzW7twaBomHHBB1pW4jLAptB9U12+dp 4HumHWgUvcB/pWIJVyTFZ30vggy0V6HN+M/DwJpsZKs9x7KYXAHlbq/bYMbr3jbsn1Eh gi4VqAtmAqsed8nTCOKOqZPDdTIPIB5Pm9GZsp4R4RnW11A1WoiHDMXVZY7TxwSWLV4w 7XpYCyPk2P8AV6ThdGntmg36iIBi2m9WsMytRfdzj3F4rEiBe51E6cNWhRukXDSYGzad TtMwKTkzDaOKO9k4teSat9p4dwtyWnpgROjLzE3GP6uxYBQqfhgwCGfmBTLv6Tg4/myS eq+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698947993; x=1699552793; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=AlT7UeqmlQ8IFDtPogYP/9SjjZolnxzlyo9trNiskvQ=; b=XttiMmdYAzIT8btMZSrFQAMS2cgzK+Bl7GJ/c8GKwb45CVLHbHFOMACVI0a9EOskH+ qaHcw9HNhTrMlLFiULJkflTKyNZ227q4R6YR9tN7s+MhFWbJA01HgQegmVn4tL1DswKI 5Hydgb0i2pf+k3wdu+VO9fPBAx2bThiquNr70YCs3U00r3qJV4rdaJEfrxjBfgdjXaB6 Uc69vboeM7vo4N7xokaN9AuHIh3FmyOOCimmJCKd1hIcuxS39s9Ck3HanGnUiYKT7/oY /cigNRkdIWlgRriDkCHNqz3Ep+XBtH8y2PQL+gk9PBF8v2jVXBOy3GaSDgLujOIdf3zV /Hxg== X-Gm-Message-State: AOJu0YxWrhvgOjEYgMK9JuoNnWxidBXshw59RPxfW5g9Q4/f0zELNUl5 WDVinOgAC/HQzuJbbDwFCD9VH3cA2R90 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bb34:df9c:836c:afca]) (user=irogers job=sendgmr) by 2002:a0d:ea4f:0:b0:5a7:be10:461d with SMTP id t76-20020a0dea4f000000b005a7be10461dmr8627ywe.2.1698947993053; Thu, 02 Nov 2023 10:59:53 -0700 (PDT) Date: Thu, 2 Nov 2023 10:57:33 -0700 In-Reply-To: <20231102175735.2272696-1-irogers@google.com> Message-Id: <20231102175735.2272696-52-irogers@google.com> Mime-Version: 1.0 References: <20231102175735.2272696-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.869.gea05f2083d-goog Subject: [PATCH v4 51/53] perf dso: Reference counting related fixes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , Vincent Whitchurch , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , liuwenyu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 02 Nov 2023 11:07:12 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781476562308407548 X-GMAIL-MSGID: 1781476562308407548 Ensure gets and puts are better aligned fixing reference couting checking problems. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 4 ++-- tools/perf/util/map.c | 1 + tools/perf/util/symbol-elf.c | 38 +++++++++++++++++------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index d4534fbc7098..bd1e2da5bb6d 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -683,7 +683,7 @@ static int machine__process_ksymbol_register(struct machine *machine, struct perf_sample *sample __maybe_unused) { struct symbol *sym; - struct dso *dso; + struct dso *dso = NULL; struct map *map = maps__find(machine__kernel_maps(machine), event->ksymbol.addr); int err = 0; @@ -696,7 +696,6 @@ static int machine__process_ksymbol_register(struct machine *machine, } dso__set_kernel(dso, DSO_SPACE__KERNEL); map = map__new2(0, dso); - dso__put(dso); if (!map) { err = -ENOMEM; goto out; @@ -735,6 +734,7 @@ static int machine__process_ksymbol_register(struct machine *machine, dso__insert_symbol(dso, sym); out: map__put(map); + dso__put(dso); return err; } diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 14fb8cf65b13..4480134ef4ea 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -200,6 +200,7 @@ struct map *map__new(struct machine *machine, u64 start, u64 len, dso__set_build_id(dso, dso__bid(header_bid_dso)); dso__set_header_build_id(dso, 1); } + dso__put(header_bid_dso); } dso__put(dso); } diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index de73f9fb3fe4..4c00463abb7e 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1366,7 +1366,7 @@ void __weak arch__sym_update(struct symbol *s __maybe_unused, static int dso__process_kernel_symbol(struct dso *dso, struct map *map, GElf_Sym *sym, GElf_Shdr *shdr, struct maps *kmaps, struct kmap *kmap, - struct dso **curr_dsop, struct map **curr_mapp, + struct dso **curr_dsop, const char *section_name, bool adjust_kernel_syms, bool kmodule, bool *remap_kernel) { @@ -1416,8 +1416,8 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, map__set_pgoff(map, shdr->sh_offset); } - *curr_mapp = map; - *curr_dsop = dso; + dso__put(*curr_dsop); + *curr_dsop = dso__get(dso); return 0; } @@ -1442,10 +1442,10 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, dso__set_binary_type(curr_dso, dso__binary_type(dso)); dso__set_adjust_symbols(curr_dso, dso__adjust_symbols(dso)); curr_map = map__new2(start, curr_dso); - dso__put(curr_dso); - if (curr_map == NULL) + if (curr_map == NULL) { + dso__put(curr_dso); return -1; - + } if (dso__kernel(curr_dso)) map__kmap(curr_map)->kmaps = kmaps; @@ -1459,21 +1459,15 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, dso__set_symtab_type(curr_dso, dso__symtab_type(dso)); if (maps__insert(kmaps, curr_map)) return -1; - /* - * Add it before we drop the reference to curr_map, i.e. while - * we still are sure to have a reference to this DSO via - * *curr_map->dso. - */ dsos__add(&maps__machine(kmaps)->dsos, curr_dso); - /* kmaps already got it */ - map__put(curr_map); dso__set_loaded(curr_dso); - *curr_mapp = curr_map; + dso__put(*curr_dsop); *curr_dsop = curr_dso; } else { - *curr_dsop = map__dso(curr_map); - map__put(curr_map); + dso__put(*curr_dsop); + *curr_dsop = dso__get(map__dso(curr_map)); } + map__put(curr_map); return 0; } @@ -1484,8 +1478,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, { struct kmap *kmap = dso__kernel(dso) ? map__kmap(map) : NULL; struct maps *kmaps = kmap ? map__kmaps(map) : NULL; - struct map *curr_map = map; - struct dso *curr_dso = dso; + struct dso *curr_dso; Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym; uint32_t nr_syms; int err = -1; @@ -1586,6 +1579,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, remap_kernel = true; adjust_kernel_syms = dso__adjust_symbols(dso); } + curr_dso = dso__get(dso); elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) { struct symbol *f; const char *elf_name = elf_sym__name(&sym, symstrs); @@ -1674,8 +1668,11 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, --sym.st_value; if (dso__kernel(dso)) { - if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &curr_dso, &curr_map, - section_name, adjust_kernel_syms, kmodule, &remap_kernel)) + if (dso__process_kernel_symbol(dso, map, &sym, &shdr, + kmaps, kmap, &curr_dso, + section_name, + adjust_kernel_syms, + kmodule, &remap_kernel)) goto out_elf_end; } else if ((used_opd && runtime_ss->adjust_symbols) || (!used_opd && syms_ss->adjust_symbols)) { @@ -1724,6 +1721,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); nr++; } + dso__put(curr_dso); /* * For misannotated, zeroed, ASM function sizes.