Skip to content

Commit a2f8392

Browse files
SergiiDmytrukkrystian-hebel
authored andcommitted
x86/boot: introduce slaunch_slrt global variable
It holds physical address of SLRT. The value is produced by slaunch_early (known as txt_early previously), gets set in assembly and then used by the main C code which don't need to know how we got it (which is different for different CPUs). This change additionally renames txt_early.c into slaunch_early.c Signed-off-by: Sergii Dmytruk <[email protected]> Signed-off-by: Krystian Hebel <[email protected]>
1 parent cb14d49 commit a2f8392

File tree

8 files changed

+59
-41
lines changed

8 files changed

+59
-41
lines changed

xen/arch/x86/boot/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ obj-bin-y += head.o
22

33
obj32 := cmdline.32.o
44
obj32 += reloc.32.o
5-
obj32 += txt_early.32.o
5+
obj32 += slaunch_early.32.o
66
obj32 += tpm_early.32.o
77

88
nocov-y += $(obj32)

xen/arch/x86/boot/head.S

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,20 +486,34 @@ __start:
486486
jmp trampoline_bios_setup
487487

488488
.Lslaunch_proto:
489+
/* Upon reaching here, CPU state mostly matches the one setup by the
490+
* bootloader with ESP, ESI and EDX being clobbered above. */
491+
489492
/* Save information that TrenchBoot slaunch was used. */
490493
movb $1, sym_esi(slaunch_active)
491494

495+
/* Prepare space for output parameter of slaunch_early_tests(), which is
496+
* a structure of two uint32_t fields. */
497+
sub $8, %esp
498+
499+
push %esp /* pointer to output structure */
492500
lea sym_offs(__2M_rwdata_end), %ecx /* end of target image */
493501
lea sym_offs(_start), %edx /* target base address */
494502
mov %esi, %eax /* load base address */
495-
/* txt_early_tests(load/eax, tgt/edx, tgt_end/ecx) using fastcall. */
496-
call txt_early_tests
503+
/* slaunch_early_tests(load/eax, tgt/edx, tgt_end/ecx, ret/stk) using fastcall. */
504+
call slaunch_early_tests
497505

498-
/*
499-
* txt_early_tests() returns MBI address, pass it to tpm_extend_mbi()
500-
* and store for later in EBX.
501-
*/
502-
movl %eax, %ebx
506+
/* Move outputs of slaunch_early_tests() from stack into registers. */
507+
pop %eax /* physical MBI address */
508+
pop %edx /* physical SLRT address */
509+
510+
/* Save physical address of SLRT for C code. */
511+
mov %edx, sym_esi(slaunch_slrt)
512+
513+
/* Store MBI address in EBX where MB2 code expects it. */
514+
mov %eax, %ebx
515+
516+
/* tpm_extend_mbi(mbi/eax, slrt/edx) using fastcall. */
503517
call tpm_extend_mbi
504518

505519
/* Move magic number expected by Multiboot 2 to EAX and fall through. */
@@ -845,9 +859,9 @@ FUNC_LOCAL(reloc)
845859
.incbin "reloc.bin"
846860
END(reloc)
847861

848-
FUNC_LOCAL(txt_early_tests)
849-
.incbin "txt_early.bin"
850-
END(txt_early_tests)
862+
FUNC_LOCAL(slaunch_early_tests)
863+
.incbin "slaunch_early.bin"
864+
END(slaunch_early_tests)
851865

852866
FUNC_LOCAL(tpm_extend_mbi)
853867
.incbin "tpm_early.bin"

xen/arch/x86/boot/txt_early.c renamed to xen/arch/x86/boot/slaunch_early.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,28 @@
1717

1818
/*
1919
* This entry point is entered from xen/arch/x86/boot/head.S with:
20-
* - %eax = load_base_addr,
21-
* - %edx = tgt_base_addr,
22-
* - %ecx = tgt_end_addr.
23-
*
24-
* A pointer to MBI is returned in %eax.
20+
* - %eax = load_base_addr,
21+
* - %edx = tgt_base_addr,
22+
* - %ecx = tgt_end_addr,
23+
* - 0x04(%esp) = &result.
2524
*/
2625
asm (
2726
" .text \n"
2827
" .globl _start \n"
2928
"_start: \n"
30-
" jmp txt_early_tests \n"
29+
" jmp slaunch_early_tests \n"
3130
);
3231

3332
#include <xen/macros.h>
3433
#include <xen/types.h>
3534
#include <asm/intel_txt.h>
3635

