Skip to content

Commit 072f58c

Browse files
tlendackyKAGA-KOKO
authored andcommitted
x86/mm: Use encrypted access of boot related data with SEV
When Secure Encrypted Virtualization (SEV) is active, boot data (such as EFI related data, setup data) is encrypted and needs to be accessed as such when mapped. Update the architecture override in early_memremap to keep the encryption attribute when mapping this data. 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: Laura Abbott <labbott@redhat.com> Cc: kvm@vger.kernel.org Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Borislav Petkov <bp@alien8.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Link: https://lkml.kernel.org/r/20171020143059.3291-6-brijesh.singh@amd.com
1 parent fcdcd6c commit 072f58c

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

arch/x86/mm/ioremap.c

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
422422
* areas should be mapped decrypted. And since the encryption key can
423423
* change across reboots, persistent memory should also be mapped
424424
* decrypted.
425+
*
426+
* If SEV is active, that implies that BIOS/UEFI also ran encrypted so
427+
* only persistent memory should be mapped decrypted.
425428
*/
426429
static bool memremap_should_map_decrypted(resource_size_t phys_addr,
427430
unsigned long size)
@@ -458,6 +461,11 @@ static bool memremap_should_map_decrypted(resource_size_t phys_addr,
458461
case E820_TYPE_ACPI:
459462
case E820_TYPE_NVS:
460463
case E820_TYPE_UNUSABLE:
464+
/* For SEV, these areas are encrypted */
465+
if (sev_active())
466+
break;
467+
/* Fallthrough */
468+
461469
case E820_TYPE_PRAM:
462470
return true;
463471
default:
@@ -581,7 +589,7 @@ static bool __init early_memremap_is_setup_data(resource_size_t phys_addr,
581589
bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
582590
unsigned long flags)
583591
{
584-
if (!sme_active())
592+
if (!mem_encrypt_active())
585593
return true;
586594

587595
if (flags & MEMREMAP_ENC)
@@ -590,12 +598,13 @@ bool arch_memremap_can_ram_remap(resource_size_t phys_addr, unsigned long size,
590598
if (flags & MEMREMAP_DEC)
591599
return false;
592600

593-
if (memremap_is_setup_data(phys_addr, size) ||
594-
memremap_is_efi_data(phys_addr, size) ||
595-
memremap_should_map_decrypted(phys_addr, size))
596-
return false;
601+
if (sme_active()) {
602+
if (memremap_is_setup_data(phys_addr, size) ||
603+
memremap_is_efi_data(phys_addr, size))
604+
return false;
605+
}
597606

598-
return true;
607+
return !memremap_should_map_decrypted(phys_addr, size);
599608
}
600609

601610
/*
@@ -608,17 +617,24 @@ pgprot_t __init early_memremap_pgprot_adjust(resource_size_t phys_addr,
608617
unsigned long size,
609618
pgprot_t prot)
610619
{
611-
if (!sme_active())
620+
bool encrypted_prot;
621+
622+
if (!mem_encrypt_active())
612623
return prot;
613624

614-
if (early_memremap_is_setup_data(phys_addr, size) ||
615-
memremap_is_efi_data(phys_addr, size) ||
616-
memremap_should_map_decrypted(phys_addr, size))
617-
prot = pgprot_decrypted(prot);
618-
else
619-
prot = pgprot_encrypted(prot);
625+
encrypted_prot = true;
626+
627+
if (sme_active()) {
628+
if (early_memremap_is_setup_data(phys_addr, size) ||
629+
memremap_is_efi_data(phys_addr, size))
630+
encrypted_prot = false;
631+
}
632+
633+
if (encrypted_prot && memremap_should_map_decrypted(phys_addr, size))
634+
encrypted_prot = false;
620635

621-
return prot;
636+
return encrypted_prot ? pgprot_encrypted(prot)
637+
: pgprot_decrypted(prot);
622638
}
623639

624640
bool phys_mem_access_encrypted(unsigned long phys_addr, unsigned long size)

0 commit comments

Comments
 (0)