From deb35a0de94a4c5599ce85323583f9d52b840aca Mon Sep 17 00:00:00 2001 From: Tw Date: Thu, 25 Nov 2021 09:50:40 +0800 Subject: [PATCH] hv: fix cpuid 0x2 mismatch when launch RTVM use atom core When CPUID executes with EAX set to 02H, the processor returns information about cache and TLB information. This information is percpu related, and should be obtained directly from the physical cpu. BTW, this patch is backported from v2.7 branch. Tracked-On: #6931 Signed-off-by: Tw Reviewed-by: Fei Li --- hypervisor/arch/x86/guest/vcpuid.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index b6eed1f31..58820d67f 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -490,6 +490,11 @@ static int32_t set_vcpuid_extended_function(struct acrn_vm *vm) return result; } +static inline bool is_percpu_related(uint32_t leaf) +{ + return ((leaf == 0x1U) || (leaf == 0xbU) || (leaf == 0xdU) || (leaf == 0x19U) || (leaf == 0x80000001U) || (leaf == 0x2U)); +} + int32_t set_vcpuid_entries(struct acrn_vm *vm) { int32_t result; @@ -509,8 +514,7 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm) vm->vcpuid_level = limit; for (i = 1U; i <= limit; i++) { - /* cpuid 1/0xb is percpu related */ - if ((i == 1U) || (i == 0xbU) || (i == 0xdU) || (i == 0x19U)) { + if (is_percpu_related(i)) { continue; } @@ -604,11 +608,6 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm) return result; } -static inline bool is_percpu_related(uint32_t leaf) -{ - return ((leaf == 0x1U) || (leaf == 0xbU) || (leaf == 0xdU) || (leaf == 0x19U) || (leaf == 0x80000001U)); -} - static void guest_cpuid_01h(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { uint32_t apicid = vlapic_get_apicid(vcpu_vlapic(vcpu)); @@ -850,11 +849,11 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t default: /* - * In this switch statement, leaf shall either be 0x01U or 0x0bU - * or 0x0dU or 0x80000001U. All the other cases have been handled properly - * before this switch statement. - * Gracefully return if prior case clauses have not been met. + * In this switch statement, leaf 0x01/0x0b/0x0d/0x19/0x80000001 + * shall be handled specifically. All the other cases + * just return physical value. */ + cpuid_subleaf(leaf, *ecx, eax, ebx, ecx, edx); break; } }