aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kiper <dkiper@net-space.pl>2011-04-27 13:31:04 +0100
committerDaniel Kiper <dkiper@net-space.pl>2011-04-27 13:31:04 +0100
commitebadc5f13970d5f82c54bbbf247486016974dd10 (patch)
treeb1a37beb1dd710f0ecc10195deb5787eb8067ddf
parent7b038a3bf50a2811dd150d5c4b188fbc3387b39c (diff)
downloadxen-ebadc5f13970d5f82c54bbbf247486016974dd10.tar.gz
xen-ebadc5f13970d5f82c54bbbf247486016974dd10.tar.bz2
xen-ebadc5f13970d5f82c54bbbf247486016974dd10.zip
pv-grub: Fix for incorrect dom->p2m_host[] list initialization
Introduction of Linux Kernel git commit ceefccc93932b920a8ec6f35f596db05202a12fe (x86: default CONFIG_PHYSICAL_START and CONFIG_PHYSICAL_ALIGN to 16 MB) revealed deeply hidden bug in pv-grub. During kernel load stage dom->p2m_host[] list has been incorrectly initialized. At the beginning of kernel load stage dom->p2m_host[] list is populated with current PFN->MFN layout. Later during memory allocation (memory is allocated page by page in kexec_allocate()) page order is changed to establish linear layout in new domain. It is done by exchanging subsequent MFNs with newly allocated MFNs. dom->p2m_host[] list is indexed by currently requested PFN (it is incremented from 0) and PFN of newly allocated paged. If PFN of newly allocated page is less than currently requested PFN then earlier allocated MFN is overwritten which leads to domain crash later. This patch corrects that issue. If PFN of newly allocated page is less then currently requested PFN then relevant PFN/MFN pair is properly calculated and usual exchange occurs later. Signed-off-by: Daniel Kiper <dkiper@net-space.pl> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org> xen-unstable changeset: 23249:83fe79c0225f xen-unstable date: Wed Apr 27 13:29:14 2011 +0100
-rw-r--r--stubdom/grub/kexec.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/stubdom/grub/kexec.c b/stubdom/grub/kexec.c
index 5b86c502dc..821c71dd8b 100644
--- a/stubdom/grub/kexec.c
+++ b/stubdom/grub/kexec.c
@@ -48,6 +48,7 @@ extern void _boot(void);
static unsigned long *pages;
static unsigned long *pages_mfns;
+static xen_pfn_t *pages_moved2pfns;
static unsigned long allocated;
int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
@@ -80,6 +81,7 @@ int kexec_allocate(struct xc_dom_image *dom, xen_vaddr_t up_to)
pages = realloc(pages, new_allocated * sizeof(*pages));
pages_mfns = realloc(pages_mfns, new_allocated * sizeof(*pages_mfns));
+ pages_moved2pfns = realloc(pages_moved2pfns, new_allocated * sizeof(*pages_moved2pfns));
for (i = allocated; i < new_allocated; i++) {
/* Exchange old page of PFN i with a newly allocated page. */
xen_pfn_t old_mfn = dom->p2m_host[i];
@@ -91,6 +93,18 @@ int kexec_allocate(struct xc_dom_image *dom, xen_vaddr_t up_to)
new_pfn = PHYS_PFN(to_phys(pages[i]));
pages_mfns[i] = new_mfn = pfn_to_mfn(new_pfn);
+ /*
+ * If PFN of newly allocated page (new_pfn) is less then currently
+ * requested PFN (i) then look for relevant PFN/MFN pair. In this
+ * situation dom->p2m_host[new_pfn] no longer contains proper MFN
+ * because original page with new_pfn was moved earlier
+ * to different location.
+ */
+ for (; new_pfn < i; new_pfn = pages_moved2pfns[new_pfn]);
+
+ /* Store destination PFN of currently requested page. */
+ pages_moved2pfns[i] = new_pfn;
+
/* Put old page at new PFN */
dom->p2m_host[new_pfn] = old_mfn;