From nobody Fri May 3 13:06:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linuxfoundation.org ARC-Seal: i=1; a=rsa-sha256; t=1652364164; cv=none; d=zohomail.com; s=zohoarc; b=ZsL8B0hIP8GWMfrPY4d7XZm9gRduzpFmE5abnnZurCUkCYSa+/BWLPEIeHxPR+P4HJBCMpjVCMZz97tyWG1nYMUuU2v9YW2MCUOhPk8nLrS7T13tOURIjyaXglIOxWuNKsA4csLQiW5iZbum0bXECE4dHvX6S6Q8eNXg8qPTEck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652364164; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=DWq1aBM7E1YUpI67PbCwheDYi8iM0feOoj7mEVNvfiA=; b=Wf2Q6mbKd8PCL+rbteUOrd2qrzABzVR2pkCEObJ2NoafYuIgmzy4n/R/7ayioCbFlx0wJSD69MI+nr2ioF2A5+k+9ZVntFtZioJEAxKvff8j3Tta9Q9DKNTQsUQWMjeokAGgZEdku+2YYqQWdBMy5qyx88rmky5jxkX5DLxZ7yk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1652364164799393.94373864166676; Thu, 12 May 2022 07:02:44 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.327727.550611 (Exim 4.92) (envelope-from ) id 1np9OE-0001re-Qs; Thu, 12 May 2022 14:02:02 +0000 Received: by outflank-mailman (output) from mailman id 327727.550611; Thu, 12 May 2022 14:02:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1np9OE-0001rV-N1; Thu, 12 May 2022 14:02:02 +0000 Received: by outflank-mailman (input) for mailman id 327727; Thu, 12 May 2022 14:02:01 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1np9OD-0001Gk-PE for xen-devel@lists.xenproject.org; Thu, 12 May 2022 14:02:01 +0000 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 16b2b2f5-d1fc-11ec-a406-831a346695d4; Thu, 12 May 2022 16:01:59 +0200 (CEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 864ACCE2971; Thu, 12 May 2022 14:01:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93749C385B8; Thu, 12 May 2022 14:01:53 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 16b2b2f5-d1fc-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652364114; bh=HqZw/phFWBMSXNUzzcc94+rWdGbz6OaJg41vKpMTZr4=; h=Subject:To:Cc:From:Date:From; b=mHoigYKGb/v6DuPlqqMgJhm74LFOd7CnSpnAbH1b1jQ33WP3IHBbI+HsHNFIXLgvc aissvHDPonfKQTPBuJyxN3PLltUvw0qBmFwzK8GwzwahG0EWFezk4nEHDxNF6OcHJ+ lVh8+Ag2Q70ic7IyabW6vS74OnYKmmiWImuu5Tjc= Subject: Patch "x86: xen: insn: Decode Xen and KVM emulate-prefix signature" has been added to the 5.4-stable tree To: andrew.cooper3@citrix.com,boris.ostrovsky@oracle.com,bp@alien8.de,gregkh@linuxfoundation.org,jgross@suse.com,jpoimboe@redhat.com,mheyne@amazon.de,mhiramat@kernel.org,mingo@kernel.org,peterz@infradead.org,rdunlap@infradead.org,sstabellini@kernel.org,x86@kernel.org,xen-devel@lists.xenproject.org Cc: From: Date: Thu, 12 May 2022 16:01:38 +0200 Message-ID: <165236409818691@kroah.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-stable: commit X-Patchwork-Hint: ignore X-ZohoMail-DKIM: pass (identity @linuxfoundation.org) X-ZM-MESSAGEID: 1652364165397100001 Content-Type: text/plain; charset="utf-8" This is a note to let you know that I've just added the patch titled x86: xen: insn: Decode Xen and KVM emulate-prefix signature to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=3Dlinux/kernel/git/stable/stable-queue.git= ;a=3Dsummary The filename of the patch is: x86-xen-insn-decode-xen-and-kvm-emulate-prefix-signature.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From 4d65adfcd1196818659d3bd9b42dccab291e1751 Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Fri, 6 Sep 2019 22:14:10 +0900 Subject: x86: xen: insn: Decode Xen and KVM emulate-prefix signature From: Masami Hiramatsu commit 4d65adfcd1196818659d3bd9b42dccab291e1751 upstream. 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. Signed-off-by: Masami Hiramatsu Signed-off-by: Peter Zijlstra (Intel) Acked-by: Josh Poimboeuf Cc: Juergen Gross Cc: x86@kernel.org Cc: Boris Ostrovsky Cc: Ingo Molnar Cc: Stefano Stabellini Cc: Andrew Cooper Cc: Borislav Petkov Cc: xen-devel@lists.xenproject.org Cc: Randy Dunlap Link: https://lkml.kernel.org/r/156777564986.25081.4964537658500952557.stgi= t@devnote2 [mheyne: resolved contextual conflict in tools/objtools/sync-check.sh] Signed-off-by: Maximilian Heyne Signed-off-by: Greg Kroah-Hartman --- 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 --- 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 in 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) { --- 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 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); --- /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 --- 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 in 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) { --- 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 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); --- 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,4 +47,4 @@ 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[\">]"' --- a/tools/perf/check-headers.sh +++ b/tools/perf/check-headers.sh @@ -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/uapi/asm/prctl.h arch/x86/lib/x86-opcode-map.txt arch/x86/tools/gen-insn-attr-x86.awk @@ -116,7 +117,7 @@ check lib/ctype.c '-I "^EXPORT_SY 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 Patches currently in stable-queue which might be from mhiramat@kernel.org a= re queue-5.4/x86-xen-kvm-gather-the-definition-of-emulate-prefixes.patch queue-5.4/x86-xen-insn-decode-xen-and-kvm-emulate-prefix-signature.patch queue-5.4/x86-asm-allow-to-pass-macros-to-__asm_form.patch queue-5.4/x86-kprobes-prohibit-probing-on-instruction-which-has-emulate-pre= fix.patch