Conflicts: tools/perf/check-headers.sh
Unified · Split
| @@ -7,9 +7,11 @@ · 6 unmodified lines | |||
| 7 | # define __ASM_FORM_RAW(x) x | 7 | # define __ASM_FORM_RAW(x) x |
| 8 | # define __ASM_FORM_COMMA(x) x, | 8 | # define __ASM_FORM_COMMA(x) x, |
| 9 | #else | 9 | #else |
| 10 | # define __ASM_FORM(x) " " #x " " | 10 | #include <linux/stringify.h> |
| 11 | # define __ASM_FORM_RAW(x) #x | 11 | |
| 12 | # define __ASM_FORM_COMMA(x) " " #x "," | 12 | # define __ASM_FORM(x) " " __stringify(x) " " |
| 13 | # define __ASM_FORM_RAW(x) __stringify(x) | ||
| 14 | # define __ASM_FORM_COMMA(x) " " __stringify(x) "," | ||
| 13 | #endif | 15 | #endif |
| 14 | 16 | ||
| 15 | #ifndef __x86_64__ | 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 | struct insn_field immediate2; /* for 64bit imm or seg16 */ | 45 | struct insn_field immediate2; /* for 64bit imm or seg16 */ |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | int emulate_prefix_size; | ||
| 48 | insn_attr_t attr; | 49 | insn_attr_t attr; |
| 49 | unsigned char opnd_bytes; | 50 | unsigned char opnd_bytes; |
| 50 | unsigned char addr_bytes; | 51 | unsigned char addr_bytes; |
| @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines | |||
| 128 | return (insn->vex_prefix.nbytes == 4); | 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 | /* Ensure this instruction is decoded completely */ | 137 | /* Ensure this instruction is decoded completely */ |
| 132 | static inline int insn_complete(struct insn *insn) | 138 | static inline int insn_complete(struct insn *insn) |
| 133 | { | 139 | { |
| @@ -379,12 +379,9 @@ struct xen_pmu_arch { · 378 unmodified lines | |||
| 379 | * Prefix forces emulation of some non-trapping instructions. | 379 | * Prefix forces emulation of some non-trapping instructions. |
| 380 | * Currently only CPUID. | 380 | * Currently only CPUID. |
| 381 | */ | 381 | */ |
| 382 | #ifdef __ASSEMBLY__ | 382 | #include <asm/emulate_prefix.h> |
| 383 | #define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ; | 383 | |
| 384 | #define XEN_CPUID XEN_EMULATE_PREFIX cpuid | 384 | #define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;) |
| 385 | #else | 385 | #define XEN_CPUID XEN_EMULATE_PREFIX __ASM_FORM(cpuid) |
| 386 | #define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; " | ||
| 387 | #define XEN_CPUID XEN_EMULATE_PREFIX "cpuid" | ||
| 388 | #endif | ||
| 389 | 386 | ||
| 390 | #endif /* _ASM_X86_XEN_INTERFACE_H */ | 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 | kernel_insn_init(insn, dest, MAX_INSN_SIZE); | 351 | kernel_insn_init(insn, dest, MAX_INSN_SIZE); |
| 352 | insn_get_length(insn); | 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 | /* Another subsystem puts a breakpoint, failed to recover */ | 358 | /* Another subsystem puts a breakpoint, failed to recover */ |
| 355 | if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION) | 359 | if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION) |
| 356 | return 0; | 360 | return 0; |
| @@ -68,6 +68,7 @@ · 67 unmodified lines | |||
| 68 | #include <asm/mshyperv.h> | 68 | #include <asm/mshyperv.h> |
| 69 | #include <asm/hypervisor.h> | 69 | #include <asm/hypervisor.h> |
| 70 | #include <asm/intel_pt.h> | 70 | #include <asm/intel_pt.h> |
| 71 | #include <asm/emulate_prefix.h> | ||
| 71 | #include <clocksource/hyperv_timer.h> | 72 | #include <clocksource/hyperv_timer.h> |
| 72 | 73 | ||
| 73 | #define CREATE_TRACE_POINTS | 74 | #define CREATE_TRACE_POINTS |
| @@ -5471,6 +5472,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); · 5397 unmodified lines | |||
| 5471 | 5472 | ||
| 5472 | int handle_ud(struct kvm_vcpu *vcpu) | 5473 | int handle_ud(struct kvm_vcpu *vcpu) |
| 5473 | { | 5474 | { |
| 5475 | static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX }; | ||
| 5474 | int emul_type = EMULTYPE_TRAP_UD; | 5476 | int emul_type = EMULTYPE_TRAP_UD; |
| 5475 | char sig[5]; /* ud2; .ascii "kvm" */ | 5477 | char sig[5]; /* ud2; .ascii "kvm" */ |
| 5476 | struct x86_exception e; | 5478 | struct x86_exception e; |
| @@ -5478,7 +5480,7 @@ int handle_ud(struct kvm_vcpu *vcpu) · 1 unmodified line | |||
| 5478 | if (force_emulation_prefix && | 5480 | if (force_emulation_prefix && |
| 5479 | kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu), | 5481 | kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu), |
| 5480 | sig, sizeof(sig), &e) == 0 && | 5482 | sig, sizeof(sig), &e) == 0 && |
| 5481 | memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) { | 5483 | memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) { |
| 5482 | kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); | 5484 | kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); |
| 5483 | emul_type = EMULTYPE_TRAP_UD_FORCED; | 5485 | emul_type = EMULTYPE_TRAP_UD_FORCED; |
| 5484 | } | 5486 | } |
| @@ -13,6 +13,8 @@ · 12 unmodified lines | |||
| 13 | #include <asm/inat.h> | 13 | #include <asm/inat.h> |
| 14 | #include <asm/insn.h> | 14 | #include <asm/insn.h> |
| 15 | 15 | ||
| 16 | #include <asm/emulate_prefix.h> | ||
| 17 | |||
| 16 | /* Verify next sizeof(t) bytes can be on the same instruction */ | 18 | /* Verify next sizeof(t) bytes can be on the same instruction */ |
| 17 | #define validate_next(t, insn, n) \ | 19 | #define validate_next(t, insn, n) \ |
| 18 | ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) | 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 | insn->addr_bytes = 4; | 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 | * insn_get_prefixes - scan x86 instruction prefix bytes | 94 | * insn_get_prefixes - scan x86 instruction prefix bytes |
| 63 | * @insn: &struct insn containing instruction | 95 | * @insn: &struct insn containing instruction |
| @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines | |||
| 76 | if (prefixes->got) | 108 | if (prefixes->got) |
| 77 | return; | 109 | return; |
| 78 | 110 | ||
| 111 | insn_get_emulate_prefix(insn); | ||
| 112 | |||
| 79 | nb = 0; | 113 | nb = 0; |
| 80 | lb = 0; | 114 | lb = 0; |
| 81 | b = peek_next(insn_byte_t, insn); | 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 | struct insn_field immediate2; /* for 64bit imm or seg16 */ | 45 | struct insn_field immediate2; /* for 64bit imm or seg16 */ |
| 46 | }; | 46 | }; |
| 47 | 47 | ||
| 48 | int emulate_prefix_size; | ||
| 48 | insn_attr_t attr; | 49 | insn_attr_t attr; |
| 49 | unsigned char opnd_bytes; | 50 | unsigned char opnd_bytes; |
| 50 | unsigned char addr_bytes; | 51 | unsigned char addr_bytes; |
| @@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines | |||
| 128 | return (insn->vex_prefix.nbytes == 4); | 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 | /* Ensure this instruction is decoded completely */ | 137 | /* Ensure this instruction is decoded completely */ |
| 132 | static inline int insn_complete(struct insn *insn) | 138 | static inline int insn_complete(struct insn *insn) |
| 133 | { | 139 | { |
| @@ -13,6 +13,8 @@ · 12 unmodified lines | |||
| 13 | #include "../include/asm/inat.h" | 13 | #include "../include/asm/inat.h" |
| 14 | #include "../include/asm/insn.h" | 14 | #include "../include/asm/insn.h" |
| 15 | 15 | ||
| 16 | #include "../include/asm/emulate_prefix.h" | ||
| 17 | |||
| 16 | /* Verify next sizeof(t) bytes can be on the same instruction */ | 18 | /* Verify next sizeof(t) bytes can be on the same instruction */ |
| 17 | #define validate_next(t, insn, n) \ | 19 | #define validate_next(t, insn, n) \ |
| 18 | ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr) | 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 | insn->addr_bytes = 4; | 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 | * insn_get_prefixes - scan x86 instruction prefix bytes | 94 | * insn_get_prefixes - scan x86 instruction prefix bytes |
| 63 | * @insn: &struct insn containing instruction | 95 | * @insn: &struct insn containing instruction |
| @@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines | |||
| 76 | if (prefixes->got) | 108 | if (prefixes->got) |
| 77 | return; | 109 | return; |
| 78 | 110 | ||
| 111 | insn_get_emulate_prefix(insn); | ||
| 112 | |||
| 79 | nb = 0; | 113 | nb = 0; |
| 80 | lb = 0; | 114 | lb = 0; |
| 81 | b = peek_next(insn_byte_t, insn); | 115 | b = peek_next(insn_byte_t, insn); |
| @@ -4,6 +4,7 @@ · 3 unmodified lines | |||
| 4 | FILES=' | 4 | FILES=' |
| 5 | arch/x86/include/asm/inat_types.h | 5 | arch/x86/include/asm/inat_types.h |
| 6 | arch/x86/include/asm/orc_types.h | 6 | arch/x86/include/asm/orc_types.h |
| 7 | arch/x86/include/asm/emulate_prefix.h | ||
| 7 | arch/x86/lib/x86-opcode-map.txt | 8 | arch/x86/lib/x86-opcode-map.txt |
| 8 | arch/x86/tools/gen-insn-attr-x86.awk | 9 | arch/x86/tools/gen-insn-attr-x86.awk |
| 9 | ' | 10 | ' |
| @@ -46,6 +47,6 @@ done · 36 unmodified lines | |||
| 46 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' | 47 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' |
| 47 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' | 48 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' |
| 48 | check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"' | 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 | cd - | 52 | cd - |
| @@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h · 27 unmodified lines | |||
| 28 | arch/x86/include/asm/required-features.h | 28 | arch/x86/include/asm/required-features.h |
| 29 | arch/x86/include/asm/cpufeatures.h | 29 | arch/x86/include/asm/cpufeatures.h |
| 30 | arch/x86/include/asm/inat_types.h | 30 | arch/x86/include/asm/inat_types.h |
| 31 | arch/x86/include/asm/emulate_prefix.h | ||
| 31 | arch/x86/include/asm/irq_vectors.h | 32 | arch/x86/include/asm/irq_vectors.h |
| 32 | arch/x86/include/asm/msr-index.h | 33 | arch/x86/include/asm/msr-index.h |
| 33 | arch/x86/include/uapi/asm/prctl.h | 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 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' | 119 | check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"' |
| 119 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' | 120 | check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"' |
| 120 | check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"' | 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 | # diff non-symmetric files | 124 | # diff non-symmetric files |
| 124 | check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl | 125 | check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl |