From patchwork Tue Oct 31 18:51:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 10035227 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 11BD1602B5 for ; Tue, 31 Oct 2017 18:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 032D128604 for ; Tue, 31 Oct 2017 18:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA2C628AEB; Tue, 31 Oct 2017 18:57:15 +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 6B56328604 for ; Tue, 31 Oct 2017 18:57:14 +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 1e9bgX-0003Yj-Pa; Tue, 31 Oct 2017 18:54:49 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9bgV-0003Yb-MC for xen-devel@lists.xenproject.org; Tue, 31 Oct 2017 18:54:47 +0000 Received: from [193.109.254.147] by server-1.bemta-6.messagelabs.com id 6F/47-31121-6F6C8F95; Tue, 31 Oct 2017 18:54:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsXitHSDve63Yz8 iDVasFLf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNenxcqOBlYMesBWwPjN7suRk4OCQF/iW2/ frGA2GwCyhI/O3vZQGwRAT2JpgPPGUFsZoE8ibOrF7GC2MIC7hK3N94CquHgYBFQldh+IhUkz CtgIbHr3ARGiJHyErvaLoKVCwkoSHRMP8YEUSMocXLmExaIkRISB1+8YJ7AyD0LSWoWktQCRq ZVjBrFqUVlqUW6RsZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJScV6yfm5mxiBYcAABDsY/8w PPMQoycGkJMq70/F7pBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3plHf0QKCRalpqdWpGXmAAMS Ji3BwaMkwnsSJM1bXJCYW5yZDpE6xWjM0XHz7h8mjmczXzcwC7Hk5eelSonzbgcpFQApzSjNg xsEi5RLjLJSwryMQKcJ8RSkFuVmlqDKv2IU52BUEua9CTKFJzOvBG7fK6BTmIBO8ZIAO6UkES El1cAYwJb6d3eM8oPn0T+PLL61OG+vW1GBxrM3ggItt3QPuBx6YhHAlHvD3cdNYJvgdWu9VcL v58y8V/r1wrtHnxlVthTlTGAUmDxpusrMf1tjJ29991Fg4s4+Ax79bX8/TprDJtSzo266SdVn y6N7hZrUXaoZmcqepue9E5IJLHrIELVgwRWjCfGaSizFGYmGWsxFxYkAPExP+I8CAAA= X-Env-Sender: prvs=470789eaf=wei.liu2@citrix.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1509476084!101863226!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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7818 invoked from network); 31 Oct 2017 18:54:45 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-14.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 31 Oct 2017 18:54:45 -0000 X-IronPort-AV: E=Sophos;i="5.44,325,1505779200"; d="scan'208";a="457116213" From: Wei Liu To: Xen-devel Date: Tue, 31 Oct 2017 18:51:31 +0000 Message-ID: <20171031185131.26625-1-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Cc: Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH RFC for-next] x86/mm: introduce and use virt_to_xen_l4e 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 Avoid open-coding in a lot of places. No functional change. Signed-off-by: Wei Liu --- Is this patch useful or is open-coding preferred? --- xen/arch/x86/mm.c | 14 +++++++------- xen/arch/x86/x86_64/mm.c | 36 +++++++++++++++++------------------- xen/include/asm-x86/page.h | 5 +++++ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index a20fdcaea4..cd70aba60c 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -363,7 +363,7 @@ void __init arch_init_memory(void) if ( l3tab ) { const l3_pgentry_t *l3idle = - l4e_to_l3e(idle_pg_table[l4_table_offset(split_va)]); + l4e_to_l3e(*virt_to_xen_l4e(split_va)); for ( i = 0; i < l3_table_offset(split_va); ++i ) l3tab[i] = l3idle[i]; @@ -1575,12 +1575,12 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn, /* Slot 256: RO M2P (if applicable). */ l4t[l4_table_offset(RO_MPT_VIRT_START)] = - ro_mpt ? idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)] + ro_mpt ? *virt_to_xen_l4e(RO_MPT_VIRT_START) : l4e_empty(); /* Slot 257: PCI MMCFG. */ l4t[l4_table_offset(PCI_MCFG_VIRT_START)] = - idle_pg_table[l4_table_offset(PCI_MCFG_VIRT_START)]; + *virt_to_xen_l4e(PCI_MCFG_VIRT_START); /* Slot 258: Self linear mappings. */ ASSERT(!mfn_eq(l4mfn, INVALID_MFN)); @@ -1609,7 +1609,7 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn, l4_pgentry_t *next; memcpy(&l4t[l4_table_offset(XEN_VIRT_START)], - &idle_pg_table[l4_table_offset(XEN_VIRT_START)], + virt_to_xen_l4e(XEN_VIRT_START), (ROOT_PAGETABLE_FIRST_XEN_SLOT + root_pgt_pv_xen_slots - l4_table_offset(XEN_VIRT_START)) * sizeof(*l4t)); @@ -1629,7 +1629,7 @@ void init_xen_l4_slots(l4_pgentry_t *l4t, mfn_t l4mfn, : ROOT_PAGETABLE_XEN_SLOTS); memcpy(&l4t[l4_table_offset(XEN_VIRT_START)], - &idle_pg_table[l4_table_offset(XEN_VIRT_START)], + virt_to_xen_l4e(XEN_VIRT_START), (ROOT_PAGETABLE_FIRST_XEN_SLOT + slots - l4_table_offset(XEN_VIRT_START)) * sizeof(*l4t)); } @@ -1643,7 +1643,7 @@ bool fill_ro_mpt(mfn_t mfn) if ( !l4e_get_intpte(l4tab[l4_table_offset(RO_MPT_VIRT_START)]) ) { l4tab[l4_table_offset(RO_MPT_VIRT_START)] = - idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]; + *virt_to_xen_l4e(RO_MPT_VIRT_START); ret = true; } unmap_domain_page(l4tab); @@ -4476,7 +4476,7 @@ static l3_pgentry_t *virt_to_xen_l3e(unsigned long v) { l4_pgentry_t *pl4e; - pl4e = &idle_pg_table[l4_table_offset(v)]; + pl4e = virt_to_xen_l4e(v); if ( !(l4e_get_flags(*pl4e) & _PAGE_PRESENT) ) { bool locking = system_state > SYS_STATE_boot; diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 34cd8457cf..87edfe0a7e 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -133,7 +133,7 @@ static int m2p_mapped(unsigned long spfn) l2_pgentry_t *l2_ro_mpt; va = RO_MPT_VIRT_START + spfn * sizeof(*machine_to_phys_mapping); - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(va)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(va)); switch ( l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & (_PAGE_PRESENT |_PAGE_PSE)) @@ -166,7 +166,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) v += n << PAGE_SHIFT ) { n = L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES; - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[ l3_table_offset(v)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) continue; @@ -193,7 +193,7 @@ static int share_hotadd_m2p_table(struct mem_hotadd_info *info) v != RDWR_COMPAT_MPT_VIRT_END; v += 1 << L2_PAGETABLE_SHIFT ) { - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[ l3_table_offset(v)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) continue; @@ -226,7 +226,7 @@ static void destroy_compat_m2p_mapping(struct mem_hotadd_info *info) if ( emap > ((RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2) ) emap = (RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START) >> 2; - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(HIRO_COMPAT_MPT_VIRT_START)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(HIRO_COMPAT_MPT_VIRT_START)); ASSERT(l3e_get_flags(l3_ro_mpt[l3_table_offset(HIRO_COMPAT_MPT_VIRT_START)]) & _PAGE_PRESENT); @@ -261,7 +261,7 @@ static void destroy_m2p_mapping(struct mem_hotadd_info *info) unsigned long i, va, rwva; unsigned long smap = info->spfn, emap = info->epfn; - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(RO_MPT_VIRT_START)); /* * No need to clean m2p structure existing before the hotplug @@ -340,7 +340,7 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info) va = HIRO_COMPAT_MPT_VIRT_START + smap * sizeof(*compat_machine_to_phys_mapping); - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(va)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(va)); ASSERT(l3e_get_flags(l3_ro_mpt[l3_table_offset(va)]) & _PAGE_PRESENT); @@ -397,9 +397,9 @@ static int setup_m2p_table(struct mem_hotadd_info *info) l3_pgentry_t *l3_ro_mpt = NULL; int ret = 0; - ASSERT(l4e_get_flags(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]) + ASSERT(l4e_get_flags(*virt_to_xen_l4e(RO_MPT_VIRT_START)) & _PAGE_PRESENT); - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(RO_MPT_VIRT_START)); smap = (info->spfn & (~((1UL << (L2_PAGETABLE_SHIFT - 3)) -1))); emap = ((info->epfn + ((1UL << (L2_PAGETABLE_SHIFT - 3)) - 1 )) & @@ -504,15 +504,14 @@ void __init paging_init(void) va < DIRECTMAP_VIRT_END && (void *)va < __va(mem_hotplug); va += (1UL << L4_PAGETABLE_SHIFT) ) { - if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & - _PAGE_PRESENT) ) + if ( !(l4e_get_flags(*virt_to_xen_l4e(va)) & _PAGE_PRESENT) ) { l3_pgentry_t *pl3t = alloc_xen_pagetable(); if ( !pl3t ) goto nomem; clear_page(pl3t); - l4e_write(&idle_pg_table[l4_table_offset(va)], + l4e_write(virt_to_xen_l4e(va), l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW)); } } @@ -521,7 +520,7 @@ void __init paging_init(void) if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; clear_page(l3_ro_mpt); - l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)], + l4e_write(virt_to_xen_l4e(RO_MPT_VIRT_START), l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); /* @@ -624,8 +623,7 @@ void __init paging_init(void) /* Create user-accessible L2 directory to map the MPT for compat guests. */ BUILD_BUG_ON(l4_table_offset(RDWR_MPT_VIRT_START) != l4_table_offset(HIRO_COMPAT_MPT_VIRT_START)); - l3_ro_mpt = l4e_to_l3e(idle_pg_table[l4_table_offset( - HIRO_COMPAT_MPT_VIRT_START)]); + l3_ro_mpt = l4e_to_l3e(*virt_to_xen_l4e(HIRO_COMPAT_MPT_VIRT_START)); if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; compat_idle_pg_table_l2 = l2_ro_mpt; @@ -675,7 +673,7 @@ void __init paging_init(void) machine_to_phys_mapping_valid = 1; /* Set up linear page table mapping. */ - l4e_write(&idle_pg_table[l4_table_offset(LINEAR_PT_VIRT_START)], + l4e_write(virt_to_xen_l4e(LINEAR_PT_VIRT_START), l4e_from_paddr(__pa(idle_pg_table), __PAGE_HYPERVISOR_RW)); return; @@ -729,7 +727,7 @@ static void cleanup_frame_table(struct mem_hotadd_info *info) while (sva < eva) { - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(sva)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(sva))[ l3_table_offset(sva)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) || (l3e_get_flags(l3e) & _PAGE_PSE) ) @@ -843,7 +841,7 @@ void __init subarch_init_memory(void) v += n << PAGE_SHIFT ) { n = L2_PAGETABLE_ENTRIES * L1_PAGETABLE_ENTRIES; - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[ l3_table_offset(v)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) continue; @@ -871,7 +869,7 @@ void __init subarch_init_memory(void) v != RDWR_COMPAT_MPT_VIRT_END; v += 1 << L2_PAGETABLE_SHIFT ) { - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[ l3_table_offset(v)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) continue; @@ -927,7 +925,7 @@ long subarch_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg) (v < (unsigned long)(machine_to_phys_mapping + max_page)); i++, v += 1UL << L2_PAGETABLE_SHIFT ) { - l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3e = l4e_to_l3e(*virt_to_xen_l4e(v))[ l3_table_offset(v)]; if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) mfn = last_mfn; diff --git a/xen/include/asm-x86/page.h b/xen/include/asm-x86/page.h index 45ca742678..0a663b298d 100644 --- a/xen/include/asm-x86/page.h +++ b/xen/include/asm-x86/page.h @@ -299,6 +299,11 @@ extern l2_pgentry_t l2_identmap[4*L2_PAGETABLE_ENTRIES]; extern l1_pgentry_t l1_fixmap[L1_PAGETABLE_ENTRIES]; void paging_init(void); void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t); + +static inline l4_pgentry_t *virt_to_xen_l4e(unsigned long va) +{ + return &idle_pg_table[l4_table_offset(va)]; +} #endif /* !defined(__ASSEMBLY__) */ #define _PAGE_NONE _AC(0x000,U)