]> xenbits.xensource.com Git - people/hx242/xen.git/commitdiff
x86: properly (un)map pages in restore_all_guests.
authorHongyan Xia <hongyax@amazon.com>
Fri, 13 Sep 2019 16:59:30 +0000 (17:59 +0100)
committerHongyan Xia <hongyax@amazon.com>
Wed, 2 Oct 2019 16:16:31 +0000 (17:16 +0100)
Before, it assumed both cr3 could be accessed via a direct map. This is
no longer true.

Signed-off-by: Hongyan Xia <hongyax@amazon.com>
xen/arch/x86/x86_64/entry.S

index 11385857fa4228cc6b8de71c18e8f99555d9a231..8ca9a8e0ea1a2986394325448517a326ee0b728e 100644 (file)
@@ -150,11 +150,27 @@ restore_all_guest:
         je    .Lrag_copy_done
         movb  $0, STACK_CPUINFO_FIELD(root_pgt_changed)(%rdx)
         movabs $PADDR_MASK & PAGE_MASK, %rsi
-        movabs $DIRECTMAP_VIRT_START, %rcx
         and   %rsi, %rdi
         and   %r9, %rsi
-        add   %rcx, %rdi
-        add   %rcx, %rsi
+
+        /* Without a direct map, we have to map pages first before copying. */
+        /* FIXME: optimisations may be needed. */
+        pushq %r9
+        pushq %rdx
+        pushq %rax
+        pushq %rsi
+        shr   $PAGE_SHIFT, %rdi
+        callq map_xen_pagetable
+        popq  %rdi
+        pushq %rax
+        shr   $PAGE_SHIFT, %rdi
+        callq map_xen_pagetable
+        mov   %rax, %rsi
+        mov   0(%rsp), %rdi
+
+        /* %rsi and %rdi are on top the stack for unmapping. */
+        pushq %rsi
+
         mov   $ROOT_PAGETABLE_FIRST_XEN_SLOT, %ecx
         mov   root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rsi), %r8
         mov   %r8, root_table_offset(SH_LINEAR_PT_VIRT_START)*8(%rdi)
@@ -166,6 +182,16 @@ restore_all_guest:
         sub   $(ROOT_PAGETABLE_FIRST_XEN_SLOT - \
                 ROOT_PAGETABLE_LAST_XEN_SLOT - 1) * 8, %rdi
         rep movsq
+
+        /* Unmap the two pages. */
+        popq  %rdi
+        callq unmap_xen_pagetable
+        popq  %rdi
+        callq unmap_xen_pagetable
+        popq  %rax
+        popq  %rdx
+        popq  %r9
+
 .Lrag_copy_done:
         mov   %r9, STACK_CPUINFO_FIELD(xen_cr3)(%rdx)
         movb  $1, STACK_CPUINFO_FIELD(use_pv_cr3)(%rdx)