From f7506424e4bf62cb9e70681a816feac9c2499c87 Mon Sep 17 00:00:00 2001 From: Haiwei Li Date: Thu, 18 Apr 2024 17:38:36 +0800 Subject: [PATCH] hv: cpuid: refactor per-cpu leaves definition CPUID returns processor identification and feature information. Different pcpus may return different infos. That is, the info is per-cpu. In hybrid architecture, per-cpu leaf is different from the previous. So introduce a struct percpu_cpuids to indicate the per-cpu leaf. struct percpu_cpuids will consist of two parts: generic percpu leaves and hybrid related percpu leaves. This patch is just to add generic percpu leaves. Tracked-On: #8608 Signed-off-by: Haiwei Li --- hypervisor/arch/x86/guest/vcpuid.c | 31 +++++++++++++++++++++++-- hypervisor/include/arch/x86/asm/cpuid.h | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index dd82fb869..eb2526e89 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -18,6 +18,11 @@ #include #include +static struct percpu_cpuids { + uint32_t leaf_nr; + uint32_t leaves[MAX_VM_VCPUID_ENTRIES]; +} pcpu_cpuids; + static inline const struct vcpuid_entry *local_find_vcpuid_entry(const struct acrn_vcpu *vcpu, uint32_t leaf, uint32_t subleaf) { @@ -499,8 +504,28 @@ static int32_t set_vcpuid_extended_function(struct acrn_vm *vm) static inline bool is_percpu_related(uint32_t leaf) { - return ((leaf == 0x1U) || (leaf == 0xbU) || (leaf == 0xdU) || (leaf == 0x19U) || - (leaf == 0x1fU) || (leaf == 0x80000001U) || (leaf == 0x2U) || (leaf == 0x1aU)); + uint32_t i; + bool ret = false; + + for (i = 0; i < pcpu_cpuids.leaf_nr; i++) { + if (leaf == pcpu_cpuids.leaves[i]) { + ret = true; + break; + } + } + return ret; +} + +static inline void percpu_cpuid_init(void) +{ + /* 0x1U, 0xBU, 0xDU, 0x19U, 0x1FU, 0x80000001U */ + uint32_t percpu_leaves[] = {CPUID_FEATURES, CPUID_EXTEND_TOPOLOGY, + CPUID_XSAVE_FEATURES, CPUID_KEY_LOCKER, + CPUID_V2_EXTEND_TOPOLOGY, CPUID_EXTEND_FUNCTION_1}; + + pcpu_cpuids.leaf_nr = sizeof(percpu_leaves)/sizeof(uint32_t); + memcpy_s(pcpu_cpuids.leaves, sizeof(percpu_leaves), + percpu_leaves, sizeof(percpu_leaves)); } int32_t set_vcpuid_entries(struct acrn_vm *vm) @@ -518,6 +543,8 @@ int32_t set_vcpuid_entries(struct acrn_vm *vm) } result = set_vcpuid_entry(vm, &entry); if (result == 0) { + percpu_cpuid_init(); + limit = entry.eax; vm->vcpuid_level = limit; diff --git a/hypervisor/include/arch/x86/asm/cpuid.h b/hypervisor/include/arch/x86/asm/cpuid.h index deb156699..37596fc21 100644 --- a/hypervisor/include/arch/x86/asm/cpuid.h +++ b/hypervisor/include/arch/x86/asm/cpuid.h @@ -167,8 +167,11 @@ #define CPUID_TLB 2U #define CPUID_SERIALNUM 3U #define CPUID_EXTEND_FEATURE 7U +#define CPUID_EXTEND_TOPOLOGY 0xBU #define CPUID_XSAVE_FEATURES 0xDU #define CPUID_RDT_ALLOCATION 0x10U +#define CPUID_KEY_LOCKER 0x19U +#define CPUID_V2_EXTEND_TOPOLOGY 0x1FU #define CPUID_MAX_EXTENDED_FUNCTION 0x80000000U #define CPUID_EXTEND_FUNCTION_1 0x80000001U #define CPUID_EXTEND_FUNCTION_2 0x80000002U