i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
cover i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
The two bugs were introduced when xsaves feature was added by commit 301e90675c3f ("target/i386: Enable support for XSAVES based features").
Xiaoyao Li (2):
i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not
available
i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and
FEAT_XSAVE_XSS_HI leafs
target/i386/cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/2 i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available
Leaf FEAT_XSAVE_XSS_LO and FEAT_XSAVE_XSS_HI also need to be cleared when CPUID_EXT_XSAVE is not set.
--- target/i386/cpu.c | 2 ++ 1 file changed, 2 insertions(+)
target/i386/cpu.c +2 -0
@@ -6926,6 +6926,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)if (!(env->features[FEAT_1_ECX ] &CPUID_EXT_XSAVE )) { env->features[FEAT_XSAVE_XCR0_LO ] =0 ; env->features[FEAT_XSAVE_XCR0_HI ] =0 ; + env->features[FEAT_XSAVE_XSS_LO ] =0 ; + env->features[FEAT_XSAVE_XSS_HI ] =0 ;return ; }
Signature · 1 line
2.34.1
Re: [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available
Quoted 14 lines · Xiaoyao
Leaf
FEAT_XSAVE_XSS_LOandFEAT_XSAVE_XSS_HIalso need to be cleared whenCPUID_EXT_XSAVEis not set.Fixes 301e90675c3f ("target/i386: Enable support for XSAVES based features")Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/cpu.c | 2 ++ 1 file changed, 2 insertions(+)target/i386/cpu.c +0
-0
target/i386/cpu.c static void x86_cpu_enable_xsave_components(X86CPU *cpu) · line 6932
Quoted 7 lines
target/i386/cpu.c +2
-0@@ -6926,6 +6926,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)if (!(env->features[FEAT_1_ECX ] &CPUID_EXT_XSAVE )) { env->features[FEAT_XSAVE_XCR0_LO ] =0 ; env->features[FEAT_XSAVE_XCR0_HI ] =0 ; + env->features[FEAT_XSAVE_XSS_LO ] =0 ; + env->features[FEAT_XSAVE_XSS_HI ] =0 ;return ; }
Thanks for fixing this!
Quoted 1 line
PATCH 2/2 i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs
In reply to Xiaoyao LiThe value of FEAT_XSAVE_XCR0_HI leaf and FEAT_XSAVE_XSS_HI leaf also need to be masked by XCR0 and XSS mask respectively, to make it logically correct.
--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/cpu.c +2 -2
@@ -6946,9 +6946,9 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu) } env->features[FEAT_XSAVE_XCR0_LO ] = mask &CPUID_XSTATE_XCR0_MASK ; - env->features[FEAT_XSAVE_XCR0_HI ] = mask >>32 ; + env->features[FEAT_XSAVE_XCR0_HI ] = (mask &CPUID_XSTATE_XCR0_MASK ) >>32 ; env->features[FEAT_XSAVE_XSS_LO ] = mask &CPUID_XSTATE_XSS_MASK ; - env->features[FEAT_XSAVE_XSS_HI ] = mask >>32 ; + env->features[FEAT_XSAVE_XSS_HI ] = (mask &CPUID_XSTATE_XSS_MASK ) >>32 ; }/***** Steps involved on loading and filtering CPUID data
Signature · 1 line
2.34.1
Re: [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs
Quoted 15 lines · Xiaoyao
The value of
FEAT_XSAVE_XCR0_HIleaf andFEAT_XSAVE_XSS_HIleaf also need to be masked by XCR0 and XSS mask respectively, to make it logically correct.Fixes 301e90675c3f ("target/i386: Enable support for XSAVES based features")Signed-off-by Xiaoyao Li <[email protected]>--- target/i386/cpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/cpu.c +0
-0
target/i386/cpu.c static void x86_cpu_enable_xsave_components(X86CPU *cpu) · line 6952
Quoted 9 lines
target/i386/cpu.c +2
-2@@ -6946,9 +6946,9 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu) } env->features[FEAT_XSAVE_XCR0_LO ] = mask &CPUID_XSTATE_XCR0_MASK ; - env->features[FEAT_XSAVE_XCR0_HI ] = mask >>32 ; + env->features[FEAT_XSAVE_XCR0_HI ] = (mask &CPUID_XSTATE_XCR0_MASK ) >>32 ; env->features[FEAT_XSAVE_XSS_LO ] = mask &CPUID_XSTATE_XSS_MASK ; - env->features[FEAT_XSAVE_XSS_HI ] = mask >>32 ; + env->features[FEAT_XSAVE_XSS_HI ] = (mask &CPUID_XSTATE_XSS_MASK ) >>32 ; }
Thanks for fixing this!
Quoted 2 lines
target/i386/cpu.c +0
-0/***** Steps involved on loading and filtering CPUID data
Hi Xiaoyao,
Quoted 8 lines · Xiaoyao Li
Date: Mon, 15 Jan 2024 04:13:23 -0500
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 0/2] i386/cpu: Two minor fixes for
x86_cpu_enable_xsave_components()
X-Mailer: git-send-email 2.34.1The two bugs were introduced when xsaves feature was added by commit
301e90675c3f("target/i386: Enable support for XSAVES based features").
Could you please provide more details about reproducing these two bugs? If I'm able, I'd be glad to help you to test and verify them.
Regards,
Zhao
Quoted 14 lines
Xiaoyao Li (2):
i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs whenCPUID_EXT_XSAVEis not
available
i386/cpu: Mask with XCR0/XSS mask forFEAT_XSAVE_XCR0_HIand
FEAT_XSAVE_XSS_HIleafstarget/i386/cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)Signature · 1 line
2.34.1
Quoted 9 lines · Zhao Liu
Hi Xiaoyao,
Quoted 6 lines · Xiaoyao Li
Date: Mon, 15 Jan 2024 04:13:23 -0500
From: Xiaoyao Li <[email protected]>
Subject: [PATCH 0/2] i386/cpu: Two minor fixes for
x86_cpu_enable_xsave_components()
X-Mailer: git-send-email 2.34.1
Quoted 5 lines
Quoted 2 lines
The two bugs were introduced when xsaves feature was added by commit
301e90675c3f("target/i386: Enable support for XSAVES based features").Could you please provide more details about reproducing these two bugs? If I'm able, I'd be glad to help you to test and verify them.
There are potential bugs and currently we don't have test step to trigger it. Because for patch 1, KVM doesn't support arch-lbr virtualization yet, which is the first user in QEMU of xss. Once KVM merges the arch-lbr series, using "-cpu xxx,+arch-lbr,-xsave" can expose arch-lbr to guest, which violates the architectural behavior of xfeatures.
For patch2, current code just happens to work correctly because there is not xfeature in upper 32-bit get defined yet. But I think make the code logically correct is important and we shouldn't depend on the happened-to-work code.
Quoted 17 lines
Regards,
ZhaoQuoted 14 lines
Xiaoyao Li (2):
i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs whenCPUID_EXT_XSAVEis not
available
i386/cpu: Mask with XCR0/XSS mask forFEAT_XSAVE_XCR0_HIand
FEAT_XSAVE_XSS_HIleafstarget/i386/cpu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)Signature · 1 line
2.34.1
Paolo Bonzini
AppliedQueued, thanks.
Paolo