From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH] KVM: x86: use correct APIC ID on x2APIC transition Date: Tue, 26 May 2015 12:38:17 +0200 Message-ID: <55644D19.6050600@redhat.com> References: <1432313111-18829-1-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org Return-path: In-Reply-To: <1432313111-18829-1-git-send-email-rkrcmar@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On 22/05/2015 18:45, Radim Kr=C4=8Dm=C3=A1=C5=99 wrote: > SDM April 2015, 10.12.5 State Changes From xAPIC Mode to x2APIC Mode > =E2=80=A2 Any APIC ID value written to the memory-mapped local APIC I= D register > is not preserved. >=20 > Fix it by sourcing vcpu_id (=3D initial APIC ID) instead of memory-ma= pped > APIC ID. Proper use of apic functions would result in two calls to > recalculate_apic_map(), so this patch makes a new helper. >=20 > Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > --- > arch/x86/kvm/lapic.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) >=20 > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index dc5b57bb1f76..c2a7d8a7a414 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -240,6 +240,15 @@ static inline void kvm_apic_set_ldr(struct kvm_l= apic *apic, u32 id) > recalculate_apic_map(apic->vcpu->kvm); > } > =20 > +static inline void kvm_apic_set_x2apic_id(struct kvm_lapic *apic, u8= id) > +{ > + u32 ldr =3D ((id >> 4) << 16) | (1 << (id & 0xf)); > + > + apic_set_reg(apic, APIC_ID, id << 24); > + apic_set_reg(apic, APIC_LDR, ldr); > + recalculate_apic_map(apic->vcpu->kvm); > +} > + > static inline int apic_lvt_enabled(struct kvm_lapic *apic, int lvt_t= ype) > { > return !(kvm_apic_get_reg(apic, lvt_type) & APIC_LVT_MASKED); > @@ -1538,9 +1547,7 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, = u64 value) > =20 > if ((old_value ^ value) & X2APIC_ENABLE) { > if (value & X2APIC_ENABLE) { > - u32 id =3D kvm_apic_id(apic); > - u32 ldr =3D ((id >> 4) << 16) | (1 << (id & 0xf)); > - kvm_apic_set_ldr(apic, ldr); > + kvm_apic_set_x2apic_id(apic, vcpu->vcpu_id); > kvm_x86_ops->set_virtual_x2apic_mode(vcpu, true); > } else > kvm_x86_ops->set_virtual_x2apic_mode(vcpu, false); >=20 Applied, thanks. Paolo