diff --git a/xen/arch/x86/genapic/x2apic.c b/xen/arch/x86/genapic/x2apic.c index 371dd100c742..fe8e664e1b63 100644 --- a/xen/arch/x86/genapic/x2apic.c +++ b/xen/arch/x86/genapic/x2apic.c @@ -30,8 +30,11 @@ static inline u32 x2apic_cluster(unsigned int cpu) static void cf_check init_apic_ldr_x2apic_cluster(void) { unsigned int cpu, this_cpu = smp_processor_id(); + uint32_t id = apic_read(APIC_ID); + uint32_t ldr = apic_read(APIC_LDR); - per_cpu(cpu_2_logical_apicid, this_cpu) = apic_read(APIC_LDR); + ASSERT(x2apic_ldr_from_id(id) == ldr); + per_cpu(cpu_2_logical_apicid, this_cpu) = ldr; if ( per_cpu(cluster_cpus, this_cpu) ) { diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c index 9cfc82666ae5..2a010a6363b7 100644 --- a/xen/arch/x86/hvm/vlapic.c +++ b/xen/arch/x86/hvm/vlapic.c @@ -1064,11 +1064,6 @@ static const struct hvm_mmio_ops vlapic_mmio_ops = { .write = vlapic_mmio_write, }; -static uint32_t x2apic_ldr_from_id(uint32_t id) -{ - return ((id & ~0xf) << 12) | (1 << (id & 0xf)); -} - static void set_x2apic_id(struct vlapic *vlapic) { const struct vcpu *v = vlapic_vcpu(vlapic); diff --git a/xen/arch/x86/include/asm/apic.h b/xen/arch/x86/include/asm/apic.h index 7b5a0832c05e..8a892fa2fa5b 100644 --- a/xen/arch/x86/include/asm/apic.h +++ b/xen/arch/x86/include/asm/apic.h @@ -148,6 +148,11 @@ static inline void ack_APIC_irq(void) apic_write(APIC_EOI, 0); } +static inline uint32_t x2apic_ldr_from_id(uint32_t id) +{ + return ((id & ~0xf) << 12) | (1 << (id & 0xf)); +} + extern int get_maxlvt(void); extern void clear_local_APIC(void); extern void connect_bsp_APIC (void);