qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
@ 2024-01-15  9:13 Xiaoyao Li
  2024-01-15  9:13 ` [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available Xiaoyao Li
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Xiaoyao Li @ 2024-01-15  9:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Yang Weijiang

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(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available
  2024-01-15  9:13 [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Xiaoyao Li
@ 2024-01-15  9:13 ` Xiaoyao Li
  2024-01-17  6:39   ` Yang, Weijiang
  2024-01-15  9:13 ` [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs Xiaoyao Li
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Xiaoyao Li @ 2024-01-15  9:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Yang Weijiang

Leaf FEAT_XSAVE_XSS_LO and FEAT_XSAVE_XSS_HI also need to be cleared
when CPUID_EXT_XSAVE is not set.

Fixes: 301e90675c3f ("target/i386: Enable support for XSAVES based features")
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 target/i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 2524881ce245..b445e2957c4f 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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;
     }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs
  2024-01-15  9:13 [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Xiaoyao Li
  2024-01-15  9:13 ` [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available Xiaoyao Li
@ 2024-01-15  9:13 ` Xiaoyao Li
  2024-01-17  6:43   ` Yang, Weijiang
  2024-01-16 14:19 ` [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Zhao Liu
  2024-01-25  9:59 ` Paolo Bonzini
  3 siblings, 1 reply; 8+ messages in thread
From: Xiaoyao Li @ 2024-01-15  9:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Yang Weijiang

The 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.

Fixes: 301e90675c3f ("target/i386: Enable support for XSAVES based features")
Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
---
 target/i386/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index b445e2957c4f..a5c08944a483 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
  2024-01-15  9:13 [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Xiaoyao Li
  2024-01-15  9:13 ` [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available Xiaoyao Li
  2024-01-15  9:13 ` [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs Xiaoyao Li
@ 2024-01-16 14:19 ` Zhao Liu
  2024-01-16 15:42   ` Xiaoyao Li
  2024-01-25  9:59 ` Paolo Bonzini
  3 siblings, 1 reply; 8+ messages in thread
From: Zhao Liu @ 2024-01-16 14:19 UTC (permalink / raw)
  To: Xiaoyao Li; +Cc: Paolo Bonzini, qemu-devel, Yang Weijiang

Hi Xiaoyao,

On Mon, Jan 15, 2024 at 04:13:23AM -0500, Xiaoyao Li wrote:
> Date: Mon, 15 Jan 2024 04:13:23 -0500
> From: Xiaoyao Li <xiaoyao.li@intel.com>
> Subject: [PATCH 0/2] i386/cpu: Two minor fixes for
>  x86_cpu_enable_xsave_components()
> X-Mailer: git-send-email 2.34.1
> 
> 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.

Regards,
Zhao

> 
> 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(-)
> 
> -- 
> 2.34.1
> 
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
  2024-01-16 14:19 ` [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Zhao Liu
@ 2024-01-16 15:42   ` Xiaoyao Li
  0 siblings, 0 replies; 8+ messages in thread
From: Xiaoyao Li @ 2024-01-16 15:42 UTC (permalink / raw)
  To: Zhao Liu; +Cc: Paolo Bonzini, qemu-devel, Yang Weijiang

On 1/16/2024 10:19 PM, Zhao Liu wrote:
> Hi Xiaoyao,
> 
> On Mon, Jan 15, 2024 at 04:13:23AM -0500, Xiaoyao Li wrote:
>> Date: Mon, 15 Jan 2024 04:13:23 -0500
>> From: Xiaoyao Li <xiaoyao.li@intel.com>
>> Subject: [PATCH 0/2] i386/cpu: Two minor fixes for
>>   x86_cpu_enable_xsave_components()
>> X-Mailer: git-send-email 2.34.1
>>
>> 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.


> Regards,
> Zhao
> 
>>
>> 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(-)
>>
>> -- 
>> 2.34.1
>>
>>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available
  2024-01-15  9:13 ` [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available Xiaoyao Li
@ 2024-01-17  6:39   ` Yang, Weijiang
  0 siblings, 0 replies; 8+ messages in thread
From: Yang, Weijiang @ 2024-01-17  6:39 UTC (permalink / raw)
  To: Li, Xiaoyao, Paolo Bonzini; +Cc: qemu-devel@nongnu.org

On 1/15/2024 5:13 PM, Li, Xiaoyao wrote:
> Leaf FEAT_XSAVE_XSS_LO and FEAT_XSAVE_XSS_HI also need to be cleared
> when CPUID_EXT_XSAVE is not set.
>
> Fixes: 301e90675c3f ("target/i386: Enable support for XSAVES based features")
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
>   target/i386/cpu.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 2524881ce245..b445e2957c4f 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -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!
Reviewed-by: Yang Weijiang <weijiang.yang@intel.com>

>   



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs
  2024-01-15  9:13 ` [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs Xiaoyao Li
@ 2024-01-17  6:43   ` Yang, Weijiang
  0 siblings, 0 replies; 8+ messages in thread
From: Yang, Weijiang @ 2024-01-17  6:43 UTC (permalink / raw)
  To: Li, Xiaoyao, Paolo Bonzini; +Cc: qemu-devel@nongnu.org

On 1/15/2024 5:13 PM, Li, Xiaoyao wrote:
> The 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.
>
> Fixes: 301e90675c3f ("target/i386: Enable support for XSAVES based features")
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
>   target/i386/cpu.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index b445e2957c4f..a5c08944a483 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -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!
Reviewed-by: Yang Weijiang <weijiang.yang@intel.com>

>   
>   /***** Steps involved on loading and filtering CPUID data



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components()
  2024-01-15  9:13 [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Xiaoyao Li
                   ` (2 preceding siblings ...)
  2024-01-16 14:19 ` [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Zhao Liu
@ 2024-01-25  9:59 ` Paolo Bonzini
  3 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2024-01-25  9:59 UTC (permalink / raw)
  To: Xiaoyao Li; +Cc: qemu-devel, Yang Weijiang

Queued, thanks.

Paolo



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-25 10:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15  9:13 [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Xiaoyao Li
2024-01-15  9:13 ` [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available Xiaoyao Li
2024-01-17  6:39   ` Yang, Weijiang
2024-01-15  9:13 ` [PATCH 2/2] i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs Xiaoyao Li
2024-01-17  6:43   ` Yang, Weijiang
2024-01-16 14:19 ` [PATCH 0/2] i386/cpu: Two minor fixes for x86_cpu_enable_xsave_components() Zhao Liu
2024-01-16 15:42   ` Xiaoyao Li
2024-01-25  9:59 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).