[PATCH] x86: cache_info: Fix setup of l2/l3 ids

From: Ido Yariv
Date: Fri Apr 06 2012 - 08:38:46 EST


From: Shai Fultheim <shai@xxxxxxxxxxx>

On some architectures (such as vSMP), it is possible to have CPUs with a
different number of cores sharing the same cache.

The current implementation implicitly assumes that all CPUs will have
the same number of cores sharing caches, and as a result, different CPUs
can end up with the same l2/l3 ids.

Fix this by masking out the shared cache bits, instead of shifting the
APICID. By doing so, it is guaranteed that the generated cache ids are
always unique.

Signed-off-by: Shai Fultheim <shai@xxxxxxxxxxx>
[ido@xxxxxxxxxx: rebased, simplified, and reworded the commit message]
Signed-off-by: Ido Yariv <ido@xxxxxxxxxx>
---
arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index 73d08ed..caa6cb0 100644
--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
@@ -615,14 +615,14 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
new_l2 = this_leaf.size/1024;
num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
index_msb = get_count_order(num_threads_sharing);
- l2_id = c->apicid >> index_msb;
+ l2_id = c->apicid & ~((1 << index_msb) - 1);
break;
case 3:
new_l3 = this_leaf.size/1024;
num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
index_msb = get_count_order(
num_threads_sharing);
- l3_id = c->apicid >> index_msb;
+ l3_id = c->apicid & ~((1 << index_msb) - 1);
break;
default:
break;
--
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/