From patchwork Fri May 5 13:12:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9713535 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 487A060362 for ; Fri, 5 May 2017 13:14:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DF7528613 for ; Fri, 5 May 2017 13:14:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5192C2869A; Fri, 5 May 2017 13:14:17 +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 E084428613 for ; Fri, 5 May 2017 13:14:16 +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 1d6d1m-0007mr-GZ; Fri, 05 May 2017 13:12:10 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d6d1k-0007me-Qi for xen-devel@lists.xenproject.org; Fri, 05 May 2017 13:12:08 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id 9D/39-02202-72A7C095; Fri, 05 May 2017 13:12:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsXS6fjDS1e9iif SoOs7v8X3LZOZHBg9Dn+4whLAGMWamZeUX5HAmjF3wT6mgoNGFbN3fGJqYLyi2sXIwSEkkCfR erC4i5GTg1fATuLKhUnsILaEgKHE0/fX2UBsFgFViV9HO1hBbDYBdYm2Z9tZQVpFBAwkzh1NA gkzC4RLfH/UywYSFhawkPj52wckLAQ0ccHkl+wgYV4BQYm/O4Qhqu0kGn9cZ5nAyD0LITMLSQ bC1pJ4+OsWlK0tsWzha2aQcmYBaYnl/zggwlYSG/49QFMCYrtKnG3dyriAkWMVo0ZxalFZapG ukYVeUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkZgQNYzMDDuYGw/4XeIUZKDSUmU N02UJ1KILyk/pTIjsTgjvqg0J7X4EKMMB4eSBO+fCqCcYFFqempFWmYOMDZg0hIcPEoivKqVQ Gne4oLE3OLMdIjUKUZFKXFeW5CEAEgiozQPrg0Wj5cYZaWEeRkZGBiEeApSi3IzS1DlXzGKcz AqCfN+BdnOk5lXAjf9FdBiJqDF0aJgi0sSEVJSDYwl0R1iK38J/1SWzzD3zoic2R3f88Ztgqi sf6/S8VU5XK2ZPJsObfnDIBTZVOdYNZU/P7+DPeRmjJKMw7kirra7pR9DAydc+vLnb776VpUl nZfTp/qcmfSUf6Z5SYiDhdW9jCcf/vz+ILerqK2pxvbdnyLTdf53m5Z2ZXbsaOHx4Th592nMI SWW4oxEQy3mouJEAPZfHKXCAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1493989925!40883521!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60377 invoked from network); 5 May 2017 13:12:06 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-4.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 May 2017 13:12:06 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 05 May 2017 07:12:04 -0600 Message-Id: <590C9644020000780015730C@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Fri, 05 May 2017 07:12:04 -0600 From: "Jan Beulich" To: "xen-devel" References: <590C9644020000780015730C@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Julien Grall Subject: [Xen-devel] [PATCH] x86: correct boot time page table setup 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 While using alloc_domheap_pages() and assuming the allocated memory is directly accessible is okay at boot time (as we run on the idle page tables there), memory hotplug code too assumes it can access the resulting page tables without using map_domain_page() or alike, and hence we need to obtain memory suitable for ordinary page table use here. Signed-off-by: Jan Beulich x86: correct boot time page table setup While using alloc_domheap_pages() and assuming the allocated memory is directly accessible is okay at boot time (as we run on the idle page tables there), memory hotplug code too assumes it can access the resulting page tables without using map_domain_page() or alike, and hence we need to obtain memory suitable for ordinary page table use here. Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -496,7 +496,7 @@ void __init paging_init(void) unsigned int n, memflags; l3_pgentry_t *l3_ro_mpt; l2_pgentry_t *l2_ro_mpt = NULL; - struct page_info *l1_pg, *l2_pg, *l3_pg; + struct page_info *l1_pg; /* * We setup the L3s for 1:1 mapping if host support memory hotplug @@ -509,23 +509,22 @@ void __init paging_init(void) if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & _PAGE_PRESENT) ) { - l3_pg = alloc_domheap_page(NULL, 0); - if ( !l3_pg ) + l3_pgentry_t *pl3t = alloc_xen_pagetable(); + + if ( !pl3t ) goto nomem; - l3_ro_mpt = page_to_virt(l3_pg); - clear_page(l3_ro_mpt); + clear_page(pl3t); l4e_write(&idle_pg_table[l4_table_offset(va)], - l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RW)); + l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW)); } } /* Create user-accessible L2 directory to map the MPT for guests. */ - if ( (l3_pg = alloc_domheap_page(NULL, 0)) == NULL ) + if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; - l3_ro_mpt = page_to_virt(l3_pg); clear_page(l3_ro_mpt); l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)], - l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); /* * Allocate and map the machine-to-phys table. @@ -607,12 +606,12 @@ void __init paging_init(void) } if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) { - if ( (l2_pg = alloc_domheap_page(NULL, memflags)) == NULL ) + if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; - l2_ro_mpt = page_to_virt(l2_pg); clear_page(l2_ro_mpt); l3e_write(&l3_ro_mpt[l3_table_offset(va)], - l3e_from_page(l2_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l3e_from_paddr(__pa(l2_ro_mpt), + __PAGE_HYPERVISOR_RO | _PAGE_USER)); ASSERT(!l2_table_offset(va)); } /* NB. Cannot be GLOBAL: guest user mode should not see it. */ Reviewed-by: Andrew Cooper --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -496,7 +496,7 @@ void __init paging_init(void) unsigned int n, memflags; l3_pgentry_t *l3_ro_mpt; l2_pgentry_t *l2_ro_mpt = NULL; - struct page_info *l1_pg, *l2_pg, *l3_pg; + struct page_info *l1_pg; /* * We setup the L3s for 1:1 mapping if host support memory hotplug @@ -509,23 +509,22 @@ void __init paging_init(void) if ( !(l4e_get_flags(idle_pg_table[l4_table_offset(va)]) & _PAGE_PRESENT) ) { - l3_pg = alloc_domheap_page(NULL, 0); - if ( !l3_pg ) + l3_pgentry_t *pl3t = alloc_xen_pagetable(); + + if ( !pl3t ) goto nomem; - l3_ro_mpt = page_to_virt(l3_pg); - clear_page(l3_ro_mpt); + clear_page(pl3t); l4e_write(&idle_pg_table[l4_table_offset(va)], - l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RW)); + l4e_from_paddr(__pa(pl3t), __PAGE_HYPERVISOR_RW)); } } /* Create user-accessible L2 directory to map the MPT for guests. */ - if ( (l3_pg = alloc_domheap_page(NULL, 0)) == NULL ) + if ( (l3_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; - l3_ro_mpt = page_to_virt(l3_pg); clear_page(l3_ro_mpt); l4e_write(&idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)], - l4e_from_page(l3_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l4e_from_paddr(__pa(l3_ro_mpt), __PAGE_HYPERVISOR_RO | _PAGE_USER)); /* * Allocate and map the machine-to-phys table. @@ -607,12 +606,12 @@ void __init paging_init(void) } if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) ) { - if ( (l2_pg = alloc_domheap_page(NULL, memflags)) == NULL ) + if ( (l2_ro_mpt = alloc_xen_pagetable()) == NULL ) goto nomem; - l2_ro_mpt = page_to_virt(l2_pg); clear_page(l2_ro_mpt); l3e_write(&l3_ro_mpt[l3_table_offset(va)], - l3e_from_page(l2_pg, __PAGE_HYPERVISOR_RO | _PAGE_USER)); + l3e_from_paddr(__pa(l2_ro_mpt), + __PAGE_HYPERVISOR_RO | _PAGE_USER)); ASSERT(!l2_table_offset(va)); } /* NB. Cannot be GLOBAL: guest user mode should not see it. */