From: Wei Liu <wl@xen.org>
To: Xen Development List <xen-devel@lists.xenproject.org>
Cc: "Wei Liu" <liuwe@microsoft.com>, "Wei Liu" <wl@xen.org>,
"Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Paul Durrant" <pdurrant@amazon.com>,
"Michael Kelley" <mikelley@microsoft.com>,
"Ross Lagerwall" <ross.lagerwall@citrix.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility
Date: Wed, 29 Jan 2020 20:20:27 +0000 [thread overview]
Message-ID: <20200129202034.15052-6-liuwe@microsoft.com> (raw)
In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com>
This allows us to set aside some address space for executable mapping.
This fixed map range starts from XEN_VIRT_END so that it is within reach
of the .text section.
Shift the percpu stub range and shrink livepatch range accordingly.
Signed-off-by: Wei Liu <liuwe@microsoft.com>
---
v5:
1. drop __virt_to_fix_x
2. also check FIX*_RESERVED in __set_fixmap*
3. generate global symbol to be used in linker script
4. address other misc comments
---
xen/arch/x86/boot/x86_64.S | 15 ++++++++++++---
xen/arch/x86/livepatch.c | 3 ++-
xen/arch/x86/mm.c | 15 ++++++++++++++-
xen/arch/x86/smpboot.c | 2 +-
xen/arch/x86/xen.lds.S | 3 +++
xen/include/asm-x86/config.h | 2 +-
xen/include/asm-x86/fixmap.h | 25 +++++++++++++++++++++++++
7 files changed, 58 insertions(+), 7 deletions(-)
diff --git a/xen/arch/x86/boot/x86_64.S b/xen/arch/x86/boot/x86_64.S
index 1cbf5acdfb..314a32a19f 100644
--- a/xen/arch/x86/boot/x86_64.S
+++ b/xen/arch/x86/boot/x86_64.S
@@ -81,11 +81,20 @@ GLOBAL(l2_directmap)
.size l2_directmap, . - l2_directmap
/*
- * L2 mapping the Xen text/data/bss region, constructed dynamically. Uses 1x
- * 4k page.
+ * L2 mapping the Xen text/data/bss region, constructed dynamically.
+ * Executable fixmap is hooked up statically.
+ * Uses 1x 4k page.
*/
GLOBAL(l2_xenmap)
- .fill L2_PAGETABLE_ENTRIES, 8, 0
+ idx = 0
+ .rept L2_PAGETABLE_ENTRIES
+ .if idx == l2_table_offset(FIXADDR_X_TOP - 1)
+ .quad sym_offs(l1_fixmap_x) + __PAGE_HYPERVISOR
+ .else
+ .quad 0
+ .endif
+ idx = idx + 1
+ .endr
.size l2_xenmap, . - l2_xenmap
/* L2 mapping the fixmap. Uses 1x 4k page. */
diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index 2749cbc5cf..513b0f3841 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -12,6 +12,7 @@
#include <xen/livepatch.h>
#include <xen/sched.h>
+#include <asm/fixmap.h>
#include <asm/nmi.h>
#include <asm/livepatch.h>
@@ -311,7 +312,7 @@ void __init arch_livepatch_init(void)
void *start, *end;
start = (void *)xen_virt_end;
- end = (void *)(XEN_VIRT_END - NR_CPUS * PAGE_SIZE);
+ end = (void *)(XEN_VIRT_END - FIXADDR_X_SIZE - NR_CPUS * PAGE_SIZE);
BUG_ON(end <= start);
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index f50c065af3..44abde24b2 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -157,6 +157,8 @@
/* Mapping of the fixmap space needed early. */
l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
l1_fixmap[L1_PAGETABLE_ENTRIES];
+l1_pgentry_t __section(".bss.page_aligned") __aligned(PAGE_SIZE)
+ l1_fixmap_x[L1_PAGETABLE_ENTRIES];
paddr_t __read_mostly mem_hotplug;
@@ -5718,10 +5720,21 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
void __set_fixmap(
enum fixed_addresses idx, unsigned long mfn, unsigned long flags)
{
- BUG_ON(idx >= __end_of_fixed_addresses);
+ BUG_ON(idx >= __end_of_fixed_addresses || idx <= FIX_RESERVED);
map_pages_to_xen(__fix_to_virt(idx), _mfn(mfn), 1, flags);
}
+void __set_fixmap_x(
+ enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags)
+{
+ BUG_ON(idx >= __end_of_fixed_addresses_x || idx <= FIX_X_RESERVED);
+ map_pages_to_xen(__fix_x_to_virt(idx), _mfn(mfn), 1, flags);
+
+ /* Generate a symbol to be used in linker script */
+ asm ( ".equ FIXADDR_X_SIZE, %c0; .global FIXADDR_X_SIZE"
+ :: "i" (__end_of_fixed_addresses_x << PAGE_SHIFT) );
+}
+
void *__init arch_vmap_virt_end(void)
{
return fix_to_virt(__end_of_fixed_addresses);
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index 93b86a09e9..e83e4564a4 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -644,7 +644,7 @@ unsigned long alloc_stub_page(unsigned int cpu, unsigned long *mfn)
unmap_domain_page(memset(__map_domain_page(pg), 0xcc, PAGE_SIZE));
}
- stub_va = XEN_VIRT_END - (cpu + 1) * PAGE_SIZE;
+ stub_va = XEN_VIRT_END - FIXADDR_X_SIZE - (cpu + 1) * PAGE_SIZE;
if ( map_pages_to_xen(stub_va, page_to_mfn(pg), 1,
PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES) )
{
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index 07c6448dbb..97f9c07891 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -3,6 +3,8 @@
#include <xen/cache.h>
#include <xen/lib.h>
+
+#include <asm/fixmap.h>
#include <asm/page.h>
#undef ENTRY
#undef ALIGN
@@ -353,6 +355,7 @@ SECTIONS
}
ASSERT(__2M_rwdata_end <= XEN_VIRT_END - XEN_VIRT_START + __XEN_VIRT_START -
+ FIXADDR_X_SIZE -
DIV_ROUND_UP(NR_CPUS, STUBS_PER_PAGE) * PAGE_SIZE,
"Xen image overlaps stubs area")
diff --git a/xen/include/asm-x86/config.h b/xen/include/asm-x86/config.h
index d0cfbb70a8..a34053c4c0 100644
--- a/xen/include/asm-x86/config.h
+++ b/xen/include/asm-x86/config.h
@@ -218,7 +218,7 @@ extern unsigned char boot_edid_info[128];
/* Slot 261: high read-only compat machine-to-phys conversion table (1GB). */
#define HIRO_COMPAT_MPT_VIRT_START RDWR_COMPAT_MPT_VIRT_END
#define HIRO_COMPAT_MPT_VIRT_END (HIRO_COMPAT_MPT_VIRT_START + GB(1))
-/* Slot 261: xen text, static data and bss (1GB). */
+/* Slot 261: xen text, static data, bss, per-cpu stubs and executable fixmap (1GB). */
#define XEN_VIRT_START (HIRO_COMPAT_MPT_VIRT_END)
#define XEN_VIRT_END (XEN_VIRT_START + GB(1))
diff --git a/xen/include/asm-x86/fixmap.h b/xen/include/asm-x86/fixmap.h
index 9fb2f47946..8094546b75 100644
--- a/xen/include/asm-x86/fixmap.h
+++ b/xen/include/asm-x86/fixmap.h
@@ -15,6 +15,7 @@
#include <asm/page.h>
#define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)
+#define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE)
#ifndef __ASSEMBLY__
@@ -89,6 +90,30 @@ static inline unsigned long virt_to_fix(const unsigned long vaddr)
return __virt_to_fix(vaddr);
}
+enum fixed_addresses_x {
+ /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */
+ FIX_X_RESERVED,
+#ifdef CONFIG_HYPERV_GUEST
+ FIX_X_HYPERV_HCALL,
+#endif
+ __end_of_fixed_addresses_x
+};
+
+#define FIXADDR_X_SIZE (__end_of_fixed_addresses_x << PAGE_SHIFT)
+#define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE)
+
+extern void __set_fixmap_x(
+ enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags);
+
+#define set_fixmap_x(idx, phys) \
+ __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES)
+
+#define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0)
+
+#define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))
+
+#define fix_x_to_virt(x) ((void *)__fix_x_to_virt(x))
+
#endif /* __ASSEMBLY__ */
#endif
--
2.20.1
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-01-29 20:21 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-29 20:20 [Xen-devel] [PATCH v5 00/12] More Hyper-V infrastructures Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 01/12] MAINTAINERS: put Hyper-V code under Viridian maintainership Wei Liu
2020-01-30 9:34 ` Durrant, Paul
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 02/12] x86/hypervisor: make hypervisor_ap_setup return an error code Wei Liu
2020-01-30 10:01 ` Roger Pau Monné
2020-01-30 13:25 ` Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 03/12] x86/smp: don't online cpu if hypervisor_ap_setup fails Wei Liu
2020-01-30 10:10 ` Roger Pau Monné
2020-01-31 13:53 ` Jan Beulich
2020-01-31 14:10 ` Wei Liu
2020-01-31 14:34 ` Jan Beulich
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 04/12] x86: make paddr_bits available earlier Wei Liu
2020-01-30 10:17 ` Roger Pau Monné
2020-01-30 12:00 ` Wei Liu
2020-01-31 13:57 ` Jan Beulich
2020-01-29 20:20 ` Wei Liu [this message]
2020-01-30 0:30 ` [Xen-devel] [PATCH v5 05/12] x86: provide executable fixmap facility Wei Liu
2020-01-31 13:12 ` Wei Liu
2020-01-31 13:19 ` Jan Beulich
2020-01-31 13:20 ` Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 06/12] x86/hypervisor: provide hypervisor_reserve_top_pages Wei Liu
2020-01-30 10:32 ` Roger Pau Monné
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 07/12] x86/hyperv: setup hypercall page Wei Liu
2020-01-30 9:57 ` Durrant, Paul
2020-01-30 11:19 ` Wei Liu
2020-01-30 10:41 ` Roger Pau Monné
2020-01-30 11:18 ` Wei Liu
2020-01-30 11:39 ` Roger Pau Monné
2020-01-30 11:47 ` Wei Liu
2020-01-30 12:11 ` Roger Pau Monné
2020-01-31 12:49 ` Wei Liu
2020-01-31 14:05 ` Jan Beulich
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 08/12] x86/hyperv: provide Hyper-V hypercall functions Wei Liu
2020-01-30 10:06 ` Durrant, Paul
2020-01-30 12:08 ` Roger Pau Monné
2020-01-30 12:28 ` Wei Liu
2020-01-30 12:32 ` Roger Pau Monné
2020-01-30 12:39 ` Wei Liu
2020-01-30 14:22 ` Roger Pau Monné
2020-01-30 14:25 ` Wei Liu
2020-01-30 14:47 ` Roger Pau Monné
2020-01-30 15:03 ` Wei Liu
2020-01-30 15:25 ` Roger Pau Monné
2020-01-30 16:02 ` Wei Liu
2020-01-31 14:12 ` Jan Beulich
2020-01-31 14:20 ` Wei Liu
2020-01-31 14:36 ` Jan Beulich
2020-01-31 14:24 ` Jan Beulich
2020-01-31 14:37 ` Wei Liu
2020-01-31 15:35 ` Jan Beulich
2020-01-31 16:15 ` Wei Liu
2020-01-31 16:18 ` Jan Beulich
2020-01-31 16:49 ` Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 09/12] DO NOT APPLY: x86/hyperv: issue an hypercall Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 10/12] x86/hyperv: provide percpu hypercall input page Wei Liu
2020-01-30 10:14 ` Durrant, Paul
2020-01-30 12:26 ` Roger Pau Monné
2020-01-30 14:09 ` Wei Liu
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 11/12] x86/hyperv: retrieve vp_index from Hyper-V Wei Liu
2020-01-31 14:27 ` Jan Beulich
2020-01-29 20:20 ` [Xen-devel] [PATCH v5 12/12] x86/hyperv: setup VP assist page Wei Liu
2020-01-30 10:34 ` Durrant, Paul
2020-01-30 14:00 ` Wei Liu
2020-01-30 12:42 ` Roger Pau Monné
2020-01-30 14:03 ` Wei Liu
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=20200129202034.15052-6-liuwe@microsoft.com \
--to=wl@xen.org \
--cc=andrew.cooper3@citrix.com \
--cc=konrad.wilk@oracle.com \
--cc=liuwe@microsoft.com \
--cc=mikelley@microsoft.com \
--cc=pdurrant@amazon.com \
--cc=roger.pau@citrix.com \
--cc=ross.lagerwall@citrix.com \
--cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.