Commit 3cba41307a2b1344ab8c1b9f55202d1e9d7bf81b
Committed by
Marcelo Tosatti
1 parent
6b7e2d0991
Exists in
master
and in
39 other branches
KVM: make make_all_cpus_request() lockless
Now, we have 'vcpu->mode' to judge whether need to send ipi to other cpus, this way is very exact, so checking request bit is needless, then we can drop the spinlock let it's collateral Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Showing 2 changed files with 3 additions and 12 deletions Side-by-side Diff
include/linux/kvm_host.h
... | ... | @@ -224,7 +224,6 @@ |
224 | 224 | |
225 | 225 | struct kvm { |
226 | 226 | spinlock_t mmu_lock; |
227 | - raw_spinlock_t requests_lock; | |
228 | 227 | struct mutex slots_lock; |
229 | 228 | struct mm_struct *mm; /* userspace tied to this vm */ |
230 | 229 | struct kvm_memslots *memslots; |
... | ... | @@ -729,11 +728,6 @@ |
729 | 728 | static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) |
730 | 729 | { |
731 | 730 | set_bit(req, &vcpu->requests); |
732 | -} | |
733 | - | |
734 | -static inline bool kvm_make_check_request(int req, struct kvm_vcpu *vcpu) | |
735 | -{ | |
736 | - return test_and_set_bit(req, &vcpu->requests); | |
737 | 731 | } |
738 | 732 | |
739 | 733 | static inline bool kvm_check_request(int req, struct kvm_vcpu *vcpu) |
virt/kvm/kvm_main.c
... | ... | @@ -165,11 +165,9 @@ |
165 | 165 | |
166 | 166 | zalloc_cpumask_var(&cpus, GFP_ATOMIC); |
167 | 167 | |
168 | - raw_spin_lock(&kvm->requests_lock); | |
169 | - me = smp_processor_id(); | |
168 | + me = get_cpu(); | |
170 | 169 | kvm_for_each_vcpu(i, vcpu, kvm) { |
171 | - if (kvm_make_check_request(req, vcpu)) | |
172 | - continue; | |
170 | + kvm_make_request(req, vcpu); | |
173 | 171 | cpu = vcpu->cpu; |
174 | 172 | |
175 | 173 | /* Set ->requests bit before we read ->mode */ |
... | ... | @@ -185,7 +183,7 @@ |
185 | 183 | smp_call_function_many(cpus, ack_flush, NULL, 1); |
186 | 184 | else |
187 | 185 | called = false; |
188 | - raw_spin_unlock(&kvm->requests_lock); | |
186 | + put_cpu(); | |
189 | 187 | free_cpumask_var(cpus); |
190 | 188 | return called; |
191 | 189 | } |
... | ... | @@ -468,7 +466,6 @@ |
468 | 466 | kvm->mm = current->mm; |
469 | 467 | atomic_inc(&kvm->mm->mm_count); |
470 | 468 | spin_lock_init(&kvm->mmu_lock); |
471 | - raw_spin_lock_init(&kvm->requests_lock); | |
472 | 469 | kvm_eventfd_init(kvm); |
473 | 470 | mutex_init(&kvm->lock); |
474 | 471 | mutex_init(&kvm->irq_lock); |