[RFC 05/14] x86/apic: Initialize APIC ID for Secure AVIC
From: Neeraj Upadhyay
Date: Fri Sep 13 2024 - 07:39:09 EST
Initialize the APIC ID in the APIC backing page with the
CPUID function 0000_000bh_EDX (Extended Topology Enumeration),
and ensure that APIC ID msr read from hypervisor is consistent
with the value read from CPUID.
Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@xxxxxxx>
---
arch/x86/kernel/apic/x2apic_savic.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/x86/kernel/apic/x2apic_savic.c b/arch/x86/kernel/apic/x2apic_savic.c
index 99151be4e173..09fbc1857bf3 100644
--- a/arch/x86/kernel/apic/x2apic_savic.c
+++ b/arch/x86/kernel/apic/x2apic_savic.c
@@ -14,6 +14,7 @@
#include <linux/sizes.h>
#include <asm/apic.h>
+#include <asm/cpuid.h>
#include <asm/sev.h>
#include "local.h"
@@ -200,6 +201,8 @@ static void x2apic_savic_send_IPI_mask_allbutself(const struct cpumask *mask, in
static void init_backing_page(void *backing_page)
{
+ u32 hv_apic_id;
+ u32 apic_id;
u32 val;
int i;
@@ -220,6 +223,13 @@ static void init_backing_page(void *backing_page)
val = read_msr_from_hv(APIC_LDR);
set_reg(backing_page, APIC_LDR, val);
+
+ /* Read APIC ID from Extended Topology Enumeration CPUID */
+ apic_id = cpuid_edx(0x0000000b);
+ hv_apic_id = read_msr_from_hv(APIC_ID);
+ WARN_ONCE(hv_apic_id != apic_id, "Inconsistent APIC_ID values: %d (cpuid), %d (msr)",
+ apic_id, hv_apic_id);
+ set_reg(backing_page, APIC_ID, apic_id);
}
static void x2apic_savic_setup(void)
--
2.34.1