]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: SVM: Allocate IOPM pages after initial setup in svm_hardware_setup()
authorSean Christopherson <seanjc@google.com>
Tue, 10 Jun 2025 22:57:07 +0000 (15:57 -0700)
committerSean Christopherson <seanjc@google.com>
Fri, 20 Jun 2025 20:05:39 +0000 (13:05 -0700)
Allocate pages for the IOPM after initial setup has been completed in
svm_hardware_setup(), so that sanity checks can be added in the setup flow
without needing to free the IOPM pages.  The IOPM is only referenced (via
iopm_base) in init_vmcb() and svm_hardware_unsetup(), so there's no need
to allocate it early on.

No functional change intended (beyond the obvious ordering differences,
e.g. if the allocation fails).

Link: https://lore.kernel.org/r/20250610225737.156318-3-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c

index 9c6ec5e8814110b87fb5abccec28add0151787c7..6ce35f01d410e51a5c92be983fb61e46b2ca26bd 100644 (file)
@@ -5494,15 +5494,6 @@ static __init int svm_hardware_setup(void)
        }
        kvm_enable_efer_bits(EFER_NX);
 
-       iopm_pages = alloc_pages(GFP_KERNEL, order);
-
-       if (!iopm_pages)
-               return -ENOMEM;
-
-       iopm_va = page_address(iopm_pages);
-       memset(iopm_va, 0xff, PAGE_SIZE * (1 << order));
-       iopm_base = __sme_page_pa(iopm_pages);
-
        init_msrpm_offsets();
 
        kvm_caps.supported_xcr0 &= ~(XFEATURE_MASK_BNDREGS |
@@ -5569,6 +5560,15 @@ static __init int svm_hardware_setup(void)
                else
                        pr_info("LBR virtualization supported\n");
        }
+
+       iopm_pages = alloc_pages(GFP_KERNEL, order);
+       if (!iopm_pages)
+               return -ENOMEM;
+
+       iopm_va = page_address(iopm_pages);
+       memset(iopm_va, 0xff, PAGE_SIZE * (1 << order));
+       iopm_base = __sme_page_pa(iopm_pages);
+
        /*
         * Note, SEV setup consumes npt_enabled and enable_mmio_caching (which
         * may be modified by svm_adjust_mmio_mask()), as well as nrips.