|
33 | 33 | #include <linux/reboot.h>
|
34 | 34 | #include <linux/slab.h>
|
35 | 35 | #include <linux/ucs2_string.h>
|
| 36 | +#include <linux/mem_encrypt.h> |
36 | 37 |
|
37 | 38 | #include <asm/setup.h>
|
38 | 39 | #include <asm/page.h>
|
@@ -370,7 +371,11 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
|
370 | 371 | * as trim_bios_range() will reserve the first page and isolate it away
|
371 | 372 | * from memory allocators anyway.
|
372 | 373 | */
|
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)) { |
374 | 379 | pr_err("Failed to create 1:1 mapping for the first page!\n");
|
375 | 380 | return 1;
|
376 | 381 | }
|
@@ -413,6 +418,9 @@ static void __init __map_region(efi_memory_desc_t *md, u64 va)
|
413 | 418 | if (!(md->attribute & EFI_MEMORY_WB))
|
414 | 419 | flags |= _PAGE_PCD;
|
415 | 420 |
|
| 421 | + if (sev_active()) |
| 422 | + flags |= _PAGE_ENC; |
| 423 | + |
416 | 424 | pfn = md->phys_addr >> PAGE_SHIFT;
|
417 | 425 | if (kernel_map_pages_in_pgd(pgd, pfn, va, md->num_pages, flags))
|
418 | 426 | 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
|
539 | 547 | if (!(md->attribute & EFI_MEMORY_RO))
|
540 | 548 | pf |= _PAGE_RW;
|
541 | 549 |
|
| 550 | + if (sev_active()) |
| 551 | + pf |= _PAGE_ENC; |
| 552 | + |
542 | 553 | return efi_update_mappings(md, pf);
|
543 | 554 | }
|
544 | 555 |
|
@@ -590,6 +601,9 @@ void __init efi_runtime_update_mappings(void)
|
590 | 601 | (md->type != EFI_RUNTIME_SERVICES_CODE))
|
591 | 602 | pf |= _PAGE_RW;
|
592 | 603 |
|
| 604 | + if (sev_active()) |
| 605 | + pf |= _PAGE_ENC; |
| 606 | + |
593 | 607 | efi_update_mappings(md, pf);
|
594 | 608 | }
|
595 | 609 | }
|
|
0 commit comments