From patchwork Fri Mar 17 15:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9630947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AA755602D6 for ; Fri, 17 Mar 2017 15:18:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE805286B4 for ; Fri, 17 Mar 2017 15:18:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A26B2286B6; Fri, 17 Mar 2017 15:18:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 26BF7286B4 for ; Fri, 17 Mar 2017 15:18:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cotbo-0006NE-Dw; Fri, 17 Mar 2017 15:16:04 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cotbn-0006Mx-0S for xen-devel@lists.xenproject.org; Fri, 17 Mar 2017 15:16:03 +0000 Received: from [85.158.137.68] by server-5.bemta-3.messagelabs.com id 47/C0-19998-2BDFBC85; Fri, 17 Mar 2017 15:16:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrEIsWRWlGSWpSXmKPExsXS6fjDS3fj39M RBlevi1h83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlNc3pZChY7VRz684y1gbHRpIuRk0NIIE/i 7q8DbCA2r4CdRN+DBmYQW0LAUOLp++tgcRYBVYlHUxYygdhsAuoSbc+2s3YxcnCICBhInDuaB GIyC+hLbFvHAlIhLOAtMWXxTyaI6UUSbY9mg9mcAvYSV7r3soCU8woISvzdIQwSZgZa+vLQdM YJjDyzEDKzkGQgbC2Jh79usUDY2hLLFr5mngW2V1pi+T8OiLCpxJHetcyYShwkDq6RWcDIsYp RvTi1qCy1SNdYL6koMz2jJDcxM0fX0MBYLze1uDgxPTUnMalYLzk/dxMjMEwZgGAHY/MXp0OM khxMSqK8L1acjhDiS8pPqcxILM6ILyrNSS0+xKjBwSGwbdfqC4xSLHn5ealKErxMX4HqBItS0 1Mr0jJzgJEEUyrBwaMkwnvnC1Cat7ggMbc4Mx0idYpRl2PO7N1vmITAZkiJ8zKCzBAAKcoozY MbAYvqS4yyUsK8jEAHCvEUpBblZpagyr9iFOdgVBLm7fwMNIUnM68EbtMroCOYgI54++EEyBE liQgpqQbGxSdmNZe9SFx38JDXtTK1gs6YyyHv1wSrcv1l8F2odKa1//Gbh/dP75QKOfl6Vf3k I69mdc7dqPgnemlOUmCd24QjPzLT3ctWiWoqljStyN3weEJpcJOJfsIm7vL7hrssF7+tafxye dbU2Toc5y+py5+Mai2MObBu8zHDQD1G16plul/qpJs3KLEUZyQaajEXFScCAOoxE67lAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1489763759!59940870!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17372 invoked from network); 17 Mar 2017 15:16:01 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-11.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Mar 2017 15:16:01 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 17 Mar 2017 09:15:58 -0600 Message-Id: <58CC0BBF0200007800144626@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Fri, 17 Mar 2017 09:15:59 -0600 From: "Jan Beulich" To: "xen-devel" References: <58CC06B002000078001445EA@prv-mh.provo.novell.com> <58CC06B002000078001445EA@prv-mh.provo.novell.com> In-Reply-To: <58CC06B002000078001445EA@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH 1/2] x86/EFI: avoid IOMMU faults on [_end, __2M_rwdata_end) X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Commit c9a4a1c419 ("x86/layout: Correct Xen's idea of its own memory layout") didn't go far enough with the conversion, causing IOMMU faults when memory from that range was handed to a domain. We must not make this memory available for allocation (the change is benign to xen.gz at this point in time). Note that the change to tboot_shutdown() is fixing another issue at once: As it looks, the function so far skipped all memory below the Xen image. Signed-off-by: Jan Beulich x86/EFI: avoid IOMMU faults on [_end,__2M_rwdata_end) Commit c9a4a1c419 ("x86/layout: Correct Xen's idea of its own memory layout") didn't go far enough with the conversion, causing IOMMU faults when memory from that range was handed to a domain. We must not make this memory available for allocation (the change is benign to xen.gz at this point in time). Note that the change to tboot_shutdown() is fixing another issue at once: As it looks, the function so far skipped all memory below the Xen image. Signed-off-by: Jan Beulich --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -922,7 +922,7 @@ void __init noreturn __start_xen(unsigne 1UL << (PAGE_SHIFT + 32)) ) e = min(HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START, 1UL << (PAGE_SHIFT + 32)); -#define reloc_size ((__pa(&_end) + mask) & ~mask) +#define reloc_size ((__pa(__2M_rwdata_end) + mask) & ~mask) /* Is the region suitable for relocating Xen? */ if ( !xen_phys_start && e <= limit ) { @@ -1119,7 +1119,9 @@ void __init noreturn __start_xen(unsigne if ( !xen_phys_start ) panic("Not enough memory to relocate Xen."); - reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end)); + + /* This needs to remain in sync with xen_in_range(). */ + reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end)); /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(&boot_e820); @@ -1689,6 +1691,14 @@ int __hwdom_init xen_in_range(unsigned l /* S3 resume code (and other real mode trampoline code) */ xen_regions[region_s3].s = bootsym_phys(trampoline_start); xen_regions[region_s3].e = bootsym_phys(trampoline_end); + + /* + * This needs to remain in sync with the uses of the same symbols in + * - __start_xen() (above) + * - is_xen_fixed_mfn() + * - tboot_shutdown() + */ + /* hypervisor .text + .rodata */ xen_regions[region_ro].s = __pa(&_stext); xen_regions[region_ro].e = __pa(&__2M_rodata_end); --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -280,7 +280,7 @@ static void tboot_gen_xenheap_integrity( if ( !mfn_valid(_mfn(mfn)) ) continue; - if ( (mfn << PAGE_SHIFT) < __pa(&_end) ) + if ( is_xen_fixed_mfn(mfn) ) continue; /* skip Xen */ if ( (mfn >= PFN_DOWN(g_tboot_shared->tboot_base - 3 * PAGE_SIZE)) && (mfn < PFN_UP(g_tboot_shared->tboot_base @@ -361,7 +361,8 @@ void tboot_shutdown(uint32_t shutdown_ty if ( shutdown_type == TB_SHUTDOWN_S3 ) { /* - * Xen regions for tboot to MAC + * Xen regions for tboot to MAC. This needs to remain in sync with + * xen_in_range(). */ g_tboot_shared->num_mac_regions = 3; /* S3 resume code (and other real mode trampoline code) */ --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -298,7 +298,7 @@ SECTIONS } ASSERT(__image_base__ > XEN_VIRT_START || - _end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE, + __2M_rwdata_end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE, "Xen image overlaps stubs area") #ifdef CONFIG_KEXEC --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -252,8 +252,8 @@ struct spage_info #define is_xen_heap_mfn(mfn) \ (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn))) #define is_xen_fixed_mfn(mfn) \ - ((((mfn) << PAGE_SHIFT) >= __pa(&_start)) && \ - (((mfn) << PAGE_SHIFT) <= __pa(&_end))) + ((((mfn) << PAGE_SHIFT) >= __pa(&_stext)) && \ + (((mfn) << PAGE_SHIFT) <= __pa(&__2M_rwdata_end))) #define PRtype_info "016lx"/* should only be used for printk's */ Reviewed-by: Andrew Cooper --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -922,7 +922,7 @@ void __init noreturn __start_xen(unsigne 1UL << (PAGE_SHIFT + 32)) ) e = min(HYPERVISOR_VIRT_END - DIRECTMAP_VIRT_START, 1UL << (PAGE_SHIFT + 32)); -#define reloc_size ((__pa(&_end) + mask) & ~mask) +#define reloc_size ((__pa(__2M_rwdata_end) + mask) & ~mask) /* Is the region suitable for relocating Xen? */ if ( !xen_phys_start && e <= limit ) { @@ -1119,7 +1119,9 @@ void __init noreturn __start_xen(unsigne if ( !xen_phys_start ) panic("Not enough memory to relocate Xen."); - reserve_e820_ram(&boot_e820, __pa(&_start), __pa(&_end)); + + /* This needs to remain in sync with xen_in_range(). */ + reserve_e820_ram(&boot_e820, __pa(_stext), __pa(__2M_rwdata_end)); /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(&boot_e820); @@ -1689,6 +1691,14 @@ int __hwdom_init xen_in_range(unsigned l /* S3 resume code (and other real mode trampoline code) */ xen_regions[region_s3].s = bootsym_phys(trampoline_start); xen_regions[region_s3].e = bootsym_phys(trampoline_end); + + /* + * This needs to remain in sync with the uses of the same symbols in + * - __start_xen() (above) + * - is_xen_fixed_mfn() + * - tboot_shutdown() + */ + /* hypervisor .text + .rodata */ xen_regions[region_ro].s = __pa(&_stext); xen_regions[region_ro].e = __pa(&__2M_rodata_end); --- a/xen/arch/x86/tboot.c +++ b/xen/arch/x86/tboot.c @@ -280,7 +280,7 @@ static void tboot_gen_xenheap_integrity( if ( !mfn_valid(_mfn(mfn)) ) continue; - if ( (mfn << PAGE_SHIFT) < __pa(&_end) ) + if ( is_xen_fixed_mfn(mfn) ) continue; /* skip Xen */ if ( (mfn >= PFN_DOWN(g_tboot_shared->tboot_base - 3 * PAGE_SIZE)) && (mfn < PFN_UP(g_tboot_shared->tboot_base @@ -361,7 +361,8 @@ void tboot_shutdown(uint32_t shutdown_ty if ( shutdown_type == TB_SHUTDOWN_S3 ) { /* - * Xen regions for tboot to MAC + * Xen regions for tboot to MAC. This needs to remain in sync with + * xen_in_range(). */ g_tboot_shared->num_mac_regions = 3; /* S3 resume code (and other real mode trampoline code) */ --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -298,7 +298,7 @@ SECTIONS } ASSERT(__image_base__ > XEN_VIRT_START || - _end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE, + __2M_rwdata_end <= XEN_VIRT_END - NR_CPUS * PAGE_SIZE, "Xen image overlaps stubs area") #ifdef CONFIG_KEXEC --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -252,8 +252,8 @@ struct spage_info #define is_xen_heap_mfn(mfn) \ (__mfn_valid(mfn) && is_xen_heap_page(__mfn_to_page(mfn))) #define is_xen_fixed_mfn(mfn) \ - ((((mfn) << PAGE_SHIFT) >= __pa(&_start)) && \ - (((mfn) << PAGE_SHIFT) <= __pa(&_end))) + ((((mfn) << PAGE_SHIFT) >= __pa(&_stext)) && \ + (((mfn) << PAGE_SHIFT) <= __pa(&__2M_rwdata_end))) #define PRtype_info "016lx"/* should only be used for printk's */