]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/kexec: Clean up and document register use in relocate_kernel_64.S
authorDavid Woodhouse <dwmw@amazon.co.uk>
Sat, 2 Nov 2024 22:32:29 +0000 (22:32 +0000)
committerDavid Woodhouse <dwmw@amazon.co.uk>
Thu, 5 Dec 2024 14:47:11 +0000 (14:47 +0000)
Add more comments explaining what each register contains, and save the
preserve_context flag to a non-clobbered register sooner, to keep things
simpler.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Acked-by: Kai Huang <kai.huang@intel.com>
arch/x86/kernel/relocate_kernel_64.S

index 1236f25fc8d1206854bc378301564701c1085e30..92478e2e254f415c5242669facda59c6be8a05b7 100644 (file)
@@ -100,6 +100,9 @@ SYM_CODE_START_NOALIGN(relocate_kernel)
        movq    %r10, CP_PA_SWAP_PAGE(%r11)
        movq    %rdi, CP_PA_BACKUP_PAGES_MAP(%r11)
 
+       /* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */
+       movq    %rcx, %r11
+
        /* Switch to the identity mapped page tables */
        movq    %r9, %cr3
 
@@ -116,6 +119,14 @@ SYM_CODE_END(relocate_kernel)
 
 SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
        UNWIND_HINT_END_OF_STACK
+       /*
+        * %rdi indirection page
+        * %rdx start address
+        * %r11 preserve_context
+        * %r12 host_mem_enc_active
+        * %r13 original CR4 when relocate_kernel() was invoked
+        */
+
        /* set return address to 0 if not preserving context */
        pushq   $0
        /* store the start address on the stack */
@@ -170,8 +181,6 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
        wbinvd
 .Lsme_off:
 
-       /* Save the preserve_context to %r11 as swap_pages clobbers %rcx. */
-       movq    %rcx, %r11
        call    swap_pages
 
        /*
@@ -183,13 +192,14 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped)
        movq    %cr3, %rax
        movq    %rax, %cr3
 
+       testq   %r11, %r11      /* preserve_context */
+       jnz .Lrelocate
+
        /*
         * set all of the registers to known values
         * leave %rsp alone
         */
 
-       testq   %r11, %r11
-       jnz .Lrelocate
        xorl    %eax, %eax
        xorl    %ebx, %ebx
        xorl    %ecx, %ecx