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=1796387301; b=WEn2Kt0a3tZT7s85XNZRsDRMWE9yX5MHbZi9HNowH8bt2KQ9A4n5wTvtmD67+VaRU8Xd C1Z7rBSeC1FMmpTiqSvG4Fr+1EH+Oznwnc5/Wx1tgETHHa37KSV4URq3y4lgu5o16ihzk 3j4qIxYnU26pNUZ9WviYnS7j+yIM+CiQ1vtF7TAyd6rdcNhRpH5pjIrtkk/8rLTqOqInt Lr6SajZ1wEpIDbHfj7GZ23DFiRQUD346XB+gaAYTUT98Z6gv8Qkc5KovroUFCN+hdlgwJ b+m+z+kYPmrjtCdtv9kYYR6p9OFJ6YefB4JXypdciBuKVV+cjBtW93pP1+pMTVThF8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387301; 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=Vf24gCz7gthclXjt7tJuff1w6f6ZwZimWqIqMAb7cQk=; b=ipw7dTbBYhWrWo2xdH1w0RwvFYNrLJqcnWKFuy5U3CYU5P2ZSm0fd5rQr+oEJwmc17dO a9gmdQaVPbGuFTkTNXjhIvuF/DZmLvboM56M5nE2v4dACWOLSiJ04i2wARQWEFLr13iE3 HLeb/Au2oK4A9ZcguZusbpWDcs6cz9UNSpNiNAk6eyrvs9jh2AVzAznwDmOwh3lbL0qhW 5wE3M48hsTOVADPyhwdlRZqgFmg43MgES6y7Ss1ICvBcHB73k587bojS51DwqO+3m3Xrm GhVgDvTeEqvHU/CcCsXTrhM/zKjOwAnhRjd8QdZ4cOFSm0clZy1/KUKcuMvpMJ0L/Nw== 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=vGOhnrbJ; 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 2DBB7606A322; Fri, 4 Dec 2026 12:28:21 +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=vGOhnrbJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98F8D1F000C2; Fri, 4 Dec 2026 12:28:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387301; bh=Vf24gCz7gthclXjt7tJuff1w6f6ZwZimWqIqMAb7cQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=vGOhnrbJ0XqrZDSJn3eySBp087S06QNh0JOuJQJBNzm3KKU6+yr5+43VVu6RTlEFH fkKH0D/cLcqqgdlve/BXAMZw9awnO/bj2L0anvHo9q+BNThHGYZlDUHsZ4a0e1SW5j 9Xwezy/26ZDcYolcwWJN22QMuJivzFyw7BhxDRf0= 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.1 0148/1059] perf/x86/amd/uncore: Avoid context migration from non-owners Date: Fri, 4 Dec 2026 18:54:39 +0900 Message-ID: <20261204100648.047908635@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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