99#include <xen/mm.h>
1010#include <asm/bootinfo.h>
1111
12+ /* SLB is 64k, 64k-aligned */
13+ #define SKINIT_SLB_SIZE 0x10000
14+ #define SKINIT_SLB_ALIGN 0x10000
15+
1216bool __initdata slaunch_active ;
1317uint32_t __initdata slaunch_slrt ;
1418
@@ -37,6 +41,19 @@ int __init map_l2(unsigned long paddr, unsigned long size)
3741 pages , PAGE_HYPERVISOR );
3842}
3943
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+
4057void __init map_slaunch_mem_regions (void )
4158{
4259 void * evt_log_addr ;
@@ -45,7 +62,14 @@ void __init map_slaunch_mem_regions(void)
4562 map_l2 (TPM_TIS_BASE , TPM_TIS_SIZE );
4663
4764 /* 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+ }
4973
5074 find_evt_log (__va (slaunch_slrt ), & evt_log_addr , & evt_log_size );
5175 if ( evt_log_addr != NULL )
@@ -71,11 +95,25 @@ void __init protect_slaunch_mem_regions(void)
7195 }
7296
7397 /* 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+ }
75110}
76111
77112static struct slr_table * slr_get_table (void )
78113{
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+
79117 struct slr_table * slrt = __va (slaunch_slrt );
80118
81119 map_l2 (slaunch_slrt , PAGE_SIZE );
@@ -85,9 +123,9 @@ static struct slr_table *slr_get_table(void)
85123 /* XXX: are newer revisions allowed? */
86124 if ( slrt -> revision != SLR_TABLE_REVISION )
87125 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 );
91129 if ( slrt -> size > slrt -> max_size )
92130 panic ("SLRT is larger than its max size: %#08x > %#08x!\n" ,
93131 slrt -> size , slrt -> max_size );
@@ -104,14 +142,18 @@ void tpm_measure_slrt(void)
104142
105143 if ( slrt -> revision == 1 )
106144 {
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+ }
115157 }
116158 else
117159 {
0 commit comments