From 7edf800f1694fbf39805925cf3470f2f4b96464a Mon Sep 17 00:00:00 2001 From: Xin Zhang Date: Mon, 27 Nov 2023 14:43:48 +0800 Subject: [PATCH] Expose CPUID leaf 0x1f to guest with patched x2APIC ID CPUID leaf 1f is preferred superset of leaf 0b, currently ACRN exposes leaf 0b but leaf 1f is empty so the 2 leaves mismatch, and so application will follow the SDM to check 1f first. Tracked-On: #8608 Signed-off-by: Xin Zhang --- hypervisor/arch/x86/guest/vcpuid.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hypervisor/arch/x86/guest/vcpuid.c b/hypervisor/arch/x86/guest/vcpuid.c index e2d5d4e0a..dd82fb869 100644 --- a/hypervisor/arch/x86/guest/vcpuid.c +++ b/hypervisor/arch/x86/guest/vcpuid.c @@ -499,7 +499,8 @@ 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 == 0x80000001U) || (leaf == 0x2U) || (leaf == 0x1aU)); + return ((leaf == 0x1U) || (leaf == 0xbU) || (leaf == 0xdU) || (leaf == 0x19U) || + (leaf == 0x1fU) || (leaf == 0x80000001U) || (leaf == 0x2U) || (leaf == 0x1aU)); } int32_t set_vcpuid_entries(struct acrn_vm *vm) @@ -776,6 +777,14 @@ static void guest_cpuid_19h(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx } } +static void guest_cpuid_1fh(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +{ + cpuid_subleaf(0x1fU, *ecx, eax, ebx, ecx, edx); + + /* Patching X2APIC */ + *edx = vlapic_get_apicid(vcpu_vlapic(vcpu)); +} + static void guest_cpuid_80000001h(const struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { @@ -859,13 +868,17 @@ void guest_cpuid(struct acrn_vcpu *vcpu, uint32_t *eax, uint32_t *ebx, uint32_t guest_cpuid_19h(vcpu, eax, ebx, ecx, edx); break; + case 0x1fU: + guest_cpuid_1fh(vcpu, eax, ebx, ecx, edx); + break; + case 0x80000001U: guest_cpuid_80000001h(vcpu, eax, ebx, ecx, edx); break; default: /* - * In this switch statement, leaf 0x01/0x0b/0x0d/0x19/0x80000001 + * In this switch statement, leaf 0x01/0x0b/0x0d/0x19/0x1f/0x80000001 * shall be handled specifically. All the other cases * just return physical value. */