Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: xen: kvm: Gather the definition of emulate prefixes

Gather the emulate prefixes, which forcibly make the following
instruction emulated on virtualization, in one place.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Juergen Gross <jgross@suse.com>
Cc: x86@kernel.org
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: xen-devel@lists.xenproject.org
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/156777563917.25081.7286628561790289995.stgit@devnote2

authored by

Masami Hiramatsu and committed by
Peter Zijlstra
b3dc0695 f7919fd9

+21 -8
+14
arch/x86/include/asm/emulate_prefix.h
··· 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
+4 -7
arch/x86/include/asm/xen/interface.h
··· 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 */
+3 -1
arch/x86/kvm/x86.c
··· 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 ··· 5447 5446 5448 5447 int handle_ud(struct kvm_vcpu *vcpu) 5449 5448 { 5449 + static const char kvm_emulate_prefix[] = { __KVM_EMULATE_PREFIX }; 5450 5450 int emul_type = EMULTYPE_TRAP_UD; 5451 5451 char sig[5]; /* ud2; .ascii "kvm" */ 5452 5452 struct x86_exception e; ··· 5455 5453 if (force_emulation_prefix && 5456 5454 kvm_read_guest_virt(vcpu, kvm_get_linear_rip(vcpu), 5457 5455 sig, sizeof(sig), &e) == 0 && 5458 - memcmp(sig, "\xf\xbkvm", sizeof(sig)) == 0) { 5456 + memcmp(sig, kvm_emulate_prefix, sizeof(sig)) == 0) { 5459 5457 kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); 5460 5458 emul_type = EMULTYPE_TRAP_UD_FORCED; 5461 5459 }