* [PATCH v2 0/2] Misc comments fixup in relocate_kernel_64.S
@ 2024-08-25 8:18 Kai Huang
2024-08-25 8:18 ` [PATCH v2 1/2] x86/kexec: Fix a comment of swap_pages() assembly Kai Huang
2024-08-25 8:18 ` [PATCH v2 2/2] x86/kexec: Add comments around swap_pages() assembly to improve readability Kai Huang
0 siblings, 2 replies; 5+ messages in thread
From: Kai Huang @ 2024-08-25 8:18 UTC (permalink / raw)
To: tglx, mingo, bp, dave.hansen, hpa, peterz
Cc: kirill.shutemov, x86, linux-kernel, nik.borisov
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
--
2.46.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 1/2] x86/kexec: Fix a comment of swap_pages() assembly 2024-08-25 8:18 [PATCH v2 0/2] Misc comments fixup in relocate_kernel_64.S Kai Huang @ 2024-08-25 8:18 ` Kai Huang 2024-08-25 12:37 ` [tip: x86/cleanups] " tip-bot2 for Kai Huang 2024-08-25 8:18 ` [PATCH v2 2/2] x86/kexec: Add comments around swap_pages() assembly to improve readability Kai Huang 1 sibling, 1 reply; 5+ messages in thread From: Kai Huang @ 2024-08-25 8:18 UTC (permalink / raw) To: tglx, mingo, bp, dave.hansen, hpa, peterz Cc: kirill.shutemov, x86, linux-kernel, nik.borisov 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. Signed-off-by: Kai Huang <kai.huang@intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> --- arch/x86/kernel/relocate_kernel_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 042c9a0334e9..f7a3ca3dee53 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -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 -- 2.46.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/cleanups] x86/kexec: Fix a comment of swap_pages() assembly 2024-08-25 8:18 ` [PATCH v2 1/2] x86/kexec: Fix a comment of swap_pages() assembly Kai Huang @ 2024-08-25 12:37 ` tip-bot2 for Kai Huang 0 siblings, 0 replies; 5+ messages in thread From: tip-bot2 for Kai Huang @ 2024-08-25 12:37 UTC (permalink / raw) To: linux-tip-commits Cc: Kai Huang, Thomas Gleixner, Kirill A. Shutemov, x86, linux-kernel 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 <kai.huang@intel.com> AuthorDate: Sun, 25 Aug 2024 20:18:05 +12:00 Committer: Thomas Gleixner <tglx@linutronix.de> 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. Signed-off-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/all/adafdfb1421c88efce04420fc9a996c0e2ca1b34.1724573384.git.kai.huang@intel.com --- arch/x86/kernel/relocate_kernel_64.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 042c9a0..f7a3ca3 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] x86/kexec: Add comments around swap_pages() assembly to improve readability 2024-08-25 8:18 [PATCH v2 0/2] Misc comments fixup in relocate_kernel_64.S Kai Huang 2024-08-25 8:18 ` [PATCH v2 1/2] x86/kexec: Fix a comment of swap_pages() assembly Kai Huang @ 2024-08-25 8:18 ` Kai Huang 2024-08-25 12:37 ` [tip: x86/cleanups] " tip-bot2 for Kai Huang 1 sibling, 1 reply; 5+ messages in thread From: Kai Huang @ 2024-08-25 8:18 UTC (permalink / raw) To: tglx, mingo, bp, dave.hansen, hpa, peterz Cc: kirill.shutemov, x86, linux-kernel, nik.borisov 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. Signed-off-by: Kai Huang <kai.huang@intel.com> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> --- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index f7a3ca3dee53..e9e88c342f75 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -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 -- 2.46.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [tip: x86/cleanups] x86/kexec: Add comments around swap_pages() assembly to improve readability 2024-08-25 8:18 ` [PATCH v2 2/2] x86/kexec: Add comments around swap_pages() assembly to improve readability Kai Huang @ 2024-08-25 12:37 ` tip-bot2 for Kai Huang 0 siblings, 0 replies; 5+ messages in thread From: tip-bot2 for Kai Huang @ 2024-08-25 12:37 UTC (permalink / raw) To: linux-tip-commits Cc: Kai Huang, Thomas Gleixner, Kirill A. Shutemov, x86, linux-kernel 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 <kai.huang@intel.com> AuthorDate: Sun, 25 Aug 2024 20:18:06 +12:00 Committer: Thomas Gleixner <tglx@linutronix.de> 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. Signed-off-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Link: https://lore.kernel.org/all/8b52b0b8513a34b2a02fb4abb05c6700c2821475.1724573384.git.kai.huang@intel.com --- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index f7a3ca3..e9e88c3 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-08-25 12:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-08-25 8:18 [PATCH v2 0/2] Misc comments fixup in relocate_kernel_64.S Kai Huang 2024-08-25 8:18 ` [PATCH v2 1/2] x86/kexec: Fix a comment of swap_pages() assembly Kai Huang 2024-08-25 12:37 ` [tip: x86/cleanups] " tip-bot2 for Kai Huang 2024-08-25 8:18 ` [PATCH v2 2/2] x86/kexec: Add comments around swap_pages() assembly to improve readability Kai Huang 2024-08-25 12:37 ` [tip: x86/cleanups] " tip-bot2 for Kai Huang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox