KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
Quoted 3 lines · Vitaly Kuznetsov
Quoted 3 lines
Guest physical APIC ID may not equal to
vcpu->vcpu_idin some case. We may set the wrong physical id inavic_handle_ldr_updateas we always usevcpu->vcpu_id.
Hi, Vitaly, thanks for your reply.
Do you think there may be a wrong physical id in avic_handle_ldr_update too ?
Quoted 11 lines
Review static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) · line 4595
Quoted 7 lines
(quoted diff) +2
-0@@ -4591,6 +4591,8 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) int ret = 0; struct vcpu_svm *svm = to_svm(vcpu); u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR); + u32 apic_id_reg = kvm_lapic_get_reg(vcpu->arch.apic, APIC_ID); + u32 id = (apic_id_reg >> 24) & 0xff;If we reach here than we're guaranteed to be in xAPIC mode, right? Could you maybe export and use
kvm_xapic_id()here then (and inavic_handle_apic_id_update()too)?
I think we're guaranteed to be in xAPIC mode when we reach here. I would have a try to export and use use kvm_xapic_id here and in avic_handle_apic_id_update too.
Thanks for your suggestion.
Have a nice day.
Best wishes.
Quoted 9 lines · linmiaohe
Quoted 3 lines · Vitaly Kuznetsov
Quoted 3 lines
Guest physical APIC ID may not equal to
vcpu->vcpu_idin some case. We may set the wrong physical id inavic_handle_ldr_updateas we always usevcpu->vcpu_id.Hi, Vitaly, thanks for your reply.
Do you think there may be a wrong physical id inavic_handle_ldr_updatetoo ?
Honestly I'm not sure, however, as we need to put physical id to LDR we'd rather get it from LAPIC then assume that it's == vcpu_id so I think your patch makes sense even if it fixes a theoretical issue.
But I may be missing something important about AVIC.
Quoted 19 lines
Quoted 12 lines
Review static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) · line 4595
Quoted 8 lines
(quoted diff) +2
-0@@ -4591,6 +4591,8 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) int ret = 0; struct vcpu_svm *svm = to_svm(vcpu); u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR); + u32 apic_id_reg = kvm_lapic_get_reg(vcpu->arch.apic, APIC_ID); + u32 id = (apic_id_reg >> 24) & 0xff;If we reach here than we're guaranteed to be in xAPIC mode, right? Could you maybe export and use
kvm_xapic_id()here then (and inavic_handle_apic_id_update()too)?I think we're guaranteed to be in xAPIC mode when we reach here. I would have a try to export and use use
kvm_xapic_idhere and inavic_handle_apic_id_updatetoo.
Thanks for your suggestion.Have a nice day.
Best wishes.
Signature · 1 line
Vitaly