linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask
@ 2017-07-28  1:52 Suravee Suthikulpanit
  2017-07-30  3:48 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: Suravee Suthikulpanit @ 2017-07-28  1:52 UTC (permalink / raw)
  To: linux-kernel, x86; +Cc: tglx, mingo, hpa, bp, Suravee Suthikulpanit

For system with X86_FEATURE_TOPOEXT, current logic use APIC ID to
calculate shared_cpu_map. However, since APIC IDs are not guaranteed
to be contiguous for cores across different L3 (e.g. family17h system
w/ downcore configuration). This breaks the logic, and results in
incorrect L3 shared_cpu_map.

Instead, always use the previously calculated cpu_llc_shared_mask of
each cpu to derive L3 shared_cpu_map. This has been tested on
family15h and family17h systems, which has L3 and support
X86_FEATURE_TOPOEXT.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
---
 arch/x86/kernel/cpu/intel_cacheinfo.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index c55fb2c..24f74932 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -811,7 +811,24 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index,
 	struct cacheinfo *this_leaf;
 	int i, sibling;
 
-	if (boot_cpu_has(X86_FEATURE_TOPOEXT)) {
+	/*
+	 * For L3, always use the pre-calculated cpu_llc_shared_mask
+	 * to derive shared_cpu_map.
+	 */
+	if (index == 3) {
+		for_each_cpu(i, cpu_llc_shared_mask(cpu)) {
+			this_cpu_ci = get_cpu_cacheinfo(i);
+			if (!this_cpu_ci->info_list)
+				continue;
+			this_leaf = this_cpu_ci->info_list + index;
+			for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) {
+				if (!cpu_online(sibling))
+					continue;
+				cpumask_set_cpu(sibling,
+						&this_leaf->shared_cpu_map);
+			}
+		}
+	} else if (boot_cpu_has(X86_FEATURE_TOPOEXT)) {
 		unsigned int apicid, nshared, first, last;
 
 		this_leaf = this_cpu_ci->info_list + index;
@@ -839,19 +856,6 @@ static int __cache_amd_cpumap_setup(unsigned int cpu, int index,
 						&this_leaf->shared_cpu_map);
 			}
 		}
-	} else if (index == 3) {
-		for_each_cpu(i, cpu_llc_shared_mask(cpu)) {
-			this_cpu_ci = get_cpu_cacheinfo(i);
-			if (!this_cpu_ci->info_list)
-				continue;
-			this_leaf = this_cpu_ci->info_list + index;
-			for_each_cpu(sibling, cpu_llc_shared_mask(cpu)) {
-				if (!cpu_online(sibling))
-					continue;
-				cpumask_set_cpu(sibling,
-						&this_leaf->shared_cpu_map);
-			}
-		}
 	} else
 		return 0;
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] x86/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask
  2017-07-28  1:52 [PATCH v2] x86/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask Suravee Suthikulpanit
@ 2017-07-30  3:48 ` Borislav Petkov
  0 siblings, 0 replies; 2+ messages in thread
From: Borislav Petkov @ 2017-07-30  3:48 UTC (permalink / raw)
  To: Suravee Suthikulpanit; +Cc: linux-kernel, x86, tglx, mingo, hpa

On Thu, Jul 27, 2017 at 08:52:35PM -0500, Suravee Suthikulpanit wrote:
> For system with X86_FEATURE_TOPOEXT, current logic use APIC ID to
> calculate shared_cpu_map. However, since APIC IDs are not guaranteed
> to be contiguous for cores across different L3 (e.g. family17h system
> w/ downcore configuration). This breaks the logic, and results in
> incorrect L3 shared_cpu_map.
> 
> Instead, always use the previously calculated cpu_llc_shared_mask of
> each cpu to derive L3 shared_cpu_map. This has been tested on
> family15h and family17h systems, which has L3 and support
> X86_FEATURE_TOPOEXT.
> 
> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> ---
>  arch/x86/kernel/cpu/intel_cacheinfo.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)

Applied, thanks.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-30  3:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-28  1:52 [PATCH v2] x86/amd: Derive L3 shared_cpu_map from cpu_llc_shared_mask Suravee Suthikulpanit
2017-07-30  3:48 ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).