From patchwork Fri Oct 14 10:06:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9376363 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 EC8086075E for ; Fri, 14 Oct 2016 10:09:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBA4E2A5F7 for ; Fri, 14 Oct 2016 10:09:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEA8C2A5FC; Fri, 14 Oct 2016 10:09:39 +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 5355F2A5F7 for ; Fri, 14 Oct 2016 10:09:39 +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 1buzOi-0004Nz-IU; Fri, 14 Oct 2016 10:07:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1buzOh-0004Ns-Kr for xen-devel@lists.xen.org; Fri, 14 Oct 2016 10:07:27 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 69/00-19721-E5EA0085; Fri, 14 Oct 2016 10:07:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrKLMWRWlGSWpSXmKPExsXitHSDvW7cOoY Ig9d3VCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oz5F++wFbTzViza5tTAeJGzi5GTQ0LAX2Ly 5gVsIDabgL7E7hefmEBsEQF1idMdF1m7GDk4mAX8JA498AUJCwt4SEy++J4dxGYRUJVovL8Rr JVXwFPizP8N7BAj5STOH//JDGILCahJXOu/xA5RIyhxcuYTFhCbWUBC4uCLF8wg4yUEuCX+dt tPYOSZhaRqFpKqBYxMqxjVi1OLylKLdC31kooy0zNKchMzc3QNDUz1clOLixPTU3MSk4r1kvN zNzECg4MBCHYwrm11PsQoycGkJMpbq8cQIcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCl2EtUE6w KDU9tSItMwcYpjBpCQ4eJRHeTauB0rzFBYm5xZnpEKlTjIpS4ryH1wAlBEASGaV5cG2w2LjEK CslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd53IFN4MvNK4Ka/AlrMBLT4QxvY4pJEhJRUA2Pd75 taOrYFbiHLFSLb7c3N7M7eD7tu3vCunXFXhGP+Ke/t3EfV0tf3Lfabl7j+6YpcNcXjFx8xnf1 Wt36F7szKRUeXWZX+/yWmFXbcblKDnXNSnfitZd65m1apTlr4bMvceQfrr8mGnjK+d7BRJTD1 07qX52/dD2jZ3W7ZlKZsIf1OgddTfJ8SS3FGoqEWc1FxIgBa3v8ziAIAAA== X-Env-Sender: prvs=088eb09a3=Andrew.Cooper3@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1476439645!64640149!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 59756 invoked from network); 14 Oct 2016 10:07:26 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 14 Oct 2016 10:07:26 -0000 X-IronPort-AV: E=Sophos;i="5.31,344,1473120000"; d="scan'208";a="392485330" From: Andrew Cooper To: Xen-devel Date: Fri, 14 Oct 2016 11:06:55 +0100 Message-ID: <1476439616-17287-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 1/2] x86/hvm: Correct the position of the %cs L/D checks 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 Contrary to the description in the software manuals, in Long Mode, attempts to load %cs check that D is not set in combination with L before the present flag is checked. This can be observed because the L/D check fails with #GP before the presence check failes with #NP Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich --- xen/arch/x86/x86_emulate/x86_emulate.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index 793ce30..b23cd99 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1405,6 +1405,14 @@ protmode_load_seg( /* Non-conforming segment: check RPL and DPL against CPL. */ : rpl > cpl || dpl != cpl ) goto raise_exn; + /* + * 64-bit code segments (L bit set) must have D bit clear. + * Experimentally in long mode, the L and D bits are checked before + * the Present bit. + */ + if ( in_longmode(ctxt, ops) && + (desc.b & (1 << 21)) && (desc.b & (1 << 22)) ) + goto raise_exn; sel = (sel ^ rpl) | cpl; break; case x86_seg_ss: @@ -1444,11 +1452,6 @@ protmode_load_seg( goto raise_exn; } - /* 64-bit code segments (L bit set) must have D bit clear. */ - if ( seg == x86_seg_cs && in_longmode(ctxt, ops) && - (desc.b & (1 << 21)) && (desc.b & (1 << 22)) ) - goto raise_exn; - /* Ensure Accessed flag is set. */ if ( a_flag && !(desc.b & a_flag) ) {