From: David Hildenbrand Date: Thu, 5 Nov 2015 08:55:08 +0000 (+0100) Subject: KVM: use heuristic for fast VCPU lookup by id X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=c896939f7cff767091b5d84587cd144e5d3613b7;p=linux-beck.git KVM: use heuristic for fast VCPU lookup by id Usually, VCPU ids match the array index. So let's try a fast lookup first before falling back to the slow iteration. Suggested-by: Christian Borntraeger Reviewed-by: Dominik Dingel Reviewed-by: Christian Borntraeger Signed-off-by: David Hildenbrand Signed-off-by: Christian Borntraeger --- diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 29119193a19f..a754fc08e194 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -472,6 +472,11 @@ static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id) struct kvm_vcpu *vcpu; int i; + if (id < 0 || id >= KVM_MAX_VCPUS) + return NULL; + vcpu = kvm_get_vcpu(kvm, id); + if (vcpu && vcpu->vcpu_id == id) + return vcpu; kvm_for_each_vcpu(i, vcpu, kvm) if (vcpu->vcpu_id == id) return vcpu;