From: "Jan Beulich" Subject: Re: [PATCH v4 2/4] x86/HVM: fix ID handling of x2APIC emulation Date: Fri, 19 Sep 2014 07:09:27 +0100 Message-ID: <541BE4B7020000780003667D@mail.emea.novell.com> References: <541B09B402000078000363B4@mail.emea.novell.com> <541B0BEB02000078000363C3@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XUrNo-0005KT-Ub for xen-devel@lists.xenproject.org; Fri, 19 Sep 2014 06:09:29 +0000 In-Reply-To: <541B0BEB02000078000363C3@mail.emea.novell.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Tim Deegan , Keir Fraser List-Id: xen-devel@lists.xenproject.org >>> On 18.09.14 at 16:44, wrote: > @@ -1227,6 +1229,22 @@ static int lapic_save_regs(struct domain > return rc; > } > > +/* > + * Following lapic_load_hidden()/lapic_load_regs() we may need to > + * correct ID and LDR when they come from an old, broken hypervisor. > + */ > +static void lapic_load_fixup(struct vlapic *vlapic) > +{ > + uint32_t id = vlapic->loaded.id; > + > + if ( vlapic_x2apic_mode(vlapic) && > + id && vlapic->loaded.ldr == 1 && > + /* Further checks are optional: ID != 0 contradicts LDR == 1. */ > + GET_xAPIC_ID(id) == vlapic_vcpu(vlapic)->vcpu_id * 2 && > + id == SET_xAPIC_ID(GET_xAPIC_ID(id)) ) > + set_x2apic_id(vlapic); + else /* Undo an eventual earlier fixup. */ + { + vlapic_set_reg(vlapic, APIC_ID, id); + vlapic_set_reg(vlapic, APIC_LDR, vlapic->loaded.ldr); + } > +} Jan