From patchwork Wed Jan 27 18:11:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8136381 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C8C2E9F440 for ; Wed, 27 Jan 2016 18:13:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CCB542034C for ; Wed, 27 Jan 2016 18:13:54 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA8B020279 for ; Wed, 27 Jan 2016 18:13:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOUYt-0007Ew-9A; Wed, 27 Jan 2016 18:11:23 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aOUYr-0007Eo-Vz for xen-devel@lists.xen.org; Wed, 27 Jan 2016 18:11:22 +0000 Received: from [193.109.254.147] by server-4.bemta-14.messagelabs.com id E0/B0-10715-94809A65; Wed, 27 Jan 2016 18:11:21 +0000 X-Env-Sender: prvs=82734b35b=Andrew.Cooper3@citrix.com X-Msg-Ref: server-5.tower-27.messagelabs.com!1453918279!19608400!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: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 13059 invoked from network); 27 Jan 2016 18:11:20 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 27 Jan 2016 18:11:20 -0000 X-IronPort-AV: E=Sophos;i="5.22,356,1449532800"; d="scan'208";a="334367927" From: Andrew Cooper To: Xen-devel Date: Wed, 27 Jan 2016 18:11:12 +0000 Message-ID: <1453918273-23008-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Kevin Tian , Jun Nakajima , Jan Beulich Subject: [Xen-devel] [PATCH 1/2] x86/vmx: Don't clobber exception_bitmap when entering/leaving emulated real mode X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Most updates to the exception bitmaps set or clear an individual bits. However, entering or exiting emulated real mode unilaterally clobbers it, leaving the exit code to recalculate what it should have been. This is error prone, and indeed currently fails to recalculate the TRAP_no_device intercept appropriately. Instead of overwriting exception_bitmap when entering emulated real mode, move the override into vmx_update_exception_bitmap() and leave exception_bitmap unmodified. This means that recalculation is unnecessary, and that the use of vmx_fpu_leave() and vmx_update_debug_state() while in emulated real mode doesn't result in TRAP_no_device and TRAP_int3 being un-intercepted. This is only a functional change on hardware lacking unrestricted guest support. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Acked-by: Kevin Tian --- CC: Jan Beulich CC: Jun Nakajima CC: Kevin Tian --- xen/arch/x86/hvm/vmx/vmx.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index 04dde83..4f9951f 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -389,10 +389,13 @@ void vmx_update_secondary_exec_control(struct vcpu *v) void vmx_update_exception_bitmap(struct vcpu *v) { + u32 bitmap = unlikely(v->arch.hvm_vmx.vmx_realmode) + ? 0xffffffffu : v->arch.hvm_vmx.exception_bitmap; + if ( nestedhvm_vcpu_in_guestmode(v) ) - nvmx_update_exception_bitmap(v, v->arch.hvm_vmx.exception_bitmap); + nvmx_update_exception_bitmap(v, bitmap); else - __vmwrite(EXCEPTION_BITMAP, v->arch.hvm_vmx.exception_bitmap); + __vmwrite(EXCEPTION_BITMAP, bitmap); } static int vmx_guest_x86_mode(struct vcpu *v) @@ -1306,8 +1309,6 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) { for ( s = x86_seg_cs ; s <= x86_seg_tr ; s++ ) vmx_set_segment_register(v, s, ®[s]); - v->arch.hvm_vmx.exception_bitmap = 0xffffffff; - vmx_update_exception_bitmap(v); } else { @@ -1315,13 +1316,9 @@ static void vmx_update_guest_cr(struct vcpu *v, unsigned int cr) if ( !(v->arch.hvm_vmx.vm86_segment_mask & (1<arch.hvm_vmx.vm86_saved_seg[s]); - v->arch.hvm_vmx.exception_bitmap = HVM_TRAP_MASK - | (paging_mode_hap(v->domain) ? - 0 : (1U << TRAP_page_fault)) - | (1U << TRAP_no_device); - vmx_update_exception_bitmap(v); - vmx_update_debug_state(v); } + + vmx_update_exception_bitmap(v); } v->arch.hvm_vcpu.hw_cr[0] =