From patchwork Mon Apr 12 08:03:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 92012 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o3C85P6q003127 for ; Mon, 12 Apr 2010 08:08:33 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752757Ab0DLIGT (ORCPT ); Mon, 12 Apr 2010 04:06:19 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:52831 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752532Ab0DLIGS (ORCPT ); Mon, 12 Apr 2010 04:06:18 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 30074170115; Mon, 12 Apr 2010 16:06:17 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o3C84iJQ016517; Mon, 12 Apr 2010 16:04:44 +0800 Received: from [10.167.141.99] (unknown [10.167.141.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 7727DDC1FC; Mon, 12 Apr 2010 16:09:05 +0800 (CST) Message-ID: <4BC2D3E0.8070602@cn.fujitsu.com> Date: Mon, 12 Apr 2010 16:03:44 +0800 From: Xiao Guangrong User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , KVM list , LKML Subject: [PATCH 4/6] KVM MMU: optimize for writing cr4 References: <4BC2D2E2.1030604@cn.fujitsu.com> In-Reply-To: <4BC2D2E2.1030604@cn.fujitsu.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 12 Apr 2010 08:08:33 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fd5c3d3..2aaa6fb 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -463,6 +463,15 @@ void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) unsigned long old_cr4 = kvm_read_cr4(vcpu); unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE; + if (cr4 == old_cr4) + return; + + if ((cr4 ^ old_cr4) == X86_CR4_PGE) { + kvm_mmu_sync_roots(vcpu); + kvm_mmu_flush_tlb(vcpu); + return; + } + if (cr4 & CR4_RESERVED_BITS) { kvm_inject_gp(vcpu, 0); return;