From: Baoquan He <bhe@redhat.com>
To: tglx@linutronix.de, hpa@zytor.com, mingo@redhat.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
keescook@chromium.org, yinghai@kernel.org, bp@suse.de,
thgarnie@google.com, kuleshovmail@gmail.com, luto@kernel.org,
mcgrof@kernel.org, anderson@redhat.com, dyoung@redhat.com,
Baoquan He <bhe@redhat.com>
Subject: [PATCH v3 1/3] x86/64: Make kernel text mapping always take one whole page table in early boot code
Date: Wed, 4 Jan 2017 16:37:31 +0800 [thread overview]
Message-ID: <1483519053-23402-2-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1483519053-23402-1-git-send-email-bhe@redhat.com>
In early boot code level2_kernel_pgt is used to map kernel text. And its
size varies with KERNEL_IMAGE_SIZE and fixed at compiling time. In fact
we can make it always take 512 entries of one whole page table, because
later function cleanup_highmap will clean up the unused entries. With the
help of this change kernel text mapping size can be decided at runtime
later, 512M if kaslr is disabled, 1G if kaslr is enabled.
Signed-off-by: Baoquan He <bhe@redhat.com>
Acked-by: Kees Cook <keescook@chromium.org>
---
arch/x86/include/asm/page_64_types.h | 3 ++-
arch/x86/kernel/head_64.S | 15 ++++++++-------
arch/x86/mm/init_64.c | 2 +-
3 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
index 9215e05..62a20ea 100644
--- a/arch/x86/include/asm/page_64_types.h
+++ b/arch/x86/include/asm/page_64_types.h
@@ -56,8 +56,9 @@
* are fully set up. If kernel ASLR is configured, it can extend the
* kernel page table mapping, reducing the size of the modules area.
*/
+#define KERNEL_MAPPING_SIZE_EXT (1024 * 1024 * 1024)
#if defined(CONFIG_RANDOMIZE_BASE)
-#define KERNEL_IMAGE_SIZE (1024 * 1024 * 1024)
+#define KERNEL_IMAGE_SIZE KERNEL_MAPPING_SIZE_EXT
#else
#define KERNEL_IMAGE_SIZE (512 * 1024 * 1024)
#endif
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index b467b14..03bcb67 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -458,17 +458,18 @@ NEXT_PAGE(level3_kernel_pgt)
NEXT_PAGE(level2_kernel_pgt)
/*
- * 512 MB kernel mapping. We spend a full page on this pagetable
- * anyway.
+ * Kernel image size is limited to 512 MB. The kernel code+data+bss
+ * must not be bigger than that.
*
- * The kernel code+data+bss must not be bigger than that.
+ * We spend a full page on this pagetable anyway, so take the whole
+ * page here so that the kernel mapping size can be decided at runtime,
+ * 512M if no kaslr, 1G if kaslr enabled. Later cleanup_highmap will
+ * clean up those unused entries.
*
- * (NOTE: at +512MB starts the module area, see MODULES_VADDR.
- * If you want to increase this then increase MODULES_VADDR
- * too.)
+ * The module area starts after kernel mapping area.
*/
PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
- KERNEL_IMAGE_SIZE/PMD_SIZE)
+ PTRS_PER_PMD)
NEXT_PAGE(level2_fixmap_pgt)
.fill 506,8,0
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index af85b68..45ef0ff 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -297,7 +297,7 @@ void __init init_extra_mapping_uc(unsigned long phys, unsigned long size)
void __init cleanup_highmap(void)
{
unsigned long vaddr = __START_KERNEL_map;
- unsigned long vaddr_end = __START_KERNEL_map + KERNEL_IMAGE_SIZE;
+ unsigned long vaddr_end = __START_KERNEL_map + KERNEL_MAPPING_SIZE_EXT;
unsigned long end = roundup((unsigned long)_brk_end, PMD_SIZE) - 1;
pmd_t *pmd = level2_kernel_pgt;
--
2.5.5
next prev parent reply other threads:[~2017-01-04 8:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-04 8:37 [PATCH v3 0/3] Determine kernel image mapping size at runtime for x86_64 Baoquan He
2017-01-04 8:37 ` Baoquan He [this message]
2017-01-04 13:00 ` [PATCH v3 1/3] x86/64: Make kernel text mapping always take one whole page table in early boot code Boris Petkov
2017-01-05 3:28 ` Baoquan He
2017-01-05 14:01 ` Borislav Petkov
2017-01-05 19:35 ` Kees Cook
2017-01-05 20:52 ` Borislav Petkov
2017-01-06 9:35 ` Baoquan He
2017-01-04 8:37 ` [PATCH v3 2/3] x86/64: Introduce a new constant KERNEL_MAPPING_SIZE Baoquan He
2017-01-04 8:37 ` [PATCH v3 3/3] x86/64/KASLR: Determine the kernel mapping size at run time Baoquan He
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=1483519053-23402-2-git-send-email-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=anderson@redhat.com \
--cc=bp@suse.de \
--cc=dyoung@redhat.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kuleshovmail@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mcgrof@kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=thgarnie@google.com \
--cc=x86@kernel.org \
--cc=yinghai@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