From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586AbcGAOMQ (ORCPT ); Fri, 1 Jul 2016 10:12:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50088 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752028AbcGAOMO (ORCPT ); Fri, 1 Jul 2016 10:12:14 -0400 Subject: Re: [PATCH v1 06/11] KVM: x86: use hardware-compatible format for APIC ID register To: =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <20160630205429.16480-1-rkrcmar@redhat.com> <20160630205429.16480-7-rkrcmar@redhat.com> <733b706a-f30f-3854-5fc7-402d6b5fd79a@redhat.com> <20160701131119.GC27840@potion> Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "Lan, Tianyu" , Igor Mammedov , Jan Kiszka , Peter Xu From: Paolo Bonzini Message-ID: <217814b5-d637-07f8-48cd-777ad498c54f@redhat.com> Date: Fri, 1 Jul 2016 16:12:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: <20160701131119.GC27840@potion> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 01 Jul 2016 14:12:14 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/07/2016 15:11, Radim Krčmář wrote: >>> >> +static void __kvm_apic_state_fixup(struct kvm_vcpu *vcpu, >>> >> + struct kvm_lapic_state *s, bool set) >>> >> +{ >>> >> + if (apic_x2apic_mode(vcpu->arch.apic)) { >>> >> + u32 *id = (u32 *)(s->regs + APIC_ID); >>> >> + if (set) >>> >> + *id >>= 24; >>> >> + else >>> >> + *id <<= 24; >>> >> + } >> > >> > When setting, this should read from the apic_base being set. So I think >> > you cannot use apic_x2apic_mode. > > apic_x2apic_mode uses apic_base MSR, so its value does not depend on > LAPIC_SET/GET. I don't like the dependency much, but all combinations > of values/orders should work well. You're right of course. However it should be documented in the KVM_GET_LAPIC/KVM_SET_LAPIC ioctl docs that KVM_SET_MSR for apic_base should be performed first. Should kvm_lapic_set_base change the value of the ID register when x2apic mode is left just like we do for entering x2apic mode? (Hint: we want kvm-unit-tests for this). Paolo