qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 6/7] target-i386: xsave: Calculate set of xsave


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH 6/7] target-i386: xsave: Calculate set of xsave components on realize
Date: Tue, 27 Sep 2016 17:06:48 -0300
User-agent: Mutt/1.7.0 (2016-08-17)

On Fri, Sep 23, 2016 at 04:45:35PM -0300, Eduardo Habkost wrote:
[...]
> @@ -2971,6 +2952,29 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, 
> FeatureWord w)
>      }
>  }
>  
> +/* Calculate XSAVE components based on the configured CPU feature flags */
> +static void x86_cpu_enable_xsave_components(X86CPU *cpu)
> +{
> +    CPUX86State *env = &cpu->env;
> +    int i;
> +
> +    env->xsave_components = (XSTATE_FP_MASK | XSTATE_SSE_MASK);

We shouldn't set xsave_components if XSAVE is disabled. The following fix was
squashed while applying:

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e6525e7..8bef3cf 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2958,6 +2958,10 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     CPUX86State *env = &cpu->env;
     int i;
 
+    if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
+        return;
+    }
+
     env->xsave_components = (XSTATE_FP_MASK | XSTATE_SSE_MASK);
     for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
         const ExtSaveArea *esa = &x86_ext_save_areas[i];

> +    for (i = 2; i < ARRAY_SIZE(x86_ext_save_areas); i++) {
> +        const ExtSaveArea *esa = &x86_ext_save_areas[i];
> +        if (env->features[esa->feature] & esa->bits) {
> +            env->xsave_components |= (1ULL << i);
> +        }
> +    }
> +
> +    if (kvm_enabled()) {
> +        KVMState *s = kvm_state;
> +        uint64_t kvm_mask = kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EDX);
> +        kvm_mask <<= 32;
> +        kvm_mask |= kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EAX);
> +        env->xsave_components &= kvm_mask;
> +    }
> +}
> +
>  #define IS_INTEL_CPU(env) ((env)->cpuid_vendor1 == CPUID_VENDOR_INTEL_1 && \
>                             (env)->cpuid_vendor2 == CPUID_VENDOR_INTEL_2 && \
>                             (env)->cpuid_vendor3 == CPUID_VENDOR_INTEL_3)
> @@ -3016,6 +3020,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error 
> **errp)
>          cpu->env.features[w] &= ~minus_features[w];
>      }
>  
> +    x86_cpu_enable_xsave_components(cpu);
>  
>      /* CPUID[EAX=7,ECX=0].EBX always increased level automatically: */
>      x86_cpu_adjust_feat_level(cpu, FEAT_7_0_EBX);
> diff --git a/target-i386/cpu.h b/target-i386/cpu.h
> index aaa45f0..6c457ed 100644
> --- a/target-i386/cpu.h
> +++ b/target-i386/cpu.h
> @@ -1122,6 +1122,7 @@ typedef struct CPUX86State {
>      uint32_t cpuid_vendor3;
>      uint32_t cpuid_version;
>      FeatureWordArray features;
> +    uint64_t xsave_components;
>      uint32_t cpuid_model[12];
>  
>      /* MTRRs */
> -- 
> 2.7.4
> 
> 

-- 
Eduardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]