From nobody Wed Nov 27 04:34:18 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 587371C331A; Mon, 14 Oct 2024 15:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919773; cv=none; b=SXu69d8b0B8Joh9jRXsuz32MszugJLwsU9xMqFC6m5f6jkrmtCqUltq6F6A/9bpHYek6Yfct5XonKlFAKcpkL0hXLhlL0uuCPBYhuELNaxrh3/3a5nzEF4uzC3uNDjmNRCxePxBcFTNpdH0t4X2jKafvRm6wIqEabS1VwTNsit4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728919773; c=relaxed/simple; bh=HliaOWIpuVeAXXP13yhqEmagwyLUvC0iDnxujig54Ys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DIGDvBYliE/H4fxwWCxFsy7URDzh8pnpucdeQdvUYQQahA9xwL+wsB63ArTR1Wu+/QKDlKI0fY4/9Evwq31AMDEnCFQRvEUxlFfFPDoeVrI0HGhRN15AlHNViyxCgAcGy/kQDGtRcpFXu8nHEUkk1fCT1sUot8Yufv1kwNnen/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sd5jvjzW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sd5jvjzW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC5AAC4CEC3; Mon, 14 Oct 2024 15:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728919773; bh=HliaOWIpuVeAXXP13yhqEmagwyLUvC0iDnxujig54Ys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sd5jvjzWEWYQDn6BwfytyJ/8P/wb8AnDesENi+qJwk+pBYOb4HdICp12eiF3NKz26 FEgCnzt3pN6SdZCqIzj1zK/Tv9PlkGSu1dsnma/dIUMH4wIBlGbGheklFA4Fc00SQ/ uqTTpjg073lg2U6j/vyeVQFLCebAFeBco7jczVxk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ian Rogers , K Prateek Nayak , Ravi Bangoria , Mark Rutland , Ross Zwisler , "Steven Rostedt (Google)" , Sean Christopherson , Yang Jihong , Peter Zijlstra , Adrian Hunter , Arnaldo Carvalho de Melo , Jiri Olsa , "Masami Hiramatsu (Google)" , Namhyung Kim , Leo Yan , Andi Kleen , Alexander Shishkin , Kan Liang , Tiezhu Yang , Ingo Molnar , Paolo Bonzini , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.1 672/798] perf lock: Dynamically allocate lockhash_table Date: Mon, 14 Oct 2024 16:20:26 +0200 Message-ID: <20241014141244.466609490@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241014141217.941104064@linuxfoundation.org> References: <20241014141217.941104064@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Rogers [ Upstream commit eef4fee5e52071d563d9a851df1c09869215ee15 ] lockhash_table is 32,768 bytes in .bss, make it a memory allocation so that the space is freed for non-lock perf commands. Signed-off-by: Ian Rogers Link: https://lore.kernel.org/r/20230526183401.2326121-10-irogers@google.com Cc: K Prateek Nayak Cc: Ravi Bangoria Cc: Mark Rutland Cc: Ross Zwisler Cc: Steven Rostedt (Google) Cc: Sean Christopherson Cc: Yang Jihong Cc: Peter Zijlstra Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Cc: Leo Yan Cc: Andi Kleen Cc: Alexander Shishkin Cc: Kan Liang Cc: Tiezhu Yang Cc: Ingo Molnar Cc: Paolo Bonzini Cc: linux-kernel@vger.kernel.org Cc: linux-perf-users@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo Stable-dep-of: 1a5efc9e13f3 ("libsubcmd: Don't free the usage string") Signed-off-by: Sasha Levin --- tools/perf/builtin-lock.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index 470106643ed52..28fa76ecc0822 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -45,7 +45,7 @@ static struct target target; #define LOCKHASH_BITS 12 #define LOCKHASH_SIZE (1UL << LOCKHASH_BITS) =20 -static struct hlist_head lockhash_table[LOCKHASH_SIZE]; +static struct hlist_head *lockhash_table; =20 #define __lockhashfn(key) hash_long((unsigned long)key, LOCKHASH_BITS) #define lockhashentry(key) (lockhash_table + __lockhashfn((key))) @@ -1645,16 +1645,22 @@ static int __cmd_contention(int argc, const char **= argv) }; struct lock_contention con =3D { .target =3D &target, - .result =3D &lockhash_table[0], .map_nr_entries =3D bpf_map_entries, .max_stack =3D max_stack_depth, .stack_skip =3D stack_skip, }; =20 + lockhash_table =3D calloc(LOCKHASH_SIZE, sizeof(*lockhash_table)); + if (!lockhash_table) + return -ENOMEM; + + con.result =3D &lockhash_table[0]; + session =3D perf_session__new(use_bpf ? NULL : &data, &eops); if (IS_ERR(session)) { pr_err("Initializing perf session failed\n"); - return PTR_ERR(session); + err =3D PTR_ERR(session); + goto out_delete; } =20 con.machine =3D &session->machines.host; @@ -1755,6 +1761,7 @@ static int __cmd_contention(int argc, const char **ar= gv) evlist__delete(con.evlist); lock_contention_finish(); perf_session__delete(session); + zfree(&lockhash_table); return err; } =20 @@ -1946,6 +1953,10 @@ int cmd_lock(int argc, const char **argv) unsigned int i; int rc =3D 0; =20 + lockhash_table =3D calloc(LOCKHASH_SIZE, sizeof(*lockhash_table)); + if (!lockhash_table) + return -ENOMEM; + for (i =3D 0; i < LOCKHASH_SIZE; i++) INIT_HLIST_HEAD(lockhash_table + i); =20 @@ -1967,7 +1978,7 @@ int cmd_lock(int argc, const char **argv) rc =3D __cmd_report(false); } else if (!strcmp(argv[0], "script")) { /* Aliased to 'perf script' */ - return cmd_script(argc, argv); + rc =3D cmd_script(argc, argv); } else if (!strcmp(argv[0], "info")) { if (argc) { argc =3D parse_options(argc, argv, @@ -1996,5 +2007,6 @@ int cmd_lock(int argc, const char **argv) usage_with_options(lock_usage, lock_options); } =20 + zfree(&lockhash_table); return rc; } --=20 2.43.0