Sync changes to mapping changes caused by memory hotplug in page fault handler.
In compact guest situation, the compat m2p table is copied, not directly mapped
in L3, so we have to sync it.
Direct mapping range may changes, and we need sync it with guest's table.
Signed-off-by: Jiang, Yunhong <yunhong.jiang@xxxxxxxxx>
Still not find test case to walk this code patch because 32 bit compatible
guest not working on my environment. But it is tested on last round version.
diff -r 502ea9007bb9 xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c Wed Dec 09 23:00:30 2009 +0800
+++ b/xen/arch/x86/traps.c Wed Dec 09 23:00:30 2009 +0800
@@ -1229,6 +1229,10 @@ static int fixup_page_fault(unsigned lon
trace_trap_two_addr(TRC_PV_PAGING_FIXUP, regs->eip, addr);
return ret;
}
+
+ if ( !(regs->error_code & PFEC_page_present) &&
+ (pagefault_by_memadd(addr, regs)) )
+ return handle_memadd_fault(addr, regs);
if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )
{
diff -r 502ea9007bb9 xen/arch/x86/x86_64/mm.c
--- a/xen/arch/x86/x86_64/mm.c Wed Dec 09 23:00:30 2009 +0800
+++ b/xen/arch/x86/x86_64/mm.c Wed Dec 09 23:27:21 2009 +0800
@@ -1261,6 +1261,87 @@ int check_descriptor(const struct domain
return 0;
}
+int pagefault_by_memadd(unsigned long addr, struct cpu_user_regs *regs)
+{
+ struct domain *d = current->domain;
+
+ if (guest_mode(regs) &&
+ is_pv_32bit_domain(d) &&
+ ((addr >= HYPERVISOR_COMPAT_VIRT_START(d)) &&
+ (addr < MACH2PHYS_COMPAT_VIRT_END)) )
+ return 1;
+ return 0;
+}
+
+int handle_memadd_fault(unsigned long addr, struct cpu_user_regs *regs)
+{
+ struct domain *d = current->domain;
+ l4_pgentry_t *pl4e = NULL;
+ l4_pgentry_t l4e;
+ l3_pgentry_t *pl3e = NULL;
+ l3_pgentry_t l3e;
+ l2_pgentry_t *pl2e = NULL;
+ l2_pgentry_t l2e, idle_l2e;
+ unsigned long mfn, idle_index;
+ int ret = 0;
+
+ if (!is_pv_32on64_domain(d))
+ return 0;
+
+ if ((addr < HYPERVISOR_COMPAT_VIRT_START(d)) ||
+ (addr > MACH2PHYS_COMPAT_VIRT_END) )
+ return 0;
+
+ mfn = (read_cr3()) >> PAGE_SHIFT;
+
+ pl4e = map_domain_page(mfn);
+
+ l4e = pl4e[addr];
+
+ if (!(l4e_get_flags(l4e) & _PAGE_PRESENT))
+ goto unmap;
+
+ mfn = l4e_get_pfn(l4e);
+ /* We don't need get page type here since it is current CR3 */
+ pl3e = map_domain_page(mfn);
+
+ l3e = pl3e[3];
+
+ if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) )
+ goto unmap;
+
+ mfn = l3e_get_pfn(l3e);
+ pl2e = map_domain_page(mfn);
+
+ l2e = pl2e[l2_table_offset(addr)];
+
+ if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT))
+ goto unmap;
+
+ idle_index = (l2_table_offset(addr) -
+ COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(d))/
+ sizeof(l2_pgentry_t);
+ idle_l2e = compat_idle_pg_table_l2[idle_index];
+ if (!(l2e_get_flags(idle_l2e) & _PAGE_PRESENT))
+ goto unmap;
+
+ memcpy(&pl2e[l2_table_offset(addr)],
+ &compat_idle_pg_table_l2[idle_index],
+ sizeof(l2_pgentry_t));
+
+ ret = EXCRET_fault_fixed;
+
+unmap:
+ if ( pl4e )
+ unmap_domain_page(pl4e);
+ if ( pl3e )
+ unmap_domain_page(pl3e);
+ if ( pl2e )
+ unmap_domain_page(pl2e);
+
+ return ret;
+}
+
void domain_set_alloc_bitsize(struct domain *d)
{
if ( !is_pv_32on64_domain(d) ||
diff -r 502ea9007bb9 xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h Wed Dec 09 23:00:30 2009 +0800
+++ b/xen/include/asm-x86/mm.h Wed Dec 09 23:26:24 2009 +0800
@@ -476,6 +476,21 @@ int ptwr_do_page_fault(struct vcpu *, u
int audit_adjust_pgtables(struct domain *d, int dir, int noisy);
+#ifdef CONFIG_X86_64
+extern int pagefault_by_memadd(unsigned long addr, struct cpu_user_regs *regs);
+extern int handle_memadd_fault(unsigned long addr, struct cpu_user_regs *regs);
+#else
+int pagefault_by_memadd(unsigned long addr, struct cpu_user_regs *regs)
+{
+ return 0;
+}
+
+int handle_memadd_fault(unsigned long addr, struct cpu_user_regs *regs)
+{
+ return 0;
+}
+#endif
+
#ifndef NDEBUG
#define AUDIT_SHADOW_ALREADY_LOCKED ( 1u << 0 )
05-page_fault.patch
Description: 05-page_fault.patch
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|