KVM: Use common function for VCPU lookup by id
authorDavid Hildenbrand <dahi@linux.vnet.ibm.com>
Thu, 5 Nov 2015 08:03:50 +0000 (09:03 +0100)
committerChristian Borntraeger <borntraeger@de.ibm.com>
Mon, 30 Nov 2015 11:47:04 +0000 (12:47 +0100)
Let's reuse the new common function for VPCU lookup 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 out the new function into a separate patch]

arch/powerpc/kvm/book3s_hv.c
arch/s390/kvm/diag.c
virt/kvm/kvm_main.c

index 54b45b73195f912688ec4afe8e9fb4c9c3d5723c..a29da44cdc6cb3e88eaacd70d01b38b68eb51eef 100644 (file)
@@ -308,16 +308,10 @@ static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
 
 static struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id)
 {
-       int r;
-       struct kvm_vcpu *v, *ret = NULL;
+       struct kvm_vcpu *ret;
 
        mutex_lock(&kvm->lock);
-       kvm_for_each_vcpu(r, v, kvm) {
-               if (v->vcpu_id == id) {
-                       ret = v;
-                       break;
-               }
-       }
+       ret = kvm_get_vcpu_by_id(kvm, id);
        mutex_unlock(&kvm->lock);
        return ret;
 }
index 5fbfb88f847731db6ef4cb1ab87b32cf601703df..05f7de9869a9f1786a8b996edd10fcdb280bd7c0 100644 (file)
@@ -155,10 +155,8 @@ static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
 
 static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
 {
-       struct kvm *kvm = vcpu->kvm;
        struct kvm_vcpu *tcpu;
        int tid;
-       int i;
 
        tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
        vcpu->stat.diagnose_9c++;
@@ -167,12 +165,9 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
        if (tid == vcpu->vcpu_id)
                return 0;
 
-       kvm_for_each_vcpu(i, tcpu, kvm)
-               if (tcpu->vcpu_id == tid) {
-                       kvm_vcpu_yield_to(tcpu);
-                       break;
-               }
-
+       tcpu = kvm_get_vcpu_by_id(vcpu->kvm, tid);
+       if (tcpu)
+               kvm_vcpu_yield_to(tcpu);
        return 0;
 }
 
index 73cbb4120d0b233daa584b7609a9051a0f890376..9649a42ee990ecbc7bd354d5426173a1ddc934e7 100644 (file)
@@ -2257,7 +2257,7 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
 static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
 {
        int r;
-       struct kvm_vcpu *vcpu, *v;
+       struct kvm_vcpu *vcpu;
 
        if (id >= KVM_MAX_VCPUS)
                return -EINVAL;
@@ -2281,12 +2281,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
                r = -EINVAL;
                goto unlock_vcpu_destroy;
        }
-
-       kvm_for_each_vcpu(r, v, kvm)
-               if (v->vcpu_id == id) {
-                       r = -EEXIST;
-                       goto unlock_vcpu_destroy;
-               }
+       if (kvm_get_vcpu_by_id(kvm, id)) {
+               r = -EEXIST;
+               goto unlock_vcpu_destroy;
+       }
 
        BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]);