Skip to content

Commit 58f02db

Browse files
committed
Merge branch 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'x86-cpu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: x86, cacheinfo: Enable L3 CID only on AMD x86, cacheinfo: Remove NUMA dependency, fix for AMD Fam10h rev D1 x86, cpu: Print AMD virtualization features in /proc/cpuinfo x86, cacheinfo: Calculate L3 indices x86, cacheinfo: Add cache index disable sysfs attrs only to L3 caches x86, cacheinfo: Fix disabling of L3 cache indices intel-agp: Switch to wbinvd_on_all_cpus x86, lib: Add wbinvd smp helpers
2 parents 43a834d + cb19060 commit 58f02db

7 files changed

Lines changed: 197 additions & 106 deletions

File tree

‎arch/x86/include/asm/cpufeature.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
#define X86_FEATURE_FLEXPRIORITY (8*32+ 2) /* Intel FlexPriority */
169169
#define X86_FEATURE_EPT (8*32+ 3) /* Intel Extended Page Table */
170170
#define X86_FEATURE_VPID (8*32+ 4) /* Intel Virtual Processor ID */
171+
#define X86_FEATURE_NPT (8*32+5) /* AMD Nested Page Table support */
172+
#define X86_FEATURE_LBRV (8*32+6) /* AMD LBR Virtualization support */
173+
#define X86_FEATURE_SVML (8*32+7) /* "svm_lock" AMD SVM locking MSR */
174+
#define X86_FEATURE_NRIPS (8*32+8) /* "nrip_save" AMD SVM next_rip save */
171175

172176
#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
173177

‎arch/x86/include/asm/smp.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ int native_cpu_disable(void);
135135
void native_cpu_die(unsigned int cpu);
136136
void native_play_dead(void);
137137
void play_dead_common(void);
138+
void wbinvd_on_cpu(int cpu);
139+
int wbinvd_on_all_cpus(void);
138140

139141
void native_send_call_func_ipi(const struct cpumask *mask);
140142
void native_send_call_func_single_ipi(int cpu);
@@ -147,6 +149,13 @@ static inline int num_booting_cpus(void)
147149
{
148150
return cpumask_weight(cpu_callout_mask);
149151
}
152+
#else /* !CONFIG_SMP */
153+
#define wbinvd_on_cpu(cpu) wbinvd()
154+
static inline int wbinvd_on_all_cpus(void)
155+
{
156+
wbinvd();
157+
return 0;
158+
}
150159
#endif /* CONFIG_SMP */
151160

152161
extern unsigned disabled_cpus __cpuinitdata;

‎arch/x86/kernel/cpu/addon_cpuid_features.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
3232
static const struct cpuid_bit __cpuinitconst cpuid_bits[] = {
3333
{ X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 },
3434
{ X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 },
35+
{ X86_FEATURE_NPT, CR_EDX, 0, 0x8000000a },
36+
{ X86_FEATURE_LBRV, CR_EDX, 1, 0x8000000a },
37+
{ X86_FEATURE_SVML, CR_EDX, 2, 0x8000000a },
38+
{ X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a },
3539
{ 0, 0, 0, 0 }
3640
};
3741

‎arch/x86/kernel/cpu/intel_cacheinfo.c‎

Lines changed: 156 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <asm/processor.h>
1919
#include <linux/smp.h>
2020
#include <asm/k8.h>
21+
#include <asm/smp.h>
2122

2223
#define LVL_1_INST 1
2324
#define LVL_1_DATA 2
@@ -152,7 +153,8 @@ struct _cpuid4_info {
152153
union _cpuid4_leaf_ebx ebx;
153154
union _cpuid4_leaf_ecx ecx;
154155
unsigned long size;
155-
unsigned long can_disable;
156+
bool can_disable;
157+
unsigned int l3_indices;
156158
DECLARE_BITMAP(shared_cpu_map, NR_CPUS);
157159
};
158160

