]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Only retrieve AT_HWCAP once
authorAndrea Bolognani <abologna@redhat.com>
Fri, 5 Feb 2021 14:01:46 +0000 (15:01 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Tue, 9 Feb 2021 08:14:42 +0000 (09:14 +0100)
No need to fetch the same information twice.

As a side effect, this solves a bug where, on platforms where
elf_aux_info() is used instead of getauxval(), we would not
make sure the CPUID feature is available before attempting to
use it.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/cpu/cpu_arm.c

index aa3e5d8980a5794d7298b4c1ab7bc1243573f7c2..71702dbc91cdcbf43662081ae00b13c3bbb105e5 100644 (file)
@@ -557,12 +557,19 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data)
     size_t i;
 
 # if defined(WITH_GETAUXVAL)
-    if (!(getauxval(AT_HWCAP) & HWCAP_CPUID)) {
+    hwcaps = getauxval(AT_HWCAP);
+# elif defined(WITH_ELF_AUX_INFO)
+    elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
+# else
+#  error No routines to retrieve a value from the auxiliary vector
+# endif
+    VIR_DEBUG("CPU flags read from register:  0x%016lx", hwcaps);
+
+    if (!(hwcaps & HWCAP_CPUID)) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("CPUID registers unavailable"));
             return -1;
     }
-# endif
 
     /* read the cpuid data from MIDR_EL1 register */
     asm("mrs %0, MIDR_EL1" : "=r" (cpuid));
@@ -573,15 +580,6 @@ virCPUarmCpuDataFromRegs(virCPUarmData *data)
     /* parse the corresponding vendor_id bits */
     data->vendor_id = (cpuid >> 24) & 0xff;
 
-# if defined(WITH_GETAUXVAL)
-    hwcaps = getauxval(AT_HWCAP);
-# elif defined(WITH_ELF_AUX_INFO)
-    elf_aux_info(AT_HWCAP, &hwcaps, sizeof(u_long));
-# else
-#  error No routines to retrieve a value from the auxiliary vector
-# endif
-    VIR_DEBUG("CPU flags read from register:  0x%016lx", hwcaps);
-
     features = g_new0(char *, MAX_CPU_FLAGS + 1);
 
     /* shift bit map mask to parse for CPU flags */