Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2709411lqt; Mon, 22 Apr 2024 21:27:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVN864EOUk/tw0KWl/y1Gkainw68hbmc451sV4P2Yjg0g4CDMAMR/HY9816kn7m1bY84boQJXV2JvCilbxcspw+Tt+p7XpPVNbR5velig== X-Google-Smtp-Source: AGHT+IHGRx4UjWLZzYs+6QLuMPrvQaXklshOenlBk7sy6TzXc/5gB3yioEOh8qbwkLTjUXmxzlQJ X-Received: by 2002:a17:906:374d:b0:a58:7936:fc6a with SMTP id e13-20020a170906374d00b00a587936fc6amr662582ejc.53.1713846473383; Mon, 22 Apr 2024 21:27:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713846473; cv=pass; d=google.com; s=arc-20160816; b=aNbZ9M15O/RMDeadDS9rnrbq3ErY3Pdj875rGr47Q1iUeTBZUNQu4dPAhGvU8zv6KW 5LJrEFHSDxt/ULu4FE3L3bh96hnYNc0qmekhxz3G9ClxXZcoBO11/S3CGnDU0tW2p2l/ sPa1jT73a/1O0q3JnGpjOERSgXZQpAS28dOpoXVg32l+7VoEcceeE4jULN9uRWgPkLbr uI+FMBGpHZVRZTOoSz0RxL0/B7TOlop7T+wivp7HYyxUEUjpSKFjhRkDUnOKzU8ajpNQ Uh1FXlpEs0IhW3gFpb7JGw8O33F0JZl2x0SpWyewKXKdnw3Zts5Gi5O8CSPqXvbVtvWj J3pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=0GpE3k2HUqwCUngw35FiLfWVB3EVA72rLEwbUIc8rrM=; fh=AuIrTaaLKjxP+EF8riRdQg9hZsa9ei2J9S4YazT0Og0=; b=iwf25cLF52QOFfAlVkU9jiIgKqy/Z1KkgH3KdyCuwWUyk7NOIGWGeb3YDMdYBOBgHa 4oUbXKwVAHYKIsYiLOQkZlzhseZirfR0RmxUrJ3PD+aFHkurLvCjEx/oOuoUxLcPedwH wx6pn3rs0zj7tAAnOadbae0WaKAR4LIjQ9XJv4/zvfmXHWdHDg7ozI4IT1rAc72YZbH/ EPD10BbiHxY69mhWv4K+MlL0fG7XjA/V2vdptTBzqZoRTCLSi6d2jWf9pZjExu+rdcn5 Ywc8ccLEZeHgqPlGk/nFgGpIA8pNNGq5R1Hyk1nFe5JFqO2B3m5nrzy189MDTVxqPBC4 18AA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PjG3hdkc; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-154500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cs18-20020a170906dc9200b00a55b9773b53si1974248ejc.859.2024.04.22.21.27.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 21:27:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=PjG3hdkc; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-154500-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id ECD7E1F22D71 for ; Tue, 23 Apr 2024 04:27:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15F8621A0D; Tue, 23 Apr 2024 04:26:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="PjG3hdkc" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B5282E633 for ; Tue, 23 Apr 2024 04:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713846397; cv=none; b=e+4uSAI+gWVeyq8Gn3mQdirwtviGoIrUAcfLR306tTqXLfLMDn2TNu/VdWaFyZGqv3etF8q2nEWiiaJMr2vGtZWe8l8Vq+TbV5aZZKVwNoudELdgCbpb8eBTcQ6wZPyCvQHtcSfES6i5P4SxPtWj55mWegw6JbZIwHeYJL9EHLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713846397; c=relaxed/simple; bh=UTxelfgn/NP6KqTtuDstAHWAUd3MVs0zQWTjQf9/5To=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=sQjtK+1tkjrQp21oT1b78JJK3T8DTENmpDCkQxsa5nIVMxAAvK7rPhSb+nJCjvK5VASTgYVjq8ysir1fcLGs2c+ybl8NaQxq/MjRPp8XtheY+iVFUnaB9WxjTjcpZEzMmeNec92eFaW3vqCns/UsyA0BnFGFfgnqsZXO5WZrnpI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=PjG3hdkc; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de465062289so11721099276.2 for ; Mon, 22 Apr 2024 21:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713846394; x=1714451194; 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=0GpE3k2HUqwCUngw35FiLfWVB3EVA72rLEwbUIc8rrM=; b=PjG3hdkcycJvXYfDKM/aL2l9IgIEQCzPOOkMzisja3Lxmdfpbus6YLdApugPYfqiZF e7FBYOPUiY9mD6J+rxbtGWu6rBH7So+IaWdsbfHPMBvkJ5HPrJ/CJBud4U9+OGYbeuRX iStsjjda1mgfKHuwKmkogStrKwAyGbSlYG6WtXj90X4cIbDooayF6JzL1mo8E9yX0QMr zqVCTSc6A2Hk2YUkazSvTJDn3nqmJzyUDqivwFeoa5SBgOJ3znq2vF1QsPXyX9hCjbQr 6NPhfJ7UBrbfTrF0vR0P+UVafy3nDbe3HA047xbpRkHkacyMHJSfKIogBhJSm+k6I1jJ CPpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713846394; x=1714451194; 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=0GpE3k2HUqwCUngw35FiLfWVB3EVA72rLEwbUIc8rrM=; b=UJQgqJBVyAOquVPo+S2RtZMPdYTZrGSa0xrv+hi5vllyNeEdnSQ6A27ufBDN7QqWNA SnvTo+DslCZVuZ2FbmRXHnM7vLR8BAWqri3PN0wbgzsvZSur2MNaQeQKxqzSrD01oRMV ItIut3rrpWJ9MKj6mleGTj7hR85wpDJjNRYunCv5kC+aNStq7TZJKnv1tzUg/ItewPLB ELell2WJj4pkQNDqaJVdf9Dy4Gthw7QF8SrkeIpbth35z8fADddmar1A4sSQoDcVWYBK ZPDwNB7PM9jjM3zKI9A5499ZvpihEVYs/WnP25yVxin8/h07gqTITjAl2tGs77qGuTHa AH+A== X-Forwarded-Encrypted: i=1; AJvYcCU9QdPTPFhv67pCMQepLOGhBW06CRnt6xmggGcPMLlGLqWnpDw8QI2vrURo6W1Y+cK8DAGvpTYfXBsWqJoS5u7MIHUKOU1AgFEnNUAh X-Gm-Message-State: AOJu0YwtdYXaYOHInWiBHOozhC2hRLWjOG5YX0Epzo9sZPUyVHjvQwvI OV3UPD9Dv/iXIxUlqmMD8LBa6Wu3a/9JakUDSUGBk+EBgenejA+5koO7FnABAANw3rt88MZ1+7z FA8cnHg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:4ca4:4d48:a7fe:d70c]) (user=irogers job=sendgmr) by 2002:a25:bc2:0:b0:de5:17cb:8334 with SMTP id 185-20020a250bc2000000b00de517cb8334mr1716652ybl.13.1713846393722; Mon, 22 Apr 2024 21:26:33 -0700 (PDT) Date: Mon, 22 Apr 2024 21:26:00 -0700 In-Reply-To: <20240423042601.2009469-1-irogers@google.com> Message-Id: <20240423042601.2009469-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240423042601.2009469-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [PATCH v4 6/7] perf dso: Reference counting related fixes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Athira Rajeev , Colin Ian King , nabijaczleweli@nabijaczleweli.xyz, Leo Yan , Song Liu , Ilkka Koskinen , Ben Gainey , K Prateek Nayak , Yanteng Si , Sun Haiyong , Changbin Du , Andi Kleen , Thomas Richter , Masami Hiramatsu , Dima Kogan , zhaimingbing , Paran Lee , Li Dong , Tiezhu Yang , Chengen Du , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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 | 51 ++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 0b8fb14f5ff6..4a4541a2e887 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 117c4bb78b35..e1d14936a60d 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 3be5e8d1e278..e398abfd13a0 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c @@ -1419,7 +1419,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, u64 max_text_sh_offset) @@ -1470,8 +1470,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; } @@ -1484,8 +1484,8 @@ static int dso__process_kernel_symbol(struct dso *dso, struct map *map, */ if (kmodule && adjust_kernel_syms && is_exe_text(shdr->sh_flags) && shdr->sh_offset <= max_text_sh_offset) { - *curr_mapp = map; - *curr_dsop = dso; + dso__put(*curr_dsop); + *curr_dsop = dso__get(dso); return 0; } @@ -1507,10 +1507,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; @@ -1524,21 +1524,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; } @@ -1549,11 +1543,9 @@ 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 = NULL; Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym; uint32_t nr_syms; - int err = -1; uint32_t idx; GElf_Ehdr ehdr; GElf_Shdr shdr; @@ -1656,6 +1648,7 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, if (kmodule && adjust_kernel_syms) max_text_sh_offset = max_text_section(runtime_ss->elf, &runtime_ss->ehdr); + 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); @@ -1744,9 +1737,13 @@ 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, max_text_sh_offset)) + if (dso__process_kernel_symbol(dso, map, &sym, &shdr, + kmaps, kmap, &curr_dso, + section_name, + adjust_kernel_syms, + kmodule, + &remap_kernel, + max_text_sh_offset)) goto out_elf_end; } else if ((used_opd && runtime_ss->adjust_symbols) || (!used_opd && syms_ss->adjust_symbols)) { @@ -1795,6 +1792,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. @@ -1810,9 +1808,10 @@ dso__load_sym_internal(struct dso *dso, struct map *map, struct symsrc *syms_ss, maps__fixup_end(kmaps); } } - err = nr; + return nr; out_elf_end: - return err; + dso__put(curr_dso); + return -1; } int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, -- 2.44.0.769.g3c40516874-goog