1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

cpu: Only retrieve AT_HWCAP once

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>
This commit is contained in:
Andrea Bolognani 2021-02-05 15:01:46 +01:00
parent 82ffb81c9c
commit 03af15c024

View 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 */