Skip to content

Commit 5ed0a99

Browse files
committed
x86/head64: Carve out the guest encryption postprocessing into a helper
Carve it out so that it is abstracted out of the main boot path. All other encrypted guest-relevant processing should be placed in there. No functional changes. Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent dbc4c70 commit 5ed0a99

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

arch/x86/kernel/head64.c

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,36 @@ static bool __head check_la57_support(unsigned long physaddr)
126126
}
127127
#endif
128128

129+
static unsigned long sme_postprocess_startup(struct boot_params *bp, pmdval_t *pmd)
130+
{
131+
unsigned long vaddr, vaddr_end;
132+
int i;
133+
134+
/* Encrypt the kernel and related (if SME is active) */
135+
sme_encrypt_kernel(bp);
136+
137+
/*
138+
* Clear the memory encryption mask from the .bss..decrypted section.
139+
* The bss section will be memset to zero later in the initialization so
140+
* there is no need to zero it after changing the memory encryption
141+
* attribute.
142+
*/
143+
if (sme_get_me_mask()) {
144+
vaddr = (unsigned long)__start_bss_decrypted;
145+
vaddr_end = (unsigned long)__end_bss_decrypted;
146+
for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
147+
i = pmd_index(vaddr);
148+
pmd[i] -= sme_get_me_mask();
149+
}
150+
}
151+
152+
/*
153+
* Return the SME encryption mask (if SME is active) to be used as a
154+
* modifier for the initial pgdir entry programmed into CR3.
155+
*/
156+
return sme_get_me_mask();
157+
}
158+
129159
/* Code in __startup_64() can be relocated during execution, but the compiler
130160
* doesn't have to generate PC-relative relocations when accessing globals from
131161
* that function. Clang actually does not generate them, which leads to
@@ -135,7 +165,6 @@ static bool __head check_la57_support(unsigned long physaddr)
135165
unsigned long __head __startup_64(unsigned long physaddr,
136166
struct boot_params *bp)
137167
{
138-
unsigned long vaddr, vaddr_end;
139168
unsigned long load_delta, *p;
140169
unsigned long pgtable_flags;
141170
pgdval_t *pgd;
@@ -276,34 +305,7 @@ unsigned long __head __startup_64(unsigned long physaddr,
276305
*/
277306
*fixup_long(&phys_base, physaddr) += load_delta - sme_get_me_mask();
278307

279-
/* Encrypt the kernel and related (if SME is active) */
280-
sme_encrypt_kernel(bp);
281-
282-
/*
283-
* Clear the memory encryption mask from the .bss..decrypted section.
284-
* The bss section will be memset to zero later in the initialization so
285-
* there is no need to zero it after changing the memory encryption
286-
* attribute.
287-
*
288-
* This is early code, use an open coded check for SME instead of
289-
* using cc_platform_has(). This eliminates worries about removing
290-
* instrumentation or checking boot_cpu_data in the cc_platform_has()
291-
* function.
292-
*/
293-
if (sme_get_me_mask()) {
294-
vaddr = (unsigned long)__start_bss_decrypted;
295-
vaddr_end = (unsigned long)__end_bss_decrypted;
296-
for (; vaddr < vaddr_end; vaddr += PMD_SIZE) {
297-
i = pmd_index(vaddr);
298-
pmd[i] -= sme_get_me_mask();
299-
}
300-
}
301-
302-
/*
303-
* Return the SME encryption mask (if SME is active) to be used as a
304-
* modifier for the initial pgdir entry programmed into CR3.
305-
*/
306-
return sme_get_me_mask();
308+
return sme_postprocess_startup(bp, pmd);
307309
}
308310

309311
unsigned long __startup_secondary_64(void)

0 commit comments

Comments
 (0)