Skip to content

Commit 8f56770

Browse files
Maxim Levitskybonzini
authored andcommitted
RISC-V: KVM: use kvm_trylock_all_vcpus when locking all vCPUs
Use kvm_trylock_all_vcpus instead of a custom implementation when locking all vCPUs of a VM. Compile tested only. Suggested-by: Paolo Bonzini <[email protected]> Signed-off-by: Maxim Levitsky <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b586c5d commit 8f56770

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

arch/riscv/kvm/aia_device.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,6 @@
1212
#include <linux/kvm_host.h>
1313
#include <linux/uaccess.h>
1414

15-
static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx)
16-
{
17-
struct kvm_vcpu *tmp_vcpu;
18-
19-
for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
20-
tmp_vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
21-
mutex_unlock(&tmp_vcpu->mutex);
22-
}
23-
}
24-
25-
static void unlock_all_vcpus(struct kvm *kvm)
26-
{
27-
unlock_vcpus(kvm, atomic_read(&kvm->online_vcpus) - 1);
28-
}
29-
30-
static bool lock_all_vcpus(struct kvm *kvm)
31-
{
32-
struct kvm_vcpu *tmp_vcpu;
33-
unsigned long c;
34-
35-
kvm_for_each_vcpu(c, tmp_vcpu, kvm) {
36-
if (!mutex_trylock(&tmp_vcpu->mutex)) {
37-
unlock_vcpus(kvm, c - 1);
38-
return false;
39-
}
40-
}
41-
42-
return true;
43-
}
44-
4515
static int aia_create(struct kvm_device *dev, u32 type)
4616
{
4717
int ret;
@@ -53,7 +23,7 @@ static int aia_create(struct kvm_device *dev, u32 type)
5323
return -EEXIST;
5424

5525
ret = -EBUSY;
56-
if (!lock_all_vcpus(kvm))
26+
if (kvm_trylock_all_vcpus(kvm))
5727
return ret;
5828

5929
kvm_for_each_vcpu(i, vcpu, kvm) {
@@ -65,7 +35,7 @@ static int aia_create(struct kvm_device *dev, u32 type)
6535
kvm->arch.aia.in_kernel = true;
6636

6737
out_unlock:
68-
unlock_all_vcpus(kvm);
38+
kvm_unlock_all_vcpus(kvm);
6939
return ret;
7040
}
7141

0 commit comments

Comments
 (0)