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=1796384642; b=IPFljsIgwwMgJFuj5Tw7+6XR7wWNqGUY5hsFMfwPp4opWg5f4OWykHhz8DLv6QbXKZeA PAXXS24RyEpRK+NEiSqcP+I5s0R66EBymPaxvlcnIleHdf09MTGQbNunuAQLhPZppwp4V R+ntsrLBDAhJ3lZ/1uYu2aR3t0Psc8HdtwUd+E7F5kCp98KsPixvaewZPumTtxWr+FNwf czlv7j09oUlREJrt5D0zi2jpDjxA9F6hYST+Er2LhdfIC0WS9rhqfsRVKXJ2426quilUt 82vVvC3vJsNbJ4GeVoOowhaxO+aqBGOKiXpi5tK6MkcGFdvEvrQR1NdLoac8WtwH/OA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384642; 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=IaOtJSzz9uNEbEnH2Ha1SzjWiLfUyv+ZA3iooYupaWY=; b=RZuVm9arssXr+FlOx4yJ/Ky6GuNNWjnAZPG3ITAM6NtL1d+3YltUMcJ/cj/fqqaFr+7t Yfft3Gs1M49rOnfDxWK7rqJ79YB1Tw1/82aMHTFWEHusfG+8xVUSvU3R7t5H9GwAErSop IMrxr6Jc6U+UJvX2SNv4LkREzcBefyxtzYdeUF9+EYwSxz8WsmeKhk0AwYnWNrtfh2wwe FlltdPJbOjvxI5RSYffUR/XL9cgLaWfLa+DcJYxa/5jQKCXX1UK1XTWlaVN59jpGNl6Yq lpia7tsBIFjGgt8NM3xO/rkLfYeCm3PU+rKPXhUEeZ9N3Gnx9Nzq7YFHdnO73iU9BVw== 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="eqkZbb/1"; 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 E25EF606A322; Fri, 4 Dec 2026 11:44:01 +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=eqkZbb/1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEDFD1F000CE; Fri, 4 Dec 2026 11:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384641; bh=IaOtJSzz9uNEbEnH2Ha1SzjWiLfUyv+ZA3iooYupaWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eqkZbb/1AORELMFunIeU8tknUIRF2tDOxN2o61luqodHhQ3dci3Bjw3Ieajp5ERjh NKcQag/gprDL/6G1fFvkg1Seb4WT0/2QNsBJkiqc1fyNWMDB/iIz3ziF6M3YmXxLDO /U22Hkvu9HCp1dlMLOwh+/s1FQHdPlbPhkuBoR6c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sandipan Das , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 6.6 0196/1167] perf/x86/amd/uncore: Avoid context migration from non-owners Date: Fri, 4 Dec 2026 18:53:43 +0900 Message-ID: <20261204100707.168774672@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: patches@lists.linux.dev 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: Sandipan Das [ Upstream commit 0ae655bce1934857fa3e316ddcb4be38c30dbd38 ] Each uncore context is owned by a single CPU that hosts all events for the corresponding uncore domain and is advertised through the sysfs cpumask attribute. When a CPU goes offline, the context is migrated to an online sibling if the departing CPU is the owner. Before commit d6389d3ccc13 ("perf/x86/amd/uncore: Refactor uncore management"), uncore_down_prepare() checked whether the CPU going offline owned the context. The check was lost when the function was replaced by amd_uncore_ctx_move(). Hence, when a CPU that is not the owner goes offline, ownership is always handed over to the first online sibling in the uncore domain irrespective of whether another sibling already owns it. This goes unnoticed as long as the owner is the lowest-numbered online CPU in the domain, since the first online sibling is then the owner itself. Once ownership has moved, that no longer holds. For example, consider an L3 domain spanning CPUs 8-15,136-143 and owned by CPU 8. $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120 $ echo 0 | sudo tee /sys/devices/system/cpu/cpu8/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,9,16,24,32,40,48,56,64,72,80,88,96,104,112,120 $ echo 1 | sudo tee /sys/devices/system/cpu/cpu8/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,9,16,24,32,40,48,56,64,72,80,88,96,104,112,120 $ echo 0 | sudo tee /sys/devices/system/cpu/cpu10/online $ cat /sys/bus/event_source/devices/amd_l3/cpumask 0,8-9,16,24,32,40,48,56,64,72,80,88,96,104,112,120 Offlining CPU 8 correctly moves ownership to CPU 9 and onlining it again leaves CPU 9 as the owner. However, offlining CPU 10 then makes CPU 8 the owner while existing events remain on CPU 9. Both CPUs are now advertised for the same domain, so tools that open an event on every CPU in the cpumask count the domain twice, and the context gets modified from two CPUs without any synchronization. Restore the ownership check that was lost during the refactor. Fixes: d6389d3ccc13 ("perf/x86/amd/uncore: Refactor uncore management") Signed-off-by: Sandipan Das Signed-off-by: Peter Zijlstra (Intel) Link: https://patch.msgid.link/273135a6d33a40f442fb18e140a90689fae7cd32.1793614726.git.sandipan.das@amd.com Signed-off-by: Sasha Levin --- arch/x86/events/amd/uncore.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c index f24122c41c430..80edb04c28c77 100644 --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -498,7 +498,7 @@ static void amd_uncore_ctx_move(struct amd_uncore *uncore, unsigned int cpu) for (i = 0; i < uncore->num_pmus; i++) { pmu = &uncore->pmus[i]; curr = *per_cpu_ptr(pmu->ctx, cpu); - if (!curr) + if (!curr || curr->cpu != cpu) continue; /* Migrate to a shared sibling if possible */ -- 2.53.0