KVM: convert vm lock to a mutex
RFC 3/8 KVM: convert vm lock to a mutex
convert kvm lock to a mutex.
TBD: after this change, a lot of logic in kvm can be simplified, eg, we don't need release lock and then do operation blocking.
--- drivers/kvm/kvm.h | 2 - drivers/kvm/kvm_main.c | 58 ++++++++++++++++++++++++------------------------- drivers/kvm/mmu.c | 8 +++--- drivers/kvm/svm.c | 8 +++--- drivers/kvm/vmx.c | 8 +++--- 5 files changed, 42 insertions(+), 42 deletions(-)
drivers/kvm/kvm.h +1 -1
@@ -437,7 +437,7 @@ struct kvm_memory_slot { };struct kvm { -spinlock_t lock;/* protects everything except vcpus */ +struct mutex lock;/* protects everything except vcpus */ int naliases;struct kvm_mem_alias aliases[KVM_ALIAS_SLOTS ];int nmemslots;
drivers/kvm/kvm_main.c +25 -25
167 lines not on this page · raw message
2. preempt_count check doesn't make sense with preempt disabled
3. vmx_cpu_run doesn't handle error correctly and kvm_mmu_reload might sleep with mutex cha
@@ -1888,12 +1888,12 @@ int kvm_setup_pio(struct kvm_vcpu *vcpu,
vcpu->pio.cur_count = now;
for (i = 0; i < nr_pages; ++i) {
- spin_lock(&vcpu->kvm->lock);
+ mutex_lock(&vcpu->kvm->lock);
page = gva_to_page(vcpu, address + i * PAGE_SIZE); if (page)
get_page(page);
vcpu->pio.guest_pages[i] = page;
- spin_unlock(&vcpu->kvm->lock);
+ mutex_unlock(&vcpu->kvm->lock);
if (!page) {
inject_gp(vcpu); free_pio_guest_pages(vcpu);
@@ -2275,13 +2275,13 @@ static int kvm_vcpu_ioctl_translate(stru
gpa_t gpa;
/vmcs_writel are called with preempt enabled
2. preempt_count check doesn't make sense with preempt disabled
3. vmx_cpu_run doesn't handle error correctly and kvm_mmu_reload might sleep with mutex cha
vcpu_load(vcpu);
- spin_lock(&vcpu->kvm->lock);
+ mutex_lock(&vcpu->kvm->lock);
gpa = vcpu->mmu.gva_to_gpa(vcpu, vaddr); tr->physical_address = gpa;
tr->valid = gpa != UNMAPPED_GVA;
tr->writeable = 1;
tr->usermode = 0;
- spin_unlock(&vcpu->kvm->lock);
+ mutex_unlock(&vcpu->kvm->lock);
vcpu_put(vcpu);
/vmcs_writel are called with preempt enabled
2. preempt_count check doesn't make sense with preempt disabled
3. vmx_cpu_run doesn't handle error correctly and kvm_mmu_reload might sleep with mutex cha
return 0;
drivers/kvm/mmu.c +4 -4
@@ -253,9 +253,9 @@ static int mmu_topup_memory_caches(struc r =__mmu_topup_memory_caches (vcpu,GFP_NOWAIT );if (r <0 ) { -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock); r =__mmu_topup_memory_caches (vcpu,GFP_KERNEL ); -spin_lock (&vcpu->kvm->lock); +mutex_lock (&vcpu->kvm->lock); }return r; }
@@ -1059,7 +1059,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) {int r; -spin_lock (&vcpu->kvm->lock); +mutex_lock (&vcpu->kvm->lock); r =mmu_topup_memory_caches (vcpu);if (r) goto out;
@@ -1067,7 +1067,7 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu) kvm_arch_ops->set_cr3 (vcpu, vcpu->mmu.root_hpa);kvm_mmu_flush_tlb (vcpu); out: -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);return r; }EXPORT_SYMBOL_GPL (kvm_mmu_load);
drivers/kvm/svm.c +4 -4
@@ -908,21 +908,21 @@ static int pf_interception(struct kvm_vcif (is_external_interrupt (exit_int_info))push_irq (vcpu, exit_int_info &SVM_EVTINJ_VEC_MASK ); -spin_lock (&vcpu->kvm->lock); +mutex_lock (&vcpu->kvm->lock); fault_address = vcpu->svm->vmcb->control.exit_info_2; error_code = vcpu->svm->vmcb->control.exit_info_1; r =kvm_mmu_page_fault (vcpu, fault_address, error_code);if (r <0 ) { -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);return r; }if (!r) { -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);return 1 ; } er =emulate_instruction (vcpu, kvm_run, fault_address, error_code); -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);switch (er) {case EMULATE_DONE :
drivers/kvm/vmx.c +4 -4
@@ -1588,19 +1588,19 @@ static int handle_exception(struct kvm_vif (is_page_fault (intr_info)) { cr2 =vmcs_readl (EXIT_QUALIFICATION ); -spin_lock (&vcpu->kvm->lock); +mutex_lock (&vcpu->kvm->lock); r =kvm_mmu_page_fault (vcpu, cr2, error_code);if (r <0 ) { -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);return r; }if (!r) { -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);return 1 ; } er =emulate_instruction (vcpu, kvm_run, cr2, error_code); -spin_unlock (&vcpu->kvm->lock); +mutex_unlock (&vcpu->kvm->lock);switch (er) {case EMULATE_DONE :
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
Quoted 5 lines · Shaohua Li
convert kvm lock to a mutex.
TBD: after this change, a lot of logic in kvm can be simplified, eg, we don't need release lock and then do operation blocking.
This is now in the preempt-hooks branch.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/