From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roman Kagan Subject: Re: [PATCH v6 4/7] KVM: x86: hyperv: keep track of mismatched VP indexes Date: Mon, 1 Oct 2018 15:54:26 +0000 Message-ID: <20181001155413.GA2314@rkaganb.sw.ru> References: <20180926170259.29796-1-vkuznets@redhat.com> <20180926170259.29796-5-vkuznets@redhat.com> <20180927075911.GB4186@rkaganb.sw.ru> <87sh1vfge0.fsf@vitty.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Cc: Vitaly Kuznetsov , "kvm@vger.kernel.org" , =?iso-8859-2?Q?Radim_Kr=E8m=E1=F8?= , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , Wanpeng Li , "linux-kernel@vger.kernel.org" To: Paolo Bonzini Return-path: In-Reply-To: Content-Language: en-US Content-ID: <66E7B0E8D764374C85FA9A4DDA2D9199@eurprd08.prod.outlook.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Mon, Oct 01, 2018 at 05:48:54PM +0200, Paolo Bonzini wrote: > On 27/09/2018 11:17, Vitaly Kuznetsov wrote: > > Roman Kagan writes: > >=20 > >> On Wed, Sep 26, 2018 at 07:02:56PM +0200, Vitaly Kuznetsov wrote: > >>> In most common cases VP index of a vcpu matches its vcpu index. Users= pace > >>> is, however, free to set any mapping it wishes and we need to account= for > >>> that when we need to find a vCPU with a particular VP index. To keep = search > >>> algorithms optimal in both cases introduce 'num_mismatched_vp_indexes= ' > >>> counter showing how many vCPUs with mismatching VP index we have. In = case > >>> the counter is zero we can assume vp_index =3D=3D vcpu_idx. > >>> > >>> Signed-off-by: Vitaly Kuznetsov > >>> --- > >>> arch/x86/include/asm/kvm_host.h | 3 +++ > >>> arch/x86/kvm/hyperv.c | 26 +++++++++++++++++++++++--- > >>> 2 files changed, 26 insertions(+), 3 deletions(-) > >>> > >>> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/k= vm_host.h > >>> index 09b2e3e2cf1b..711f79f1b5e6 100644 > >>> --- a/arch/x86/include/asm/kvm_host.h > >>> +++ b/arch/x86/include/asm/kvm_host.h > >>> @@ -781,6 +781,9 @@ struct kvm_hv { > >>> u64 hv_reenlightenment_control; > >>> u64 hv_tsc_emulation_control; > >>> u64 hv_tsc_emulation_status; > >>> + > >>> + /* How many vCPUs have VP index !=3D vCPU index */ > >>> + atomic_t num_mismatched_vp_indexes; > >>> }; > >>> =20 > >>> enum kvm_irqchip_mode { > >>> diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > >>> index c8764faf783b..6a19c8e3c432 100644 > >>> --- a/arch/x86/kvm/hyperv.c > >>> +++ b/arch/x86/kvm/hyperv.c > >>> @@ -1045,11 +1045,31 @@ static int kvm_hv_set_msr(struct kvm_vcpu *vc= pu, u32 msr, u64 data, bool host) > >>> struct kvm_vcpu_hv *hv_vcpu =3D &vcpu->arch.hyperv; > >>> =20 > >>> switch (msr) { > >>> - case HV_X64_MSR_VP_INDEX: > >>> - if (!host || (u32)data >=3D KVM_MAX_VCPUS) > >>> + case HV_X64_MSR_VP_INDEX: { > >>> + struct kvm_hv *hv =3D &vcpu->kvm->arch.hyperv; > >>> + int vcpu_idx =3D kvm_vcpu_get_idx(vcpu); > >>> + u32 new_vp_index =3D (u32)data; > >>> + > >>> + if (!host || new_vp_index >=3D KVM_MAX_VCPUS) > >>> return 1; > >>> - hv_vcpu->vp_index =3D (u32)data; > >>> + > >>> + if (new_vp_index =3D=3D hv_vcpu->vp_index) > >>> + return 0; > >>> + > >>> + /* > >>> + * VP index is changing, increment num_mismatched_vp_indexes in > >>> + * case it was equal to vcpu_idx before; on the other hand, if > >>> + * the new VP index matches vcpu_idx num_mismatched_vp_indexes > >>> + * needs to be decremented. > >> > >> It may be worth mentioning that the initial balance is provided by > >> kvm_hv_vcpu_postcreate setting vp_index =3D vcpu_idx. > >> > >=20 > > Of course, yes, will update the comment in case I'll be re-submitting. >=20 > /* > * VP index is initialized to hv_vcpu->vp_index by > * kvm_hv_vcpu_postcreate so they initially match. Now the > * VP index is changing, adjust num_mismatched_vp_indexes if > * it now matches or no longer matches vcpu_idx. > */ >=20 > ? To my taste - perfect :) Roman.