Tools: fix save/restore of 32-bit guests with 64-bit tools
PATCH 1/1 Tools: fix save/restore of 32-bit guests with 64-bit tools
Tools: fix save/restore of 32-bit PV guests with 64-bit tools by removing some obvious typos, handling CR3 folding and hvirt_start based on guest word-size, and understanding 32-bit INVALID_MFN.
Signed-off-by Tim Deegan <[email protected]>
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, Citrix Systems (R&D) Ltd. [Company #02300071, SL9 0DZ, UK.]
tools/libxc/xc_domain_restore.c +6 -6
@@ -251,7 +251,7 @@ static xen_pfn_t *load_p2m_frame_list(/* Now that we know the guest's word-size, can safely allocate * the p2m frame list */ -if ( (p2m_frame_list =malloc (P2M_FL_SIZE )) ==NULL ) +if ( (p2m_frame_list =malloc (P2M_TOOLS_FL_SIZE )) ==NULL ) {ERROR ("Couldn't allocate p2m_frame_list array" );return NULL ;
@@ -1040,7 +1040,7 @@ int xc_domain_restore(int xc_handle, intSET_FIELD (&ctxt, gdt_frames[j], p2m[pfn]); }/* Uncanonicalise the page table base pointer. */ - pfn =xen_cr3_to_pfn (GET_FIELD (&ctxt, ctrlreg[3 ])); + pfn =UNFOLD_CR3 (GET_FIELD (&ctxt, ctrlreg[3 ]));if ( pfn >= p2m_size ) {
@@ -1057,12 +1057,12 @@ int xc_domain_restore(int xc_handle, int (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT); goto out; } -SET_FIELD (&ctxt, ctrlreg[3 ],xen_pfn_to_cr3 (p2m[pfn])); +SET_FIELD (&ctxt, ctrlreg[3 ],FOLD_CR3 (p2m[pfn]));/* Guest pagetable (x86/64) stored in otherwise-unused CR1. */ if ( (pt_levels ==4 ) && (ctxt.x64.ctrlreg[1 ] &1 ) ) { - pfn =xen_cr3_to_pfn (ctxt.x64.ctrlreg[1 ] & ~1 ); + pfn =UNFOLD_CR3 (ctxt.x64.ctrlreg[1 ] & ~1 );if ( pfn >= p2m_size ) { ERROR("User PT base is bad: pfn=%lu p2m_size=%lu",
@@ -1077,7 +1077,7 @@ int xc_domain_restore(int xc_handle, int (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT); goto out; } - ctxt.x64.ctrlreg[1 ] =xen_pfn_to_cr3 (p2m[pfn]); + ctxt.x64.ctrlreg[1 ] =FOLD_CR3 (p2m[pfn]); } domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = (domid_t )dom;
@@ -1158,7 +1158,7 @@ int xc_domain_restore(int xc_handle, intif ( guest_width >sizeof (xen_pfn_t) )for ( i = p2m_size -1 ; i >=0 ; i-- ) ((uint64_t *)p2m)[i] = p2m[i]; -else if ( guest_width >sizeof (xen_pfn_t) ) +else if ( guest_width <sizeof (xen_pfn_t) )for ( i =0 ; i < p2m_size; i++ ) ((uint32_t *)p2m)[i] = p2m[i];
tools/libxc/xc_domain_save.c +25 -23
109 lines not on this page · raw message
tools/libxc/xg_private.h +3 -1
@@ -155,7 +155,9 @@ typedef l4_pgentry_64_t l4_pgentry_t;#define P2M_FL_ENTRIES (((p2m_size)+FPP-1)/FPP)/* Size in bytes of the pfn_to_mfn_frame_list */ -#define P2M_FL_SIZE ((P2M_FL_ENTRIES)*(guest_width)) +#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (guest_width)) +#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) * \ + MAX((sizeof (xen_pfn_t)), guest_width))/* Masks for PTE<->PFN conversions */ #define MADDR_BITS_X86 ((guest_width == 8) ? 52 : 44)
tools/libxc/xg_save_restore.h +17 -0
@@ -68,6 +68,13 @@ static inline int get_platform_info(int *guest_width = domctl.u.address_size.size /8 ; +/* 64-bit tools will see the 64-bit hvirt_start, but 32-bit guests +* will be using the compat one. */ +if ( *guest_width <sizeof (unsigned long ) ) +/* XXX need to fix up a way of extracting this value from Xen if +* XXX it becomes variable for domU */ + *hvirt_start =0xf5800000 ; +if (strstr (xen_caps,"xen-3.0-x86_64" ))/* Depends on whether it's a compat 32-on-64 guest */ *pt_levels = ( (*guest_width ==8 ) ?4 :3 );
@@ -136,6 +143,16 @@ typedef union (_p)->x32._f = (_v); \ } while (0) +#define UNFOLD_CR3 (_c) \ + ((uint64_t)((guest_width == 8) \ + ? ((_c) >> 12) \ + : (((uint32_t)(_c) >> 12) | ((uint32_t)(_c) << 20)))) + +#define FOLD_CR3 (_c) \ + ((uint64_t)((guest_width == 8) \ + ? ((uint64_t)(_c)) << 12 \ + : (((uint32_t)(_c) << 12) | ((uint32_t)(_c) >> 20)))) +#define MEMCPY_FIELD (_d, _s, _f) do { \ if (guest_width == 8) \ memcpy(&(_d)->x64._f, &(_s)->x64._f,sizeof((_d)->x64._f)); \
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel