[RHEL7,COMMIT] ms/KVM: Provide function for VCPU lookup by id

Submitted by Konstantin Khorenko on Oct. 12, 2017, 11:25 a.m.

Details

Message ID 201710121125.v9CBPgeI013430@finist_ce7.work
State New
Series "kvm: hyperv: backport latest stuff from mainstream"
Headers show

Commit Message

Konstantin Khorenko Oct. 12, 2017, 11:25 a.m.
The commit is pushed to "branch-rh7-3.10.0-693.1.1.vz7.37.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.1.1.vz7.37.12
------>
commit 8607d518adee981838ed421cbb3d7ddd46f1a590
Author: David Hildenbrand <dahi@linux.vnet.ibm.com>
Date:   Thu Oct 12 14:25:42 2017 +0300

    ms/KVM: Provide function for VCPU lookup by id
    
    Let's provide a function to lookup a VCPU by id.
    
    Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
    Reviewed-by: Dominik Dingel <dingel@linux.vnet.ibm.com>
    Signed-off-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
    Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
    [split patch from refactoring patch]
    
    (cherry picked from commit db27a7a37aa0b1f8b373f8b0fb72a2ccaafb85b7)
    Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
---
 include/linux/kvm_host.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ccc33ac..de3cc6d 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -477,6 +477,17 @@  static inline struct kvm_vcpu *kvm_get_vcpu(struct kvm *kvm, int i)
 	     (vcpup = kvm_get_vcpu(kvm, idx)) != NULL; \
 	     idx++)
 
+static inline struct kvm_vcpu *kvm_get_vcpu_by_id(struct kvm *kvm, int id)
+{
+	struct kvm_vcpu *vcpu;
+	int i;
+
+	kvm_for_each_vcpu(i, vcpu, kvm)
+		if (vcpu->vcpu_id == id)
+			return vcpu;
+	return NULL;
+}
+
 #define kvm_for_each_memslot(memslot, slots)	\
 	for (memslot = &slots->memslots[0];	\
 	      memslot < slots->memslots + KVM_MEM_SLOTS_NUM && memslot->npages;\