mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-29 12:47:47 -04:00
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@intel.com> Cc: Yosry Ahmed <yosry@kernel.org> Signed-off-by: Sean Christopherson <seanjc@google.com> Acked-by: Naveen N Rao (AMD) <naveen@kernel.org> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Yosry Ahmed <yosry@kernel.org> Message-ID: <20260612185459.591892-1-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
43 lines
868 B
C
43 lines
868 B
C
/*
|
|
* Common functions shared between the various APIC flavours
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
*/
|
|
#include <linux/irq.h>
|
|
#include <linux/kvm_types.h>
|
|
#include <asm/apic.h>
|
|
|
|
#include "local.h"
|
|
|
|
u32 apic_default_calc_apicid(unsigned int cpu)
|
|
{
|
|
return per_cpu(x86_cpu_to_apicid, cpu);
|
|
}
|
|
|
|
u32 apic_flat_calc_apicid(unsigned int cpu)
|
|
{
|
|
return 1U << cpu;
|
|
}
|
|
|
|
u32 default_cpu_present_to_apicid(int mps_cpu)
|
|
{
|
|
if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
|
|
return (int)per_cpu(x86_cpu_to_apicid, mps_cpu);
|
|
else
|
|
return BAD_APICID;
|
|
}
|
|
|
|
/*
|
|
* Set up the logical destination ID when the APIC operates in logical
|
|
* destination mode.
|
|
*/
|
|
void default_init_apic_ldr(void)
|
|
{
|
|
unsigned long val;
|
|
|
|
apic_write(APIC_DFR, APIC_DFR_FLAT);
|
|
val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
|
|
val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
|
|
apic_write(APIC_LDR, val);
|
|
}
|