[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <fc113a81-b5b8-aaae-5799-c6d49b77b2b4@redhat.com>
Date: Mon, 13 Dec 2021 10:16:27 +0100
From: Paolo Bonzini <pbonzini@...hat.com>
To: Yang Zhong <yang.zhong@...el.com>, x86@...nel.org,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com
Cc: seanjc@...gle.com, jun.nakajima@...el.com, kevin.tian@...el.com,
jing2.liu@...ux.intel.com, jing2.liu@...el.com
Subject: Re: [PATCH 09/19] kvm: x86: Prepare reallocation check
On 12/8/21 01:03, Yang Zhong wrote:
> + u64 xcr0 = vcpu->arch.xcr0 & XFEATURE_MASK_USER_DYNAMIC;
> +
> + /* For any state which is enabled dynamically */
> + if ((xfd & xcr0) != xcr0) {
> + u64 request = (xcr0 ^ xfd) & xcr0;
> + struct fpu_guest *guest_fpu = &vcpu->arch.guest_fpu;
> +
> + /*
> + * If requested features haven't been enabled, update
> + * the request bitmap and tell the caller to request
> + * dynamic buffer reallocation.
> + */
> + if ((guest_fpu->user_xfeatures & request) != request) {
> + vcpu->arch.guest_fpu.realloc_request = request;
This should be "|=". If you have
wrmsr(XFD, dynamic-feature-1);
...
wrmsr(XFD, dynamic-feature-2);
then the space for both features has to be allocated.
> + return true;
> + }
> + }
> +
This is just:
struct fpu_guest *guest_fpu = &vcpu->arch.guest_fpu;
u64 xcr0 = vcpu->arch.xcr0 & XFEATURE_MASK_USER_DYNAMIC;
u64 dynamic_enabled = xcr0 & ~xfd;
if (!(dynamic_enabled & ~guest_fpu->user_xfeatures))
return false;
/*
* This should actually not be in guest_fpu, see review of
* patch 2. Also see above regarding "=" vs "|=".
*/
vcpu->arch.guest_fpu.realloc_request |= dynamic_enabled;
return true;
But without documentation I'm not sure why this exit-to-userspace step
is needed:
- if (dynamic_enabled & ~guest_fpu->user_perm) != 0, then this is a
userspace error and you can #GP the guest without any issue. Userspace
is buggy
- if (dynamic_enabled & ~guest_fpu->user_xfeatures) != 0, but the
feature *is* permitted, then it is okay to just go on and reallocate the
guest FPU.
Paolo
Powered by blists - more mailing lists