Skip to content

Commit

Permalink
End the agony
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk committed Jan 24, 2025
1 parent 2ec229a commit b0bcb55
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
31 changes: 13 additions & 18 deletions grub-core/loader/multiboot_mbi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,6 @@ grub_multiboot2_perform_slaunch (grub_uint32_t mbi_target,
grub_uint32_t mbi_size)
{
grub_err_t err;
grub_relocator_chunk_t ch;
struct grub_slaunch_params *slparams = &grub_multiboot2_slparams;
struct grub_slr_entry_dl_info *dlinfo;
struct fill_policy_hook_data hook_data = {
Expand All @@ -1243,28 +1242,22 @@ grub_multiboot2_perform_slaunch (grub_uint32_t mbi_target,
slparams->fill_policy_hook = &fill_policy_hook;
slparams->fill_policy_hook_data = &hook_data;

if (grub_relocator_alloc_chunk_align (slparams->relocator, &ch, 0x1000000,
0xffffffff - GRUB_PAGE_SIZE,
GRUB_PAGE_SIZE, GRUB_PAGE_SIZE,
GRUB_RELOCATOR_PREFERENCE_NONE, 1))
return grub_error (grub_errno, N_("Failed to allocate SLRT"));

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 ("multiboot_loader",
"slr_table_base = %lx, slr_table_size = %x\n",
(unsigned long) slparams->slr_table_base,
(unsigned) slparams->slr_table_size);

if (slparams->platform_type == SLP_INTEL_TXT)
{
slparams->slr_table_base = GRUB_SLAUNCH_STORE_IN_OS2MLE;
slparams->slr_table_size = GRUB_PAGE_SIZE;

slparams->slr_table_mem = grub_zalloc (slparams->slr_table_size);
if (slparams->slr_table_mem == NULL)
return grub_error (grub_errno, N_("Failed to allocate SLRT"));

err = grub_txt_boot_prepare (slparams);
if (err != GRUB_ERR_NONE)
return grub_error (err, "TXT boot preparation failed");

grub_memcpy ((void *)(grub_addr_t) slparams->slr_table_base,
slparams->slr_table_mem,
slparams->slr_table_size);
}
else if (slparams->platform_type == SLP_AMD_SKINIT)
{
Expand All @@ -1285,6 +1278,8 @@ grub_multiboot2_perform_slaunch (grub_uint32_t mbi_target,
(unsigned) slparams->slr_table_size);

dlinfo = grub_slr_next_entry_by_tag (slparams->slr_table_mem, NULL, GRUB_SLR_ENTRY_DL_INFO);
if (dlinfo == NULL)
return grub_error (GRUB_ERR_BUG, N_("Failed to find DL-info SLRT entry"));
grub_dprintf ("slaunch", "slparams = %p\n", slparams);
grub_dprintf ("slaunch", "dlinfo = %p\n", dlinfo);
grub_dprintf ("slaunch", "dlinfo->bl_context.context = %p\n", dlinfo->bl_context.context);
Expand Down
26 changes: 13 additions & 13 deletions grub-core/loader/slaunch/txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,19 +590,19 @@ init_txt_heap (struct grub_slaunch_params *slparams, struct grub_txt_acm_header
size = (grub_uint64_t *) ((grub_addr_t) os_mle_data - sizeof (grub_uint64_t));
*size = sizeof (*os_mle_data) + sizeof (grub_uint64_t);

//if (slparams->slr_table_base == GRUB_SLAUNCH_STORE_IN_OS2MLE)
// {
// /* SLRT needs to be at least 4-byte aligned per specification. */
// slparams->slr_table_base =
// ALIGN_UP ((grub_addr_t) os_mle_data + sizeof (*os_mle_data), 4);

// /* Recompute size including SLRT table in it. */
// *size = (slparams->slr_table_base + slparams->slr_table_size)
// - ((grub_addr_t) os_mle_data - sizeof (grub_uint64_t));

// /* Size of heap sections should be a multiple of 8. */
// *size = ALIGN_UP (*size, 8);
// }
if (slparams->slr_table_base == GRUB_SLAUNCH_STORE_IN_OS2MLE)
{
/* SLRT needs to be at least 4-byte aligned per specification. */
slparams->slr_table_base =
ALIGN_UP ((grub_addr_t) os_mle_data + sizeof (*os_mle_data), 4);

/* Recompute size including SLRT table in it. */
*size = (slparams->slr_table_base + slparams->slr_table_size)
- ((grub_addr_t) os_mle_data - sizeof (grub_uint64_t));

/* Size of heap sections should be a multiple of 8. */
*size = ALIGN_UP (*size, 8);
}

grub_memset (os_mle_data, 0, sizeof (*os_mle_data));

Expand Down
13 changes: 13 additions & 0 deletions include/grub/slaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@

#define GRUB_SLAUNCH_TPM_EVT_LOG_SIZE (8 * GRUB_PAGE_SIZE)

/*
* Special value for slr_table_base of struct grub_slaunch_params that indicates
* that the table should be stored near OS2MLE data (right after it).
*
* In this case:
* 1. Platform-specific code (e.g., TXT-code) is responsible for setting
* slr_table_base to its final value
* 2. SLRT should be copied from slr_table_mem to slr_table_base after invoking
* grub_slaunch_finish_slr_table () by the code which used this special
* value.
*/
#define GRUB_SLAUNCH_STORE_IN_OS2MLE ((grub_uint64_t) 0xFFFFFFFFFFFFFFFF)

#ifndef ASM_FILE

#define GRUB_SL_BOOT_TYPE_INVALID 0
Expand Down

0 comments on commit b0bcb55

Please sign in to comment.