Messages in this thread | | | Subject | Re: [PATCH v1] kvm: x86: Revise guest_fpu xcomp_bv field | From | "Liu, Jing2" <> | Date | Mon, 22 Feb 2021 11:21:06 +0800 |
| |
On 2/9/2021 1:24 AM, Sean Christopherson wrote: > On Mon, Feb 08, 2021, Dave Hansen wrote: >> On 2/8/21 8:16 AM, Jing Liu wrote: >>> -#define XSTATE_COMPACTION_ENABLED (1ULL << 63) >>> - >>> static void fill_xsave(u8 *dest, struct kvm_vcpu *vcpu) >>> { >>> struct xregs_state *xsave = &vcpu->arch.guest_fpu->state.xsave; >>> @@ -4494,7 +4492,8 @@ static void load_xsave(struct kvm_vcpu *vcpu, u8 *src) >>> /* Set XSTATE_BV and possibly XCOMP_BV. */ >>> xsave->header.xfeatures = xstate_bv; >>> if (boot_cpu_has(X86_FEATURE_XSAVES)) >>> - xsave->header.xcomp_bv = host_xcr0 | XSTATE_COMPACTION_ENABLED; >>> + xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | >>> + xfeatures_mask_all; > This is wrong, xfeatures_mask_all also tracks supervisor states. When looking at SDM Vol2 XSAVES instruction Operation part, it says as follows,
RFBM ← (XCR0 OR IA32_XSS) AND EDX:EAX; COMPMASK ← RFBM OR 80000000_00000000H; ...
XCOMP_BV field in XSAVE header ← COMPMASK;
So it seems xcomp_bv also tracks supervisor states?
BRs, Jing > >> Are 'host_xcr0' and 'xfeatures_mask_all' really interchangeable? If so, >> shouldn't we just remove 'host_xcr0' everywhere? > I think so? But use xfeatures_mask_user(). > > In theory, host_xss can also be replaced with the _supervisor() and _dynamic() > variants. That code needs a good hard look at the _dynamic() features, which is > currently just architectural LBRs. E.g. I wouldn't be surprised if KVM currently > fails to save/restore arch LBRs due to the bit not being set in host_xss.
| |