History

Merge branch 'x86/core' into perf/core, to resolve conflicts and to pick up completed topic tree

Conflicts: tools/perf/check-headers.sh

Ingo Molnar committed 6 years ago

Commit ceb9e772 parents c494cd6 004e8dc12 files · +128 −13Browse files

Unified · Split

12 files
  1. arch/x86/include/asm/asm.h +5 −3
  2. arch/x86/include/asm/emulate_prefix.h +14 −0
  3. arch/x86/include/asm/insn.h +6 −0
  4. arch/x86/include/asm/xen/interface.h +4 −7
  5. arch/x86/kernel/kprobes/core.c +4 −0
  6. arch/x86/kvm/x86.c +3 −1
  7. arch/x86/lib/insn.c +34 −0
  8. tools/arch/x86/include/asm/emulate_prefix.h +14 −0
  9. tools/arch/x86/include/asm/insn.h +6 −0
  10. tools/arch/x86/lib/insn.c +34 −0
  11. tools/objtool/sync-check.sh +2 −1
  12. tools/perf/check-headers.sh +2 −1
arch/x86/include/asm/asm.h+5−3
@@ -7,9 +7,11 @@ · 6 unmodified lines
7# define __ASM_FORM_RAW(x) x7# define __ASM_FORM_RAW(x) x
8# define __ASM_FORM_COMMA(x) x,8# define __ASM_FORM_COMMA(x) x,
9#else9#else
10# define __ASM_FORM(x) " " #x " "10#include <linux/stringify.h>
11# define __ASM_FORM_RAW(x) #x11
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#endif15#endif
14 16
15#ifndef __x86_64__17#ifndef __x86_64__
arch/x86/include/asm/emulate_prefix.h+14−0
@@ -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
arch/x86/include/asm/insn.h+6−0
@@ -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
132static 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 */
132static inline int insn_complete(struct insn *insn)138static inline int insn_complete(struct insn *insn)
133{139{
arch/x86/include/asm/xen/interface.h+4−7
@@ -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 cpuid384#define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;)
385#else385#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 */
arch/x86/kernel/kprobes/core.c+4−0
@@ -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;
arch/x86/kvm/x86.c+3−1
@@ -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_POINTS74#define CREATE_TRACE_POINTS
@@ -5471,6 +5472,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); · 5397 unmodified lines
5471 5472
5472int handle_ud(struct kvm_vcpu *vcpu)5473int 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 }
arch/x86/lib/insn.c+34−0
@@ -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
63static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
64static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
65
66static 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
81err_out:
82 return 0;
83}
84
85static 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 bytes94 * insn_get_prefixes - scan x86 instruction prefix bytes
63 * @insn: &struct insn containing instruction95 * @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);
tools/arch/x86/include/asm/emulate_prefix.h+14−0
@@ -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
tools/arch/x86/include/asm/insn.h+6−0
@@ -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
132static 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 */
132static inline int insn_complete(struct insn *insn)138static inline int insn_complete(struct insn *insn)
133{139{
tools/arch/x86/lib/insn.c+34−0
@@ -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
63static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
64static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
65
66static 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
81err_out:
82 return 0;
83}
84
85static 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 bytes94 * insn_get_prefixes - scan x86 instruction prefix bytes
63 * @insn: &struct insn containing instruction95 * @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);
tools/objtool/sync-check.sh+2−1
@@ -4,6 +4,7 @@ · 3 unmodified lines
4FILES='4FILES='
5arch/x86/include/asm/inat_types.h5arch/x86/include/asm/inat_types.h
6arch/x86/include/asm/orc_types.h6arch/x86/include/asm/orc_types.h
7arch/x86/include/asm/emulate_prefix.h
7arch/x86/lib/x86-opcode-map.txt8arch/x86/lib/x86-opcode-map.txt
8arch/x86/tools/gen-insn-attr-x86.awk9arch/x86/tools/gen-insn-attr-x86.awk
9'10'
@@ -46,6 +47,6 @@ done · 36 unmodified lines
46check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'47check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
47check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'48check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
48check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'49check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
49check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'50check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"'
50 51
51cd -52cd -
tools/perf/check-headers.sh+2−1
@@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h · 27 unmodified lines
28arch/x86/include/asm/required-features.h28arch/x86/include/asm/required-features.h
29arch/x86/include/asm/cpufeatures.h29arch/x86/include/asm/cpufeatures.h
30arch/x86/include/asm/inat_types.h30arch/x86/include/asm/inat_types.h
31arch/x86/include/asm/emulate_prefix.h
31arch/x86/include/asm/irq_vectors.h32arch/x86/include/asm/irq_vectors.h
32arch/x86/include/asm/msr-index.h33arch/x86/include/asm/msr-index.h
33arch/x86/include/uapi/asm/prctl.h34arch/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
118check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'119check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
119check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'120check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
120check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'121check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
121check arch/x86/lib/insn.c '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'122check 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 files124# diff non-symmetric files
124check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl125check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t