public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: Fix lockdep false negative during host resume
@ 2022-02-15 10:15 Wanpeng Li
  2022-02-15 16:26 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Wanpeng Li @ 2022-02-15 10:15 UTC (permalink / raw)
  To: linux-kernel, kvm
  Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

From: Wanpeng Li <wanpengli@tencent.com>

I saw the below splatting after the host suspended and resumed.

   WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm]
   CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G        W IOE     5.17.0-rc3+ #4
   RIP: 0010:kvm_resume+0x2c/0x30 [kvm]
   Call Trace:
    <TASK>
    syscore_resume+0x90/0x340
    suspend_devices_and_enter+0xaee/0xe90
    pm_suspend.cold+0x36b/0x3c2
    state_store+0x82/0xf0
    kernfs_fop_write_iter+0x1b6/0x260
    new_sync_write+0x258/0x370
    vfs_write+0x33f/0x510
    ksys_write+0xc9/0x160
    do_syscall_64+0x3b/0xc0
    entry_SYSCALL_64_after_hwframe+0x44/0xae

lockdep_is_held() can return -1 when lockdep is disabled which triggers
this warning. Let's use lockdep_assert_not_held() which can detect 
incorrect calls while holding a lock and it also avoids false negatives
when lockdep is disabled.

Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 83c57bcc6eb6..3f861f33bfe0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5528,7 +5528,7 @@ static void kvm_resume(void)
 {
 	if (kvm_usage_count) {
 #ifdef CONFIG_LOCKDEP
-		WARN_ON(lockdep_is_held(&kvm_count_lock));
+		lockdep_assert_not_held(&kvm_count_lock);
 #endif
 		hardware_enable_nolock(NULL);
 	}
-- 
2.25.1


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

* Re: [PATCH] KVM: Fix lockdep false negative during host resume
  2022-02-15 10:15 [PATCH] KVM: Fix lockdep false negative during host resume Wanpeng Li
@ 2022-02-15 16:26 ` Sean Christopherson
  2022-02-15 17:34   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2022-02-15 16:26 UTC (permalink / raw)
  To: Wanpeng Li
  Cc: linux-kernel, kvm, Paolo Bonzini, Vitaly Kuznetsov, Wanpeng Li,
	Jim Mattson, Joerg Roedel

On Tue, Feb 15, 2022, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
> 
> I saw the below splatting after the host suspended and resumed.
> 
>    WARNING: CPU: 0 PID: 2943 at kvm/arch/x86/kvm/../../../virt/kvm/kvm_main.c:5531 kvm_resume+0x2c/0x30 [kvm]
>    CPU: 0 PID: 2943 Comm: step_after_susp Tainted: G        W IOE     5.17.0-rc3+ #4
>    RIP: 0010:kvm_resume+0x2c/0x30 [kvm]
>    Call Trace:
>     <TASK>
>     syscore_resume+0x90/0x340
>     suspend_devices_and_enter+0xaee/0xe90
>     pm_suspend.cold+0x36b/0x3c2
>     state_store+0x82/0xf0
>     kernfs_fop_write_iter+0x1b6/0x260
>     new_sync_write+0x258/0x370
>     vfs_write+0x33f/0x510
>     ksys_write+0xc9/0x160
>     do_syscall_64+0x3b/0xc0
>     entry_SYSCALL_64_after_hwframe+0x44/0xae
> 
> lockdep_is_held() can return -1 when lockdep is disabled which triggers
> this warning. Let's use lockdep_assert_not_held() which can detect 
> incorrect calls while holding a lock and it also avoids false negatives
> when lockdep is disabled.
> 

Fixes: 2eb06c306a57 ("KVM: Fix spinlock taken warning during host resume")

> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 83c57bcc6eb6..3f861f33bfe0 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -5528,7 +5528,7 @@ static void kvm_resume(void)
>  {
>  	if (kvm_usage_count) {
>  #ifdef CONFIG_LOCKDEP

The #ifdef can be dropped, it was added only to omit the WARN_ON.

With that,

Reviewed-by: Sean Christopherson <seanjc@google.com>

> -		WARN_ON(lockdep_is_held(&kvm_count_lock));
> +		lockdep_assert_not_held(&kvm_count_lock);
>  #endif
>  		hardware_enable_nolock(NULL);
>  	}
> -- 
> 2.25.1
> 

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

* Re: [PATCH] KVM: Fix lockdep false negative during host resume
  2022-02-15 16:26 ` Sean Christopherson
@ 2022-02-15 17:34   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-02-15 17:34 UTC (permalink / raw)
  To: Sean Christopherson, Wanpeng Li
  Cc: linux-kernel, kvm, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel

On 2/15/22 17:26, Sean Christopherson wrote:
> Reviewed-by: Sean Christopherson<seanjc@google.com>

Queued with the #ifdef removed, thanks.

Paolo


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

end of thread, other threads:[~2022-02-15 17:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-15 10:15 [PATCH] KVM: Fix lockdep false negative during host resume Wanpeng Li
2022-02-15 16:26 ` Sean Christopherson
2022-02-15 17:34   ` Paolo Bonzini

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