From 4a70416b98c4725dc28608152b66ec42a233b2e8 Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Sun, 9 Jan 2022 18:09:08 +0200 Subject: [PATCH 1/8] KVM: x86: lapic: don't allow to change APIC ID when apic acceleration is enabled No sane guest would change physical APIC IDs, and allowing this introduces bugs into APIC acceleration code. Signed-off-by: Maxim Levitsky --- arch/x86/kvm/lapic.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 6e1fbbf4c508b..56bc494cadd3e 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2007,10 +2007,16 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val) switch (reg) { case APIC_ID: /* Local APIC ID */ - if (!apic_x2apic_mode(apic)) - kvm_apic_set_xapic_id(apic, val >> 24); - else + if (!apic_x2apic_mode(apic) || + /* + * Don't allow setting APIC ID with any APIC acceleration + * enabled to avoid unexpected issues + */ + (enable_apicv && ((val >> 24) != apic->vcpu->vcpu_id))) { ret = 1; + break; + } + kvm_apic_set_xapic_id(apic, val >> 24); break; case APIC_TASKPRI: -- 2.26.3