From patchwork Thu Jul 20 16:04:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9855325 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B8CF8600F5 for ; Thu, 20 Jul 2017 16:18:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9002286DE for ; Thu, 20 Jul 2017 16:18:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C5E7286FD; Thu, 20 Jul 2017 16:18:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F1AF8286DE for ; Thu, 20 Jul 2017 16:18:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYE7m-0002mX-G2; Thu, 20 Jul 2017 16:16:26 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYE7k-0002lv-V0 for xen-devel@lists.xenproject.org; Thu, 20 Jul 2017 16:16:25 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id 27/00-18997-857D0795; Thu, 20 Jul 2017 16:16:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBIsWRWlGSWpSXmKPExsXitHSDvW749YJ Ig4VrDC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxfM/8wFXzyrdh5eTdLA+Mbqy5GTg4JAX+J 45/nsoHYbALKEj87e8FsEQE9iaYDzxm7GLk4mAXmMEpMndvFCJIQFrCSmL7iIFgRi4CqxLrzl 1lBbF4BC4nXfy4yQwyVl9jVdhEszgkUX/PrKxOILSRgLrF5/3wWCFtBomP6MSaIXkGJkzOfgM WZBSQkDr54wTyBkXcWktQsJKkFjEyrGDWKU4vKUot0jQz0kooy0zNKchMzc3QNDUz1clOLixP TU3MSk4r1kvNzNzECw6eegYFxB2PjbL9DjJIcTEqivCyBBZFCfEn5KZUZicUZ8UWlOanFhxhl ODiUJHgZrgHlBItS01Mr0jJzgIEMk5bg4FES4RUESfMWFyTmFmemQ6ROMRpzdMz4+Y2J49WE/ 9+YhFjy8vNSpcR5bUBKBUBKM0rz4AbBIuwSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWHeeJ ApPJl5JXD7XgGdwgR0yiM3sFNKEhFSUg2M3bGXbYNtDvYfEVro5t47q+kZk4lqp0pCYJ7f52q HDU9L6ydofkvaKt267E63eK3UxcIpEct0dqn/Muz4uFCUZZtwa5u6Da/TxkfvX7yfss64su3y zJsvt7j/d8ovf7L3NW9qw/tur823RdVNJ9rz7XX5OJNv5hH3Otmut+t94q6euBN+y0hMiaU4I 9FQi7moOBEAflkCE6sCAAA= X-Env-Sender: prvs=3674d857a=wei.liu2@citrix.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1500567381!103772445!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 63920 invoked from network); 20 Jul 2017 16:16:23 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 20 Jul 2017 16:16:23 -0000 X-IronPort-AV: E=Sophos;i="5.40,384,1496102400"; d="scan'208";a="440670485" From: Wei Liu To: Xen-devel Date: Thu, 20 Jul 2017 17:04:25 +0100 Message-ID: <20170720160426.2343-21-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170720160426.2343-1-wei.liu2@citrix.com> References: <20170720160426.2343-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v3 20/21] x86/mm: move l4 table setup code X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 #include #include +#include #include /* 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 #include +#include 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 #include +#include /* * 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__ */