Skip to contentSkip to conversation

KVM: VMX: do not overwrite uptodate vcpu->arch.cr3 on KVM_SET_SREGS

PATCH Marcelo Tosatti 2 participants 4 messages Jun 6, 2011 – Jun 12, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

arch/x86/kvm/vmx.c +3 -1
index 750b0ff..772c4d2 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 5 lines · Marcelo Tosatti

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

arch/x86/kvm/vmx.c static void ept_update_paging_mode_cr0(unsigned long *hw_cr0, · line 2057

Quoted 10 lines
arch/x86/kvm/vmx.c +3 -1
@@ -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.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#2 lore raw
Quoted 5 lines · Avi Kivity
Quoted 4 lines · Marcelo Tosatti

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

Quoted 16 lines

arch/x86/kvm/vmx.c static void ept_update_paging_mode_cr0(unsigned long *hw_cr0, · line 2057

Quoted 11 lines
arch/x86/kvm/vmx.c +3 -1
@@ -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.

#3 lore raw
Quoted 10 lines · Marcelo Tosatti
Quoted 5 lines

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.

Signature · 1 line
error compiling committee.c: too many arguments to function