Sorry, hit send on the wrong window. This is the only patch that will require a bit more work.

On 1/18/22 13:52, Paolo Bonzini wrote:
@@ -124,6 +150,8 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
      MachineState *ms = MACHINE(x86ms);
      MachineClass *mc = MACHINE_GET_CLASS(x86ms);
+    /* Request AMX pemission for guest */
+    x86_xsave_req_perm();
      x86_cpu_set_default_version(default_cpu_version);

This should be done before creating a CPU with support for state component 18.  It happens in kvm_init_vcpu, with the following call stack:

     kvm_init_vcpu
     kvm_vcpu_thread_fn
     kvm_start_vcpu_thread
     qemu_init_vcpu
     x86_cpu_realizefn

The issue however is that this has to be done before KVM_GET_SUPPORTED_CPUID and KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2).

For the former, you can assume that anything returned by ARCH_GET_XCOMP_GUEST_PERM will be returned by KVM_GET_SUPPORTED_CPUID in CPUID[0xD].EDX:EAX, so you can:

- add it to kvm_arch_get_supported_cpuid

... together with the other special cases (otherwise x86_cpu_get_supported_feature_word complains that XTILEDATA is not available)

- change kvm_cpu_xsave_init to use host_cpuid instead of kvm_arch_get_supported_cpuid.

- call ARCH_REQ_XCOMP_GUEST_PERM from x86_cpu_enable_xsave_components, with a conditional like

    if (kvm_enabled()) {
        kvm_request_xsave_components(cpu, mask);
    }

KVM_CHECK_EXTENSION(KVM_CAP_XSAVE2) is actually not a problem; the ioctl is only called from kvm_arch_init_vcpu and therefore after x86_cpu_enable_xsave_components.

Thanks,

Paolo


Reply via email to