x86, CPU: TLB flushall shift, the AMD side
cover x86, CPU: TLB flushall shift, the AMD side
From: Borislav Petkov <[email protected]>
Hi all,
here's v1 with hpa's suggested changes.
Changelog:
* v0:
now that the Intel TLB subset flushing patches are in mainline, here's the AMD side of the deal.
Those have been tested on all our families with the mprotect microbenchmark. Any comments are appreciated.
Thanks.
PATCH 1/4 x86, CPU: Fixup tlb_flushall_shift formatting
From: Borislav Petkov <[email protected]>
The TLB characteristics appeared like this in dmesg:
[ 0.065817] Last level iTLB entries: 4KB 512, 2MB 1024, 4MB 512 [ 0.065817] Last level dTLB entries: 4KB 1024, 2MB 1024, 4MB 512 [ 0.065817] tlb_flushall_shift is 0xffffffff
where tlb_flushall_shift is actually -1 but dumped as a hex number. However, the Kconfig option CONFIG_DEBUG_TLBFLUSH and the rest of the code treats this as a signed decimal and states "If you set it to -1, the code flushes the whole TLB unconditionally."
So, fix its formatting in accordance with the other references to it.
--- arch/x86/kernel/cpu/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/cpu/common.c +1 -1
@@ -474,7 +474,7 @@ void __cpuinit cpu_detect_tlb(struct cpuinfo_x86 *c) printk(KERN_INFO "Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \ "Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \ - "tlb_flushall_shift is 0x%x\n", + "tlb_flushall_shift: %d\n", tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES], tlb_lli_4m[ENTRIES], tlb_lld_4k[ENTRIES], tlb_lld_2m[ENTRIES], tlb_lld_4m[ENTRIES],
Signature · 1 line
1.7.11.rc1
[tip:x86/mm] x86, cpu: Fixup tlb_flushall_shift formatting
Commit-ID: a9ad773e0dd833651f0831020a0ea0265c29f2ea Gitweb: http://git.kernel.org/tip/a9ad773e0dd833651f0831020a0ea0265c29f2ea Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Aug 2012 19:00:36 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 6 Aug 2012 19:18:09 -0700
x86, cpu: Fixup tlb_flushall_shift formatting
The TLB characteristics appeared like this in dmesg:
[ 0.065817] Last level iTLB entries: 4KB 512, 2MB 1024, 4MB 512 [ 0.065817] Last level dTLB entries: 4KB 1024, 2MB 1024, 4MB 512 [ 0.065817] tlb_flushall_shift is 0xffffffff
where tlb_flushall_shift is actually -1 but dumped as a hex number. However, the Kconfig option CONFIG_DEBUG_TLBFLUSH and the rest of the code treats this as a signed decimal and states "If you set it to -1, the code flushes the whole TLB unconditionally."
So, fix its formatting in accordance with the other references to it.
--- arch/x86/kernel/cpu/common.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/common.c +1 -1
@@ -474,7 +474,7 @@ void __cpuinit cpu_detect_tlb(struct cpuinfo_x86 *c) printk(KERN_INFO "Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \ "Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \ - "tlb_flushall_shift is 0x%x\n", + "tlb_flushall_shift: %d\n", tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES], tlb_lli_4m[ENTRIES], tlb_lld_4k[ENTRIES], tlb_lld_2m[ENTRIES], tlb_lld_4m[ENTRIES],
PATCH 2/4 x86, CPU: Push TLB detection CPUID check down
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Push the max CPUID leaf check into the ->detect_tlb function and remove general test case from the generic path.
--- arch/x86/kernel/cpu/common.c | 3 +-- arch/x86/kernel/cpu/intel.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/common.c +1 -2
@@ -940,8 +940,7 @@ void __init identify_boot_cpu(void)#else vgetcpu_set_mode ();#endif -if (boot_cpu_data.cpuid_level >=2 ) -cpu_detect_tlb (&boot_cpu_data); +cpu_detect_tlb (&boot_cpu_data); }void __cpuinit identify_secondary_cpu (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/intel.c +4 -0
@@ -648,6 +648,10 @@ static void __cpuinit intel_detect_tlb(struct cpuinfo_x86 *c)int i, j, n;unsigned int regs[4 ];unsigned char *desc = (unsigned char *)regs; + +if (c->cpuid_level <2 ) +return ; +/* Number of times to iterate */ n =cpuid_eax (2 ) &0xFF ;
Signature · 1 line
1.7.11.rc1
Re: [PATCH v1 2/4] x86, CPU: Push TLB detection CPUID check down
Quoted 6 lines · Borislav Petkov
From: Borislav Petkov <[email protected]>
Push the max CPUID leaf check into the ->detect_tlb function and remove general test case from the generic path.
Signed-off-by Borislav Petkov <[email protected]>
Quoted 34 lines
--- arch/x86/kernel/cpu/common.c | 3 +-- arch/x86/kernel/cpu/intel.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)arch/x86/kernel/cpu/common.c +1
-2@@ -940,8 +940,7 @@ void __init identify_boot_cpu(void)#else vgetcpu_set_mode ();#endif -if (boot_cpu_data.cpuid_level >=2 ) -cpu_detect_tlb (&boot_cpu_data); +cpu_detect_tlb (&boot_cpu_data); }void __cpuinit identify_secondary_cpu (struct cpuinfo_x86 *c)arch/x86/kernel/cpu/intel.c +4
-0@@ -648,6 +648,10 @@ static void __cpuinit intel_detect_tlb(struct cpuinfo_x86 *c)int i, j, n;unsigned int regs[4 ];unsigned char *desc = (unsigned char *)regs; + +if (c->cpuid_level <2 ) +return ; +/* Number of times to iterate */ n =cpuid_eax (2 ) &0xFF ;
[tip:x86/mm] x86, cpu: Push TLB detection CPUID check down
In reply to Borislav PetkovCommit-ID: 5b556332c3ab19e6375836d35ca658776e9ba0f6 Gitweb: http://git.kernel.org/tip/5b556332c3ab19e6375836d35ca658776e9ba0f6 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Aug 2012 19:00:37 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 6 Aug 2012 19:18:29 -0700
x86, cpu: Push TLB detection CPUID check down
Push the max CPUID leaf check into the ->detect_tlb function and remove general test case from the generic path.
--- arch/x86/kernel/cpu/common.c | 3 +-- arch/x86/kernel/cpu/intel.c | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/common.c +1 -2
@@ -940,8 +940,7 @@ void __init identify_boot_cpu(void)#else vgetcpu_set_mode ();#endif -if (boot_cpu_data.cpuid_level >=2 ) -cpu_detect_tlb (&boot_cpu_data); +cpu_detect_tlb (&boot_cpu_data); }void __cpuinit identify_secondary_cpu (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/intel.c +4 -0
@@ -648,6 +648,10 @@ static void __cpuinit intel_detect_tlb(struct cpuinfo_x86 *c)int i, j, n;unsigned int regs[4 ];unsigned char *desc = (unsigned char *)regs; + +if (c->cpuid_level <2 ) +return ; +/* Number of times to iterate */ n =cpuid_eax (2 ) &0xFF ;
PATCH 3/4 x86, CPU: Add AMD TLB size detection
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Read I- and DTLB entries count from CPUID on AMD. Handle all the different family-specific cases.
--- arch/x86/kernel/cpu/amd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
arch/x86/kernel/cpu/amd.c +54 -0
@@ -737,6 +737,59 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, }#endif +static void __cpuinit cpu_detect_tlb_amd (struct cpuinfo_x86 *c) +{ +u32 ebx, eax, ecx, edx; +u16 mask =0xfff ; + +if (c->x86 <0xf ) +return ; + +if (c->extended_cpuid_level <0x80000006 ) +return ; + +cpuid (0x80000006 , &eax, &ebx, &ecx, &edx); + + tlb_lld_4k[ENTRIES ] = (ebx >>16 ) & mask; + tlb_lli_4k[ENTRIES ] = ebx & mask; + +/* +* K8 doesn't have 2M/4M entries in the L2 TLB so read out the L1 TLB +* characteristics from the CPUID function 0x80000005 instead. +*/ +if (c->x86 ==0xf ) { +cpuid (0x80000005 , &eax, &ebx, &ecx, &edx); + mask =0xff ; + } + +/* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ +if (!((eax >>16 ) & mask)) { +u32 a, b, c, d; + +cpuid (0x80000005 , &a, &b, &c, &d); + tlb_lld_2m[ENTRIES ] = (a >>16 ) &0xff ; + }else { + tlb_lld_2m[ENTRIES ] = (eax >>16 ) & mask; + } + +/* a 4M entry uses two 2M entries */ + tlb_lld_4m[ENTRIES ] = tlb_lld_2m[ENTRIES ] >>1 ; + +/* Handle ITLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ +if (!(eax & mask)) { +/* Erratum 658 */ +if (c->x86 ==0x15 && c->x86_model <=0x1f ) { + tlb_lli_2m[ENTRIES ] =1024 ; + }else { +cpuid (0x80000005 , &eax, &ebx, &ecx, &edx); + tlb_lli_2m[ENTRIES ] = eax &0xff ; + } + }else + tlb_lli_2m[ENTRIES ] = eax & mask; + + tlb_lli_4m[ENTRIES ] = tlb_lli_2m[ENTRIES ] >>1 ; +} +static const struct cpu_dev __cpuinitconst amd_cpu_dev = { .c_vendor ="AMD" , .c_ident = {"AuthenticAMD" },
@@ -756,6 +809,7 @@ static const struct cpu_dev __cpuinitconst amd_cpu_dev = { .c_size_cache = amd_size_cache, #endif .c_early_init = early_init_amd, + .c_detect_tlb = cpu_detect_tlb_amd, .c_bsp_init = bsp_init_amd, .c_init = init_amd, .c_x86_vendor = X86_VENDOR_AMD,
Signature · 1 line
1.7.11.rc1
[tip:x86/mm] x86, cpu: Add AMD TLB size detection
Commit-ID: b46882e4c4de4813947fce940fe74af794a1eb72 Gitweb: http://git.kernel.org/tip/b46882e4c4de4813947fce940fe74af794a1eb72 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Aug 2012 19:00:38 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 6 Aug 2012 19:18:34 -0700
x86, cpu: Add AMD TLB size detection
Read I- and DTLB entries count from CPUID on AMD. Handle all the different family-specific cases.
--- arch/x86/kernel/cpu/amd.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/amd.c +54 -0
@@ -737,6 +737,59 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, }#endif +static void __cpuinit cpu_detect_tlb_amd (struct cpuinfo_x86 *c) +{ +u32 ebx, eax, ecx, edx; +u16 mask =0xfff ; + +if (c->x86 <0xf ) +return ; + +if (c->extended_cpuid_level <0x80000006 ) +return ; + +cpuid (0x80000006 , &eax, &ebx, &ecx, &edx); + + tlb_lld_4k[ENTRIES ] = (ebx >>16 ) & mask; + tlb_lli_4k[ENTRIES ] = ebx & mask; + +/* +* K8 doesn't have 2M/4M entries in the L2 TLB so read out the L1 TLB +* characteristics from the CPUID function 0x80000005 instead. +*/ +if (c->x86 ==0xf ) { +cpuid (0x80000005 , &eax, &ebx, &ecx, &edx); + mask =0xff ; + } + +/* Handle DTLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ +if (!((eax >>16 ) & mask)) { +u32 a, b, c, d; + +cpuid (0x80000005 , &a, &b, &c, &d); + tlb_lld_2m[ENTRIES ] = (a >>16 ) &0xff ; + }else { + tlb_lld_2m[ENTRIES ] = (eax >>16 ) & mask; + } + +/* a 4M entry uses two 2M entries */ + tlb_lld_4m[ENTRIES ] = tlb_lld_2m[ENTRIES ] >>1 ; + +/* Handle ITLB 2M and 4M sizes, fall back to L1 if L2 is disabled */ +if (!(eax & mask)) { +/* Erratum 658 */ +if (c->x86 ==0x15 && c->x86_model <=0x1f ) { + tlb_lli_2m[ENTRIES ] =1024 ; + }else { +cpuid (0x80000005 , &eax, &ebx, &ecx, &edx); + tlb_lli_2m[ENTRIES ] = eax &0xff ; + } + }else + tlb_lli_2m[ENTRIES ] = eax & mask; + + tlb_lli_4m[ENTRIES ] = tlb_lli_2m[ENTRIES ] >>1 ; +} +static const struct cpu_dev __cpuinitconst amd_cpu_dev = { .c_vendor ="AMD" , .c_ident = {"AuthenticAMD" },
@@ -756,6 +809,7 @@ static const struct cpu_dev __cpuinitconst amd_cpu_dev = { .c_size_cache = amd_size_cache, #endif .c_early_init = early_init_amd, + .c_detect_tlb = cpu_detect_tlb_amd, .c_bsp_init = bsp_init_amd, .c_init = init_amd, .c_x86_vendor = X86_VENDOR_AMD,
PATCH 4/4 x86, CPU: Preset default tlb_flushall_shift on AMD
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Run the mprotect.c microbenchmark on all our families >= K8 and preset the flushall shift variable accordingly.
--- arch/x86/kernel/cpu/amd.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/kernel/cpu/amd.c +13 -0
@@ -737,6 +737,17 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, }#endif +static void __cpuinit cpu_set_tlb_flushall_shift (struct cpuinfo_x86 *c) +{ +if (!cpu_has_invlpg) +return ; + + tlb_flushall_shift =5 ; + +if (c->x86 <=0x11 ) + tlb_flushall_shift =4 ; +} +static void __cpuinit cpu_detect_tlb_amd (struct cpuinfo_x86 *c) {u32 ebx, eax, ecx, edx;
@@ -788,6 +799,8 @@ static void __cpuinit cpu_detect_tlb_amd(struct cpuinfo_x86 *c) tlb_lli_2m[ENTRIES ] = eax & mask; tlb_lli_4m[ENTRIES ] = tlb_lli_2m[ENTRIES ] >>1 ; + +cpu_set_tlb_flushall_shift (c); }static const struct cpu_dev __cpuinitconst amd_cpu_dev = {
Signature · 1 line
1.7.11.rc1
[tip:x86/mm] x86, cpu: Preset default tlb_flushall_shift on AMD
Commit-ID: 057237bb35a605d795fd787868a1088705f26ee5 Gitweb: http://git.kernel.org/tip/057237bb35a605d795fd787868a1088705f26ee5 Author: Borislav Petkov <[email protected]> AuthorDate: Mon, 6 Aug 2012 19:00:39 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Mon, 6 Aug 2012 19:18:39 -0700
x86, cpu: Preset default tlb_flushall_shift on AMD
Run the mprotect.c microbenchmark on all our families >= K8 and preset the flushall shift variable accordingly.
--- arch/x86/kernel/cpu/amd.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/amd.c +13 -0
@@ -737,6 +737,17 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, }#endif +static void __cpuinit cpu_set_tlb_flushall_shift (struct cpuinfo_x86 *c) +{ +if (!cpu_has_invlpg) +return ; + + tlb_flushall_shift =5 ; + +if (c->x86 <=0x11 ) + tlb_flushall_shift =4 ; +} +static void __cpuinit cpu_detect_tlb_amd (struct cpuinfo_x86 *c) {u32 ebx, eax, ecx, edx;
@@ -788,6 +799,8 @@ static void __cpuinit cpu_detect_tlb_amd(struct cpuinfo_x86 *c) tlb_lli_2m[ENTRIES ] = eax & mask; tlb_lli_4m[ENTRIES ] = tlb_lli_2m[ENTRIES ] >>1 ; + +cpu_set_tlb_flushall_shift (c); }static const struct cpu_dev __cpuinitconst amd_cpu_dev = {