[Devel] [PATCH RHEL7 COMMIT] ms/KVM: Add kvm_vcpu_get_idx to get vcpu index in kvm->vcpus

Konstantin Khorenko khorenko at virtuozzo.com
Thu Oct 12 14:25:42 MSK 2017


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 70dd618ac470a639e3b0e8f4ed02be36590acfb0
Author: Christoffer Dall <cdall at linaro.org>
Date:   Thu Oct 12 14:25:42 2017 +0300

    ms/KVM: Add kvm_vcpu_get_idx to get vcpu index in kvm->vcpus
    
    There are occasional needs to use the index of vcpu in the kvm->vcpus
    array to map something related to a VCPU.  For example, unlike the
    vcpu->vcpu_id, the vcpu index is guaranteed to not be sparse across all
    vcpus which is useful when allocating a memory area for each vcpu.
    
    Signed-off-by: Christoffer Dall <cdall at linaro.org>
    Reviewed-by: Eric Auger <eric.auger at redhat.com>
    
    (cherry picked from commit 497d72d80a789501501cccabdad6b145f9e31371)
    Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
 include/linux/kvm_host.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

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


More information about the Devel mailing list