xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	Ross Lagerwall <ross.lagerwall@citrix.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	David Vrabel <david.vrabel@citrix.com>
Subject: [PATCH] xen/setup: Don't relocate p2m/initrd over existing one
Date: Fri, 9 Dec 2016 15:50:06 +0000	[thread overview]
Message-ID: <1481298606-2550-1-git-send-email-ross.lagerwall@citrix.com> (raw)

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 <ross.lagerwall@citrix.com>
---
 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);
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

             reply	other threads:[~2016-12-09 15:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 15:50 Ross Lagerwall [this message]
2016-12-09 21:08 ` [PATCH] xen/setup: Don't relocate p2m/initrd over existing one Boris Ostrovsky
2016-12-12  7:28   ` Ross Lagerwall
2016-12-12  8:19 ` Juergen Gross
2016-12-12  8:28   ` Ross Lagerwall
2016-12-12  8:37     ` Juergen Gross

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=1481298606-2550-1-git-send-email-ross.lagerwall@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=jgross@suse.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).