From: "Jan Beulich" Subject: [PATCH] x86/EFI + Live Patch: avoid symbol address truncation Date: Tue, 28 Jun 2016 08:03:57 -0600 Message-ID: <57729FED02000078000F975B@prv-mh.provo.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part13253BDD.1__=" Return-path: Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bHtcR-0006Sh-UM for xen-devel@lists.xenproject.org; Tue, 28 Jun 2016 14:04:04 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel Cc: Andrew Cooper 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. --=__Part13253BDD.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ld associates __init_end, placed outside of any section by the linker script, with the following section, resulting in a huge (wrapped, as it would be negative) section relative offset. COFF symbol tables store section relative addresses, and hence the above leads to assembler truncation warnings when all symbols get included in the symbol table (for Live Patching code). To overcome this, move __init_end past both ALIGN() directives. The consuming code (init_done()) is fine with such an adjustment (the distinction really would only be relevant for the loop claring the pages, and I think it's acceptable to clear a few more on - for now - EFI). This effectively results in the (__init_begin,__init_end) and (__2M_init_start,__2M_init_end) pairs to become identical, with their different names only serving documentation purposes now. Note that moving __init_end and __2M_init_end into .init is not a good idea, as that would significantly grow xen.efi binary size. While inspecting symbol table and ld behavior I also noticed that __2M_text_start gets put at address zero in the EFI case, which hasn't caused problems solely because we don't actually reference that symbol. Correct the setting of the initial address, and comment out said symbol for the time being, as with the initial address correction it would in turn cause an assembler truncation warning similar to the one mentioned above. While checking init_done() for correctness with the above changes I noticed that code can easily be folded there, at once correcting the logged amount of memory which has got freed for the 2M-alignment case (i.e. EFI right now). Signed-off-by: Jan Beulich --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -515,6 +515,7 @@ static inline bool_t using_2M_mapping(vo static void noinline init_done(void) { void *va; + unsigned long start, end; =20 system_state =3D SYS_STATE_active; =20 @@ -530,18 +531,18 @@ static void noinline init_done(void) /* Destroy Xen's mappings, and reuse the pages. */ if ( using_2M_mapping() ) { - destroy_xen_mappings((unsigned long)&__2M_init_start, - (unsigned long)&__2M_init_end); - init_xenheap_pages(__pa(__2M_init_start), __pa(__2M_init_end)); + start =3D (unsigned long)&__2M_init_start, + end =3D (unsigned long)&__2M_init_end; } else { - destroy_xen_mappings((unsigned long)&__init_begin, - (unsigned long)&__init_end); - init_xenheap_pages(__pa(__init_begin), __pa(__init_end)); + start =3D (unsigned long)&__init_begin; + end =3D (unsigned long)&__init_end; } =20 - printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>= 10); + destroy_xen_mappings(start, end); + init_xenheap_pages(__pa(start), __pa(end)); + printk("Freed %ldkB init memory\n", (end - start) >> 10); =20 startup_cpu_idle_loop(); } --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -40,9 +40,20 @@ SECTIONS #if !defined(EFI) . =3D __XEN_VIRT_START; __image_base__ =3D .; +#else + . =3D __image_base__; #endif =20 +#if 0 +/* + * We don't really use this symbol anywhere, and the way it would get = defined + * here would result in it having a negative (wrapped to huge positive) + * offset relative to the .text section. That, in turn, causes an = assembler + * truncation warning when including all symbols in the symbol table for = Live + * Patching code. + */ __2M_text_start =3D .; /* Start of 2M superpages, mapped RX. */ +#endif =20 . =3D __XEN_VIRT_START + MB(1); _start =3D .; @@ -194,14 +205,13 @@ SECTIONS *(.ctors) __ctors_end =3D .; } :text - . =3D ALIGN(PAGE_SIZE); - __init_end =3D .; =20 #ifdef EFI . =3D ALIGN(MB(2)); #else . =3D ALIGN(PAGE_SIZE); #endif + __init_end =3D .; __2M_init_end =3D .; =20 __2M_rwdata_start =3D .; /* Start of 2M superpages, mapped RW. */ @@ -296,7 +306,6 @@ ASSERT(__image_base__ > XEN_VIRT_START | ASSERT(kexec_reloc_size - kexec_reloc <=3D PAGE_SIZE, "kexec_reloc is too = large") #endif =20 -ASSERT(IS_ALIGNED(__2M_text_start, MB(2)), "__2M_text_start misaligned")= #ifdef EFI ASSERT(IS_ALIGNED(__2M_text_end, MB(2)), "__2M_text_end misaligned") ASSERT(IS_ALIGNED(__2M_rodata_start, MB(2)), "__2M_rodata_start misaligned= ") --=__Part13253BDD.1__= Content-Type: text/plain; name="x86-EFI-symbol-truncation.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-EFI-symbol-truncation.patch" x86/EFI + Live Patch: avoid symbol address truncation=0A=0Ald associates = __init_end, placed outside of any section by the linker=0Ascript, with the = following section, resulting in a huge (wrapped, as it=0Awould be = negative) section relative offset. COFF symbol tables store=0Asection = relative addresses, and hence the above leads to assembler=0Atruncation = warnings when all symbols get included in the symbol table=0A(for Live = Patching code). To overcome this, move __init_end past both=0AALIGN() = directives. The consuming code (init_done()) is fine with such=0Aan = adjustment (the distinction really would only be relevant for the=0Aloop = claring the pages, and I think it's acceptable to clear a few=0Amore on - = for now - EFI). This effectively results in the=0A(__init_begin,__init_end)= and (__2M_init_start,__2M_init_end) pairs to=0Abecome identical, with = their different names only serving documentation=0Apurposes now.=0A=0ANote = that moving __init_end and __2M_init_end into .init is not a good=0Aidea, = as that would significantly grow xen.efi binary size.=0A=0AWhile inspecting= symbol table and ld behavior I also noticed that=0A__2M_text_start gets = put at address zero in the EFI case, which hasn't=0Acaused problems solely = because we don't actually reference that symbol.=0ACorrect the setting of = the initial address, and comment out said symbol=0Afor the time being, as = with the initial address correction it would in=0Aturn cause an assembler = truncation warning similar to the one mentioned=0Aabove.=0A=0AWhile = checking init_done() for correctness with the above changes I=0Anoticed = that code can easily be folded there, at once correcting the=0Alogged = amount of memory which has got freed for the 2M-alignment case=0A(i.e. EFI = right now).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/setup.c=0A+++ b/xen/arch/x86/setup.c=0A@@ -515,6 +515,7 @@ = static inline bool_t using_2M_mapping(vo=0A static void noinline init_done(= void)=0A {=0A void *va;=0A+ unsigned long start, end;=0A =0A = system_state =3D SYS_STATE_active;=0A =0A@@ -530,18 +531,18 @@ static void = noinline init_done(void)=0A /* Destroy Xen's mappings, and reuse the = pages. */=0A if ( using_2M_mapping() )=0A {=0A- destroy_xen_= mappings((unsigned long)&__2M_init_start,=0A- = (unsigned long)&__2M_init_end);=0A- init_xenheap_pages(__pa(__2M_ini= t_start), __pa(__2M_init_end));=0A+ start =3D (unsigned long)&__2M_i= nit_start,=0A+ end =3D (unsigned long)&__2M_init_end;=0A }=0A = else=0A {=0A- destroy_xen_mappings((unsigned long)&__init_be= gin,=0A- (unsigned long)&__init_end);=0A- = init_xenheap_pages(__pa(__init_begin), __pa(__init_end));=0A+ = start =3D (unsigned long)&__init_begin;=0A+ end =3D (unsigned = long)&__init_end;=0A }=0A =0A- printk("Freed %ldkB init memory.\n", = (long)(__init_end-__init_begin)>>10);=0A+ destroy_xen_mappings(start, = end);=0A+ init_xenheap_pages(__pa(start), __pa(end));=0A+ printk("Fre= ed %ldkB init memory\n", (end - start) >> 10);=0A =0A startup_cpu_idle_= loop();=0A }=0A--- a/xen/arch/x86/xen.lds.S=0A+++ b/xen/arch/x86/xen.lds.S= =0A@@ -40,9 +40,20 @@ SECTIONS=0A #if !defined(EFI)=0A . =3D __XEN_VIRT_S= TART;=0A __image_base__ =3D .;=0A+#else=0A+ . =3D __image_base__;=0A = #endif=0A =0A+#if 0=0A+/*=0A+ * We don't really use this symbol anywhere, = and the way it would get defined=0A+ * here would result in it having a = negative (wrapped to huge positive)=0A+ * offset relative to the .text = section. That, in turn, causes an assembler=0A+ * truncation warning when = including all symbols in the symbol table for Live=0A+ * Patching = code.=0A+ */=0A __2M_text_start =3D .; /* Start of 2M superpages,= mapped RX. */=0A+#endif=0A =0A . =3D __XEN_VIRT_START + MB(1);=0A = _start =3D .;=0A@@ -194,14 +205,13 @@ SECTIONS=0A *(.ctors)=0A = __ctors_end =3D .;=0A } :text=0A- . =3D ALIGN(PAGE_SIZE);=0A- = __init_end =3D .;=0A =0A #ifdef EFI=0A . =3D ALIGN(MB(2));=0A #else=0A = . =3D ALIGN(PAGE_SIZE);=0A #endif=0A+ __init_end =3D .;=0A __2M_init_end= =3D .;=0A =0A __2M_rwdata_start =3D .; /* Start of 2M superpages, = mapped RW. */=0A@@ -296,7 +306,6 @@ ASSERT(__image_base__ > XEN_VIRT_START = |=0A ASSERT(kexec_reloc_size - kexec_reloc <=3D PAGE_SIZE, "kexec_reloc is = too large")=0A #endif=0A =0A-ASSERT(IS_ALIGNED(__2M_text_start, MB(2)), = "__2M_text_start misaligned")=0A #ifdef EFI=0A ASSERT(IS_ALIGNED(__2M_text_= end, MB(2)), "__2M_text_end misaligned")=0A ASSERT(IS_ALIGNED(__2M_roda= ta_start, MB(2)), "__2M_rodata_start misaligned")=0A --=__Part13253BDD.1__= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --=__Part13253BDD.1__=--