From nobody Tue Nov 11 09:01:49 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1567775784; cv=none; d=zoho.com; s=zohoarc; b=VJpFXgR2gEJixpYSetu163n+GCybBGCtvUaDW7QQTx4eozuulw2aTUEwZadFyiM6Ztnod9bifMITp6a9qFXdNMXghQx0dA3SnDLo8l+9qpKArRxs2wvy2PAdfMb897GxqFL8TZ1j+Zm7vGQjsJNFwp5+Tud1n310+/P1qwgrUpo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567775784; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=09+yHRMpp0Wbo7i21pIl0p3Zy8mQQTDa9r2gZ+g7iyk=; b=DfI4aYvE+FORxqS+0WAa6oDK+SWBavzgkJ2nLfP6j66LU2TAtH7z/NpIQ58XOqVQ7CMSjvG8ihd3JUICOzCxLr7ge0dlkFJXJa0+f2pMGSJFiF8zzSvl25rDRqo73ke+A46LtwkuOL41svXkSy8yAXMMnducNdehELkay2TFCVA= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1567775784324210.68979743843101; Fri, 6 Sep 2019 06:16:24 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i6E3z-0000qN-O8; Fri, 06 Sep 2019 13:14:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i6E3x-0000q9-TD for xen-devel@lists.xenproject.org; Fri, 06 Sep 2019 13:14:05 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3377ecea-d0a8-11e9-b299-bc764e2007e4; Fri, 06 Sep 2019 13:14:05 +0000 (UTC) Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD58C206CD; Fri, 6 Sep 2019 13:14:01 +0000 (UTC) X-Inumbo-ID: 3377ecea-d0a8-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567775644; bh=xwevScULOZ8aHH02UdNxNNbZKln2GGka5KsITPUu01w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ywcKvpjP6yQuQ4ollCyO25HczFce4Msz6VtqlYmlk6swCFAeqdhyWFKeD3CXoeHoF HL6carKTp5DncQeBKlw9iX41TV7uwbKZENeYEhGGqqzGNpND5Gc1qxqdTOaBpfSAf3 /Pp9GZwNtIvwmSvmfreLDNphR1OkYBf/+h5lC5uc= From: Masami Hiramatsu To: Ingo Molnar Date: Fri, 6 Sep 2019 22:13:59 +0900 Message-Id: <156777563917.25081.7286628561790289995.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <156777561745.25081.1205321122446165328.stgit@devnote2> References: <156777561745.25081.1205321122446165328.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Xen-devel] [PATCH -tip v4 2/4] x86: xen: kvm: Gather the definition of emulate prefixes X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Peter Zijlstra , Andrew Cooper , Randy Dunlap , x86@kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , Josh Poimboeuf , xen-devel@lists.xenproject.org, Boris Ostrovsky Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Gather the emulate prefixes, which forcibly make the following instruction emulated on virtualization, in one place. Suggested-by: Peter Zijlstra Signed-off-by: Masami Hiramatsu --- arch/x86/include/asm/emulate_prefix.h | 14 ++++++++++++++ arch/x86/include/asm/xen/interface.h | 11 ++++------- arch/x86/kvm/x86.c | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 arch/x86/include/asm/emulate_prefix.h diff --git a/arch/x86/include/asm/emulate_prefix.h b/arch/x86/include/asm/e= mulate_prefix.h new file mode 100644 index 000000000000..70f5b98a5286 --- /dev/null +++ b/arch/x86/include/asm/emulate_prefix.h @@ -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 "x= en" */ +#define __KVM_EMULATE_PREFIX 0x0f,0x0b,0x6b,0x76,0x6d /* ud2 ; .ascii "kv= m" */ + +#endif diff --git a/arch/x86/include/asm/xen/interface.h b/arch/x86/include/asm/xe= n/interface.h index 62ca03ef5c65..9139b3e86316 100644 --- a/arch/x86/include/asm/xen/interface.h +++ b/arch/x86/include/asm/xen/interface.h @@ -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 + +#define XEN_EMULATE_PREFIX __ASM_FORM(.byte __XEN_EMULATE_PREFIX ;) +#define XEN_CPUID XEN_EMULATE_PREFIX __ASM_FORM(cpuid) =20 #endif /* _ASM_X86_XEN_INTERFACE_H */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 290c3c3efb87..5f8b0a60f48b 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -68,6 +68,7 @@ #include #include #include +#include #include =20 #define CREATE_TRACE_POINTS @@ -5319,6 +5320,7 @@ EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); =20 int handle_ud(struct kvm_vcpu *vcpu) { + static const char kvm_emulate_prefix[] =3D { __KVM_EMULATE_PREFIX }; int emul_type =3D EMULTYPE_TRAP_UD; enum emulation_result er; char sig[5]; /* ud2; .ascii "kvm" */ @@ -5327,7 +5329,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) =3D=3D 0 && - memcmp(sig, "\xf\xbkvm", sizeof(sig)) =3D=3D 0) { + memcmp(sig, kvm_emulate_prefix, sizeof(sig)) =3D=3D 0) { kvm_rip_write(vcpu, kvm_rip_read(vcpu) + sizeof(sig)); emul_type =3D 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel