From patchwork Mon Dec 5 10:09:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9460763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 990CD60459 for ; Mon, 5 Dec 2016 10:11:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 924B622ADC for ; Mon, 5 Dec 2016 10:11:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86FF326490; Mon, 5 Dec 2016 10:11:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63EB822ADC for ; Mon, 5 Dec 2016 10:11:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cDqDQ-0007oD-2r; Mon, 05 Dec 2016 10:09:44 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cDqDO-0007mK-Fz for xen-devel@lists.xen.org; Mon, 05 Dec 2016 10:09:42 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 6F/7C-22495-5EC35485; Mon, 05 Dec 2016 10:09:41 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrohUvepjWu Ewa8nEhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8b8q4vZC3YLVPT9nszUwLiOu4uRk0NCwF/i 3e29LCA2m4C+xO4Xn5hAbBEBdYnTHRdZuxg5OJgF/CQOPfAFCQsLuEvsuXUarJxFQEXi6+yvz CAlvAKeEvcuWEJMlJM4f/wnM4jNKeAlsXT2VrByIaCS3x/7mCBsNYlr/ZfYQWxeAUGJkzOfgN UwC0hIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGhnrJRVlpmeU5CZm5ugaGhjr5aYWFye mp+YkJhXrJefnbmIEBk49AwPjDsa+vX6HGCU5mJREeVsMXSOE+JLyUyozEosz4otKc1KLDzHK cHAoSfC2WAPlBItS01Mr0jJzgCEMk5bg4FES4d0OkuYtLkjMLc5Mh0idYlSUEuc9AZIQAElkl ObBtcHi5hKjrJQwLyMDA4MQT0FqUW5mCar8K0ZxDkYlYd4zIFN4MvNK4Ka/AlrMBLT4xHFnkM UliQgpqQbGbe2CW1v/udw9kbfi8sOMCK9bCkppCy/3uU2f8b/siETs/4DHIsv7vj7XuZPz8H2 1ua6VmNbqPx8E/28KFOU9+SLM3fXTusmPDbgkSxv4LGsr7DgfPX3I9Ydj5vbb0xssVi6/0mzz 0fWLjoACm/qOTTe3CCd/Y/z4z77drdFWq2Dnk9+irxJfKLEUZyQaajEXFScCAMpTmcaWAgAA X-Env-Sender: prvs=140b549e8=Andrew.Cooper3@citrix.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1480932577!57653486!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52960 invoked from network); 5 Dec 2016 10:09:41 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-12.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 5 Dec 2016 10:09:41 -0000 X-IronPort-AV: E=Sophos;i="5.33,747,1477958400"; d="scan'208";a="393002854" From: Andrew Cooper To: Xen-devel Date: Mon, 5 Dec 2016 10:09:31 +0000 Message-ID: <1480932571-23547-9-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1480932571-23547-1-git-send-email-andrew.cooper3@citrix.com> References: <1480932571-23547-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 8/8] x86/emul: Implement the STAC and CLAC instructions X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Note that unlike most privilege restricted instructions, STAC and CLAC are documented to raise #UD rather than #GP[0], and indeed do so. Signed-off-by: Andrew Cooper --- CC: Jan Beulich --- xen/arch/x86/x86_emulate/x86_emulate.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 67495eb..111bb91 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -429,6 +429,7 @@ typedef union { #define CR4_OSXMMEXCPT (1<<10) #define CR4_UMIP (1<<11) #define CR4_OSXSAVE (1<<18) +#define CR4_SMAP (1<<21) /* EFLAGS bit definitions. */ #define EFLG_VIP (1<<20) @@ -4362,11 +4363,27 @@ x86_emulate( switch( modrm ) { -#ifdef __XEN__ - case 0xd1: /* xsetbv */ - { unsigned long cr4; + case 0xca: /* clac */ + case 0xcb: /* stac */ + generate_exception_if( + lock_prefix || (_regs.eflags & EFLG_VM), EXC_UD); + if ( !ops->read_cr || ops->read_cr(4, &cr4, ctxt) != X86EMUL_OKAY ) + cr4 = 0; + /* + * Contrary to expectation (i.e. #GP[0]), #UD for the CPL check is + * the documented and observed behaviour. + */ + generate_exception_if(!(cr4 & CR4_SMAP) || !mode_ring0(), EXC_UD); + + _regs.eflags &= ~EFLG_AC; + if ( modrm == 0xcb ) + _regs.eflags |= EFLG_AC; + goto no_writeback; + +#ifdef __XEN__ + case 0xd1: /* xsetbv */ generate_exception_if(vex.pfx, EXC_UD); if ( !ops->read_cr || ops->read_cr(4, &cr4, ctxt) != X86EMUL_OKAY ) cr4 = 0; @@ -4376,7 +4393,6 @@ x86_emulate( _regs._eax | (_regs.rdx << 32)), EXC_GP, 0); goto no_writeback; - } #endif case 0xd4: /* vmfunc */