@@ -162,7 +164,8 @@ struct _cpuid4_info_regs {
162164
union _cpuid4_leaf_ebx ebx;
163165
union _cpuid4_leaf_ecx ecx;
164166
unsigned long size;
165-
unsigned long can_disable;
167+
bool can_disable;
168+
unsigned int l3_indices;
166169
};
167170

168171
unsigned short num_cache_leaves;
@@ -292,6 +295,36 @@ amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax,
292295
(ebx->split.ways_of_associativity + 1) - 1;
293296
}
294297

298+
struct _cache_attr {
299+
struct attribute attr;
300+
ssize_t (*show)(struct _cpuid4_info *, char *);
301+
ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
302+
};
303+
304+
#ifdef CONFIG_CPU_SUP_AMD
305+
static unsigned int __cpuinit amd_calc_l3_indices(void)
306+
{
307+
/*
308+
* We're called over smp_call_function_single() and therefore
309+
* are on the correct cpu.
310+
*/
311+
int cpu = smp_processor_id();
312+
int node = cpu_to_node(cpu);
313+
struct pci_dev *dev = node_to_k8_nb_misc(node);
314+
unsigned int sc0, sc1, sc2, sc3;
315+
u32 val = 0;
316+
317+
pci_read_config_dword(dev, 0x1C4, &val);
318+
319+
/* calculate subcache sizes */
320+
sc0 = !(val & BIT(0));
321+
sc1 = !(val & BIT(4));
322+
sc2 = !(val & BIT(8)) + !(val & BIT(9));
323+
sc3 = !(val & BIT(12)) + !(val & BIT(13));
324+
325+
return (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
326+
}
327+
295328
static void __cpuinit
296329
amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
297330
{
@@ -301,12 +334,103 @@ amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
301334
if (boot_cpu_data.x86 == 0x11)
302335
return;
303336

304-
/* see erratum #382 */
305-
if ((boot_cpu_data.x86 == 0x10) && (boot_cpu_data.x86_model < 0x8))
337+
/* see errata #382 and #388 */
338+
if ((boot_cpu_data.x86 == 0x10) &&
339+
((boot_cpu_data.x86_model < 0x8) ||
340+
(boot_cpu_data.x86_mask < 0x1)))
306341
return;
307342

308-
this_leaf->can_disable = 1;
343+
this_leaf->can_disable = true;
344+
this_leaf->l3_indices = amd_calc_l3_indices();
345+
}
346+
347+
static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
348+
unsigned int index)
349+
{
350+
int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
351+
int node = amd_get_nb_id(cpu);
352+
struct pci_dev *dev = node_to_k8_nb_misc(node);
353+
unsigned int reg = 0;
354+
355+
if (!this_leaf->can_disable)
356+
return -EINVAL;
357+
358+
if (!dev)
359+
return -EINVAL;
360+
361+
pci_read_config_dword(dev, 0x1BC + index * 4, &reg);
362+
return sprintf(buf, "0x%08x\n", reg);
363+
}
364+
365+
#define SHOW_CACHE_DISABLE(index) \
366+
static ssize_t \
367+
show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \
368+
{ \
369+
return show_cache_disable(this_leaf, buf, index); \
370+
}
371+
SHOW_CACHE_DISABLE(0)
372+
SHOW_CACHE_DISABLE(1)
373+
374+
static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
375+
const char *buf, size_t count, unsigned int index)
376+
{
377+
int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
378+
int node = amd_get_nb_id(cpu);
379+
struct pci_dev *dev = node_to_k8_nb_misc(node);
380+
unsigned long val = 0;
381+
382+
#define SUBCACHE_MASK (3UL << 20)
383+
#define SUBCACHE_INDEX 0xfff
384+
385+
if (!this_leaf->can_disable)
386+
return -EINVAL;
387+
388+
if (!capable(CAP_SYS_ADMIN))
389+
return -EPERM;
390+
391+
if (!dev)
392+
return -EINVAL;
393+
394+
if (strict_strtoul(buf, 10, &val) < 0)
395+
return -EINVAL;
396+
397+
/* do not allow writes outside of allowed bits */
398+
if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) ||
399+
((val & SUBCACHE_INDEX) > this_leaf->l3_indices))
400+
return -EINVAL;
401+
402+
val |= BIT(30);
403+
pci_write_config_dword(dev, 0x1BC + index * 4, val);
404+
/*
405+
* We need to WBINVD on a core on the node containing the L3 cache which
406+
* indices we disable therefore a simple wbinvd() is not sufficient.
407+
*/
408+
wbinvd_on_cpu(cpu);
409+
pci_write_config_dword(dev, 0x1BC + index * 4, val | BIT(31));
410+
return count;
411+
}
412+
413+
#define STORE_CACHE_DISABLE(index) \
414+
static ssize_t \
415+
store_cache_disable_##index(struct _cpuid4_info *this_leaf, \
416+
const char *buf, size_t count) \
417+
{ \
418+
return store_cache_disable(this_leaf, buf, count, index); \
309419
}
420+
STORE_CACHE_DISABLE(0)
421+
STORE_CACHE_DISABLE(1)
422+
423+
static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644,
424+
show_cache_disable_0, store_cache_disable_0);
425+
static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644,
426+
show_cache_disable_1, store_cache_disable_1);
427+
428+
#else /* CONFIG_CPU_SUP_AMD */
429+
static void __cpuinit
430+
amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
431+
{
432+
};
433+
#endif /* CONFIG_CPU_SUP_AMD */
310434

311435
static int
312436
__cpuinit cpuid4_cache_lookup_regs(int index,
@@ -713,82 +837,6 @@ static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf)
713837
#define to_object(k) container_of(k, struct _index_kobject, kobj)
714838
#define to_attr(a) container_of(a, struct _cache_attr, attr)
715839

716-
static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
717-
unsigned int index)
718-
{
719-
int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
720-
int node = cpu_to_node(cpu);
721-
struct pci_dev *dev = node_to_k8_nb_misc(node);
722-
unsigned int reg = 0;
723-
724-
if (!this_leaf->can_disable)
725-
return -EINVAL;
726-
727-
if (!dev)
728-
return -EINVAL;
729-
730-
pci_read_config_dword(dev, 0x1BC + index * 4, &reg);
731-
return sprintf(buf, "%x\n", reg);
732-
}
733-
734-
#define SHOW_CACHE_DISABLE(index) \
735-
static ssize_t \
736-
show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf) \
737-
{ \
738-
return show_cache_disable(this_leaf, buf, index); \
739-
}
740-
SHOW_CACHE_DISABLE(0)
741-
SHOW_CACHE_DISABLE(1)
742-
743-
static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
744-
const char *buf, size_t count, unsigned int index)
745-
{
746-
int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
747-
int node = cpu_to_node(cpu);
748-
struct pci_dev *dev = node_to_k8_nb_misc(node);
749-
unsigned long val = 0;
750-
unsigned int scrubber = 0;
751-
752-
if (!this_leaf->can_disable)
753-
return -EINVAL;
754-
755-
if (!capable(CAP_SYS_ADMIN))
756-
return -EPERM;
757-
758-
if (!dev)
759-
return -EINVAL;
760-
761-
if (strict_strtoul(buf, 10, &val) < 0)
762-
return -EINVAL;
763-
764-
val |= 0xc0000000;
765-
766-
pci_read_config_dword(dev, 0x58, &scrubber);
767-
scrubber &= ~0x1f000000;
768-
pci_write_config_dword(dev, 0x58, scrubber);
769-
770-
pci_write_config_dword(dev, 0x1BC + index * 4, val & ~0x40000000);
771-
wbinvd();
772-
pci_write_config_dword(dev, 0x1BC + index * 4, val);
773-
return count;
774-
}
775-
776-
#define STORE_CACHE_DISABLE(index) \
777-
static ssize_t \
778-
store_cache_disable_##index(struct _cpuid4_info *this_leaf, \
779-
const char *buf, size_t count) \
780-
{ \
781-
return store_cache_disable(this_leaf, buf, count, index); \
782-
}
783-
STORE_CACHE_DISABLE(0)
784-
STORE_CACHE_DISABLE(1)
785-
786-
struct _cache_attr {
787-
struct attribute attr;
788-
ssize_t (*show)(struct _cpuid4_info *, char *);
789-
ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
790-
};
791-
792840
#define define_one_ro(_name) \
793841
static struct _cache_attr _name = \
794842
__ATTR(_name, 0444, show_##_name, NULL)
@@ -803,23 +851,28 @@ define_one_ro(size);
803851
define_one_ro(shared_cpu_map);
804852
define_one_ro(shared_cpu_list);
805853

806-
static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644,
807-
show_cache_disable_0, store_cache_disable_0);
808-
static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644,
809-
show_cache_disable_1, store_cache_disable_1);
854+
#define DEFAULT_SYSFS_CACHE_ATTRS \
855+
&type.attr, \
856+
&level.attr, \
857+
&coherency_line_size.attr, \
858+
&physical_line_partition.attr, \
859+
&ways_of_associativity.attr, \
860+
&number_of_sets.attr, \
861+
&size.attr, \
862+
&shared_cpu_map.attr, \
863+
&shared_cpu_list.attr
810864

811865
static struct attribute *default_attrs[] = {
812-
&type.attr,
813-
&level.attr,
814-
&coherency_line_size.attr,
815-
&physical_line_partition.attr,
816-
&ways_of_associativity.attr,
817-
&number_of_sets.attr,
818-
&size.attr,
819-
&shared_cpu_map.attr,
820-
&shared_cpu_list.attr,
866+
DEFAULT_SYSFS_CACHE_ATTRS,
867+
NULL
868+
};
869+
870+
static struct attribute *default_l3_attrs[] = {
871+
DEFAULT_SYSFS_CACHE_ATTRS,
872+
#ifdef CONFIG_CPU_SUP_AMD
821873
&cache_disable_0.attr,
822874
&cache_disable_1.attr,
875+
#endif
823876
NULL
824877
};
825878

@@ -910,6 +963,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
910963
unsigned int cpu = sys_dev->id;
911964
unsigned long i, j;
912965
struct _index_kobject *this_object;
966+
struct _cpuid4_info *this_leaf;
913967
int retval;
914968

915969
retval = cpuid4_cache_sysfs_init(cpu);
@@ -928,6 +982,14 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
928982
this_object = INDEX_KOBJECT_PTR(cpu, i);
929983
this_object->cpu = cpu;
930984
this_object->index = i;
985+
986+
this_leaf = CPUID4_INFO_IDX(cpu, i);
987+
988+
if (this_leaf->can_disable)
989+
ktype_cache.default_attrs = default_l3_attrs;
990+
else
991+
ktype_cache.default_attrs = default_attrs;
992+
931993
retval = kobject_init_and_add(&(this_object->kobj),
932994
&ktype_cache,
933995
per_cpu(ici_cache_kobject, cpu),

‎arch/x86/lib/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $(obj)/inat.o: $(obj)/inat-tables.c
1414

1515
clean-files := inat-tables.c
1616

17-
obj-$(CONFIG_SMP) += msr-smp.o
17+
obj-$(CONFIG_SMP) += msr-smp.o cache-smp.o
1818

1919
lib-y := delay.o
2020
lib-y += thunk_$(BITS).o

‎arch/x86/lib/cache-smp.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <linux/smp.h>
2+
#include <linux/module.h>
3+
4+
static void __wbinvd(void *dummy)
5+
{
6+
wbinvd();
7+
}
8+
9+
void wbinvd_on_cpu(int cpu)
10+
{
11+
smp_call_function_single(cpu, __wbinvd, NULL, 1);
12+
}
13+
EXPORT_SYMBOL(wbinvd_on_cpu);
14+
15+
int wbinvd_on_all_cpus(void)
16+
{
17+
return on_each_cpu(__wbinvd, NULL, 1);
18+
}
19+
EXPORT_SYMBOL(wbinvd_on_all_cpus);

0 commit comments

Comments
 (0)