From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Huth Subject: Re: [PATCH] KVM: PPC: Book3S HV: Replace kvmppc_find_vcpu() with kvm_get_vcpu() Date: Fri, 8 May 2015 10:19:04 +0200 Message-ID: <20150508101904.509c629a@thh440s> References: <1431013779-28910-1-git-send-email-thuth@redhat.com> <20150507230718.GA9410@iris.ozlabs.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, agraf@suse.de, gleb@kernel.org, pbonzini@redhat.com, benh@kernel.crashing.org, mpe@ellerman.id.au To: Paul Mackerras Return-path: In-Reply-To: <20150507230718.GA9410@iris.ozlabs.ibm.com> Sender: kvm-ppc-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Fri, 8 May 2015 09:07:18 +1000 Paul Mackerras wrote: > On Thu, May 07, 2015 at 05:49:39PM +0200, Thomas Huth wrote: > > Both functions are doing the same thing - looking up the struct > > kvm_vcpu pointer for a given vCPU ID. > > No, kvm_get_vcpu(n) returns the n'th vcpu created, which is often > but not necessarily the same as the vcpu with id n. In fact, due to > the way we do threading in HV KVM, it's quite common for userspace to > create vcpus with ids 0, 8, 16, ..., which means that the n'th vcpu > created does not have id n (except of course for vcpu 0). Ah, ok, thanks a lot for the explanation ... I thought that KVM would always put the VCPUs at the position of their ID into the array, but looking at kvm_vm_ioctl_create_vcpu(), you're right, it's using the amount of online CPUs as index instead: kvm->vcpus[atomic_read(&kvm->online_vcpus)] = vcpu; So never mind, and sorry for the nuisance! Thomas