@@ -57,15 +57,15 @@ static PML4: StaticPml4 = {
5757 page_table
5858} ;
5959
60- #[ unsafe( link_section = ".pagetables " ) ]
60+ #[ unsafe( link_section = ".ropagetables " ) ]
6161static PDP_256 : StaticPdp = {
6262 let mut page_table = StaticPageTable :: new ( ) ;
6363 page_table. set_table ( 0 , & PD_256_0 , flags ! ( WRITE ) ) ;
6464 page_table. set_page ( 1 , PROFILER_BUFFER , flags ! ( WRITE | GLOBAL ) ) ;
6565 page_table
6666} ;
6767
68- #[ unsafe( link_section = ".pagetables " ) ]
68+ #[ unsafe( link_section = ".ropagetables " ) ]
6969static PD_256_0 : StaticPd = {
7070 let mut page_table = StaticPageTable :: new ( ) ;
7171 page_table. set_page ( 0 , RESET_VECTOR , flags ! ( GLOBAL ) ) ;
@@ -82,7 +82,7 @@ static PD_256_0: StaticPd = {
8282 page_table
8383} ;
8484
85- #[ unsafe( link_section = ".pagetables " ) ]
85+ #[ unsafe( link_section = ".ropagetables " ) ]
8686static PDP_352 : StaticPdp = {
8787 let mut page_table = StaticPageTable :: new ( ) ;
8888 page_table. set_table ( 0 , & PD_352_0 , flags ! ( WRITE | EXECUTE_DISABLE ) ) ;
@@ -91,7 +91,7 @@ static PDP_352: StaticPdp = {
9191 page_table
9292} ;
9393
94- #[ unsafe( link_section = ".pagetables " ) ]
94+ #[ unsafe( link_section = ".ropagetables " ) ]
9595static PD_352_0 : StaticPd = {
9696 let mut page_table = StaticPageTable :: new ( ) ;
9797 page_table. set_page ( 0 , TEXT_SHADOW , flags ! ( GLOBAL | EXECUTE_DISABLE ) ) ;
@@ -102,21 +102,21 @@ static PD_352_0: StaticPd = {
102102 page_table
103103} ;
104104
105- #[ unsafe( link_section = ".pagetables " ) ]
105+ #[ unsafe( link_section = ".ropagetables " ) ]
106106static PD_352_72 : StaticPd = {
107107 let mut page_table = StaticPageTable :: new ( ) ;
108108 page_table. set_page ( 0 , INIT_FILE_SHADOW , flags ! ( GLOBAL | EXECUTE_DISABLE ) ) ;
109109 page_table
110110} ;
111111
112- #[ unsafe( link_section = ".pagetables " ) ]
112+ #[ unsafe( link_section = ".ropagetables " ) ]
113113static PD_352_80 : StaticPd = {
114114 let mut page_table = StaticPageTable :: new ( ) ;
115115 page_table. set_page ( 0 , INPUT_FILE_SHADOW , flags ! ( GLOBAL | EXECUTE_DISABLE ) ) ;
116116 page_table
117117} ;
118118
119- #[ unsafe( link_section = ".pagetables " ) ]
119+ #[ unsafe( link_section = ".ropagetables " ) ]
120120static PDP_257 : StaticPdp = {
121121 let mut page_table = StaticPageTable :: new ( ) ;
122122 page_table. set_page_range ( 0 , DYNAMIC , flags ! ( WRITE | GLOBAL | EXECUTE_DISABLE ) ) ;
@@ -131,24 +131,34 @@ static PDP_257: StaticPdp = {
131131#[ used]
132132#[ unsafe( link_section = ".pagetables.tdx.pml4" ) ]
133133static TDX_PML4 : StaticPml4 = {
134+ // Most kernel mappings are set up through the HLAT PML4, so we can start
135+ // with an empty PML4.
136+ let mut page_table = StaticPageTable :: new ( ) ;
137+ page_table. set_recursive_table ( 510 , & TDX_PML4 , flags ! ( WRITE ) ) ;
138+ page_table
139+ } ;
140+
141+ #[ used]
142+ #[ unsafe( link_section = ".ropagetables.tdx.pml4" ) ]
143+ static TDX_HLAT_PML4 : StaticPml4 = {
134144 let mut page_table = unsafe { PML4 . clone ( ) } ;
135145 page_table. clear_entry ( 256 ) ;
136146 page_table. set_table ( 256 , & TDX_PDP_256 , flags ! ( WRITE ) ) ;
137- // Fix the recursive entry.
147+ // Clear the recursive entry. It should get translated through the regular page tables .
138148 page_table. clear_entry ( 510 ) ;
139- page_table. set_recursive_table ( 510 , & TDX_PML4 , flags ! ( WRITE ) ) ;
149+ page_table. fill_hlat_restart ( ) ;
140150 page_table
141151} ;
142152
143- #[ unsafe( link_section = ".pagetables " ) ]
153+ #[ unsafe( link_section = ".ropagetables " ) ]
144154static TDX_PDP_256 : StaticPdp = {
145155 let mut page_table = unsafe { PDP_256 . clone ( ) } ;
146156 page_table. clear_entry ( 0 ) ;
147157 page_table. set_table ( 0 , & TDX_PD_256_0 , flags ! ( WRITE ) ) ;
148158 page_table
149159} ;
150160
151- #[ unsafe( link_section = ".pagetables " ) ]
161+ #[ unsafe( link_section = ".ropagetables " ) ]
152162static TDX_PD_256_0 : StaticPd = {
153163 let mut page_table = unsafe { PD_256_0 . clone ( ) } ;
154164 page_table. clear_entry ( 56 ) ;
0 commit comments