From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Andy Lutomirski <luto@amacapital.net>,
Cyrill Gorcunov <gorcunov@openvz.org>,
Borislav Petkov <bp@suse.de>, Andi Kleen <ak@linux.intel.com>,
Matthew Wilcox <willy@infradead.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCHv7 5/4] x86/boot/compressed/64: Support switching from 5- to 4-level paging
Date: Tue, 30 Jan 2018 16:52:36 +0300 [thread overview]
Message-ID: <20180130135239.72244-3-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <20180130135239.72244-1-kirill.shutemov@linux.intel.com>
If a bootloader enabled 5-level paging before handing off control to
kernel, we may want to switch it to 4-level paging when kernel is
compiled with CONFIG_X86_5LEVEL=n.
Let's modify decompression code to handle the situation.
This will fail if the kernel image is loaded above 64TiB since 4-level
paging would not be able to access the image.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
arch/x86/boot/compressed/head_64.S | 17 +++++++++++++++--
arch/x86/boot/compressed/pgtable.h | 2 +-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index f5ac9a6515ef..5942b7d9d6a2 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -520,19 +520,32 @@ ENTRY(trampoline_32bit_src)
btrl $X86_CR0_PG_BIT, %eax
movl %eax, %cr0
- /* For 5-level paging, point CR3 to the trampoline's new top level page table */
+ /* Check what paging mode we want to be in after the trampoline */
cmpl $0, %edx
jz 1f
/* Don't touch CR3 if it already points to 5-level page tables */
movl %cr4, %eax
testl $X86_CR4_LA57, %eax
- jnz 1f
+ jnz 2f
+ /* For 5-level paging, point CR3 to the trampoline's new top level page table */
leal TRAMPOLINE_32BIT_PGTABLE_OFFSET(%ecx), %eax
movl %eax, %cr3
1:
+ /* Don't touch CR3 if it already points to 4-level page tables */
+ movl %cr4, %eax
+ testl $X86_CR4_LA57, %eax
+ jz 2f
+ /*
+ * We are in 5-level paging mode, but we want to switch to 4-level.
+ * Let's take the first entry in the top-level page table as our new CR3.
+ */
+ movl %cr3, %eax
+ movl (%eax), %eax
+ movl %eax, %cr3
+2:
/* Enable PAE and LA57 (if required) paging modes */
movl %cr4, %eax
orl $X86_CR4_PAE, %eax
diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h
index 6e0db2260147..cd62c546afd5 100644
--- a/arch/x86/boot/compressed/pgtable.h
+++ b/arch/x86/boot/compressed/pgtable.h
@@ -6,7 +6,7 @@
#define TRAMPOLINE_32BIT_PGTABLE_OFFSET 0
#define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE
-#define TRAMPOLINE_32BIT_CODE_SIZE 0x60
+#define TRAMPOLINE_32BIT_CODE_SIZE 0x70
#define TRAMPOLINE_32BIT_STACK_END TRAMPOLINE_32BIT_SIZE
--
2.15.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2018-01-30 13:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-30 13:52 [PATCHv8 0/4] x86: 5-level related changes into decompression code Kirill A. Shutemov
2018-01-30 13:52 ` [PATCHv8 1/4] x86/boot/compressed/64: Rename pagetable.c to kaslr_64.c Kirill A. Shutemov
2018-01-30 13:52 ` Kirill A. Shutemov [this message]
2018-01-30 13:56 ` [PATCHv7 5/4] x86/boot/compressed/64: Support switching from 5- to 4-level paging Kirill A. Shutemov
2018-01-30 13:52 ` [PATCHv8 2/4] x86/boot/compressed/64: Introduce paging_prepare() Kirill A. Shutemov
2018-01-30 13:52 ` [PATCHv8 3/4] x86/boot/compressed/64: Prepare trampoline memory Kirill A. Shutemov
2018-01-30 13:52 ` [PATCHv8 4/4] x86/boot/compressed/64: Handle 5-level paging boot if kernel is above 4G Kirill A. Shutemov
-- strict thread matches above, loose matches on Subject: below --
2018-01-29 11:53 [PATCHv7 0/4] x86: 5-level related changes into decompression code Kirill A. Shutemov
2018-01-29 15:07 ` [PATCHv7 5/4] x86/boot/compressed/64: Support switching from 5- to 4-level paging Kirill A. Shutemov
2018-01-29 15:39 ` Kirill A. Shutemov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180130135239.72244-3-kirill.shutemov@linux.intel.com \
--to=kirill.shutemov@linux.intel.com \
--cc=ak@linux.intel.com \
--cc=bp@suse.de \
--cc=gorcunov@openvz.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@amacapital.net \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=willy@infradead.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).