On 1/27/22 14:45, Yang Zhong wrote:
Thanks Paolo, from your below KVM changes:
   
https://lore.kernel.org/kvm/20220126152210.3044876-3-pbonz...@redhat.com/T/#m7bf9a03c47c29d21deb78604bc290a45aa5e98f5

   So the changes in kvm_arch_get_supported_cpuid() like below?
   +    } else if (function == 0xd && index == 0 && reg == R_EAX) {

&& (reg == R_EAX || reg == R_EDX)

   +    struct kvm_device_attr attr = {
   +            .group = 0,
   +            .attr = KVM_X86_XCOMP_GUEST_SUPP,
   +            .addr = (unsigned long) &bitmask
   +    };
   +
   +    kvm_fd = open_kvm_dev_path_or_exit();
   +    rc = ioctl(kvm_fd, KVM_GET_DEVICE_ATTR, &attr);

Yes, you need to check if it fails though (and in that case do not assign). The file descriptor is already there in QEMU, so you can use kvm_ioctl.

  +     ret = bitmask;

To support R_EDX as well:

ret = (reg == R_EAX) ? bitmask : bitmask >> 32;

   So in the kvm_request_xsave_components(), we can do below steps?
+ /* Check supported_xr0 firstly */
   +    rc = kvm_arch_get_supported_cpuid(s, 0xd, 0, R_EAX);
   +    if (!(rc & XFEATURE_XTILE_MASK)) {

rc = kvm_arch_get_supported_cpuid(s, 0xd, 0,
                                  (xdata_bit < 32 ? R_EAX : R_EDX));
if (!(rc & BIT(xdata_bit & 31)) {
    ...
}

Also please use warn_report and don't exit. With e.g. "-cpu foo,amx,xfd,enforce" you should not reach this code at all if the host lacks AMX.

Thanks,

Paolo

   +        error_report("host xcr0 can't support AMX xdata and rc=0x%lx", rc);
   +        exit(EXIT_FAILURE);
   +    }

   +   /* request amx permission */
   +   syscall(ARCH_REQ_XCOMP_GUEST_PERM, xdata_bit);


   +   /* check amx permission */
   +   syscall(ARCH_GET_XCOMP_GUEST_PERM);


Reply via email to