Skip to content

Commit b7155df

Browse files
dwmw2Ingo Molnar
authored andcommitted
x86/kexec: Eliminate writes through kernel mapping of relocate_kernel page
All writes to the relocate_kernel control page are now done *after* the %cr3 switch via simple %rip-relative addressing, which means the DATA() macro with its pointer arithmetic can also now be removed. Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Baoquan He <[email protected]> Cc: Vivek Goyal <[email protected]> Cc: Dave Young <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b3adaba commit b7155df

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

arch/x86/kernel/relocate_kernel_64.S

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,24 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
6161
pushq %r15
6262
pushf
6363

64-
movq %rsp, saved_rsp(%rip)
65-
movq %cr0, %rax
66-
movq %rax, saved_cr0(%rip)
67-
movq %cr3, %rax
68-
movq %rax, saved_cr3(%rip)
69-
movq %cr4, %rax
70-
movq %rax, saved_cr4(%rip)
71-
72-
/* Save CR4. Required to enable the right paging mode later. */
73-
movq %rax, %r13
74-
7564
/* zero out flags, and disable interrupts */
7665
pushq $0
7766
popfq
7867

68+
/* Switch to the identity mapped page tables */
69+
movq %cr3, %rax
70+
movq kexec_pa_table_page(%rip), %r9
71+
movq %r9, %cr3
72+
73+
/* Save %rsp and CRs. */
74+
movq %rsp, saved_rsp(%rip)
75+
movq %rax, saved_cr3(%rip)
76+
movq %cr0, %rax
77+
movq %rax, saved_cr0(%rip)
78+
/* Leave CR4 in %r13 to enable the right paging mode later. */
79+
movq %cr4, %r13
80+
movq %r13, saved_cr4(%rip)
81+
7982
/* Save SME active flag */
8083
movq %r8, %r12
8184

@@ -85,10 +88,6 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
8588
/* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */
8689
movq %rcx, %r11
8790

88-
/* Switch to the identity mapped page tables */
89-
movq kexec_pa_table_page(%rip), %r9
90-
movq %r9, %cr3
91-
9291
/* Physical address of control page */
9392
movq %rsi, %r8
9493

0 commit comments

Comments
 (0)