Magellan Linux

Contents of /trunk/kernel-alx/patches-5.4/0293-5.4.194-all-fixes.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3637 - (show annotations) (download)
Mon Oct 24 12:40:44 2022 UTC (18 months, 1 week ago) by niro
File size: 37633 byte(s)
-add missing
1 diff --git a/Documentation/vm/memory-model.rst b/Documentation/vm/memory-model.rst
2 index 58a12376b7df7..94db75ba7fbe2 100644
3 --- a/Documentation/vm/memory-model.rst
4 +++ b/Documentation/vm/memory-model.rst
5 @@ -52,8 +52,7 @@ wrapper :c:func:`free_area_init`. Yet, the mappings array is not
6 usable until the call to :c:func:`memblock_free_all` that hands all
7 the memory to the page allocator.
8
9 -If an architecture enables `CONFIG_ARCH_HAS_HOLES_MEMORYMODEL` option,
10 -it may free parts of the `mem_map` array that do not cover the
11 +An architecture may free parts of the `mem_map` array that do not cover the
12 actual physical pages. In such case, the architecture specific
13 :c:func:`pfn_valid` implementation should take the holes in the
14 `mem_map` into account.
15 diff --git a/Makefile b/Makefile
16 index 888d896058553..044a85fea9216 100644
17 --- a/Makefile
18 +++ b/Makefile
19 @@ -1,7 +1,7 @@
20 # SPDX-License-Identifier: GPL-2.0
21 VERSION = 5
22 PATCHLEVEL = 4
23 -SUBLEVEL = 193
24 +SUBLEVEL = 194
25 EXTRAVERSION =
26 NAME = Kleptomaniac Octopus
27
28 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
29 index 4b36bbcf5a5b4..a1622b9290fd5 100644
30 --- a/arch/arm/Kconfig
31 +++ b/arch/arm/Kconfig
32 @@ -26,7 +26,7 @@ config ARM
33 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
34 select ARCH_HAVE_CUSTOM_GPIO_H
35 select ARCH_HAS_GCOV_PROFILE_ALL
36 - select ARCH_KEEP_MEMBLOCK if HAVE_ARCH_PFN_VALID || KEXEC
37 + select ARCH_KEEP_MEMBLOCK
38 select ARCH_MIGHT_HAVE_PC_PARPORT
39 select ARCH_NO_SG_CHAIN if !ARM_HAS_SG_CHAIN
40 select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
41 @@ -521,7 +521,6 @@ config ARCH_S3C24XX
42 config ARCH_OMAP1
43 bool "TI OMAP1"
44 depends on MMU
45 - select ARCH_HAS_HOLES_MEMORYMODEL
46 select ARCH_OMAP
47 select CLKDEV_LOOKUP
48 select CLKSRC_MMIO
49 @@ -1518,9 +1517,6 @@ config OABI_COMPAT
50 UNPREDICTABLE (in fact it can be predicted that it won't work
51 at all). If in doubt say N.
52
53 -config ARCH_HAS_HOLES_MEMORYMODEL
54 - bool
55 -
56 config ARCH_SPARSEMEM_ENABLE
57 bool
58
59 @@ -1528,7 +1524,7 @@ config ARCH_SPARSEMEM_DEFAULT
60 def_bool ARCH_SPARSEMEM_ENABLE
61
62 config HAVE_ARCH_PFN_VALID
63 - def_bool ARCH_HAS_HOLES_MEMORYMODEL || !SPARSEMEM
64 + def_bool y
65
66 config HIGHMEM
67 bool "High Memory Support"
68 diff --git a/arch/arm/mach-bcm/Kconfig b/arch/arm/mach-bcm/Kconfig
69 index 5e5f1fabc3d40..634d1bc3c0114 100644
70 --- a/arch/arm/mach-bcm/Kconfig
71 +++ b/arch/arm/mach-bcm/Kconfig
72 @@ -214,7 +214,6 @@ config ARCH_BRCMSTB
73 select HAVE_ARM_ARCH_TIMER
74 select BRCMSTB_L2_IRQ
75 select BCM7120_L2_IRQ
76 - select ARCH_HAS_HOLES_MEMORYMODEL
77 select ZONE_DMA if ARM_LPAE
78 select SOC_BRCMSTB
79 select SOC_BUS
80 diff --git a/arch/arm/mach-davinci/Kconfig b/arch/arm/mach-davinci/Kconfig
81 index 02b180ad72454..4d3b7d0418c40 100644
82 --- a/arch/arm/mach-davinci/Kconfig
83 +++ b/arch/arm/mach-davinci/Kconfig
84 @@ -5,7 +5,6 @@ menuconfig ARCH_DAVINCI
85 depends on ARCH_MULTI_V5
86 select DAVINCI_TIMER
87 select ZONE_DMA
88 - select ARCH_HAS_HOLES_MEMORYMODEL
89 select PM_GENERIC_DOMAINS if PM
90 select PM_GENERIC_DOMAINS_OF if PM && OF
91 select REGMAP_MMIO
92 diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig
93 index 9dab1f50a02f8..fc01137628e4b 100644
94 --- a/arch/arm/mach-exynos/Kconfig
95 +++ b/arch/arm/mach-exynos/Kconfig
96 @@ -8,7 +8,6 @@
97 menuconfig ARCH_EXYNOS
98 bool "Samsung EXYNOS"
99 depends on ARCH_MULTI_V7
100 - select ARCH_HAS_HOLES_MEMORYMODEL
101 select ARCH_SUPPORTS_BIG_ENDIAN
102 select ARM_AMBA
103 select ARM_GIC
104 diff --git a/arch/arm/mach-highbank/Kconfig b/arch/arm/mach-highbank/Kconfig
105 index 1bc68913d62c1..9de38ce8124f2 100644
106 --- a/arch/arm/mach-highbank/Kconfig
107 +++ b/arch/arm/mach-highbank/Kconfig
108 @@ -2,7 +2,6 @@
109 config ARCH_HIGHBANK
110 bool "Calxeda ECX-1000/2000 (Highbank/Midway)"
111 depends on ARCH_MULTI_V7
112 - select ARCH_HAS_HOLES_MEMORYMODEL
113 select ARCH_SUPPORTS_BIG_ENDIAN
114 select ARM_AMBA
115 select ARM_ERRATA_764369 if SMP
116 diff --git a/arch/arm/mach-omap2/Kconfig b/arch/arm/mach-omap2/Kconfig
117 index fdb6743760a2e..0211f4aa8cc75 100644
118 --- a/arch/arm/mach-omap2/Kconfig
119 +++ b/arch/arm/mach-omap2/Kconfig
120 @@ -94,7 +94,7 @@ config SOC_DRA7XX
121 config ARCH_OMAP2PLUS
122 bool
123 select ARCH_HAS_BANDGAP
124 - select ARCH_HAS_HOLES_MEMORYMODEL
125 + select ARCH_HAS_RESET_CONTROLLER
126 select ARCH_OMAP
127 select CLKSRC_MMIO
128 select GENERIC_IRQ_CHIP
129 diff --git a/arch/arm/mach-s5pv210/Kconfig b/arch/arm/mach-s5pv210/Kconfig
130 index 03984a7918791..69ff1bb89f38f 100644
131 --- a/arch/arm/mach-s5pv210/Kconfig
132 +++ b/arch/arm/mach-s5pv210/Kconfig
133 @@ -8,7 +8,6 @@
134 config ARCH_S5PV210
135 bool "Samsung S5PV210/S5PC110"
136 depends on ARCH_MULTI_V7
137 - select ARCH_HAS_HOLES_MEMORYMODEL
138 select ARM_VIC
139 select CLKSRC_SAMSUNG_PWM
140 select COMMON_CLK_SAMSUNG
141 diff --git a/arch/arm/mach-tango/Kconfig b/arch/arm/mach-tango/Kconfig
142 index 25b2fd4348617..a9eeda36aeb15 100644
143 --- a/arch/arm/mach-tango/Kconfig
144 +++ b/arch/arm/mach-tango/Kconfig
145 @@ -3,7 +3,6 @@ config ARCH_TANGO
146 bool "Sigma Designs Tango4 (SMP87xx)"
147 depends on ARCH_MULTI_V7
148 # Cortex-A9 MPCore r3p0, PL310 r3p2
149 - select ARCH_HAS_HOLES_MEMORYMODEL
150 select ARM_ERRATA_754322
151 select ARM_ERRATA_764369 if SMP
152 select ARM_ERRATA_775420
153 diff --git a/arch/mips/bmips/setup.c b/arch/mips/bmips/setup.c
154 index 2f81a94c71a60..7aee9ff19c1a6 100644
155 --- a/arch/mips/bmips/setup.c
156 +++ b/arch/mips/bmips/setup.c
157 @@ -167,7 +167,7 @@ void __init plat_mem_setup(void)
158 dtb = phys_to_virt(fw_arg2);
159 else if (fw_passed_dtb) /* UHI interface or appended dtb */
160 dtb = (void *)fw_passed_dtb;
161 - else if (__dtb_start != __dtb_end)
162 + else if (&__dtb_start != &__dtb_end)
163 dtb = (void *)__dtb_start;
164 else
165 panic("no dtb found");
166 diff --git a/arch/mips/lantiq/prom.c b/arch/mips/lantiq/prom.c
167 index 51a218f04fe0d..3f568f5aae2d1 100644
168 --- a/arch/mips/lantiq/prom.c
169 +++ b/arch/mips/lantiq/prom.c
170 @@ -79,7 +79,7 @@ void __init plat_mem_setup(void)
171
172 if (fw_passed_dtb) /* UHI interface */
173 dtb = (void *)fw_passed_dtb;
174 - else if (__dtb_start != __dtb_end)
175 + else if (&__dtb_start != &__dtb_end)
176 dtb = (void *)__dtb_start;
177 else
178 panic("no dtb found");
179 diff --git a/arch/mips/pic32/pic32mzda/init.c b/arch/mips/pic32/pic32mzda/init.c
180 index 50f376f058f43..f232c77ff5265 100644
181 --- a/arch/mips/pic32/pic32mzda/init.c
182 +++ b/arch/mips/pic32/pic32mzda/init.c
183 @@ -28,7 +28,7 @@ static ulong get_fdtaddr(void)
184 if (fw_passed_dtb && !fw_arg2 && !fw_arg3)
185 return (ulong)fw_passed_dtb;
186
187 - if (__dtb_start < __dtb_end)
188 + if (&__dtb_start < &__dtb_end)
189 ftaddr = (ulong)__dtb_start;
190
191 return ftaddr;
192 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
193 index 4e38a905ab386..e2c71c6c667da 100644
194 --- a/arch/mips/ralink/of.c
195 +++ b/arch/mips/ralink/of.c
196 @@ -77,7 +77,7 @@ void __init plat_mem_setup(void)
197 */
198 if (fw_passed_dtb)
199 dtb = (void *)fw_passed_dtb;
200 - else if (__dtb_start != __dtb_end)
201 + else if (&__dtb_start != &__dtb_end)
202 dtb = (void *)__dtb_start;
203
204 __dt_setup_arch(dtb);
205 diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
206 index 3ff577c0b1024..1b563f9167eae 100644
207 --- a/arch/x86/include/asm/asm.h
208 +++ b/arch/x86/include/asm/asm.h
209 @@ -7,9 +7,11 @@
210 # define __ASM_FORM_RAW(x) x
211 # define __ASM_FORM_COMMA(x) x,
212 #else
213 -# define __ASM_FORM(x) " " #x " "
214 -# define __ASM_FORM_RAW(x) #x
215 -# define __ASM_FORM_COMMA(x) " " #x ","
216 +#include <linux/stringify.h>
217 +
218 +# define __ASM_FORM(x) " " __stringify(x) " "
219 +# define __ASM_FORM_RAW(x) __stringify(x)
220 +# define __ASM_FORM_COMMA(x) " " __stringify(x) ","
221 #endif
222
223 #ifndef __x86_64__
224 diff --git a/arch/x86/include/asm/emulate_prefix.h b/arch/x86/include/asm/emulate_prefix.h
225 new file mode 100644
226 index 0000000000000..70f5b98a52869
227 --- /dev/null
228 +++ b/arch/x86/include/asm/emulate_prefix.h
229 @@ -0,0 +1,14 @@
230 +/* SPDX-License-Identifier: GPL-2.0 */
231 +#ifndef _ASM_X86_EMULATE_PREFIX_H
232 +#define _ASM_X86_EMULATE_PREFIX_H
233 +
234 +/*
235 + * Virt escape sequences to trigger instruction emulation;
236 + * ideally these would decode to 'whole' instruction and not destroy
237 + * the instruction stream; sadly this is not true for the 'kvm' one :/
238 + */
239 +
240 +#define __XEN_EMULATE_PREFIX 0x0f,0x0b,0x78,0x65,0x6e /* ud2 ; .ascii "xen" */
241 +#define __KVM_EMULATE_PREFIX 0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */
242 +
243 +#endif
244 diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h
245 index a51ffeea6d879..a8c3d284fa46c 100644
246 --- a/arch/x86/include/asm/insn.h
247 +++ b/arch/x86/include/asm/insn.h
248 @@ -45,6 +45,7 @@ struct insn {
249 struct insn_field immediate2; /* for 64bit imm or seg16 */
250 };
251
252 + int emulate_prefix_size;
253 insn_attr_t attr;
254 unsigned char opnd_bytes;
255 unsigned char addr_bytes;
256 @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn)
257 return (insn->vex_prefix.nbytes == 4);
258 }
259
260 +static inline int insn_has_emulate_prefix(struct insn *insn)
261 +{
262 + return !!insn->emulate_prefix_size;
263 +}
264 +
265 /* Ensure this instruction is decoded completely */
266 static inline int insn_complete(struct insn *insn)
267 {
268 diff --git a/arch/x86/include/asm/xen/interface.h b/arch/x86/include/asm/xen/interface.h
269 index 62ca03ef5c657..9139b3e863161 100644
270 --- a/arch/x86/include/asm/xen/interface.h
271 +++ b/arch/x86/include/asm/xen/interface.h
272 @@ -379,12 +379,9 @@ struct xen_pmu_arch {
273 * Prefix forces emulation of some non-trapping instructions.
274 * Currently only CPUID.
275 */
276 -#ifdef __ASSEMBLY__
277 -#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
278 -#define XEN_CPUID XEN_EMULATE_PREFIX cpuid
279 -#else
280 -#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
281 -#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid"
282 -#endif
283 +#include <asm/emulate_prefix.h>
284 +
285 +#define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;)
286 +#define XEN_CPUID XEN_EMULATE_PREFIX __ASM_FORM(cpuid)
287
288 #endif /* _ASM_X86_XEN_INTERFACE_H */
289 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
290 index c205d77d57da3..3700dc94847c6 100644
291 --- a/arch/x86/kernel/kprobes/core.c
292 +++ b/arch/x86/kernel/kprobes/core.c
293 @@ -358,6 +358,10 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn)
294 kernel_insn_init(insn, dest, MAX_INSN_SIZE);
295 insn_get_length(insn);
296
297 + /* We can not probe force emulate prefixed instruction */
298 + if (insn_has_emulate_prefix(insn))
299 + return 0;
300 +
301 /* Another subsystem puts a breakpoint, failed to recover */
302 if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
303 return 0;
304 diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
305 index e0e3776059af4..32561431acde0 100644
306 --- a/arch/x86/kvm/pmu.c
307 +++ b/arch/x86/kvm/pmu.c
308 @@ -143,7 +143,6 @@ static void pmc_reprogram_counter(struct kvm_pmc *pmc, u32 type,
309 void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
310 {
311 unsigned config, type = PERF_TYPE_RAW;
312 - u8 event_select, unit_mask;
313 struct kvm *kvm = pmc->vcpu->kvm;
314 struct kvm_pmu_event_filter *filter;
315 int i;
316 @@ -175,17 +174,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
317 if (!allow_event)
318 return;
319
320 - event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
321 - unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
322 -
323 if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
324 ARCH_PERFMON_EVENTSEL_INV |
325 ARCH_PERFMON_EVENTSEL_CMASK |
326 HSW_IN_TX |
327 HSW_IN_TX_CHECKPOINTED))) {
328 - config = kvm_x86_ops->pmu_ops->find_arch_event(pmc_to_pmu(pmc),
329 - event_select,
330 - unit_mask);
331 + config = kvm_x86_ops->pmu_ops->pmc_perf_hw_id(pmc);
332 if (config != PERF_COUNT_HW_MAX)
333 type = PERF_TYPE_HARDWARE;
334 }
335 diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h
336 index 3fc98afd72a82..b63859e340e4e 100644
337 --- a/arch/x86/kvm/pmu.h
338 +++ b/arch/x86/kvm/pmu.h
339 @@ -22,8 +22,7 @@ struct kvm_event_hw_type_mapping {
340 };
341
342 struct kvm_pmu_ops {
343 - unsigned (*find_arch_event)(struct kvm_pmu *pmu, u8 event_select,
344 - u8 unit_mask);
345 + unsigned int (*pmc_perf_hw_id)(struct kvm_pmc *pmc);
346 unsigned (*find_fixed_event)(int idx);
347 bool (*pmc_is_enabled)(struct kvm_pmc *pmc);
348 struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx);
349 diff --git a/arch/x86/kvm/pmu_amd.c b/arch/x86/kvm/pmu_amd.c
350 index 6bc656abbe66d..799b9a3144e3b 100644
351 --- a/arch/x86/kvm/pmu_amd.c
352 +++ b/arch/x86/kvm/pmu_amd.c
353 @@ -44,6 +44,22 @@ static struct kvm_event_hw_type_mapping amd_event_mapping[] = {
354 [7] = { 0xd1, 0x00, PERF_COUNT_HW_STALLED_CYCLES_BACKEND },
355 };
356
357 +/* duplicated from amd_f17h_perfmon_event_map. */
358 +static struct kvm_event_hw_type_mapping amd_f17h_event_mapping[] = {
359 + [0] = { 0x76, 0x00, PERF_COUNT_HW_CPU_CYCLES },
360 + [1] = { 0xc0, 0x00, PERF_COUNT_HW_INSTRUCTIONS },
361 + [2] = { 0x60, 0xff, PERF_COUNT_HW_CACHE_REFERENCES },
362 + [3] = { 0x64, 0x09, PERF_COUNT_HW_CACHE_MISSES },
363 + [4] = { 0xc2, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
364 + [5] = { 0xc3, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
365 + [6] = { 0x87, 0x02, PERF_COUNT_HW_STALLED_CYCLES_FRONTEND },
366 + [7] = { 0x87, 0x01, PERF_COUNT_HW_STALLED_CYCLES_BACKEND },
367 +};
368 +
369 +/* amd_pmc_perf_hw_id depends on these being the same size */
370 +static_assert(ARRAY_SIZE(amd_event_mapping) ==
371 + ARRAY_SIZE(amd_f17h_event_mapping));
372 +
373 static unsigned int get_msr_base(struct kvm_pmu *pmu, enum pmu_type type)
374 {
375 struct kvm_vcpu *vcpu = pmu_to_vcpu(pmu);
376 @@ -126,21 +142,27 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr,
377 return &pmu->gp_counters[msr_to_index(msr)];
378 }
379
380 -static unsigned amd_find_arch_event(struct kvm_pmu *pmu,
381 - u8 event_select,
382 - u8 unit_mask)
383 +static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
384 {
385 + struct kvm_event_hw_type_mapping *event_mapping;
386 + u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
387 + u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
388 int i;
389
390 + if (guest_cpuid_family(pmc->vcpu) >= 0x17)
391 + event_mapping = amd_f17h_event_mapping;
392 + else
393 + event_mapping = amd_event_mapping;
394 +
395 for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
396 - if (amd_event_mapping[i].eventsel == event_select
397 - && amd_event_mapping[i].unit_mask == unit_mask)
398 + if (event_mapping[i].eventsel == event_select
399 + && event_mapping[i].unit_mask == unit_mask)
400 break;
401
402 if (i == ARRAY_SIZE(amd_event_mapping))
403 return PERF_COUNT_HW_MAX;
404
405 - return amd_event_mapping[i].event_type;
406 + return event_mapping[i].event_type;
407 }
408
409 /* return PERF_COUNT_HW_MAX as AMD doesn't have fixed events */
410 @@ -300,7 +322,7 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
411 }
412
413 struct kvm_pmu_ops amd_pmu_ops = {
414 - .find_arch_event = amd_find_arch_event,
415 + .pmc_perf_hw_id = amd_pmc_perf_hw_id,
416 .find_fixed_event = amd_find_fixed_event,
417 .pmc_is_enabled = amd_pmc_is_enabled,
418 .pmc_idx_to_pmc = amd_pmc_idx_to_pmc,
419 diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c
420 index 181e352d38de4..395566018ba95 100644
421 --- a/arch/x86/kvm/vmx/pmu_intel.c
422 +++ b/arch/x86/kvm/vmx/pmu_intel.c
423 @@ -64,10 +64,11 @@ static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
424 reprogram_counter(pmu, bit);
425 }
426
427 -static unsigned intel_find_arch_event(struct kvm_pmu *pmu,
428 - u8 event_select,
429 - u8 unit_mask)
430 +static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc)
431 {
432 + struct kvm_pmu *pmu = pmc_to_pmu(pmc);
433 + u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
434 + u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
435 int i;
436
437 for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++)
438 @@ -374,7 +375,7 @@ static void intel_pmu_reset(struct kvm_vcpu *vcpu)
439 }
440
441 struct kvm_pmu_ops intel_pmu_ops = {
442 - .find_arch_event = intel_find_arch_event,
443 + .pmc_perf_hw_id = intel_pmc_perf_hw_id,
444 .find_fixed_event = intel_find_fixed_event,
445 .pmc_is_enabled = intel_pmc_is_enabled,
446 .pmc_idx_to_pmc = intel_pmc_idx_to_pmc,
447 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
448 index 1f7dfa5aa42da..6dd77e426889b 100644
449 --- a/arch/x86/kvm/x86.c
450 +++ b/arch/x86/kvm/x86.c
451 @@ -68,6 +68,7 @@
452 #include <asm/mshyperv.h>
453 #include <asm/hypervisor.h>
454 #include <asm/intel_pt.h>
455 +#include <asm/emulate_prefix.h>
456 #include <clocksource/hyperv_timer.h>
457
458 #define CREATE_TRACE_POINTS
459 @@ -5583,6 +5584,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
460
461 int handle_ud(struct kvm_vcpu *vcpu)
462 {
463 + static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX };
464 int emul_type = EMULTYPE_TRAP_UD;
465 char sig[5]; /* ud2; .ascii "kvm" */
466 struct x86_exception e;
467 @@ -5590,7 +5592,7 @@ int handle_ud(struct kvm_vcpu *vcpu)
468 if (force_emulation_prefix &&
469 kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu),
470 sig, sizeof(sig), &e) == 0 &&
471 - memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) {
472 + memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) {
473 kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig));
474 emul_type = EMULTYPE_TRAP_UD_FORCED;
475 }
476 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
477 index 0b5862ba6a75e..404279563891a 100644
478 --- a/arch/x86/lib/insn.c
479 +++ b/arch/x86/lib/insn.c
480 @@ -13,6 +13,8 @@
481 #include <asm/inat.h>
482 #include <asm/insn.h>
483
484 +#include <asm/emulate_prefix.h>
485 +
486 /* Verify next sizeof(t) bytes can be on the same instruction */
487 #define validate_next(t, insn, n) \
488 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
489 @@ -58,6 +60,36 @@ void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64)
490 insn->addr_bytes = 4;
491 }
492
493 +static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
494 +static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
495 +
496 +static int __insn_get_emulate_prefix(struct insn *insn,
497 + const insn_byte_t *prefix, size_t len)
498 +{
499 + size_t i;
500 +
501 + for (i = 0; i < len; i++) {
502 + if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i])
503 + goto err_out;
504 + }
505 +
506 + insn->emulate_prefix_size = len;
507 + insn->next_byte += len;
508 +
509 + return 1;
510 +
511 +err_out:
512 + return 0;
513 +}
514 +
515 +static void insn_get_emulate_prefix(struct insn *insn)
516 +{
517 + if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix)))
518 + return;
519 +
520 + __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix));
521 +}
522 +
523 /**
524 * insn_get_prefixes - scan x86 instruction prefix bytes
525 * @insn: &struct insn containing instruction
526 @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn)
527 if (prefixes->got)
528 return;
529
530 + insn_get_emulate_prefix(insn);
531 +
532 nb = 0;
533 lb = 0;
534 b = peek_next(insn_byte_t, insn);
535 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
536 index bfb00d3b091f1..52dd517ff5419 100644
537 --- a/drivers/block/drbd/drbd_nl.c
538 +++ b/drivers/block/drbd/drbd_nl.c
539 @@ -791,9 +791,11 @@ int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info)
540 mutex_lock(&adm_ctx.resource->adm_mutex);
541
542 if (info->genlhdr->cmd == DRBD_ADM_PRIMARY)
543 - retcode = drbd_set_role(adm_ctx.device, R_PRIMARY, parms.assume_uptodate);
544 + retcode = (enum drbd_ret_code)drbd_set_role(adm_ctx.device,
545 + R_PRIMARY, parms.assume_uptodate);
546 else
547 - retcode = drbd_set_role(adm_ctx.device, R_SECONDARY, 0);
548 + retcode = (enum drbd_ret_code)drbd_set_role(adm_ctx.device,
549 + R_SECONDARY, 0);
550
551 mutex_unlock(&adm_ctx.resource->adm_mutex);
552 genl_lock();
553 @@ -1971,7 +1973,7 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
554 drbd_flush_workqueue(&connection->sender_work);
555
556 rv = _drbd_request_state(device, NS(disk, D_ATTACHING), CS_VERBOSE);
557 - retcode = rv; /* FIXME: Type mismatch. */
558 + retcode = (enum drbd_ret_code)rv;
559 drbd_resume_io(device);
560 if (rv < SS_SUCCESS)
561 goto fail;
562 @@ -2696,7 +2698,8 @@ int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
563 }
564 rcu_read_unlock();
565
566 - retcode = conn_request_state(connection, NS(conn, C_UNCONNECTED), CS_VERBOSE);
567 + retcode = (enum drbd_ret_code)conn_request_state(connection,
568 + NS(conn, C_UNCONNECTED), CS_VERBOSE);
569
570 conn_reconfig_done(connection);
571 mutex_unlock(&adm_ctx.resource->adm_mutex);
572 @@ -2809,7 +2812,7 @@ int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info)
573 mutex_lock(&adm_ctx.resource->adm_mutex);
574 rv = conn_try_disconnect(connection, parms.force_disconnect);
575 if (rv < SS_SUCCESS)
576 - retcode = rv; /* FIXME: Type mismatch. */
577 + retcode = (enum drbd_ret_code)rv;
578 else
579 retcode = NO_ERROR;
580 mutex_unlock(&adm_ctx.resource->adm_mutex);
581 diff --git a/drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c b/drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
582 index d03165e71dc65..0be817f8cae6b 100644
583 --- a/drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
584 +++ b/drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
585 @@ -53,8 +53,8 @@
586 */
587
588 struct gpio_service *dal_gpio_service_create(
589 - enum dce_version dce_version_major,
590 - enum dce_version dce_version_minor,
591 + enum dce_version dce_version,
592 + enum dce_environment dce_environment,
593 struct dc_context *ctx)
594 {
595 struct gpio_service *service;
596 @@ -67,14 +67,14 @@ struct gpio_service *dal_gpio_service_create(
597 return NULL;
598 }
599
600 - if (!dal_hw_translate_init(&service->translate, dce_version_major,
601 - dce_version_minor)) {
602 + if (!dal_hw_translate_init(&service->translate, dce_version,
603 + dce_environment)) {
604 BREAK_TO_DEBUGGER();
605 goto failure_1;
606 }
607
608 - if (!dal_hw_factory_init(&service->factory, dce_version_major,
609 - dce_version_minor)) {
610 + if (!dal_hw_factory_init(&service->factory, dce_version,
611 + dce_environment)) {
612 BREAK_TO_DEBUGGER();
613 goto failure_1;
614 }
615 diff --git a/drivers/gpu/drm/amd/display/include/gpio_service_interface.h b/drivers/gpu/drm/amd/display/include/gpio_service_interface.h
616 index 9c55d247227ea..7e3240e73c1fc 100644
617 --- a/drivers/gpu/drm/amd/display/include/gpio_service_interface.h
618 +++ b/drivers/gpu/drm/amd/display/include/gpio_service_interface.h
619 @@ -42,8 +42,8 @@ void dal_gpio_destroy(
620 struct gpio **ptr);
621
622 struct gpio_service *dal_gpio_service_create(
623 - enum dce_version dce_version_major,
624 - enum dce_version dce_version_minor,
625 + enum dce_version dce_version,
626 + enum dce_environment dce_environment,
627 struct dc_context *ctx);
628
629 struct gpio *dal_gpio_service_create_irq(
630 diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
631 index 198a91c765314..5c21c06189c1d 100644
632 --- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
633 +++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
634 @@ -1452,7 +1452,7 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct i915_vma *vma)
635
636 urelocs = u64_to_user_ptr(entry->relocs_ptr);
637 remain = entry->relocation_count;
638 - if (unlikely(remain > N_RELOC(ULONG_MAX)))
639 + if (unlikely((unsigned long)remain > N_RELOC(ULONG_MAX)))
640 return -EINVAL;
641
642 /*
643 diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c
644 index 3496dfa1b5217..e613cd5707e27 100644
645 --- a/drivers/net/can/grcan.c
646 +++ b/drivers/net/can/grcan.c
647 @@ -241,7 +241,7 @@ struct grcan_device_config {
648 .rxsize = GRCAN_DEFAULT_BUFFER_SIZE, \
649 }
650
651 -#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 0x4100
652 +#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 4100
653 #define GRLIB_VERSION_MASK 0xffff
654
655 /* GRCAN private data structure */
656 @@ -1137,7 +1137,7 @@ static int grcan_close(struct net_device *dev)
657 return 0;
658 }
659
660 -static int grcan_transmit_catch_up(struct net_device *dev, int budget)
661 +static void grcan_transmit_catch_up(struct net_device *dev)
662 {
663 struct grcan_priv *priv = netdev_priv(dev);
664 unsigned long flags;
665 @@ -1145,7 +1145,7 @@ static int grcan_transmit_catch_up(struct net_device *dev, int budget)
666
667 spin_lock_irqsave(&priv->lock, flags);
668
669 - work_done = catch_up_echo_skb(dev, budget, true);
670 + work_done = catch_up_echo_skb(dev, -1, true);
671 if (work_done) {
672 if (!priv->resetting && !priv->closing &&
673 !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
674 @@ -1159,8 +1159,6 @@ static int grcan_transmit_catch_up(struct net_device *dev, int budget)
675 }
676
677 spin_unlock_irqrestore(&priv->lock, flags);
678 -
679 - return work_done;
680 }
681
682 static int grcan_receive(struct net_device *dev, int budget)
683 @@ -1242,19 +1240,13 @@ static int grcan_poll(struct napi_struct *napi, int budget)
684 struct net_device *dev = priv->dev;
685 struct grcan_registers __iomem *regs = priv->regs;
686 unsigned long flags;
687 - int tx_work_done, rx_work_done;
688 - int rx_budget = budget / 2;
689 - int tx_budget = budget - rx_budget;
690 + int work_done;
691
692 - /* Half of the budget for receiveing messages */
693 - rx_work_done = grcan_receive(dev, rx_budget);
694 + work_done = grcan_receive(dev, budget);
695
696 - /* Half of the budget for transmitting messages as that can trigger echo
697 - * frames being received
698 - */
699 - tx_work_done = grcan_transmit_catch_up(dev, tx_budget);
700 + grcan_transmit_catch_up(dev);
701
702 - if (rx_work_done < rx_budget && tx_work_done < tx_budget) {
703 + if (work_done < budget) {
704 napi_complete(napi);
705
706 /* Guarantee no interference with a running reset that otherwise
707 @@ -1271,7 +1263,7 @@ static int grcan_poll(struct napi_struct *napi, int budget)
708 spin_unlock_irqrestore(&priv->lock, flags);
709 }
710
711 - return rx_work_done + tx_work_done;
712 + return work_done;
713 }
714
715 /* Work tx bug by waiting while for the risky situation to clear. If that fails,
716 @@ -1656,6 +1648,7 @@ exit_free_candev:
717 static int grcan_probe(struct platform_device *ofdev)
718 {
719 struct device_node *np = ofdev->dev.of_node;
720 + struct device_node *sysid_parent;
721 struct resource *res;
722 u32 sysid, ambafreq;
723 int irq, err;
724 @@ -1665,10 +1658,15 @@ static int grcan_probe(struct platform_device *ofdev)
725 /* Compare GRLIB version number with the first that does not
726 * have the tx bug (see start_xmit)
727 */
728 - err = of_property_read_u32(np, "systemid", &sysid);
729 - if (!err && ((sysid & GRLIB_VERSION_MASK)
730 - >= GRCAN_TXBUG_SAFE_GRLIB_VERSION))
731 - txbug = false;
732 + sysid_parent = of_find_node_by_path("/ambapp0");
733 + if (sysid_parent) {
734 + of_node_get(sysid_parent);
735 + err = of_property_read_u32(sysid_parent, "systemid", &sysid);
736 + if (!err && ((sysid & GRLIB_VERSION_MASK) >=
737 + GRCAN_TXBUG_SAFE_GRLIB_VERSION))
738 + txbug = false;
739 + of_node_put(sysid_parent);
740 + }
741
742 err = of_property_read_u32(np, "freq", &ambafreq);
743 if (err) {
744 diff --git a/drivers/net/ethernet/netronome/nfp/nfp_asm.c b/drivers/net/ethernet/netronome/nfp/nfp_asm.c
745 index b04b83687fe21..488615434e4ae 100644
746 --- a/drivers/net/ethernet/netronome/nfp/nfp_asm.c
747 +++ b/drivers/net/ethernet/netronome/nfp/nfp_asm.c
748 @@ -196,7 +196,7 @@ int swreg_to_unrestricted(swreg dst, swreg lreg, swreg rreg,
749 }
750
751 reg->dst_lmextn = swreg_lmextn(dst);
752 - reg->src_lmextn = swreg_lmextn(lreg) | swreg_lmextn(rreg);
753 + reg->src_lmextn = swreg_lmextn(lreg) || swreg_lmextn(rreg);
754
755 return 0;
756 }
757 @@ -277,7 +277,7 @@ int swreg_to_restricted(swreg dst, swreg lreg, swreg rreg,
758 }
759
760 reg->dst_lmextn = swreg_lmextn(dst);
761 - reg->src_lmextn = swreg_lmextn(lreg) | swreg_lmextn(rreg);
762 + reg->src_lmextn = swreg_lmextn(lreg) || swreg_lmextn(rreg);
763
764 return 0;
765 }
766 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
767 index e2ed8e08cc7ad..d1cabccc02b7a 100644
768 --- a/fs/proc/kcore.c
769 +++ b/fs/proc/kcore.c
770 @@ -193,8 +193,6 @@ kclist_add_private(unsigned long pfn, unsigned long nr_pages, void *arg)
771 return 1;
772
773 p = pfn_to_page(pfn);
774 - if (!memmap_valid_within(pfn, p, page_zone(p)))
775 - return 1;
776
777 ent = kmalloc(sizeof(*ent), GFP_KERNEL);
778 if (!ent)
779 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
780 index e4f9df955040f..b138ddad619e8 100644
781 --- a/include/linux/mmzone.h
782 +++ b/include/linux/mmzone.h
783 @@ -1438,37 +1438,6 @@ void memory_present(int nid, unsigned long start, unsigned long end);
784 #define pfn_valid_within(pfn) (1)
785 #endif
786
787 -#ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
788 -/*
789 - * pfn_valid() is meant to be able to tell if a given PFN has valid memmap
790 - * associated with it or not. This means that a struct page exists for this
791 - * pfn. The caller cannot assume the page is fully initialized in general.
792 - * Hotplugable pages might not have been onlined yet. pfn_to_online_page()
793 - * will ensure the struct page is fully online and initialized. Special pages
794 - * (e.g. ZONE_DEVICE) are never onlined and should be treated accordingly.
795 - *
796 - * In FLATMEM, it is expected that holes always have valid memmap as long as
797 - * there is valid PFNs either side of the hole. In SPARSEMEM, it is assumed
798 - * that a valid section has a memmap for the entire section.
799 - *
800 - * However, an ARM, and maybe other embedded architectures in the future
801 - * free memmap backing holes to save memory on the assumption the memmap is
802 - * never used. The page_zone linkages are then broken even though pfn_valid()
803 - * returns true. A walker of the full memmap must then do this additional
804 - * check to ensure the memmap they are looking at is sane by making sure
805 - * the zone and PFN linkages are still valid. This is expensive, but walkers
806 - * of the full memmap are extremely rare.
807 - */
808 -bool memmap_valid_within(unsigned long pfn,
809 - struct page *page, struct zone *zone);
810 -#else
811 -static inline bool memmap_valid_within(unsigned long pfn,
812 - struct page *page, struct zone *zone)
813 -{
814 - return true;
815 -}
816 -#endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
817 -
818 #endif /* !__GENERATING_BOUNDS.H */
819 #endif /* !__ASSEMBLY__ */
820 #endif /* _LINUX_MMZONE_H */
821 diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
822 index 14d00cc10e22e..ecad25900ad78 100644
823 --- a/include/net/bluetooth/hci_core.h
824 +++ b/include/net/bluetooth/hci_core.h
825 @@ -34,6 +34,9 @@
826 /* HCI priority */
827 #define HCI_PRIO_MAX 7
828
829 +/* HCI maximum id value */
830 +#define HCI_MAX_ID 10000
831 +
832 /* HCI Core structures */
833 struct inquiry_data {
834 bdaddr_t bdaddr;
835 diff --git a/mm/memory.c b/mm/memory.c
836 index 8a72fd3e73bf1..d416e329442dc 100644
837 --- a/mm/memory.c
838 +++ b/mm/memory.c
839 @@ -4801,6 +4801,8 @@ long copy_huge_page_from_user(struct page *dst_page,
840 if (rc)
841 break;
842
843 + flush_dcache_page(subpage);
844 +
845 cond_resched();
846 }
847 return ret_val;
848 diff --git a/mm/migrate.c b/mm/migrate.c
849 index 5092ef2aa8a1f..6948d6ec0fd03 100644
850 --- a/mm/migrate.c
851 +++ b/mm/migrate.c
852 @@ -994,9 +994,12 @@ static int move_to_new_page(struct page *newpage, struct page *page,
853 if (!PageMappingFlags(page))
854 page->mapping = NULL;
855
856 - if (likely(!is_zone_device_page(newpage)))
857 - flush_dcache_page(newpage);
858 + if (likely(!is_zone_device_page(newpage))) {
859 + int i, nr = compound_nr(newpage);
860
861 + for (i = 0; i < nr; i++)
862 + flush_dcache_page(newpage + i);
863 + }
864 }
865 out:
866 return rc;
867 diff --git a/mm/mmzone.c b/mm/mmzone.c
868 index 4686fdc23bb96..f337831affc2d 100644
869 --- a/mm/mmzone.c
870 +++ b/mm/mmzone.c
871 @@ -72,20 +72,6 @@ struct zoneref *__next_zones_zonelist(struct zoneref *z,
872 return z;
873 }
874
875 -#ifdef CONFIG_ARCH_HAS_HOLES_MEMORYMODEL
876 -bool memmap_valid_within(unsigned long pfn,
877 - struct page *page, struct zone *zone)
878 -{
879 - if (page_to_pfn(page) != pfn)
880 - return false;
881 -
882 - if (page_zone(page) != zone)
883 - return false;
884 -
885 - return true;
886 -}
887 -#endif /* CONFIG_ARCH_HAS_HOLES_MEMORYMODEL */
888 -
889 void lruvec_init(struct lruvec *lruvec)
890 {
891 enum lru_list lru;
892 diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
893 index 640ff2bd9a693..6fa66e2111ea7 100644
894 --- a/mm/userfaultfd.c
895 +++ b/mm/userfaultfd.c
896 @@ -53,6 +53,8 @@ static int mcopy_atomic_pte(struct mm_struct *dst_mm,
897 /* don't free the page */
898 goto out;
899 }
900 +
901 + flush_dcache_page(page);
902 } else {
903 page = *pagep;
904 *pagep = NULL;
905 @@ -572,6 +574,7 @@ retry:
906 err = -EFAULT;
907 goto out;
908 }
909 + flush_dcache_page(page);
910 goto retry;
911 } else
912 BUG_ON(page);
913 diff --git a/mm/vmstat.c b/mm/vmstat.c
914 index a8222041bd44d..240fe2153ca9e 100644
915 --- a/mm/vmstat.c
916 +++ b/mm/vmstat.c
917 @@ -1444,10 +1444,6 @@ static void pagetypeinfo_showblockcount_print(struct seq_file *m,
918 if (!page)
919 continue;
920
921 - /* Watch for unexpected holes punched in the memmap */
922 - if (!memmap_valid_within(pfn, page, zone))
923 - continue;
924 -
925 if (page_zone(page) != zone)
926 continue;
927
928 diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
929 index 2edaa601df13a..2ebb6480b6ecb 100644
930 --- a/net/bluetooth/hci_core.c
931 +++ b/net/bluetooth/hci_core.c
932 @@ -3304,10 +3304,10 @@ int hci_register_dev(struct hci_dev *hdev)
933 */
934 switch (hdev->dev_type) {
935 case HCI_PRIMARY:
936 - id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL);
937 + id = ida_simple_get(&hci_index_ida, 0, HCI_MAX_ID, GFP_KERNEL);
938 break;
939 case HCI_AMP:
940 - id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL);
941 + id = ida_simple_get(&hci_index_ida, 1, HCI_MAX_ID, GFP_KERNEL);
942 break;
943 default:
944 return -EINVAL;
945 @@ -3316,7 +3316,7 @@ int hci_register_dev(struct hci_dev *hdev)
946 if (id < 0)
947 return id;
948
949 - sprintf(hdev->name, "hci%d", id);
950 + snprintf(hdev->name, sizeof(hdev->name), "hci%d", id);
951 hdev->id = id;
952
953 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
954 diff --git a/tools/arch/x86/include/asm/emulate_prefix.h b/tools/arch/x86/include/asm/emulate_prefix.h
955 new file mode 100644
956 index 0000000000000..70f5b98a52869
957 --- /dev/null
958 +++ b/tools/arch/x86/include/asm/emulate_prefix.h
959 @@ -0,0 +1,14 @@
960 +/* SPDX-License-Identifier: GPL-2.0 */
961 +#ifndef _ASM_X86_EMULATE_PREFIX_H
962 +#define _ASM_X86_EMULATE_PREFIX_H
963 +
964 +/*
965 + * Virt escape sequences to trigger instruction emulation;
966 + * ideally these would decode to 'whole' instruction and not destroy
967 + * the instruction stream; sadly this is not true for the 'kvm' one :/
968 + */
969 +
970 +#define __XEN_EMULATE_PREFIX 0x0f,0x0b,0x78,0x65,0x6e /* ud2 ; .ascii "xen" */
971 +#define __KVM_EMULATE_PREFIX 0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */
972 +
973 +#endif
974 diff --git a/tools/arch/x86/include/asm/insn.h b/tools/arch/x86/include/asm/insn.h
975 index d7f0ae8f3c442..52c6262e6bfd1 100644
976 --- a/tools/arch/x86/include/asm/insn.h
977 +++ b/tools/arch/x86/include/asm/insn.h
978 @@ -45,6 +45,7 @@ struct insn {
979 struct insn_field immediate2; /* for 64bit imm or seg16 */
980 };
981
982 + int emulate_prefix_size;
983 insn_attr_t attr;
984 unsigned char opnd_bytes;
985 unsigned char addr_bytes;
986 @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn)
987 return (insn->vex_prefix.nbytes == 4);
988 }
989
990 +static inline int insn_has_emulate_prefix(struct insn *insn)
991 +{
992 + return !!insn->emulate_prefix_size;
993 +}
994 +
995 /* Ensure this instruction is decoded completely */
996 static inline int insn_complete(struct insn *insn)
997 {
998 diff --git a/tools/arch/x86/lib/insn.c b/tools/arch/x86/lib/insn.c
999 index 79e048f1d9028..0151dfc6da616 100644
1000 --- a/tools/arch/x86/lib/insn.c
1001 +++ b/tools/arch/x86/lib/insn.c
1002 @@ -13,6 +13,8 @@
1003 #include "../include/asm/inat.h"
1004 #include "../include/asm/insn.h"
1005
1006 +#include "../include/asm/emulate_prefix.h"
1007 +
1008 /* Verify next sizeof(t) bytes can be on the same instruction */
1009 #define validate_next(t, insn, n) \
1010 ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
1011 @@ -58,6 +60,36 @@ void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64)
1012 insn->addr_bytes = 4;
1013 }
1014
1015 +static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
1016 +static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
1017 +
1018 +static int __insn_get_emulate_prefix(struct insn *insn,
1019 + const insn_byte_t *prefix, size_t len)
1020 +{
1021 + size_t i;
1022 +
1023 + for (i = 0; i < len; i++) {
1024 + if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i])
1025 + goto err_out;
1026 + }
1027 +
1028 + insn->emulate_prefix_size = len;
1029 + insn->next_byte += len;
1030 +
1031 + return 1;
1032 +
1033 +err_out:
1034 + return 0;
1035 +}
1036 +
1037 +static void insn_get_emulate_prefix(struct insn *insn)
1038 +{
1039 + if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix)))
1040 + return;
1041 +
1042 + __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix));
1043 +}
1044 +
1045 /**
1046 * insn_get_prefixes - scan x86 instruction prefix bytes
1047 * @insn: &struct insn containing instruction
1048 @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn)
1049 if (prefixes->got)
1050 return;
1051
1052 + insn_get_emulate_prefix(insn);
1053 +
1054 nb = 0;
1055 lb = 0;
1056 b = peek_next(insn_byte_t, insn);
1057 diff --git a/tools/objtool/sync-check.sh b/tools/objtool/sync-check.sh
1058 index c3ae1e8ae1194..2a1261bfbb625 100755
1059 --- a/tools/objtool/sync-check.sh
1060 +++ b/tools/objtool/sync-check.sh
1061 @@ -4,6 +4,7 @@
1062 FILES='
1063 arch/x86/include/asm/inat_types.h
1064 arch/x86/include/asm/orc_types.h
1065 +arch/x86/include/asm/emulate_prefix.h
1066 arch/x86/lib/x86-opcode-map.txt
1067 arch/x86/tools/gen-insn-attr-x86.awk
1068 '
1069 @@ -46,4 +47,4 @@ done
1070 check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
1071 check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
1072 check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
1073 -check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'
1074 +check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"'
1075 diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
1076 index cea13cb987d00..499235a411628 100755
1077 --- a/tools/perf/check-headers.sh
1078 +++ b/tools/perf/check-headers.sh
1079 @@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h
1080 arch/x86/include/asm/required-features.h
1081 arch/x86/include/asm/cpufeatures.h
1082 arch/x86/include/asm/inat_types.h
1083 +arch/x86/include/asm/emulate_prefix.h
1084 arch/x86/include/uapi/asm/prctl.h
1085 arch/x86/lib/x86-opcode-map.txt
1086 arch/x86/tools/gen-insn-attr-x86.awk
1087 @@ -116,7 +117,7 @@ check lib/ctype.c '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B
1088 check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
1089 check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
1090 check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
1091 -check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'
1092 +check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"'
1093
1094 # diff non-symmetric files
1095 check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl