kvm: fix a bug and remove a redundancy in async_pf
cover kvm: fix a bug and remove a redundancy in async_pf
I did not reproduce the bug fixed in [1/2], but there are not that many reasons why we could not unload a module, so the spot is quite obvious.
Radim Krčmář (2):
kvm: free resources after canceling async_pf
kvm: remove .done from struct kvm_async_pf
include/linux/kvm_host.h | 1 - virt/kvm/async_pf.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 kvm: free resources after canceling async_pf
When we cancel 'async_pf_execute()', we should behave as if the work was never scheduled in 'kvm_setup_async_pf()'.
Fixes a bug when we can't unload module because the vm wasn't destroyed.
--- virt/kvm/async_pf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
virt/kvm/async_pf.c +4 -1
@@ -102,8 +102,11 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu) typeof(*work), queue);cancel_work_sync (&work->work);list_del (&work->queue); -if (!work->done)/* work was canceled */ +if (!work->done) {/* work was canceled */ +mmdrop (work->mm); +kvm_put_kvm (vcpu->kvm);/* == work->vcpu->kvm */ kmem_cache_free (async_pf_cache, work); + } }spin_lock (&vcpu->async_pf.lock);
Signature · 1 line
1.8.3.1
PATCH 2/2 kvm: remove .done from struct kvm_async_pf
In reply to Radim Krčmář'.done' is used to mark the completion of 'async_pf_execute()', but 'cancel_work_sync()' returns true when the work was canceled, so we use it instead.
--- include/linux/kvm_host.h | 1 - virt/kvm/async_pf.c | 5 +---- 2 files changed, 1 insertion(+), 5 deletions(-)
include/linux/kvm_host.h +0 -1
@@ -190,7 +190,6 @@ struct kvm_async_pf {unsigned long addr;struct kvm_arch_async_pf arch;struct page *page; -bool done; };void kvm_clear_async_pf_completion_queue (struct kvm_vcpu *vcpu);
virt/kvm/async_pf.c +1 -4
@@ -76,7 +76,6 @@ static void async_pf_execute(struct work_struct *work)spin_lock (&vcpu->async_pf.lock);list_add_tail (&apf->link, &vcpu->async_pf.done); apf->page = page; - apf->done = true;spin_unlock (&vcpu->async_pf.lock);/*
@@ -100,9 +99,8 @@ void kvm_clear_async_pf_completion_queue(struct kvm_vcpu *vcpu)struct kvm_async_pf *work =list_entry (vcpu->async_pf.queue.next,typeof (*work), queue); -cancel_work_sync (&work->work);list_del (&work->queue); -if (!work->done) {/* work was canceled */ +if (cancel_work_sync (&work->work)) {mmdrop (work->mm);kvm_put_kvm (vcpu->kvm);/* == work->vcpu->kvm */ kmem_cache_free (async_pf_cache, work);
@@ -167,7 +165,6 @@ int kvm_setup_async_pf(struct kvm_vcpu *vcpu, gva_t gva, gfn_t gfn,return 0 ; work->page =NULL ; - work->done = false; work->vcpu = vcpu; work->gva = gva; work->addr =gfn_to_hva (vcpu->kvm, gfn);
Signature · 1 line
1.8.3.1
Il 04/09/2013 22:32, Radim Krčmář ha scritto:
Quoted 4 lines
I did not reproduce the bug fixed in [1/2], but there are not that many reasons why we could not unload a module, so the spot is quite obvious.
Quoted 8 lines
Radim Krčmář (2):
kvm: free resources after cancelingasync_pf
kvm: remove .done from structkvm_async_pfinclude/linux/kvm_host.h | 1 - virt/kvm/async_pf.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-)
Quoted 4 lines · Radim Krčmář
I did not reproduce the bug fixed in [1/2], but there are not that many reasons why we could not unload a module, so the spot is quite obvious.
Quoted 10 lines
Radim Krčmář (2):
kvm: free resources after cancelingasync_pf
kvm: remove .done from structkvm_async_pfinclude/linux/kvm_host.h | 1 - virt/kvm/async_pf.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-)Signature · 1 line
1.8.3.1
--
Gleb.
Il 04/09/2013 22:32, Radim Krčmář ha scritto:
Quoted 4 lines
I did not reproduce the bug fixed in [1/2], but there are not that many reasons why we could not unload a module, so the spot is quite obvious.
Quoted 8 lines
Radim Krčmář (2):
kvm: free resources after cancelingasync_pf
kvm: remove .done from structkvm_async_pfinclude/linux/kvm_host.h | 1 - virt/kvm/async_pf.c | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-)
Applied to kvm-queue; patch 1 will go in 3.12, patch 2 won't.
Paolo