From: Wei Liu <wei.liu2@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <JBeulich@suse.com>
Subject: [PATCH v3 20/21] x86/mm: move l4 table setup code
Date: Thu, 20 Jul 2017 17:04:25 +0100 [thread overview]
Message-ID: <20170720160426.2343-21-wei.liu2@citrix.com> (raw)
In-Reply-To: <20170720160426.2343-1-wei.liu2@citrix.com>
Move two functions to pv/mm.c. Add prefix to init_guest_l4_table.
Export them via pv/mm.h. Fix up call sites.
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
---
xen/arch/x86/mm.c | 69 +-------------------------------------------
xen/arch/x86/pv/dom0_build.c | 3 +-
xen/arch/x86/pv/domain.c | 3 +-
xen/arch/x86/pv/mm.c | 68 +++++++++++++++++++++++++++++++++++++++++++
xen/include/asm-x86/mm.h | 2 --
xen/include/asm-x86/pv/mm.h | 8 +++++
6 files changed, 81 insertions(+), 72 deletions(-)
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index c7c989d8f8..5687e29824 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -251,53 +251,6 @@ void __init init_frametable(void)
init_spagetable();
}
-#ifndef NDEBUG
-static unsigned int __read_mostly root_pgt_pv_xen_slots
- = ROOT_PAGETABLE_PV_XEN_SLOTS;
-static l4_pgentry_t __read_mostly split_l4e;
-#else
-#define root_pgt_pv_xen_slots ROOT_PAGETABLE_PV_XEN_SLOTS
-#endif
-
-static void pv_arch_init_memory(void)
-{
-#ifndef NDEBUG
- unsigned int i;
-
- if ( highmem_start )
- {
- unsigned long split_va = (unsigned long)__va(highmem_start);
-
- if ( split_va < HYPERVISOR_VIRT_END &&
- split_va - 1 == (unsigned long)__va(highmem_start - 1) )
- {
- root_pgt_pv_xen_slots = l4_table_offset(split_va) -
- ROOT_PAGETABLE_FIRST_XEN_SLOT;
- ASSERT(root_pgt_pv_xen_slots < ROOT_PAGETABLE_PV_XEN_SLOTS);
- if ( l4_table_offset(split_va) == l4_table_offset(split_va - 1) )
- {
- l3_pgentry_t *l3tab = alloc_xen_pagetable();
-
- if ( l3tab )
- {
- const l3_pgentry_t *l3idle =
- l4e_to_l3e(idle_pg_table[l4_table_offset(split_va)]);
-
- for ( i = 0; i < l3_table_offset(split_va); ++i )
- l3tab[i] = l3idle[i];
- for ( ; i < L3_PAGETABLE_ENTRIES; ++i )
- l3tab[i] = l3e_empty();
- split_l4e = l4e_from_pfn(virt_to_mfn(l3tab),
- __PAGE_HYPERVISOR_RW);
- }
- else
- ++root_pgt_pv_xen_slots;
- }
- }
- }
-#endif
-}
-
void __init arch_init_memory(void)
{
unsigned long i, pfn, rstart_pfn, rend_pfn, iostart_pfn, ioend_pfn;
@@ -1468,26 +1421,6 @@ static int alloc_l3_table(struct page_info *page)
return rc > 0 ? 0 : rc;
}
-void init_guest_l4_table(l4_pgentry_t l4tab[], const struct domain *d,
- bool zap_ro_mpt)
-{
- /* Xen private mappings. */
- memcpy(&l4tab[ROOT_PAGETABLE_FIRST_XEN_SLOT],
- &idle_pg_table[ROOT_PAGETABLE_FIRST_XEN_SLOT],
- root_pgt_pv_xen_slots * sizeof(l4_pgentry_t));
-#ifndef NDEBUG
- if ( l4e_get_intpte(split_l4e) )
- l4tab[ROOT_PAGETABLE_FIRST_XEN_SLOT + root_pgt_pv_xen_slots] =
- split_l4e;
-#endif
- l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =
- l4e_from_pfn(domain_page_map_to_mfn(l4tab), __PAGE_HYPERVISOR_RW);
- l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] =
- l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW);
- if ( zap_ro_mpt || is_pv_32bit_domain(d) )
- l4tab[l4_table_offset(RO_MPT_VIRT_START)] = l4e_empty();
-}
-
bool fill_ro_mpt(unsigned long mfn)
{
l4_pgentry_t *l4tab = map_domain_page(_mfn(mfn));
@@ -1562,7 +1495,7 @@ static int alloc_l4_table(struct page_info *page)
if ( rc >= 0 )
{
- init_guest_l4_table(pl4e, d, !VM_ASSIST(d, m2p_strict));
+ pv_init_guest_l4_table(pl4e, d, !VM_ASSIST(d, m2p_strict));
atomic_inc(&d->arch.pv_domain.nr_l4_pages);
rc = 0;
}
diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c
index 18c19a256f..ef789410fe 100644
--- a/xen/arch/x86/pv/dom0_build.c
+++ b/xen/arch/x86/pv/dom0_build.c
@@ -18,6 +18,7 @@
#include <asm/bzimage.h>
#include <asm/dom0_build.h>
#include <asm/page.h>
+#include <asm/pv/mm.h>
#include <asm/setup.h>
/* Allow ring-3 access in long mode as guest cannot use ring 1 ... */
@@ -590,7 +591,7 @@ int __init dom0_construct_pv(struct domain *d,
l3start = __va(mpt_alloc); mpt_alloc += PAGE_SIZE;
}
clear_page(l4tab);
- init_guest_l4_table(l4tab, d, 0);
+ pv_init_guest_l4_table(l4tab, d, 0);
v->arch.guest_table = pagetable_from_paddr(__pa(l4start));
if ( is_pv_32bit_domain(d) )
v->arch.guest_table_user = v->arch.guest_table;
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 6cb61f2e14..415d0634a3 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -10,6 +10,7 @@
#include <xen/sched.h>
#include <asm/pv/domain.h>
+#include <asm/pv/mm.h>
static void noreturn continue_nonidle_domain(struct vcpu *v)
{
@@ -29,7 +30,7 @@ static int setup_compat_l4(struct vcpu *v)
l4tab = __map_domain_page(pg);
clear_page(l4tab);
- init_guest_l4_table(l4tab, v->domain, 1);
+ pv_init_guest_l4_table(l4tab, v->domain, 1);
unmap_domain_page(l4tab);
/* This page needs to look like a pagetable so that it can be shadowed */
diff --git a/xen/arch/x86/pv/mm.c b/xen/arch/x86/pv/mm.c
index 32e73d59df..0f4303cef2 100644
--- a/xen/arch/x86/pv/mm.c
+++ b/xen/arch/x86/pv/mm.c
@@ -23,6 +23,7 @@
#include <xen/guest_access.h>
#include <asm/pv/mm.h>
+#include <asm/setup.h>
/*
* PTE updates can be done with ordinary writes except:
@@ -32,6 +33,14 @@
#define PTE_UPDATE_WITH_CMPXCHG
#endif
+#ifndef NDEBUG
+static unsigned int __read_mostly root_pgt_pv_xen_slots
+ = ROOT_PAGETABLE_PV_XEN_SLOTS;
+static l4_pgentry_t __read_mostly split_l4e;
+#else
+#define root_pgt_pv_xen_slots ROOT_PAGETABLE_PV_XEN_SLOTS
+#endif
+
/* Read a PV guest's l1e that maps this virtual address. */
void pv_get_guest_eff_l1e(unsigned long addr, l1_pgentry_t *eff_l1e)
{
@@ -96,6 +105,65 @@ void pv_unmap_guest_l1e(void *p)
unmap_domain_page(p);
}
+void pv_init_guest_l4_table(l4_pgentry_t l4tab[], const struct domain *d,
+ bool zap_ro_mpt)
+{
+ /* Xen private mappings. */
+ memcpy(&l4tab[ROOT_PAGETABLE_FIRST_XEN_SLOT],
+ &idle_pg_table[ROOT_PAGETABLE_FIRST_XEN_SLOT],
+ root_pgt_pv_xen_slots * sizeof(l4_pgentry_t));
+#ifndef NDEBUG
+ if ( l4e_get_intpte(split_l4e) )
+ l4tab[ROOT_PAGETABLE_FIRST_XEN_SLOT + root_pgt_pv_xen_slots] =
+ split_l4e;
+#endif
+ l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =
+ l4e_from_pfn(domain_page_map_to_mfn(l4tab), __PAGE_HYPERVISOR_RW);
+ l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] =
+ l4e_from_page(d->arch.perdomain_l3_pg, __PAGE_HYPERVISOR_RW);
+ if ( zap_ro_mpt || is_pv_32bit_domain(d) )
+ l4tab[l4_table_offset(RO_MPT_VIRT_START)] = l4e_empty();
+}
+
+void pv_arch_init_memory(void)
+{
+#ifndef NDEBUG
+ unsigned int i;
+
+ if ( highmem_start )
+ {
+ unsigned long split_va = (unsigned long)__va(highmem_start);
+
+ if ( split_va < HYPERVISOR_VIRT_END &&
+ split_va - 1 == (unsigned long)__va(highmem_start - 1) )
+ {
+ root_pgt_pv_xen_slots = l4_table_offset(split_va) -
+ ROOT_PAGETABLE_FIRST_XEN_SLOT;
+ ASSERT(root_pgt_pv_xen_slots < ROOT_PAGETABLE_PV_XEN_SLOTS);
+ if ( l4_table_offset(split_va) == l4_table_offset(split_va - 1) )
+ {
+ l3_pgentry_t *l3tab = alloc_xen_pagetable();
+
+ if ( l3tab )
+ {
+ const l3_pgentry_t *l3idle =
+ l4e_to_l3e(idle_pg_table[l4_table_offset(split_va)]);
+
+ for ( i = 0; i < l3_table_offset(split_va); ++i )
+ l3tab[i] = l3idle[i];
+ for ( ; i < L3_PAGETABLE_ENTRIES; ++i )
+ l3tab[i] = l3e_empty();
+ split_l4e = l4e_from_pfn(virt_to_mfn(l3tab),
+ __PAGE_HYPERVISOR_RW);
+ }
+ else
+ ++root_pgt_pv_xen_slots;
+ }
+ }
+ }
+#endif
+}
+
/*
* How to write an entry to the guest pagetables.
* Returns false for failure (pointer not valid), true for success.
diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h
index 07287d97ca..19c80da995 100644
--- a/xen/include/asm-x86/mm.h
+++ b/xen/include/asm-x86/mm.h
@@ -322,8 +322,6 @@ static inline void *__page_to_virt(const struct page_info *pg)
int free_page_type(struct page_info *page, unsigned long type,
int preemptible);
-void init_guest_l4_table(l4_pgentry_t[], const struct domain *,
- bool_t zap_ro_mpt);
bool_t fill_ro_mpt(unsigned long mfn);
void zap_ro_mpt(unsigned long mfn);
diff --git a/xen/include/asm-x86/pv/mm.h b/xen/include/asm-x86/pv/mm.h
index a71ce934fa..8fd542e630 100644
--- a/xen/include/asm-x86/pv/mm.h
+++ b/xen/include/asm-x86/pv/mm.h
@@ -90,6 +90,10 @@ bool pv_update_intpte(intpte_t *p, intpte_t old, intpte_t new,
l1_pgentry_t *pv_map_guest_l1e(unsigned long addr, unsigned long *gl1mfn);
void pv_unmap_guest_l1e(void *p);
+void pv_init_guest_l4_table(l4_pgentry_t[], const struct domain *,
+ bool zap_ro_mpt);
+void pv_arch_init_memory(void);
+
#else
static inline void pv_get_guest_eff_l1e(unsigned long addr,
@@ -111,6 +115,10 @@ static inline l1_pgentry_t *pv_map_guest_l1e(unsigned long addr,
static inline void pv_unmap_guest_l1e(void *p) {}
+static inline void pv_init_guest_l4_table(l4_pgentry_t[],
+ const struct domain *,
+ bool zap_ro_mpt) {}
+static inline void pv_arch_init_memory(void) {}
#endif
#endif /* __X86_PV_MM_H__ */
--
2.11.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-07-20 16:16 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-20 16:04 [PATCH v3 00/21] x86: refactor mm.c (the easy part) Wei Liu
2017-07-20 16:04 ` [PATCH v3 01/21] x86/mm: carve out create_grant_pv_mapping Wei Liu
2017-08-28 15:16 ` George Dunlap
2017-07-20 16:04 ` [PATCH v3 02/21] x86/mm: carve out replace_grant_pv_mapping Wei Liu
2017-08-28 15:19 ` George Dunlap
2017-07-20 16:04 ` [PATCH v3 03/21] x86/mm: split HVM grant table code to hvm/grant_table.c Wei Liu
2017-07-20 16:04 ` [PATCH v3 04/21] x86/mm: lift PAGE_CACHE_ATTRS to page.h Wei Liu
2017-07-20 16:04 ` [PATCH v3 05/21] x86/mm: document the return values from get_page_from_l*e Wei Liu
2017-07-20 16:04 ` [PATCH v3 06/21] x86: move pv_emul_is_mem_write to pv/emulate.c Wei Liu
2017-07-20 16:04 ` [PATCH v3 07/21] x86/mm: move and rename guest_get_eff{, kern}_l1e Wei Liu
2017-07-20 16:04 ` [PATCH v3 08/21] x86/mm: export get_page_from_pagenr Wei Liu
2017-07-20 16:04 ` [PATCH v3 09/21] x86/mm: rename and move update_intpte Wei Liu
2017-07-20 16:04 ` [PATCH v3 10/21] x86/mm: move {un, }adjust_guest_* to pv/mm.h Wei Liu
2017-07-20 16:04 ` [PATCH v3 11/21] x86/mm: split out writable pagetable emulation code Wei Liu
2017-07-20 16:04 ` [PATCH v3 12/21] x86/mm: split out readonly MMIO " Wei Liu
2017-07-20 16:04 ` [PATCH v3 13/21] x86/mm: remove the unused inclusion of pv/emulate.h Wei Liu
2017-07-20 16:04 ` [PATCH v3 14/21] x86/mm: move and rename guest_{, un}map_l1e Wei Liu
2017-07-20 16:04 ` [PATCH v3 15/21] x86/mm: split out PV grant table code Wei Liu
2017-07-20 16:04 ` [PATCH v3 16/21] x86/mm: split out descriptor " Wei Liu
2017-07-20 16:04 ` [PATCH v3 17/21] x86/mm: move compat descriptor handling code Wei Liu
2017-07-20 16:04 ` [PATCH v3 18/21] x86/mm: move and rename map_ldt_shadow_page Wei Liu
2017-07-20 16:04 ` [PATCH v3 19/21] x86/mm: factor out pv_arch_init_memory Wei Liu
2017-07-20 16:04 ` Wei Liu [this message]
2017-07-20 16:04 ` [PATCH v3 21/21] x86/mm: add "pv_" prefix to new_guest_cr3 Wei Liu
2017-07-30 6:26 ` [PATCH v3 00/21] x86: refactor mm.c (the easy part) Jan Beulich
2017-07-30 9:23 ` Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 00/11] x86: refactor mm.c: page APIs and hypercalls Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 01/11] x86: add pv_ prefix to {alloc, free}_page_type Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 02/11] x86/mm: export more get/put page functions Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 03/11] x86/mm: move and add pv_ prefix to create_pae_xen_mappings Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 04/11] x86/mm: move disallow_mask variable and macros Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 05/11] x86/mm: move pv_{alloc, free}_page_type Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 06/11] x86/mm: move and add pv_ prefix to invalidate_shadow_ldt Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 07/11] x86/mm: move PV hypercalls to pv/mm-hypercalls.c Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 08/11] x86/mm: remove the now unused inclusion of pv/mm.h Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 09/11] x86/mm: use put_page_type_preemptible in put_page_from_l{2, 3}e Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 10/11] x86/mm: move {get, put}_page_from_l{2, 3, 4}e Wei Liu
2017-07-30 15:43 ` [PATCH v3 extra 11/11] x86/mm: move description of x86 page table API to pv/mm.c Wei Liu
2017-07-31 9:58 ` [PATCH v3 extra 00/11] x86: refactor mm.c: page APIs and hypercalls 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=20170720160426.2343-21-wei.liu2@citrix.com \
--to=wei.liu2@citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=george.dunlap@eu.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 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).