From mboxrd@z Thu Jan 1 00:00:00 1970 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH v1 06/11] KVM: x86: use hardware-compatible format for APIC ID register Date: Fri, 1 Jul 2016 15:11:20 +0200 Message-ID: <20160701131119.GC27840@potion> References: <20160630205429.16480-1-rkrcmar@redhat.com> <20160630205429.16480-7-rkrcmar@redhat.com> <733b706a-f30f-3854-5fc7-402d6b5fd79a@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, "Lan, Tianyu" , Igor Mammedov , Jan Kiszka , Peter Xu To: Paolo Bonzini Return-path: Content-Disposition: inline In-Reply-To: <733b706a-f30f-3854-5fc7-402d6b5fd79a@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org 2016-07-01 10:33+0200, Paolo Bonzini: > On 30/06/2016 22:54, Radim Kr=C4=8Dm=C3=A1=C5=99 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 =3D (u32 *)(s->regs + APIC_ID); >> + if (set) >> + *id >>=3D 24; >> + else >> + *id <<=3D 24; >> + } >=20 > When setting, this should read from the apic_base being set. So I th= ink > 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. > With this change, you don't need the struct kvm_vcpu argument now; ad= d a > struct kvm argument instead in patch 10. I don't think we can use hardware-compatible format in API without knowing the x2apic mode through vcpu. (The big endian format could do without knowing apic mode.) >> @@ -2780,6 +2780,7 @@ static int kvm_vcpu_ioctl_get_lapic(struct kvm= _vcpu *vcpu, >> kvm_x86_ops->sync_pir_to_irr(vcpu); >> =20 >> memcpy(s->regs, vcpu->arch.apic->regs, sizeof *s); >> + kvm_apic_state_get_fixup(vcpu, s); >=20 > Instead of kvm_apic_state_get/set_fixup, group the memcpy and > __kvm_apic_state_fixup in a new function kvm_apic_get_state(struct > kvm_lapic *apic, char *regs). Ok. >> return 0; >> } >> @@ -2787,6 +2788,7 @@ static int kvm_vcpu_ioctl_get_lapic(struct kvm= _vcpu *vcpu, >> static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, >> struct kvm_lapic_state *s) >> { >> + kvm_apic_state_set_fixup(vcpu, s); >> kvm_apic_post_state_restore(vcpu, s); >=20 > ... and likewise merge these two in a refactored > kvm_apic_post_state_restore called kvm_apic_set_state(struct kvm_lapi= c > *apic, char *regs), by calling __kvm_apic_state_fixup before > kvm_apic_post_state_restore's memcpy. >=20 > With these changes I guess there's no need for the underscores in > __kvm_apic_state_fixup. Yes, good idea. > And you can also change the struct > kvm_lapic_state pointer in the function to a char *. Ok, I'll pass just s->regs. Thanks.