x86, AMD: Correct F15h IC aliasing issue
Subsystems (4)
PATCH 2/3 x86: Add a BSP cpuinit helper
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
Add a function ptr to struct x86_cpuinit_ops which is destined to be run only once on the BSP during boot.
--- arch/x86/include/asm/x86_init.h | 1 + arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/x86_init.c | 1 + 3 files changed, 4 insertions(+), 0 deletions(-)
arch/x86/include/asm/x86_init.h +1 -0
@@ -147,6 +147,7 @@ struct x86_init_ops {*/ struct x86_cpuinit_ops {void (*setup_percpu_clockev)(void ); +void (*run_on_bsp)(void ); };/**
arch/x86/kernel/cpu/common.c +2 -0
@@ -681,6 +681,8 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c)filter_cpuid_features (c, false);setup_smep (c); + + x86_cpuinit.run_on_bsp (); }void __init early_cpu_init (void )
arch/x86/kernel/x86_init.c +1 -0
@@ -90,6 +90,7 @@ struct x86_init_ops x86_init __initdata = {struct x86_cpuinit_ops x86_cpuinit__cpuinitdata = { .setup_percpu_clockev = setup_secondary_APIC_clock, + .run_on_bsp = x86_init_noop, };static void default_nmi_init (void ) { };
Signature · 1 line
1.7.4.rc2
cover x86, AMD: Correct F15h IC aliasing issue
From: Borislav Petkov <[email protected]>
Hi,
here's an updated and revised patchset addressing all comments from last time:
* saturate bits [14:12] instead of clearing them
* calculate the mask from the CPUID 0x8000_0005 IC identifier instead of hardcoding it
Please take a look and apply, if no objections.
Thanks.
---
Changelog:
v2:
here's the second version of this patch which actually turned into a small patchset. As Ingo suggested, the initial patch stays first to ease backporting and the following 3 patches address (hopefully) all review comments from the initial submission. The patchset has been tested with Debian's old stable lenny (i.e. 5.0) distro in a 32-bit environment and all worked as expected.
Below some performance data to show that there is no noticeable performance degradation introduced by the changeset.
So please, do take a look again and let me know.
Thanks.
VA alignment enabled.
====================
Performance counter stats for './build.sh' (10 runs):
3187047.935990 task-clock # 24.001 CPUs utilized ( +- 1.37% )
510,888 context-switches # 0.000 M/sec ( +- 0.44% )
60,712 CPU-migrations # 0.000 M/sec ( +- 0.51% )
26,046,891 page-faults # 0.008 M/sec ( +- 0.00% )
1,841,068,123,735 cycles # 0.578 GHz ( +- 1.10% ) [63.39%]
560,044,437,348 stalled-cycles-frontend # 30.42% frontend cycles idle ( +- 1.13% ) [64.65%]
436,165,228,465 stalled-cycles-backend # 23.69% backend cycles idle ( +- 1.19% ) [67.21%]
1,461,854,088,667 instructions # 0.79 insns per cycle
# 0.38 stalled cycles per insn ( +- 0.77% ) [70.31%]
334,169,452,362 branches # 104.852 M/sec ( +- 1.20% ) [69.43%]
21,485,007,982 branch-misses # 6.43% of all branches ( +- 0.68% ) [65.01%]132.787483539 seconds time elapsed ( +- 1.37% )
VA alignment disabled
=====================
Performance counter stats for './build.sh' (10 runs):
3173688.887193 task-clock # 24.001 CPUs utilized ( +- 1.37% )
511,425 context-switches # 0.000 M/sec ( +- 0.28% )
60,522 CPU-migrations # 0.000 M/sec ( +- 0.60% )
26,046,902 page-faults # 0.008 M/sec ( +- 0.00% )
1,832,825,813,094 cycles # 0.578 GHz ( +- 0.96% ) [63.60%]
563,123,451,900 stalled-cycles-frontend # 30.72% frontend cycles idle ( +- 0.96% ) [63.97%]
439,565,070,106 stalled-cycles-backend # 23.98% backend cycles idle ( +- 1.23% ) [66.69%]
1,465,314,643,020 instructions # 0.80 insns per cycle
# 0.38 stalled cycles per insn ( +- 0.74% ) [70.11%]
332,416,669,982 branches # 104.741 M/sec ( +- 0.85% ) [69.71%]
21,181,821,204 branch-misses # 6.37% of all branches ( +- 0.97% ) [65.93%]132.230903628 seconds time elapsed ( +- 1.37% )
stock 3.0
=========
Performance counter stats for './build.sh' (10 runs):
3369707.240439 task-clock # 24.001 CPUs utilized ( +- 1.18% )
510,450 context-switches # 0.000 M/sec ( +- 0.29% )
58,906 CPU-migrations # 0.000 M/sec ( +- 0.35% )
26,057,272 page-faults # 0.008 M/sec ( +- 0.00% )
1,836,326,075,063 cycles # 0.545 GHz ( +- 1.05% ) [63.51%]
561,850,647,545 stalled-cycles-frontend # 30.60% frontend cycles idle ( +- 1.03% ) [64.17%]
439,923,021,200 stalled-cycles-backend # 23.96% backend cycles idle ( +- 1.10% ) [66.64%]
1,467,236,934,265 instructions # 0.80 insns per cycle
# 0.38 stalled cycles per insn ( +- 0.87% ) [70.06%]
331,937,054,120 branches # 98.506 M/sec ( +- 0.81% ) [69.83%]
21,228,553,080 branch-misses # 6.40% of all branches ( +- 0.87% ) [65.79%]140.398317711 seconds time elapsed ( +- 1.18% )
PATCH 3/3 x86, AMD: Move BSP code to cpuinit helper
From: Borislav Petkov <[email protected]>
Move code which is run once on the BSP during boot into the cpuinit helper.
--- arch/x86/kernel/cpu/amd.c | 55 +++++++++++++++++++++++--------------------- 1 files changed, 29 insertions(+), 26 deletions(-)
arch/x86/kernel/cpu/amd.c +29 -26
@@ -410,6 +410,34 @@ static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)#endif } +static void __cpuinit amd_run_on_bsp (void ) +{ +struct cpuinfo_x86 *c = &boot_cpu_data; + +if (static_cpu_has (X86_FEATURE_CONSTANT_TSC )) { + +if (c->x86 >0x10 || + (c->x86 ==0x10 && c->x86_model >=0x2 )) { +u64 val; + +rdmsrl (MSR_K7_HWCR , val); +if (!(val &BIT (24 ))) + printk(KERN_WARNING FW_BUG "TSC doesn't count " +"with P0 frequency!\n" ); + } + } + +if (c->x86 ==0x15 ) { +u32 cpuid, assoc; + + cpuid =cpuid_edx (0x80000005 ); + assoc = cpuid >>16 &0xff ; + + align_upperbit = ((cpuid >>24 ) <<10 ) / assoc; + align_va_addr =ALIGN_VA_32 |ALIGN_VA_64 ; + } +} +static void __cpuinit early_init_amd (struct cpuinfo_x86 *c) {early_init_amd_mc (c);
@@ -442,32 +470,7 @@ static void __cpuinit early_init_amd(struct cpuinfo_x86 *c) }#endif -/* We need to do the following only once */ -if (c != &boot_cpu_data) -return ; - -if (cpu_has (c,X86_FEATURE_CONSTANT_TSC )) { - -if (c->x86 >0x10 || - (c->x86 ==0x10 && c->x86_model >=0x2 )) { -u64 val; - -rdmsrl (MSR_K7_HWCR , val); -if (!(val &BIT (24 ))) - printk(KERN_WARNING FW_BUG "TSC doesn't count " -"with P0 frequency!\n" ); - } - } - -if (c->x86 ==0x15 ) { -u32 cpuid, assoc; - - cpuid =cpuid_edx (0x80000005 ); - assoc = cpuid >>16 &0xff ; - - align_upperbit = ((cpuid >>24 ) <<10 ) / assoc; - align_va_addr =ALIGN_VA_32 |ALIGN_VA_64 ; - } + x86_cpuinit.run_on_bsp = amd_run_on_bsp; }static void __cpuinit init_amd (struct cpuinfo_x86 *c)
Signature · 1 line
1.7.4.rc2
PATCH 1/3 x86, AMD: Correct F15h IC aliasing issue
In reply to Borislav PetkovFrom: Borislav Petkov <[email protected]>
This patch provides performance tuning for the "Bulldozer" CPU. With its shared instruction cache there is a chance of generating an excessive number of cache cross-invalidates when running specific workloads on the cores of a compute module.
This excessive amount of cross-invalidations can be observed if cache lines backed by shared physical memory alias in bits [14:12] of their virtual addresses, as those bits are used for the index generation.
This patch addresses the issue by setting all the bits in the [14:12] slice of the file mapping's virtual address at generation time, thus forcing those bits the same for all mappings of a single shared library across processes and, in doing so, avoids instruction cache aliases.
It also adds the command line option "align_va_addr=(32|64|on|off)" with which virtual address alignment can be enabled for 32-bit or 64-bit x86 individually, or both, or be completely disabled.
This change leaves virtual region address allocation on other families and/or vendors unaffected.
--- Documentation/kernel-parameters.txt | 13 ++++++ arch/x86/include/asm/elf.h | 27 ++++++++++++ arch/x86/kernel/cpu/amd.c | 10 ++++ arch/x86/kernel/sys_x86_64.c | 79 +++++++++++++++++++++++++++++++++- arch/x86/mm/mmap.c | 15 ------- arch/x86/vdso/vma.c | 9 ++++ 6 files changed, 135 insertions(+), 18 deletions(-)
Documentation/kernel-parameters.txt +13 -0
@@ -299,6 +299,19 @@ bytes respectively. Such letter suffixes can also be entirely omitted. behaviour to be specified. Bit 0 enables warnings, bit 1 enables fixups, and bit 2 sends a segfault. + align_va_addr= [X86-64] + Align virtual addresses by clearing slice [14:12] when + allocating a VMA at process creation time. This option + gives you up to 3% performance improvement on AMD F15h + machines (where it is enabled by default) for a + CPU-intensive style benchmark, and it can vary highly in + a microbenchmark depending on workload and compiler. + + 1: only for 32-bit processes + 2: only for 64-bit processes + on: enable for both 32- and 64-bit processes + off: disable for both 32- and 64-bit processes + amd_iommu= [HW,X86-84] Pass parameters to the AMD IOMMU driver in the system. Possible values are:
arch/x86/include/asm/elf.h +27 -0
@@ -4,6 +4,7 @@/* * ELF register definitions.. */ +#include <linux/thread_info.h> #include <asm/ptrace.h> #include <asm/user.h>
@@ -320,4 +321,30 @@ extern int syscall32_setup_pages(struct linux_binprm *, int exstack);extern unsigned long arch_randomize_brk (struct mm_struct *mm);#define arch_randomize_brk arch_randomize_brk +/* +* True on X86_32 or when emulating IA32 on X86_64 +*/ +static inline int mmap_is_ia32 (void ) +{ +#ifdef CONFIG_X86_32 +return 1 ; +#endif +#ifdef CONFIG_IA32_EMULATION +if (test_thread_flag (TIF_IA32 )) +return 1 ; +#endif +return 0 ; +} + +/* The first two values are special, do not change. See align_addr() */ +enum align_flags { +ALIGN_VA_32 =BIT (0 ), +ALIGN_VA_64 =BIT (1 ), +ALIGN_VDSO =BIT (2 ), +ALIGN_TOPDOWN =BIT (3 ), +}; + +extern int align_va_addr; +extern unsigned long align_upperbit; +extern unsigned long align_addr (unsigned long ,struct file *,enum align_flags );#endif /* _ASM_X86_ELF_H */
arch/x86/kernel/cpu/amd.c +10 -0
@@ -458,6 +458,16 @@ static void __cpuinit early_init_amd(struct cpuinfo_x86 *c) "with P0 frequency!\n"); } } + +if (c->x86 ==0x15 ) { +u32 cpuid, assoc; + + cpuid =cpuid_edx (0x80000005 ); + assoc = cpuid >>16 &0xff ; + + align_upperbit = ((cpuid >>24 ) <<10 ) / assoc; + align_va_addr =ALIGN_VA_32 |ALIGN_VA_64 ; + } }static void __cpuinit init_amd (struct cpuinfo_x86 *c)
arch/x86/kernel/sys_x86_64.c +76 -3
110 lines not on this page · raw message
arch/x86/mm/mmap.c +0 -15
@@ -51,21 +51,6 @@ static unsigned int stack_maxrandom_size(void)#define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())#define MAX_GAP (TASK_SIZE/6*5) -/* -* True on X86_32 or when emulating IA32 on X86_64 -*/ -static int mmap_is_ia32 (void ) -{ -#ifdef CONFIG_X86_32 -return 1 ; -#endif -#ifdef CONFIG_IA32_EMULATION -if (test_thread_flag (TIF_IA32 )) -return 1 ; -#endif -return 0 ; -} -static int mmap_is_legacy (void ) {if (current->personality &ADDR_COMPAT_LAYOUT )
arch/x86/vdso/vma.c +9 -0
@@ -69,6 +69,15 @@ static unsigned long vdso_addr(unsigned long start, unsigned len) addr = start + (offset <<PAGE_SHIFT );if (addr >= end) addr = end; + +/* +* page-align it here so that get_unmapped_area doesn't +* align it wrongfully again to the next page. addr can come in 4K +* unaligned here as a result of stack start randomization. +*/ + addr =PAGE_ALIGN (addr); + addr =align_addr (addr,NULL ,ALIGN_VDSO ); +return addr; }
Signature · 1 line
1.7.4.rc2