From: Keir Fraser Subject: Re: Re: [Xen-changelog] [xen-3.4-testing] tboot: fix tboot memory mapping for 32b Date: Thu, 01 Oct 2009 18:29:33 +0100 Message-ID: References: <521a4d120910010947t47c7782fn6f0a068dccabb7a9@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <521a4d120910010947t47c7782fn6f0a068dccabb7a9@mail.gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Mark Johnson , "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org I'll backport the fix. Thanks. K. On 01/10/2009 17:47, "Mark Johnson" wrote: > FYI. I'm seeing the same error with this patch that we saw > in unstable. >=20 > tboot.c: In function `tboot_copy_memory': > tboot.c:77: warning: 'map_addr' might be used uninitialized in this funct= ion > gmake[5]: *** [tboot.o] Error 1 >=20 >=20 > MRJ >=20 >=20 > On Thu, Oct 1, 2009 at 11:25 AM, Xen patchbot-3.4-testing > wrote: >> # HG changeset patch >> # User Keir Fraser >> # Date 1254410050 -3600 >> # Node ID efcb14260292a686740cee8239aae0a503097eb8 >> # Parent =A01764b0cba2e9dcf1684d5c82975302277ba62064 >> tboot: fix tboot memory mapping for 32b >>=20 >> This patch used fixmap to get TXT heap base/size and SINIT base/size >> from TXT pub config registers (whose address starts from 0xfed20000), >> and get DMAR table copy from TXT heap (whose address may start from >> 0x7d520000) for tboot, instead of using map_pages_to_xen(), which will >> cause panic on x86_32. >>=20 >> Signed-off-by: Shane Wang >> xen-unstable changeset: =A0 20242:bcb6b95b30b1 >> xen-unstable date: =A0 =A0 =A0 =A0Tue Sep 22 08:36:40 2009 +0100 >> --- >> =A0xen/arch/x86/tboot.c =A0 =A0 =A0 =A0 | =A0 94 >> ++++++++++++++++++++++++------------------- >> =A0xen/include/asm-x86/fixmap.h | =A0 =A01 >> =A02 files changed, 54 insertions(+), 41 deletions(-) >>=20 >> diff -r 1764b0cba2e9 -r efcb14260292 xen/arch/x86/tboot.c >> --- a/xen/arch/x86/tboot.c =A0 =A0 =A0Thu Oct 01 16:13:03 2009 +0100 >> +++ b/xen/arch/x86/tboot.c =A0 =A0 =A0Thu Oct 01 16:14:10 2009 +0100 >> @@ -70,12 +70,29 @@ typedef struct __packed { >> =A0 =A0 uint32_t =A0 =A0 vtd_dmars_off; >> =A0} sinit_mle_data_t; >>=20 >> +static void tboot_copy_memory(unsigned char *va, uint32_t size, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0unsigned long pa) >> +{ >> + =A0 =A0uint32_t map_base; >> + =A0 =A0unsigned long map_addr; >> + =A0 =A0int i; >> + >> + =A0 =A0map_base =3D 0; >> + =A0 =A0for (i =3D 0; i < size; i++) { >> + =A0 =A0 =A0 =A0if ( map_base !=3D PFN_DOWN(pa + i) ) { >> + =A0 =A0 =A0 =A0 =A0 =A0map_base =3D PFN_DOWN(pa + i); >> + =A0 =A0 =A0 =A0 =A0 =A0set_fixmap(FIX_TBOOT_MAP_ADDRESS, map_base << PAGE_SHIFT); >> + =A0 =A0 =A0 =A0 =A0 =A0map_addr =3D (unsigned long)fix_to_virt(FIX_TBOOT_MAP_ADDRESS= ); >> + =A0 =A0 =A0 =A0} >> + =A0 =A0 =A0 =A0*(va + i) =3D *(unsigned char *)(map_addr + pa + i >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 - (map_base << PAGE_SHIFT)); >> + =A0 =A0} >> +} >> + >> =A0void __init tboot_probe(void) >> =A0{ >> =A0 =A0 tboot_shared_t *tboot_shared; >> =A0 =A0 unsigned long p_tboot_shared; >> - =A0 =A0uint32_t map_base, map_size; >> - =A0 =A0unsigned long map_addr; >>=20 >> =A0 =A0 /* Look for valid page-aligned address for shared page. */ >> =A0 =A0 p_tboot_shared =3D simple_strtoul(opt_tboot, NULL, 0); >> @@ -108,26 +125,17 @@ void __init tboot_probe(void) >> =A0 =A0 /* these will be needed by tboot_protect_mem_regions() and/or >> =A0 =A0 =A0 =A0tboot_parse_dmar_table(), so get them now */ >>=20 >> - =A0 =A0map_base =3D PFN_DOWN(TXT_PUB_CONFIG_REGS_BASE); >> - =A0 =A0map_size =3D PFN_UP(NR_TXT_CONFIG_PAGES * PAGE_SIZE); >> - =A0 =A0map_addr =3D (unsigned long)__va(map_base << PAGE_SHIFT); >> - =A0 =A0if ( map_pages_to_xen(map_addr, map_base, map_size, __PAGE_HYPERVIS= OR) ) >> - =A0 =A0 =A0 =A0return; >> - >> + =A0 =A0txt_heap_base =3D txt_heap_size =3D sinit_base =3D sinit_size =3D 0; >> =A0 =A0 /* TXT Heap */ >> - =A0 =A0txt_heap_base =3D >> - =A0 =A0 =A0 =A0*(uint64_t *)__va(TXT_PUB_CONFIG_REGS_BASE + TXTCR_HEAP_BASE); >> - =A0 =A0txt_heap_size =3D >> - =A0 =A0 =A0 =A0*(uint64_t *)__va(TXT_PUB_CONFIG_REGS_BASE + TXTCR_HEAP_SIZE); >> - >> + =A0 =A0tboot_copy_memory((unsigned char *)&txt_heap_base, >> sizeof(txt_heap_base), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TXT_PUB_CONFIG_REGS_BASE + TXTCR_HEAP_BASE); >> + =A0 =A0tboot_copy_memory((unsigned char *)&txt_heap_size, >> sizeof(txt_heap_size), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TXT_PUB_CONFIG_REGS_BASE + TXTCR_HEAP_SIZE); >> =A0 =A0 /* SINIT */ >> - =A0 =A0sinit_base =3D >> - =A0 =A0 =A0 =A0*(uint64_t *)__va(TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE); >> - =A0 =A0sinit_size =3D >> - =A0 =A0 =A0 =A0*(uint64_t *)__va(TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_SIZE); >> - >> - =A0 =A0destroy_xen_mappings((unsigned long)__va(map_base << PAGE_SHIFT), >> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (unsigned long)__va((map_base + map_size) << >> PAGE_SHIFT)); >> + =A0 =A0tboot_copy_memory((unsigned char *)&sinit_base, sizeof(sinit_base), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_BASE); >> + =A0 =A0tboot_copy_memory((unsigned char *)&sinit_size, sizeof(sinit_size), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0TXT_PUB_CONFIG_REGS_BASE + TXTCR_SINIT_SIZE); >> =A0} >>=20 >> =A0/* definitions from xen/drivers/passthrough/vtd/iommu.h >> @@ -380,11 +388,14 @@ int __init tboot_protect_mem_regions(voi >>=20 >> =A0int __init tboot_parse_dmar_table(acpi_table_handler dmar_handler) >> =A0{ >> - =A0 =A0uint32_t map_base, map_size; >> - =A0 =A0unsigned long map_vaddr; >> - =A0 =A0void *heap_ptr; >> =A0 =A0 struct acpi_table_header *dmar_table; >> =A0 =A0 int rc; >> + =A0 =A0uint64_t size; >> + =A0 =A0uint32_t dmar_table_length; >> + =A0 =A0unsigned long pa; >> + =A0 =A0sinit_mle_data_t sinit_mle_data; >> + =A0 =A0unsigned char *dmar_table_raw; >> + >>=20 >> =A0 =A0 if ( !tboot_in_measured_env() ) >> =A0 =A0 =A0 =A0 return acpi_table_parse(ACPI_SIG_DMAR, dmar_handler); >> @@ -396,32 +407,33 @@ int __init tboot_parse_dmar_table(acpi_t >> =A0 =A0 =A0 =A0 return 1; >>=20 >> =A0 =A0 /* map TXT heap into Xen addr space */ >> - =A0 =A0map_base =3D PFN_DOWN(txt_heap_base); >> - =A0 =A0map_size =3D PFN_UP(txt_heap_size); >> - =A0 =A0map_vaddr =3D (unsigned long)__va(map_base << PAGE_SHIFT); >> - =A0 =A0if ( map_pages_to_xen(map_vaddr, map_base, map_size, __PAGE_HYPERVI= SOR) >> ) >> - =A0 =A0 =A0 =A0return 1; >>=20 >> =A0 =A0 /* walk heap to SinitMleData */ >> - =A0 =A0heap_ptr =3D __va(txt_heap_base); >> + =A0 =A0pa =3D txt_heap_base; >> =A0 =A0 /* skip BiosData */ >> - =A0 =A0heap_ptr +=3D *(uint64_t *)heap_ptr; >> + =A0 =A0tboot_copy_memory((unsigned char *)&size, sizeof(size), pa); >> + =A0 =A0pa +=3D size; >> =A0 =A0 /* skip OsMleData */ >> - =A0 =A0heap_ptr +=3D *(uint64_t *)heap_ptr; >> + =A0 =A0tboot_copy_memory((unsigned char *)&size, sizeof(size), pa); >> + =A0 =A0pa +=3D size; >> =A0 =A0 /* skip OsSinitData */ >> - =A0 =A0heap_ptr +=3D *(uint64_t *)heap_ptr; >> + =A0 =A0tboot_copy_memory((unsigned char *)&size, sizeof(size), pa); >> + =A0 =A0pa +=3D size; >> =A0 =A0 /* now points to SinitMleDataSize; set to SinitMleData */ >> - =A0 =A0heap_ptr +=3D sizeof(uint64_t); >> + =A0 =A0pa +=3D sizeof(uint64_t); >> + =A0 =A0tboot_copy_memory((unsigned char *)&sinit_mle_data, >> sizeof(sinit_mle_data), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa); >> =A0 =A0 /* get addr of DMAR table */ >> - =A0 =A0dmar_table =3D (struct acpi_table_header *)(heap_ptr + >> - =A0 =A0 =A0 =A0 =A0 =A0((sinit_mle_data_t *)heap_ptr)->vtd_dmars_off - >> sizeof(uint64_t)); >> - >> + =A0 =A0pa +=3D sinit_mle_data.vtd_dmars_off - sizeof(uint64_t); >> + =A0 =A0tboot_copy_memory((unsigned char *)&dmar_table_length, >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0sizeof(dmar_table_length), >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pa + sizeof(char) * ACPI_NAME_SIZE); >> + =A0 =A0dmar_table_raw =3D xmalloc_array(unsigned char, dmar_table_length); >> + =A0 =A0tboot_copy_memory(dmar_table_raw, dmar_table_length, pa); >> + =A0 =A0dmar_table =3D (struct acpi_table_header *)dmar_table_raw; >> =A0 =A0 rc =3D dmar_handler(dmar_table); >> - >> - =A0 =A0destroy_xen_mappings( >> - =A0 =A0 =A0 =A0(unsigned long)__va(map_base << PAGE_SHIFT), >> - =A0 =A0 =A0 =A0(unsigned long)__va((map_base + map_size) << PAGE_SHIFT)); >> - >> + =A0 =A0xfree(dmar_table_raw); >> + >> =A0 =A0 /* acpi_parse_dmar() zaps APCI DMAR signature in TXT heap table */ >> =A0 =A0 /* but dom0 will read real table, so must zap it there too */ >> =A0 =A0 dmar_table =3D NULL; >> diff -r 1764b0cba2e9 -r efcb14260292 xen/include/asm-x86/fixmap.h >> --- a/xen/include/asm-x86/fixmap.h =A0 =A0 =A0Thu Oct 01 16:13:03 2009 +0100 >> +++ b/xen/include/asm-x86/fixmap.h =A0 =A0 =A0Thu Oct 01 16:14:10 2009 +0100 >> @@ -51,6 +51,7 @@ enum fixed_addresses { >> =A0 =A0 FIX_TBOOT_SHARED_BASE, >> =A0 =A0 FIX_MSIX_IO_RESERV_BASE, >> =A0 =A0 FIX_MSIX_IO_RESERV_END =3D FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGE= S -1, >> + =A0 =A0FIX_TBOOT_MAP_ADDRESS, >> =A0 =A0 __end_of_fixed_addresses >> =A0}; >>=20 >>=20 >> _______________________________________________ >> Xen-changelog mailing list >> Xen-changelog@lists.xensource.com >> http://lists.xensource.com/xen-changelog >>=20 >=20 > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel