Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3289201pxk; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvgVVZXQc76b9qHGbGgqDmDA5xH03PjGgj1YlmziqJJQ7iLwCGqUHbzr7CThxU2Xw0EUwz X-Received: by 2002:a17:906:4685:: with SMTP id a5mr346799ejr.446.1600706857254; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600706857; cv=none; d=google.com; s=arc-20160816; b=HPd9H7itzWdyxXs84PUWSzYM02bENWb7jRWDmYShIaexhoEN3OA9bjCur9vXv5Webz OnE1OgzimqEIe70E/BmB5yruGUb+S4hgSwaLjv/AajhJNV7ZDTy5wumdQW6JhlR4D+Kd LNof4jgNRSz/vM1DaXE/Iloc+nYJjwGeT2PPd0CftyheyMavz//rnx5fG8hZJE6iM2eu U90sUXj+vdiJb4gCM/XF404P1k3+B1hF8JRYxiQixDJIzfB4Ip7RyPC6bpu6nBQkLyRL ybElOjgviZbjN9IgKZpucmtcsp5//IsNsmGq1q8d4+kw74UI88zRDUb7mfS2V6RJ0a8Y TnuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JSLaWCkSGqKwq4GdYD0tDNV33oDhZd8XvtAWU6wG614=; b=LtrN/nrE61RycmSqSPzmSdMQeI6Jv+y5SRlRS8ucqSixNNbbZziishJC4eH9VT1W2Q 9ryjQpJsoB6wKx/JrtlnN4Q8ZeSbfYiauKCWKko4nNIUQpklemDoqBm8JFoBBW0fbFNh +GdmMURzHgg3iohpUay+sDGlHn8dM9NCp65djQXNaXkLsC+CTCSIRkbCfnhLEqRCj+V4 LdwCIrR4ah+q9Ian4Q6fl+l/D0HI3ZNhRyC6/BwJGGHzXg4G0UX3M9/1O5vsaqD4WGRp /+qadQc3tWNaGPWOobVtFVb3ie5C/sS4QA26yuE1W8C9uvSNZdUxLvIOe39KXQ7dgvar C7GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I0ilcwsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u15si8699983edo.55.2020.09.21.09.47.13; Mon, 21 Sep 2020 09:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I0ilcwsr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729594AbgIUQqV (ORCPT + 99 others); Mon, 21 Sep 2020 12:46:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:52396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727838AbgIUQqS (ORCPT ); Mon, 21 Sep 2020 12:46:18 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 89A1423888; Mon, 21 Sep 2020 16:46:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706778; bh=OQezxXUbYJ6jSeu0GCWveY6tXoG4TZbVPRRZEvs0g3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0ilcwsrgBjqBgljtpCtcDefMV5x3LvNEhL/LfJ5xeruqQ2jmoYSV+LoxCygqQbBq R6tJuyClqhB61sMVoR7/QVSm0kTFCc9C/BJqzPfOe6B4mnMcFtF1itKDdnVLxsii5P Zt5eesCDdvjyEe99edcP1PB0G7C8YXVF4fjDxXSg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Jiri Olsa , Alexander Shishkin , Andi Kleen , Ian Rogers , Mark Rutland , Peter Zijlstra , Stephane Eranian , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.8 061/118] perf evlist: Fix cpu/thread map leak Date: Mon, 21 Sep 2020 18:27:53 +0200 Message-Id: <20200921162039.192261076@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namhyung Kim [ Upstream commit bfd1b83d75e44a9f65de30accb3dd3b5940bd3ac ] Asan reported leak of cpu and thread maps as they have one more refcount than released. I found that after setting evlist maps it should release it's refcount. It seems to be broken from the beginning so I chose the original commit as the culprit. But not sure how it's applied to stable trees since there are many changes in the code after that. Fixes: 7e2ed097538c5 ("perf evlist: Store pointer to the cpu and thread maps") Fixes: 4112eb1899c0e ("perf evlist: Default to syswide target when no thread/cpu maps set") Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ian Rogers Cc: Mark Rutland Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lore.kernel.org/lkml/20200915031819.386559-4-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/evlist.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ab48be4cf2584..b279888bb1aab 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -946,6 +946,10 @@ int perf_evlist__create_maps(struct evlist *evlist, struct target *target) perf_evlist__set_maps(&evlist->core, cpus, threads); + /* as evlist now has references, put count here */ + perf_cpu_map__put(cpus); + perf_thread_map__put(threads); + return 0; out_delete_threads: @@ -1273,11 +1277,12 @@ static int perf_evlist__create_syswide_maps(struct evlist *evlist) goto out_put; perf_evlist__set_maps(&evlist->core, cpus, threads); -out: - return err; + + perf_thread_map__put(threads); out_put: perf_cpu_map__put(cpus); - goto out; +out: + return err; } int evlist__open(struct evlist *evlist) -- 2.25.1