Skip to contentSkip to conversation

Two Fixes for xsave compoent features

PATCH In review Xiaoyao Li 3 participants 8 messages Jul 16, 2020 – Aug 18, 2020

lore
Share & tools
lore

Xiaoyao Li

author
#0 lore raw

cover Two Fixes for xsave compoent features

Two simple fixes for XSAVE component features, please see each one for details.

Xiaoyao Li (2):
i386/cpu: Clear FEAT_XSAVE_COMP_{LO,HI} when XSAVE is not available i386/cpu: Mask off unsupported XSAVE components

 target/i386/cpu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.18.4
author
#1 lore raw

PATCH 1/2 i386/cpu: Clear FEAT_XSAVE_COMP_{LO, HI} when XSAVE is not available

Per Intel SDM vol 1, 13.2, if CPUID.1:ECX.XSAVE[bit 26] is 0, the processor provides no further enumeration through CPUID function 0DH.

---
 target/i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target/i386/cpu.c +2 -0
index 1e5123251d74..f5f11603e805 100644
@@ -6261,6 +6261,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     uint64_t mask;
 
     if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
+        env->features[FEAT_XSAVE_COMP_LO] = 0;
+        env->features[FEAT_XSAVE_COMP_HI] = 0;
         return;
     }
 
Signature · 1 line
2.18.4
#2 lore raw

Re: [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_COMP_{LO,HI} when XSAVE is not available

Quoted 2 lines · Xiaoyao Li

Per Intel SDM vol 1, 13.2, if CPUID.1:ECX.XSAVE[bit 26] is 0, the processor provides no further enumeration through CPUID function 0DH.

Can you explain what's the bug you are trying to fix? env->features[FEAT_XSAVE_COMP_*] is already initialized as zero.

Quoted 22 lines
---
 target/i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target/i386/cpu.c +2 -0
index 1e5123251d74..f5f11603e805 100644
@@ -6261,6 +6261,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     uint64_t mask;
 
     if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
+        env->features[FEAT_XSAVE_COMP_LO] = 0;
+        env->features[FEAT_XSAVE_COMP_HI] = 0;
         return;
     }
 
Signature · 1 line
2.18.4
Signature · 1 line
Eduardo
author
#3 lore raw

Re: [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_COMP_{LO, HI} when XSAVE is not available

Quoted 6 lines · Eduardo Habkost
Quoted 2 lines · Xiaoyao Li

Per Intel SDM vol 1, 13.2, if CPUID.1:ECX.XSAVE[bit 26] is 0, the processor provides no further enumeration through CPUID function 0DH.

Can you explain what's the bug you are trying to fix? env->features[FEAT_XSAVE_COMP_*] is already initialized as zero.

When "-cpu host", it's not zero I think.

Quoted 24 lines
Quoted 23 lines
---
  target/i386/cpu.c | 2 ++
  1 file changed, 2 insertions(+)
target/i386/cpu.c +2 -0
index 1e5123251d74..f5f11603e805 100644
@@ -6261,6 +6261,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
      uint64_t mask;
 
      if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
+        env->features[FEAT_XSAVE_COMP_LO] = 0;
+        env->features[FEAT_XSAVE_COMP_HI] = 0;
          return;
      }
 
Signature · 1 line
2.18.4
#4 lore raw

Re: [PATCH 1/2] i386/cpu: Clear FEAT_XSAVE_COMP_{LO, HI} when XSAVE is not available

In reply to Xiaoyao Li
Quoted 14 lines · Xiaoyao Li

Per Intel SDM vol 1, 13.2, if CPUID.1:ECX.XSAVE[bit 26] is 0, the processor provides no further enumeration through CPUID function 0DH.

---
 target/i386/cpu.c | 2 ++
 1 file changed, 2 insertions(+)
target/i386/cpu.c +0 -0
index 1e5123251d74..f5f11603e805 100644

target/i386/cpu.c static void x86_cpu_enable_xsave_components(X86CPU *cpu) · line 6268

