Re: [PATCH] x86/apic: KVM: Use cpu_physical_id() to get APIC ID of running vCPU for AVIC
From: Naveen N Rao
Date: Tue Jun 16 2026 - 04:00:00 EST
On Fri, Jun 12, 2026 at 11:54:59AM -0700, Sean Christopherson wrote:
> Use cpu_physical_id() instead of default_cpu_present_to_apicid() when
> getting the APIC ID of the pCPU on which a vCPU is running/loaded, as the
> kernel has gone way off the rails if a vCPU is loaded on a pCPU that has
> been physically removed from the system.
Or, has been unloaded from a pCPU that is then soft-offlined and
physically hot unplugged before that vCPU ever got a chance to run
again!
> Even if the impossible were to
> happen, the absolutely worst case scenario is that hardware will ring the
> AIVC doorbell on the wrong pCPU, i.e. a severely broken system will
> experience mild performance issues.
Indeed, sending a doorbell to BAD_APICID doesn't seem to do anything
bad, so I think we are ok with this.
>
> Kill off KVM's superfluous kvm_cpu_get_apicid() wrapper along with the
> for-KVM export of default_cpu_present_to_apicid(), as they existed purely
> for the wonky AVIC usage.
>
> Cc: Kai Huang <kai.huang@xxxxxxxxx>
> Cc: Yosry Ahmed <yosry@xxxxxxxxxx>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Acked-by: Naveen N Rao (AMD) <naveen@xxxxxxxxxx>
- Naveen