Commit 988896bb authored by Leonardo Bras's avatar Leonardo Bras Committed by Paolo Bonzini

x86/kvm/fpu: Remove kvm_vcpu_arch.guest_supported_xcr0

kvm_vcpu_arch currently contains the guest supported features in both
guest_supported_xcr0 and guest_fpu.fpstate->user_xfeatures field.

Currently both fields are set to the same value in
kvm_vcpu_after_set_cpuid() and are not changed anywhere else after that.

Since it's not good to keep duplicated data, remove guest_supported_xcr0.

To keep the code more readable, introduce kvm_guest_supported_xcr()
and kvm_guest_supported_xfd() to replace the previous usages of
guest_supported_xcr0.
Signed-off-by: default avatarLeonardo Bras <leobras@redhat.com>
Message-Id: <20220217053028.96432-3-leobras@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent ad856280
...@@ -703,7 +703,6 @@ struct kvm_vcpu_arch { ...@@ -703,7 +703,6 @@ struct kvm_vcpu_arch {
struct fpu_guest guest_fpu; struct fpu_guest guest_fpu;
u64 xcr0; u64 xcr0;
u64 guest_supported_xcr0;
struct kvm_pio_request pio; struct kvm_pio_request pio;
void *pio_data; void *pio_data;
......
...@@ -282,6 +282,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) ...@@ -282,6 +282,7 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
{ {
struct kvm_lapic *apic = vcpu->arch.apic; struct kvm_lapic *apic = vcpu->arch.apic;
struct kvm_cpuid_entry2 *best; struct kvm_cpuid_entry2 *best;
u64 guest_supported_xcr0;
best = kvm_find_cpuid_entry(vcpu, 1, 0); best = kvm_find_cpuid_entry(vcpu, 1, 0);
if (best && apic) { if (best && apic) {
...@@ -293,10 +294,10 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) ...@@ -293,10 +294,10 @@ static void kvm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu)
kvm_apic_set_version(vcpu); kvm_apic_set_version(vcpu);
} }
vcpu->arch.guest_supported_xcr0 = guest_supported_xcr0 =
cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent); cpuid_get_supported_xcr0(vcpu->arch.cpuid_entries, vcpu->arch.cpuid_nent);
vcpu->arch.guest_fpu.fpstate->user_xfeatures = vcpu->arch.guest_supported_xcr0; vcpu->arch.guest_fpu.fpstate->user_xfeatures = guest_supported_xcr0;
kvm_update_pv_runtime(vcpu); kvm_update_pv_runtime(vcpu);
......
...@@ -984,6 +984,16 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu) ...@@ -984,6 +984,16 @@ void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu)
} }
EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state); EXPORT_SYMBOL_GPL(kvm_load_host_xsave_state);
static inline u64 kvm_guest_supported_xcr0(struct kvm_vcpu *vcpu)
{
return vcpu->arch.guest_fpu.fpstate->user_xfeatures;
}
static inline u64 kvm_guest_supported_xfd(struct kvm_vcpu *vcpu)
{
return kvm_guest_supported_xcr0(vcpu) & XFEATURE_MASK_USER_DYNAMIC;
}
static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
{ {
u64 xcr0 = xcr; u64 xcr0 = xcr;
...@@ -1003,7 +1013,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr) ...@@ -1003,7 +1013,7 @@ static int __kvm_set_xcr(struct kvm_vcpu *vcpu, u32 index, u64 xcr)
* saving. However, xcr0 bit 0 is always set, even if the * saving. However, xcr0 bit 0 is always set, even if the
* emulated CPU does not support XSAVE (see kvm_vcpu_reset()). * emulated CPU does not support XSAVE (see kvm_vcpu_reset()).
*/ */
valid_bits = vcpu->arch.guest_supported_xcr0 | XFEATURE_MASK_FP; valid_bits = kvm_guest_supported_xcr0(vcpu) | XFEATURE_MASK_FP;
if (xcr0 & ~valid_bits) if (xcr0 & ~valid_bits)
return 1; return 1;
...@@ -3706,8 +3716,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -3706,8 +3716,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
!guest_cpuid_has(vcpu, X86_FEATURE_XFD)) !guest_cpuid_has(vcpu, X86_FEATURE_XFD))
return 1; return 1;
if (data & ~(XFEATURE_MASK_USER_DYNAMIC & if (data & ~kvm_guest_supported_xfd(vcpu))
vcpu->arch.guest_supported_xcr0))
return 1; return 1;
fpu_update_guest_xfd(&vcpu->arch.guest_fpu, data); fpu_update_guest_xfd(&vcpu->arch.guest_fpu, data);
...@@ -3717,8 +3726,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -3717,8 +3726,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
!guest_cpuid_has(vcpu, X86_FEATURE_XFD)) !guest_cpuid_has(vcpu, X86_FEATURE_XFD))
return 1; return 1;
if (data & ~(XFEATURE_MASK_USER_DYNAMIC & if (data & ~kvm_guest_supported_xfd(vcpu))
vcpu->arch.guest_supported_xcr0))
return 1; return 1;
vcpu->arch.guest_fpu.xfd_err = data; vcpu->arch.guest_fpu.xfd_err = data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment