From 0e50e712c2e1c197cc39d835c431b2907bb4cd32 Mon Sep 17 00:00:00 2001 From: Ross Philipson Date: Wed, 17 Aug 2022 17:47:54 +0200 Subject: [PATCH] i386/linux: Add support for AMD SKINIT Signed-off-by: Ross Philipson Signed-off-by: Daniel Kiper Signed-off-by: Sergii Dmytruk --- grub-core/loader/i386/linux.c | 57 ++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 7c7df7b09..21668fde1 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -250,7 +251,7 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, prot_mode_mem = get_virtual_current_address (ch); prot_mode_target = get_physical_target_address (ch); - if (grub_slaunch_platform_type () == SLP_INTEL_TXT) + if (grub_slaunch_platform_type () != SLP_NONE) { /* Zero out memory to get stable MLE measurements. */ grub_memset (prot_mode_mem, 0, total_size); @@ -269,22 +270,29 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, slparams->mle_ptab_mem, (unsigned long) slparams->mle_ptab_target, (unsigned) slparams->mle_ptab_size); - err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, - 0xffffffff - GRUB_PAGE_SIZE, - GRUB_PAGE_SIZE, GRUB_PAGE_SIZE, - GRUB_RELOCATOR_PREFERENCE_NONE, 1); - if (err) - goto fail; - - slparams->slr_table_base = get_physical_target_address (ch); - slparams->slr_table_size = GRUB_PAGE_SIZE; - slparams->slr_table_mem = get_virtual_current_address (ch); - - grub_memset (slparams->slr_table_mem, 0, slparams->slr_table_size); - - grub_dprintf ("linux", "slr_table_base = %lx, slr_table_size = %x\n", - (unsigned long) slparams->slr_table_base, - (unsigned) slparams->slr_table_size); + /* + * For AMD SKINIT, SLRT is part of SLB and it will be initialized by + * grub_skinit_boot_prepare(). + */ + if (grub_slaunch_platform_type () == SLP_INTEL_TXT) + { + err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, + 0xffffffff - GRUB_PAGE_SIZE, + GRUB_PAGE_SIZE, GRUB_PAGE_SIZE, + GRUB_RELOCATOR_PREFERENCE_NONE, 1); + if (err) + goto fail; + + slparams->slr_table_base = get_physical_target_address (ch); + slparams->slr_table_size = GRUB_PAGE_SIZE; + slparams->slr_table_mem = get_virtual_current_address (ch); + + grub_memset (slparams->slr_table_mem, 0, slparams->slr_table_size); + + grub_dprintf ("linux", "slr_table_base = %lx, slr_table_size = %x\n", + (unsigned long) slparams->slr_table_base, + (unsigned) slparams->slr_table_size); + } err = grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, 0xffffffff - GRUB_SLAUNCH_TPM_EVT_LOG_SIZE, @@ -837,6 +845,21 @@ grub_linux_boot (void) state.ecx = slparams->dce_size; state.edx = 0; } + else if (state.edi == SLP_AMD_SKINIT) + { + slparams->boot_params_addr = ctx.real_mode_target; + + err = grub_skinit_boot_prepare (relocator, slparams); + + if (err != GRUB_ERR_NONE) + return grub_error (err, "SKINIT preparations have failed"); + + grub_slaunch_add_slrt_policy_entries (); + grub_linux_setup_slr_table (slparams); + grub_slaunch_finish_slr_table (); + + state.eax = slparams->dce_base; + } else { /* FIXME. */