Skip to content

Commit ab29614

Browse files
gzhai7lijinxia
authored andcommitted
HV: VMX reshuffle: put EPT check before enabling
Current EPT check runs after EPT enabling in init_exec_ctrl. This patch fixes wrong order. Signed-off-by: Edwin Zhai <edwin.zhai@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 112b4ea commit ab29614

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ bool x2apic_enabled = false;
4141

4242
struct cpu_capability {
4343
uint8_t vapic_features;
44+
uint8_t ept_features;
4445
};
4546
static struct cpu_capability cpu_caps;
4647

4748
struct cpuinfo_x86 boot_cpu_data;
4849

4950
static void bsp_boot_post(void);
5051
static void cpu_secondary_post(void);
51-
static void vapic_cap_detect(void);
52+
static void cpu_cap_detect(void);
5253
static void cpu_xsave_init(void);
5354
static void set_current_cpu_id(uint16_t pcpu_id);
5455
static void print_hv_banner(void);
@@ -237,6 +238,11 @@ static int hardware_detect_support(void)
237238
return -ENODEV;
238239
}
239240

241+
if (!is_ept_supported()) {
242+
pr_fatal("%s, EPT not supported\n", __func__);
243+
return -ENODEV;
244+
}
245+
240246
ret = check_vmx_mmu_cap();
241247
if (ret != 0) {
242248
return ret;
@@ -484,7 +490,7 @@ static void bsp_boot_post(void)
484490
set_fs_base();
485491
#endif
486492

487-
vapic_cap_detect();
493+
cpu_cap_detect();
488494

489495
cpu_xsave_init();
490496

@@ -838,6 +844,26 @@ static bool is_ctrl_setting_allowed(uint64_t msr_val, uint32_t ctrl)
838844
return ((((uint32_t)(msr_val >> 32UL)) & ctrl) == ctrl);
839845
}
840846

847+
static void ept_cap_detect(void)
848+
{
849+
uint64_t msr_val;
850+
851+
cpu_caps.ept_features = 0U;
852+
853+
/* Read primary processor based VM control. */
854+
msr_val = msr_read(MSR_IA32_VMX_PROCBASED_CTLS);
855+
856+
/* Check if secondary processor based VM control is available. */
857+
if ((msr_val & (((uint64_t)VMX_PROCBASED_CTLS_SECONDARY) << 32)) == 0U)
858+
return;
859+
860+
/* Read secondary processor based VM control. */
861+
msr_val = msr_read(MSR_IA32_VMX_PROCBASED_CTLS2);
862+
863+
if (is_ctrl_setting_allowed(msr_val, VMX_PROCBASED_CTLS2_EPT))
864+
cpu_caps.ept_features = 1U;
865+
}
866+
841867
static void vapic_cap_detect(void)
842868
{
843869
uint8_t features;
@@ -880,6 +906,17 @@ static void vapic_cap_detect(void)
880906
cpu_caps.vapic_features = features;
881907
}
882908

909+
static void cpu_cap_detect(void)
910+
{
911+
vapic_cap_detect();
912+
ept_cap_detect();
913+
}
914+
915+
bool is_ept_supported(void)
916+
{
917+
return (cpu_caps.ept_features != 0U);
918+
}
919+
883920
bool is_vapic_supported(void)
884921
{
885922
return ((cpu_caps.vapic_features & VAPIC_FEATURE_VIRT_ACCESS) != 0U);

hypervisor/arch/x86/ept.c

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,35 +144,6 @@ uint64_t hpa2gpa(struct vm *vm, uint64_t hpa)
144144
| (hpa & (pg_size - 1UL)));
145145
}
146146

147-
bool is_ept_supported(void)
148-
{
149-
bool status;
150-
uint64_t tmp64;
151-
152-
/* Read primary processor based VM control. */
153-
tmp64 = msr_read(MSR_IA32_VMX_PROCBASED_CTLS);
154-
155-
/* Check if secondary processor based VM control is available. */
156-
if ((tmp64 & MMU_MEM_ATTR_BIT_EXECUTE_DISABLE) != 0U) {
157-
/* Read primary processor based VM control. */
158-
tmp64 = msr_read(MSR_IA32_VMX_PROCBASED_CTLS2);
159-
160-
/* Check if EPT is supported. */
161-
if ((tmp64 & (((uint64_t)VMX_PROCBASED_CTLS2_EPT) << 32)) != 0U) {
162-
/* EPT is present. */
163-
status = true;
164-
} else {
165-
status = false;
166-
}
167-
168-
} else {
169-
/* Secondary processor based VM control is not present */
170-
status = false;
171-
}
172-
173-
return status;
174-
}
175-
176147
int ept_violation_vmexit_handler(struct vcpu *vcpu)
177148
{
178149
int status = -EINVAL, ret;

hypervisor/arch/x86/vmx.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,14 +1054,6 @@ static void init_exec_ctrl(struct vcpu *vcpu)
10541054
}
10551055
}
10561056

1057-
/* Check for EPT support */
1058-
if (is_ept_supported()) {
1059-
pr_dbg("EPT is supported");
1060-
}
1061-
else {
1062-
pr_err("Error: EPT is not supported");
1063-
}
1064-
10651057
/* Load EPTP execution control
10661058
* TODO: introduce API to make this data driven based
10671059
* on VMX_EPT_VPID_CAP

hypervisor/include/arch/x86/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ void trampoline_start16(void);
324324
bool is_vapic_supported(void);
325325
bool is_vapic_intr_delivery_supported(void);
326326
bool is_vapic_virt_reg_supported(void);
327+
bool is_ept_supported(void);
327328
bool cpu_has_cap(uint32_t bit);
328329
void load_cpu_state_data(void);
329330
void bsp_boot_init(void);

hypervisor/include/arch/x86/mmu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ static inline void clflush(volatile void *p)
376376
}
377377

378378
/* External Interfaces */
379-
bool is_ept_supported(void);
380379
uint64_t create_guest_initial_paging(struct vm *vm);
381380
void destroy_ept(struct vm *vm);
382381
uint64_t gpa2hpa(struct vm *vm, uint64_t gpa);

0 commit comments

Comments
 (0)