target/i386: Switch back XFRM value
PATCH 1/1 target/i386: Switch back XFRM value
The previous patch wrongly replaced FEAT_XSAVE_XCR0_{LO|HI} with FEAT_XSAVE_XSS_{LO|HI} in CPUID(EAX=12,ECX=1):ECX, which made SGX enclave only supported SSE and x87 feature(xfrm=0x3).
--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/cpu.c +2 -2
@@ -5584,8 +5584,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, }else { *eax &= env->features[FEAT_SGX_12_1_EAX ]; *ebx &=0 ;/* ebx reserve */ - *ecx &= env->features[FEAT_XSAVE_XSS_LO ]; - *edx &= env->features[FEAT_XSAVE_XSS_HI ]; + *ecx &= env->features[FEAT_XSAVE_XCR0_LO ]; + *edx &= env->features[FEAT_XSAVE_XCR0_HI ];/* FP and SSE are always allowed regardless of XSAVE/XCR0. */ *ecx |=XSTATE_FP_MASK |XSTATE_SSE_MASK ;
Signature · 1 line
2.30.2
Quoted 2 lines · Yang Zhong
The previous patch wrongly replaced FEAT_XSAVE_XCR0_{LO|HI} with FEAT_XSAVE_XSS_{LO|HI} in CPUID(EAX=12,ECX=1):ECX, which made SGX
^
Nit: both ECX and EDX are wrongly set, but not only ECX.
Quoted 1 line
enclave only supported SSE and x87 feature(xfrm=0x3).
Is this true? Perhaps I am missing something, but it seems env-
Quoted 1 line
features[FEAT_XSAVE_XCR0_LO] only includes LBR bit, which is bit 15.
/* Calculate XSAVE components based on the configured CPU feature flags */ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
{
...
env->features[FEAT_XSAVE_XSS_LO] = mask & CPUID_XSTATE_XSS_MASK;
...
}/* CPUID feature bits available in XSS */
#define CPUID_XSTATE_XSS_MASK (XSTATE_ARCH_LBR_MASK)
Quoted 13 lines
Fixes 301e90675c3f ("target/i386: Enable support for XSAVES based features")Signed-off-by Yang Zhong <[email protected]>--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/cpu.c +0
-0
target/i386/cpu.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, · line 5591
Quoted 10 lines
target/i386/cpu.c +2
-2@@ -5584,8 +5584,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, }else { *eax &= env->features[FEAT_SGX_12_1_EAX ]; *ebx &=0 ;/* ebx reserve */ - *ecx &= env->features[FEAT_XSAVE_XSS_LO ]; - *edx &= env->features[FEAT_XSAVE_XSS_HI ]; + *ecx &= env->features[FEAT_XSAVE_XCR0_LO ]; + *edx &= env->features[FEAT_XSAVE_XCR0_HI ];/* FP and SSE are always allowed regardless of XSAVE/XCR0. */ *ecx |=XSTATE_FP_MASK |XSTATE_SSE_MASK ;
The code looks good:
Quoted 7 lines · Kai
Quoted 2 lines · Yang Zhong
The previous patch wrongly replaced FEAT_XSAVE_XCR0_{LO|HI} with FEAT_XSAVE_XSS_{LO|HI} in CPUID(EAX=12,ECX=1):ECX, which made SGX
^Nit: both ECX and EDX are wrongly set, but not only ECX.
Yes, I will change to CPUID(EAX=12,ECX=1):{ECX,EDX}, thanks!
Quoted 4 lines
Quoted 1 line
enclave only supported SSE and x87 feature(xfrm=0x3).
Is this true? Perhaps I am missing something, but it seems env-
Quoted 1 line
features[FEAT_XSAVE_XCR0_LO] only includes LBR bit, which is bit 15.
We printed the XFRM value from SGX SDK to find this issue.
Quoted 40 lines
/* Calculate XSAVE components based on the configured CPU feature flags */ static void
x86_cpu_enable_xsave_components(X86CPU *cpu){ ... env->features[FEAT_XSAVE_XSS_LO] = mask & CPUID_XSTATE_XSS_MASK; ... }/* CPUID feature bits available in XSS */
#defineCPUID_XSTATE_XSS_MASK(XSTATE_ARCH_LBR_MASK)Quoted 13 lines
Fixes 301e90675c3f ("target/i386: Enable support for XSAVES based features")Signed-off-by Yang Zhong <[email protected]>--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/cpu.c +0
-0target/i386/cpu.c void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, · line 5591
Quoted 10 lines
target/i386/cpu.c +2
-2@@ -5584,8 +5584,8 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, }else { *eax &= env->features[FEAT_SGX_12_1_EAX ]; *ebx &=0 ;/* ebx reserve */ - *ecx &= env->features[FEAT_XSAVE_XSS_LO ]; - *edx &= env->features[FEAT_XSAVE_XSS_HI ]; + *ecx &= env->features[FEAT_XSAVE_XCR0_LO ]; + *edx &= env->features[FEAT_XSAVE_XCR0_HI ];/* FP and SSE are always allowed regardless of XSAVE/XCR0. */ *ecx |=XSTATE_FP_MASK |XSTATE_SSE_MASK ;The code looks good:
Reviewed-by Kai Huang <[email protected]>
Quoted 6 lines · Yang Zhong
Quoted 4 lines
Quoted 1 line
enclave only supported SSE and x87 feature(xfrm=0x3).
Is this true? Perhaps I am missing something, but it seems env-
Quoted 1 line
features[FEAT_XSAVE_XCR0_LO] only includes LBR bit, which is bit 15.
We printed the XFRM value from SGX SDK to find this issue.
I don't know how you added the print, but the exact value that set to SGX CPUID is irrelevant, as it is wrong anyway. The value can also differ when you run on different machines, etc. IMHO in changelog we just need to point out the fact that the XSAVE enabling patch wrongly messed up with SGX CPUID and this patch fixes that.