aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/powerpc/kvm/book3s_hv.c10
-rw-r--r--arch/s390/kvm/diag.c11
-rw-r--r--virt/kvm/kvm_main.c12
3 files changed, 10 insertions, 23 deletions
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 54b45b73195f..a29da44cdc6c 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -308,16 +308,10 @@ static void kvmppc_dump_regs(struct kvm_vcpu *vcpu)
308 308
309static struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id) 309static struct kvm_vcpu *kvmppc_find_vcpu(struct kvm *kvm, int id)
310{ 310{
311 int r; 311 struct kvm_vcpu *ret;
312 struct kvm_vcpu *v, *ret = NULL;
313 312
314 mutex_lock(&kvm->lock); 313 mutex_lock(&kvm->lock);
315 kvm_for_each_vcpu(r, v, kvm) { 314 ret = kvm_get_vcpu_by_id(kvm, id);
316 if (v->vcpu_id == id) {
317 ret = v;
318 break;
319 }
320 }
321 mutex_unlock(&kvm->lock); 315 mutex_unlock(&kvm->lock);
322 return ret; 316 return ret;
323} 317}
diff --git a/arch/s390/kvm/diag.c b/arch/s390/kvm/diag.c
index 5fbfb88f8477..05f7de9869a9 100644
--- a/arch/s390/kvm/diag.c
+++ b/arch/s390/kvm/diag.c
@@ -155,10 +155,8 @@ static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
155 155
156static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu) 156static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
157{ 157{
158 struct kvm *kvm = vcpu->kvm;
159 struct kvm_vcpu *tcpu; 158 struct kvm_vcpu *tcpu;
160 int tid; 159 int tid;
161 int i;
162 160
163 tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4]; 161 tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
164 vcpu->stat.diagnose_9c++; 162 vcpu->stat.diagnose_9c++;
@@ -167,12 +165,9 @@ static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
167 if (tid == vcpu->vcpu_id) 165 if (tid == vcpu->vcpu_id)
168 return 0; 166 return 0;
169 167
170 kvm_for_each_vcpu(i, tcpu, kvm) 168 tcpu = kvm_get_vcpu_by_id(vcpu->kvm, tid);
171 if (tcpu->vcpu_id == tid) { 169 if (tcpu)
172 kvm_vcpu_yield_to(tcpu); 170 kvm_vcpu_yield_to(tcpu);
173 break;
174 }
175
176 return 0; 171 return 0;
177} 172}
178 173
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 73cbb4120d0b..9649a42ee990 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2257,7 +2257,7 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
2257static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id) 2257static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
2258{ 2258{
2259 int r; 2259 int r;
2260 struct kvm_vcpu *vcpu, *v; 2260 struct kvm_vcpu *vcpu;
2261 2261
2262 if (id >= KVM_MAX_VCPUS) 2262 if (id >= KVM_MAX_VCPUS)
2263 return -EINVAL; 2263 return -EINVAL;
@@ -2281,12 +2281,10 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)
2281 r = -EINVAL; 2281 r = -EINVAL;
2282 goto unlock_vcpu_destroy; 2282 goto unlock_vcpu_destroy;
2283 } 2283 }
2284 2284 if (kvm_get_vcpu_by_id(kvm, id)) {
2285 kvm_for_each_vcpu(r, v, kvm) 2285 r = -EEXIST;
2286 if (v->vcpu_id == id) { 2286 goto unlock_vcpu_destroy;
2287 r = -EEXIST; 2287 }
2288 goto unlock_vcpu_destroy;
2289 }
2290 2288
2291 BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]); 2289 BUG_ON(kvm->vcpus[atomic_read(&kvm->online_vcpus)]);
2292 2290