Conflicts: tools/perf/check-headers.sh
Unified · Split
| @@ -7,9 +7,11 @@ · 6 unmodified lines | ||
| 7 | 7 | # define __ASM_FORM_RAW(x) x |
| 8 | 8 | # define __ASM_FORM_COMMA(x) x, |
| 9 | 9 | #else |
| 10 | −# define __ASM_FORM(x) " " #x " " | |
| 11 | −# define __ASM_FORM_RAW(x) #x | |
| 12 | −# define __ASM_FORM_COMMA(x) " " #x "," | |
| 10 | +#include <linux/stringify.h> | |
| 11 | + | |
| 12 | +# define __ASM_FORM(x) " " __stringify(x) " " | |
| 13 | +# define __ASM_FORM_RAW(x) __stringify(x) | |
| 14 | +# define __ASM_FORM_COMMA(x) " " __stringify(x) "," | |
| 13 | 15 | #endif |
| 14 | 16 | |
| 15 | 17 | #ifndef __x86_64__ |
| @@ -0,0 +1,14 @@ | ||
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | +#ifndef _ASM_X86_EMULATE_PREFIX_H | |
| 3 | +#define _ASM_X86_EMULATE_PREFIX_H | |
| 4 | + | |
| 5 | +/* | |
| 6 | + * Virt escape sequences to trigger instruction emulation; | |
| 7 | + * ideally these would decode to 'whole' instruction and not destroy | |
| 8 | + * the instruction stream; sadly this is not true for the 'kvm' one :/ | |
| 9 | + */ | |
| 10 | + | |
| 11 | +#define __XEN_EMULATE_PREFIX 0x0f,0x0b,0x78,0x65,0x6e /* ud2 ; .ascii "xen" */ | |
| 12 | +#define __KVM_EMULATE_PREFIX 0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */ | |
| 13 | + | |
| 14 | +#endif | |
| @@ -45,6 +45,7 @@ struct insn { · 44 unmodified lines | ||
| 45 | 45 | struct insn_field immediate2; /* for 64bit imm or seg16 */ |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | + int emulate_prefix_size; | |
| 48 | 49 | insn_attr_t attr; |
| 49 | 50 | unsigned char opnd_bytes; |
| 50 | 51 | unsigned char addr_bytes; |
| @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines | ||
| 128 | 129 | return (insn->vex_prefix.nbytes == 4); |
| 129 | 130 | } |
| 130 | 131 | |
| 132 | +static inline int insn_has_emulate_prefix(struct insn *insn) | |
| 133 | +{ | |
| 134 | + return !!insn->emulate_prefix_size; | |
| 135 | +} | |
| 136 | + | |
| 131 | 137 | /* Ensure this instruction is decoded completely */ |
| 132 | 138 | static inline int insn_complete(struct insn *insn) |
| 133 | 139 | { |
| @@ -379,12 +379,9 @@ struct xen_pmu_arch { · 378 unmodified lines | ||
| 379 | 379 | * Prefix forces emulation of some non-trapping instructions. |
| 380 | 380 | * Currently only CPUID. |
| 381 | 381 | */ |
| 382 | −#ifdef __ASSEMBLY__ | |
| 383 | −#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; | |
| 384 | −#define XEN_CPUID XEN_EMULATE_PREFIX cpuid | |
| 385 | −#else | |
| 386 | −#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " | |
| 387 | −#define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" | |
| 388 | −#endif | |
| 382 | +#include <asm/emulate_prefix.h> | |
| 383 | + | |
| 384 | +#define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;) | |
| 385 | +#define XEN_CPUID XEN_EMULATE_PREFIX __ASM_FORM(cpuid) | |
| 389 | 386 | |
| 390 | 387 | #endif /* _ASM_X86_XEN_INTERFACE_H */ |
| @@ -351,6 +351,10 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn) · 350 unmodified lines | ||
| 351 | 351 | kernel_insn_init(insn, dest, MAX_INSN_SIZE); |
| 352 | 352 | insn_get_length(insn); |
| 353 | 353 | |
| 354 | + /* We can not probe force emulate prefixed instruction */ | |
| 355 | + if (insn_has_emulate_prefix(insn)) | |
| 356 | + return 0; | |
| 357 | + | |
| 354 | 358 | /* Another subsystem puts a breakpoint, failed to recover */ |
| 355 | 359 | if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION) |
| 356 | 360 | return 0; |
| @@ -68,6 +68,7 @@ · 67 unmodified lines | ||
| 68 | 68 | #include <asm/mshyperv.h> |
| 69 | 69 | #include <asm/hypervisor.h> |
| 70 | 70 | #include <asm/intel_pt.h> |
| 71 | +#include <asm/emulate_prefix.h> | |
| 71 | 72 | #include <clocksource/hyperv_timer.h> |
| 72 | 73 | |
| 73 | 74 | #define CREATE_TRACE_POINTS |
| @@ -5471,6 +5472,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); · 5397 unmodified lines | ||
| 5471 | 5472 | |
| 5472 | 5473 | int handle_ud(struct kvm_vcpu *vcpu) |
| 5473 | 5474 | { |
| 5475 | + static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX }; | |
| 5474 | 5476 | int emul_type = EMULTYPE_TRAP_UD; |
| 5475 | 5477 | char sig[5]; /* ud2; .ascii "kvm" */ |
| 5476 | 5478 | struct x86_exception e; |
| @@ -5478,7 +5480,7 @@ int handle_ud(struct kvm_vcpu *vcpu) · 1 unmodified line | ||
| 5478 | 5480 | if (force_emulation_prefix && |
| 5479 | 5481 | kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu), |
| 5480 | 5482 | sig, sizeof(sig), &e) == 0 && |
| 5481 | − memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) { | |
| 5483 | + memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) { | |
| 5482 | 5484 | kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); |
| 5483 | 5485 | emul_type = EMULTYPE_TRAP_UD_FORCED; |
| 5484 | 5486 | } |
| @@ -13,6 +13,8 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <asm/inat.h> |
| 14 | 14 | #include <asm/insn.h> |
| 15 | 15 | |
| 16 | +#include <asm/emulate_prefix.h> | |
| 17 | + | |
| 16 | 18 | /* Verify next sizeof(t) bytes can be on the same instruction */ |
| 17 | 19 | #define validate_next(t, insn, n) \ |
| 18 | 20 | ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) |
| @@ -58,6 +60,36 @@ void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64) · 39 unmodified lines | ||
| 58 | 60 | insn->addr_bytes = 4; |
| 59 | 61 | } |
| 60 | 62 | |
| 63 | +static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX }; | |
| 64 | +static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX }; | |
| 65 | + | |
| 66 | +static int __insn_get_emulate_prefix(struct insn *insn, | |
| 67 | + const insn_byte_t *prefix, size_t len) | |
| 68 | +{ | |
| 69 | + size_t i; | |
| 70 | + | |
| 71 | + for (i = 0; i < len; i++) { | |
| 72 | + if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i]) | |
| 73 | + goto err_out; | |
| 74 | + } | |
| 75 | + | |
| 76 | + insn->emulate_prefix_size = len; | |
| 77 | + insn->next_byte += len; | |
| 78 | + | |
| 79 | + return 1; | |
| 80 | + | |
| 81 | +err_out: | |
| 82 | + return 0; | |
| 83 | +} | |
| 84 | + | |
| 85 | +static void insn_get_emulate_prefix(struct insn *insn) | |
| 86 | +{ | |
| 87 | + if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix))) | |
| 88 | + return; | |
| 89 | + | |
| 90 | + __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix)); | |
| 91 | +} | |
| 92 | + | |
| 61 | 93 | /** |
| 62 | 94 | * insn_get_prefixes - scan x86 instruction prefix bytes |
| 63 | 95 | * @insn: &struct insn containing instruction |
| @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines | ||
| 76 | 108 | if (prefixes->got) |
| 77 | 109 | return; |
| 78 | 110 | |
| 111 | + insn_get_emulate_prefix(insn); | |
| 112 | + | |
| 79 | 113 | nb = 0; |
| 80 | 114 | lb = 0; |
| 81 | 115 | b = peek_next(insn_byte_t, insn); |
| @@ -0,0 +1,14 @@ | ||
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
| 2 | +#ifndef _ASM_X86_EMULATE_PREFIX_H | |
| 3 | +#define _ASM_X86_EMULATE_PREFIX_H | |
| 4 | + | |
| 5 | +/* | |
| 6 | + * Virt escape sequences to trigger instruction emulation; | |
| 7 | + * ideally these would decode to 'whole' instruction and not destroy | |
| 8 | + * the instruction stream; sadly this is not true for the 'kvm' one :/ | |
| 9 | + */ | |
| 10 | + | |
| 11 | +#define __XEN_EMULATE_PREFIX 0x0f,0x0b,0x78,0x65,0x6e /* ud2 ; .ascii "xen" */ | |
| 12 | +#define __KVM_EMULATE_PREFIX 0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */ | |
| 13 | + | |
| 14 | +#endif | |
| @@ -45,6 +45,7 @@ struct insn { · 44 unmodified lines | ||
| 45 | 45 | struct insn_field immediate2; /* for 64bit imm or seg16 */ |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | + int emulate_prefix_size; | |
| 48 | 49 | insn_attr_t attr; |
| 49 | 50 | unsigned char opnd_bytes; |
| 50 | 51 | unsigned char addr_bytes; |
| @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines | ||
| 128 | 129 | return (insn->vex_prefix.nbytes == 4); |
| 129 | 130 | } |
| 130 | 131 | |
| 132 | +static inline int insn_has_emulate_prefix(struct insn *insn) | |
| 133 | +{ | |
| 134 | + return !!insn->emulate_prefix_size; | |
| 135 | +} | |
| 136 | + | |
| 131 | 137 | /* Ensure this instruction is decoded completely */ |
| 132 | 138 | static inline int insn_complete(struct insn *insn) |
| 133 | 139 | { |
| @@ -13,6 +13,8 @@ · 12 unmodified lines | ||
| 13 | 13 | #include "../include/asm/inat.h" |
| 14 | 14 | #include "../include/asm/insn.h" |
| 15 | 15 | |
| 16 | +#include "../include/asm/emulate_prefix.h" | |
| 17 | + | |
| 16 | 18 | /* Verify next sizeof(t) bytes can be on the same instruction */ |
| 17 | 19 | #define validate_next(t, insn, n) \ |
| 18 | 20 | ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) |
| @@ -58,6 +60,36 @@ void insn_init(struct insn *insn, const void *kaddr, int buf_len, int x86_64) · 39 unmodified lines | ||
| 58 | 60 | insn->addr_bytes = 4; |
| 59 | 61 | } |
| 60 | 62 | |
| 63 | +static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX }; | |
| 64 | +static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX }; | |
| 65 | + | |
| 66 | +static int __insn_get_emulate_prefix(struct insn *insn, | |
| 67 | + const insn_byte_t *prefix, size_t len) | |
| 68 | +{ | |
| 69 | + size_t i; | |
| 70 | + | |
| 71 | + for (i = 0; i < len; i++) { | |
| 72 | + if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i]) | |
| 73 | + goto err_out; | |
| 74 | + } | |
| 75 | + | |
| 76 | + insn->emulate_prefix_size = len; | |
| 77 | + insn->next_byte += len; | |
| 78 | + | |
| 79 | + return 1; | |
| 80 | + | |
| 81 | +err_out: | |
| 82 | + return 0; | |
| 83 | +} | |
| 84 | + | |
| 85 | +static void insn_get_emulate_prefix(struct insn *insn) | |
| 86 | +{ | |
| 87 | + if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix))) | |
| 88 | + return; | |
| 89 | + | |
| 90 | + __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix)); | |
| 91 | +} | |
| 92 | + | |
| 61 | 93 | /** |
| 62 | 94 | * insn_get_prefixes - scan x86 instruction prefix bytes |
| 63 | 95 | * @insn: &struct insn containing instruction |
| @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines | ||
| 76 | 108 | if (prefixes->got) |
| 77 | 109 | return; |
| 78 | 110 | |
| 111 | + insn_get_emulate_prefix(insn); | |
| 112 | + | |
| 79 | 113 | nb = 0; |
| 80 | 114 | lb = 0; |
| 81 | 115 | b = peek_next(insn_byte_t, insn); |
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | FILES=' |
| 5 | 5 | arch/x86/include/asm/inat_types.h |
| 6 | 6 | arch/x86/include/asm/orc_types.h |
| 7 | +arch/x86/include/asm/emulate_prefix.h | |
| 7 | 8 | arch/x86/lib/x86-opcode-map.txt |
| 8 | 9 | arch/x86/tools/gen-insn-attr-x86.awk |
| 9 | 10 | ' |
| @@ -46,6 +47,6 @@ done · 36 unmodified lines | ||
| 46 | 47 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' |
| 47 | 48 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' |
| 48 | 49 | check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"' |
| 49 | −check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"' | |
| 50 | +check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"' | |
| 50 | 51 | |
| 51 | 52 | cd - |
| @@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h · 27 unmodified lines | ||
| 28 | 28 | arch/x86/include/asm/required-features.h |
| 29 | 29 | arch/x86/include/asm/cpufeatures.h |
| 30 | 30 | arch/x86/include/asm/inat_types.h |
| 31 | +arch/x86/include/asm/emulate_prefix.h | |
| 31 | 32 | arch/x86/include/asm/irq_vectors.h |
| 32 | 33 | arch/x86/include/asm/msr-index.h |
| 33 | 34 | arch/x86/include/uapi/asm/prctl.h |
| @@ -118,7 +119,7 @@ check lib/ctype.c '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B · 84 unmodified lines | ||
| 118 | 119 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' |
| 119 | 120 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' |
| 120 | 121 | check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"' |
| 121 | −check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"' | |
| 122 | +check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"' | |
| 122 | 123 | |
| 123 | 124 | # diff non-symmetric files |
| 124 | 125 | check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl |