public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS
@ 2011-06-06 17:27 Marcelo Tosatti
  2011-06-07  8:24 ` Avi Kivity
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Tosatti @ 2011-06-06 17:27 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm


Only decache guest CR3 value if vcpu->arch.cr3 is stale. 
Fixes loadvm with live guest.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Tested-by: Markus Schade <markus.schade@gmail.com>

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 750b0ff..772c4d2 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -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,
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS
  2011-06-06 17:27 KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS Marcelo Tosatti
@ 2011-06-07  8:24 ` Avi Kivity
  2011-06-09 17:11   ` Marcelo Tosatti
  0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2011-06-07  8:24 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm

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.


-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS
  2011-06-07  8:24 ` Avi Kivity
@ 2011-06-09 17:11   ` Marcelo Tosatti
  2011-06-12  8:50     ` Avi Kivity
  0 siblings, 1 reply; 4+ messages in thread
From: Marcelo Tosatti @ 2011-06-09 17:11 UTC (permalink / raw)
  To: Avi Kivity; +Cc: kvm

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.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS
  2011-06-09 17:11   ` Marcelo Tosatti
@ 2011-06-12  8:50     ` Avi Kivity
  0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2011-06-12  8:50 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm

On 06/09/2011 08:11 PM, Marcelo Tosatti wrote:
> >
> >  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.
>

Right.  Should have called kvm_set_cr3().  It's tricky since we need to 
set the order of writing various registers, I'll take a look.

-- 
error compiling committee.c: too many arguments to function


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-06-12  8:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-06 17:27 KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS Marcelo Tosatti
2011-06-07  8:24 ` Avi Kivity
2011-06-09 17:11   ` Marcelo Tosatti
2011-06-12  8:50     ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox