Skip to content

Commit f2350b0

Browse files
committed
KVM: SVM: Update svm->ldr_reg cache even if LDR is "bad"
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-284.30.1.el9_2 commit-author Sean Christopherson <seanjc@google.com> commit 4f160b7 Update SVM's cache of the LDR even if the new value is "bad". Leaving stale information in the cache can result in KVM missing updates and/or invalidating the wrong entry, e.g. if avic_invalidate_logical_id_entry() is triggered after a different vCPU has "claimed" the old LDR. Fixes: 18f40c5 ("svm: Add VMEXIT handlers for AVIC") Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com> Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230106011306.85230-27-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit 4f160b7) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 850932b commit f2350b0

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,23 +539,21 @@ static u32 *avic_get_logical_id_entry(struct kvm_vcpu *vcpu, u32 ldr, bool flat)
539539
return &logical_apic_id_table[index];
540540
}
541541

542-
static int avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr)
542+
static void avic_ldr_write(struct kvm_vcpu *vcpu, u8 g_physical_id, u32 ldr)
543543
{
544544
bool flat;
545545
u32 *entry, new_entry;
546546

547547
flat = kvm_lapic_get_reg(vcpu->arch.apic, APIC_DFR) == APIC_DFR_FLAT;
548548
entry = avic_get_logical_id_entry(vcpu, ldr, flat);
549549
if (!entry)
550-
return -EINVAL;
550+
return;
551551

552552
new_entry = READ_ONCE(*entry);
553553
new_entry &= ~AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK;
554554
new_entry |= (g_physical_id & AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK);
555555
new_entry |= AVIC_LOGICAL_ID_ENTRY_VALID_MASK;
556556
WRITE_ONCE(*entry, new_entry);
557-
558-
return 0;
559557
}
560558

561559
static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
@@ -575,7 +573,6 @@ static void avic_invalidate_logical_id_entry(struct kvm_vcpu *vcpu)
575573

576574
static void avic_handle_ldr_update(struct kvm_vcpu *vcpu)
577575
{
578-
int ret = 0;
579576
struct vcpu_svm *svm = to_svm(vcpu);
580577
u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR);
581578
u32 id = kvm_xapic_id(vcpu->arch.apic);
@@ -589,11 +586,8 @@ static void avic_handle_ldr_update(struct kvm_vcpu *vcpu)
589586

590587
avic_invalidate_logical_id_entry(vcpu);
591588

592-
if (ldr)
593-
ret = avic_ldr_write(vcpu, id, ldr);
594-
595-
if (!ret)
596-
svm->ldr_reg = ldr;
589+
svm->ldr_reg = ldr;
590+
avic_ldr_write(vcpu, id, ldr);
597591
}
598592

599593
static void avic_handle_dfr_update(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)