Skip to content

Commit d7d2ef8

Browse files
lifeixjren1
authored andcommitted
hv: xsave: remove is_xsave_supported
Update X86_FEATURE_OSXSAVE when enabled and replace is_xsave_supported with cpu_has_cap(X86_FEATURE_OSXSAVE). Signed-off-by: Li, Fei1 <fei1.li@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 6560ff3 commit d7d2ef8

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,6 @@ bool is_vapic_virt_reg_supported(void)
761761
return ((cpu_caps.vapic_features & VAPIC_FEATURE_VIRT_REG) != 0);
762762
}
763763

764-
bool is_xsave_supported(void)
765-
{
766-
/*
767-
*todo:
768-
*below flag also should be tested, but current it will be false
769-
*as it is not updated after turning on the host's CR4.OSXSAVE bit,
770-
*will be fixed in cpuid related patch.
771-
*boot_cpu_data.cpuid_leaves[FEAT_1_ECX] & CPUID_ECX_OSXSAVE
772-
**/
773-
return !!(boot_cpu_data.cpuid_leaves[FEAT_1_ECX] & CPUID_ECX_XSAVE);
774-
}
775-
776764
static void cpu_xsave_init(void)
777765
{
778766
uint64_t val64;
@@ -781,5 +769,15 @@ static void cpu_xsave_init(void)
781769
CPU_CR_READ(cr4, &val64);
782770
val64 |= CR4_OSXSAVE;
783771
CPU_CR_WRITE(cr4, val64);
772+
773+
if (get_cpu_id() == CPU_BOOT_ID) {
774+
uint32_t ecx, unused;
775+
cpuid(CPUID_FEATURES, &unused, &unused, &ecx, &unused);
776+
777+
/* if set, update it */
778+
if (ecx & CPUID_ECX_OSXSAVE)
779+
boot_cpu_data.cpuid_leaves[FEAT_1_ECX] |=
780+
CPUID_ECX_OSXSAVE;
781+
}
784782
}
785783
}

hypervisor/arch/x86/cpuid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void guest_cpuid(struct vcpu *vcpu,
356356
break;
357357

358358
case 0x0d:
359-
if (!is_xsave_supported()) {
359+
if (!cpu_has_cap(X86_FEATURE_OSXSAVE)) {
360360
*eax = 0;
361361
*ebx = 0;
362362
*ecx = 0;

hypervisor/arch/x86/vmx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ static void init_exec_ctrl(struct vcpu *vcpu)
933933
exec_vmwrite(VMX_TPR_THRESHOLD, 0);
934934
}
935935

936-
if (is_xsave_supported()) {
936+
if (cpu_has_cap(X86_FEATURE_OSXSAVE)) {
937937
exec_vmwrite64(VMX_XSS_EXITING_BITMAP_FULL, 0);
938938
value32 |= VMX_PROCBASED_CTLS2_XSVE_XRSTR;
939939
}

hypervisor/include/arch/x86/cpu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ int hv_main(int cpu_id);
258258
bool is_vapic_supported(void);
259259
bool is_vapic_intr_delivery_supported(void);
260260
bool is_vapic_virt_reg_supported(void);
261-
bool is_xsave_supported(void);
262261
bool cpu_has_cap(uint32_t bit);
263262

264263
/* Read control register */

0 commit comments

Comments
 (0)