From nobody Thu Mar 28 10:38:19 2024 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=1567775771; cv=none; d=zoho.com; s=zohoarc; b=WVtplPkTJW75cDzvm4I8dzc6Gq5rY7qeyKAXoyYdvJJDdayN2iW1jAr0PP9P20r2Lf5DmJesDGPkIRVp+t02uguD9+W/K9lGkT40U7Q316FUxi2zmk5DbLhMzdldvVBDlx1+elHpY81w5yCDG7ji7iElAJZCoZ2hWjq+KOSsUqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567775771; 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=7Hra4PzDSio1PA8yNkzwFTGAD3Z+wBxmr6PVPZIreu0=; b=Pgaz2IrnDPDOyLSl0r3zkFMMycLty0eLJiO+eS7C1HTxnLd/3b591f/+P+AFcMoAy47Gv3ZEIfIyt829iev8RzQ1WAyTcWenKugG/nypxiiUZx2y8LEhcYoKmDDJHs/3hitIgjPp2SHOqGUprLEgl7EFnlq69G7a/ll4Rwl8FL0= 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 1567775771837579.1070606744323; Fri, 6 Sep 2019 06:16:11 -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 1i6E3o-0000oQ-E6; Fri, 06 Sep 2019 13:13:56 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i6E3m-0000oC-Ow for xen-devel@lists.xenproject.org; Fri, 06 Sep 2019 13:13:54 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d0f1d88-d0a8-11e9-abf5-12813bfff9fa; Fri, 06 Sep 2019 13:13:54 +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 00E2E206BB; Fri, 6 Sep 2019 13:13:50 +0000 (UTC) X-Inumbo-ID: 2d0f1d88-d0a8-11e9-abf5-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567775633; bh=rZzxI9XArt0wbskwU2r8uJHAgPdmUcSFpX/eT3zQGMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C6NY01TImkhzgeTZiksXsH1gnuCvp59kbibTxZmzs4RbcDHmv/N8J/RTAVQ1u2WUM gNBp8lMkjd6IlByDMIOGHwx0Z7DL/Xa6VMvWQykvlni9e1vmH4ZVGHPTnbOotvK1oO Lmo+YFCSuclG7ZsK7KMSa+YJj0y4flOxq8/Qb3oc= From: Masami Hiramatsu To: Ingo Molnar Date: Fri, 6 Sep 2019 22:13:48 +0900 Message-Id: <156777562873.25081.2288083344657460959.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 1/4] x86/asm: Allow to pass macros to __ASM_FORM() 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) Use __stringify() at __ASM_FORM() so that user can pass code including macros to __ASM_FORM(). Signed-off-by: Masami Hiramatsu --- arch/x86/include/asm/asm.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h index 3ff577c0b102..1b563f9167ea 100644 --- a/arch/x86/include/asm/asm.h +++ b/arch/x86/include/asm/asm.h @@ -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 + +# define __ASM_FORM(x) " " __stringify(x) " " +# define __ASM_FORM_RAW(x) __stringify(x) +# define __ASM_FORM_COMMA(x) " " __stringify(x) "," #endif =20 #ifndef __x86_64__ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 10:38:19 2024 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 From nobody Thu Mar 28 10:38:19 2024 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=1567775795; cv=none; d=zoho.com; s=zohoarc; b=M3Sk3ymgKrnRgwCR5f21yUezrNrMeWjJg7421bssC9slEB9TSnCbY2YlpGYmopiHc7vrKgZHGDGGlZqlR2JU2B76lxSzfLVe6ZbQpYxa9AnpjLdMJH2dNFfDBSEP97crF6CxPXyQ10a1M55ZAlnfE1GZC33W4R+GmZD21qOgCU0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567775795; 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=qXmIViCZzpSqOzuVNpwmPXon+VRzhnlAaucL79XCfmI=; b=CxVUrslPG6my21vkh8vHhqaded73e3NnVbRl0XMS62sWaqY9ys1S2aMz/mHu6t+zGpcK35CM3ZSl/7D62s8R/t1DmMWTOoThTA7ULtlFZjJbLJsXMxx+kYL0OJrxzkGaya+a9G00DIqdETCxd79+40MKz61zYXy3n0Nwmyg0SA8= 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 1567775795689175.3212202934095; Fri, 6 Sep 2019 06:16:35 -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 1i6E4A-0000sK-2C; Fri, 06 Sep 2019 13:14:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i6E48-0000rz-Il for xen-devel@lists.xenproject.org; Fri, 06 Sep 2019 13:14:16 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 39c615b8-d0a8-11e9-b299-bc764e2007e4; Fri, 06 Sep 2019 13:14:16 +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 4A55A207FC; Fri, 6 Sep 2019 13:14:12 +0000 (UTC) X-Inumbo-ID: 39c615b8-d0a8-11e9-b299-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567775655; bh=YxdWojc5fQhCsI3MCFNUb/S38/XJllDgwfcUjCixi7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XkKh5q5Aus2YgqR1dKqCz2etHrZWowX7W3djWGR1gL3U8RvdvMP18XVzrLm0PVhvq //NYVg8iMWghQpO3BWms/dSwsIM70WgaKZlAfM2MP0Ky5XqqK7Fgu+pZ8LCj27jCCE +I0vJVlcHcRe7KlsdYNQ1IBm+oyj6BNlkGQaS2bI= From: Masami Hiramatsu To: Ingo Molnar Date: Fri, 6 Sep 2019 22:14:10 +0900 Message-Id: <156777564986.25081.4964537658500952557.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 3/4] x86: xen: insn: Decode Xen and KVM emulate-prefix signature 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) Decode Xen and KVM's emulate-prefix signature by x86 insn decoder. It is called "prefix" but actually not x86 instruction prefix, so this adds insn.emulate_prefix_size field instead of reusing insn.prefixes. If x86 decoder finds a special sequence of instructions of XEN_EMULATE_PREFIX and 'ud2a; .ascii "kvm"', it just counts the length, set insn.emulate_prefix_size and fold it with the next instruction. In other words, the signature and the next instruction is treated as a single instruction. Reported-by: Josh Poimboeuf Signed-off-by: Masami Hiramatsu Acked-by: Josh Poimboeuf --- Changes in v4: - Use asm/emulate_prefix.h instead of xen/prefix.h - Fix to add emulate_prefix.h to the checkist of perf. --- arch/x86/include/asm/insn.h | 6 +++++ arch/x86/lib/insn.c | 34 +++++++++++++++++++++++= ++++ tools/arch/x86/include/asm/emulate_prefix.h | 14 +++++++++++ tools/arch/x86/include/asm/insn.h | 6 +++++ tools/arch/x86/lib/insn.c | 34 +++++++++++++++++++++++= ++++ tools/objtool/sync-check.sh | 3 ++ tools/perf/check-headers.sh | 3 ++ 7 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 tools/arch/x86/include/asm/emulate_prefix.h diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 154f27be8bfc..5c1ae3eff9d4 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -45,6 +45,7 @@ struct insn { struct insn_field immediate2; /* for 64bit imm or seg16 */ }; =20 + 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 =3D=3D 4); } =20 +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) { diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 0b5862ba6a75..404279563891 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -13,6 +13,8 @@ #include #include =20 +#include + /* Verify next sizeof(t) bytes can be on the same instruction */ #define validate_next(t, insn, n) \ ((insn)->next_byte + sizeof(t) + n <=3D (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 =3D 4; } =20 +static const insn_byte_t xen_prefix[] =3D { __XEN_EMULATE_PREFIX }; +static const insn_byte_t kvm_prefix[] =3D { __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 =3D 0; i < len; i++) { + if (peek_nbyte_next(insn_byte_t, insn, i) !=3D prefix[i]) + goto err_out; + } + + insn->emulate_prefix_size =3D len; + insn->next_byte +=3D 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; =20 + insn_get_emulate_prefix(insn); + nb =3D 0; lb =3D 0; b =3D peek_next(insn_byte_t, insn); diff --git a/tools/arch/x86/include/asm/emulate_prefix.h b/tools/arch/x86/i= nclude/asm/emulate_prefix.h new file mode 100644 index 000000000000..70f5b98a5286 --- /dev/null +++ b/tools/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/tools/arch/x86/include/asm/insn.h b/tools/arch/x86/include/asm= /insn.h index 37a4c390750b..568854b14d0a 100644 --- a/tools/arch/x86/include/asm/insn.h +++ b/tools/arch/x86/include/asm/insn.h @@ -45,6 +45,7 @@ struct insn { struct insn_field immediate2; /* for 64bit imm or seg16 */ }; =20 + 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 =3D=3D 4); } =20 +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) { diff --git a/tools/arch/x86/lib/insn.c b/tools/arch/x86/lib/insn.c index 79e048f1d902..0151dfc6da61 100644 --- a/tools/arch/x86/lib/insn.c +++ b/tools/arch/x86/lib/insn.c @@ -13,6 +13,8 @@ #include "../include/asm/inat.h" #include "../include/asm/insn.h" =20 +#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 <=3D (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 =3D 4; } =20 +static const insn_byte_t xen_prefix[] =3D { __XEN_EMULATE_PREFIX }; +static const insn_byte_t kvm_prefix[] =3D { __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 =3D 0; i < len; i++) { + if (peek_nbyte_next(insn_byte_t, insn, i) !=3D prefix[i]) + goto err_out; + } + + insn->emulate_prefix_size =3D len; + insn->next_byte +=3D 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; =20 + insn_get_emulate_prefix(insn); + nb =3D 0; lb =3D 0; b =3D peek_next(insn_byte_t, insn); diff --git a/tools/objtool/sync-check.sh b/tools/objtool/sync-check.sh index 0a832e265a50..9bd04bbed01e 100755 --- a/tools/objtool/sync-check.sh +++ b/tools/objtool/sync-check.sh @@ -4,6 +4,7 @@ FILES=3D' 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_ty= pes.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_pre= fix.h[\">]"' =20 cd - diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh index e2e0f06c97d0..988b1879ec98 100755 --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -27,6 +27,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/uapi/asm/prctl.h arch/x86/lib/x86-opcode-map.txt arch/x86/tools/gen-insn-attr-x86.awk @@ -115,7 +116,7 @@ check lib/ctype.c '-I "^EXPORT_SYMBOL" -I "^#inc= lude " -B check arch/x86/include/asm/inat.h '-I "^#include [\"<]\(asm/\)*inat_ty= pes.h[\">]"' check arch/x86/include/asm/insn.h '-I "^#include [\"<]\(asm/\)*inat.h[= \">]"' check arch/x86/lib/inat.c '-I "^#include [\"<]\(../include/\)*asm/in= sn.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_pre= fix.h[\">]"' =20 # diff non-symmetric files check_2 tools/perf/arch/x86/entry/syscalls/syscall_64.tbl arch/x86/entry/s= yscalls/syscall_64.tbl _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Mar 28 10:38:19 2024 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=1567775803; cv=none; d=zoho.com; s=zohoarc; b=f5KadLXNxZVrIuvUMCnrA6HaaKn3ULV1hOCp0bTODeaiOKJxdNWUuS4Nox6W9YvVjfIdadqPeMLu6+PXlTzHyJfDi0vthvtW4dkheJT+fAOgG3ykMV3CyC6VyvCv/CJnpaA/1kJGuuThibqoOsVXi6M7hAZqz93V6rvm2F0CK8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567775803; 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=6885yqWl8lobZhOnlGlT6UlsQ3UGcVYI/MMtWcJZ/LU=; b=HaLqTfTTrfQDccPPs88MawOGpPnussuIXOWVVSbmqCm521Vv53w59nxGHMRMSVKQGT0a3PvCo2vcEILd6VnRxQSI1y6wsv/8gvHJpZwYYEJkXFRAorRRrSWPeeDRZbl+X894c87EWW9v9lX8NoC3b26M1KlU6LUviZqng0p0ccM= 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 1567775803231778.7370569339; Fri, 6 Sep 2019 06:16:43 -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 1i6E4J-0000vc-Fx; Fri, 06 Sep 2019 13:14:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i6E4I-0000vN-Tc for xen-devel@lists.xenproject.org; Fri, 06 Sep 2019 13:14:26 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4019ce3c-d0a8-11e9-978d-bc764e2007e4; Fri, 06 Sep 2019 13:14:26 +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 0D837206BB; Fri, 6 Sep 2019 13:14:22 +0000 (UTC) X-Inumbo-ID: 4019ce3c-d0a8-11e9-978d-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567775665; bh=dTI/PD6Zp/AXRe7dx+Oz3QClHlFgk/sT4V/cXDhsk68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kTmx2s+62Y/4eEQFPY035FvyFlUmf88LUNSIVewSZCHATtGSevTrRRVXP+wltKibl b9yLGk+TUP3KzvCreKIPMGfToBbt9VZV7BklHS3DfBKoSGwzouEtlf+gOnTPv7y+hu W0io4Di/0BRZrRDopawOxAenhii0ZCxjO2iT1PPI= From: Masami Hiramatsu To: Ingo Molnar Date: Fri, 6 Sep 2019 22:14:20 +0900 Message-Id: <156777566048.25081.6296162369492175325.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 4/4] x86: kprobes: Prohibit probing on instruction which has emulate prefix 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) Prohibit probing on instruction which has XEN_EMULATE_PREFIX or KVM's emulate prefix. Since that prefix is a marker for Xen and KVM, if we modify the marker by kprobe's int3, that doesn't work as expected. Signed-off-by: Masami Hiramatsu --- arch/x86/kernel/kprobes/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 43fc13c831af..4f13af7cbcdb 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -351,6 +351,10 @@ int __copy_instruction(u8 *dest, u8 *src, u8 *real, st= ruct insn *insn) kernel_insn_init(insn, dest, MAX_INSN_SIZE); insn_get_length(insn); =20 + /* 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] =3D=3D BREAKPOINT_INSTRUCTION) return 0; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel