Skip to content

Commit 1b79f28

Browse files
YadongQiwenlingz
authored andcommitted
hv: update CR0/CR4 on demand in run_vcpu()
Suppose run_ctx.cr0/cr4 are correct when do world switching, so call vcpu_set_cr0/cr4() to update cr0/cr4 directly before resume to guest. This design is only for trusty world switching. Tracked-On: #2773 Signed-off-by: Qi Yadong <yadong.qi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 19c5342 commit 1b79f28

File tree

1 file changed

+13
-0
lines changed
  • hypervisor/arch/x86/guest

1 file changed

+13
-0
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,19 @@ int32_t run_vcpu(struct acrn_vcpu *vcpu)
432432
if (bitmap_test_and_clear_lock(CPU_REG_RFLAGS, &vcpu->reg_updated))
433433
exec_vmwrite(VMX_GUEST_RFLAGS, ctx->rflags);
434434

435+
/*
436+
* Currently, updating CR0/CR4 here is only designed for world
437+
* switching. There should no other module request updating
438+
* CR0/CR4 here.
439+
*/
440+
if (bitmap_test_and_clear_lock(CPU_REG_CR0, &vcpu->reg_updated)) {
441+
vcpu_set_cr0(vcpu, ctx->cr0);
442+
}
443+
444+
if (bitmap_test_and_clear_lock(CPU_REG_CR4, &vcpu->reg_updated)) {
445+
vcpu_set_cr4(vcpu, ctx->cr4);
446+
}
447+
435448
/* If this VCPU is not already launched, launch it */
436449
if (!vcpu->launched) {
437450
pr_info("VM %d Starting VCPU %hu",

0 commit comments

Comments
 (0)