Re: [PATCH v3 14/17] x86/apic: Add kexec support for Secure AVIC

From: Francesco Lavra
Date: Fri Apr 11 2025 - 13:04:17 EST


On Tue, 2025-04-01 at 17:06 +0530, Neeraj Upadhyay wrote:
> Add a apic->teardown() callback to disable Secure AVIC before
> rebooting into the new kernel. This ensures that the new
> kernel does not access the old APIC backing page which was
> allocated by the previous kernel. Such accesses can happen
> if there are any APIC accesses done during guest boot before
> Secure AVIC driver probe is done by the new kernel (as Secure
> AVIC would have remained enabled in the Secure AVIC control
> msr).
>
> Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@xxxxxxx>
> ---
> Changes since v2:
>  - Change savic_unregister_gpa() interface to allow GPA
> unregistration
>    only for local CPU.
>
>  arch/x86/coco/sev/core.c            | 25 +++++++++++++++++++++++++
>  arch/x86/include/asm/apic.h         |  1 +
>  arch/x86/include/asm/sev.h          |  2 ++
>  arch/x86/kernel/apic/apic.c         |  3 +++
>  arch/x86/kernel/apic/x2apic_savic.c |  8 ++++++++
>  5 files changed, 39 insertions(+)
>
> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> index 9ade2b1993ad..2381859491db 100644
> --- a/arch/x86/coco/sev/core.c
> +++ b/arch/x86/coco/sev/core.c
> @@ -1588,6 +1588,31 @@ enum es_result savic_register_gpa(u64 gpa)
>         return res;
>  }
>  
> +enum es_result savic_unregister_gpa(u64 *gpa)
> +{
> +       struct ghcb_state state;
> +       struct es_em_ctxt ctxt;
> +       unsigned long flags;
> +       struct ghcb *ghcb;
> +       int ret = 0;

This should be an enum es_result, and there is no need to zero-
initialize it.

> +
> +       local_irq_save(flags);

guard(irqsave)();

> +
> +       ghcb = __sev_get_ghcb(&state);
> +
> +       vc_ghcb_invalidate(ghcb);
> +
> +       ghcb_set_rax(ghcb, -1ULL);
> +       ret = sev_es_ghcb_hv_call(ghcb, &ctxt,
> SVM_VMGEXIT_SECURE_AVIC,
> +                       SVM_VMGEXIT_SECURE_AVIC_UNREGISTER_GPA, 0);
> +       if (gpa && ret == ES_OK)
> +               *gpa = ghcb->save.rbx;
> +       __sev_put_ghcb(&state);
> +
> +       local_irq_restore(flags);
> +       return ret;
> +}