From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385206; b=zEevaw5r/ybFqXBspLMjOuYqydtffOnWLwhP8m6Maxzp2YWDDGaQ/9DCgAjqNhCGWBGn h869lw7rt/hOEuQW6/3S1TfatUeNQ4Gj2PeuCmAJr1GV0jDitCoAGyX2cxfpY44M3nSHk XTbUtQjcmfUPn9jTLdfIODSO8fiZGqjBKpqkrpOZFb+jluUygd1JXLFgnSLTDbUqlD0jY gbc7aKfGVop1UJtIAh5s4dyU9rROK3Wq5pgh8GO5mcqdkWv/WfDT0D/eG2DF+rMME7FKT dS9Mp0TDgqBHQhvdV+S7vAjrggZhf13ua5qf0l5n5RnemrlDV8O86s7NTGkZg13hj/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385206; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=wS4b0mhVlA6/Nj9HQiBh8UZew5RML1I+cp7iT6Llwz0=; b=mDHmC/W4RyCLP28i6k1CwoQ99F3KnN+V4BZboR/bsOByupzAIRq1aHdPdwt9wZLjBc4A JHR6GaYwLbKQYQv69tEdOSKUTqRhVg0JQrBOzD88ylO5we65jc6ApBZU6vIvHg2RUY681 AfSJSeyUM2NRVRYUVXP2gwQwAqZEcLdAb1s3ZblooL46s+2ZZU92QEBj57ZTRsQjwVhkg ieAIdKGGMNLsJw7TgVvp8lF+Vuo3YDfLo23jkxQ5SMV4RgPUy7F4Kov/bbhBlOglhuSv4 gFOrEwdKmSsWyz8hTiIe4/irwF3ZxA9rnxS0OtT0g1wLAoMbONTZM2FGnDqhJbisGbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UGKBYeyj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D076606A322; Fri, 4 Dec 2026 11:53:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UGKBYeyj Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB8721F00934; Fri, 4 Dec 2026 11:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385206; bh=wS4b0mhVlA6/Nj9HQiBh8UZew5RML1I+cp7iT6Llwz0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UGKBYeyjjA0pViXBsc2vuBUnc+gMcdFyecQ8jTTARBZiof5of7lSDroRYax3TyUlE 5dTJMoBHEH1el9b5Py0Qe/G4TFIzepGVkDXUIgcTueDKqqHmw61jRf8VyV/c4cbwSh WLEU5+LPcM0l7KYreEzFrNKV1rXCkyMRkdHjtwUc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Namhyung Kim , Ian Rogers , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 6.6 0456/1167] perf lock contention: Filter events before creating lock_stat Date: Fri, 4 Dec 2026 18:58:03 +0900 Message-ID: <20261204100713.894269166@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ian Rogers [ Upstream commit c58d1598e79554cc8f587668ab2ebcaeb616b076 ] In report_lock_contention_begin_event(), lock_stat_findnew() was called before checking filters.nr_types (-Y), filters.nr_addrs (-L), and match_callstack_filter() (-S). When a filtered-out lock event (such as a mutex contention when running with -Y spinlock) shared the same aggregation key as a subsequent matching event (for example, contention on the mutex's internal wait_lock spinlock from the same caller), the first event created the lock_stat entry with the filtered-out lock's flags and the second event reused that entry, causing non-spinlock entries to appear in -Y spinlock output. Check the type, address, and callstack filters before looking up or creating the lock_stat entry. Fixes: b4a7eff93c39f985 ("perf lock contention: Add -Y/--type-filter option") Reviewed-by: Namhyung Kim Signed-off-by: Ian Rogers Signed-off-by: Arnaldo Carvalho de Melo [ sashal: adjusted context for the 6.6 API: lock_contention_caller() keeps its evsel argument, and the moved lookup block has no LOCK_AGGR_CGROUP case. ] Signed-off-by: Sasha Levin --- tools/perf/builtin-lock.c | 59 +++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c index bd294fd574972..644057defa50b 100644 --- a/tools/perf/builtin-lock.c +++ b/tools/perf/builtin-lock.c @@ -1067,6 +1067,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, struct machine *machine = &session->machines.host; struct map *kmap; struct symbol *sym; + u64 *callstack = NULL; ret = get_key_by_aggr_mode(&key, addr, evsel, sample); if (ret < 0) @@ -1102,32 +1103,6 @@ static int report_lock_contention_begin_event(struct evsel *evsel, } } - ls = lock_stat_find(key); - if (!ls) { - char buf[128]; - const char *name = ""; - - switch (aggr_mode) { - case LOCK_AGGR_ADDR: - sym = machine__find_kernel_symbol(machine, key, &kmap); - if (sym) - name = sym->name; - break; - case LOCK_AGGR_CALLER: - name = buf; - if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) - name = "Unknown"; - break; - case LOCK_AGGR_TASK: - default: - break; - } - - ls = lock_stat_findnew(key, name, flags); - if (!ls) - return -ENOMEM; - } - if (filters.nr_types) { bool found = false; @@ -1157,7 +1132,7 @@ static int report_lock_contention_begin_event(struct evsel *evsel, } if (needs_callstack()) { - u64 *callstack = get_callstack(sample, max_stack_depth); + callstack = get_callstack(sample, max_stack_depth); if (callstack == NULL) return -ENOMEM; @@ -1165,7 +1140,37 @@ static int report_lock_contention_begin_event(struct evsel *evsel, free(callstack); return 0; } + } + + ls = lock_stat_find(key); + if (!ls) { + char buf[128]; + const char *name = ""; + + switch (aggr_mode) { + case LOCK_AGGR_ADDR: + sym = machine__find_kernel_symbol(machine, key, &kmap); + if (sym) + name = sym->name; + break; + case LOCK_AGGR_CALLER: + name = buf; + if (lock_contention_caller(evsel, sample, buf, sizeof(buf)) < 0) + name = "Unknown"; + break; + case LOCK_AGGR_TASK: + default: + break; + } + + ls = lock_stat_findnew(key, name, flags); + if (!ls) { + free(callstack); + return -ENOMEM; + } + } + if (callstack) { if (ls->callstack == NULL) ls->callstack = callstack; else -- 2.53.0