Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752164AbcDUOa2 (ORCPT ); Thu, 21 Apr 2016 10:30:28 -0400 Received: from e06smtp10.uk.ibm.com ([195.75.94.106]:45861 "EHLO e06smtp10.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbcDUOa0 (ORCPT ); Thu, 21 Apr 2016 10:30:26 -0400 X-IBM-Helo: d06dlp03.portsmouth.uk.ibm.com X-IBM-MailFrom: gkurz@linux.vnet.ibm.com X-IBM-RcptTo: kvm@vger.kernel.org;linux-kernel@vger.kernel.org Date: Thu, 21 Apr 2016 16:30:07 +0200 From: Greg Kurz To: David Hildenbrand Cc: Paolo Bonzini , james.hogan@imgtec.com, mingo@redhat.com, linux-mips@linux-mips.org, kvm@vger.kernel.org, rkrcmar@redhat.com, linux-kernel@vger.kernel.org, qemu-ppc@nongnu.org, Cornelia Huck , Paul Mackerras , David Gibson Subject: Re: [PATCH v4 1/2] KVM: remove NULL return path for vcpu ids >= KVM_MAX_VCPUS Message-ID: <20160421163007.6302a1bc@bahia.huguette.org> In-Reply-To: <20160421161729.2f430008@thinkpad-w530> References: <146124809455.32509.15232948272580716135.stgit@bahia.huguette.org> <146124810201.32509.2946887043729554992.stgit@bahia.huguette.org> <20160421161729.2f430008@thinkpad-w530> Organization: IBM X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16042114-0041-0000-0000-00001AD52452 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1802 Lines: 59 On Thu, 21 Apr 2016 16:17:29 +0200 David Hildenbrand wrote: > > Commit c896939f7cff ("KVM: use heuristic for fast VCPU lookup by id") added > > a return path that prevents vcpu ids to exceed KVM_MAX_VCPUS. This is a > > problem for powerpc where vcpu ids can grow up to 8*KVM_MAX_VCPUS. > > > > This patch simply reverses the logic so that we only try fast path if the > > vcpu id can be tried as an index in kvm->vcpus[]. The slow path is not > > affected by the change. > > > > Signed-off-by: Greg Kurz > > --- > > include/linux/kvm_host.h | 7 ++++--- > > 1 file changed, 4 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h > > index 5276fe0916fc..23bfe1bd159c 100644 > > --- a/include/linux/kvm_host.h > > +++ b/include/linux/kvm_host.h > > @@ -447,12 +447,13 @@ static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i) > > > > static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id) > > { > > - struct kvm_vcpu *vcpu; > > + struct kvm_vcpu *vcpu = NULL; > > int i; > > > > - if (id < 0 || id >= KVM_MAX_VCPUS) > > + if (id < 0) > > return NULL; > > - vcpu = kvm_get_vcpu(kvm, id); > > + if (id < KVM_MAX_VCPUS) > > + vcpu = kvm_get_vcpu(kvm, id); > > Maybe this check even should go into kvm_get_vcpu() > Yeah possibly, but there are 19 users for kvm_get_vcpu() and I'm not sure if none of them is on a hot path where this extra check could hurt... maybe this can be done in a cleanup patch afterwards ? > > if (vcpu && vcpu->vcpu_id == id) > > return vcpu; > > kvm_for_each_vcpu(i, vcpu, kvm) > > > > Anyhow, > > Reviewed-by: David Hildenbrand > > David Thanks for the review ! Cheers. -- Greg