Skip to content

Commit 1379edd

Browse files
tlendackyKAGA-KOKO
authored andcommitted
x86/efi: Access EFI data as encrypted when SEV is active
EFI data is encrypted when the kernel is run under SEV. Update the page table references to be sure the EFI memory areas are accessed encrypted. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Borislav Petkov <bp@suse.de> Tested-by: Borislav Petkov <bp@suse.de> Cc: linux-efi@vger.kernel.org Cc: kvm@vger.kernel.org Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Borislav Petkov <bp@alien8.de> Cc: Andy Lutomirski <luto@kernel.org> Link: https://lkml.kernel.org/r/20171020143059.3291-8-brijesh.singh@amd.com
1 parent a72ec5a commit 1379edd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

arch/x86/platform/efi/efi_64.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/reboot.h>
3434
#include <linux/slab.h>
3535
#include <linux/ucs2_string.h>
36+
#include <linux/mem_encrypt.h>
3637

3738
#include <asm/setup.h>
3839
#include <asm/page.h>
@@ -370,7 +371,11 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
370371
* as trim_bios_range() will reserve the first page and isolate it away
371372
* from memory allocators anyway.
372373
*/
373-
if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, _PAGE_RW)) {
374+
pf = _PAGE_RW;
375+
if (sev_active())
376+
pf |= _PAGE_ENC;
377+
378+
if (kernel_map_pages_in_pgd(pgd, 0x0, 0x0, 1, pf)) {
374379
pr_err("Failed to create 1:1 mapping for the first page!\n");
375380
return 1;
376381
}
@@ -413,6 +418,9 @@ static void __init __map_region(efi_memory_desc_t *md, u64 va)
413418
if (!(md->attribute & EFI_MEMORY_WB))
414419
flags |= _PAGE_PCD;
415420

421+
if (sev_active())
422+
flags |= _PAGE_ENC;
423+
416424
pfn = md->phys_addr >> PAGE_SHIFT;
417425
if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
418426
pr_warn("Error mapping PA 0x%llx -> VA 0x%llx!\n",
@@ -539,6 +547,9 @@ static int __init efi_update_mem_attr(struct mm_struct *mm, efi_memory_desc_t *m
539547
if (!(md->attribute & EFI_MEMORY_RO))
540548
pf |= _PAGE_RW;
541549

550+
if (sev_active())
551+
pf |= _PAGE_ENC;
552+
542553
return efi_update_mappings(md, pf);
543554
}
544555

@@ -590,6 +601,9 @@ void __init efi_runtime_update_mappings(void)
590601
(md->type != EFI_RUNTIME_SERVICES_CODE))
591602
pf |= _PAGE_RW;
592603

604+
if (sev_active())
605+
pf |= _PAGE_ENC;
606+
593607
efi_update_mappings(md, pf);
594608
}
595609
}

0 commit comments

Comments
 (0)