]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
x86/kexec: Use correct swap page in swap_pages function
authorDavid Woodhouse <dwmw@amazon.co.uk>
Thu, 9 Jan 2025 14:04:15 +0000 (14:04 +0000)
committerBorislav Petkov (AMD) <bp@alien8.de>
Tue, 14 Jan 2025 11:54:36 +0000 (12:54 +0100)
The swap_pages function expects the swap page to be in %r10, but there
was no documentation to that effect. Once upon a time the setup code
used to load its value from a kernel virtual address and save it to an
address which is accessible in the identity-mapped page tables, and
*happened* to use %r10 to do so, with no comment that it was left there
on *purpose* instead of just being a scratch register. Once that was no
longer necessary, %r10 just holds whatever the kernel happened to leave
in it.

Now that the original value passed by the kernel is accessible via
%rip-relative addressing, load directly from there instead of using %r10
for it. But document the other parameters that the swap_pages function
*does* expect in registers.

Fixes: b3adabae8a96 ("x86/kexec: Drop page_list argument from relocate_kernel()")
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20250109140757.2841269-4-dwmw2@infradead.org
arch/x86/kernel/relocate_kernel_64.S

index 6fce4b459652c1d98fa821b523c225633ee85955..3ca3bf6b3f49745d11850244f80f0c8c2b777157 100644 (file)
@@ -264,6 +264,10 @@ SYM_CODE_END(virtual_mapped)
        /* Do the copies */
 SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
        UNWIND_HINT_END_OF_STACK
+       /*
+        * %rdi indirection page
+        * %r11 preserve_context
+        */
        movq    %rdi, %rcx      /* Put the indirection_page in %rcx */
        xorl    %edi, %edi
        xorl    %esi, %esi
@@ -302,7 +306,7 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
        jz      .Lnoswap
 
        /* copy source page to swap page */
-       movq    %r10, %rdi
+       movq    kexec_pa_swap_page(%rip), %rdi
        movl    $512, %ecx
        rep ; movsq
 
@@ -314,7 +318,7 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages)
 
        /* copy swap page to destination page */
        movq    %rdx, %rdi
-       movq    %r10, %rsi
+       movq    kexec_pa_swap_page(%rip), %rsi
 .Lnoswap:
        movl    $512, %ecx
        rep ; movsq