Skip to content

Commit f912953

Browse files
wuxyintellijinxia
authored andcommitted
HV:treewide:Update exec_vmread/exec_vmwrite and exec_vmread64/exec_vmwrite64
In the hypervisor, VMCS fields include 16-bit fields, 32-bit fields, 64-bit fields and natural-width fields. In the current implement, there are exec_vmread/exec_vmwrite used for accessing 32-bit fields, 64-bit field and natural-width fields. This usage will confue developer. So there are many type casting for the return value and parameters vmread/vmwrite operations. Since exec_vmread/exec_vmwrite and exec_vmread64/exec_vmwrite64 are the same, update current exec_vmread/exec_vmwrite implement into exec_vmread64/exec_vmwrite64 implement and add MACRO define for exec_vmread/exec_vmwrite in head file; To access 64-bit fields in VMCS, callers use exec_vmread64/exec_vmwrite64; Update related variables type for vmread/vmwrite operations; Update related caller according to VMCS fields size. Note:Natural-width fields have 64 bits on processors that support Intel 64 architecture.To access natural-width fields in VMCS, callers still use exec_vmread/exec_vmwrite, keep the current implementation. V1--V2: This is new part of this patch serial to only update 64-bit vmread/vmread opertions and related caller, for netural width fields, still use exec_vmread or exec_vmwrite. V2-->V3: Fix few mistake updations for netural fields in VMCS, just keep exec_vmread/exec_vmwrite to access them; Fix few mistake updations for 64-bit fields in VMCS. V3--V4: Add "016ll" for 64-bit variable in log function; Few updates for coding style; Rename lssd32_idx as tr_sel in VMX module. V4-->V5: Use CPU_NATURAL_LAST in the vm_get_register and vm_set_register to make condition statement more understandable. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent 612cdce commit f912953

File tree

7 files changed

+94
-113
lines changed

7 files changed

+94
-113
lines changed

hypervisor/arch/x86/ept.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ int ept_misconfig_vmexit_handler(__unused struct vcpu *vcpu)
471471

472472
/* TODO - EPT Violation handler */
473473
pr_info("%s, Guest linear address: 0x%016llx ",
474-
__func__, exec_vmread64(VMX_GUEST_LINEAR_ADDR));
474+
__func__, exec_vmread(VMX_GUEST_LINEAR_ADDR));
475475

476476
pr_info("%s, Guest physical address: 0x%016llx ",
477477
__func__, exec_vmread64(VMX_GUEST_PHYSICAL_ADDR_FULL));

hypervisor/arch/x86/guest/instr_emul_wrapper.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ int vm_get_register(struct vcpu *vcpu, enum cpu_reg_name reg, uint64_t *retval)
4444
uint32_t field = get_vmcs_field(reg);
4545

4646
if (field != VMX_INVALID_VMCS_FIELD) {
47-
if (reg < CPU_REG_64BIT_LAST) {
47+
if (reg < CPU_REG_NATURAL_LAST) {
4848
*retval = exec_vmread(field);
49+
} else if (reg < CPU_REG_64BIT_LAST) {
50+
*retval = exec_vmread64(field);
4951
} else {
5052
*retval = (uint64_t)exec_vmread16(field);
5153
}
@@ -77,8 +79,10 @@ int vm_set_register(struct vcpu *vcpu, enum cpu_reg_name reg, uint64_t val)
7779
uint32_t field = get_vmcs_field(reg);
7880

7981
if (field != VMX_INVALID_VMCS_FIELD) {
80-
if (reg < CPU_REG_64BIT_LAST) {
82+
if (reg < CPU_REG_NATURAL_LAST) {
8183
exec_vmwrite(field, val);
84+
} else if (reg <= CPU_REG_64BIT_LAST) {
85+
exec_vmwrite64(field, val);
8286
} else {
8387
exec_vmwrite16(field, (uint16_t)val);
8488
}

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ int start_vcpu(struct vcpu *vcpu)
193193
*/
194194
instlen = vcpu->arch_vcpu.inst_len;
195195
rip = cur_context->rip;
196-
exec_vmwrite(VMX_GUEST_RIP, ((rip + instlen) &
197-
0xFFFFFFFFFFFFFFFF));
196+
exec_vmwrite(VMX_GUEST_RIP, ((rip +(uint64_t)instlen) &
197+
0xFFFFFFFFFFFFFFFFUL));
198198

199199
/* Resume the VM */
200200
status = vmx_vmrun(cur_context, VM_RESUME, ibrs_type);

hypervisor/arch/x86/guest/vlapic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,14 +2221,14 @@ apicv_set_tmr(__unused struct vlapic *vlapic, uint32_t vector, bool level)
22212221
mask = 1UL << (vector % 64U);
22222222
field = VMX_EOI_EXIT(vector);
22232223

2224-
val = exec_vmread(field);
2224+
val = exec_vmread64(field);
22252225
if (level) {
22262226
val |= mask;
22272227
} else {
22282228
val &= ~mask;
22292229
}
22302230

2231-
exec_vmwrite(field, val);
2231+
exec_vmwrite64(field, val);
22322232
}
22332233

22342234
/* Update the VMX_EOI_EXIT according to related tmr */

hypervisor/arch/x86/trusty.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void save_world_ctx(struct run_context *context)
232232
* the wrmsr handler keeps track of 'ia32_pat', and we only
233233
* need to load 'vmx_ia32_pat' here.
234234
*/
235-
context->vmx_ia32_pat = exec_vmread(VMX_GUEST_IA32_PAT_FULL);
235+
context->vmx_ia32_pat = exec_vmread64(VMX_GUEST_IA32_PAT_FULL);
236236
context->ia32_efer = exec_vmread64(VMX_GUEST_IA32_EFER_FULL);
237237
context->ia32_sysenter_esp = exec_vmread(VMX_GUEST_IA32_SYSENTER_ESP);
238238
context->ia32_sysenter_eip = exec_vmread(VMX_GUEST_IA32_SYSENTER_EIP);
@@ -426,7 +426,7 @@ static bool init_secure_world_env(struct vcpu *vcpu,
426426

427427
exec_vmwrite(VMX_GUEST_RSP,
428428
TRUSTY_EPT_REBASE_GPA + size);
429-
exec_vmwrite(VMX_TSC_OFFSET_FULL,
429+
exec_vmwrite64(VMX_TSC_OFFSET_FULL,
430430
vcpu->arch_vcpu.contexts[SECURE_WORLD].tsc_offset);
431431

432432
return setup_trusty_info(vcpu, size, base_hpa);

0 commit comments

Comments
 (0)