From nobody Tue Feb 10 06:05:43 2026 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 18519157493 for ; Mon, 6 May 2024 18:01:53 +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=1715018515; cv=none; b=bRcqSvkc8UPyksH7OcacpHw77b0hbMlV4YmjYGdPJnQbGTzERekjVMWXcdcjLevXG2qPKnooGvKyBExcraSGD5NnJo9kcKgACY8WhruTuPLYeaLmajWvu76PnyOoACJTbTi7ZsqVeUP0j6j3orlus32DV4vm4twl+tb28FtGAkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018515; c=relaxed/simple; bh=70y0Uq70fTi9vP6E1n3v/21p95xUIVe00JfnSvODJ4M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=WJzdAxPcvj/vvTThUKJUn7K3DQMn2kqojQYP5wRX8S2FE8bFnVknkBqbK4POmEVsQD5c356m/dXT1ai4epN3Gc1e63XYvHkjHz9as1JX+q6jB6IDnX6dW5Voa0xwboFQBI50C/i73lHD0gENOGm8GdyR5L73JH+XPh7RxB/a224= 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=a3Do7Wgg; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a3Do7Wgg" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de617c7649dso4377559276.0 for ; Mon, 06 May 2024 11:01:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715018513; x=1715623313; 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=0nd3szNl+OFQsnbvKRBpAQwbxRmYTuaSHyM0OpbQt04=; b=a3Do7WggtAq/5DHafmiQOhbax/yaC4GHim3qOAatI1BlC3x5AZT5wX/uybqHQJDNE7 qAtmCSEVk1tRrFVmld/ZOyBQh8B+VSDW0vDZ79lRYOLqeJNXYJoO/UQJHA4vloaqCFlS zMU5+F+jdESru34V8MJIphlIw7a9oHsbfDaqEMMBoAbHOGnTBP8W9g6q+4XW/xt82EUE Gk8gopvwIPqMiJ4X6EFC+jNp+RTgcgneFewqDfDi+o3ZJTm31Id28g4golaHQ7glpuoQ Vk3EvqFAPK8a/sLHg7v4ZmMQIjj69FfByHCGV1gdmsRN4NNTN2ohlPDRi05g+NUBIWV1 o1EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715018513; x=1715623313; 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=0nd3szNl+OFQsnbvKRBpAQwbxRmYTuaSHyM0OpbQt04=; b=rjMmpS+MCssxZe91yQfQCItfp0ctwBa+7eIrmj261DJlwfxS9ovvxJ9MpdIwHfzzex MqVbJg6OwnQ1gNA/ifLDjkjOaadHQYGzRTE7cFD65KMwtKgwyibFVBhq/xUbnuftM409 6lvAHu5Aj/sRIx62E5C20KeS6++9ah7emjNfrMhL3iLuotzcCe5bPH/0TXnmlcu/vapK Vt2V9PJgmXolFoaaVvrO9Kmm5N5ViSXmYHGDWTd537vatPO7rxHn5Rw2pKJ//l/i4NHH 26HlYCh/gerDTAOxLd8laBvB4XQAY6S9uJfwhg8nJK7nlUYXoWjx3OpUXMLqV4hJQ7Ma VwSQ== X-Forwarded-Encrypted: i=1; AJvYcCWyNtdJQhWGuFLdZf5v6kGINwVjSYN/+jE47kt3KqsGZQgp9FxP+ytA39Z9yAo+MClVUKM7TWwToFq6PVCgzTtdOuhvit5BRoxq0aI0 X-Gm-Message-State: AOJu0Yw09MSiNwZTTo+BF/qcVIXI6Y1OIXg/cbjQmZZpfLluAo8EQM7W xf77hFGc1NLABlWq6lHM2lFmqNHSDdZ3Kph60tgxWNd4NP+6rnDllugNn2X4FHlk7C1RUGaHyz5 b5UtjJw== X-Google-Smtp-Source: AGHT+IFIF+mKPfdZA5z89/oE5y8/Z4uzaRdxsq56RtVsVl63c4Yu6VzU7+jSmmjQuDKupcDjwG02lEt15AT1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:91df:9b7f:c8d8:409a]) (user=irogers job=sendgmr) by 2002:a05:6902:726:b0:de5:5693:4e8e with SMTP id l6-20020a056902072600b00de556934e8emr1533970ybt.11.1715018513213; Mon, 06 May 2024 11:01:53 -0700 (PDT) Date: Mon, 6 May 2024 11:01:01 -0700 In-Reply-To: <20240506180104.485674-1-irogers@google.com> Message-Id: <20240506180104.485674-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240506180104.485674-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v7 1/4] perf map: Add missing dso__put in map__new 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 , Athira Rajeev , Changbin Du , Tiezhu Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A dso__put is needed for the dsos__find when the map is created and a buildid is sought. Fixes: f649ed80f3ca ("perf dsos: Tidy reference counting and locking") Signed-off-by: Ian Rogers --- tools/perf/util/map.c | 1 + 1 file changed, 1 insertion(+) 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); } --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Tue Feb 10 06:05:43 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 28D90158A2C for ; Mon, 6 May 2024 18:01:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018517; cv=none; b=fGhpLbOQvzYpEz3GeSVN37pcKa2HRpwySQ6Ks0afnwckBY+U/oCpN5A2dTyDP0/DIhb/BPDKMKIvLjSdnMKvmfeS2TY7GQIVbFdi0Q48igRwpBb2KDK23oIth6cmF4h/0xAUGe20B7gVk3PX0jPK9lNcZew+y+8HOo1RT5Wzmqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018517; c=relaxed/simple; bh=1yzFprNhaKFl6mEsHce9Oo3cfn1awTKRipJQsB6Z/KA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XuzshBu1sRH8rz/4ESr0d+ZbwwtS/4u8g3s+rIoqItclvd3V0f7iR0fsrolm1OQYIjUHwxjEtOrgFA70DtoOlhP3n5RHkQuQOc0RSlVn7azX9u9XUYiRfa2IeOHW09pNKdJU5IxcfL+IlWi3WMs0s1BNjOeQdO/FQIt8bnzeZQo= 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=F72Uk8HH; arc=none smtp.client-ip=209.85.128.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="F72Uk8HH" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be8f7ed6eso28366747b3.0 for ; Mon, 06 May 2024 11:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715018515; x=1715623315; 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=Gs61+vEHfK1A5CqaImlmWdzNwJtN0dQgBykm78W0t8E=; b=F72Uk8HHQgCMJtg8dIFxvq9u2vdUcSlPTd5FPdbEHx7YQwH2SpsxNnoGRYVftbdjpo FzWSexwt7k4bgRFJcBn26xgkeJ4Mqjtreo9IqQtfqtfS3KlsKvXCpBUEPfeaz2exBhn4 KcAW5QPAfc+FKprGZd6o6dUglVI0TESd6+bEm+1DQnrZY7zNh65Vuo9ObgnSb8L/nCl9 UgiRX/j7XvV9bwk9fpc+vmXp6beGcUYHrEl6iq+MS+pJl+p69GEg0P4qe8QP+Ah2osIV uFDfng49qz3uNrcLx6BXQl6j+mCZaK5MxS1V5uc7/whI05jPG/NSFveLZsl70Ob85FPg wvXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715018515; x=1715623315; 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=Gs61+vEHfK1A5CqaImlmWdzNwJtN0dQgBykm78W0t8E=; b=xCGS8ZeG77D171mtSK28Q6BKL8OJC23rzdt/P1A/YTtG55iKvKOuZwXaFQSUp2qLtn 2n616YtB206thnznrru8r3U2yYsQ4Bu2tqsJHFlSRHlAxT5R26EaS9+TYQRvKTYa1IHI bwPwiSAqc5dooP1ELkzkpM4yKKshgYFPRSa2wYVNQ5SESX51OUyLZNhg7YqXnWYr00ug PKdt3Pc1ZJoHlb/+7xLTImGl9QFhb5mMLvHy3XbDmPAtXN0JlMd3Fr3/oENzM18B2h+f tCEoDAZLJk1Ww367+T0CYQ1ncQitgNo4/sDBeOKpv2Ndek/njN/4ivJFYzLrT8YGUdv2 JOaQ== X-Forwarded-Encrypted: i=1; AJvYcCVY4kBtF76HQBgQX5Jfge3peGhUWYdIWThq3PhfkfQoqhsO0wOnvZyM/R33//ILYm2L1HyokTgZ7GEZeWH0Oe/gGgsk26fptvBWoERh X-Gm-Message-State: AOJu0YzLCzqBxkX06jhDwqRUxF/VgfGFE+iMLib15P0T882LXOMzVr+2 mxda8SbfnqHLzLD+4mYLdJMOfCglu7lEJuf75arZSj+4HSHpPYi/qhXd+kdQCfUh5HKOKlrM58X H3hyAmw== X-Google-Smtp-Source: AGHT+IHmpR/kZ77gWROkDuGj7RyagbQ7fJ7wQtcFf7RNBG+mtFYr8arNJ6kJc90frUmzyys/IOnpbg7lqixv X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:91df:9b7f:c8d8:409a]) (user=irogers job=sendgmr) by 2002:a81:910d:0:b0:611:5a9d:bb0e with SMTP id i13-20020a81910d000000b006115a9dbb0emr82660ywg.4.1715018515209; Mon, 06 May 2024 11:01:55 -0700 (PDT) Date: Mon, 6 May 2024 11:01:02 -0700 In-Reply-To: <20240506180104.485674-1-irogers@google.com> Message-Id: <20240506180104.485674-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240506180104.485674-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v7 2/4] perf symbol-elf: Ensure dso__put in machine__process_ksymbol_register 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 , Athira Rajeev , Changbin Du , Tiezhu Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dso__put after the map creation causes a use after put in the dso__set_loaded. To ensure there is a +1 reference count on both sides of the if-else, do a dso__get on the found map's dso. Signed-off-by: Ian Rogers --- tools/perf/util/machine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 0b8fb14f5ff6..a3ff2ab154bd 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -683,7 +683,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, struct perf_sample *sample __maybe_unused) { struct symbol *sym; - struct dso *dso; + struct dso *dso =3D NULL; struct map *map =3D maps__find(machine__kernel_maps(machine), event->ksym= bol.addr); int err =3D 0; =20 @@ -696,7 +696,6 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, } dso__set_kernel(dso, DSO_SPACE__KERNEL); map =3D map__new2(0, dso); - dso__put(dso); if (!map) { err =3D -ENOMEM; goto out; @@ -722,7 +721,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, dso__set_long_name(dso, "", false); } } else { - dso =3D map__dso(map); + dso =3D dso__get(map__dso(map)); } =20 sym =3D symbol__new(map__map_ip(map, map__start(map)), @@ -735,6 +734,7 @@ static int machine__process_ksymbol_register(struct mac= hine *machine, dso__insert_symbol(dso, sym); out: map__put(map); + dso__put(dso); return err; } =20 --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Tue Feb 10 06:05:43 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 D1125158A14 for ; Mon, 6 May 2024 18:01:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018521; cv=none; b=a4JYgxHy1SOGlX+bD/oZbsk0CgGMAOVl4p6RF2sHoVMKfEKLNfUvZ4d7gPazYHT5awgLKp8ChrQvxakUlELDjilg8jvlGLGh1EUwrwPXlW9lA/vPpKVNONU+OG075YrCoJJSmdIgbYubrkOP+LwlX4SSojQm/gy+uqqNVbTnMsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018521; c=relaxed/simple; bh=B5YCrNJTCZryBr4SX9wn6iX9/7NXKsUtgmUQYdaTOqU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=dgO2AsEOeZDEoJtN6FjMPccmYDDYVzfLbqHKRyDDtBpAPUzTAKOPAVeqi0gg58qFzDZVo6pBXaXt1faLklOZFpQL0LfKH6NuydCEfH2UvSk2wKZpu5lxnCdLBN46t5Y/6W4XaDeAEzlmdJQFZEepE7Xazoyxy1BqH68aAFON5Kw= 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=2aFOfafb; arc=none smtp.client-ip=209.85.219.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="2aFOfafb" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de59ff8af0bso3411912276.2 for ; Mon, 06 May 2024 11:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715018519; x=1715623319; 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=eshutGTjVoHzsDoYZ6X7cLa8J+Y1qLX+rGm1M53txEQ=; b=2aFOfafbEFmIv3QfB8bzDCCmfw6iHenS/UTsBq4qDvNWe8alMMpADcjpndmubXiO9d pxqzq53tTzWME3yeSq2VSmXzHoWthhnlcL9VtWRPKWStwc/pvoZnuPPJB4H7QNdI93sD WTCzdCozdcV90uB/oyDdBHUxRWkRkd/e7cP1hlurypUgC/MYsT1Jikdu6JtNyrU7J3nf Fw/CDWgLFR2cSuLsY50W8JnPib9CLT+40QyQLDW3NcBPyzKXnE0DLWegRXa2KnMhp707 WyFkj8p4XpziP1mIleYvY0D46tYlCCquoJM2nrz6TdiAAjWjqmftrPgdRfOl3WuINBYl QH/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715018519; x=1715623319; 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=eshutGTjVoHzsDoYZ6X7cLa8J+Y1qLX+rGm1M53txEQ=; b=Is6k9O3JwtpD35RdqNpIRueCsVxcS+lC/V92flsVLgNZDGofXPfcPku3Er53SEzvAG 5XX5nKD9NsPiKOhW01W4er0Tze2KnCqDsDcMxaCNO34f3QRGyExO83FzFUjVdgHxxxIX JkLNuMsT6FKGDJ22JFVugXMZ8O0DmWZ9O7oJX3ULrrptRZHrsq8dOSoIU2TvzPrG0VW2 Pv71g8NqJI/7LkcYgRl4urNAp6eKNn2Y71PBw/e6o2I0cGJPl+VkPo3UWhPypY7VTm8R GxiBuRoVgwZwD9TNgDF/W4nNYpx2wnKBQdjb4fmhNJtcT4B7Aa0sCCLoNvPqUK5zOHBI TSWw== X-Forwarded-Encrypted: i=1; AJvYcCW2HXfOQARGadUiWUZzy09KSJwtH9aCylscC/hoT/Lggju4ApPaPRI7Mo32sx9J+ZiI93jD0bVbn/1QzSftiQ/lfePZ4VMhwR99BYRl X-Gm-Message-State: AOJu0Yz3r7Pe2tu+qhMK7NvK/34p4geeJKLNYPfy9ZLBmOxltzLa8to5 WETtfDjBKltx5xXrKcIHqUA7u8D2w+dTJLURPlT0kjlt9Oq33VT5mjwnndy4woy4vdhn3kB1YWI k7RaJPA== X-Google-Smtp-Source: AGHT+IFycb80TYJHS38MiZ1ZZKc5F2EMkIKPLrvf5Bh1gwndCYV7HCmlJHYbrUfSp1G78RAFb2VjnjghsBW6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:91df:9b7f:c8d8:409a]) (user=irogers job=sendgmr) by 2002:a05:6902:703:b0:dbe:30cd:8fcb with SMTP id k3-20020a056902070300b00dbe30cd8fcbmr1331405ybt.0.1715018518877; Mon, 06 May 2024 11:01:58 -0700 (PDT) Date: Mon, 6 May 2024 11:01:03 -0700 In-Reply-To: <20240506180104.485674-1-irogers@google.com> Message-Id: <20240506180104.485674-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240506180104.485674-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v7 3/4] perf symbol-elf: dso__load_sym_internal reference count 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 , Athira Rajeev , Changbin Du , Tiezhu Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dso__load_sym_internal passed curr_mapp as an out argument to dso__process_kernel_symbol. The out argument was never used so remove it to simplify the reference counting logic. Simplify reference counting issues with curr_dso by ensuring the value it points to has a +1 reference count, and then putting as necessary. This avoids some reference counting games when the dso is created making the code more obviously correct with some possible introduced overhead due to the reference counting get/puts. This, however, silences reference count checking and we can always optimize from a seemingly correct point. Signed-off-by: Ian Rogers --- tools/perf/util/symbol-elf.c | 51 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) 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); } =20 - *curr_mapp =3D map; - *curr_dsop =3D dso; + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(dso); return 0; } =20 @@ -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 <=3D max_text_sh_offset) { - *curr_mapp =3D map; - *curr_dsop =3D dso; + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(dso); return 0; } =20 @@ -1507,10 +1507,10 @@ static int dso__process_kernel_symbol(struct dso *d= so, 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 =3D map__new2(start, curr_dso); - dso__put(curr_dso); - if (curr_map =3D=3D NULL) + if (curr_map =3D=3D NULL) { + dso__put(curr_dso); return -1; - + } if (dso__kernel(curr_dso)) map__kmap(curr_map)->kmaps =3D kmaps; =20 @@ -1524,21 +1524,15 @@ static int dso__process_kernel_symbol(struct dso *d= so, 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 =3D curr_map; + dso__put(*curr_dsop); *curr_dsop =3D curr_dso; } else { - *curr_dsop =3D map__dso(curr_map); - map__put(curr_map); + dso__put(*curr_dsop); + *curr_dsop =3D dso__get(map__dso(curr_map)); } + map__put(curr_map); =20 return 0; } @@ -1549,11 +1543,9 @@ dso__load_sym_internal(struct dso *dso, struct map *= map, struct symsrc *syms_ss, { struct kmap *kmap =3D dso__kernel(dso) ? map__kmap(map) : NULL; struct maps *kmaps =3D kmap ? map__kmaps(map) : NULL; - struct map *curr_map =3D map; - struct dso *curr_dso =3D dso; + struct dso *curr_dso =3D NULL; Elf_Data *symstrs, *secstrs, *secstrs_run, *secstrs_sym; uint32_t nr_syms; - int err =3D -1; uint32_t idx; GElf_Ehdr ehdr; GElf_Shdr shdr; @@ -1656,6 +1648,7 @@ dso__load_sym_internal(struct dso *dso, struct map *m= ap, struct symsrc *syms_ss, if (kmodule && adjust_kernel_syms) max_text_sh_offset =3D max_text_section(runtime_ss->elf, &runtime_ss->eh= dr); =20 + curr_dso =3D dso__get(dso); elf_symtab__for_each_symbol(syms, nr_syms, idx, sym) { struct symbol *f; const char *elf_name =3D 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; =20 if (dso__kernel(dso)) { - if (dso__process_kernel_symbol(dso, map, &sym, &shdr, kmaps, kmap, &cur= r_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 *m= ap, struct symsrc *syms_ss, __symbols__insert(dso__symbols(curr_dso), f, dso__kernel(dso)); nr++; } + dso__put(curr_dso); =20 /* * 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 =3D nr; + return nr; out_elf_end: - return err; + dso__put(curr_dso); + return -1; } =20 int dso__load_sym(struct dso *dso, struct map *map, struct symsrc *syms_ss, --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Tue Feb 10 06:05:43 2026 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 F0F7E1591E5 for ; Mon, 6 May 2024 18:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018524; cv=none; b=ecbgnTxdeu9jJczlopZbX7CViHcrTKkZNQSZyvK+FmQaVpMsrykWGtehH1lu6SQoDkD8Wr+8+nE1hIK/w3Zvd4NlYeNm0KHtAqkDqzCvreks2QePA8+j54/XcD1G7S7QFm9pBxjrC84tacfuhATCZBpAZK7nTqd/vysTnj+Qrqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715018524; c=relaxed/simple; bh=EnPZ72Jy6PLP4dTT506sUjost8vtZko8wVVrrNdjs5c=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=HqthMY6PLNBU/yS2faTMyU4g9hd/fs5VWcOTScGF3aAxcZRL+5Sc6NLONLMctvKSrCZZyBMtM+cX/qcJZZkI8RAIg+zcCgwVWrYS2jsTjWjiJ4HJhYXGArfUMMzafQa5VRHmpB6pwb4lr9kU2ouag0ocwlCMCE703IIr17yRkgI= 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=yfwWygja; arc=none smtp.client-ip=209.85.219.201 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yfwWygja" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-ddaf165a8d9so3463776276.1 for ; Mon, 06 May 2024 11:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1715018521; x=1715623321; 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=q472qqxF5ihtJmhy47OpIos2OiFBFiIxQhyS5d/9W5Q=; b=yfwWygjaPBRfQFbZeFwOPe6oKCgwDK5i7Pub+ibHpPsDhRhl+cGkB8jWUQKv6G9e6p UjsELKKU0ePMbXF0pjzuzqjOxsAUP/BBEYYH3S3myG3UXdxH32Kpx93mm96KvkkYKYWd g5QBdwuts/lwu+9P4g6Cqu8h7SGIgKvBXfKaiSXDFDHwzCM7qIpO4W7w/hxrELrwokGE hPKNnj5qElue5RbGTTUCyN7vrWcejAI4qd1oZ3ArbxWkRmu3IdwXzIfge0hzzgkx+et4 7UGbS/6ZGMj0ZmT++g1T3/v9VT90Lk8bsI+E/dVz7DSsPtgHQ58kOCEOw5IwGUFvWP/e B03Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715018521; x=1715623321; 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=q472qqxF5ihtJmhy47OpIos2OiFBFiIxQhyS5d/9W5Q=; b=E7CsiNdXW2Y0+kazvMcgRewJVjU4GUYQRBEeXH4YVL45TeSxA4iHBhjxDBOUNzifVw NxOdjdta3qrY4/XWxFbTYfV+lb1kkwMviPpMoIqy1GH2sewsOSRiSMfl8WCa/0imkKsN EEyIu3dLkfnIHFM/pNGbsNgrkUQsCTLmDEsFISUBDNsjpR1elcIZrQaPwJYpfvQ5Jl54 PMRsbDnFnxwRSlEzgwBatsx+Ou/gMOIMMq8j9bqrPqHIqPCUFDTcEj9XSzVtw2NI2gXn 4lrc/pn212jlHyovfTwWR18uOWmXmTMPRza0aRuPs7deD3ErW1goFsuCIJrii3TQ1YWk o+oA== X-Forwarded-Encrypted: i=1; AJvYcCUyzda7YgjoPAawmYBot5d3bxhmx12AwRXsPFoKNqaOqsvoqtCb7z40Az4twEx1k0nxZEyykYSoq6ZUf08LhTVum2xwcYlZ9OBuH8xd X-Gm-Message-State: AOJu0Yz5RMFGGWButsZ+GDbO/FpKlXIIhPDIlH+7MsctCG8f+nTosWXS kHv3bLEJwuuau4fZZaB8+3o7+BvLnTdvf9f+jeX+skgrjcu7S/GrHLWFpiPFQcYPT8DWZyW6G46 J50kzHA== X-Google-Smtp-Source: AGHT+IEeO4AWB5B5D068fGnz9janYAk7jmAAzSDgkgTwNJ2PoWAwP8T6RPgewaZyqLob0DyUiRV+DTkEyaGC X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:91df:9b7f:c8d8:409a]) (user=irogers job=sendgmr) by 2002:a25:b311:0:b0:dc6:44d4:bee0 with SMTP id l17-20020a25b311000000b00dc644d4bee0mr1359444ybj.7.1715018521035; Mon, 06 May 2024 11:02:01 -0700 (PDT) Date: Mon, 6 May 2024 11:01:04 -0700 In-Reply-To: <20240506180104.485674-1-irogers@google.com> Message-Id: <20240506180104.485674-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240506180104.485674-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v7 4/4] perf dso: Use container_of to avoid a pointer in dso_data 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 , Athira Rajeev , Changbin Du , Tiezhu Yang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The dso pointer in dso_data is necessary for reference count checking to account for the dso_data forming a global list of open dso's with references to the dso. The dso pointer also allows for the indirection that reference count checking needs. Outside of reference count checking the indirection isn't needed and container_of is more efficient and saves space. The reference count won't be increased by placing items onto the global list, matching how things were before the reference count checking change, but we assert the dso is in dsos holding it live (and that the set of open dsos is a subset of all dsos for the machine). Update the DSO data tests so that they use a dsos struct to make the invariant true. Signed-off-by: Ian Rogers --- tools/perf/tests/dso-data.c | 60 ++++++++++++++++++------------------- tools/perf/util/dso.c | 16 +++++++++- tools/perf/util/dso.h | 2 ++ 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/tools/perf/tests/dso-data.c b/tools/perf/tests/dso-data.c index fde4eca84b6f..5286ae8bd2d7 100644 --- a/tools/perf/tests/dso-data.c +++ b/tools/perf/tests/dso-data.c @@ -10,6 +10,7 @@ #include #include #include "dso.h" +#include "dsos.h" #include "machine.h" #include "symbol.h" #include "tests.h" @@ -123,9 +124,10 @@ static int test__dso_data(struct test_suite *test __ma= ybe_unused, int subtest __ TEST_ASSERT_VAL("No test file", file); =20 memset(&machine, 0, sizeof(machine)); + dsos__init(&machine.dsos); =20 - dso =3D dso__new((const char *)file); - + dso =3D dso__new(file); + TEST_ASSERT_VAL("Failed to add dso", !dsos__add(&machine.dsos, dso)); TEST_ASSERT_VAL("Failed to access to dso", dso__data_fd(dso, &machine) >=3D 0); =20 @@ -170,6 +172,7 @@ static int test__dso_data(struct test_suite *test __may= be_unused, int subtest __ } =20 dso__put(dso); + dsos__exit(&machine.dsos); unlink(file); return 0; } @@ -199,41 +202,35 @@ static long open_files_cnt(void) return nr - 1; } =20 -static struct dso **dsos; - -static int dsos__create(int cnt, int size) +static int dsos__create(int cnt, int size, struct dsos *dsos) { int i; =20 - dsos =3D malloc(sizeof(*dsos) * cnt); - TEST_ASSERT_VAL("failed to alloc dsos array", dsos); + dsos__init(dsos); =20 for (i =3D 0; i < cnt; i++) { - char *file; + struct dso *dso; + char *file =3D test_file(size); =20 - file =3D test_file(size); TEST_ASSERT_VAL("failed to get dso file", file); - - dsos[i] =3D dso__new(file); - TEST_ASSERT_VAL("failed to get dso", dsos[i]); + dso =3D dso__new(file); + TEST_ASSERT_VAL("failed to get dso", dso); + TEST_ASSERT_VAL("failed to add dso", !dsos__add(dsos, dso)); + dso__put(dso); } =20 return 0; } =20 -static void dsos__delete(int cnt) +static void dsos__delete(struct dsos *dsos) { - int i; - - for (i =3D 0; i < cnt; i++) { - struct dso *dso =3D dsos[i]; + for (unsigned int i =3D 0; i < dsos->cnt; i++) { + struct dso *dso =3D dsos->dsos[i]; =20 dso__data_close(dso); unlink(dso__name(dso)); - dso__put(dso); } - - free(dsos); + dsos__exit(dsos); } =20 static int set_fd_limit(int n) @@ -267,10 +264,10 @@ static int test__dso_data_cache(struct test_suite *te= st __maybe_unused, int subt /* and this is now our dso open FDs limit */ dso_cnt =3D limit / 2; TEST_ASSERT_VAL("failed to create dsos\n", - !dsos__create(dso_cnt, TEST_FILE_SIZE)); + !dsos__create(dso_cnt, TEST_FILE_SIZE, &machine.dsos)); =20 for (i =3D 0; i < (dso_cnt - 1); i++) { - struct dso *dso =3D dsos[i]; + struct dso *dso =3D machine.dsos.dsos[i]; =20 /* * Open dsos via dso__data_fd(), it opens the data @@ -290,17 +287,17 @@ static int test__dso_data_cache(struct test_suite *te= st __maybe_unused, int subt } =20 /* verify the first one is already open */ - TEST_ASSERT_VAL("dsos[0] is not open", dso__data(dsos[0])->fd !=3D -1); + TEST_ASSERT_VAL("dsos[0] is not open", dso__data(machine.dsos.dsos[0])->f= d !=3D -1); =20 /* open +1 dso to reach the allowed limit */ - fd =3D dso__data_fd(dsos[i], &machine); + fd =3D dso__data_fd(machine.dsos.dsos[i], &machine); TEST_ASSERT_VAL("failed to get fd", fd > 0); =20 /* should force the first one to be closed */ - TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(dsos[0])->fd =3D=3D = -1); + TEST_ASSERT_VAL("failed to close dsos[0]", dso__data(machine.dsos.dsos[0]= )->fd =3D=3D -1); =20 /* cleanup everything */ - dsos__delete(dso_cnt); + dsos__delete(&machine.dsos); =20 /* Make sure we did not leak any file descriptor. */ nr_end =3D open_files_cnt(); @@ -325,9 +322,9 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub long nr_end, nr =3D open_files_cnt(), lim =3D new_limit(3); int fd, fd_extra; =20 -#define dso_0 (dsos[0]) -#define dso_1 (dsos[1]) -#define dso_2 (dsos[2]) +#define dso_0 (machine.dsos.dsos[0]) +#define dso_1 (machine.dsos.dsos[1]) +#define dso_2 (machine.dsos.dsos[2]) =20 /* Rest the internal dso open counter limit. */ reset_fd_limit(); @@ -347,7 +344,8 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub TEST_ASSERT_VAL("failed to set file limit", !set_fd_limit((lim))); =20 - TEST_ASSERT_VAL("failed to create dsos\n", !dsos__create(3, TEST_FILE_SIZ= E)); + TEST_ASSERT_VAL("failed to create dsos\n", + !dsos__create(3, TEST_FILE_SIZE, &machine.dsos)); =20 /* open dso_0 */ fd =3D dso__data_fd(dso_0, &machine); @@ -386,7 +384,7 @@ static int test__dso_data_reopen(struct test_suite *tes= t __maybe_unused, int sub =20 /* cleanup everything */ close(fd_extra); - dsos__delete(3); + dsos__delete(&machine.dsos); =20 /* Make sure we did not leak any file descriptor. */ nr_end =3D open_files_cnt(); diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 27db65e96e04..dde706b71da7 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -497,14 +497,20 @@ static pthread_mutex_t dso__data_open_lock =3D PTHREA= D_MUTEX_INITIALIZER; static void dso__list_add(struct dso *dso) { list_add_tail(&dso__data(dso)->open_entry, &dso__data_open); +#ifdef REFCNT_CHECKING dso__data(dso)->dso =3D dso__get(dso); +#endif + /* Assume the dso is part of dsos, hence the optional reference count abo= ve. */ + assert(dso__dsos(dso)); dso__data_open_cnt++; } =20 static void dso__list_del(struct dso *dso) { list_del_init(&dso__data(dso)->open_entry); +#ifdef REFCNT_CHECKING dso__put(dso__data(dso)->dso); +#endif WARN_ONCE(dso__data_open_cnt <=3D 0, "DSO data fd counter out of bounds."); dso__data_open_cnt--; @@ -654,9 +660,15 @@ static void close_dso(struct dso *dso) static void close_first_dso(void) { struct dso_data *dso_data; + struct dso *dso; =20 dso_data =3D list_first_entry(&dso__data_open, struct dso_data, open_entr= y); - close_dso(dso_data->dso); +#ifdef REFCNT_CHECKING + dso =3D dso_data->dso; +#else + dso =3D container_of(dso_data, struct dso, data); +#endif + close_dso(dso); } =20 static rlim_t get_fd_limit(void) @@ -1449,7 +1461,9 @@ struct dso *dso__new_id(const char *name, struct dso_= id *id) data->fd =3D -1; data->status =3D DSO_DATA_STATUS_UNKNOWN; INIT_LIST_HEAD(&data->open_entry); +#ifdef REFCNT_CHECKING data->dso =3D NULL; /* Set when on the open_entry list. */ +#endif } return res; } diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index f9689dd60de3..df2c98402af3 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -147,7 +147,9 @@ struct dso_cache { struct dso_data { struct rb_root cache; struct list_head open_entry; +#ifdef REFCNT_CHECKING struct dso *dso; +#endif int fd; int status; u32 status_seen; --=20 2.45.0.rc1.225.g2a3ae87e7f-goog