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
77 # define __ASM_FORM_RAW(x) x
88 # define __ASM_FORM_COMMA(x) x,
99 #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) ","
1315 #endif
1416
1517 #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
4545 struct insn_field immediate2; /* for 64bit imm or seg16 */
4646 };
4747
48+ int emulate_prefix_size;
4849 insn_attr_t attr;
4950 unsigned char opnd_bytes;
5051 unsigned char addr_bytes;
@@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines
128129 return (insn->vex_prefix.nbytes == 4);
129130 }
130131
132+static inline int insn_has_emulate_prefix(struct insn *insn)
133+{
134+ return !!insn->emulate_prefix_size;
135+}
136+
131137 /* Ensure this instruction is decoded completely */
132138 static inline int insn_complete(struct insn *insn)
133139 {
arch/x86/include/asm/xen/interface.h+4−7
@@ -379,12 +379,9 @@ struct xen_pmu_arch { · 378 unmodified lines
379379 * Prefix forces emulation of some non-trapping instructions.
380380 * Currently only CPUID.
381381 */
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)
389386
390387 #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
351351 kernel_insn_init(insn, dest, MAX_INSN_SIZE);
352352 insn_get_length(insn);
353353
354+ /* We can not probe force emulate prefixed instruction */
355+ if (insn_has_emulate_prefix(insn))
356+ return 0;
357+
354358 /* Another subsystem puts a breakpoint, failed to recover */
355359 if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
356360 return 0;
arch/x86/kvm/x86.c+3−1
@@ -68,6 +68,7 @@ · 67 unmodified lines
6868 #include <asm/mshyperv.h>
6969 #include <asm/hypervisor.h>
7070 #include <asm/intel_pt.h>
71+#include <asm/emulate_prefix.h>
7172 #include <clocksource/hyperv_timer.h>
7273
7374 #define CREATE_TRACE_POINTS
@@ -5471,6 +5472,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); · 5397 unmodified lines
54715472
54725473 int handle_ud(struct kvm_vcpu *vcpu)
54735474 {
5475+ static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX };
54745476 int emul_type = EMULTYPE_TRAP_UD;
54755477 char sig[5]; /* ud2; .ascii "kvm" */
54765478 struct x86_exception e;
@@ -5478,7 +5480,7 @@ int handle_ud(struct kvm_vcpu *vcpu) · 1 unmodified line
54785480 if (force_emulation_prefix &&
54795481 kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu),
54805482 sig, sizeof(sig), &e) == 0 &&
5481− memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) {
5483+ memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) {
54825484 kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig));
54835485 emul_type = EMULTYPE_TRAP_UD_FORCED;
54845486 }
arch/x86/lib/insn.c+34−0
@@ -13,6 +13,8 @@ · 12 unmodified lines
1313 #include <asm/inat.h>
1414 #include <asm/insn.h>
1515
16+#include <asm/emulate_prefix.h>
17+
1618 /* Verify next sizeof(t) bytes can be on the same instruction */
1719 #define validate_next(t, insn, n) \
1820 ((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
5860 insn->addr_bytes = 4;
5961 }
6062
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+
6193 /**
6294 * insn_get_prefixes - scan x86 instruction prefix bytes
6395 * @insn: &struct insn containing instruction
@@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines
76108 if (prefixes->got)
77109 return;
78110
111+ insn_get_emulate_prefix(insn);
112+
79113 nb = 0;
80114 lb = 0;
81115 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
4545 struct insn_field immediate2; /* for 64bit imm or seg16 */
4646 };
4747
48+ int emulate_prefix_size;
4849 insn_attr_t attr;
4950 unsigned char opnd_bytes;
5051 unsigned char addr_bytes;
@@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn) · 77 unmodified lines
128129 return (insn->vex_prefix.nbytes == 4);
129130 }
130131
132+static inline int insn_has_emulate_prefix(struct insn *insn)
133+{
134+ return !!insn->emulate_prefix_size;
135+}
136+
131137 /* Ensure this instruction is decoded completely */
132138 static inline int insn_complete(struct insn *insn)
133139 {
tools/arch/x86/lib/insn.c+34−0
@@ -13,6 +13,8 @@ · 12 unmodified lines
1313 #include "../include/asm/inat.h"
1414 #include "../include/asm/insn.h"
1515
16+#include "../include/asm/emulate_prefix.h"
17+
1618 /* Verify next sizeof(t) bytes can be on the same instruction */
1719 #define validate_next(t, insn, n) \
1820 ((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
5860 insn->addr_bytes = 4;
5961 }
6062
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+
6193 /**
6294 * insn_get_prefixes - scan x86 instruction prefix bytes
6395 * @insn: &struct insn containing instruction
@@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn) · 12 unmodified lines
76108 if (prefixes->got)
77109 return;
78110
111+ insn_get_emulate_prefix(insn);
112+
79113 nb = 0;
80114 lb = 0;
81115 b = peek_next(insn_byte_t, insn);
tools/objtool/sync-check.sh+2−1
@@ -4,6 +4,7 @@ · 3 unmodified lines
44 FILES='
55 arch/x86/include/asm/inat_types.h
66 arch/x86/include/asm/orc_types.h
7+arch/x86/include/asm/emulate_prefix.h
78 arch/x86/lib/x86-opcode-map.txt
89 arch/x86/tools/gen-insn-attr-x86.awk
910 '
@@ -46,6 +47,6 @@ done · 36 unmodified lines
4647 check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
4748 check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
4849 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[\">]"'
5051
5152 cd -
tools/perf/check-headers.sh+2−1
@@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h · 27 unmodified lines
2828 arch/x86/include/asm/required-features.h
2929 arch/x86/include/asm/cpufeatures.h
3030 arch/x86/include/asm/inat_types.h
31+arch/x86/include/asm/emulate_prefix.h
3132 arch/x86/include/asm/irq_vectors.h
3233 arch/x86/include/asm/msr-index.h
3334 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
118119 check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
119120 check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
120121 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[\">]"'
122123
123124 # diff non-symmetric files
124125 check_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