From 3200924ed056efe58b3d1d12675c194bea98c0fc Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Sun, 9 Jan 2022 18:14:12 +0200 Subject: [PATCH 2/8] KVM: x86: AVIC: remove broken code that updated APIC ID Signed-off-by: Maxim Levitsky --- arch/x86/kvm/svm/avic.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/arch/x86/kvm/svm/avic.c b/arch/x86/kvm/svm/avic.c index f3ab00f407d5b..8655b35043134 100644 --- a/arch/x86/kvm/svm/avic.c +++ b/arch/x86/kvm/svm/avic.c @@ -480,35 +480,6 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) return ret; } -static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu) -{ - u64 *old, *new; - struct vcpu_svm *svm = to_svm(vcpu); - u32 id = kvm_xapic_id(vcpu->arch.apic); - - if (vcpu->vcpu_id == id) - return 0; - - old = avic_get_physical_id_entry(vcpu, vcpu->vcpu_id); - new = avic_get_physical_id_entry(vcpu, id); - if (!new || !old) - return 1; - - /* We need to move physical_id_entry to new offset */ - *new = *old; - *old = 0ULL; - to_svm(vcpu)->avic_physical_id_cache = new; - - /* - * Also update the guest physical APIC ID in the logical - * APIC ID table entry if already setup the LDR. - */ - if (svm->ldr_reg) - avic_handle_ldr_update(vcpu); - - return 0; -} - static void avic_handle_dfr_update(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); @@ -529,8 +500,10 @@ static int avic_unaccel_trap_write(struct vcpu_svm *svm) switch (offset) { case APIC_ID: - if (avic_handle_apic_id_update(&svm->vcpu)) - return 0; + /* restore the value that we had, we don't support APIC ID + * changes, but due to trap VM exit, the value was + * already written*/ + kvm_lapic_reg_write(apic, offset, svm->vcpu.vcpu_id << 24); break; case APIC_LDR: if (avic_handle_ldr_update(&svm->vcpu)) @@ -624,8 +597,6 @@ int avic_init_vcpu(struct vcpu_svm *svm) void avic_post_state_restore(struct kvm_vcpu *vcpu) { - if (avic_handle_apic_id_update(vcpu) != 0) - return; avic_handle_dfr_update(vcpu); avic_handle_ldr_update(vcpu); } -- 2.26.3