From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Jan Beulich <JBeulich@suse.com>
Subject: [PATCH] xen/x86: Use 2M superpages for text/data/bss mappings
Date: Wed, 24 Feb 2016 19:07:35 +0000 [thread overview]
Message-ID: <1456340856-3065-8-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1456340856-3065-1-git-send-email-andrew.cooper3@citrix.com>
This balloons the size of Xen in memory from 4.4MB to 8MB, because of the
required alignment adjustments.
However
* All mappings are 2M superpages.
* .text (and .init at boot) are the only sections marked executable.
* .text and .rodata are marked read-only.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
v2:
* .data and .bss are adjcent (from earlier patch), so don't require 2M
alignment
v3:
* Move externs into an x86 location.
---
xen/arch/x86/setup.c | 38 +++++++++++++++++++++++++++++++++++---
xen/arch/x86/xen.lds.S | 27 +++++++++++++++++++++++++++
xen/include/asm-x86/setup.h | 5 +++++
3 files changed, 67 insertions(+), 3 deletions(-)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index cddf954..806fa95 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -920,14 +920,46 @@ void __init noreturn __start_xen(unsigned long mbi_p)
/* The only data mappings to be relocated are in the Xen area. */
pl2e = __va(__pa(l2_xenmap));
+ /*
+ * Undo the temporary-hooking of the l1_identmap. __2M_text_start
+ * is contained in this PTE.
+ */
*pl2e++ = l2e_from_pfn(xen_phys_start >> PAGE_SHIFT,
- PAGE_HYPERVISOR_RWX | _PAGE_PSE);
+ PAGE_HYPERVISOR_RX | _PAGE_PSE);
for ( i = 1; i < L2_PAGETABLE_ENTRIES; i++, pl2e++ )
{
+ unsigned int flags;
+
if ( !(l2e_get_flags(*pl2e) & _PAGE_PRESENT) )
continue;
- *pl2e = l2e_from_intpte(l2e_get_intpte(*pl2e) +
- xen_phys_start);
+
+ if ( i < l2_table_offset((unsigned long)&__2M_text_end) )
+ {
+ flags = PAGE_HYPERVISOR_RX | _PAGE_PSE;
+ }
+ else if ( i >= l2_table_offset((unsigned long)&__2M_rodata_start) &&
+ i < l2_table_offset((unsigned long)&__2M_rodata_end) )
+ {
+ flags = PAGE_HYPERVISOR_RO | _PAGE_PSE;
+ }
+ else if ( i >= l2_table_offset((unsigned long)&__2M_init_start) &&
+ i < l2_table_offset((unsigned long)&__2M_init_end) )
+ {
+ flags = PAGE_HYPERVISOR_RWX | _PAGE_PSE;
+ }
+ else if ( (i >= l2_table_offset((unsigned long)&__2M_rwdata_start) &&
+ i < l2_table_offset((unsigned long)&__2M_rwdata_end)) )
+ {
+ flags = PAGE_HYPERVISOR_RW | _PAGE_PSE;
+ }
+ else
+ {
+ *pl2e = l2e_empty();
+ continue;
+ }
+
+ *pl2e = l2e_from_paddr(
+ l2e_get_paddr(*pl2e) + xen_phys_start, flags);
}
/* Re-sync the stack and then switch to relocated pagetables. */
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index f78309d..77d0ed0 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -38,6 +38,9 @@ SECTIONS
. = __XEN_VIRT_START;
__image_base__ = .;
#endif
+
+ __2M_text_start = .; /* Start of 2M superpages, mapped RX. */
+
. = __XEN_VIRT_START + MB(1);
_start = .;
.text : {
@@ -50,6 +53,10 @@ SECTIONS
_etext = .; /* End of text section */
} :text = 0x9090
+ . = ALIGN(MB(2));
+ __2M_text_end = .;
+
+ __2M_rodata_start = .; /* Start of 2M superpages, mapped RO. */
.rodata : {
/* Bug frames table */
. = ALIGN(4);
@@ -74,6 +81,10 @@ SECTIONS
#endif
} :text
+ . = ALIGN(MB(2));
+ __2M_rodata_end = .;
+
+ __2M_init_start = .; /* Start of 2M superpages, mapped RWX (boot only). */
. = ALIGN(PAGE_SIZE); /* Init code and data */
__init_begin = .;
.init.text : {
@@ -136,6 +147,10 @@ SECTIONS
. = ALIGN(PAGE_SIZE);
__init_end = .;
+ . = ALIGN(MB(2));
+ __2M_init_end = .;
+
+ __2M_rwdata_start = .; /* Start of 2M superpages, mapped RW. */
. = ALIGN(SMP_CACHE_BYTES);
.data.read_mostly : {
/* Exception table */
@@ -184,6 +199,9 @@ SECTIONS
} :text
_end = . ;
+ . = ALIGN(MB(2));
+ __2M_rwdata_end = .;
+
#ifdef EFI
. = ALIGN(4);
.reloc : {
@@ -230,4 +248,13 @@ ASSERT(__image_base__ > XEN_VIRT_START ||
ASSERT(kexec_reloc_size - kexec_reloc <= PAGE_SIZE, "kexec_reloc is too large")
#endif
+ASSERT(IS_ALIGNED(__2M_text_start, MB(2)), "__2M_text_start misaligned")
+ASSERT(IS_ALIGNED(__2M_text_end, MB(2)), "__2M_text_end misaligned")
+ASSERT(IS_ALIGNED(__2M_rodata_start, MB(2)), "__2M_rodata_start misaligned")
+ASSERT(IS_ALIGNED(__2M_rodata_end, MB(2)), "__2M_rodata_end misaligned")
+ASSERT(IS_ALIGNED(__2M_init_start, MB(2)), "__2M_init_start misaligned")
+ASSERT(IS_ALIGNED(__2M_init_end, MB(2)), "__2M_init_end misaligned")
+ASSERT(IS_ALIGNED(__2M_rwdata_start, MB(2)), "__2M_rwdata_start misaligned")
+ASSERT(IS_ALIGNED(__2M_rwdata_end, MB(2)), "__2M_rwdata_end misaligned")
+
ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned")
diff --git a/xen/include/asm-x86/setup.h b/xen/include/asm-x86/setup.h
index 381d9f8..c65b79c 100644
--- a/xen/include/asm-x86/setup.h
+++ b/xen/include/asm-x86/setup.h
@@ -4,6 +4,11 @@
#include <xen/multiboot.h>
#include <asm/numa.h>
+extern const char __2M_text_start[], __2M_text_end[];
+extern const char __2M_rodata_start[], __2M_rodata_end[];
+extern char __2M_init_start[], __2M_init_end[];
+extern char __2M_rwdata_start[], __2M_rwdata_end[];
+
extern unsigned long xenheap_initial_phys_start;
void early_cpu_init(void);
--
2.1.4
next prev parent reply other threads:[~2016-02-24 19:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 19:07 [PATCH] Map Xen code/data/bss with superpages Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/lockprof: Move .lockprofile.data into .rodata Andrew Cooper
2016-02-25 11:02 ` Stefano Stabellini
2016-02-25 11:12 ` Stefano Stabellini
2016-02-24 19:07 ` [PATCH] xen/x86: Improvements to build-time pagetable generation Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Construct the {l2, l3}_bootmap at compile time Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/memguard: Drop memguard_init() entirely Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Disable CR0.WP while applying alternatives Andrew Cooper
2016-02-24 19:07 ` [PATCH] xen/x86: Reorder .data and .init when linking Andrew Cooper
2016-02-24 19:07 ` Andrew Cooper [this message]
2016-02-24 19:07 ` [PATCH] xen/x86: Unilaterally remove .init mappings Andrew Cooper
-- strict thread matches above, loose matches on Subject: below --
2016-02-18 18:03 [PATCH] xen/x86: Map Xen code/data/bss with superpages Andrew Cooper
2016-02-18 18:03 ` [PATCH] xen/x86: Use 2M superpages for text/data/bss mappings Andrew Cooper
2016-02-19 14:58 ` Jan Beulich
2016-02-19 15:51 ` Andrew Cooper
2016-02-22 9:55 ` Jan Beulich
2016-02-22 10:24 ` Andrew Cooper
2016-02-22 10:43 ` Jan Beulich
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=1456340856-3065-8-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.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).