Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes/fixes on top of v11 AMD patches for non-PSP case #26

Draft
wants to merge 26 commits into
base: grub-sl-2.12-v11-amd
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6c173bd
loader/slaunch/psp.c: don't cause use of __udivmoddi4()
SergiiDmytruk Nov 11, 2024
c9ffe3f
grub-core: fix non-EFI build
SergiiDmytruk Nov 10, 2024
682497d
grub-core/loader/slaunch/psp.c: fix rounding up after division
SergiiDmytruk Nov 29, 2024
8147876
loader: fix pointer <-> integer conversions
SergiiDmytruk Nov 10, 2024
025f421
loader/slaunch: fix invalid format specifiers
SergiiDmytruk Nov 10, 2024
8b80806
loader/slaunch/txt.c: FIXME cleanup
SergiiDmytruk Nov 19, 2024
e69ea65
i386/txt: Initialize TPM 1.2 event log in TXT heap
miczyg1 Aug 31, 2022
0231aa9
loader/slaunch: make SKINIT work on AMD without PSP
SergiiDmytruk Nov 10, 2024
561f864
loader/slaunch: {SKL,SLB}_MIN_A{,L}IGNMENT
SergiiDmytruk Nov 10, 2024
3fbbb79
loader/slaunch/skl.c: fix allocating SKL and placing SLRT
SergiiDmytruk Nov 10, 2024
81876ee
loader/slaunch: fix reading mle_header
SergiiDmytruk Nov 10, 2024
b883adc
loader/slaunch: allow multiple "slaunch_module" commands
SergiiDmytruk Nov 10, 2024
8a69289
loader/slaunch/skl.c: improve grub_skl_set_module() checks
SergiiDmytruk Nov 10, 2024
4d853d2
loader/slaunch/dlstub.c: better checks/errors
SergiiDmytruk Nov 18, 2024
d4b61e3
loader/slaunch/dlstub.c: start with zeroed relocator state
SergiiDmytruk Nov 19, 2024
b64de8b
loader/slaunch/skl.c: better errors and checks
SergiiDmytruk Nov 19, 2024
5fc2a42
include/grub/i386/txt.h: add missing #include
SergiiDmytruk Nov 19, 2024
54100f5
loader/slaunch/slrt.c: add NULL checks
SergiiDmytruk Nov 19, 2024
d92ba09
include/grub/slaunch.h: add missing forward declaration
SergiiDmytruk Nov 19, 2024
6e77edd
loader/slaunch/skl.c: fix a comment typo
SergiiDmytruk Nov 19, 2024
8c705ef
slaunch: introduce a hook for filling SLRT policy
SergiiDmytruk Nov 19, 2024
d00a1a6
multiboot: Make GRUB_MULTIBOOT(make_mbi) return MBI's size
SergiiDmytruk Nov 22, 2023
e383612
multiboot2: Support TXT and SKINIT slaunch
miczyg1 Sep 1, 2022
a655a9e
grub-core/loader/slaunch/psp.c: simplify is_drtm_device()
SergiiDmytruk Nov 24, 2024
8b35409
grub-core/loader/slaunch/psp.c: fix comment capitalization
SergiiDmytruk Nov 24, 2024
805d4f3
grub-core/loader/slaunch/psp.c: drop extra assignments from init_drtm…
SergiiDmytruk Nov 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grub-core/Makefile.core.def
Original file line number Diff line number Diff line change
Expand Up @@ -1878,12 +1878,12 @@ module = {
x86 = loader/slaunch/acmod.c;
x86 = loader/slaunch/verify.c;
x86 = loader/slaunch/i386_linux.c;
x86 = loader/slaunch/x86_efi_linux.c;
x86 = loader/slaunch/psp.c;
x86 = loader/slaunch/skinit.c;
x86 = loader/slaunch/skl.c;
x86 = loader/slaunch/dlstub.c;
x86 = loader/efi/dltrampoline.S;
x86_64_efi = loader/slaunch/x86_efi_linux.c;
enable = x86;
};

Expand Down
2 changes: 1 addition & 1 deletion grub-core/loader/i386/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ grub_linux_boot (void)
return GRUB_ERR_BAD_DEVICE;

dlinfo = grub_slr_next_entry_by_tag (slrt, NULL, GRUB_SLR_ENTRY_DL_INFO);
dl_entry ((grub_uint64_t)&dlinfo->bl_context);
dl_entry ((grub_uint64_t)(grub_addr_t)&dlinfo->bl_context);

/* If this returns, something failed miserably */
return GRUB_ERR_BAD_DEVICE;
Expand Down
4 changes: 3 additions & 1 deletion grub-core/loader/i386/multiboot_mbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ retrieve_video_parameters (struct multiboot_info *mbi,
}

grub_err_t
grub_multiboot_make_mbi (grub_uint32_t *target)
grub_multiboot_make_mbi (grub_uint32_t *target, grub_uint32_t *size)
{
struct multiboot_info *mbi;
struct multiboot_mod_list *modlist;
Expand Down Expand Up @@ -621,6 +621,8 @@ grub_multiboot_make_mbi (grub_uint32_t *target)
return err;
#endif

*size = (char *) ptrorig - (char *) mbi;

return GRUB_ERR_NONE;
}

Expand Down
14 changes: 13 additions & 1 deletion grub-core/loader/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <grub/video.h>
#include <grub/memory.h>
#include <grub/i18n.h>
#include <grub/slaunch.h>

GRUB_MOD_LICENSE ("GPLv3+");

Expand Down Expand Up @@ -177,6 +178,7 @@ static grub_err_t
grub_multiboot_boot (void)
{
grub_err_t err;
grub_uint32_t mbi_size;

#ifdef GRUB_USE_MULTIBOOT2
struct grub_relocator32_state state = MULTIBOOT2_INITIAL_STATE;
Expand All @@ -185,11 +187,21 @@ grub_multiboot_boot (void)
#endif
state.MULTIBOOT_ENTRY_REGISTER = GRUB_MULTIBOOT (payload_eip);

err = GRUB_MULTIBOOT (make_mbi) (&state.MULTIBOOT_MBI_REGISTER);
err = GRUB_MULTIBOOT (make_mbi) (&state.MULTIBOOT_MBI_REGISTER, &mbi_size);

if (err)
return err;

#ifdef GRUB_USE_MULTIBOOT2
if (grub_slaunch_platform_type () != SLP_NONE)
{
err = grub_multiboot2_perform_slaunch (state.MULTIBOOT_MBI_REGISTER,
mbi_size);
if (err)
return grub_error (err, N_("failed to perform Multiboot2 slaunch"));
}
#endif

if (grub_efi_is_finished)
normal_boot (GRUB_MULTIBOOT (relocator), state);
else
Expand Down
90 changes: 89 additions & 1 deletion grub-core/loader/multiboot_elfxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
#error "I'm confused"
#endif

#include <grub/i386/txt.h>
#include <grub/i386/relocator.h>
#include <grub/slaunch.h>

#define CONCAT(a,b) CONCAT_(a, b)
#define CONCAT_(a,b) a ## b
Expand Down Expand Up @@ -73,6 +75,11 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
grub_off_t phlimit;
unsigned int i;
void *source = NULL;
#ifdef GRUB_USE_MULTIBOOT2
struct grub_slaunch_params *slparams = &grub_multiboot2_slparams;
grub_uint32_t mle_hdr_offset;
struct grub_txt_mle_header *mle_hdr;
#endif

if (ehdr->e_ident[EI_MAG0] != ELFMAG0
|| ehdr->e_ident[EI_MAG1] != ELFMAG1
Expand Down Expand Up @@ -127,6 +134,18 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
{
load_size = highest_load - mld->link_base_addr;

#ifndef GRUB_USE_MULTIBOOT2
if (grub_slaunch_platform_type () != SLP_NONE)
return grub_error (GRUB_ERR_BAD_OS, "Only multiboot2 supported for slaunch");
#else
if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
{
/* Do not go below GRUB_TXT_PMR_ALIGN. */
if (mld->align < GRUB_TXT_PMR_ALIGN)
mld->align = GRUB_TXT_PMR_ALIGN;
}
#endif

grub_dprintf ("multiboot_loader", "align=0x%lx, preference=0x%x, "
"load_size=0x%x, avoid_efi_boot_services=%d\n",
(long) mld->align, mld->preference, load_size,
Expand All @@ -148,9 +167,57 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)

mld->load_base_addr = get_physical_target_address (ch);
source = get_virtual_current_address (ch);

#ifdef GRUB_USE_MULTIBOOT2
grub_memset (source, 0, load_size);
grub_dprintf ("multiboot_loader", "load_base_addr=0x%lx, source=0x%lx\n",
(long) mld->load_base_addr, (long) source);

if (grub_slaunch_platform_type () != SLP_NONE)
{
slparams->mle_start = mld->load_base_addr;
slparams->mle_mem = source;
slparams->mle_ptab_size = 0;
}

if (grub_slaunch_platform_type () == SLP_INTEL_TXT)
{
/*
* Allocate the binary together with the page tables to make one
* contiguous block for MLE.
*/
slparams->mle_ptab_size = grub_txt_get_mle_ptab_size (load_size);
slparams->mle_ptab_size = ALIGN_UP (slparams->mle_ptab_size, GRUB_TXT_PMR_ALIGN);

err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch,
GRUB_MEMORY_MACHINE_UPPER_START,
mld->load_base_addr - slparams->mle_ptab_size,
slparams->mle_ptab_size, GRUB_TXT_PMR_ALIGN,
GRUB_RELOCATOR_PREFERENCE_NONE, 1);
if (err)
{
grub_dprintf ("multiboot_loader", "Cannot allocate memory for MLE page tables\n");
return err;
}

slparams->mle_ptab_mem = get_virtual_current_address (ch);
slparams->mle_ptab_target = (grub_uint64_t) get_physical_target_address (ch);
grub_dprintf ("multiboot_loader", "mle_ptab_mem = %p, mle_ptab_target = %lx, mle_ptab_size = %x\n",
slparams->mle_ptab_mem, (unsigned long) slparams->mle_ptab_target,
(unsigned) slparams->mle_ptab_size);
}
#endif
}
else
mld->load_base_addr = mld->link_base_addr;
{
#ifdef GRUB_USE_MULTIBOOT2
/* TODO: support non-relocatable */
if (grub_slaunch_platform_type () != SLP_NONE)
return grub_error (GRUB_ERR_BAD_OS, "Non-relocatable ELF not supported with slaunch");
#endif

mld->load_base_addr = mld->link_base_addr;
}

grub_dprintf ("multiboot_loader", "relocatable=%d, link_base_addr=0x%x, "
"load_base_addr=0x%x\n", mld->relocatable,
Expand Down Expand Up @@ -213,6 +280,27 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld)
}
}

#ifdef GRUB_USE_MULTIBOOT2
if (grub_slaunch_platform_type () != SLP_NONE)
{
/* TODO: decide on universal way of conveying location of MLE header */
for (mle_hdr_offset = 0; mle_hdr_offset < 0x1000; mle_hdr_offset += 16)
{
mle_hdr = (struct grub_txt_mle_header *)((grub_addr_t)source + mle_hdr_offset);
if (!grub_memcmp (mle_hdr->uuid, GRUB_TXT_MLE_UUID, 16))
{
break;
}
}

if (mle_hdr_offset >= 0x1000)
return grub_error (GRUB_ERR_BAD_ARGUMENT, "MLE header not found");

slparams->mle_header_offset = mle_hdr_offset;
slparams->mle_size = mle_hdr->mle_end - mle_hdr->mle_start;
}
#endif

for (i = 0; i < phnum; i++)
if (phdr(i)->p_vaddr <= ehdr->e_entry
&& phdr(i)->p_vaddr + phdr(i)->p_memsz > ehdr->e_entry)
Expand Down
Loading