From: "Bruce Rogers" Subject: [PATCH] Support cross-bitness guest when core-dumping Date: Wed, 14 Jan 2009 16:47:41 -0700 Message-ID: <496E172D0200004800067E52@lucius.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartBB93918D.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartBB93918D.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This patch allows core-dumping to work on a cross-bit host/guest configurat= ion, whereas previously that was not supported. It supports both PV and = FV guests. The core file format generated by the host, needs to match that = of the guest, so an alignment issue is addressed, along with the p2m frame = list handling being done according to the guest size. Signed-off-by: Bruce Rogers --=__PartBB93918D.0__= Content-Type: text/plain; name="cross-bit-core-dump.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cross-bit-core-dump.patch" diff -r 77476eeb8c42 tools/libxc/xc_core.c=0A--- a/tools/libxc/xc_core.c = Wed Jan 14 11:39:01 2009 +0000=0A+++ b/tools/libxc/xc_core.c Wed Jan 14 = 16:40:17 2009 -0700=0A@@ -57,9 +57,6 @@=0A =0A /* number of pages to write = at a time */=0A #define DUMP_INCREMENT (4 * 1024)=0A-=0A-/* Don't yet = support cross-address-size core dump */=0A-#define guest_width (sizeof = (unsigned long))=0A =0A /* string table */=0A struct xc_core_strtab {=0A@@ = -240,7 +237,7 @@ xc_core_ehdr_init(Elf64_Ehdr *ehdr)=0A ehdr->e_ident[E= I_ABIVERSION] =3D EV_CURRENT;=0A =0A ehdr->e_type =3D ET_CORE;=0A- = ehdr->e_machine =3D ELF_ARCH_MACHINE;=0A+ /* e_machine will be filled = in later */=0A ehdr->e_version =3D EV_CURRENT;=0A ehdr->e_entry = =3D 0;=0A ehdr->e_phoff =3D 0;=0A@@ -359,7 +356,8 @@ elfnote_dump_core_= header(=0A }=0A =0A static int=0A-elfnote_dump_xen_version(void *args, = dumpcore_rtn_t dump_rtn, int xc_handle)=0A+elfnote_dump_xen_version(void = *args, dumpcore_rtn_t dump_rtn, int xc_handle,=0A+ = unsigned int guest_width)=0A {=0A int sts;=0A struct elfnote = elfnote;=0A@@ -371,6 +369,12 @@ elfnote_dump_xen_version(void *args, = dum=0A elfnote.descsz =3D sizeof(xen_version);=0A elfnote.type =3D = XEN_ELFNOTE_DUMPCORE_XEN_VERSION;=0A elfnote_fill_xen_version(xc_handle= , &xen_version);=0A+ if (guest_width < sizeof(unsigned long))=0A+ = {=0A+ // 32 bit elf file format differs in pagesize's alignment=0A+ = char *p =3D (char *)&xen_version.pagesize;=0A+ memmove(p - = 4, p, sizeof(xen_version.pagesize));=0A+ }=0A sts =3D dump_rtn(args,= (char*)&elfnote, sizeof(elfnote));=0A if ( sts !=3D 0 )=0A = return sts;=0A@@ -396,6 +400,24 @@ elfnote_dump_format_version(void *args, = =0A return dump_rtn(args, (char*)&format_version, sizeof(format_version= ));=0A }=0A =0A+static int=0A+get_guest_width(int xc_handle,=0A+ = uint32_t domid,=0A+ unsigned int *guest_width)=0A+{=0A+= DECLARE_DOMCTL;=0A+=0A+ memset(&domctl, 0, sizeof(domctl));=0A+ = domctl.domain =3D domid;=0A+ domctl.cmd =3D XEN_DOMCTL_get_address_size;= =0A+=0A+ if ( do_domctl(xc_handle, &domctl) !=3D 0 )=0A+ return = 1;=0A+ =0A+ *guest_width =3D domctl.u.address_size.size / 8;=0A+ = return 0;=0A+}=0A+=0A int=0A xc_domain_dumpcore_via_callback(int = xc_handle,=0A uint32_t domid,=0A@@ -403,7 = +425,8 @@ xc_domain_dumpcore_via_callback(int xc_h=0A = dumpcore_rtn_t dump_rtn)=0A {=0A xc_dominfo_t info;=0A- = shared_info_t *live_shinfo =3D NULL;=0A+ shared_info_any_t *live_shinfo = =3D NULL;=0A+ unsigned int guest_width; =0A =0A int nr_vcpus =3D = 0;=0A char *dump_mem, *dump_mem_start =3D NULL;=0A@@ -437,6 +460,12 @@ = xc_domain_dumpcore_via_callback(int xc_h=0A uint16_t strtab_idx;=0A = struct xc_core_section_headers *sheaders =3D NULL;=0A Elf64_Shdr = *shdr;=0A+ =0A+ if ( get_guest_width(xc_handle, domid, &guest_width) = !=3D 0 )=0A+ {=0A+ PERROR("Could not get address size for = domain");=0A+ return sts;=0A+ }=0A =0A xc_core_arch_context_i= nit(&arch_ctxt);=0A if ( (dump_mem_start =3D malloc(DUMP_INCREMENT*PAGE= _SIZE)) =3D=3D NULL )=0A@@ -500,7 +529,7 @@ xc_domain_dumpcore_via_callback= (int xc_h=0A goto out;=0A }=0A =0A- sts =3D = xc_core_arch_map_p2m(xc_handle, &info, live_shinfo,=0A+ sts =3D = xc_core_arch_map_p2m(xc_handle, guest_width, &info, live_shinfo,=0A = &p2m, &p2m_size);=0A if ( sts !=3D 0 = )=0A goto out;=0A@@ -676,6 +705,7 @@ xc_domain_dumpcore_via_cal= lback(int xc_h=0A /* write out elf header */=0A ehdr.e_shnum =3D = sheaders->num;=0A ehdr.e_shstrndx =3D strtab_idx;=0A+ ehdr.e_machine= =3D ELF_ARCH_MACHINE;=0A sts =3D dump_rtn(args, (char*)&ehdr, = sizeof(ehdr));=0A if ( sts !=3D 0 )=0A goto out;=0A@@ -697,7 = +727,7 @@ xc_domain_dumpcore_via_callback(int xc_h=0A goto out;=0A = =0A /* elf note section: xen version */=0A- sts =3D elfnote_dump_xen= _version(args, dump_rtn, xc_handle);=0A+ sts =3D elfnote_dump_xen_versio= n(args, dump_rtn, xc_handle, guest_width);=0A if ( sts !=3D 0 )=0A = goto out;=0A =0A@@ -757,9 +787,21 @@ xc_domain_dumpcore_via_callback(in= t xc_h=0A =0A if ( !auto_translated_physmap )=0A = {=0A- gmfn =3D p2m[i];=0A- if ( gmfn =3D=3D = INVALID_P2M_ENTRY )=0A- continue;=0A+ if = ( guest_width >=3D sizeof(unsigned long) )=0A+ {=0A+ = if ( guest_width =3D=3D sizeof(unsigned long) )=0A+ = gmfn =3D p2m[i];=0A+ else=0A+ = gmfn =3D ((uint64_t *)p2m)[i];=0A+ if ( gmfn = =3D=3D INVALID_P2M_ENTRY )=0A+ continue;=0A+ = }=0A+ else=0A+ {=0A+ = gmfn =3D ((uint32_t *)p2m)[i];=0A+ if ( gmfn =3D=3D = (uint32_t)INVALID_P2M_ENTRY )=0A+ continue;=0A+ = }=0A =0A p2m_array[j].pfn =3D i;=0A = p2m_array[j].gmfn =3D gmfn;=0A@@ -802,7 +844,7 @@ copy_done:=0A = /* When live dump-mode (-L option) is specified,=0A * guest = domain may reduce memory. pad with zero pages.=0A */=0A- = IPRINTF("j (%ld) !=3D nr_pages (%ld)", j , nr_pages);=0A+ IPRINTF("j= (%ld) !=3D nr_pages (%ld)", j, nr_pages);=0A memset(dump_mem_start= , 0, PAGE_SIZE);=0A for (; j < nr_pages; j++) {=0A sts = =3D dump_rtn(args, dump_mem_start, PAGE_SIZE);=0A@@ -891,7 +933,7 @@ = xc_domain_dumpcore(int xc_handle,=0A struct dump_args da;=0A int = sts;=0A =0A- if ( (da.fd =3D open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IR= USR)) < 0 )=0A+ if ( (da.fd =3D open(corename, O_CREAT|O_RDWR|O_TRUNC, = S_IWUSR|S_IRUSR)) < 0 )=0A {=0A PERROR("Could not open = corefile %s", corename);=0A return -errno;=0Adiff -r 77476eeb8c42 = tools/libxc/xc_core.h=0A--- a/tools/libxc/xc_core.h Wed Jan 14 = 11:39:01 2009 +0000=0A+++ b/tools/libxc/xc_core.h Wed Jan 14 = 16:40:17 2009 -0700=0A@@ -136,12 +136,12 @@ struct xc_core_arch_context;=0A= struct xc_core_arch_context;=0A int xc_core_arch_memory_map_get(int = xc_handle,=0A struct xc_core_arch_context = *arch_ctxt,=0A- xc_dominfo_t *info, = shared_info_t *live_shinfo,=0A+ xc_dominfo_t= *info, shared_info_any_t *live_shinfo,=0A = xc_core_memory_map_t **mapp,=0A unsigned = int *nr_entries);=0A-int xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t = *info,=0A- shared_info_t *live_shinfo, xen_pfn_t = **live_p2m,=0A- unsigned long *pfnp);=0A+int = xc_core_arch_map_p2m(int xc_handle, unsigned int guest_width,=0A+ = xc_dominfo_t *info, shared_info_any_t *live_shinfo,=0A+ = xen_pfn_t **live_p2m, unsigned long *pfnp);=0A =0A =0A = #if defined (__i386__) || defined (__x86_64__)=0Adiff -r 77476eeb8c42 = tools/libxc/xc_core_ia64.c=0A--- a/tools/libxc/xc_core_ia64.c Wed Jan 14 = 11:39:01 2009 +0000=0A+++ b/tools/libxc/xc_core_ia64.c Wed Jan 14 = 16:40:17 2009 -0700=0A@@ -235,7 +235,7 @@ old:=0A }=0A =0A int=0A-xc_core_a= rch_map_p2m(int xc_handle, xc_dominfo_t *info,=0A+xc_core_arch_map_p2m(int = xc_handle, unsigned int guest_width, xc_dominfo_t *info,=0A = shared_info_t *live_shinfo, xen_pfn_t **live_p2m,=0A = unsigned long *pfnp)=0A {=0Adiff -r 77476eeb8c42 tools/libxc/xc_core_x= 86.c=0A--- a/tools/libxc/xc_core_x86.c Wed Jan 14 11:39:01 2009 +0000=0A++= + b/tools/libxc/xc_core_x86.c Wed Jan 14 16:40:17 2009 -0700=0A@@ -20,9 = +20,25 @@=0A =0A #include "xg_private.h"=0A #include "xc_core.h"=0A+#includ= e "xc_e820.h"=0A =0A-/* Don't yet support cross-address-size core dump = */=0A-#define guest_width (sizeof (unsigned long))=0A+#define GET_FIELD(_p,= _f) ((guest_width=3D=3D8) ? ((_p)->x64._f) : ((_p)->x32._f))=0A+=0A+#ifnde= f MAX=0A+#define MAX(_a, _b) ((_a) >=3D (_b) ? (_a) : (_b))=0A+#endif=0A+= =0A+int=0A+xc_core_arch_gpfn_may_present(struct xc_core_arch_context = *arch_ctxt,=0A+ unsigned long pfn)=0A+{=0A+ = if ((pfn >=3D 0xa0 && pfn < 0xc0) /* VGA hole */=0A+ || (pfn >=3D = (HVM_BELOW_4G_MMIO_START >> PAGE_SHIFT)=0A+ && pfn < (1ULL<<32) = >> PAGE_SHIFT)) /* MMIO */=0A+ return 0;=0A+ return 1;=0A+}=0A+= =0A =0A static int nr_gpfns(int xc_handle, domid_t domid)=0A {=0A@@ -37,7 = +53,7 @@ xc_core_arch_auto_translated_physmap(con=0A =0A int=0A xc_core_arc= h_memory_map_get(int xc_handle, struct xc_core_arch_context *unused,=0A- = xc_dominfo_t *info, shared_info_t *live_shinfo,=0A= + xc_dominfo_t *info, shared_info_any_t = *live_shinfo,=0A xc_core_memory_map_t = **mapp,=0A unsigned int *nr_entries)=0A {=0A@@ = -60,17 +76,22 @@ xc_core_arch_memory_map_get(int xc_handl=0A }=0A =0A = int=0A-xc_core_arch_map_p2m(int xc_handle, xc_dominfo_t *info,=0A- = shared_info_t *live_shinfo, xen_pfn_t **live_p2m,=0A+xc_core_ar= ch_map_p2m(int xc_handle, unsigned int guest_width, xc_dominfo_t *info,=0A+= shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m,= =0A unsigned long *pfnp)=0A {=0A /* Double and = single indirect references to the live P2M table */=0A xen_pfn_t = *live_p2m_frame_list_list =3D NULL;=0A xen_pfn_t *live_p2m_frame_list = =3D NULL;=0A+ /* Copies of the above. */=0A+ xen_pfn_t *p2m_frame_lis= t_list =3D NULL;=0A+ xen_pfn_t *p2m_frame_list =3D NULL;=0A+=0A = uint32_t dom =3D info->domid;=0A unsigned long p2m_size =3D nr_gpfns(xc= _handle, info->domid);=0A int ret =3D -1;=0A int err;=0A+ int = i;=0A =0A if ( p2m_size < info->nr_pages )=0A {=0A@@ -80,7 +101,7 = @@ xc_core_arch_map_p2m(int xc_handle, xc_d=0A =0A live_p2m_frame_list_= list =3D=0A xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, = PROT_READ,=0A- live_shinfo->arch.pfn_to_mfn_fra= me_list_list);=0A+ GET_FIELD(live_shinfo, = arch.pfn_to_mfn_frame_list_list));=0A =0A if ( !live_p2m_frame_list_lis= t )=0A {=0A@@ -88,9 +109,28 @@ xc_core_arch_map_p2m(int xc_handle, = xc_d=0A goto out;=0A }=0A =0A+ /* Get a local copy of the = live_P2M_frame_list_list */=0A+ if ( !(p2m_frame_list_list =3D = malloc(PAGE_SIZE)) )=0A+ {=0A+ ERROR("Couldn't allocate = p2m_frame_list_list array");=0A+ goto out;=0A+ }=0A+ = memcpy(p2m_frame_list_list, live_p2m_frame_list_list, PAGE_SIZE);=0A+=0A+ = /* Canonicalize guest's unsigned long vs ours */=0A+ if ( guest_width = > sizeof(unsigned long) )=0A+ for ( i =3D 0; i < PAGE_SIZE/sizeof(un= signed long); i++ )=0A+ if ( i < PAGE_SIZE/guest_width )=0A+ = p2m_frame_list_list[i] =3D ((uint64_t *)p2m_frame_list_list)[i]= ;=0A+ else=0A+ p2m_frame_list_list[i] =3D 0;=0A+ = else if ( guest_width < sizeof(unsigned long) )=0A+ for ( i =3D = PAGE_SIZE/sizeof(unsigned long) - 1; i >=3D 0; i-- )=0A+ = p2m_frame_list_list[i] =3D ((uint32_t *)p2m_frame_list_list)[i];=0A+=0A = live_p2m_frame_list =3D=0A xc_map_foreign_pages(xc_handle, dom, = PROT_READ,=0A- live_p2m_frame_list_list,=0A+ = p2m_frame_list_list,=0A = P2M_FLL_ENTRIES);=0A =0A if ( !live_p2m_frame_list )=0A@@ -99,8 = +139,25 @@ xc_core_arch_map_p2m(int xc_handle, xc_d=0A goto = out;=0A }=0A =0A+ /* Get a local copy of the live_P2M_frame_list = */=0A+ if ( !(p2m_frame_list =3D malloc(P2M_TOOLS_FL_SIZE)) )=0A+ = {=0A+ ERROR("Couldn't allocate p2m_frame_list array");=0A+ = goto out;=0A+ }=0A+ memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE);=0A+= memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE);=0A+=0A+= /* Canonicalize guest's unsigned long vs ours */=0A+ if ( guest_widt= h > sizeof(unsigned long) )=0A+ for ( i =3D 0; i < P2M_FL_ENTRIES; = i++ )=0A+ p2m_frame_list[i] =3D ((uint64_t *)p2m_frame_list)[i];= =0A+ else if ( guest_width < sizeof(unsigned long) )=0A+ for ( i = =3D P2M_FL_ENTRIES - 1; i >=3D 0; i-- )=0A+ p2m_frame_list[i] = =3D ((uint32_t *)p2m_frame_list)[i];=0A+=0A *live_p2m =3D xc_map_foreig= n_pages(xc_handle, dom, PROT_READ,=0A- = live_p2m_frame_list,=0A+ p2m_frame_list,= =0A P2M_FL_ENTRIES);=0A =0A if ( = !*live_p2m )=0A@@ -122,6 +179,12 @@ out:=0A if ( live_p2m_frame_list = )=0A munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);=0A = =0A+ if ( p2m_frame_list_list )=0A+ free(p2m_frame_list_list);=0A= +=0A+ if ( p2m_frame_list )=0A+ free(p2m_frame_list);=0A+=0A = errno =3D err;=0A return ret;=0A }=0Adiff -r 77476eeb8c42 tools/libxc/x= c_core_x86.h=0A--- a/tools/libxc/xc_core_x86.h Wed Jan 14 11:39:01 2009 = +0000=0A+++ b/tools/libxc/xc_core_x86.h Wed Jan 14 16:40:17 2009 -0700=0A@@= -21,15 +21,8 @@=0A #ifndef XC_CORE_X86_H=0A #define XC_CORE_X86_H=0A = =0A-#if defined(__i386__) || defined(__x86_64__)=0A #define ELF_ARCH_DATA = ELFDATA2LSB=0A-#if defined (__i386__)=0A-# define ELF_ARCH_MACHINE= EM_386=0A-#else=0A-# define ELF_ARCH_MACHINE EM_X86_64=0A-#end= if=0A-#endif /* __i386__ or __x86_64__ */=0A-=0A+#define ELF_ARCH_MACHINE = (guest_width =3D=3D 8 ? EM_X86_64 : EM_386)=0A =0A struct xc_core_arch= _context {=0A /* nothing */=0A@@ -40,8 +33,10 @@ struct xc_core_arch_co= ntext {=0A #define xc_core_arch_context_get(arch_ctxt, ctxt, xc_handle, = domid) \=0A = (0)=0A #define xc_core_arch_context_dump(arch_ctxt, args, dump_rtn) = (0)=0A-#define xc_core_arch_gpfn_may_present(arch_ctxt, i) = (1)=0A =0A+int=0A+xc_core_arch_gpfn_may_present(struct xc_core_arch_context= *arch_ctxt,=0A+ unsigned long pfn);=0A = static inline int=0A xc_core_arch_context_get_shdr(struct xc_core_arch_cont= ext *arch_ctxt, =0A struct xc_core_section_he= aders *sheaders,=0A --=__PartBB93918D.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartBB93918D.0__=--