41
41
#include <linux/mem_encrypt.h>
42
42
#include <linux/cc_platform.h>
43
43
44
+ #include <asm/init.h>
44
45
#include <asm/setup.h>
45
46
#include <asm/sections.h>
46
47
#include <asm/coco.h>
@@ -94,7 +95,7 @@ struct sme_populate_pgd_data {
94
95
*/
95
96
static char sme_workarea [2 * PMD_SIZE ] __section (".init.scratch" );
96
97
97
- static void __init sme_clear_pgd (struct sme_populate_pgd_data * ppd )
98
+ static void __head sme_clear_pgd (struct sme_populate_pgd_data * ppd )
98
99
{
99
100
unsigned long pgd_start , pgd_end , pgd_size ;
100
101
pgd_t * pgd_p ;
@@ -109,7 +110,7 @@ static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd)
109
110
memset (pgd_p , 0 , pgd_size );
110
111
}
111
112
112
- static pud_t __init * sme_prepare_pgd (struct sme_populate_pgd_data * ppd )
113
+ static pud_t __head * sme_prepare_pgd (struct sme_populate_pgd_data * ppd )
113
114
{
114
115
pgd_t * pgd ;
115
116
p4d_t * p4d ;
@@ -146,7 +147,7 @@ static pud_t __init *sme_prepare_pgd(struct sme_populate_pgd_data *ppd)
146
147
return pud ;
147
148
}
148
149
149
- static void __init sme_populate_pgd_large (struct sme_populate_pgd_data * ppd )
150
+ static void __head sme_populate_pgd_large (struct sme_populate_pgd_data * ppd )
150
151
{
151
152
pud_t * pud ;
152
153
pmd_t * pmd ;
@@ -162,7 +163,7 @@ static void __init sme_populate_pgd_large(struct sme_populate_pgd_data *ppd)
162
163
set_pmd (pmd , __pmd (ppd -> paddr | ppd -> pmd_flags ));
163
164
}
164
165
165
- static void __init sme_populate_pgd (struct sme_populate_pgd_data * ppd )
166
+ static void __head sme_populate_pgd (struct sme_populate_pgd_data * ppd )
166
167
{
167
168
pud_t * pud ;
168
169
pmd_t * pmd ;
@@ -188,7 +189,7 @@ static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd)
188
189
set_pte (pte , __pte (ppd -> paddr | ppd -> pte_flags ));
189
190
}
190
191
191
- static void __init __sme_map_range_pmd (struct sme_populate_pgd_data * ppd )
192
+ static void __head __sme_map_range_pmd (struct sme_populate_pgd_data * ppd )
192
193
{
193
194
while (ppd -> vaddr < ppd -> vaddr_end ) {
194
195
sme_populate_pgd_large (ppd );
@@ -198,7 +199,7 @@ static void __init __sme_map_range_pmd(struct sme_populate_pgd_data *ppd)
198
199
}
199
200
}
200
201
201
- static void __init __sme_map_range_pte (struct sme_populate_pgd_data * ppd )
202
+ static void __head __sme_map_range_pte (struct sme_populate_pgd_data * ppd )
202
203
{
203
204
while (ppd -> vaddr < ppd -> vaddr_end ) {
204
205
sme_populate_pgd (ppd );
@@ -208,7 +209,7 @@ static void __init __sme_map_range_pte(struct sme_populate_pgd_data *ppd)
208
209
}
209
210
}
210
211
211
- static void __init __sme_map_range (struct sme_populate_pgd_data * ppd ,
212
+ static void __head __sme_map_range (struct sme_populate_pgd_data * ppd ,
212
213
pmdval_t pmd_flags , pteval_t pte_flags )
213
214
{
214
215
unsigned long vaddr_end ;
@@ -232,22 +233,22 @@ static void __init __sme_map_range(struct sme_populate_pgd_data *ppd,
232
233
__sme_map_range_pte (ppd );
233
234
}
234
235
235
- static void __init sme_map_range_encrypted (struct sme_populate_pgd_data * ppd )
236
+ static void __head sme_map_range_encrypted (struct sme_populate_pgd_data * ppd )
236
237
{
237
238
__sme_map_range (ppd , PMD_FLAGS_ENC , PTE_FLAGS_ENC );
238
239
}
239
240
240
- static void __init sme_map_range_decrypted (struct sme_populate_pgd_data * ppd )
241
+ static void __head sme_map_range_decrypted (struct sme_populate_pgd_data * ppd )
241
242
{
242
243
__sme_map_range (ppd , PMD_FLAGS_DEC , PTE_FLAGS_DEC );
243
244
}
244
245
245
- static void __init sme_map_range_decrypted_wp (struct sme_populate_pgd_data * ppd )
246
+ static void __head sme_map_range_decrypted_wp (struct sme_populate_pgd_data * ppd )
246
247
{
247
248
__sme_map_range (ppd , PMD_FLAGS_DEC_WP , PTE_FLAGS_DEC_WP );
248
249
}
249
250
250
- static unsigned long __init sme_pgtable_calc (unsigned long len )
251
+ static unsigned long __head sme_pgtable_calc (unsigned long len )
251
252
{
252
253
unsigned long entries = 0 , tables = 0 ;
253
254
@@ -284,7 +285,7 @@ static unsigned long __init sme_pgtable_calc(unsigned long len)
284
285
return entries + tables ;
285
286
}
286
287
287
- void __init sme_encrypt_kernel (struct boot_params * bp )
288
+ void __head sme_encrypt_kernel (struct boot_params * bp )
288
289
{
289
290
unsigned long workarea_start , workarea_end , workarea_len ;
290
291
unsigned long execute_start , execute_end , execute_len ;
@@ -319,9 +320,8 @@ void __init sme_encrypt_kernel(struct boot_params *bp)
319
320
* memory from being cached.
320
321
*/
321
322
322
- /* Physical addresses gives us the identity mapped virtual addresses */
323
- kernel_start = __pa_symbol (_text );
324
- kernel_end = ALIGN (__pa_symbol (_end ), PMD_SIZE );
323
+ kernel_start = (unsigned long )RIP_REL_REF (_text );
324
+ kernel_end = ALIGN ((unsigned long )RIP_REL_REF (_end ), PMD_SIZE );
325
325
kernel_len = kernel_end - kernel_start ;
326
326
327
327
initrd_start = 0 ;
@@ -338,14 +338,6 @@ void __init sme_encrypt_kernel(struct boot_params *bp)
338
338
}
339
339
#endif
340
340
341
- /*
342
- * We're running identity mapped, so we must obtain the address to the
343
- * SME encryption workarea using rip-relative addressing.
344
- */
345
- asm ("lea sme_workarea(%%rip), %0"
346
- : "=r" (workarea_start )
347
- : "p" (sme_workarea ));
348
-
349
341
/*
350
342
* Calculate required number of workarea bytes needed:
351
343
* executable encryption area size:
@@ -355,7 +347,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)
355
347
* pagetable structures for the encryption of the kernel
356
348
* pagetable structures for workarea (in case not currently mapped)
357
349
*/
358
- execute_start = workarea_start ;
350
+ execute_start = workarea_start = ( unsigned long ) RIP_REL_REF ( sme_workarea ) ;
359
351
execute_end = execute_start + (PAGE_SIZE * 2 ) + PMD_SIZE ;
360
352
execute_len = execute_end - execute_start ;
361
353
@@ -498,7 +490,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp)
498
490
native_write_cr3 (__native_read_cr3 ());
499
491
}
500
492
501
- void __init sme_enable (struct boot_params * bp )
493
+ void __head sme_enable (struct boot_params * bp )
502
494
{
503
495
unsigned int eax , ebx , ecx , edx ;
504
496
unsigned long feature_mask ;
0 commit comments