]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
KVM: SVM: Free sev_asid_bitmap during init if SEV setup fails
authorSean Christopherson <seanjc@google.com>
Thu, 22 Apr 2021 02:11:12 +0000 (19:11 -0700)
committerKelsey Skunberg <kelsey.skunberg@canonical.com>
Mon, 24 May 2021 23:46:43 +0000 (17:46 -0600)
BugLink: https://bugs.launchpad.net/bugs/1929455
[ Upstream commit f31b88b35f90f6b7ae4abc1015494a285f459221 ]

Free sev_asid_bitmap if the reclaim bitmap allocation fails, othwerise
KVM will unnecessarily keep the bitmap when SEV is not fully enabled.

Freeing the page is also necessary to avoid introducing a bug when a
future patch eliminates svm_sev_enabled() in favor of using the global
'sev' flag directly.  While sev_hardware_enabled() checks max_sev_asid,
which is true even if KVM setup fails, 'sev' will be true if and only
if KVM setup fully succeeds.

Fixes: 33af3a7ef9e6 ("KVM: SVM: Reduce WBINVD/DF_FLUSH invocations")
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210422021125.3417167-3-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kelsey Skunberg <kelsey.skunberg@canonical.com>
arch/x86/kvm/svm/sev.c

index 80c49a5e593aded71bd7f5ade3ccb60e5d8f0f37..7c233c79c124d731f88cf6880c07186370c5b8e4 100644 (file)
@@ -1276,8 +1276,11 @@ void __init sev_hardware_setup(void)
                goto out;
 
        sev_reclaim_asid_bitmap = bitmap_zalloc(max_sev_asid, GFP_KERNEL);
-       if (!sev_reclaim_asid_bitmap)
+       if (!sev_reclaim_asid_bitmap) {
+               bitmap_free(sev_asid_bitmap);
+               sev_asid_bitmap = NULL;
                goto out;
+       }
 
        pr_info("SEV supported: %u ASIDs\n", max_sev_asid - min_sev_asid + 1);
        sev_supported = true;