From patchwork Fri Dec 9 15:50:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9468507 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 2FAEC60586 for ; Fri, 9 Dec 2016 15:52:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FCEC28419 for ; Fri, 9 Dec 2016 15:52:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1119728623; Fri, 9 Dec 2016 15:52:37 +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 7B23228419 for ; Fri, 9 Dec 2016 15:52:36 +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 1cFNRR-00054s-IH; Fri, 09 Dec 2016 15:50:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFNRQ-00054e-4k for xen-devel@lists.xenproject.org; Fri, 09 Dec 2016 15:50:32 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id F0/6E-01948-7C2DA485; Fri, 09 Dec 2016 15:50:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsXitHRDpO6xS14 RBl/m2Vh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmdvXcZC7pUKqbt+8PewLherouRk0NCwF/i zs8jTCA2m4CBxK1L35m7GDk4RARUJG7vNehi5OJgFljOKHH8wUxGkBphAXeJgx2LWUFsFqCap 5vOs4DU8wp4SCzYJgoxUk7i5rlOZhBbSEBN4u3yMywgNq+AoMTJmU/AbGYBCYmDL14wT2Dkno UkNQtJagEj0ypGjeLUorLUIl0jS72kosz0jJLcxMwcXUMDU73c1OLixPTUnMSkYr3k/NxNjMB QqGdgYNzBeHmL3yFGSQ4mJVHeYiavCCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvOkXgXKCRanp qRVpmTnAoIRJS3DwKInwngVJ8xYXJOYWZ6ZDpE4x6nKsO7XkKZMQS15+XqqUOG8iSJEASFFGa R7cCFiEXGKUlRLmZWRgYBDiKUgtys0sQZV/xSjOwagkzNsPMoUnM68EbtMroCOYgI6Yd8Md5I iSRISUVAPj7nyfyGWZ3p/e/bHJevhy2qSNdwObDacsztG5XCB29vVJIb3Aji41XZeP6VOKZvy 6eCXt4qPquYxZoofZfwYG/7K3NdF/s/98q5X7iuVpdg+ihRMvX6nfYdJ6OX7JmtWpTi38klZR y68dU2bZuHvX9iNHGuo6dAJW6/i/OsyuHRP04rtetsImJZbijERDLeai4kQAaEoiC4sCAAA= X-Env-Sender: prvs=1442424a8=ross.lagerwall@citrix.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1481298627!74764106!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23022 invoked from network); 9 Dec 2016 15:50:29 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-9.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 9 Dec 2016 15:50:29 -0000 X-IronPort-AV: E=Sophos;i="5.33,324,1477958400"; d="scan'208";a="393976264" From: Ross Lagerwall To: Date: Fri, 9 Dec 2016 15:50:06 +0000 Message-ID: <1481298606-2550-1-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Cc: Juergen Gross , Ross Lagerwall , Boris Ostrovsky , David Vrabel Subject: [Xen-devel] [PATCH] xen/setup: Don't relocate p2m/initrd over existing one 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 When relocating the p2m/initrd, take special care not to relocate it so that is overlaps with the current location of the p2m/initrd. This is needed since the full extent of the current location is not marked as a reserved region in the e820 (and it shouldn't be since it is about to be moved). This was seen to happen to a dom0 with a large initial p2m and a small reserved region in the middle of the initial p2m. Signed-off-by: Ross Lagerwall --- arch/x86/xen/mmu.c | 4 ++-- arch/x86/xen/setup.c | 16 ++++++++++------ arch/x86/xen/xen-ops.h | 5 +++-- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c index 7d5afdb..bc40325 100644 --- a/arch/x86/xen/mmu.c +++ b/arch/x86/xen/mmu.c @@ -2074,7 +2074,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr) * Find a new area for the hypervisor supplied p2m list and relocate the p2m to * this area. */ -void __init xen_relocate_p2m(void) +void __init xen_relocate_p2m(phys_addr_t cur_start, phys_addr_t cur_size) { phys_addr_t size, new_area, pt_phys, pmd_phys, pud_phys; unsigned long p2m_pfn, p2m_pfn_end, n_frames, pfn, pfn_end; @@ -2092,7 +2092,7 @@ void __init xen_relocate_p2m(void) n_pud = roundup(size, PGDIR_SIZE) >> PGDIR_SHIFT; n_frames = n_pte + n_pt + n_pmd + n_pud; - new_area = xen_find_free_area(PFN_PHYS(n_frames)); + new_area = xen_find_free_area(PFN_PHYS(n_frames), cur_start, cur_size); if (!new_area) { xen_raw_console_write("Can't find new memory area for p2m needed due to E820 map conflict\n"); BUG(); diff --git a/arch/x86/xen/setup.c b/arch/x86/xen/setup.c index f8960fc..513c48b 100644 --- a/arch/x86/xen/setup.c +++ b/arch/x86/xen/setup.c @@ -634,14 +634,15 @@ bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size) } /* - * Find a free area in physical memory not yet reserved and compliant with - * E820 map. + * Find a free area in physical memory not yet reserved, compliant with the + * E820 map and not overlapping with the pre-allocated area. * Used to relocate pre-allocated areas like initrd or p2m list which are in * conflict with the to be used E820 map. * In case no area is found, return 0. Otherwise return the physical address * of the area which is already reserved for convenience. */ -phys_addr_t __init xen_find_free_area(phys_addr_t size) +phys_addr_t __init xen_find_free_area(phys_addr_t size, phys_addr_t cur_start, + phys_addr_t cur_size) { unsigned mapcnt; phys_addr_t addr, start; @@ -652,7 +653,8 @@ phys_addr_t __init xen_find_free_area(phys_addr_t size) continue; start = entry->addr; for (addr = start; addr < start + size; addr += PAGE_SIZE) { - if (!memblock_is_reserved(addr)) + if (!memblock_is_reserved(addr) && + (addr < cur_start || addr >= cur_start + cur_size)) continue; start = addr + PAGE_SIZE; if (start + size > entry->addr + entry->size) @@ -726,7 +728,7 @@ static void __init xen_reserve_xen_mfnlist(void) xen_raw_console_write("Xen hypervisor allocated p2m list conflicts with E820 map\n"); BUG(); #else - xen_relocate_p2m(); + xen_relocate_p2m(start, size); #endif } @@ -887,7 +889,9 @@ char * __init xen_memory_setup(void) boot_params.hdr.ramdisk_size)) { phys_addr_t new_area, start, size; - new_area = xen_find_free_area(boot_params.hdr.ramdisk_size); + new_area = xen_find_free_area(boot_params.hdr.ramdisk_size, + boot_params.hdr.ramdisk_image, + boot_params.hdr.ramdisk_size); if (!new_area) { xen_raw_console_write("Can't find new memory area for initrd needed due to E820 map conflict\n"); BUG(); diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h index 3cbce3b..d3342b8 100644 --- a/arch/x86/xen/xen-ops.h +++ b/arch/x86/xen/xen-ops.h @@ -41,14 +41,15 @@ void __init xen_pt_check_e820(void); void xen_mm_pin_all(void); void xen_mm_unpin_all(void); #ifdef CONFIG_X86_64 -void __init xen_relocate_p2m(void); +void __init xen_relocate_p2m(phys_addr_t cur_start, phys_addr_t cur_size); #endif bool __init xen_is_e820_reserved(phys_addr_t start, phys_addr_t size); unsigned long __ref xen_chk_extra_mem(unsigned long pfn); void __init xen_inv_extra_mem(void); void __init xen_remap_memory(void); -phys_addr_t __init xen_find_free_area(phys_addr_t size); +phys_addr_t __init xen_find_free_area(phys_addr_t size, phys_addr_t cur_start, + phys_addr_t cur_size); char * __init xen_memory_setup(void); char * xen_auto_xlated_memory_setup(void); void __init xen_arch_setup(void);