From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bwXEF-0000j3-6R for qemu-devel@nongnu.org; Tue, 18 Oct 2016 12:27:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bwXEB-0001Ne-V7 for qemu-devel@nongnu.org; Tue, 18 Oct 2016 12:27:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50840) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1bwXEB-0001NO-QF for qemu-devel@nongnu.org; Tue, 18 Oct 2016 12:26:59 -0400 Date: Tue, 18 Oct 2016 18:26:54 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20161018162654.GA20846@potion> References: <20161013140844.GC15008@potion> <1476444115-205593-1-git-send-email-imammedo@redhat.com> <20161018145623.GX3275@thinpad.lan.raisama.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20161018145623.GX3275@thinpad.lan.raisama.net> Subject: Re: [Qemu-devel] [PATCH v4 09/13] pc: kvm_apic: pass APIC ID depending on xAPIC/x2APIC mode List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: Igor Mammedov , qemu-devel@nongnu.org, liuxiaojian6@huawei.com, mst@redhat.com, peterx@redhat.com, kevin@koconnor.net, kraxel@redhat.com, pbonzini@redhat.com, lersek@redhat.com, chao.gao@intel.com 2016-10-18 12:56-0200, Eduardo Habkost: > On Fri, Oct 14, 2016 at 01:21:55PM +0200, Igor Mammedov wrote: >> Signed-off-by: Igor Mammedov >> --- >> v4: >> - restore kvm_has_x2apic_api() and use it to avoid side-effects >> of kvm_enable_x2apic(). x2APIC API will be enabled by iommu >> if it's present or not enabled at all. >> v3: >> - drop kvm_has_x2apic_api() and reuse kvm_enable_x2apic() instead >> --- >> diff --git a/hw/i386/kvm/apic.c b/hw/i386/kvm/apic.c >> @@ -34,7 +34,11 @@ static void kvm_put_apic_state(APICCommonState *s, struct kvm_lapic_state *kapic >> int i; >> >> memset(kapic, 0, sizeof(*kapic)); >> - kvm_apic_set_reg(kapic, 0x2, s->id << 24); >> + if (kvm_has_x2apic_api() && s->apicbase & MSR_IA32_APICBASE_EXTD) { >> + kvm_apic_set_reg(kapic, 0x2, s->initial_apic_id); > > What happens if: > > * x2apic is enabled on CPUID; > * guest sets MSR_IA32_APICBASE_EXTD; an > * the x2apic API is not enabled? KVM expects APIC ID to be in upper 8 bits of the register then. Guest APIC mode does not come into play if the x2APIC API is not enabled. This is to keep compatibility with old KVMs that used xAPIC format regardless of APIC mode. > Does that mean kvm_{put,get}_apic_state() was already broken, or > is the x2apic ID translated to the old format by the kernel when > the x2apic API is disabled? The latter. KVM stores the 8 bits in an appropriate format, but it doesn't really matter to QEMU: the exchange format without enabled x2APIC API is defined to be the xAPIC one. (KVM used to keep always keep ID in xAPIC format and trapped x2APIC ID reads to shift the value.)