@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
70
70
*/
71
71
int kvm_vgic_create (struct kvm * kvm , u32 type )
72
72
{
73
- int i , vcpu_lock_idx = -1 , ret ;
73
+ int i , ret ;
74
74
struct kvm_vcpu * vcpu ;
75
75
76
76
if (irqchip_in_kernel (kvm ))
@@ -86,17 +86,9 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
86
86
!kvm_vgic_global_state .can_emulate_gicv2 )
87
87
return - ENODEV ;
88
88
89
- /*
90
- * Any time a vcpu is run, vcpu_load is called which tries to grab the
91
- * vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
92
- * that no other VCPUs are run while we create the vgic.
93
- */
94
89
ret = - EBUSY ;
95
- kvm_for_each_vcpu (i , vcpu , kvm ) {
96
- if (!mutex_trylock (& vcpu -> mutex ))
97
- goto out_unlock ;
98
- vcpu_lock_idx = i ;
99
- }
90
+ if (!lock_all_vcpus (kvm ))
91
+ return ret ;
100
92
101
93
kvm_for_each_vcpu (i , vcpu , kvm ) {
102
94
if (vcpu -> arch .has_run_once )
@@ -125,10 +117,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
125
117
INIT_LIST_HEAD (& kvm -> arch .vgic .rd_regions );
126
118
127
119
out_unlock :
128
- for (; vcpu_lock_idx >= 0 ; vcpu_lock_idx -- ) {
129
- vcpu = kvm_get_vcpu (kvm , vcpu_lock_idx );
130
- mutex_unlock (& vcpu -> mutex );
131
- }
120
+ unlock_all_vcpus (kvm );
132
121
return ret ;
133
122
}
134
123
0 commit comments