]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - arch/x86/platform/efi/efi_64.c
Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.git] / arch / x86 / platform / efi / efi_64.c
index 39c4b35ac7a4a9cc0d2b54cbc7b7ea58997da09f..d87ac96e37ede3ea93dabb67d99538fdadc03de0 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/ucs2_string.h>
+#include <linux/mem_encrypt.h>
 
 #include <asm/setup.h>
 #include <asm/page.h>
@@ -209,7 +210,7 @@ int __init efi_alloc_page_tables(void)
        if (efi_enabled(EFI_OLD_MEMMAP))
                return 0;
 
-       gfp_mask = GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO;
+       gfp_mask = GFP_KERNEL | __GFP_ZERO;
        efi_pgd = (pgd_t *)__get_free_pages(gfp_mask, PGD_ALLOCATION_ORDER);
        if (!efi_pgd)
                return -ENOMEM;
@@ -373,7 +374,11 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
         * as trim_bios_range() will reserve the first page and isolate it away
         * from memory allocators anyway.
         */
-       if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, _PAGE_RW)) {
+       pf = _PAGE_RW;
+       if (sev_active())
+               pf |= _PAGE_ENC;
+
+       if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) {
                pr_err("Failed to create 1:1 mapping for the first page!\n");
                return 1;
        }
@@ -416,6 +421,9 @@ static void __init __map_region(efi_memory_desc_t *md, u64 va)
        if (!(md->attribute & EFI_MEMORY_WB))
                flags |= _PAGE_PCD;
 
+       if (sev_active())
+               flags |= _PAGE_ENC;
+
        pfn = md->phys_addr >> PAGE_SHIFT;
        if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
                pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
@@ -542,6 +550,9 @@ static int __init efi_update_mem_attr(struct mm_struct *mm, efi_memory_desc_t *m
        if (!(md->attribute & EFI_MEMORY_RO))
                pf |= _PAGE_RW;
 
+       if (sev_active())
+               pf |= _PAGE_ENC;
+
        return efi_update_mappings(md, pf);
 }
 
@@ -593,6 +604,9 @@ void __init efi_runtime_update_mappings(void)
                        (md->type != EFI_RUNTIME_SERVICES_CODE))
                        pf |= _PAGE_RW;
 
+               if (sev_active())
+                       pf |= _PAGE_ENC;
+
                efi_update_mappings(md, pf);
        }
 }