virHostCPUGetCPUID: Add comment on how KVM_GET_SUPPORTED_CPUID works

The commit adding the code fetching host CPU flags via the
KVM_GET_SUPPORTED_CPUID didn't describe at all why such an alghorithm is
needed.

Add a comment from the documentation outlining how the userspace
function is expected to allocate memory here.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2022-04-25 12:47:25 +02:00
parent fe027c9b0a
commit 25327c9d69

View File

@ -1327,6 +1327,13 @@ virHostCPUGetCPUID(void)
return NULL;
}
/* Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 structure
* with the 'nent' field indicating the number of entries in the variable-size
* array 'entries'. If the number of entries is too low to describe the cpu
* capabilities, an error (E2BIG) is returned. If the number is too high,
* the 'nent' field is adjusted and an error (ENOMEM) is returned. If the
* number is just right, the 'nent' field is adjusted to the number of valid
* entries in the 'entries' array, which is then filled. */
for (i = 1; i < INT32_MAX; i *= 2) {
g_autofree struct kvm_cpuid2 *kvm_cpuid = NULL;
kvm_cpuid = g_malloc0(sizeof(struct kvm_cpuid2) +