Re: [sos-linux-ext-patches] [RFC 05/14] x86/apic: Initialize APIC ID for Secure AVIC

From: Melody (Huibo) Wang
Date: Sat Nov 09 2024 - 15:13:55 EST


Hi Neeraj,

On 9/13/2024 4:36 AM, Neeraj Upadhyay wrote:
> 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);
> }
>
With this warning that hv_apic_id and apic_id is different, do you still want to set_reg after that? If so, wonder why we have this warning?

Thanks,
Melody
> static void x2apic_savic_setup(void)