Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbdHQFDK (ORCPT ); Thu, 17 Aug 2017 01:03:10 -0400 Received: from mga09.intel.com ([134.134.136.24]:39346 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750926AbdHQFDJ (ORCPT ); Thu, 17 Aug 2017 01:03:09 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,386,1498546800"; d="scan'208";a="138551475" Subject: Re: [PATCH] KVM/VMX: Avoid CR3 VMEXIT during guest real mode when "unrestricted guest" is supported. To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <1502848704-7474-1-git-send-email-tianyu.lan@intel.com> <20170816132625.GD5975@flask> Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org From: Lan Tianyu Message-ID: Date: Thu, 17 Aug 2017 13:00:11 +0800 User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20170816132625.GD5975@flask> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1712 Lines: 53 On 2017年08月16日 21:26, Radim Krčmář wrote: > 2017-08-15 21:58-0400, Lan Tianyu: >> These CR3 VMEXITs was introduced for platform without "unrestricted guest" >> support. This is to set ept identity table to guest CR3 in guest real >> mode because these platforms don't support ept real mode(CR0.PE and CR0.PG >> must be set to 1). But these VMEXITs is redundant for platforms with >> "unrestricted guest" support. >> >> Signed-off-by: Lan Tianyu >> --- >> arch/x86/kvm/vmx.c | 22 +++++++++++++--------- >> 1 file changed, 13 insertions(+), 9 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> @@ -4311,7 +4313,9 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3) >> } >> >> vmx_flush_tlb(vcpu); >> - vmcs_writel(GUEST_CR3, guest_cr3); >> + >> + if (!enable_unrestricted_guest || !enable_ept) >> + vmcs_writel(GUEST_CR3, guest_cr3); > > This looks wrong -- it would prevent update GUEST_CR3 outside of > non-root mode with enable_unrestricted_guest. > OK. Do you mean nest mode? I didn't consider that case. I thought there were three cases here. 1) Shadow page mode(enable_ept=0) 2) ept mode without unrestricted guest mode (ept=1, enable_unrestricted_guest = 0) 3) ept mode with unrestricted guest mode (ept=1, enable_unrestricted_guest = 1) >From my understanding, only (1) and (2) need to update guest cr3. If nest mode is still needed to update guest CR3, we can add is_guest_mode() in the if condition. Other choice is to just ignore setting guest cr3 for case3. The condition maybe changed to if (!(enable_unrestricted_guest && enable_ept)) vmcs_writel(GUEST_CR3, guest_cr3); -- Best regards Tianyu Lan