9
9
#include <xen/mm.h>
10
10
#include <xen/multiboot.h>
11
11
12
+ /* SLB is 64k, 64k-aligned */
13
+ #define SKINIT_SLB_SIZE 0x10000
14
+ #define SKINIT_SLB_ALIGN 0x10000
15
+
12
16
bool __initdata slaunch_active ;
13
17
uint32_t __initdata slaunch_slrt ;
14
18
@@ -37,6 +41,19 @@ int __init map_l2(unsigned long paddr, unsigned long size)
37
41
pages , PAGE_HYPERVISOR );
38
42
}
39
43
44
+ static uint32_t get_slb_start (void )
45
+ {
46
+ /* The runtime computation relies on size being a power of 2 and equal to
47
+ * alignment. Make sure these assumptions hold. */
48
+ BUILD_BUG_ON (SKINIT_SLB_SIZE != SKINIT_SLB_ALIGN );
49
+ BUILD_BUG_ON (SKINIT_SLB_SIZE == 0 );
50
+ BUILD_BUG_ON ((SKINIT_SLB_SIZE & (SKINIT_SLB_SIZE - 1 )) != 0 );
51
+
52
+ /* Rounding any address within SLB down to alignment gives SLB base and
53
+ * SLRT is inside SLB on AMD. */
54
+ return slaunch_slrt & ~(SKINIT_SLB_SIZE - 1 );
55
+ }
56
+
40
57
void __init map_slaunch_mem_regions (void )
41
58
{
42
59
void * evt_log_addr ;
@@ -45,7 +62,14 @@ void __init map_slaunch_mem_regions(void)
45
62
map_l2 (TPM_TIS_BASE , TPM_TIS_SIZE );
46
63
47
64
/* Vendor-specific part. It may include contain slaunch_slrt. */
48
- map_txt_mem_regions ();
65
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
66
+ {
67
+ map_txt_mem_regions ();
68
+ }
69
+ else if ( boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
70
+ {
71
+ map_l2 (get_slb_start (), SKINIT_SLB_SIZE );
72
+ }
49
73
50
74
find_evt_log (__va (slaunch_slrt ), & evt_log_addr , & evt_log_size );
51
75
if ( evt_log_addr != NULL )
@@ -71,11 +95,25 @@ void __init protect_slaunch_mem_regions(void)
71
95
}
72
96
73
97
/* Vendor-specific part. */
74
- protect_txt_mem_regions ();
98
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
99
+ {
100
+ protect_txt_mem_regions ();
101
+ }
102
+ else if ( boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
103
+ {
104
+ uint64_t slb_start = get_slb_start ();
105
+ uint64_t slb_end = slb_start + SKINIT_SLB_SIZE ;
106
+ printk ("SLAUNCH: reserving SLB (%#lx - %#lx)\n" , slb_start , slb_end );
107
+ e820_change_range_type (& e820_raw , slb_start , slb_end ,
108
+ E820_RAM , E820_RESERVED );
109
+ }
75
110
}
76
111
77
112
static struct slr_table * slr_get_table (void )
78
113
{
114
+ bool intel_cpu = (boot_cpu_data .x86_vendor == X86_VENDOR_INTEL );
115
+ uint16_t slrt_architecture = intel_cpu ? SLR_INTEL_TXT : SLR_AMD_SKINIT ;
116
+
79
117
struct slr_table * slrt = __va (slaunch_slrt );
80
118
81
119
map_l2 (slaunch_slrt , PAGE_SIZE );
@@ -85,9 +123,9 @@ static struct slr_table *slr_get_table(void)
85
123
/* XXX: are newer revisions allowed? */
86
124
if ( slrt -> revision != SLR_TABLE_REVISION )
87
125
panic ("SLRT is of unsupported revision: %#04x!\n" , slrt -> revision );
88
- if ( slrt -> architecture != SLR_INTEL_TXT )
89
- panic ("SLRT is for unexpected architecture: %#04x!\n" ,
90
- slrt -> architecture );
126
+ if ( slrt -> architecture != slrt_architecture )
127
+ panic ("SLRT is for unexpected architecture: %#04x != %#04x !\n" ,
128
+ slrt -> architecture , slrt_architecture );
91
129
if ( slrt -> size > slrt -> max_size )
92
130
panic ("SLRT is larger than its max size: %#08x > %#08x!\n" ,
93
131
slrt -> size , slrt -> max_size );
@@ -104,14 +142,18 @@ void tpm_measure_slrt(void)
104
142
105
143
if ( slrt -> revision == 1 )
106
144
{
107
- /* In revision one of the SLRT, only Intel info table is measured. */
108
- struct slr_entry_intel_info * intel_info =
109
- (void * )slr_next_entry_by_tag (slrt , NULL , SLR_ENTRY_INTEL_INFO );
110
- if ( intel_info == NULL )
111
- panic ("SLRT is missing Intel-specific information!\n" );
112
-
113
- tpm_hash_extend (DRTM_LOC , DRTM_DATA_PCR , (uint8_t * )intel_info ,
114
- sizeof (* intel_info ), DLE_EVTYPE_SLAUNCH , NULL , 0 );
145
+ if ( boot_cpu_data .x86_vendor == X86_VENDOR_INTEL )
146
+ {
147
+ /* In revision one of the SLRT, only Intel info table is
148
+ * measured. */
149
+ struct slr_entry_intel_info * intel_info =
150
+ (void * )slr_next_entry_by_tag (slrt , NULL , SLR_ENTRY_INTEL_INFO );
151
+ if ( intel_info == NULL )
152
+ panic ("SLRT is missing Intel-specific information!\n" );
153
+
154
+ tpm_hash_extend (DRTM_LOC , DRTM_DATA_PCR , (uint8_t * )intel_info ,
155
+ sizeof (* intel_info ), DLE_EVTYPE_SLAUNCH , NULL , 0 );
156
+ }
115
157
}
116
158
else
117
159
{
0 commit comments