From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796273908; b=4QD7GqPCi9a3bVf+dPyO6a7EAC1xSnM8r4CHGccTP/zNbYe3HT2Ln8Vtm/+NZdEBtq93 bzxFl6RfEWH8r87NM+yFn9L0AcLfLtvL3zttR8mMQqIURGjqD9c2CWTdwrpApF8gg4fR1 OYIpdmACiR1R/vbdf/lU/ugFu9VQNsZ1m7/fSs6+jWuArRxEZJ9dP+tzCyrTraHivrtz2 gk4CxWIfL1RVhgu4W9vYJuz9G9KULeLY5PEz1RW5LqM2WzS1kVP0WlTc/Ils1yiIcOalT EYOFJlCAdwVhi7JV4HCBb6G/Y0S95+G5xb7EDwO1HFDb+a2K+7KY9USsRz4QxX0nzMQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796273908; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=XtmDaMDcgxI+YUxCwjih+N0tkJAJu2ZUmshd3WK2qCU=; b=ICB7ry5/8rLfx3irlrsmA7xWi+jJIY47Y85xnCWzvu0QyzVkSBQUYj40+TC9tHjgQfLd 56yEm8gqz67G8s5nRi6SPiol8RlszUorW68mq5wnYSZP2zsWWQcj+4RiwjZGz1XUioYe8 AJtbnf+IM6yqjhR1zkaLWe33yjWIu4/OZj/fFjfgfp3tZAAwNADMY0NC+j79JBQO2hmrr GbG9L1eg6+vby1gkAHUBON/3kMVJGj78AZ2migd5Y4a6CuG9u0OJxA+axmNiPSslMJBbN S/DKmkTa1WtQRktF1rk6Lfs+1lX8OV4WjXs7n5kQFZ/WcDPHmREuR2o+1cnPUs4QAwg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=g5OYOT5U; arc=none smtp.remote-ip=198.175.65.11 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DA2E606A33A for ; Thu, 3 Dec 2026 04:58:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1DA2E606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=g5OYOT5U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796273909; x=1827809909; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=XtmDaMDcgxI+YUxCwjih+N0tkJAJu2ZUmshd3WK2qCU=; b=g5OYOT5UFSURr7YqiSiEgfB++V4oRhXhVJEFTFBFOIw0+Fwoky5ecLse SoY45AvWQav5RkEjHGkgaJgVxWtKjTuTouxEyufqsmpHLYWfvKEJ/T47h VBZupGqlF5Imfn3r6+odN92DI5t/KmYbUrCICybVZ8GV7kXXi1oPrTp9X T6cjaRtvvKZR29ET81wyHPtjrYpgG8P6ZIxtUtPZhdr3w1+05YkWsCnlp hTcvoxO+jSilSe4293IKvX/0RyJRNqoCi2J2DdVzURfqmLkNkh05K29gF 2hAqhVQwVouFJpQQVB0fxmBNEQIEe7Cri3pleRM6hSFVoFTCqTLugBGcG g==; X-CSE-ConnectionGUID: kfef62VHTdukY7ls5kAK5w== X-CSE-MsgGUID: Hd5XvY58SqKNRrYHsvVEsQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5115269" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5115269" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 20:58:27 -0800 X-CSE-ConnectionGUID: 1ZwZg9+SRveBv7ccp3gFBg== X-CSE-MsgGUID: xgy4BozFQnqzvGcVYwcZXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13534976" Received: from unknown (HELO [172.25.112.21]) ([172.25.112.21]) by orviesa004.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 20:58:27 -0800 From: Ricardo Neri Date: Wed, 02 Dec 2026 20:58:05 -0800 Subject: [PATCH v2 2/2] x86/cacheinfo: Use calc_cache_topo_id() in __cache_cpumap_setup() X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-rneri-x86-cacheinfoid-bug-v2-2-a00d768927f2@linux.intel.com> References: <20261202-rneri-x86-cacheinfoid-bug-v2-0-a00d768927f2@linux.intel.com> In-Reply-To: <20261202-rneri-x86-cacheinfoid-bug-v2-0-a00d768927f2@linux.intel.com> To: x86@kernel.org Cc: Reinette Chatre , Tony Luck , K Prateek Nayak , "Ahmed S. Darwish" , Len Brown , Javid Rzayev , Ricardo Neri , linux-kernel@vger.kernel.org, Ricardo Neri X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796273905; l=2717; i=ricardo.neri-calderon@linux.intel.com; s=20250602; h=from:subject:message-id; bh=dOX71fBC1Gg49/HPnbDHeAxciDr6ZF+pEv9pT3EOQc0=; b=IZ0TX6kBph7VJmZmVEZOistitBd2t1TJrrkhDLTCACgUrt/zd1WgGH4zc1A0BEx8h9mQfhGMy Z/44ItpM97fBvKVUZggVJakp5HCKmk3efU6kN6+qvBVz80KlAJQ1nnR X-Developer-Key: i=ricardo.neri-calderon@linux.intel.com; a=ed25519; pk=NfZw5SyQ2lxVfmNMaMR6KUj3+0OhcwDPyRzFDH9gY2w= __cache_cpumap_setup() open-codes a cache ID comparison: it right-shifts the APIC IDs of two CPUs by N and compares the results. N is the smallest integer such that 2^N is greater than or equal to the maximum number of addressable IDs for logical processors sharing the cache of the CPU being set up. calc_cache_topo_id() already computes the cache IDs exposed in sysfs on hybrid processors. Use calc_cache_topo_id() for that comparison as well, so that the file no longer open-codes a cache ID computation next to its two helpers. No functional change intended: both sides use the N of the CPU being set up. With the same N, masking and shifting select the same CPUs. A different N on other CPUs does not matter. The CPUs sharing a cache with the CPU being set up are those whose APIC IDs match its APIC ID in all but the N least-significant bits. Signed-off-by: Ricardo Neri --- Changes in v2: - Introduce this patch. --- arch/x86/kernel/cpu/cacheinfo.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c index 4d0f47e5f6c0..5e830ee44d13 100644 --- a/arch/x86/kernel/cpu/cacheinfo.c +++ b/arch/x86/kernel/cpu/cacheinfo.c @@ -551,7 +551,8 @@ static void __cache_cpumap_setup(unsigned int cpu, int index, struct cpuinfo_x86 *c = &cpu_data(cpu); struct cacheinfo *ci, *sibling_ci; unsigned long num_threads_sharing; - int index_msb, i; + unsigned int cache_id; + int i; if (c->x86_vendor == X86_VENDOR_AMD || c->x86_vendor == X86_VENDOR_HYGON) { if (__cache_amd_cpumap_setup(cpu, index, id4)) @@ -565,10 +566,15 @@ static void __cache_cpumap_setup(unsigned int cpu, int index, if (num_threads_sharing == 1) return; - index_msb = get_count_order(num_threads_sharing); + cache_id = calc_cache_topo_id(c, id4); - for_each_online_cpu(i) - if (cpu_data(i).topo.apicid >> index_msb == c->topo.apicid >> index_msb) { + for_each_online_cpu(i) { + /* + * Use @cpu's CPUID(0x4) data for CPU i too: CPU i shares this + * cache iff its APIC ID matches @cpu's in all bits above those + * reserved for the CPUs sharing the cache. + */ + if (cache_id == calc_cache_topo_id(&cpu_data(i), id4)) { struct cpu_cacheinfo *sib_cpu_ci = get_cpu_cacheinfo(i); /* Skip if itself or no cacheinfo */ @@ -579,6 +585,7 @@ static void __cache_cpumap_setup(unsigned int cpu, int index, cpumask_set_cpu(i, &ci->shared_cpu_map); cpumask_set_cpu(cpu, &sibling_ci->shared_cpu_map); } + } } static void ci_info_init(struct cacheinfo *ci, const struct _cpuid4_info *id4, -- 2.43.0