Skip to content

Commit

Permalink
arch/x86: move generic memory mapping and protection to slaunch.c
Browse files Browse the repository at this point in the history
Signed-off-by: Sergii Dmytruk <[email protected]>
  • Loading branch information
SergiiDmytruk authored and krystian-hebel committed Nov 6, 2024
1 parent e735521 commit 3667bdf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
4 changes: 4 additions & 0 deletions xen/arch/x86/include/asm/slaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static inline void find_evt_log(struct slr_table *slrt, void **evt_log,
}
}

void map_slaunch_mem_regions(void);

void protect_slaunch_mem_regions(void);

/*
* This helper function is used to map memory using L2 page tables by aligning
* mapped regions to 2MB. This way page allocator (which at this point isn't
Expand Down
24 changes: 0 additions & 24 deletions xen/arch/x86/intel_txt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ static uint64_t __initdata txt_heap_base, txt_heap_size;

void __init map_txt_mem_regions(void)
{
void *evt_log_addr;
uint32_t evt_log_size;

map_l2(TXT_PRIV_CONFIG_REGS_BASE, NR_TXT_CONFIG_SIZE);
map_l2(TPM_TIS_BASE, TPM_TIS_SIZE);

txt_heap_base = read_txt_reg(TXTCR_HEAP_BASE);
BUG_ON(txt_heap_base == 0);
Expand All @@ -28,20 +24,11 @@ void __init map_txt_mem_regions(void)
BUG_ON(txt_heap_size == 0);

map_l2(txt_heap_base, txt_heap_size);

find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
map_l2((unsigned long)evt_log_addr, evt_log_size);
if ( evt_log_addr != NULL )
map_l2((unsigned long)evt_log_addr, evt_log_size);
}

void __init protect_txt_mem_regions(void)
{
int rc;

void *evt_log_addr;
uint32_t evt_log_size;

uint64_t sinit_base, sinit_size;

/* TXT Heap */
Expand All @@ -52,17 +39,6 @@ void __init protect_txt_mem_regions(void)
txt_heap_base + txt_heap_size);
BUG_ON(rc == 0);

/* TXT TPM Event Log */
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
if ( evt_log_addr != NULL ) {
printk("SLAUNCH: reserving event log (%#lx - %#lx)\n",
(uint64_t)evt_log_addr,
(uint64_t)evt_log_addr + evt_log_size);
rc = reserve_e820_ram(&e820_raw, (uint64_t)evt_log_addr,
(uint64_t)evt_log_addr + evt_log_size);
BUG_ON(rc == 0);
}

sinit_base = read_txt_reg(TXTCR_SINIT_BASE);
BUG_ON(sinit_base == 0);

Expand Down
11 changes: 6 additions & 5 deletions xen/arch/x86/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include <asm/prot-key.h>
#include <asm/pv/domain.h>
#include <asm/trampoline.h>
#include <asm/intel_txt.h>
#include <asm/slaunch.h>
#include <asm/tpm.h>

Expand Down Expand Up @@ -1363,13 +1362,15 @@ void asmlinkage __init noreturn __start_xen(void)

if ( slaunch_active )
{
/* Prepare for TXT-related code. */
map_txt_mem_regions();
/* Prepare for accesses to essential data structures setup by boot
* environment. */
map_slaunch_mem_regions();

/* Measure SLRT here because it gets used by init_e820(), the rest is
* measured below by tpm_process_drtm_policy(). */
tpm_measure_slrt();
/* Reserve TXT heap and SINIT. */
protect_txt_mem_regions();

protect_slaunch_mem_regions();
}

/* Sanitise the raw E820 map to produce a final clean version. */
Expand Down
39 changes: 39 additions & 0 deletions xen/arch/x86/slaunch.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <xen/types.h>
#include <asm/e820.h>
#include <asm/intel_txt.h>
#include <asm/page.h>
#include <asm/processor.h>
#include <asm/slaunch.h>
Expand Down Expand Up @@ -35,6 +37,43 @@ int __init map_l2(unsigned long paddr, unsigned long size)
pages, PAGE_HYPERVISOR);
}

void __init map_slaunch_mem_regions(void)
{
void *evt_log_addr;
uint32_t evt_log_size;

map_l2(TPM_TIS_BASE, TPM_TIS_SIZE);

/* Vendor-specific part. It may include contain slaunch_slrt. */
map_txt_mem_regions();

find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
if ( evt_log_addr != NULL )
map_l2((unsigned long)evt_log_addr, evt_log_size);
}

void __init protect_slaunch_mem_regions(void)
{
int rc;

void *evt_log_addr;
uint32_t evt_log_size;

find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
if ( evt_log_addr != NULL )
{
printk("SLAUNCH: reserving event log (%#lx - %#lx)\n",
(uint64_t)evt_log_addr,
(uint64_t)evt_log_addr + evt_log_size);
rc = reserve_e820_ram(&e820_raw, (uint64_t)evt_log_addr,
(uint64_t)evt_log_addr + evt_log_size);
BUG_ON(rc == 0);
}

/* Vendor-specific part. */
protect_txt_mem_regions();
}

static struct slr_table *slr_get_table(void)
{
struct slr_table *slrt = __va(slaunch_slrt);
Expand Down

0 comments on commit 3667bdf

Please sign in to comment.