Skip to content

Commit 38eeccc

Browse files
tlendackyIngo Molnar
authored andcommitted
x86/efi: Update EFI pagetable creation to work with SME
When SME is active, pagetable entries created for EFI need to have the encryption mask set as necessary. When the new pagetable pages are allocated they are mapped encrypted. So, update the efi_pgt value that will be used in CR3 to include the encryption mask so that the PGD table can be read successfully. The pagetable mapping as well as the kernel are also added to the pagetable mapping as encrypted. All other EFI mappings are mapped decrypted (tables, etc.). Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Matt Fleming <matt@codeblueprint.co.uk> Reviewed-by: Borislav Petkov <bp@suse.de> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Brijesh Singh <brijesh.singh@amd.com> Cc: Dave Young <dyoung@redhat.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Larry Woodman <lwoodman@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael S. Tsirkin <mst@redhat.com> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Radim Krčmář <rkrcmar@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Toshimitsu Kani <toshi.kani@hpe.com> Cc: kasan-dev@googlegroups.com Cc: kvm@vger.kernel.org Cc: linux-arch@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-efi@vger.kernel.org Cc: linux-mm@kvack.org Link: http://lkml.kernel.org/r/9a8f4c502db4a84b09e2f0a1555bb75aa8b69785.1500319216.git.thomas.lendacky@amd.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent f99afd0 commit 38eeccc

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

arch/x86/platform/efi/efi_64.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,20 @@ virt_to_phys_or_null_size(void *va, unsigned long size)
327327

328328
int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
329329
{
330-
unsigned long pfn, text;
330+
unsigned long pfn, text, pf;
331331
struct page *page;
332332
unsigned npages;
333333
pgd_t *pgd;
334334

335335
if (efi_enabled(EFI_OLD_MEMMAP))
336336
return 0;
337337

338-
efi_scratch.efi_pgt = (pgd_t *)__pa(efi_pgd);
338+
/*
339+
* Since the PGD is encrypted, set the encryption mask so that when
340+
* this value is loaded into cr3 the PGD will be decrypted during
341+
* the pagetable walk.
342+
*/
343+
efi_scratch.efi_pgt = (pgd_t *)__sme_pa(efi_pgd);
339344
pgd = efi_pgd;
340345

341346
/*
@@ -345,7 +350,8 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
345350
* phys_efi_set_virtual_address_map().
346351
*/
347352
pfn = pa_memmap >> PAGE_SHIFT;
348-
if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, _PAGE_NX | _PAGE_RW)) {
353+
pf = _PAGE_NX | _PAGE_RW | _PAGE_ENC;
354+
if (kernel_map_pages_in_pgd(pgd, pfn, pa_memmap, num_pages, pf)) {
349355
pr_err("Error ident-mapping new memmap (0x%lx)!\n", pa_memmap);
350356
return 1;
351357
}
@@ -388,7 +394,8 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
388394
text = __pa(_text);
389395
pfn = text >> PAGE_SHIFT;
390396

391-
if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, _PAGE_RW)) {
397+
pf = _PAGE_RW | _PAGE_ENC;
398+
if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) {
392399
pr_err("Failed to map kernel text 1:1\n");
393400
return 1;
394401
}

0 commit comments

Comments
 (0)