diff options
author | Miaohe Lin <linmiaohe@huawei.com> | 2019-10-17 22:50:31 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2019-10-22 12:47:50 -0400 |
commit | 5c94ac5d0f9e3c8791d1686e0bf22a2a341d1597 (patch) | |
tree | 293779223b4f869c256b8548a7ea3cc9e1b18348 /arch/x86/kvm | |
parent | 20baa8e515a55dc7467d9584cc458b5700c0a3aa (diff) |
KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
Guest physical APIC ID may not equal to vcpu->vcpu_id in some case.
We may set the wrong physical id in avic_handle_ldr_update as we
always use vcpu->vcpu_id. Get physical APIC ID from vAPIC page
instead.
Export and use kvm_xapic_id here and in avic_handle_apic_id_update
as suggested by Vitaly.
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r-- | arch/x86/kvm/lapic.c | 5 | ||||
-rw-r--r-- | arch/x86/kvm/lapic.h | 5 | ||||
-rw-r--r-- | arch/x86/kvm/svm.c | 6 |
3 files changed, 8 insertions, 8 deletions
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 87b0fcc23ef8..b29d00b661ff 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c | |||
@@ -111,11 +111,6 @@ static inline int apic_enabled(struct kvm_lapic *apic) | |||
111 | (LVT_MASK | APIC_MODE_MASK | APIC_INPUT_POLARITY | \ | 111 | (LVT_MASK | APIC_MODE_MASK | APIC_INPUT_POLARITY | \ |
112 | APIC_LVT_REMOTE_IRR | APIC_LVT_LEVEL_TRIGGER) | 112 | APIC_LVT_REMOTE_IRR | APIC_LVT_LEVEL_TRIGGER) |
113 | 113 | ||
114 | static inline u8 kvm_xapic_id(struct kvm_lapic *apic) | ||
115 | { | ||
116 | return kvm_lapic_get_reg(apic, APIC_ID) >> 24; | ||
117 | } | ||
118 | |||
119 | static inline u32 kvm_x2apic_id(struct kvm_lapic *apic) | 114 | static inline u32 kvm_x2apic_id(struct kvm_lapic *apic) |
120 | { | 115 | { |
121 | return apic->vcpu->vcpu_id; | 116 | return apic->vcpu->vcpu_id; |
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 2aad7e226fc0..1f5014852e20 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h | |||
@@ -242,4 +242,9 @@ static inline enum lapic_mode kvm_apic_mode(u64 apic_base) | |||
242 | return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE); | 242 | return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE); |
243 | } | 243 | } |
244 | 244 | ||
245 | static inline u8 kvm_xapic_id(struct kvm_lapic *apic) | ||
246 | { | ||
247 | return kvm_lapic_get_reg(apic, APIC_ID) >> 24; | ||
248 | } | ||
249 | |||
245 | #endif | 250 | #endif |
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index f8ecb6df5106..ca200b50cde4 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -4591,6 +4591,7 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) | |||
4591 | int ret = 0; | 4591 | int ret = 0; |
4592 | struct vcpu_svm *svm = to_svm(vcpu); | 4592 | struct vcpu_svm *svm = to_svm(vcpu); |
4593 | u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR); | 4593 | u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR); |
4594 | u32 id = kvm_xapic_id(vcpu->arch.apic); | ||
4594 | 4595 | ||
4595 | if (ldr == svm->ldr_reg) | 4596 | if (ldr == svm->ldr_reg) |
4596 | return 0; | 4597 | return 0; |
@@ -4598,7 +4599,7 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu) | |||
4598 | avic_invalidate_logical_id_entry(vcpu); | 4599 | avic_invalidate_logical_id_entry(vcpu); |
4599 | 4600 | ||
4600 | if (ldr) | 4601 | if (ldr) |
4601 | ret = avic_ldr_write(vcpu, vcpu->vcpu_id, ldr); | 4602 | ret = avic_ldr_write(vcpu, id, ldr); |
4602 | 4603 | ||
4603 | if (!ret) | 4604 | if (!ret) |
4604 | svm->ldr_reg = ldr; | 4605 | svm->ldr_reg = ldr; |
@@ -4610,8 +4611,7 @@ static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu) | |||
4610 | { | 4611 | { |
4611 | u64 *old, *new; | 4612 | u64 *old, *new; |
4612 | struct vcpu_svm *svm = to_svm(vcpu); | 4613 | struct vcpu_svm *svm = to_svm(vcpu); |
4613 | u32 apic_id_reg = kvm_lapic_get_reg(vcpu->arch.apic, APIC_ID); | 4614 | u32 id = kvm_xapic_id(vcpu->arch.apic); |
4614 | u32 id = (apic_id_reg >> 24) & 0xff; | ||
4615 | 4615 | ||
4616 | if (vcpu->vcpu_id == id) | 4616 | if (vcpu->vcpu_id == id) |
4617 | return 0; | 4617 | return 0; |