* 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, kvm, linux-kernel, Mingfangsen, pbonzini, rkrcmar,
sean.j.christopherson, wanpengli, jmattson, joro, tglx, mingo,
bp, hpa
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
* Re: [PATCH] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
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
0 siblings, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2019-10-17 9:48 UTC (permalink / raw)
To: linmiaohe
Cc: x86, kvm, linux-kernel, Mingfangsen, pbonzini, rkrcmar,
sean.j.christopherson, wanpengli, jmattson, joro, tglx, mingo,
bp, hpa
linmiaohe <linmiaohe@huawei.com> writes:
> 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 ?
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.
>
>>>
>>> @@ -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.
--
Vitaly
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [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, 0 replies; 4+ messages in thread
From: Vitaly Kuznetsov @ 2019-10-16 16:55 UTC (permalink / raw)
To: Miaohe Lin
Cc: x86, kvm, linux-kernel, linmiaohe, mingfangsen, pbonzini,
rkrcmar, sean.j.christopherson, wanpengli, jmattson, joro, tglx,
mingo, bp, hpa
Miaohe Lin <linmiaohe@huawei.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.
>
> 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 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)?
>
> 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;
--
Vitaly
^ 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;
as well as URLs for NNTP newsgroup(s).