Misc comments fixup in relocate_kernel_64.S
v2 cover Misc comments fixup in relocate_kernel_64.S
The assembly code of relcocate_kernel() takes some time to follow for newbies like me. This series adds some comments to try to improve the readability hoping they could be helpful to others too. Also fix an error (IIUC) in one comment.
v1 -> v2:
- Add Kirill's tag.
v1: https://lore.kernel.org/lkml/q2y5vte3wwn5qde5p4nfmjfqtzxfen3nhjdyafc7nbirfidpvr@ro3djjz3pub4/T/
Kai Huang (2):
x86/kexec: Fix a comment of swap_pages() assembly x86/kexec: Add comments around swap_pages() assembly to improve
readability
arch/x86/kernel/relocate_kernel_64.S | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
base-commit: e77f8f275278886d05ce6dfe9e3bc854e7bf0713
Signature · 1 line
2.46.0
PATCH v2 1/2 x86/kexec: Fix a comment of swap_pages() assembly
When relocate_kernel() gets called, %rdi holds 'indirection_page' and %rsi holds 'page_list'. And %rdi always holds 'indirection_page' when swap_pages() is called.
Therefore the comment of the first line code of swap_pages()
movq %rdi, %rcx /* Put the page_list in %rcx */
.. isn't correct because it actually moves the 'indirection_page' to the %rcx. Fix it.
--- arch/x86/kernel/relocate_kernel_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/relocate_kernel_64.S +1 -1
@@ -258,7 +258,7 @@ SYM_CODE_END(virtual_mapped) /* Do the copies */ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) UNWIND_HINT_END_OF_STACK - movq %rdi, %rcx /* Put the page_list in %rcx */ + movq %rdi, %rcx /* Put the indirection_page in %rcx */ xorl %edi, %edi xorl %esi, %esi jmp 1f
Signature · 1 line
2.46.0
PATCH v2 2/2 x86/kexec: Add comments around swap_pages() assembly to improve readability
In reply to Kai HuangThe current assembly around swap_pages() in the relocate_kernel() takes some time to follow because the use of registers can be easily lost when the line of assembly goes long. Add a couple of comments to clarify the code around swap_pages() to improve readability.
--- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/relocate_kernel_64.S +6 -2
@@ -170,6 +170,7 @@ 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
@@ -289,18 +290,21 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) movq %rcx, %rsi /* For ever source page do a copy */ andq $0xfffffffffffff000, %rsi - movq %rdi, %rdx - movq %rsi, %rax + movq %rdi, %rdx /* Save destination page to %rdx */ + movq %rsi, %rax /* Save source page to %rax */ + /* copy source page to swap page */ movq %r10, %rdi movl $512, %ecx rep ; movsq + /* copy destination page to source page */ movq %rax, %rdi movq %rdx, %rsi movl $512, %ecx rep ; movsq + /* copy swap page to destination page */ movq %rdx, %rdi movq %r10, %rsi movl $512, %ecx
Signature · 1 line
2.46.0
[tip: x86/cleanups] x86/kexec: Fix a comment of swap_pages() assembly
In reply to Kai HuangThe following commit has been merged into the x86/cleanups branch of tip:
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: 3c41ad39f179c0e41f585975eb6834cd14f286ec Gitweb: https://git.kernel.org/tip/3c41ad39f179c0e41f585975eb6834cd14f286ec Author: Kai Huang <[email protected]> AuthorDate: Sun, 25 Aug 2024 20:18:05 +12:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sun, 25 Aug 2024 14:29:39 +02:00
x86/kexec: Fix a comment of swap_pages() assembly
When relocate_kernel() gets called, %rdi holds 'indirection_page' and %rsi holds 'page_list'. And %rdi always holds 'indirection_page' when swap_pages() is called.
Therefore the comment of the first line code of swap_pages()
movq %rdi, %rcx /* Put the page_list in %rcx */
.. isn't correct because it actually moves the 'indirection_page' to the %rcx. Fix it.
--- arch/x86/kernel/relocate_kernel_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/relocate_kernel_64.S +1 -1
@@ -258,7 +258,7 @@ SYM_CODE_END(virtual_mapped) /* Do the copies */ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) UNWIND_HINT_END_OF_STACK - movq %rdi, %rcx /* Put the page_list in %rcx */ + movq %rdi, %rcx /* Put the indirection_page in %rcx */ xorl %edi, %edi xorl %esi, %esi jmp 1f
[tip: x86/cleanups] x86/kexec: Add comments around swap_pages() assembly to improve readability
In reply to Kai HuangThe following commit has been merged into the x86/cleanups branch of tip:
The following commit has been merged into the x86/cleanups branch of tip:
Commit-ID: ea49cdb26e7cffc261ceb1db26707e6d337fa104 Gitweb: https://git.kernel.org/tip/ea49cdb26e7cffc261ceb1db26707e6d337fa104 Author: Kai Huang <[email protected]> AuthorDate: Sun, 25 Aug 2024 20:18:06 +12:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Sun, 25 Aug 2024 14:29:39 +02:00
x86/kexec: Add comments around swap_pages() assembly to improve readability
The current assembly around swap_pages() in the relocate_kernel() takes some time to follow because the use of registers can be easily lost when the line of assembly goes long. Add a couple of comments to clarify the code around swap_pages() to improve readability.
--- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kernel/relocate_kernel_64.S +6 -2
@@ -170,6 +170,7 @@ 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
@@ -289,18 +290,21 @@ SYM_CODE_START_LOCAL_NOALIGN(swap_pages) movq %rcx, %rsi /* For ever source page do a copy */ andq $0xfffffffffffff000, %rsi - movq %rdi, %rdx - movq %rsi, %rax + movq %rdi, %rdx /* Save destination page to %rdx */ + movq %rsi, %rax /* Save source page to %rax */ + /* copy source page to swap page */ movq %r10, %rdi movl $512, %ecx rep ; movsq + /* copy destination page to source page */ movq %rax, %rdi movq %rdx, %rsi movl $512, %ecx rep ; movsq + /* copy swap page to destination page */ movq %rdx, %rdi movq %r10, %rsi movl $512, %ecx