Skip to content

Commit

Permalink
x86/boot: find MBI and SLRT on AMD
Browse files Browse the repository at this point in the history
secure-kernel-loader on AMD with SKINIT passes MBI as a parameter for
Multiboot kernel.

Another thing of interest is the location of SLRT which is bootloader's
data after SKL.

Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk authored and krystian-hebel committed Oct 10, 2024
1 parent 76a672d commit 84c621a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions xen/arch/x86/boot/head.S
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ __start:

/* Push arguments to stack and call slaunch_early_tests(). */
push %esp /* pointer to output structure */
push %ebp /* Slaunch parameter on AMD */
push %ebx /* Multiboot parameter */
push $sym_offs(__2M_rwdata_end) /* end of target image */
push $sym_offs(_start) /* target base address */
push %esi /* load base address */
Expand Down
40 changes: 40 additions & 0 deletions xen/arch/x86/boot/slaunch_early.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,33 @@ asm (
#include "../include/asm/intel_txt.h"
#include "../include/asm/slaunch.h"

//#include "../../../tools/include/xen-tools/common-macros.h"
#define __AC(X, Y) (X ## Y)
#define _AC(X, Y) __AC(X, Y)

#include "../include/asm/x86-vendors.h"

struct early_tests_results
{
uint32_t mbi_pa;
uint32_t slrt_pa;
} __packed;

static bool is_intel_cpu(void)
{
/*
* asm/processor.h can't be included in early code, which means neither
* cpuid() function nor boot_cpu_data can be used here.
*/
uint32_t eax, ebx, ecx, edx;
asm volatile ( "cpuid"
: "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
: "0" (0), "c" (0) );
return ebx == X86_VENDOR_INTEL_EBX
&& ecx == X86_VENDOR_INTEL_ECX
&& edx == X86_VENDOR_INTEL_EDX;
}

static void verify_pmr_ranges(struct txt_os_mle_data *os_mle,
struct txt_os_sinit_data *os_sinit,
uint32_t load_base_addr, uint32_t tgt_base_addr,
Expand Down Expand Up @@ -115,13 +136,32 @@ static void verify_pmr_ranges(struct txt_os_mle_data *os_mle,
void __stdcall slaunch_early_tests(uint32_t load_base_addr,
uint32_t tgt_base_addr,
uint32_t tgt_end_addr,
uint32_t multiboot_param,
uint32_t slaunch_param,
struct early_tests_results *result)
{
void *txt_heap;
struct txt_os_mle_data *os_mle;
struct txt_os_sinit_data *os_sinit;
uint32_t size = tgt_end_addr - tgt_base_addr;

if ( !is_intel_cpu() )
{
/*
* Not an Intel CPU. Currently the only other option is AMD with SKINIT
* and secure-kernel-loader.
*/

const uint16_t *sl_header = (void *)slaunch_param;
/* secure-kernel-loader passes MBI as a parameter for Multiboot
* kernel. */
result->mbi_pa = multiboot_param;
/* The fourth 16-bit integer of SKL's header is an offset to
* bootloader's data, which is SLRT. */
result->slrt_pa = slaunch_param + sl_header[3];
return;
}

/* Clear the TXT error registers for a clean start of day */
write_txt_reg(TXTCR_ERRORCODE, 0);

Expand Down

0 comments on commit 84c621a

Please sign in to comment.