Skip to contentSkip to conversation

x86/svm: Don't clear clean bits on every context switch

PATCH In review Ross Lagerwall 3 participants 3 messages Oct 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/svm: Don't clear clean bits on every context switch

Clear the cleanbits only when the VMCB is used on a different pCPU rather than on every context switch to the vCPU. This follows the APM guideline for when to clear the cleanbits:

"The hypervisor executes the guest on a different CPU core than one used the last time that guest was executed."

---
 xen/arch/x86/hvm/svm/svm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/x86/hvm/svm/svm.c +1 -2
index 71e48351f22c..4e22322f4b42 100644
@@ -890,7 +890,6 @@ static void cf_check svm_ctxt_switch_from(struct vcpu *v)
 
 static void cf_check svm_ctxt_switch_to(struct vcpu *v)
 {
-    struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
     int cpu = smp_processor_id();
 
     /*
@@ -908,7 +907,6 @@ static void cf_check svm_ctxt_switch_to(struct vcpu *v)
 
     svm_restore_dr(v);
 
-    vmcb->cleanbits.raw = 0;
     svm_tsc_ratio_load(v);
 
     if ( cpu_has_msr_tsc_aux )
@@ -953,6 +951,7 @@ static void noreturn cf_check svm_do_resume(void)
         hvm_migrate_pirqs(v);
         /* Migrating to another ASID domain.  Request a new ASID. */
         hvm_asid_flush_vcpu(v);
+        vmcb->cleanbits.raw = 0;
     }
 
     if ( !vcpu_guestmode && !vlapic_hw_disabled(vlapic) )
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ross Lagerwall

Clear the cleanbits only when the VMCB is used on a different pCPU rather than on every context switch to the vCPU. This follows the APM guideline for when to clear the cleanbits:

"The hypervisor executes the guest on a different CPU core than one used the last time that guest was executed."

The other times are:
"This is the first time a particular guest is run."

The vmcb page is zeroed in alloc_vmcb().

"The hypervisor has moved the guest's VMCB to a different physical page since the last time that guest was executed."

VMCBs aren't moved.

Regards,
Jason

#2 lore raw
In reply to Ross Lagerwall
Quoted 6 lines · Ross Lagerwall

Clear the cleanbits only when the VMCB is used on a different pCPU rather than on every context switch to the vCPU. This follows the APM guideline for when to clear the cleanbits:

"The hypervisor executes the guest on a different CPU core than one used the last time that guest was executed."

I think this wants the whole section from the APM, not just the one sentence in isolation.  It doesn't quite form a stand-alone sentence.

I can fix up on commit.

Quoted 2 lines

Code-wise, Reviewed-by: Andrew Cooper <[email protected]>