]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge branch 'x86/core' into perf/core, to resolve conflicts and to pick up completed...
authorIngo Molnar <mingo@kernel.org>
Mon, 25 Nov 2019 08:09:27 +0000 (09:09 +0100)
committerIngo Molnar <mingo@kernel.org>
Mon, 25 Nov 2019 08:09:27 +0000 (09:09 +0100)
Conflicts:
tools/perf/check-headers.sh

Signed-off-by: Ingo Molnar <mingo@kernel.org>
12 files changed:
arch/x86/include/asm/asm.h
arch/x86/include/asm/emulate_prefix.h [new file with mode: 0644]
arch/x86/include/asm/insn.h
arch/x86/include/asm/xen/interface.h
arch/x86/kernel/kprobes/core.c
arch/x86/kvm/x86.c
arch/x86/lib/insn.c
tools/arch/x86/include/asm/emulate_prefix.h [new file with mode: 0644]
tools/arch/x86/include/asm/insn.h
tools/arch/x86/lib/insn.c
tools/objtool/sync-check.sh
tools/perf/check-headers.sh

index 3ff577c0b1024af1ed0e0fc9f2805f5a8ba5e804..1b563f9167eaeb05d097be1b0f3b7e25a6415cb9 100644 (file)
@@ -7,9 +7,11 @@
 # define __ASM_FORM_RAW(x)     x
 # define __ASM_FORM_COMMA(x) x,
 #else
-# define __ASM_FORM(x) " " #x " "
-# define __ASM_FORM_RAW(x)     #x
-# define __ASM_FORM_COMMA(x) " " #x ","
+#include <linux/stringify.h>
+
+# define __ASM_FORM(x) " " __stringify(x) " "
+# define __ASM_FORM_RAW(x)     __stringify(x)
+# define __ASM_FORM_COMMA(x) " " __stringify(x) ","
 #endif
 
 #ifndef __x86_64__
diff --git a/arch/x86/include/asm/emulate_prefix.h b/arch/x86/include/asm/emulate_prefix.h
new file mode 100644 (file)
index 0000000..70f5b98
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_EMULATE_PREFIX_H
+#define _ASM_X86_EMULATE_PREFIX_H
+
+/*
+ * Virt escape sequences to trigger instruction emulation;
+ * ideally these would decode to 'whole' instruction and not destroy
+ * the instruction stream; sadly this is not true for the 'kvm' one :/
+ */
+
+#define __XEN_EMULATE_PREFIX  0x0f,0x0b,0x78,0x65,0x6e  /* ud2 ; .ascii "xen" */
+#define __KVM_EMULATE_PREFIX  0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */
+
+#endif
index 154f27be8bfcb24bf7ba11f9db20c6dc60abdf54..5c1ae3eff9d4275c9fefa0eae1b5a3095aee5238 100644 (file)
@@ -45,6 +45,7 @@ struct insn {
                struct insn_field immediate2;   /* for 64bit imm or seg16 */
        };
 
+       int     emulate_prefix_size;
        insn_attr_t attr;
        unsigned char opnd_bytes;
        unsigned char addr_bytes;
@@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn)
        return (insn->vex_prefix.nbytes == 4);
 }
 
