From ff56b6f62d4626bba1eb41ec210905df607a80eb Mon Sep 17 00:00:00 2001 From: Sainath Grandhi Date: Thu, 1 Nov 2018 15:42:24 -0700 Subject: [PATCH] hv: Add support for leaf 0xb emulation ACRN does not support platforms that do not have x2APIC mode of LAPIC in hardware. With this patch, x2APIC is exposed to guests by default. Extended Topology Leaf 0xb in cpuid returns x2APIC ID and topology information to OS. This patch adds support to return guest topology and guest x2APIC ID. Number of SMT siblings is returned as 0. Tracked-On: #1626 Signed-off-by: Sainath Grandhi Reviewed-by: Xu Anthony --- hypervisor/arch/x86/cpu.c | 2 -- hypervisor/arch/x86/cpuid.c | 41 +++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/hypervisor/arch/x86/cpu.c b/hypervisor/arch/x86/cpu.c index 672152aee..5345b2da0 100644 --- a/hypervisor/arch/x86/cpu.c +++ b/hypervisor/arch/x86/cpu.c @@ -23,8 +23,6 @@ static uint64_t startup_paddr = 0UL; /* physical cpu active bitmap, support up to 64 cpus */ uint64_t pcpu_active_bitmap = 0UL; -/* X2APIC mode is disabled by default. */ -bool x2apic_enabled = false; static bool skip_l1dfl_vmentry; static uint64_t x86_arch_capabilities; diff --git a/hypervisor/arch/x86/cpuid.c b/hypervisor/arch/x86/cpuid.c index 0e0c29649..c9784ba37 100644 --- a/hypervisor/arch/x86/cpuid.c +++ b/hypervisor/arch/x86/cpuid.c @@ -6,8 +6,6 @@ #include -extern bool x2apic_enabled; - static inline struct vcpuid_entry *find_vcpuid_entry(const struct vcpu *vcpu, uint32_t leaf_arg, uint32_t subleaf) { @@ -337,13 +335,6 @@ void guest_cpuid(struct vcpu *vcpu, *edx &= ~CPUID_EDX_MTRR; #endif - /* Patching X2APIC, X2APIC mode is disabled by default. */ - if (x2apic_enabled) { - *ecx |= CPUID_ECX_x2APIC; - } else { - *ecx &= ~CPUID_ECX_x2APIC; - } - /* mask pcid */ *ecx &= ~CPUID_ECX_PCID; @@ -369,13 +360,33 @@ void guest_cpuid(struct vcpu *vcpu, case 0x0bU: /* Patching X2APIC */ - if (!x2apic_enabled) { - *eax = 0U; - *ebx = 0U; - *ecx = 0U; - *edx = 0U; - } else { + if (is_vm0(vcpu->vm)) { cpuid_subleaf(leaf, subleaf, eax, ebx, ecx, edx); + } else { + *ecx = subleaf & 0xFFU; + *edx = vlapic_get_apicid(vcpu_vlapic(vcpu)); + /* No HT emulation for UOS */ + switch (subleaf) { + case 0U: + *eax = 0U; + *ebx = 1U; + *ecx |= (1U << 8U); + break; + case 1U: + if (vcpu->vm->hw.created_vcpus == 1U) { + *eax = 0U; + } else { + *eax = (uint32_t)fls32(vcpu->vm->hw.created_vcpus - 1U) + 1U; + } + *ebx = vcpu->vm->hw.created_vcpus; + *ecx |= (2U << 8U); + break; + default: + *eax = 0U; + *ebx = 0U; + *ecx |= (0U << 8U); + break; + } } break;