Skip to content

KVM: pVMX: Use fpu_user_cfg.max_size to compute fpsize#77

Open
mmisono wants to merge 1 commit intointel-staging:pkvm-v6.18from
mmisono:fix/pkvm-v6.18-fpsize
Open

KVM: pVMX: Use fpu_user_cfg.max_size to compute fpsize#77
mmisono wants to merge 1 commit intointel-staging:pkvm-v6.18from
mmisono:fix/pkvm-v6.18-fpsize

Conversation

@mmisono
Copy link

@mmisono mmisono commented Feb 24, 2026

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")

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 +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants