From: Paolo Bonzini <pbonzini@redhat.com>
To: Miaohe Lin <linmiaohe@huawei.com>,
rkrcmar@redhat.com, sean.j.christopherson@intel.com,
vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com,
joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com,
bp@alien8.de, hpa@zytor.com
Cc: x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, mingfangsen@huawei.com
Subject: Re: [PATCH v2] KVM: SVM: Fix potential wrong physical id in avic_handle_ldr_update
Date: Tue, 22 Oct 2019 18:47:58 +0200 [thread overview]
Message-ID: <696ae8db-fe41-4710-483c-0f30a06bdd32@redhat.com> (raw)
In-Reply-To: <1571367031-6844-1-git-send-email-linmiaohe@huawei.com>
On 18/10/19 04:50, Miaohe Lin wrote:
> 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>
> ---
> arch/x86/kvm/lapic.c | 5 -----
> arch/x86/kvm/lapic.h | 5 +++++
> 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)
> (LVT_MASK | APIC_MODE_MASK | APIC_INPUT_POLARITY | \
> APIC_LVT_REMOTE_IRR | APIC_LVT_LEVEL_TRIGGER)
>
> -static inline u8 kvm_xapic_id(struct kvm_lapic *apic)
> -{
> - return kvm_lapic_get_reg(apic, APIC_ID) >> 24;
> -}
> -
> static inline u32 kvm_x2apic_id(struct kvm_lapic *apic)
> {
> 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)
> return apic_base & (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE);
> }
>
> +static inline u8 kvm_xapic_id(struct kvm_lapic *apic)
> +{
> + return kvm_lapic_get_reg(apic, APIC_ID) >> 24;
> +}
> +
> #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)
> int ret = 0;
> struct vcpu_svm *svm = to_svm(vcpu);
> u32 ldr = kvm_lapic_get_reg(vcpu->arch.apic, APIC_LDR);
> + u32 id = kvm_xapic_id(vcpu->arch.apic);
>
> if (ldr == svm->ldr_reg)
> return 0;
> @@ -4598,7 +4599,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;
> @@ -4610,8 +4611,7 @@ static int avic_handle_apic_id_update(struct kvm_vcpu *vcpu)
> {
> u64 *old, *new;
> struct vcpu_svm *svm = to_svm(vcpu);
> - u32 apic_id_reg = kvm_lapic_get_reg(vcpu->arch.apic, APIC_ID);
> - u32 id = (apic_id_reg >> 24) & 0xff;
> + u32 id = kvm_xapic_id(vcpu->arch.apic);
>
> if (vcpu->vcpu_id == id)
> return 0;
>
Queued, thanks.
Paolo
prev parent reply other threads:[~2019-10-22 16:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-18 2:50 Miaohe Lin
2019-10-22 16:47 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=696ae8db-fe41-4710-483c-0f30a06bdd32@redhat.com \
--to=pbonzini@redhat.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingfangsen@huawei.com \
--cc=mingo@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®