]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: SVM: Set the encryption mask for the SVM host save area
authorTom Lendacky <thomas.lendacky@amd.com>
Thu, 10 Dec 2020 17:10:04 +0000 (11:10 -0600)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 15 Dec 2020 10:20:57 +0000 (05:20 -0500)
The SVM host save area is used to restore some host state on VMEXIT of an
SEV-ES guest. After allocating the save area, clear it and add the
encryption mask to the SVM host save area physical address that is
programmed into the VM_HSAVE_PA MSR.

Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <b77aa28af6d7f1a0cb545959e08d6dc75e0c3cba.1607620209.git.thomas.lendacky@amd.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/sev.c
arch/x86/kvm/svm/svm.c
arch/x86/kvm/svm/svm.h

index c3006e9ef5ae751ebd5d0aee38d39b7ca4e47dd8..0e922741023bc9fbaeff6123eec39cf890e32f92 100644 (file)
@@ -30,7 +30,6 @@ unsigned int max_sev_asid;
 static unsigned int min_sev_asid;
 static unsigned long *sev_asid_bitmap;
 static unsigned long *sev_reclaim_asid_bitmap;
-#define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT)
 
 struct enc_region {
        struct list_head list;
index 2e43f79c27030f64e52a2d3a7e0f792fb9b7b06b..4be7d13d4462b66194fd0a55f4a6143fc843b2d0 100644 (file)
@@ -497,7 +497,7 @@ static int svm_hardware_enable(void)
 
        wrmsrl(MSR_EFER, efer | EFER_SVME);
 
-       wrmsrl(MSR_VM_HSAVE_PA, page_to_pfn(sd->save_area) << PAGE_SHIFT);
+       wrmsrl(MSR_VM_HSAVE_PA, __sme_page_pa(sd->save_area));
 
        if (static_cpu_has(X86_FEATURE_TSCRATEMSR)) {
                wrmsrl(MSR_AMD64_TSC_RATIO, TSC_RATIO_DEFAULT);
@@ -565,6 +565,7 @@ static int svm_cpu_init(int cpu)
        sd->save_area = alloc_page(GFP_KERNEL);
        if (!sd->save_area)
                goto free_cpu_data;
+       clear_page(page_address(sd->save_area));
 
        if (svm_sev_enabled()) {
                sd->sev_vmcbs = kmalloc_array(max_sev_asid + 1,
index b3f03dede6ac1fce3f444bdfd9fcdcc39818b02e..b85c162a8a1e78bb7adad7e55a08157830fcdb66 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <asm/svm.h>
 
+#define __sme_page_pa(x) __sme_set(page_to_pfn(x) << PAGE_SHIFT)
+
 static const u32 host_save_user_msrs[] = {
 #ifdef CONFIG_X86_64
        MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, MSR_KERNEL_GS_BASE,