public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: fix rcu warning on VM_CREATE errors
@ 2017-09-13 12:17 Christian Borntraeger
  2017-09-13 12:23 ` David Hildenbrand
  2017-09-13 15:40 ` Radim Krčmář
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Borntraeger @ 2017-09-13 12:17 UTC (permalink / raw)
  To: Paolo Bonzini, Radim Krčmář
  Cc: KVM, Christian Borntraeger, Stefan Haberland

commit 3898da947bba ("KVM: avoid using rcu_dereference_protected") can
trigger the following lockdep/rcu splat if the VM_CREATE ioctl fails,
for example if kvm_arch_init_vm fails:

WARNING: suspicious RCU usage
4.13.0+ #105 Not tainted
-----------------------------
./include/linux/kvm_host.h:481 suspicious rcu_dereference_check() usage!

other info that might help us debug this:

rcu_scheduler_active = 2, debug_locks = 1
no locks held by qemu-system-s39/79.
stack backtrace:
CPU: 0 PID: 79 Comm: qemu-system-s39 Not tainted 4.13.0+ #105
Hardware name: IBM 2964 NC9 704 (KVM/Linux)
Call Trace:
([<00000000001140b2>] show_stack+0xea/0xf0)
 [<00000000008a68a4>] dump_stack+0x94/0xd8
 [<0000000000134c12>] kvm_dev_ioctl+0x372/0x7a0
 [<000000000038f940>] do_vfs_ioctl+0xa8/0x6c8
 [<0000000000390004>] SyS_ioctl+0xa4/0xb8
 [<00000000008c7a8c>] system_call+0xc4/0x27c
no locks held by qemu-system-s39/79.

We have to reset the just created users_count back to 0 to
tell the check to not trigger.

Reported-by: Stefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Fixes: 3898da947bba ("KVM: avoid using rcu_dereference_protected")
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
 virt/kvm/kvm_main.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1b3fa3f..1205d20 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -716,6 +716,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
 out_err_no_srcu:
 	hardware_disable_all();
 out_err_no_disable:
+	refcount_set(&kvm->users_count, 0);
 	for (i = 0; i < KVM_NR_BUSES; i++)
 		kfree(kvm_get_bus(kvm, i));
 	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
-- 
2.9.4

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

* Re: [PATCH] KVM: fix rcu warning on VM_CREATE errors
  2017-09-13 12:17 [PATCH] KVM: fix rcu warning on VM_CREATE errors Christian Borntraeger
@ 2017-09-13 12:23 ` David Hildenbrand
  2017-09-13 15:40 ` Radim Krčmář
  1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2017-09-13 12:23 UTC (permalink / raw)
  To: Christian Borntraeger, Paolo Bonzini, Radim Krčmář
  Cc: KVM, Stefan Haberland

On 13.09.2017 14:17, Christian Borntraeger wrote:
> commit 3898da947bba ("KVM: avoid using rcu_dereference_protected") can
> trigger the following lockdep/rcu splat if the VM_CREATE ioctl fails,
> for example if kvm_arch_init_vm fails:
> 
> WARNING: suspicious RCU usage
> 4.13.0+ #105 Not tainted
> -----------------------------
> ./include/linux/kvm_host.h:481 suspicious rcu_dereference_check() usage!
> 
> other info that might help us debug this:
> 
> rcu_scheduler_active = 2, debug_locks = 1
> no locks held by qemu-system-s39/79.
> stack backtrace:
> CPU: 0 PID: 79 Comm: qemu-system-s39 Not tainted 4.13.0+ #105
> Hardware name: IBM 2964 NC9 704 (KVM/Linux)
> Call Trace:
> ([<00000000001140b2>] show_stack+0xea/0xf0)
>  [<00000000008a68a4>] dump_stack+0x94/0xd8
>  [<0000000000134c12>] kvm_dev_ioctl+0x372/0x7a0
>  [<000000000038f940>] do_vfs_ioctl+0xa8/0x6c8
>  [<0000000000390004>] SyS_ioctl+0xa4/0xb8
>  [<00000000008c7a8c>] system_call+0xc4/0x27c
> no locks held by qemu-system-s39/79.
> 
> We have to reset the just created users_count back to 0 to
> tell the check to not trigger.
> 
> Reported-by: Stefan Haberland <sth@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Fixes: 3898da947bba ("KVM: avoid using rcu_dereference_protected")
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  virt/kvm/kvm_main.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 1b3fa3f..1205d20 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -716,6 +716,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
>  out_err_no_srcu:
>  	hardware_disable_all();
>  out_err_no_disable:
> +	refcount_set(&kvm->users_count, 0);
>  	for (i = 0; i < KVM_NR_BUSES; i++)
>  		kfree(kvm_get_bus(kvm, i));
>  	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++)
> 

Makes sense to me.

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David

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

* Re: [PATCH] KVM: fix rcu warning on VM_CREATE errors
  2017-09-13 12:17 [PATCH] KVM: fix rcu warning on VM_CREATE errors Christian Borntraeger
  2017-09-13 12:23 ` David Hildenbrand
@ 2017-09-13 15:40 ` Radim Krčmář
  1 sibling, 0 replies; 3+ messages in thread
From: Radim Krčmář @ 2017-09-13 15:40 UTC (permalink / raw)
  To: Christian Borntraeger; +Cc: Paolo Bonzini, KVM, Stefan Haberland

2017-09-13 14:17+0200, Christian Borntraeger:
> commit 3898da947bba ("KVM: avoid using rcu_dereference_protected") can
> trigger the following lockdep/rcu splat if the VM_CREATE ioctl fails,
> for example if kvm_arch_init_vm fails:
> 
> WARNING: suspicious RCU usage
> 4.13.0+ #105 Not tainted
> -----------------------------
> ./include/linux/kvm_host.h:481 suspicious rcu_dereference_check() usage!
> 
> other info that might help us debug this:
> 
> rcu_scheduler_active = 2, debug_locks = 1
> no locks held by qemu-system-s39/79.
> stack backtrace:
> CPU: 0 PID: 79 Comm: qemu-system-s39 Not tainted 4.13.0+ #105
> Hardware name: IBM 2964 NC9 704 (KVM/Linux)
> Call Trace:
> ([<00000000001140b2>] show_stack+0xea/0xf0)
>  [<00000000008a68a4>] dump_stack+0x94/0xd8
>  [<0000000000134c12>] kvm_dev_ioctl+0x372/0x7a0
>  [<000000000038f940>] do_vfs_ioctl+0xa8/0x6c8
>  [<0000000000390004>] SyS_ioctl+0xa4/0xb8
>  [<00000000008c7a8c>] system_call+0xc4/0x27c
> no locks held by qemu-system-s39/79.
> 
> We have to reset the just created users_count back to 0 to
> tell the check to not trigger.
> 
> Reported-by: Stefan Haberland <sth@linux.vnet.ibm.com>
> Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
> Fixes: 3898da947bba ("KVM: avoid using rcu_dereference_protected")
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---

Applied, thanks.

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

end of thread, other threads:[~2017-09-13 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-13 12:17 [PATCH] KVM: fix rcu warning on VM_CREATE errors Christian Borntraeger
2017-09-13 12:23 ` David Hildenbrand
2017-09-13 15:40 ` Radim Krčmář

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox