Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753730AbcD0JlF (ORCPT ); Wed, 27 Apr 2016 05:41:05 -0400 Received: from e18.ny.us.ibm.com ([129.33.205.208]:55863 "EHLO e18.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753748AbcD0JlB (ORCPT ); Wed, 27 Apr 2016 05:41:01 -0400 X-IBM-Helo: d01dlp01.pok.ibm.com X-IBM-MailFrom: gkurz@linux.vnet.ibm.com X-IBM-RcptTo: kvm@vger.kernel.org;linux-kernel@vger.kernel.org Date: Wed, 27 Apr 2016 05:40:52 -0400 Message-ID: <20160427054052.Horde.SSxGXKxS_wcijUfLJchjWw2@ltc.linux.ibm.com> From: Gerg Kurz To: Paolo Bonzini , james.hogan@imgtec.com, mingo@redhat.com Cc: linux-mips@linux-mips.org, kvm@vger.kernel.org, rkrcmar@redhat.com, linux-kernel@vger.kernel.org, David Hildenbrand , qemu-ppc@nongnu.org, Cornelia Huck , Paul Mackerras , David Gibson , Radim =?utf-8?b?S3LEjW3DocWZ?= Subject: Re: [PATCH v4 1/2] KVM: remove NULL return path for vcpu ids >= KVM_MAX_VCPUS References: <146124809455.32509.15232948272580716135.stgit@bahia.huguette.org> <146124810201.32509.2946887043729554992.stgit@bahia.huguette.org> In-Reply-To: <146124810201.32509.2946887043729554992.stgit@bahia.huguette.org> User-Agent: Internet Messaging Program (IMP) H5 (6.1.7) Content-Type: text/plain; charset=UTF-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16042709-0045-0000-0000-00000409639B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1763 Lines: 58 Quoting Greg Kurz : > 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 > --- Radim, I think this sanity check is only needed because kvm_get_vcpu() use the id as an index in kvm->vcpus[]. Checking against the new KVM_MAX_VCPU_ID would be clearly wrong here. And this patch got two R-b tags already. Do you agree we keep it ? Cheers. -- Greg > 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); > if (vcpu && vcpu->vcpu_id == id) > return vcpu; > kvm_for_each_vcpu(i, vcpu, kvm) > > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html