x86/apic/savic: Forward APIC_SPIV writes to the hypervisor
Subsystems (3)
PATCH 1/1 x86/apic/savic: Forward APIC_SPIV writes to the hypervisor
From: Shruti <[email protected]>
For Secure AVIC (SAVIC) guests, the hypervisor (KVM) emulates the LAPIC timer and LVT registers, while the guest's APIC backing page is kept in encrypted guest-private memory that the hypervisor cannot read.
Currently, savic_write() updates APIC_SPIV (Spurious Interrupt Vector Register) only in the guest's private APIC backing page without notifying the hypervisor. Because the hypervisor never sees the guest set the APIC Software Enable bit (APIC_SPIV_APIC_ENABLED) in APIC_SPIV, it continues to treat the vCPU's Local APIC as software-disabled.
When the hypervisor sees a vCPU's APIC as software-disabled, it forcibly masks all LVT writes (including APIC_LVTT for the local timer) and drops timer and fixed interrupts for that vCPU. On SMP guests, where secondary CPUs (APs) start with their emulated APIC reset to software-disabled, this prevents APs from receiving local timer interrupts and leaves them hung in idle (HLT) during boot.
Forward APIC_SPIV writes to the hypervisor via savic_ghcb_msr_write() in addition to updating the guest's APIC backing page so the hypervisor's APIC state stays in sync with the guest.
--- arch/x86/kernel/apic/x2apic_savic.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/apic/x2apic_savic.c +4 -1
@@ -214,7 +214,6 @@ static void savic_write(u32 reg, u32 data)break ;case APIC_TASKPRI :case APIC_EOI : -case APIC_SPIV :case SAVIC_NMI_REQ :case APIC_ESR :case APIC_ECTRL :
@@ -223,6 +222,10 @@ static void savic_write(u32 reg, u32 data) case APIC_EILVTn(0) ... APIC_EILVTn(3):apic_set_reg (ap, reg, data);break ; +case APIC_SPIV : +savic_ghcb_msr_write (reg, data); +apic_set_reg (ap, reg, data); +break ;case APIC_ICR :savic_icr_write (data,0 );break ;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] x86/apic: lost interrupts due to incorrect APIC_SPIV update order --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] x86/apic: lost interrupts due to incorrect APIC_SPIV update order --
commit 26f070fb302ca5a93ef870d540aaf2cf4fb25a54
Author: Shruti <[email protected]>
x86/apic/savic: Forward APIC_SPIV writes to the hypervisor
This commit updates savic_write() to forward APIC_SPIV writes to the hypervisor so that the emulated APIC state stays in sync with the guest's local backing page.
Quoted 3 lines
arch/x86/kernel/apic/x2apic_savic.c +0
-0
[ ... ]
arch/x86/kernel/apic/x2apic_savic.c static void savic_write(u32 reg, u32 data) · line 227
Quoted 7 lines
arch/x86/kernel/apic/x2apic_savic.c +3
-0@@ -223,6 +222,10 @@ static void savic_write(u32 reg, u32 data) case APIC_EILVTn(0) ... APIC_EILVTn(3):apic_set_reg (ap, reg, data);break ; +case APIC_SPIV : +savic_ghcb_msr_write (reg, data); +apic_set_reg (ap, reg, data);
[Severity: High]
Does this specific ordering cause a regression where interrupts could be dropped?
When a vCPU writes to APIC_SPIV to enable the APIC, savic_ghcb_msr_write() notifies the hypervisor. The hypervisor then marks the emulated APIC as software-enabled and may immediately inject a pending interrupt before resuming the guest.
When the guest resumes, the hardware AVIC evaluates the injected interrupt against the local APIC backing page. Because apic_set_reg() has not yet executed, the local backing page still reflects a software-disabled APIC, causing the hardware AVIC to drop the interrupt.
Would reversing the order of these two calls ensure the local backing page is ready before the hypervisor is notified?
Quoted 4 lines
arch/x86/kernel/apic/x2apic_savic.c +1
-0+break ;case APIC_ICR :savic_icr_write (data,0 );break ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Borislav Petkov
maintainer+ some more AMD people and drop stable@
Quoted 1 line · On Tue, Sep 29, 2026 at 05:52:55AM +0000, [email protected] wrote:
From: Shruti <[email protected]>
You should use your legal name when you sign off on patches.
Leaving in the rest for the newly CCed.
Quoted 54 lines
For Secure AVIC (SAVIC) guests, the hypervisor (KVM) emulates the LAPIC timer and LVT registers, while the guest's APIC backing page is kept in encrypted guest-private memory that the hypervisor cannot read.
Currently,
savic_write()updatesAPIC_SPIV(Spurious Interrupt Vector Register) only in the guest's private APIC backing page without notifying the hypervisor. Because the hypervisor never sees the guest set the APIC Software Enable bit (APIC_SPIV_APIC_ENABLED) inAPIC_SPIV, it continues to treat the vCPU's Local APIC as software-disabled.When the hypervisor sees a vCPU's APIC as software-disabled, it forcibly masks all LVT writes (including
APIC_LVTTfor the local timer) and drops timer and fixed interrupts for that vCPU. On SMP guests, where secondary CPUs (APs) start with their emulated APIC reset to software-disabled, this prevents APs from receiving local timer interrupts and leaves them hung in idle (HLT) during boot.Forward
APIC_SPIVwrites to the hypervisor viasavic_ghcb_msr_write()in addition to updating the guest's APIC backing page so the hypervisor's APIC state stays in sync with the guest.Fixes c822f58a4fab ("x86/apic: Populate .read()/.write() callbacks of Secure AVIC driver")Signed-off-by Shruti <[email protected]>--- arch/x86/kernel/apic/x2apic_savic.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/x86/kernel/apic/x2apic_savic.c +4
-1@@ -214,7 +214,6 @@ static void savic_write(u32 reg, u32 data)break ;case APIC_TASKPRI :case APIC_EOI : -case APIC_SPIV :case SAVIC_NMI_REQ :case APIC_ESR :case APIC_ECTRL :@@ -223,6 +222,10 @@ static void savic_write(u32 reg, u32 data) case APIC_EILVTn(0) ... APIC_EILVTn(3):apic_set_reg (ap, reg, data);break ; +case APIC_SPIV : +savic_ghcb_msr_write (reg, data); +apic_set_reg (ap, reg, data); +break ;case APIC_ICR :savic_icr_write (data,0 );break ;Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette