Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932618AbbEZOPk (ORCPT ); Tue, 26 May 2015 10:15:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39461 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932594AbbEZOPf (ORCPT ); Tue, 26 May 2015 10:15:35 -0400 Message-ID: <55644D19.6050600@redhat.com> Date: Tue, 26 May 2015 12:38:17 +0200 From: Paolo Bonzini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , linux-kernel@vger.kernel.org CC: kvm@vger.kernel.org Subject: Re: [PATCH] KVM: x86: use correct APIC ID on x2APIC transition References: <1432313111-18829-1-git-send-email-rkrcmar@redhat.com> In-Reply-To: <1432313111-18829-1-git-send-email-rkrcmar@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2044 Lines: 57 On 22/05/2015 18:45, Radim Krčmář wrote: > SDM April 2015, 10.12.5 State Changes From xAPIC Mode to x2APIC Mode > • Any APIC ID value written to the memory-mapped local APIC ID register > is not preserved. > > Fix it by sourcing vcpu_id (= initial APIC ID) instead of memory-mapped > APIC ID. Proper use of apic functions would result in two calls to > recalculate_apic_map(), so this patch makes a new helper. > > Signed-off-by: Radim Krčmář > --- > arch/x86/kvm/lapic.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > 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_lapic *apic, u32 id) > recalculate_apic_map(apic->vcpu->kvm); > } > > +static inline void kvm_apic_set_x2apic_id(struct kvm_lapic *apic, u8 id) > +{ > + u32 ldr = ((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_type) > { > 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) > > if ((old_value ^ value) & X2APIC_ENABLE) { > if (value & X2APIC_ENABLE) { > - u32 id = kvm_apic_id(apic); > - u32 ldr = ((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); > Applied, thanks. Paolo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/