Quoted 8 lines
target/i386/cpu.c +2 -0
@@ -6261,6 +6261,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     uint64_t mask;
 
     if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
+        env->features[FEAT_XSAVE_COMP_LO] = 0;
+        env->features[FEAT_XSAVE_COMP_HI] = 0;
         return;
     }
 

Queued this patch, noting in the commit message that it affects "-cpu host,-xsave".

Paolo

author
#5 lore raw

PATCH 2/2 i386/cpu: Mask off unsupported XSAVE components

In reply to Xiaoyao Li

When setting up XSAVE components, it needs to mask off those unsupported by KVM.

---
 target/i386/cpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/i386/cpu.c +4 -2
index f5f11603e805..efc92334b7b1 100644
@@ -6274,8 +6274,10 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
         }
     }
 
-    env->features[FEAT_XSAVE_COMP_LO] = mask;
-    env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
+    env->features[FEAT_XSAVE_COMP_LO] = mask &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_LO, cpu->migratable);
+    env->features[FEAT_XSAVE_COMP_HI] = (mask >> 32) &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_HI, cpu->migratable);
 }
 
 /***** Steps involved on loading and filtering CPUID data
Signature · 1 line
2.18.4
#6 lore raw

Re: [PATCH 2/2] i386/cpu: Mask off unsupported XSAVE components

Quoted 4 lines · Xiaoyao Li

When setting up XSAVE components, it needs to mask off those unsupported by KVM.

We must never disable CPUID features silently based on host capabilities, otherwise we can't guarantee guest ABI stability when migrating to another host. Filtering of features should involve a call to mark_unavailable_features() (or some equivalent mechanism) so we can report the missing features properly through QMP.

Could you explain what's the bug you are trying to fix? The loop at x86_cpu_filter_features() is already supposed to disable features unsupported by the host.

Quoted 24 lines
---
 target/i386/cpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/i386/cpu.c +4 -2
index f5f11603e805..efc92334b7b1 100644
@@ -6274,8 +6274,10 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
         }
     }
 
-    env->features[FEAT_XSAVE_COMP_LO] = mask;
-    env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
+    env->features[FEAT_XSAVE_COMP_LO] = mask &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_LO, cpu->migratable);
+    env->features[FEAT_XSAVE_COMP_HI] = (mask >> 32) &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_HI, cpu->migratable);
 }
 
 /***** Steps involved on loading and filtering CPUID data
Signature · 1 line
2.18.4
Signature · 1 line
Eduardo
author
#7 lore raw

Re: [PATCH 2/2] i386/cpu: Mask off unsupported XSAVE components

Quoted 13 lines · Eduardo Habkost
Quoted 4 lines · Xiaoyao Li

When setting up XSAVE components, it needs to mask off those unsupported by KVM.

We must never disable CPUID features silently based on host capabilities, otherwise we can't guarantee guest ABI stability when migrating to another host. Filtering of features should involve a call to mark_unavailable_features() (or some equivalent mechanism) so we can report the missing features properly through QMP.

Quoted 3 lines

Could you explain what's the bug you are trying to fix? The loop at x86_cpu_filter_features() is already supposed to disable features unsupported by the host.

Sorry, I forgot x86_cpu_filter_features() totally when code inspection.

Quoted 25 lines
Quoted 24 lines
---
  target/i386/cpu.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
target/i386/cpu.c +4 -2
index f5f11603e805..efc92334b7b1 100644
@@ -6274,8 +6274,10 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
          }
      }
 
-    env->features[FEAT_XSAVE_COMP_LO] = mask;
-    env->features[FEAT_XSAVE_COMP_HI] = mask >> 32;
+    env->features[FEAT_XSAVE_COMP_LO] = mask &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_LO, cpu->migratable);
+    env->features[FEAT_XSAVE_COMP_HI] = (mask >> 32) &
+        x86_cpu_get_supported_feature_word(FEAT_XSAVE_COMP_HI, cpu->migratable);
  }
 
  /***** Steps involved on loading and filtering CPUID data
Signature · 1 line
2.18.4