From: Sean Christopherson <seanjc@google.com>
To: Peter Gonda <pgonda@google.com>
Cc: kvm@vger.kernel.org, John Sperbeck <jsperbeck@google.com>,
David Rientjes <rientjes@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] KVM: SEV: Mark nested locking of vcpu->mutex
Date: Wed, 6 Apr 2022 18:05:55 +0000 [thread overview]
Message-ID: <Yk3Wg3eZsGZKb3Wm@google.com> (raw)
In-Reply-To: <20220405174637.2074319-1-pgonda@google.com>
On Tue, Apr 05, 2022, Peter Gonda wrote:
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 75fa6dd268f0..673e1ee2cfc9 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -1591,14 +1591,21 @@ static void sev_unlock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
> atomic_set_release(&src_sev->migration_in_progress, 0);
> }
>
> +#define SEV_MIGRATION_SOURCE 0
> +#define SEV_MIGRATION_TARGET 1
>
> -static int sev_lock_vcpus_for_migration(struct kvm *kvm)
> +/*
> + * To avoid lockdep warnings callers should pass @vm argument with either
I think it's important to call that these are false positives, saying "avoid
lockdep warnings" suggests we're intentionally not fixing bugs :-)
> + * SEV_MIGRATION_SOURCE or SEV_MIGRATE_TARGET. This allows subclassing of all
> + * vCPU mutex locks.
> + */
If we use an enum, that'll make the param self-documenting. And we can also use
that to eliminate the remaining magic number '2'. E.g. this as fixup.
---
arch/x86/kvm/svm/sev.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 673e1ee2cfc9..1e07d5d3f85a 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -1591,21 +1591,27 @@ static void sev_unlock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm)
atomic_set_release(&src_sev->migration_in_progress, 0);
}
-#define SEV_MIGRATION_SOURCE 0
-#define SEV_MIGRATION_TARGET 1
/*
- * To avoid lockdep warnings callers should pass @vm argument with either
- * SEV_MIGRATION_SOURCE or SEV_MIGRATE_TARGET. This allows subclassing of all
- * vCPU mutex locks.
+ * To suppress lockdep false positives, subclass all vCPU mutex locks by
+ * assigning even numbers to the source vCPUs and odd numbers to destination
+ * vCPUs based on the vCPU's index.
*/
-static int sev_lock_vcpus_for_migration(struct kvm *kvm, int vm)
+enum sev_migration_role {
+ SEV_MIGRATION_SOURCE = 0,
+ SEV_MIGRATION_TARGET,
+ SEV_NR_MIGRATION_ROLES,
+};
+
+static int sev_lock_vcpus_for_migration(struct kvm *kvm,
+ enum sev_migration_role role)
{
struct kvm_vcpu *vcpu;
unsigned long i, j;
kvm_for_each_vcpu(i, vcpu, kvm) {
- if (mutex_lock_killable_nested(&vcpu->mutex, i * 2 + vm))
+ if (mutex_lock_killable_nested(&vcpu->mutex,
+ i * SEV_NR_MIGRATION_ROLES + role))
goto out_unlock;
}
base-commit: 6600ddafa53b35fd5c869aff4a5efb981ed06955
--
next prev parent reply other threads:[~2022-04-06 19:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 17:46 [PATCH v2] KVM: SEV: Mark nested locking of vcpu->mutex Peter Gonda
2022-04-06 18:05 ` Sean Christopherson [this message]
2022-04-07 19:59 ` Peter Gonda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yk3Wg3eZsGZKb3Wm@google.com \
--to=seanjc@google.com \
--cc=jsperbeck@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=pgonda@google.com \
--cc=rientjes@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.