From: David Hildenbrand <d...@linux.vnet.ibm.com>

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 <borntrae...@de.ibm.com>
Reviewed-by: Dominik Dingel <din...@linux.vnet.ibm.com>
Reviewed-by: Christian Borntraeger <borntrae...@de.ibm.com>
Signed-off-by: David Hildenbrand <d...@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntrae...@de.ibm.com>
---
 include/linux/kvm_host.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 2911919..a754fc0 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;
-- 
2.3.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to