Skip to content

Commit bd2771f

Browse files
SergiiDmytrukkrystian-hebel
authored andcommitted
arch/x86: move generic memory mapping and protection to slaunch.c
Signed-off-by: Sergii Dmytruk <[email protected]>
1 parent a4e1e67 commit bd2771f

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ static inline void find_evt_log(struct slr_table *slrt, void **evt_log,
4040
}
4141
}
4242

43+
void map_slaunch_mem_regions(void);
44+
45+
void protect_slaunch_mem_regions(void);
46+
4347
/*
4448
* This helper function is used to map memory using L2 page tables by aligning
4549
* mapped regions to 2MB. This way page allocator (which at this point isn't

xen/arch/x86/intel_txt.c

-24
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ static uint64_t __initdata txt_heap_base, txt_heap_size;
1515

1616
void __init map_txt_mem_regions(void)
1717
{
18-
void *evt_log_addr;
19-
uint32_t evt_log_size;
20-
2118
map_l2(TXT_PRIV_CONFIG_REGS_BASE, NR_TXT_CONFIG_SIZE);
22-
map_l2(TPM_TIS_BASE, TPM_TIS_SIZE);
2319

2420
txt_heap_base = read_txt_reg(TXTCR_HEAP_BASE);
2521
BUG_ON(txt_heap_base == 0);
@@ -28,20 +24,11 @@ void __init map_txt_mem_regions(void)
2824
BUG_ON(txt_heap_size == 0);
2925

3026
map_l2(txt_heap_base, txt_heap_size);
31-
32-
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
33-
map_l2((unsigned long)evt_log_addr, evt_log_size);
34-
if ( evt_log_addr != NULL )
35-
map_l2((unsigned long)evt_log_addr, evt_log_size);
3627
}
3728

3829
void __init protect_txt_mem_regions(void)
3930
{
4031
int rc;
41-
42-
void *evt_log_addr;
43-
uint32_t evt_log_size;
44-
4532
uint64_t sinit_base, sinit_size;
4633

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

55-
/* TXT TPM Event Log */
56-
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
57-
if ( evt_log_addr != NULL ) {
58-
printk("SLAUNCH: reserving event log (%#lx - %#lx)\n",
59-
(uint64_t)evt_log_addr,
60-
(uint64_t)evt_log_addr + evt_log_size);
61-
rc = reserve_e820_ram(&e820_raw, (uint64_t)evt_log_addr,
62-
(uint64_t)evt_log_addr + evt_log_size);
63-
BUG_ON(rc == 0);
64-
}
65-
6642
sinit_base = read_txt_reg(TXTCR_SINIT_BASE);
6743
BUG_ON(sinit_base == 0);
6844

xen/arch/x86/setup.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include <asm/prot-key.h>
6161
#include <asm/pv/domain.h>
6262
#include <asm/trampoline.h>
63-
#include <asm/intel_txt.h>
6463
#include <asm/slaunch.h>
6564
#include <asm/tpm.h>
6665

@@ -1281,13 +1280,15 @@ void asmlinkage __init noreturn __start_xen(unsigned long mbi_p)
12811280

12821281
if ( slaunch_active )
12831282
{
1284-
/* Prepare for TXT-related code. */
1285-
map_txt_mem_regions();
1283+
/* Prepare for accesses to essential data structures setup by boot
1284+
* environment. */
1285+
map_slaunch_mem_regions();
1286+
12861287
/* Measure SLRT here because it gets used by init_e820(), the rest is
12871288
* measured below by tpm_process_drtm_policy(). */
12881289
tpm_measure_slrt();
1289-
/* Reserve TXT heap and SINIT. */
1290-
protect_txt_mem_regions();
1290+
1291+
protect_slaunch_mem_regions();
12911292
}
12921293

12931294
/* Sanitise the raw E820 map to produce a final clean version. */

xen/arch/x86/slaunch.c

+39
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include <xen/types.h>
2+
#include <asm/e820.h>
3+
#include <asm/intel_txt.h>
24
#include <asm/page.h>
35
#include <asm/processor.h>
46
#include <asm/slaunch.h>
@@ -35,6 +37,43 @@ int __init map_l2(unsigned long paddr, unsigned long size)
3537
pages, PAGE_HYPERVISOR);
3638
}
3739

40+
void __init map_slaunch_mem_regions(void)
41+
{
42+
void *evt_log_addr;
43+
uint32_t evt_log_size;
44+
45+
map_l2(TPM_TIS_BASE, TPM_TIS_SIZE);
46+
47+
/* Vendor-specific part. It may include contain slaunch_slrt. */
48+
map_txt_mem_regions();
49+
50+
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
51+
if ( evt_log_addr != NULL )
52+
map_l2((unsigned long)evt_log_addr, evt_log_size);
53+
}
54+
55+
void __init protect_slaunch_mem_regions(void)
56+
{
57+
int rc;
58+
59+
void *evt_log_addr;
60+
uint32_t evt_log_size;
61+
62+
find_evt_log(__va(slaunch_slrt), &evt_log_addr, &evt_log_size);
63+
if ( evt_log_addr != NULL )
64+
{
65+
printk("SLAUNCH: reserving event log (%#lx - %#lx)\n",
66+
(uint64_t)evt_log_addr,
67+
(uint64_t)evt_log_addr + evt_log_size);
68+
rc = reserve_e820_ram(&e820_raw, (uint64_t)evt_log_addr,
69+
(uint64_t)evt_log_addr + evt_log_size);
70+
BUG_ON(rc == 0);
71+
}
72+
73+
/* Vendor-specific part. */
74+
protect_txt_mem_regions();
75+
}
76+
3877
static struct slr_table *slr_get_table(void)
3978
{
4079
struct slr_table *slrt = __va(slaunch_slrt);

0 commit comments

Comments
 (0)