Re: [PATCH 10/19] kvm: x86: Emulate WRMSR of guest IA32_XFD

Paolo Bonzini
2021-12-10T16:02:58Z

First, the MSR should be added to msrs_to_save_all and
kvm_cpu_cap_has(X86_FEATURE_XFD) should be checked in kvm_init_msr_list.

It seems that RDMSR support is missing, too.

More important, please include:

- documentation for the new KVM_EXIT_* value

- a selftest that explains how userspace should react to it.

This is a strong requirement for any new API (the first has been for
years; but the latter is also almost always respected these days). This
series should not have been submitted without documentation.

Also:

On 12/8/21 01:03, Yang Zhong wrote:
>
> + if (!guest_cpuid_has(vcpu, X86_FEATURE_XFD))
> + return 1;

This should allow msr->host_initiated always (even if XFD is not part of
CPUID). However, if XFD is nonzero and kvm_check_guest_realloc_fpstate
returns true, then it should return 1.

The selftest should also cover using KVM_GET_MSR/KVM_SET_MSR.

> + /* Setting unsupported bits causes #GP */
> + if (~XFEATURE_MASK_USER_DYNAMIC & data) {
> + kvm_inject_gp(vcpu, 0);
> + break;
> + }

This should check

if (data & ~(XFEATURE_MASK_USER_DYNAMIC &
vcpu->arch.guest_supported_xcr0))

instead.

Paolo