]> xenbits.xensource.com Git - libvirt.git/commitdiff
virHostCPUGetCPUID: Add comment on how KVM_GET_SUPPORTED_CPUID works
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 Apr 2022 10:47:25 +0000 (12:47 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 25 Apr 2022 14:38:01 +0000 (16:38 +0200)
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>
src/util/virhostcpu.c

index 011ef8a153a64dfb47767514f48b30075f44215b..6be00a5b7662695f1f37e9fb081e91f72146e5ff 100644 (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) +