Skip to content

Commit ff56b6f

Browse files
Sainath Grandhilijinxia
authored andcommitted
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 <sainath.grandhi@intel.com> Reviewed-by: Xu Anthony <anthony.xu@intel.com>
1 parent f3aa20a commit ff56b6f

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

hypervisor/arch/x86/cpu.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ static uint64_t startup_paddr = 0UL;
2323
/* physical cpu active bitmap, support up to 64 cpus */
2424
uint64_t pcpu_active_bitmap = 0UL;
2525

26-
/* X2APIC mode is disabled by default. */
27-
bool x2apic_enabled = false;
2826
static bool skip_l1dfl_vmentry;
2927
static uint64_t x86_arch_capabilities;
3028

hypervisor/arch/x86/cpuid.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <hypervisor.h>
88

9-
extern bool x2apic_enabled;
10-
119
static inline struct vcpuid_entry *find_vcpuid_entry(const struct vcpu *vcpu,
1210
uint32_t leaf_arg, uint32_t subleaf)
1311
{
@@ -337,13 +335,6 @@ void guest_cpuid(struct vcpu *vcpu,
337335
*edx &= ~CPUID_EDX_MTRR;
338336
#endif
339337

340-
/* Patching X2APIC, X2APIC mode is disabled by default. */
341-
if (x2apic_enabled) {
342-
*ecx |= CPUID_ECX_x2APIC;
343-
} else {
344-
*ecx &= ~CPUID_ECX_x2APIC;
345-
}
346-
347338
/* mask pcid */
348339
*ecx &= ~CPUID_ECX_PCID;
349340

@@ -369,13 +360,33 @@ void guest_cpuid(struct vcpu *vcpu,
369360

370361
case 0x0bU:
371362
/* Patching X2APIC */
372-
if (!x2apic_enabled) {
373-
*eax = 0U;
374-
*ebx = 0U;
375-
*ecx = 0U;
376-
*edx = 0U;
377-
} else {
363+
if (is_vm0(vcpu->vm)) {
378364
cpuid_subleaf(leaf, subleaf, eax, ebx, ecx, edx);
365+
} else {
366+
*ecx = subleaf & 0xFFU;
367+
*edx = vlapic_get_apicid(vcpu_vlapic(vcpu));
368+
/* No HT emulation for UOS */
369+
switch (subleaf) {
370+
case 0U:
371+
*eax = 0U;
372+
*ebx = 1U;
373+
*ecx |= (1U << 8U);
374+
break;
375+
case 1U:
376+
if (vcpu->vm->hw.created_vcpus == 1U) {
377+
*eax = 0U;
378+
} else {
379+
*eax = (uint32_t)fls32(vcpu->vm->hw.created_vcpus - 1U) + 1U;
380+
}
381+
*ebx = vcpu->vm->hw.created_vcpus;
382+
*ecx |= (2U << 8U);
383+
break;
384+
default:
385+
*eax = 0U;
386+
*ebx = 0U;
387+
*ecx |= (0U << 8U);
388+
break;
389+
}
379390
}
380391
break;
381392

0 commit comments

Comments
 (0)