public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
@ 2019-10-17  2:12 linmiaohe
  2019-10-17  9:48 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 4+ messages in thread
From: linmiaohe @ 2019-10-17  2:12 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mingfangsen, pbonzini@redhat.com, rkrcmar@redhat.com,
	sean.j.christopherson@intel.com, wanpengli@tencent.com,
	jmattson@google.com, joro@8bytes.org, tglx@linutronix.de,
	mingo@redhat.com, bp@alien8.de, hpa@zytor.com


Vitaly Kuznetsov <vkuznets@redhat.com> writes:

>> 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.

Hi, Vitaly, thanks for your reply.
Do you think there may be a wrong physical id in avic_handle_ldr_update too ?

>>
>> @@ -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 in
>avic_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.

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
@ 2019-10-16  9:25 Miaohe Lin
  2019-10-16 16:55 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 4+ messages in thread
From: Miaohe Lin @ 2019-10-16  9:25 UTC (permalink / raw)
  To: pbonzini, rkrcmar, sean.j.christopherson, vkuznets, wanpengli,
	jmattson, joro, tglx, mingo, bp, hpa
  Cc: x86, kvm, linux-kernel, linmiaohe, mingfangsen

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.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 arch/x86/kvm/svm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f8ecb6d..67cb5ba 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -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 (ldr == svm->ldr_reg)
 		return 0;
@@ -4598,7 +4600,7 @@ static int avic_handle_ldr_update(struct kvm_vcpu *vcpu)
 	avic_invalidate_logical_id_entry(vcpu);
 
 	if (ldr)
-		ret = avic_ldr_write(vcpu, vcpu->vcpu_id, ldr);
+		ret = avic_ldr_write(vcpu, id, ldr);
 
 	if (!ret)
 		svm->ldr_reg = ldr;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-10-17  9:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-17  2:12 [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update linmiaohe
2019-10-17  9:48 ` Vitaly Kuznetsov
  -- strict thread matches above, loose matches on Subject: below --
2019-10-16  9:25 Miaohe Lin
2019-10-16 16:55 ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox