Skip to content

Commit ff41c00

Browse files
YadongQiEddie Dong
authored andcommitted
hv: trusty: refine control registers switching method
Remove vmx_cr0/vmx_cr4 from ext_context structure, they are duplicated with cr0/cr4 fields in run_context. Switch cr0/cr4 of run_context structure on demand when do world switch. Remove vmx_cr0_read_shadow/vmx_cr4_read_shadow from ext_context structure. These fields should be same for both normal world and secure world. Tracked-On: #2773 Signed-off-by: Qi Yadong <yadong.qi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 4157b84 commit ff41c00

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

hypervisor/arch/x86/guest/trusty.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,16 @@ static void save_world_ctx(struct acrn_vcpu *vcpu, struct ext_context *ext_ctx)
158158
{
159159
uint32_t i;
160160

161-
/* cache on-demand run_context for efer/rflags/rsp/rip */
161+
/* cache on-demand run_context for efer/rflags/rsp/rip/cr0/cr4 */
162162
(void)vcpu_get_efer(vcpu);
163163
(void)vcpu_get_rflags(vcpu);
164164
(void)vcpu_get_rsp(vcpu);
165165
(void)vcpu_get_rip(vcpu);
166+
(void)vcpu_get_cr0(vcpu);
167+
(void)vcpu_get_cr4(vcpu);
166168

167169
/* VMCS GUEST field */
168170
ext_ctx->tsc_offset = exec_vmread(VMX_TSC_OFFSET_FULL);
169-
ext_ctx->vmx_cr0 = exec_vmread(VMX_GUEST_CR0);
170-
ext_ctx->vmx_cr4 = exec_vmread(VMX_GUEST_CR4);
171-
ext_ctx->vmx_cr0_read_shadow = exec_vmread(VMX_CR0_READ_SHADOW);
172-
ext_ctx->vmx_cr4_read_shadow = exec_vmread(VMX_CR4_READ_SHADOW);
173171
ext_ctx->cr3 = exec_vmread(VMX_GUEST_CR3);
174172
ext_ctx->dr7 = exec_vmread(VMX_GUEST_DR7);
175173
ext_ctx->ia32_debugctl = exec_vmread64(VMX_GUEST_IA32_DEBUGCTL_FULL);
@@ -219,20 +217,18 @@ static void load_world_ctx(struct acrn_vcpu *vcpu, const struct ext_context *ext
219217
{
220218
uint32_t i;
221219

222-
/* mark to update on-demand run_context for efer/rflags/rsp */
220+
/* mark to update on-demand run_context for efer/rflags/rsp/rip/cr0/cr4 */
223221
bitmap_set_lock(CPU_REG_EFER, &vcpu->reg_updated);
224222
bitmap_set_lock(CPU_REG_RFLAGS, &vcpu->reg_updated);
225223
bitmap_set_lock(CPU_REG_RSP, &vcpu->reg_updated);
226224
bitmap_set_lock(CPU_REG_RIP, &vcpu->reg_updated);
225+
bitmap_set_lock(CPU_REG_CR0, &vcpu->reg_updated);
226+
bitmap_set_lock(CPU_REG_CR4, &vcpu->reg_updated);
227227

228228
/* VMCS Execution field */
229229
exec_vmwrite64(VMX_TSC_OFFSET_FULL, ext_ctx->tsc_offset);
230230

231231
/* VMCS GUEST field */
232-
exec_vmwrite(VMX_GUEST_CR0, ext_ctx->vmx_cr0);
233-
exec_vmwrite(VMX_GUEST_CR4, ext_ctx->vmx_cr4);
234-
exec_vmwrite(VMX_CR0_READ_SHADOW, ext_ctx->vmx_cr0_read_shadow);
235-
exec_vmwrite(VMX_CR4_READ_SHADOW, ext_ctx->vmx_cr4_read_shadow);
236232
exec_vmwrite(VMX_GUEST_CR3, ext_ctx->cr3);
237233
exec_vmwrite(VMX_GUEST_DR7, ext_ctx->dr7);
238234
exec_vmwrite64(VMX_GUEST_IA32_DEBUGCTL_FULL, ext_ctx->ia32_debugctl);

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct run_context {
171171
};
172172

173173
/*
174-
* extended context does not save/restore during vm exity/entry, it's mainly
174+
* extended context does not save/restore during vm exit/entry, it's mainly
175175
* used in trusty world switch
176176
*/
177177
struct ext_context {
@@ -203,11 +203,6 @@ struct ext_context {
203203
uint64_t dr7;
204204
uint64_t tsc_offset;
205205

206-
uint64_t vmx_cr0;
207-
uint64_t vmx_cr4;
208-
uint64_t vmx_cr0_read_shadow;
209-
uint64_t vmx_cr4_read_shadow;
210-
211206
/* The 512 bytes area to save the FPU/MMX/SSE states for the guest */
212207
uint64_t
213208
fxstore_guest_area[VMX_CPU_S_FXSAVE_GUEST_AREA_SIZE / sizeof(uint64_t)]

0 commit comments

Comments
 (0)