KVM: pVMX: Use fpu_user_cfg.max_size to compute fpsize#77
KVM: pVMX: Use fpu_user_cfg.max_size to compute fpsize#77mmisono wants to merge 1 commit intointel-staging:pkvm-v6.18from
Conversation
Since pKVM enforces the host's cpuids, calculate fpsize based on the value that the hardware supports instead of that of the vCPU reported. Without this, pKVM fails to boot a VM on a machine with Intel AMX, as crosvm does not request that feature. fixes: 58f48d1 ("KVM: pVMX: Add new fpstate memory for xfd") Signed-off-by: Masanori Misono <m.misono760@gmail.com>
| int ret; | ||
|
|
||
| fpsize = PAGE_ALIGN(vcpu->arch.guest_fpu.fpstate->size + | ||
| fpsize = PAGE_ALIGN(fpu_user_cfg.max_size + |
There was a problem hiding this comment.
Seems I didn't fully understand the root cause. I don't have a machine with Intel AMX feature, but suppose if the guest cpuid has enabled the XFD feature, the vcpu->arch.guest_fpu.fpstate->size will be set by the host KVM via kvm_check_cpuid -> fpu_enable_guest_xfd_features -> __xfd_enable_feature ->fpstate_realloc. Is this true from your side?
But as you mentioned in the commit message, the crosvm doesn't request the XFD feature for the guest, then this function will not be called as (vcpu->arch.guest_fpu.xfeatures & XFEATURE_MASK_USER_DYNAMIC) == false.
There was a problem hiding this comment.
On my machine, pkvm_vcpu_after_set_cpuid hypercallls fails as __xfd_enable_feature() fails here. AFAICT, in the hypercall handler, pkvm_enforce_cpuid() populate actual cpu's cpuid entries. Then pkvm_vcpu_after_set_cpuid() calls kvm_set_cpuid() -> kvm_check_cpuid() -> fpu_enable_guest_xfd_features() -> __xfd_enable_feature(), which triggers ENOMEM.
then this function will not be called as (vcpu->arch.guest_fpu.xfeatures & XFEATURE_MASK_USER_DYNAMIC) == false.
yes, pkvm_vcpu_realloc_fpstate() is not called because of this. On my machine, I get:
[ 138.684348] pkvm_host: [pkvm] vcpu->arch.guest_fpu.xfeatures & XFEATURE_MASK_USER_DYNAMIC = 0
[ 138.684351] pkvm_host: [pkvm] vcpu->arch.guest_fpu.fpstate->size = 2560
[ 138.684353] pkvm_host: [pkvm] fpu_user_cfg.max_features & XFEATURE_MASK_USER_DYNAMIC = 0x40000
[ 138.684353] pkvm_host: [pkvm] fpu_user_cfg.max_size = 11008
There was a problem hiding this comment.
It looks like pkvm_enforce_cpuid() populate the actual cpu's cpuid entries, leaf 0xd and its subleaves, are not the same with the cpuid entries set by the crosvm?
If so, npVM should be fine?
There was a problem hiding this comment.
It looks like pkvm_enforce_cpuid() populate the actual cpu's cpuid entries, leaf 0xd and its subleaves, are not the same with the cpuid entries set by the crosvm?
That is my understanding. Alternatively, enforce_cpuid() could respect crosvm's xfd configuration.
If so, npVM should be fine?
My commit message is ambiguous but I have this issue for pVM. I just confirmed that npVM works fine without this change as you said.
There was a problem hiding this comment.
That is my understanding. Alternatively, enforce_cpuid() could respect crosvm's xfd configuration.
This seems to be a better way.
My commit message is ambiguous but I have this issue for pVM. I just confirmed that npVM works fine without this change as you said.
Thanks for confirming this.
There was a problem hiding this comment.
This seems to be a better way.
as this patch fixes my issue, I don't plan work on this for the moment. Please feel free to discard/adopt this change in any way.
Since pKVM enforces the host's cpuids, calculate fpsize based on the value that the hardware supports instead of that of the vCPU reported.
Without this, pKVM fails to boot a VM on a machine with Intel AMX, as crosvm does not request that feature.
fixes: 58f48d1 ("KVM: pVMX: Add new fpstate memory for xfd")