36+
struct early_tests_results
37+
{
38+
uint32_t mbi_pa;
39+
uint32_t slrt_pa;
40+
} __packed;
41+
3742
static void verify_pmr_ranges(struct txt_os_mle_data *os_mle,
3843
struct txt_os_sinit_data *os_sinit,
3944
uint32_t load_base_addr, uint32_t tgt_base_addr,
@@ -110,9 +115,10 @@ static void verify_pmr_ranges(struct txt_os_mle_data *os_mle,
110115
*/
111116
}
112117

113-
uint32_t txt_early_tests(uint32_t load_base_addr,
118+
void slaunch_early_tests(uint32_t load_base_addr,
114119
uint32_t tgt_base_addr,
115-
uint32_t tgt_end_addr)
120+
uint32_t tgt_end_addr,
121+
struct early_tests_results *result)
116122
{
117123
void *txt_heap;
118124
struct txt_os_mle_data *os_mle;
@@ -133,5 +139,6 @@ uint32_t txt_early_tests(uint32_t load_base_addr,
133139

134140
verify_pmr_ranges(os_mle, os_sinit, load_base_addr, tgt_base_addr, size);
135141

136-
return os_mle->boot_params_addr;
142+
result->mbi_pa = os_mle->boot_params_addr;
143+
result->slrt_pa = os_mle->slrt;
137144
}

xen/arch/x86/include/asm/intel_txt.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,6 @@ static inline int is_in_pmr(struct txt_os_sinit_data *os_sinit, uint64_t base,
330330
return 0;
331331
}
332332

333-
/* Returns physical address. */
334-
static inline uint32_t txt_find_slrt(void)
335-
{
336-
struct txt_os_mle_data *os_mle =
337-
txt_os_mle_data_start(_txt(read_txt_reg(TXTCR_HEAP_BASE)));
338-
return os_mle->slrt;
339-
}
340-
341333
extern void map_txt_mem_regions(void);
342334
extern void protect_txt_mem_regions(void);
343335
extern void txt_restore_mtrrs(bool e820_verbose);

xen/arch/x86/include/asm/slaunch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define DLE_EVTYPE_SLAUNCH_END (TXT_EVTYPE_BASE + 0x104)
1919

2020
extern bool slaunch_active;
21+
extern uint32_t slaunch_slrt; /* physical address */
2122

2223
/* evt_log is a physical address and the caller must map it to virtual, if
2324
* needed. */

xen/arch/x86/intel_txt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void __init map_txt_mem_regions(void)
2929

3030
map_l2(txt_heap_base, txt_heap_size);
3131

32-
find_evt_log(__va(txt_find_slrt()), &evt_log_addr, &evt_log_size);
32+
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
3333
map_l2((unsigned long)evt_log_addr, evt_log_size);
3434
if ( evt_log_addr != NULL )
3535
map_l2((unsigned long)evt_log_addr, evt_log_size);
@@ -53,7 +53,7 @@ void __init protect_txt_mem_regions(void)
5353
BUG_ON(rc == 0);
5454

5555
/* TXT TPM Event Log */
56-
find_evt_log(__va(txt_find_slrt()), &evt_log_addr, &evt_log_size);
56+
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
5757
if ( evt_log_addr != NULL ) {
5858
printk("SLAUNCH: reserving event log (%#lx - %#lx)\n",
5959
(uint64_t)evt_log_addr,

xen/arch/x86/slaunch.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <xen/types.h>
2-
#include <asm/intel_txt.h>
32
#include <asm/page.h>
43
#include <asm/processor.h>
54
#include <asm/slaunch.h>
@@ -9,6 +8,7 @@
98
#include <xen/multiboot.h>
109

1110
bool __initdata slaunch_active;
11+
uint32_t __initdata slaunch_slrt;
1212

1313
static void __maybe_unused compile_time_checks(void)
1414
{
@@ -37,10 +37,9 @@ int __init map_l2(unsigned long paddr, unsigned long size)
3737

3838
static struct slr_table *slr_get_table(void)
3939
{
40-
uint32_t slrt_pa = txt_find_slrt();
41-
struct slr_table *slrt = __va(slrt_pa);
40+
struct slr_table *slrt = __va(slaunch_slrt);
4241

43-
map_l2(slrt_pa, PAGE_SIZE);
42+
map_l2(slaunch_slrt, PAGE_SIZE);
4443

4544
if ( slrt->magic != SLR_TABLE_MAGIC )
4645
panic("SLRT has invalid magic value: %#08x!\n", slrt->magic);
@@ -55,7 +54,7 @@ static struct slr_table *slr_get_table(void)
5554
slrt->size, slrt->max_size);
5655

5756
if ( slrt->size > PAGE_SIZE )
58-
map_l2(slrt_pa, slrt->size);
57+
map_l2(slaunch_slrt, slrt->size);
5958

6059
return slrt;
6160
}

xen/arch/x86/tpm.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424

2525
#ifdef __EARLY_TPM__
2626
/*
27-
* This entry point is entered from xen/arch/x86/boot/head.S with MBI base at
28-
* %eax.
27+
* This entry point is entered from xen/arch/x86/boot/head.S with:
28+
* - %eax = &mbi,
29+
* - %edx = slrt_pa.
2930
*/
3031
asm (
3132
" .text \n"
@@ -40,6 +41,8 @@ asm (
4041

4142
#define __va(x) _p(x)
4243

44+
uint32_t slaunch_slrt;
45+
4346
/*
4447
* The code is being compiled as a standalone binary without linking to any
4548
* other part of Xen. Providing implementation of builtin functions in this
@@ -933,9 +936,7 @@ void tpm_hash_extend(unsigned loc, unsigned pcr, uint8_t *buf, unsigned size,
933936
void *evt_log_addr;
934937
uint32_t evt_log_size;
935938

936-
struct slr_table *slrt = __va(txt_find_slrt());
937-
938-
find_evt_log(slrt, &evt_log_addr, &evt_log_size);
939+
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
939940
evt_log_addr = __va((uintptr_t)evt_log_addr);
940941

941942
if ( is_tpm12() ) {
@@ -973,8 +974,12 @@ void tpm_hash_extend(unsigned loc, unsigned pcr, uint8_t *buf, unsigned size,
973974
}
974975

975976
#ifdef __EARLY_TPM__
976-
void tpm_extend_mbi(uint32_t *mbi)
977+
void tpm_extend_mbi(uint32_t *mbi, uint32_t slrt_pa)
977978
{
979+
/* Early TPM code isn't linked with the rest but still needs to have this
980+
* variable with correct value. */
981+
slaunch_slrt = slrt_pa;
982+
978983
/* MBI starts with uint32_t total_size. */
979984
tpm_hash_extend(DRTM_LOC, DRTM_DATA_PCR, (uint8_t *)mbi, *mbi,
980985
DLE_EVTYPE_SLAUNCH, NULL, 0);

0 commit comments

Comments
 (0)