From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEA50C47087 for ; Mon, 4 Apr 2022 21:23:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381744AbiDDVX5 (ORCPT ); Mon, 4 Apr 2022 17:23:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380365AbiDDTsF (ORCPT ); Mon, 4 Apr 2022 15:48:05 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C7830F6A for ; Mon, 4 Apr 2022 12:46:08 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id g145-20020a625297000000b004fb2cf9d380so6483618pfb.22 for ; Mon, 04 Apr 2022 12:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=pT/6Qdmm3tGb7HLrr7GqjKevauNrm0C8oEo/kdSI0ug=; b=DX180veywuwX26kBGb4IS3QvBU35h9XvsRIASvum61dFNYnZS7OLefgyf3qPP6lGa4 XxRYSgT9bKas8WCz2qeYHpQgwwHAvjjwMV/0RkSxZZDuGBbLyCWfeG2wsJNDLl8Q0mOw xnWozmkr/vUAQX1nIDMRbYoIXIDdxhBtPqaE9y91l1qaKqWp1k6cIXnK5YT738jdyKGv TNpopmpt42kRQfuoCfxV7Az+dss4alEDWfSv07wkZcFASxV4k0ByUOxrNcpLR3mf35hi Y8DfkY9vRnLwM9bVRvbJih55QTFyzYqcAKzs2z4cuYO+exrc0fD59Y/+lIajydhE/0vH 2PwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=pT/6Qdmm3tGb7HLrr7GqjKevauNrm0C8oEo/kdSI0ug=; b=x8KuJ0mvYdksFP9/LwR9OfQArhXVzGkJcBzyyBDwIYXmG9SbPzNWMAyHQerf/XfxhZ whRbQvQd4LdH69VpxpldoMbgWPakvRyqr7yp9xxae9C6fMCdO//bS+6kIwJ6AeuHqPNH 3cteeWbIW2EZKlFAm+La6K4FN2LcdH1oqllEUsc0sEWNEDsObMivALo97L1NuV6lmVvZ LDI1jDGzCWGPbxOMoQwTfIB1SDmqD+MhoOIUXUmY/zWpU43DXYPn4gLSi9YgcbM9wTbW jOXBq/LBVGuuXNmxAKtBBZZTreKNTWxu6Ep7ZrCUwFWFsspTgrVl5Gx8eDqyJV2MlQkP fz2w== X-Gm-Message-State: AOAM533oP19T7nxGKRAx61OYYo2VlrV5qn9c19inVjDT6UWLpdTX6hnC 3YgFOIzIeDQKu6uABBkXVo8iVZZzPdw= X-Google-Smtp-Source: ABdhPJwfcqk6KaaBz0Oi+OSkD69vCvSBFe18Kal7m0AgXBWa7DktPfr3Jda+1wNf7qEamm9U33+gjllt6Hs= X-Received: from pgonda1.kir.corp.google.com ([2620:15c:29:203:805:a056:1a51:2b9e]) (user=pgonda job=sendgmr) by 2002:a17:902:f54c:b0:154:6794:ab18 with SMTP id h12-20020a170902f54c00b001546794ab18mr1280283plf.118.1649101568063; Mon, 04 Apr 2022 12:46:08 -0700 (PDT) Date: Mon, 4 Apr 2022 12:46:05 -0700 Message-Id: <20220404194605.1569855-1-pgonda@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1094.g7c7d902a7c-goog Subject: [PATCH] KVM: SEV: Mark nested locking of vcpu->lock From: Peter Gonda To: kvm@vger.kernel.org Cc: Peter Gonda , John Sperbeck , David Rientjes , Paolo Bonzini , Sean Christopherson , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org svm_vm_migrate_from() uses sev_lock_vcpus_for_migration() to lock all source and target vcpu->locks. Mark the nested subclasses to avoid false positives from lockdep. Fixes: b56639318bb2b ("KVM: SEV: Add support for SEV intra host migration") Reported-by: John Sperbeck Suggested-by: David Rientjes Signed-off-by: Peter Gonda Cc: Paolo Bonzini Cc: Sean Christopherson Cc: kvm@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- Tested by running sev_migrate_tests with lockdep enabled. Before we see a warning from sev_lock_vcpus_for_migration(). After we get no warnings. --- arch/x86/kvm/svm/sev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 75fa6dd268f0..8f77421c1c4b 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1591,15 +1591,16 @@ static void sev_unlock_two_vms(struct kvm *dst_kvm, struct kvm *src_kvm) atomic_set_release(&src_sev->migration_in_progress, 0); } - -static int sev_lock_vcpus_for_migration(struct kvm *kvm) +static int sev_lock_vcpus_for_migration(struct kvm *kvm, unsigned int *subclass) { struct kvm_vcpu *vcpu; unsigned long i, j; kvm_for_each_vcpu(i, vcpu, kvm) { - if (mutex_lock_killable(&vcpu->mutex)) + if (mutex_lock_killable_nested(&vcpu->mutex, *subclass)) goto out_unlock; + + ++(*subclass); } return 0; @@ -1717,6 +1718,7 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd) struct kvm *source_kvm; bool charged = false; int ret; + unsigned int vcpu_mutex_subclass = 0; source_kvm_file = fget(source_fd); if (!file_is_kvm(source_kvm_file)) { @@ -1745,10 +1747,10 @@ int sev_vm_move_enc_context_from(struct kvm *kvm, unsigned int source_fd) charged = true; } - ret = sev_lock_vcpus_for_migration(kvm); + ret = sev_lock_vcpus_for_migration(kvm, &vcpu_mutex_subclass); if (ret) goto out_dst_cgroup; - ret = sev_lock_vcpus_for_migration(source_kvm); + ret = sev_lock_vcpus_for_migration(source_kvm, &vcpu_mutex_subclass); if (ret) goto out_dst_vcpu; -- 2.35.1.1094.g7c7d902a7c-goog