x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image
authorDaniel Kiper <daniel.kiper@oracle.com>
Fri, 20 Apr 2018 09:54:00 +0000 (11:54 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 28 Jun 2018 07:28:42 +0000 (09:28 +0200)
commitcfc888f8cc5e0070df9c60b2cef068aef7dc3257
tree5ca7df904f1c5aa7f2600ff7a5d529a2aaef3ee7
parent149b321279fe8edf87b7f68134e78eb8be47ce6a
x86/setup: properly update PTEs if src/dst overlaps when relocating Xen image

Commit 0d31d16 (x86/setup: do not relocate Xen over current Xen image
placement) disallowed src/dst images overlaps when relocating Xen image.
Though it deliberately allowed destination region between __image_base__
and (__image_base__ + XEN_IMG_OFFSET) overlaps with the end of source
image. And here is the problem. If anything between __page_tables_start
and __page_tables_end in source image lands in the overlap then some or
even all page table entries may not be updated. This usually means boom
in early boot which will be difficult to the investigate. So, I think
that we have three choices to fix the issue:
  - drop XEN_IMG_OFFSET from
    if ( (end > s) && (end - reloc_size + XEN_IMG_OFFSET >= __pa(_end)) )
  - add XEN_IMG_OFFSET to xen_phys_start in PFN_DOWN(xen_phys_start)
    used in loops as one of conditions and replace ">" with ">=",
  - change PFN_DOWN(xen_phys_start) to PFN_DOWN(xen_remap_end_pfn)
    proposed in earlier version of this patch.

This patch implements the second option. This way we still allow source
and destination partial overlap as described above but PTEs are properly
updated now.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/setup.c