From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS Date: Thu, 9 Jun 2011 14:11:23 -0300 Message-ID: <20110609171123.GA5030@amt.cnet> References: <20110606172747.GA30900@amt.cnet> <4DEDE051.2090908@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:25840 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753278Ab1FIRLc (ORCPT ); Thu, 9 Jun 2011 13:11:32 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p59HBVRN019754 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 9 Jun 2011 13:11:31 -0400 Content-Disposition: inline In-Reply-To: <4DEDE051.2090908@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Jun 07, 2011 at 11:24:49AM +0300, Avi Kivity wrote: > On 06/06/2011 08:27 PM, Marcelo Tosatti wrote: > >Only decache guest CR3 value if vcpu->arch.cr3 is stale. > >Fixes loadvm with live guest. > > > > > >@@ -2049,7 +2049,9 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0, > > unsigned long cr0, > > struct kvm_vcpu *vcpu) > > { > >- vmx_decache_cr3(vcpu); > >+ > >+ if (!test_bit(VCPU_EXREG_CR3, (ulong *)&vcpu->arch.regs_avail)) > >+ vmx_decache_cr3(vcpu); > > if (!(cr0& X86_CR0_PG)) { > > /* From paging/starting to nonpaging */ > > vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, > > Applied and queued, but I think there is something rotten here. How > does arch.cr3 get into GUEST_CR3 after KVM_SET_SREGS? arch.cr3 is a > supposed to be write-through cache - it only has a bit in > regs_avail, not regs_dirty. KVM_SET_SREGS sets good kvm->arch.cr3. Then vmx_decache_cr3 overwrites kvm->arch.cr3 from GUEST_CR3, which is stale.