Re: [PATCH] x86/apic: KVM: Use cpu_physical_id() to get APIC ID of running vCPU for AVIC
From: Yosry Ahmed
Date: Fri Jun 12 2026 - 17:27:56 EST
On Fri, Jun 12, 2026 at 11:55 AM Sean Christopherson <seanjc@xxxxxxxxxx> 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. 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.
>
> 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>
Took me a bit to realize cpu_physical_id() is the APIC ID, but yeah
this looks to be equivalent as long as the CPU is present, which as
you described should be true as long as we didn't screw up.
cpu_physical_id() seems to also be used by VMX anyway.
Reviewed-by: Yosry Ahmed <yosry@xxxxxxxxxx>