2022-01-05 06:42:02

by Wanpeng Li

[permalink] [raw]
Subject: [PATCH] KVM: SEV: Add lock subtyping in sev_lock_two_vms so lockdep doesn't report false dependencies

From: Wanpeng Li <[email protected]>

Both source and dest vms' kvm->locks are held in sev_lock_two_vms,
we should mark one with different subtype to avoid false positives
from lockdep.

Fixes: c9d61dcb0bc26 (KVM: SEV: accept signals in sev_lock_two_vms)
Reported-by: Yiru Xu <[email protected]>
Tested-by: Jinrong Liang <[email protected]>
Signed-off-by: Wanpeng Li <[email protected]>
---
arch/x86/kvm/svm/sev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 7656a2c..be28831 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -1565,7 +1565,7 @@ static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
r = -EINTR;
if (mutex_lock_killable(&dst_kvm->lock))
goto release_src;
- if (mutex_lock_killable(&src_kvm->lock))
+ if (mutex_lock_killable_nested(&src_kvm->lock, SINGLE_DEPTH_NESTING))
goto unlock_dst;
return 0;

--
2.7.4



2022-01-07 17:01:22

by Paolo Bonzini

[permalink] [raw]
Subject: Re: [PATCH] KVM: SEV: Add lock subtyping in sev_lock_two_vms so lockdep doesn't report false dependencies

On 1/5/22 07:41, Wanpeng Li wrote:
> From: Wanpeng Li <[email protected]>
>
> Both source and dest vms' kvm->locks are held in sev_lock_two_vms,
> we should mark one with different subtype to avoid false positives
> from lockdep.
>
> Fixes: c9d61dcb0bc26 (KVM: SEV: accept signals in sev_lock_two_vms)
> Reported-by: Yiru Xu <[email protected]>
> Tested-by: Jinrong Liang <[email protected]>
> Signed-off-by: Wanpeng Li <[email protected]>
> ---
> arch/x86/kvm/svm/sev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 7656a2c..be28831 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -1565,7 +1565,7 @@ static int sev_lock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
> r = -EINTR;
> if (mutex_lock_killable(&dst_kvm->lock))
> goto release_src;
> - if (mutex_lock_killable(&src_kvm->lock))
> + if (mutex_lock_killable_nested(&src_kvm->lock, SINGLE_DEPTH_NESTING))
> goto unlock_dst;
> return 0;
>

Queued, thanks.

Paolo