LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf
@ 2013-09-04 20:32 Radim Krčmář
  2013-09-04 20:32 ` [PATCH 1/2] kvm: free resources after canceling async_pf Radim Krčmář
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Radim Krčmář @ 2013-09-04 20:32 UTC (permalink / raw
  To: linux-kernel; +Cc: kvm, Gleb Natapov, Paolo Bonzini

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(-)

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] kvm: free resources after canceling async_pf
  2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
@ 2013-09-04 20:32 ` Radim Krčmář
  2013-09-04 20:32 ` [PATCH 2/2] kvm: remove .done from struct kvm_async_pf Radim Krčmář
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Radim Krčmář @ 2013-09-04 20:32 UTC (permalink / raw
  To: linux-kernel; +Cc: kvm, Gleb Natapov, Paolo Bonzini

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.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 virt/kvm/async_pf.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index b44cea0..f30aa1c 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -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);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] kvm: remove .done from struct kvm_async_pf
  2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
  2013-09-04 20:32 ` [PATCH 1/2] kvm: free resources after canceling async_pf Radim Krčmář
@ 2013-09-04 20:32 ` Radim Krčmář
  2013-09-05 15:52 ` [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Paolo Bonzini
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Radim Krčmář @ 2013-09-04 20:32 UTC (permalink / raw
  To: linux-kernel; +Cc: kvm, Gleb Natapov, Paolo Bonzini

'.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.

Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
---
 include/linux/kvm_host.h | 1 -
 virt/kvm/async_pf.c      | 5 +----
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ca645a0..c7a5e08 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -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);
diff --git a/virt/kvm/async_pf.c b/virt/kvm/async_pf.c
index f30aa1c..89acf41 100644
--- a/virt/kvm/async_pf.c
+++ b/virt/kvm/async_pf.c
@@ -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);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf
  2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
  2013-09-04 20:32 ` [PATCH 1/2] kvm: free resources after canceling async_pf Radim Krčmář
  2013-09-04 20:32 ` [PATCH 2/2] kvm: remove .done from struct kvm_async_pf Radim Krčmář
@ 2013-09-05 15:52 ` Paolo Bonzini
  2013-09-08  8:33 ` Gleb Natapov
  2013-09-12 16:32 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2013-09-05 15:52 UTC (permalink / raw
  To: Radim Krčmář; +Cc: linux-kernel, kvm, Gleb Natapov

Il 04/09/2013 22:32, Radim Krčmář ha scritto:
> 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(-)
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf
  2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
                   ` (2 preceding siblings ...)
  2013-09-05 15:52 ` [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Paolo Bonzini
@ 2013-09-08  8:33 ` Gleb Natapov
  2013-09-12 16:32 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Gleb Natapov @ 2013-09-08  8:33 UTC (permalink / raw
  To: Radim Krčmář; +Cc: linux-kernel, kvm, Paolo Bonzini

On Wed, Sep 04, 2013 at 10:32:22PM +0200, Radim Krčmář wrote:
> 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.
> 
> 
Reviewed-by: Gleb Natapov <gleb@redhat.com>

> 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(-)
> 
> -- 
> 1.8.3.1

--
			Gleb.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf
  2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
                   ` (3 preceding siblings ...)
  2013-09-08  8:33 ` Gleb Natapov
@ 2013-09-12 16:32 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2013-09-12 16:32 UTC (permalink / raw
  To: Radim Krčmář; +Cc: linux-kernel, kvm, Gleb Natapov

Il 04/09/2013 22:32, Radim Krčmář ha scritto:
> 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(-)
> 

Applied to kvm-queue; patch 1 will go in 3.12, patch 2 won't.

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-09-12 16:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-04 20:32 [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Radim Krčmář
2013-09-04 20:32 ` [PATCH 1/2] kvm: free resources after canceling async_pf Radim Krčmář
2013-09-04 20:32 ` [PATCH 2/2] kvm: remove .done from struct kvm_async_pf Radim Krčmář
2013-09-05 15:52 ` [PATCH 0/2] kvm: fix a bug and remove a redundancy in async_pf Paolo Bonzini
2013-09-08  8:33 ` Gleb Natapov
2013-09-12 16:32 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).