From patchwork Fri Feb 2 06:15:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 195605 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp239518dyc; Thu, 1 Feb 2024 22:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjTUbV5KoAqQKd5wgtGWTfGQzkhUmqrQIKW/ePA4oDdvVTGZl9zUZ1SoS1Eo6jrFC4fXgD X-Received: by 2002:a05:622a:1007:b0:42a:339f:516c with SMTP id d7-20020a05622a100700b0042a339f516cmr7311081qte.68.1706854917334; Thu, 01 Feb 2024 22:21:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706854917; cv=pass; d=google.com; s=arc-20160816; b=NRJgp6qfgbcPBrO/sFDljZDsw3M6P+KDiGHvfJJf/kkFvMvItdireJPdDxi0JWRMO9 0b6mhVPMeDJCrDUz8Fd7YHTDIWVdNCj55G1pInBDC3Z6K1M2r4roC68BUAMEghbddAEO k3ccREyWSZqxmPygBFGjSm3orjUUwcom7+QRZeBnB0HMJU3/YPWBIdIUtaw5BpZ2GBkA igG6dhVzzslTNPIwQhhVWdsVlhwcYR1ynG85AC0P9sC/mKeT4ZOibBKwe3wUwWcBJJpu 7/9/IqaMA3v9iXpP94pAfvajf20bZNy8Z6db3o58Gb1+jV0FD6mNTq9TZU4dvpZyl1E7 FYtg== 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=n5YvFgFYxmEyXAB6dNy5nJiKJQA6ckdB9Gak22tlTgE=; fh=PTRHhjrTWr/ESokv+sRc/CXZeI+LI4CFGyM0+u40K7s=; b=TTGX2hr0PTgihVZ+rx7SdUHXlJAa3vtNl9k7CoLNwwB5e0YwRSPlXvmobnVJarP8QX 9uKm2qWE5kGHH+2ocEem9jDgFA7dKhlsHX9Bh550ilhYjfhNr0z9K3PADLNRKIYPAwPP AgsUS9YNKOookDtQI9ErsUsKjHuJcV1b0e+SqeRlgg5vYVl36eiFAEV3cSfmBsMtJjRX 8bS0DYZ2HoWBrnle5q50zd9Jd0PNVtasMX7ZGf8L4I4bMeR3S+dZk342wKpGp9jonHt5 8XwS1CzyWRMD9tF2fU0PKKJgH9O8fSNi/AGl3V3RVZzdVgDPpHXXMV+NCpUXnJ8qsf/g 8UVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eWgChzYT; 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-49262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49262-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCXe4rpWXO0G4oZsmk7XBXboIYqNUpPmz6yDNJXvskO1WK0TRjBQpigVqYog5XsgD040PERY3c1ywKXbEKYerDowKsMB9A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t22-20020a05622a01d600b0042bffb5a617si1245668qtw.273.2024.02.01.22.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 22:21:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=eWgChzYT; 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-49262-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49262-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 148DB1C23B86 for ; Fri, 2 Feb 2024 06:21:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DB5B17BD9; Fri, 2 Feb 2024 06:16:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="eWgChzYT" 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 A9F87487A2 for ; Fri, 2 Feb 2024 06:16:43 +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=1706854605; cv=none; b=FuYiwds8BZxgA0rdbJT9w4c9YDtOz2/N3odjPMRxa/55xN/XlsfN7f+V7Hifz/l/qNnkEubsWSwvBDZhegYWtgj7HCQlgTQiqu/SCmeFCFLkudw8iqx3/6qZWeo3f4rVfO7F6K/PLbNx7TtH3pIEQZEw56NU0WzFi3iYCd8yKuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706854605; c=relaxed/simple; bh=HTmMDuQzLKDWBOK/Fg5hhps0giyc5BqyAMhZAoiZKiY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=qBTJgmKtXlkOTbtRcoJB1YatGL6fq6/oUjxGryyF1XCkhMEC2HEJzEsNjdW8Ee6w+RY6aCqth4qQ1+Hrd7l38Pn2M6QguqiZgleJkheKx3d6rx/LWD0ioFuBM+8aMcKSaCoEem6HPO8hjgiTT6iqNnMmWqvO+/6vKngYBbNMgho= 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=eWgChzYT; 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-dc6b2681571so2728574276.2 for ; Thu, 01 Feb 2024 22:16:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706854602; x=1707459402; 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=n5YvFgFYxmEyXAB6dNy5nJiKJQA6ckdB9Gak22tlTgE=; b=eWgChzYTYpjx/3ijzvouZXIZFaSP6xov+U/cMp5k+LtJ/r7vGdB5g4G5XZAzu7DK3T QoiK4Xkb9YmmLDa0SgiWAya+7UAYAuhNHm7QCvJn5v0GYx3zKoDEX+LBOTZmufyMekKT AEPFcr/QEdtl/of3otCDKXEX6u4/ONSeneyCQzAqmzApifhsdWLFpt4pxdqWtDISI3dm LqWOtYChweAahOcF8ko1HEjMZ9uOkaYqBnGlWCVDy35g5S9ISuwpDCl2Rh3podUg6/z1 /SAJFDz1kJc4l9Oj4mah9cgblyqwxJlYbsIXX4ELQ381iVwil9PQaYxAotcHUSpfbTzL xTCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706854602; x=1707459402; 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=n5YvFgFYxmEyXAB6dNy5nJiKJQA6ckdB9Gak22tlTgE=; b=fzSSu9MgFc6mipyslJxAGjhEwm55oIqAND2QW2xVStW0AgExsSYLvWpqpdtP40IhQB 8FMPNW6xNOELPZOQeUVXuvi3WobdjbqSJW8+X+NyJlIJ0Osjl5yljMLZARrOx4b7TFVv KQJ2seaPFfUEw8jyVNf4eh1tBhstFKhTH+K7XB4UFDyRGuw1Nr2n4XBPe+OKjDuSRN9/ JU9DmNPSuGpnb+Iq7hDWMwK483S5mtxHMeC4nRqDyCN0zHE6NuHaFZPPVzoyGTKXvW42 Ly5m3K+bcnu/StNRmu0EeAuBOXALJqhPaBTokH/GMHm7sCvqJOvkPrMwdvyCDMfTdZcm fQDw== X-Gm-Message-State: AOJu0YxjTFe49Astmk5r+39Ozd+fhExg/hsTtSblF44ZxktTZ7cIRBjq c6Cui8iYrGRYDBQnrYWsZx5aPjeS+IyTK4KKLPkE5lseFn9n0ocCIe8ZI1EErgSf1A9t24tAvfe 1U/OFFw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:a85f:db1d:a66b:7f53]) (user=irogers job=sendgmr) by 2002:a05:6902:cc9:b0:dc2:57c9:b44d with SMTP id cq9-20020a0569020cc900b00dc257c9b44dmr179235ybb.8.1706854602622; Thu, 01 Feb 2024 22:16:42 -0800 (PST) Date: Thu, 1 Feb 2024 22:15:31 -0800 In-Reply-To: <20240202061532.1939474-1-irogers@google.com> Message-Id: <20240202061532.1939474-25-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202061532.1939474-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v8 24/25] 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 , "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 , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789767101908994955 X-GMAIL-MSGID: 1789767101908994955 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 49b8ccd5affe..2dbb7b06b117 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -682,7 +682,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; @@ -695,7 +695,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; @@ -734,6 +733,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.