aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Molnar <mingo@kernel.org>2016-04-13 05:36:44 -0400
committerIngo Molnar <mingo@kernel.org>2016-04-13 05:36:44 -0400
commit95a8e746f82bdda5d8a443b6557c930782d65b86 (patch)
tree6047fecc66e133c10d04be7b0bec89069c3e1654
parentd8d1c35139481ee8e292d91cd3fd35a6b3a316eb (diff)
parenta3125494cff084b098c80bb36fbe2061ffed9d52 (diff)
Merge branch 'x86/urgent' into x86/asm to pick up dependent fixes
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--Documentation/x86/protection-keys.txt27
-rw-r--r--Documentation/x86/topology.txt208
-rw-r--r--arch/x86/boot/compressed/Makefile14
-rw-r--r--arch/x86/boot/compressed/head_32.S28
-rw-r--r--arch/x86/boot/compressed/head_64.S8
-rw-r--r--arch/x86/events/amd/core.c21
-rw-r--r--arch/x86/events/perf_event.h5
-rw-r--r--arch/x86/include/asm/msr-index.h8
-rw-r--r--arch/x86/include/asm/processor.h2
-rw-r--r--arch/x86/include/asm/smp.h1
-rw-r--r--arch/x86/include/asm/thread_info.h6
-rw-r--r--arch/x86/kernel/amd_nb.c6
-rw-r--r--arch/x86/kernel/cpu/amd.c12
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce-genpool.c4
-rw-r--r--arch/x86/kernel/cpu/powerflags.c2
-rw-r--r--arch/x86/kernel/smpboot.c2
-rw-r--r--arch/x86/ras/mce_amd_inj.c3
-rw-r--r--drivers/lguest/interrupts_and_traps.c6
-rw-r--r--drivers/lguest/lg.h1
-rw-r--r--drivers/lguest/x86/core.c6
20 files changed, 335 insertions, 35 deletions
diff --git a/Documentation/x86/protection-keys.txt b/Documentation/x86/protection-keys.txt
new file mode 100644
index 000000000000..c281ded1ba16
--- /dev/null
+++ b/Documentation/x86/protection-keys.txt
@@ -0,0 +1,27 @@
1Memory Protection Keys for Userspace (PKU aka PKEYs) is a CPU feature
2which will be found on future Intel CPUs.
3
4Memory Protection Keys provides a mechanism for enforcing page-based
5protections, but without requiring modification of the page tables
6when an application changes protection domains. It works by
7dedicating 4 previously ignored bits in each page table entry to a
8"protection key", giving 16 possible keys.
9
10There is also a new user-accessible register (PKRU) with two separate
11bits (Access Disable and Write Disable) for each key. Being a CPU
12register, PKRU is inherently thread-local, potentially giving each
13thread a different set of protections from every other thread.
14
15There are two new instructions (RDPKRU/WRPKRU) for reading and writing
16to the new register. The feature is only available in 64-bit mode,
17even though there is theoretically space in the PAE PTEs. These
18permissions are enforced on data access only and have no effect on
19instruction fetches.
20
21=========================== Config Option ===========================
22
23This config option adds approximately 1.5kb of text. and 50 bytes of
24data to the executable. A workload which does large O_DIRECT reads
25of holes in XFS files was run to exercise get_user_pages_fast(). No
26performance delta was observed with the config option
27enabled or disabled.
diff --git a/Documentation/x86/topology.txt b/Documentation/x86/topology.txt
new file mode 100644
index 000000000000..06afac252f5b
--- /dev/null
+++ b/Documentation/x86/topology.txt
@@ -0,0 +1,208 @@
1x86 Topology
2============
3
4This documents and clarifies the main aspects of x86 topology modelling and
5representation in the kernel. Update/change when doing changes to the
6respective code.
7
8The architecture-agnostic topology definitions are in
9Documentation/cputopology.txt. This file holds x86-specific
10differences/specialities which must not necessarily apply to the generic
11definitions. Thus, the way to read up on Linux topology on x86 is to start
12with the generic one and look at this one in parallel for the x86 specifics.
13
14Needless to say, code should use the generic functions - this file is *only*
15here to *document* the inner workings of x86 topology.
16
17Started by Thomas Gleixner <tglx@linutronix.de> and Borislav Petkov <bp@alien8.de>.
18
19The main aim of the topology facilities is to present adequate interfaces to
20code which needs to know/query/use the structure of the running system wrt
21threads, cores, packages, etc.
22
23The kernel does not care about the concept of physical sockets because a
24socket has no relevance to software. It's an electromechanical component. In
25the past a socket always contained a single package (see below), but with the
26advent of Multi Chip Modules (MCM) a socket can hold more than one package. So
27there might be still references to sockets in the code, but they are of
28historical nature and should be cleaned up.
29
30The topology of a system is described in the units of:
31
32 - packages
33 - cores
34 - threads
35
36* Package:
37
38 Packages contain a number of cores plus shared resources, e.g. DRAM
39 controller, shared caches etc.
40
41 AMD nomenclature for package is 'Node'.
42
43 Package-related topology information in the kernel:
44
45 - cpuinfo_x86.x86_max_cores:
46
47 The number of cores in a package. This information is retrieved via CPUID.
48
49 - cpuinfo_x86.phys_proc_id:
50
51 The physical ID of the package. This information is retrieved via CPUID
52 and deduced from the APIC IDs of the cores in the package.
53
54 - cpuinfo_x86.logical_id:
55
56 The logical ID of the package. As we do not trust BIOSes to enumerate the
57 packages in a consistent way, we introduced the concept of logical package
58 ID so we can sanely calculate the number of maximum possible packages in
59 the system and have the packages enumerated linearly.
60
61 - topology_max_packages():
62
63 The maximum possible number of packages in the system. Helpful for per
64 package facilities to preallocate per package information.
65
66
67* Cores:
68
69 A core consists of 1 or more threads. It does not matter whether the threads
70 are SMT- or CMT-type threads.
71
72 AMDs nomenclature for a CMT core is "Compute Unit". The kernel always uses
73 "core".
74
75 Core-related topology information in the kernel:
76
77 - smp_num_siblings:
78
79 The number of threads in a core. The number of threads in a package can be
80 calculated by:
81
82 threads_per_package = cpuinfo_x86.x86_max_cores * smp_num_siblings
83
84
85* Threads:
86
87 A thread is a single scheduling unit. It's the equivalent to a logical Linux
88 CPU.
89
90 AMDs nomenclature for CMT threads is "Compute Unit Core". The kernel always
91 uses "thread".
92
93 Thread-related topology information in the kernel:
94
95 - topology_core_cpumask():
96
97 The cpumask contains all online threads in the package to which a thread
98 belongs.
99
100 The number of online threads is also printed in /proc/cpuinfo "siblings."
101
102 - topology_sibling_mask():
103
104 The cpumask contains all online threads in the core to which a thread
105 belongs.
106
107 - topology_logical_package_id():
108
109 The logical package ID to which a thread belongs.
110
111 - topology_physical_package_id():
112
113 The physical package ID to which a thread belongs.
114
115 - topology_core_id();
116
117 The ID of the core to which a thread belongs. It is also printed in /proc/cpuinfo
118 "core_id."
119
120
121
122System topology examples
123
124Note:
125
126The alternative Linux CPU enumeration depends on how the BIOS enumerates the
127threads. Many BIOSes enumerate all threads 0 first and then all threads 1.
128That has the "advantage" that the logical Linux CPU numbers of threads 0 stay
129the same whether threads are enabled or not. That's merely an implementation
130detail and has no practical impact.
131
1321) Single Package, Single Core
133
134 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
135
1362) Single Package, Dual Core
137
138 a) One thread per core
139
140 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
141 -> [core 1] -> [thread 0] -> Linux CPU 1
142
143 b) Two threads per core
144
145 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
146 -> [thread 1] -> Linux CPU 1
147 -> [core 1] -> [thread 0] -> Linux CPU 2
148 -> [thread 1] -> Linux CPU 3
149
150 Alternative enumeration:
151
152 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
153 -> [thread 1] -> Linux CPU 2
154 -> [core 1] -> [thread 0] -> Linux CPU 1
155 -> [thread 1] -> Linux CPU 3
156
157 AMD nomenclature for CMT systems:
158
159 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
160 -> [Compute Unit Core 1] -> Linux CPU 1
161 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
162 -> [Compute Unit Core 1] -> Linux CPU 3
163
1644) Dual Package, Dual Core
165
166 a) One thread per core
167
168 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
169 -> [core 1] -> [thread 0] -> Linux CPU 1
170
171 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
172 -> [core 1] -> [thread 0] -> Linux CPU 3
173
174 b) Two threads per core
175
176 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
177 -> [thread 1] -> Linux CPU 1
178 -> [core 1] -> [thread 0] -> Linux CPU 2
179 -> [thread 1] -> Linux CPU 3
180
181 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 4
182 -> [thread 1] -> Linux CPU 5
183 -> [core 1] -> [thread 0] -> Linux CPU 6
184 -> [thread 1] -> Linux CPU 7
185
186 Alternative enumeration:
187
188 [package 0] -> [core 0] -> [thread 0] -> Linux CPU 0
189 -> [thread 1] -> Linux CPU 4
190 -> [core 1] -> [thread 0] -> Linux CPU 1
191 -> [thread 1] -> Linux CPU 5
192
193 [package 1] -> [core 0] -> [thread 0] -> Linux CPU 2
194 -> [thread 1] -> Linux CPU 6
195 -> [core 1] -> [thread 0] -> Linux CPU 3
196 -> [thread 1] -> Linux CPU 7
197
198 AMD nomenclature for CMT systems:
199
200 [node 0] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 0
201 -> [Compute Unit Core 1] -> Linux CPU 1
202 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 2
203 -> [Compute Unit Core 1] -> Linux CPU 3
204
205 [node 1] -> [Compute Unit 0] -> [Compute Unit Core 0] -> Linux CPU 4
206 -> [Compute Unit Core 1] -> Linux CPU 5
207 -> [Compute Unit 1] -> [Compute Unit Core 0] -> Linux CPU 6
208 -> [Compute Unit Core 1] -> Linux CPU 7
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 6915ff2bd996..8774cb23064f 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -26,7 +26,7 @@ targets := vmlinux vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma \
26 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4 26 vmlinux.bin.xz vmlinux.bin.lzo vmlinux.bin.lz4
27 27
28KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2 28KBUILD_CFLAGS := -m$(BITS) -D__KERNEL__ $(LINUX_INCLUDE) -O2
29KBUILD_CFLAGS += -fno-strict-aliasing -fPIC 29KBUILD_CFLAGS += -fno-strict-aliasing $(call cc-option, -fPIE, -fPIC)
30KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING 30KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
31cflags-$(CONFIG_X86_32) := -march=i386 31cflags-$(CONFIG_X86_32) := -march=i386
32cflags-$(CONFIG_X86_64) := -mcmodel=small 32cflags-$(CONFIG_X86_64) := -mcmodel=small
@@ -40,6 +40,18 @@ GCOV_PROFILE := n
40UBSAN_SANITIZE :=n 40UBSAN_SANITIZE :=n
41 41
42LDFLAGS := -m elf_$(UTS_MACHINE) 42LDFLAGS := -m elf_$(UTS_MACHINE)
43ifeq ($(CONFIG_RELOCATABLE),y)
44# If kernel is relocatable, build compressed kernel as PIE.
45ifeq ($(CONFIG_X86_32),y)
46LDFLAGS += $(call ld-option, -pie) $(call ld-option, --no-dynamic-linker)
47else
48# To build 64-bit compressed kernel as PIE, we disable relocation
49# overflow check to avoid relocation overflow error with a new linker
50# command-line option, -z noreloc-overflow.
51LDFLAGS += $(shell $(LD) --help 2>&1 | grep -q "\-z noreloc-overflow" \
52 && echo "-z noreloc-overflow -pie --no-dynamic-linker")
53endif
54endif
43LDFLAGS_vmlinux := -T 55LDFLAGS_vmlinux := -T
44 56
45hostprogs-y := mkpiggy 57hostprogs-y := mkpiggy
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index 8ef964ddc18e..0256064da8da 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -31,6 +31,34 @@
31#include <asm/asm-offsets.h> 31#include <asm/asm-offsets.h>
32#include <asm/bootparam.h> 32#include <asm/bootparam.h>
33 33
34/*
35 * The 32-bit x86 assembler in binutils 2.26 will generate R_386_GOT32X
36 * relocation to get the symbol address in PIC. When the compressed x86
37 * kernel isn't built as PIC, the linker optimizes R_386_GOT32X
38 * relocations to their fixed symbol addresses. However, when the
39 * compressed x86 kernel is loaded at a different address, it leads
40 * to the following load failure:
41 *
42 * Failed to allocate space for phdrs
43 *
44 * during the decompression stage.
45 *
46 * If the compressed x86 kernel is relocatable at run-time, it should be
47 * compiled with -fPIE, instead of -fPIC, if possible and should be built as
48 * Position Independent Executable (PIE) so that linker won't optimize
49 * R_386_GOT32X relocation to its fixed symbol address. Older
50 * linkers generate R_386_32 relocations against locally defined symbols,
51 * _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less
52 * optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle
53 * R_386_32 relocations when relocating the kernel. To generate
54 * R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as
55 * hidden:
56 */
57 .hidden _bss
58 .hidden _ebss
59 .hidden _got
60 .hidden _egot
61
34 __HEAD 62 __HEAD
35ENTRY(startup_32) 63ENTRY(startup_32)
36#ifdef CONFIG_EFI_STUB 64#ifdef CONFIG_EFI_STUB
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index b0c0d16ef58d..86558a199139 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -33,6 +33,14 @@
33#include <asm/asm-offsets.h> 33#include <asm/asm-offsets.h>
34#include <asm/bootparam.h> 34#include <asm/bootparam.h>
35 35
36/*
37 * Locally defined symbols should be marked hidden:
38 */
39 .hidden _bss
40 .hidden _ebss
41 .hidden _got
42 .hidden _egot
43
36 __HEAD 44 __HEAD
37 .code32 45 .code32
38ENTRY(startup_32) 46ENTRY(startup_32)
diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
index 049ada8d4e9c..86a9bec18dab 100644
--- a/arch/x86/events/amd/core.c
+++ b/arch/x86/events/amd/core.c
@@ -369,7 +369,7 @@ static int amd_pmu_cpu_prepare(int cpu)
369 369
370 WARN_ON_ONCE(cpuc->amd_nb); 370 WARN_ON_ONCE(cpuc->amd_nb);
371 371
372 if (boot_cpu_data.x86_max_cores < 2) 372 if (!x86_pmu.amd_nb_constraints)
373 return NOTIFY_OK; 373 return NOTIFY_OK;
374 374
375 cpuc->amd_nb = amd_alloc_nb(cpu); 375 cpuc->amd_nb = amd_alloc_nb(cpu);
@@ -388,7 +388,7 @@ static void amd_pmu_cpu_starting(int cpu)
388 388
389 cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY; 389 cpuc->perf_ctr_virt_mask = AMD64_EVENTSEL_HOSTONLY;
390 390
391 if (boot_cpu_data.x86_max_cores < 2) 391 if (!x86_pmu.amd_nb_constraints)
392 return; 392 return;
393 393
394 nb_id = amd_get_nb_id(cpu); 394 nb_id = amd_get_nb_id(cpu);
@@ -414,7 +414,7 @@ static void amd_pmu_cpu_dead(int cpu)
414{ 414{
415 struct cpu_hw_events *cpuhw; 415 struct cpu_hw_events *cpuhw;
416 416
417 if (boot_cpu_data.x86_max_cores < 2) 417 if (!x86_pmu.amd_nb_constraints)
418 return; 418 return;
419 419
420 cpuhw = &per_cpu(cpu_hw_events, cpu); 420 cpuhw = &per_cpu(cpu_hw_events, cpu);
@@ -648,6 +648,8 @@ static __initconst const struct x86_pmu amd_pmu = {
648 .cpu_prepare = amd_pmu_cpu_prepare, 648 .cpu_prepare = amd_pmu_cpu_prepare,
649 .cpu_starting = amd_pmu_cpu_starting, 649 .cpu_starting = amd_pmu_cpu_starting,
650 .cpu_dead = amd_pmu_cpu_dead, 650 .cpu_dead = amd_pmu_cpu_dead,
651
652 .amd_nb_constraints = 1,
651}; 653};
652 654
653static int __init amd_core_pmu_init(void) 655static int __init amd_core_pmu_init(void)
@@ -674,6 +676,11 @@ static int __init amd_core_pmu_init(void)
674 x86_pmu.eventsel = MSR_F15H_PERF_CTL; 676 x86_pmu.eventsel = MSR_F15H_PERF_CTL;
675 x86_pmu.perfctr = MSR_F15H_PERF_CTR; 677 x86_pmu.perfctr = MSR_F15H_PERF_CTR;
676 x86_pmu.num_counters = AMD64_NUM_COUNTERS_CORE; 678 x86_pmu.num_counters = AMD64_NUM_COUNTERS_CORE;
679 /*
680 * AMD Core perfctr has separate MSRs for the NB events, see
681 * the amd/uncore.c driver.
682 */
683 x86_pmu.amd_nb_constraints = 0;
677 684
678 pr_cont("core perfctr, "); 685 pr_cont("core perfctr, ");
679 return 0; 686 return 0;
@@ -693,6 +700,14 @@ __init int amd_pmu_init(void)
693 if (ret) 700 if (ret)
694 return ret; 701 return ret;
695 702
703 if (num_possible_cpus() == 1) {
704 /*
705 * No point in allocating data structures to serialize
706 * against other CPUs, when there is only the one CPU.
707 */
708 x86_pmu.amd_nb_constraints = 0;
709 }
710
696 /* Events are common for all AMDs */ 711 /* Events are common for all AMDs */
697 memcpy(hw_cache_event_ids, amd_hw_cache_event_ids, 712 memcpy(hw_cache_event_ids, amd_hw_cache_event_ids,
698 sizeof(hw_cache_event_ids)); 713 sizeof(hw_cache_event_ids));
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index ba6ef18528c9..716d0482f5db 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -608,6 +608,11 @@ struct x86_pmu {
608 atomic_t lbr_exclusive[x86_lbr_exclusive_max]; 608 atomic_t lbr_exclusive[x86_lbr_exclusive_max];
609 609
610 /* 610 /*
611 * AMD bits
612 */
613 unsigned int amd_nb_constraints : 1;
614
615 /*
611 * Extra registers for events 616 * Extra registers for events
612 */ 617 */
613 struct extra_reg *extra_regs; 618 struct extra_reg *extra_regs;
diff --git a/arch/x86/include/asm/msr-index.h b/arch/x86/include/asm/msr-index.h
index 2da46ac16e37..426e946ed0c0 100644
--- a/arch/x86/include/asm/msr-index.h
+++ b/arch/x86/include/asm/msr-index.h
@@ -190,6 +190,7 @@
190#define MSR_PP1_ENERGY_STATUS 0x00000641 190#define MSR_PP1_ENERGY_STATUS 0x00000641
191#define MSR_PP1_POLICY 0x00000642 191#define MSR_PP1_POLICY 0x00000642
192 192
193/* Config TDP MSRs */
193#define MSR_CONFIG_TDP_NOMINAL 0x00000648 194#define MSR_CONFIG_TDP_NOMINAL 0x00000648
194#define MSR_CONFIG_TDP_LEVEL_1 0x00000649 195#define MSR_CONFIG_TDP_LEVEL_1 0x00000649
195#define MSR_CONFIG_TDP_LEVEL_2 0x0000064A 196#define MSR_CONFIG_TDP_LEVEL_2 0x0000064A
@@ -210,13 +211,6 @@
210#define MSR_GFX_PERF_LIMIT_REASONS 0x000006B0 211#define MSR_GFX_PERF_LIMIT_REASONS 0x000006B0
211#define MSR_RING_PERF_LIMIT_REASONS 0x000006B1 212#define MSR_RING_PERF_LIMIT_REASONS 0x000006B1
212 213
213/* Config TDP MSRs */
214#define MSR_CONFIG_TDP_NOMINAL 0x00000648
215#define MSR_CONFIG_TDP_LEVEL1 0x00000649
216#define MSR_CONFIG_TDP_LEVEL2 0x0000064A
217#define MSR_CONFIG_TDP_CONTROL 0x0000064B
218#define MSR_TURBO_ACTIVATION_RATIO 0x0000064C
219
220/* Hardware P state interface */ 214/* Hardware P state interface */
221#define MSR_PPERF 0x0000064e 215#define MSR_PPERF 0x0000064e
222#define MSR_PERF_LIMIT_REASONS 0x0000064f 216#define MSR_PERF_LIMIT_REASONS 0x0000064f
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 983738ac014c..9264476f3d57 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -132,8 +132,6 @@ struct cpuinfo_x86 {
132 u16 logical_proc_id; 132 u16 logical_proc_id;
133 /* Core id: */ 133 /* Core id: */
134 u16 cpu_core_id; 134 u16 cpu_core_id;
135 /* Compute unit id */
136 u8 compute_unit_id;
137 /* Index into per_cpu list: */ 135 /* Index into per_cpu list: */
138 u16 cpu_index; 136 u16 cpu_index;
139 u32 microcode; 137 u32 microcode;
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 20a3de5cb3b0..66b057306f40 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -155,6 +155,7 @@ static inline int wbinvd_on_all_cpus(void)
155 wbinvd(); 155 wbinvd();
156 return 0; 156 return 0;
157} 157}
158#define smp_num_siblings 1
158#endif /* CONFIG_SMP */ 159#endif /* CONFIG_SMP */
159 160
160extern unsigned disabled_cpus; 161extern unsigned disabled_cpus;
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 82866697fcf1..ffae84df8a93 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -276,11 +276,9 @@ static inline bool is_ia32_task(void)
276 */ 276 */
277#define force_iret() set_thread_flag(TIF_NOTIFY_RESUME) 277#define force_iret() set_thread_flag(TIF_NOTIFY_RESUME)
278 278
279#endif /* !__ASSEMBLY__ */
280
281#ifndef __ASSEMBLY__
282extern void arch_task_cache_init(void); 279extern void arch_task_cache_init(void);
283extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src); 280extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
284extern void arch_release_task_struct(struct task_struct *tsk); 281extern void arch_release_task_struct(struct task_struct *tsk);
285#endif 282#endif /* !__ASSEMBLY__ */
283
286#endif /* _ASM_X86_THREAD_INFO_H */ 284#endif /* _ASM_X86_THREAD_INFO_H */
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 29fa475ec518..a147e676fc7b 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -170,15 +170,13 @@ int amd_get_subcaches(int cpu)
170{ 170{
171 struct pci_dev *link = node_to_amd_nb(amd_get_nb_id(cpu))->link; 171 struct pci_dev *link = node_to_amd_nb(amd_get_nb_id(cpu))->link;
172 unsigned int mask; 172 unsigned int mask;
173 int cuid;
174 173
175 if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) 174 if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
176 return 0; 175 return 0;
177 176
178 pci_read_config_dword(link, 0x1d4, &mask); 177 pci_read_config_dword(link, 0x1d4, &mask);
179 178
180 cuid = cpu_data(cpu).compute_unit_id; 179 return (mask >> (4 * cpu_data(cpu).cpu_core_id)) & 0xf;
181 return (mask >> (4 * cuid)) & 0xf;
182} 180}
183 181
184int amd_set_subcaches(int cpu, unsigned long mask) 182int amd_set_subcaches(int cpu, unsigned long mask)
@@ -204,7 +202,7 @@ int amd_set_subcaches(int cpu, unsigned long mask)
204 pci_write_config_dword(nb->misc, 0x1b8, reg & ~0x180000); 202 pci_write_config_dword(nb->misc, 0x1b8, reg & ~0x180000);
205 } 203 }
206 204
207 cuid = cpu_data(cpu).compute_unit_id; 205 cuid = cpu_data(cpu).cpu_core_id;
208 mask <<= 4 * cuid; 206 mask <<= 4 * cuid;
209 mask |= (0xf ^ (1 << cuid)) << 26; 207 mask |= (0xf ^ (1 << cuid)) << 26;
210 208
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index 02ac79b6256e..19d7dcfc8b3e 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
@@ -300,7 +300,6 @@ static int nearby_node(int apicid)
300#ifdef CONFIG_SMP 300#ifdef CONFIG_SMP
301static void amd_get_topology(struct cpuinfo_x86 *c) 301static void amd_get_topology(struct cpuinfo_x86 *c)
302{ 302{
303 u32 cores_per_cu = 1;
304 u8 node_id; 303 u8 node_id;
305 int cpu = smp_processor_id(); 304 int cpu = smp_processor_id();
306 305
@@ -313,8 +312,8 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
313 312
314 /* get compute unit information */ 313 /* get compute unit information */
315 smp_num_siblings = ((ebx >> 8) & 3) + 1; 314 smp_num_siblings = ((ebx >> 8) & 3) + 1;
316 c->compute_unit_id = ebx & 0xff; 315 c->x86_max_cores /= smp_num_siblings;
317 cores_per_cu += ((ebx >> 8) & 3); 316 c->cpu_core_id = ebx & 0xff;
318 } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) { 317 } else if (cpu_has(c, X86_FEATURE_NODEID_MSR)) {
319 u64 value; 318 u64 value;
320 319
@@ -325,19 +324,16 @@ static void amd_get_topology(struct cpuinfo_x86 *c)
325 324
326 /* fixup multi-node processor information */ 325 /* fixup multi-node processor information */
327 if (nodes_per_socket > 1) { 326 if (nodes_per_socket > 1) {
328 u32 cores_per_node;
329 u32 cus_per_node; 327 u32 cus_per_node;
330 328
331 set_cpu_cap(c, X86_FEATURE_AMD_DCM); 329 set_cpu_cap(c, X86_FEATURE_AMD_DCM);
332 cores_per_node = c->x86_max_cores / nodes_per_socket; 330 cus_per_node = c->x86_max_cores / nodes_per_socket;
333 cus_per_node = cores_per_node / cores_per_cu;
334 331
335 /* store NodeID, use llc_shared_map to store sibling info */ 332 /* store NodeID, use llc_shared_map to store sibling info */
336 per_cpu(cpu_llc_id, cpu) = node_id; 333 per_cpu(cpu_llc_id, cpu) = node_id;
337 334
338 /* core id has to be in the [0 .. cores_per_node - 1] range */ 335 /* core id has to be in the [0 .. cores_per_node - 1] range */
339 c->cpu_core_id %= cores_per_node; 336 c->cpu_core_id %= cus_per_node;
340 c->compute_unit_id %= cus_per_node;
341 } 337 }
342} 338}
343#endif 339#endif
diff --git a/arch/x86/kernel/cpu/mcheck/mce-genpool.c b/arch/x86/kernel/cpu/mcheck/mce-genpool.c
index 0a850100c594..2658e2af74ec 100644
--- a/arch/x86/kernel/cpu/mcheck/mce-genpool.c
+++ b/arch/x86/kernel/cpu/mcheck/mce-genpool.c
@@ -29,7 +29,7 @@ static char gen_pool_buf[MCE_POOLSZ];
29void mce_gen_pool_process(void) 29void mce_gen_pool_process(void)
30{ 30{
31 struct llist_node *head; 31 struct llist_node *head;
32 struct mce_evt_llist *node; 32 struct mce_evt_llist *node, *tmp;
33 struct mce *mce; 33 struct mce *mce;
34 34
35 head = llist_del_all(&mce_event_llist); 35 head = llist_del_all(&mce_event_llist);
@@ -37,7 +37,7 @@ void mce_gen_pool_process(void)
37 return; 37 return;
38 38
39 head = llist_reverse_order(head); 39 head = llist_reverse_order(head);
40 llist_for_each_entry(node, head, llnode) { 40 llist_for_each_entry_safe(node, tmp, head, llnode) {
41 mce = &node->mce; 41 mce = &node->mce;
42 atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce); 42 atomic_notifier_call_chain(&x86_mce_decoder_chain, 0, mce);
43 gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node)); 43 gen_pool_free(mce_evt_pool, (unsigned long)node, sizeof(*node));
diff --git a/arch/x86/kernel/cpu/powerflags.c b/arch/x86/kernel/cpu/powerflags.c
index 31f0f335ed22..1dd8294fd730 100644
--- a/arch/x86/kernel/cpu/powerflags.c
+++ b/arch/x86/kernel/cpu/powerflags.c
@@ -18,4 +18,6 @@ const char *const x86_power_flags[32] = {
18 "", /* tsc invariant mapped to constant_tsc */ 18 "", /* tsc invariant mapped to constant_tsc */
19 "cpb", /* core performance boost */ 19 "cpb", /* core performance boost */
20 "eff_freq_ro", /* Readonly aperf/mperf */ 20 "eff_freq_ro", /* Readonly aperf/mperf */
21 "proc_feedback", /* processor feedback interface */
22 "acc_power", /* accumulated power mechanism */
21}; 23};
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index b2c99f811c3f..a2065d3b3b39 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -422,7 +422,7 @@ static bool match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o)
422 422
423 if (c->phys_proc_id == o->phys_proc_id && 423 if (c->phys_proc_id == o->phys_proc_id &&
424 per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2) && 424 per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2) &&
425 c->compute_unit_id == o->compute_unit_id) 425 c->cpu_core_id == o->cpu_core_id)
426 return topology_sane(c, o, "smt"); 426 return topology_sane(c, o, "smt");
427 427
428 } else if (c->phys_proc_id == o->phys_proc_id && 428 } else if (c->phys_proc_id == o->phys_proc_id &&
diff --git a/arch/x86/ras/mce_amd_inj.c b/arch/x86/ras/mce_amd_inj.c
index 55d38cfa46c2..9e02dcaef683 100644
--- a/arch/x86/ras/mce_amd_inj.c
+++ b/arch/x86/ras/mce_amd_inj.c
@@ -20,6 +20,7 @@
20#include <linux/pci.h> 20#include <linux/pci.h>
21 21
22#include <asm/mce.h> 22#include <asm/mce.h>
23#include <asm/smp.h>
23#include <asm/amd_nb.h> 24#include <asm/amd_nb.h>
24#include <asm/irq_vectors.h> 25#include <asm/irq_vectors.h>
25 26
@@ -206,7 +207,7 @@ static u32 get_nbc_for_node(int node_id)
206 struct cpuinfo_x86 *c = &boot_cpu_data; 207 struct cpuinfo_x86 *c = &boot_cpu_data;
207 u32 cores_per_node; 208 u32 cores_per_node;
208 209
209 cores_per_node = c->x86_max_cores / amd_get_nodes_per_socket(); 210 cores_per_node = (c->x86_max_cores * smp_num_siblings) / amd_get_nodes_per_socket();
210 211
211 return cores_per_node * node_id; 212 return cores_per_node * node_id;
212} 213}
diff --git a/drivers/lguest/interrupts_and_traps.c b/drivers/lguest/interrupts_and_traps.c
index eb934b0242e0..67392b6ab845 100644
--- a/drivers/lguest/interrupts_and_traps.c
+++ b/drivers/lguest/interrupts_and_traps.c
@@ -331,7 +331,7 @@ void set_interrupt(struct lg_cpu *cpu, unsigned int irq)
331 * Actually now I think of it, it's possible that Ron *is* half the Plan 9 331 * Actually now I think of it, it's possible that Ron *is* half the Plan 9
332 * userbase. Oh well. 332 * userbase. Oh well.
333 */ 333 */
334static bool could_be_syscall(unsigned int num) 334bool could_be_syscall(unsigned int num)
335{ 335{
336 /* Normal Linux IA32_SYSCALL_VECTOR or reserved vector? */ 336 /* Normal Linux IA32_SYSCALL_VECTOR or reserved vector? */
337 return num == IA32_SYSCALL_VECTOR || num == syscall_vector; 337 return num == IA32_SYSCALL_VECTOR || num == syscall_vector;
@@ -416,6 +416,10 @@ bool deliver_trap(struct lg_cpu *cpu, unsigned int num)
416 * 416 *
417 * This routine indicates if a particular trap number could be delivered 417 * This routine indicates if a particular trap number could be delivered
418 * directly. 418 * directly.
419 *
420 * Unfortunately, Linux 4.6 started using an interrupt gate instead of a
421 * trap gate for syscalls, so this trick is ineffective. See Mastery for
422 * how we could do this anyway...
419 */ 423 */
420static bool direct_trap(unsigned int num) 424static bool direct_trap(unsigned int num)
421{ 425{
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h
index ac8ad0461e80..69b3814afd2f 100644
--- a/drivers/lguest/lg.h
+++ b/drivers/lguest/lg.h
@@ -167,6 +167,7 @@ void guest_set_clockevent(struct lg_cpu *cpu, unsigned long delta);
167bool send_notify_to_eventfd(struct lg_cpu *cpu); 167bool send_notify_to_eventfd(struct lg_cpu *cpu);
168void init_clockdev(struct lg_cpu *cpu); 168void init_clockdev(struct lg_cpu *cpu);
169bool check_syscall_vector(struct lguest *lg); 169bool check_syscall_vector(struct lguest *lg);
170bool could_be_syscall(unsigned int num);
170int init_interrupts(void); 171int init_interrupts(void);
171void free_interrupts(void); 172void free_interrupts(void);
172 173
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
index 65f22debf3c6..6e9042e3d2a9 100644
--- a/drivers/lguest/x86/core.c
+++ b/drivers/lguest/x86/core.c
@@ -429,8 +429,12 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
429 return; 429 return;
430 break; 430 break;
431 case 32 ... 255: 431 case 32 ... 255:
432 /* This might be a syscall. */
433 if (could_be_syscall(cpu->regs->trapnum))
434 break;
435
432 /* 436 /*
433 * These values mean a real interrupt occurred, in which case 437 * Other values mean a real interrupt occurred, in which case
434 * the Host handler has already been run. We just do a 438 * the Host handler has already been run. We just do a
435 * friendly check if another process should now be run, then 439 * friendly check if another process should now be run, then
436 * return to run the Guest again. 440 * return to run the Guest again.