Skip to content

Commit d01d4a4

Browse files
suomilewissean-jc
authored andcommitted
KVM: selftests: Move XSAVE and OSXSAVE CPUID checks into AMX's init_regs()
Move the checks on XSAVE and OSXSAVE into init_regs() so that the XSAVE check is done before setting CR4.OSXSAVE, i.e. before a potential #GP, and so that the OSXSAVE check is performend immediately after enabling XSAVE in CR4. Signed-off-by: Aaron Lewis <aaronlewis@google.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> Link: https://lore.kernel.org/r/20230221163655.920289-12-mizhang@google.com [sean: keep XSAVE check, rewrite changelog accordingly] Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 2ab3991 commit d01d4a4

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

tools/testing/selftests/kvm/x86_64/amx_test.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ static inline void __xsavec(struct xstate *xstate, uint64_t rfbm)
109109
: "memory");
110110
}
111111

112-
static inline void check_cpuid_xsave(void)
113-
{
114-
GUEST_ASSERT(this_cpu_has(X86_FEATURE_XSAVE));
115-
GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE));
116-
}
117-
118112
static void check_xtile_info(void)
119113
{
120114
GUEST_ASSERT(this_cpu_has_p(X86_PROPERTY_XSTATE_MAX_SIZE_XCR0));
@@ -153,10 +147,13 @@ static void init_regs(void)
153147
{
154148
uint64_t cr4, xcr0;
155149

150+
GUEST_ASSERT(this_cpu_has(X86_FEATURE_XSAVE));
151+
156152
/* turn on CR4.OSXSAVE */
157153
cr4 = get_cr4();
158154
cr4 |= X86_CR4_OSXSAVE;
159155
set_cr4(cr4);
156+
GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE));
160157

161158
xcr0 = __xgetbv(0);
162159
xcr0 |= XFEATURE_MASK_XTILE;
@@ -169,7 +166,6 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg,
169166
struct xstate *xstate)
170167
{
171168
init_regs();
172-
check_cpuid_xsave();
173169
check_xtile_info();
174170
GUEST_SYNC(1);
175171

0 commit comments

Comments
 (0)