+static inline int insn_has_emulate_prefix(struct insn *insn)
+{
+       return !!insn->emulate_prefix_size;
+}
+
 /* Ensure this instruction is decoded completely */
 static inline int insn_complete(struct insn *insn)
 {
index 62ca03ef5c657c68ecb312a9a811ea2916f731c5..9139b3e86316114c0eb8c7cb8d50998d0c918a02 100644 (file)
@@ -379,12 +379,9 @@ struct xen_pmu_arch {
  * Prefix forces emulation of some non-trapping instructions.
  * Currently only CPUID.
  */
-#ifdef __ASSEMBLY__
-#define XEN_EMULATE_PREFIX .byte 0x0f,0x0b,0x78,0x65,0x6e ;
-#define XEN_CPUID          XEN_EMULATE_PREFIX cpuid
-#else
-#define XEN_EMULATE_PREFIX ".byte 0x0f,0x0b,0x78,0x65,0x6e ; "
-#define XEN_CPUID          XEN_EMULATE_PREFIX "cpuid"
-#endif
+#include <asm/emulate_prefix.h>
+
+#define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;)
+#define XEN_CPUID          XEN_EMULATE_PREFIX __ASM_FORM(cpuid)
 
 #endif /* _ASM_X86_XEN_INTERFACE_H */
index 43fc13c831af0c77db4ff29bbfa8e4b7c9f8bd48..4f13af7cbcdb17f169e0a2a02003573f08442da5 100644 (file)
@@ -351,6 +351,10 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, struct insn *insn)
        kernel_insn_init(insn, dest, MAX_INSN_SIZE);
        insn_get_length(insn);
 
+       /* We can not probe force emulate prefixed instruction */
+       if (insn_has_emulate_prefix(insn))
+               return 0;
+
        /* Another subsystem puts a breakpoint, failed to recover */
        if (insn->opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
                return 0;
index 5d530521f11ddb5cd98bb3816f661cd51475ccba..783aa8d141bfa4da0fcc045282da0e5769307dbe 100644 (file)
@@ -68,6 +68,7 @@
 #include <asm/mshyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/intel_pt.h>
+#include <asm/emulate_prefix.h>
 #include <clocksource/hyperv_timer.h>
 
 #define CREATE_TRACE_POINTS
@@ -5471,6 +5472,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
 
 int handle_ud(struct kvm_vcpu *vcpu)
 {
+       static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX };
        int emul_type = EMULTYPE_TRAP_UD;
        char sig[5]; /* ud2; .ascii "kvm" */
        struct x86_exception e;
@@ -5478,7 +5480,7 @@ int handle_ud(struct kvm_vcpu *vcpu)
        if (force_emulation_prefix &&
            kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu),
                                sig, sizeof(sig), &e) == 0 &&
-           memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) {
+           memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) {
                kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig));
                emul_type = EMULTYPE_TRAP_UD_FORCED;
        }
index 0b5862ba6a75e04b069dd02c8917bb6e598fba0f..404279563891ac4db6e3f0909baa3af4f839ba54 100644 (file)
@@ -13,6 +13,8 @@
 #include <asm/inat.h>
 #include <asm/insn.h>
 
+#include <asm/emulate_prefix.h>
+
 /* Verify next sizeof(t) bytes can be on the same instruction */
 #define validate_next(t, insn, n)      \
        ((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)
                insn->addr_bytes = 4;
 }
 
+static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
+static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
+
+static int __insn_get_emulate_prefix(struct insn *insn,
+                                    const insn_byte_t *prefix, size_t len)
+{
+       size_t i;
+
+       for (i = 0; i < len; i++) {
+               if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i])
+                       goto err_out;
+       }
+
+       insn->emulate_prefix_size = len;
+       insn->next_byte += len;
+
+       return 1;
+
+err_out:
+       return 0;
+}
+
+static void insn_get_emulate_prefix(struct insn *insn)
+{
+       if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix)))
+               return;
+
+       __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix));
+}
+
 /**
  * insn_get_prefixes - scan x86 instruction prefix bytes
  * @insn:      &struct insn containing instruction
@@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn)
        if (prefixes->got)
                return;
 
+       insn_get_emulate_prefix(insn);
+
        nb = 0;
        lb = 0;
        b = peek_next(insn_byte_t, insn);
diff --git a/tools/arch/x86/include/asm/emulate_prefix.h b/tools/arch/x86/include/asm/emulate_prefix.h
new file mode 100644 (file)
index 0000000..70f5b98
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_EMULATE_PREFIX_H
+#define _ASM_X86_EMULATE_PREFIX_H
+
+/*
+ * Virt escape sequences to trigger instruction emulation;
+ * ideally these would decode to 'whole' instruction and not destroy
+ * the instruction stream; sadly this is not true for the 'kvm' one :/
+ */
+
+#define __XEN_EMULATE_PREFIX  0x0f,0x0b,0x78,0x65,0x6e  /* ud2 ; .ascii "xen" */
+#define __KVM_EMULATE_PREFIX  0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kvm" */
+
+#endif
index 37a4c390750bc0a0236a2a33836b3cf17888a54e..568854b14d0a57d49ac5d2eabfafa054cf66bec2 100644 (file)
@@ -45,6 +45,7 @@ struct insn {
                struct insn_field immediate2;   /* for 64bit imm or seg16 */
        };
 
+       int     emulate_prefix_size;
        insn_attr_t attr;
        unsigned char opnd_bytes;
        unsigned char addr_bytes;
@@ -128,6 +129,11 @@ static inline int insn_is_evex(struct insn *insn)
        return (insn->vex_prefix.nbytes == 4);
 }
 
