OSDN Git Service

KVM: SVM: Do not support updating APIC ID when in x2APIC mode
authorSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Thu, 19 May 2022 10:26:58 +0000 (05:26 -0500)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 Jun 2022 16:45:29 +0000 (12:45 -0400)
In X2APIC mode, the Logical Destination Register is read-only,
which provides a fixed mapping between the logical and physical
APIC IDs. Therefore, there is no Logical APIC ID table in X2AVIC
and the processor uses the X2APIC ID in the backing page to create
a vCPU’s logical ID.

In addition, KVM does not support updating APIC ID in x2APIC mode,
which means AVIC does not need to handle this case.

Therefore, check x2APIC mode when handling physical and logical
APIC ID update, and when invalidating logical APIC ID table.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Suggested-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Message-Id: <20220519102709.24125-7-suravee.suthikulpanit@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/avic.c

index 8b8a221..cc4da23 100644 (file)
@@ -526,8 +526,13 @@ static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
 {
        struct vcpu_svm *svm = to_svm(vcpu);
        bool flat = svm->dfr_reg == APIC_DFR_FLAT;
-       u32 *entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
+       u32 *entry;
 
+       /* Note: x2AVIC does not use logical APIC ID table */
+       if (apic_x2apic_mode(vcpu->arch.apic))
+               return;
+
+       entry = avic_get_logical_id_entry(vcpu, svm->ldr_reg, flat);
        if (entry)
                clear_bit(AVIC_LOGICAL_ID_ENTRY_VALID_BIT, (unsigned long *)entry);
 }
@@ -539,6 +544,10 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
        u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR);
        u32 id = kvm_xapic_id(vcpu->arch.apic);
 
+       /* AVIC does not support LDR update for x2APIC */
+       if (apic_x2apic_mode(vcpu->arch.apic))
+               return 0;
+
        if (ldr == svm->ldr_reg)
                return 0;