From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roman Kagan Subject: Re: [PATCH v3 3/5] KVM: x86: hyperv: use get_vcpu_by_vpidx() in kvm_hv_flush_tlb() Date: Fri, 29 Jun 2018 19:53:03 +0300 Message-ID: <20180629165303.GA16672@rkaganb.sw.ru> References: <20180629141455.19525-1-vkuznets@redhat.com> <20180629141455.19525-4-vkuznets@redhat.com> <20180629150104.GE15656@rkaganb.sw.ru> <87a7rdd3ec.fsf@vitty.brq.redhat.com> <20180629162636.GG15656@rkaganb.sw.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, x86@kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , "Michael Kelley (EOSG)" , Mohammed Gamal , Cathy Avery , Wanpeng Li , linux-kernel@vger.kernel.org To: Vitaly Kuznetsov Return-path: Content-Disposition: inline In-Reply-To: <20180629162636.GG15656@rkaganb.sw.ru> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Fri, Jun 29, 2018 at 07:26:36PM +0300, Roman Kagan wrote: > On Fri, Jun 29, 2018 at 05:21:47PM +0200, Vitaly Kuznetsov wrote: > > Roman Kagan writes: > > > > > On Fri, Jun 29, 2018 at 04:14:53PM +0200, Vitaly Kuznetsov wrote: > > >> VP_INDEX almost always matches VCPU id and get_vcpu_by_vpidx() is fast, > > >> use it instead of traversing full vCPU list every time. > > >> > > >> To support the change switch kvm_make_vcpus_request_mask() to checking > > >> vcpu_id instead of vcpu index, > > > > > > I'm afraid you can't do this: vcpu_id (== apic id) can be sparse, i.e. > > > it's not very well suited for bitmaps and can exceed the max number of > > > vcpus. > > > > True. The bitmap should be of KVM_MAX_VCPU_ID size, not > > KVM_MAX_VCPUS. > > > > Unfortunately there's no convenient way to get VCPU idx from VCPU > > id, kvm_vcpu_get_idx() just walks the whole list :-( I see two possible > > options: > > 1) Add vcpu_idx fields to struct kvm_vcpu > > 2) Keep the change expecting masks of KVM_MAX_VCPU_ID in > > kvm_make_vcpus_request_mask(). KVM_MAX_VCPU_ID is currently 1023 so our > > bitmaps will be 16 longs long. Not sure if it's too much. > > 3) rework get_vcpu_by_vpidx into get_vcpu_idx_by_vpidx followed by > get_cpu, and use the former for your purposes s/get_cpu/kvm_get_vcpu/ of course > 4) duplicate get_vcpu_by_vpidx logic in get_vcpu_idx_by_vpidx > > Roman. > > P.S. I'm starting to wonder how safe this get_vcpu_* thing is WRT vcpu > removal, but that's a different story anyway.