+static inline int insn_has_emulate_prefix(struct insn *insn)
+{
+       return !!insn->emulate_prefix_size;
+}
+
 /* Ensure this instruction is decoded completely */
 static inline int insn_complete(struct insn *insn)
 {
index 79e048f1d90280c999547a928a6cb402481f375d..0151dfc6da616d92acaece78515df5967eb2e1a5 100644 (file)
@@ -13,6 +13,8 @@
 #include "../include/asm/inat.h"
 #include "../include/asm/insn.h"
 
+#include "../include/asm/emulate_prefix.h"
+
 /* Verify next sizeof(t) bytes can be on the same instruction */
 #define validate_next(t, insn, n)      \
        ((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)
                insn->addr_bytes = 4;
 }
 
+static const insn_byte_t xen_prefix[] = { __XEN_EMULATE_PREFIX };
+static const insn_byte_t kvm_prefix[] = { __KVM_EMULATE_PREFIX };
+
+static int __insn_get_emulate_prefix(struct insn *insn,
+                                    const insn_byte_t *prefix, size_t len)
+{
+       size_t i;
+
+       for (i = 0; i < len; i++) {
+               if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i])
+                       goto err_out;
+       }
+
+       insn->emulate_prefix_size = len;
+       insn->next_byte += len;
+
+       return 1;
+
+err_out:
+       return 0;
+}
+
+static void insn_get_emulate_prefix(struct insn *insn)
+{
+       if (__insn_get_emulate_prefix(insn, xen_prefix, sizeof(xen_prefix)))
+               return;
+
+       __insn_get_emulate_prefix(insn, kvm_prefix, sizeof(kvm_prefix));
+}
+
 /**
  * insn_get_prefixes - scan x86 instruction prefix bytes
  * @insn:      &struct insn containing instruction
@@ -76,6 +108,8 @@ void insn_get_prefixes(struct insn *insn)
        if (prefixes->got)
                return;
 
+       insn_get_emulate_prefix(insn);
+
        nb = 0;
        lb = 0;
        b = peek_next(insn_byte_t, insn);
index 0a832e265a50766f6df3129747d4aeac57e59bc4..9bd04bbed01e2b2d34a2ef6eb10ff947d53a06d3 100755 (executable)
@@ -4,6 +4,7 @@
 FILES='
 arch/x86/include/asm/inat_types.h
 arch/x86/include/asm/orc_types.h
+arch/x86/include/asm/emulate_prefix.h
 arch/x86/lib/x86-opcode-map.txt
 arch/x86/tools/gen-insn-attr-x86.awk
 '
@@ -46,6 +47,6 @@ done
 check arch/x86/include/asm/inat.h     '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
 check arch/x86/include/asm/insn.h     '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
 check arch/x86/lib/inat.c             '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
-check arch/x86/lib/insn.c             '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'
+check arch/x86/lib/insn.c             '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"'
 
 cd -
index 48290a0c917cf714a89f27835e59b80ce88b746d..a1dc1672435201513b3e3ad3a7bbbab59b4a32ec 100755 (executable)
@@ -28,6 +28,7 @@ arch/x86/include/asm/disabled-features.h
 arch/x86/include/asm/required-features.h
 arch/x86/include/asm/cpufeatures.h
 arch/x86/include/asm/inat_types.h
+arch/x86/include/asm/emulate_prefix.h
 arch/x86/include/asm/irq_vectors.h
 arch/x86/include/asm/msr-index.h
 arch/x86/include/uapi/asm/prctl.h
@@ -118,7 +119,7 @@ check lib/ctype.c                 '-I "^EXPORT_SYMBOL" -I "^#include <linux/export.h>" -B
 check arch/x86/include/asm/inat.h     '-I "^#include [\"<]\(asm/\)*inat_types.h[\">]"'
 check arch/x86/include/asm/insn.h     '-I "^#include [\"<]\(asm/\)*inat.h[\">]"'
 check arch/x86/lib/inat.c            '-I "^#include [\"<]\(../include/\)*asm/insn.h[\">]"'
-check arch/x86/lib/insn.c            '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]"'
+check arch/x86/lib/insn.c             '-I "^#include [\"<]\(../include/\)*asm/in\(at\|sn\).h[\">]" -I "^#include [\"<]\(../include/\)*asm/emulate_prefix.h[\">]"'
 
 # diff non-symmetric files
 check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/syscalls/syscall_64.tbl