From patchwork Tue Feb 23 16:31:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8394251 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3A069F52D for ; Tue, 23 Feb 2016 16:34:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 16762202EC for ; Tue, 23 Feb 2016 16:34:04 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 17DF0202F8 for ; Tue, 23 Feb 2016 16:34:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYFsS-0002PB-VK; Tue, 23 Feb 2016 16:31:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aYFsQ-0002Ig-Tb for xen-devel@lists.xen.org; Tue, 23 Feb 2016 16:31:55 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id 4F/E8-02989-4798CC65; Tue, 23 Feb 2016 16:31:48 +0000 X-Env-Sender: prvs=8544ffb4f=Andrew.Cooper3@citrix.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1456245106!24454406!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39999 invoked from network); 23 Feb 2016 16:31:47 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 23 Feb 2016 16:31:47 -0000 X-IronPort-AV: E=Sophos;i="5.22,490,1449532800"; d="scan'208";a="340282608" From: Andrew Cooper To: Xen-devel Date: Tue, 23 Feb 2016 16:31:25 +0000 Message-ID: <1456245085-2302-9-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1456245085-2302-1-git-send-email-andrew.cooper3@citrix.com> References: <1456245085-2302-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v2 8/8] xen/x86: Unilaterally remove .init mappings X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because of the new 2M alignment of .init and .bss, the existing memory guarding infrastructure causes a shattered 2M superpage with non-present entries for .init, and present entries for the alignment space. Do away with the difference in behaviour between debug and non-debug builds; always destroy the .init mappings, and reuse the space for xenheap. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- xen/arch/x86/setup.c | 24 +++++++++++------------- xen/arch/x86/xen.lds.S | 3 +++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c index 806fa95..8431f06 100644 --- a/xen/arch/x86/setup.c +++ b/xen/arch/x86/setup.c @@ -176,16 +176,6 @@ void __init discard_initial_images(void) initial_images = NULL; } -static void free_xen_data(char *s, char *e) -{ -#ifndef MEMORY_GUARD - init_xenheap_pages(__pa(s), __pa(e)); -#endif - memguard_guard_range(s, e-s); - /* Also zap the mapping in the 1:1 area. */ - memguard_guard_range(__va(__pa(s)), e-s); -} - extern char __init_begin[], __init_end[], __bss_start[], __bss_end[]; static void __init init_idle_domain(void) @@ -509,13 +499,21 @@ static void __init kexec_reserve_area(struct e820map *e820) static void noinline init_done(void) { + void *va; + system_state = SYS_STATE_active; domain_unpause_by_systemcontroller(hardware_domain); - /* Free (or page-protect) the init areas. */ - memset(__init_begin, 0xcc, __init_end - __init_begin); /* int3 poison */ - free_xen_data(__init_begin, __init_end); + /* Zero the .init code and data. */ + for ( va = __init_begin; va < _p(__init_end); va += PAGE_SIZE ) + clear_page(va); + + /* Destroy Xen's mappings, and reuse the pages. */ + destroy_xen_mappings((unsigned long)&__2M_init_start, + (unsigned long)&__2M_init_end); + init_xenheap_pages(__pa(__2M_init_start), __pa(__2M_init_end)); + printk("Freed %ldkB init memory.\n", (long)(__init_end-__init_begin)>>10); startup_cpu_idle_loop(); diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index aadb082..f3908d1 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -257,3 +257,6 @@ ASSERT(IS_ALIGNED(__2M_rwdata_start, MB(2)), "__2M_rwdata_start misaligned") ASSERT(IS_ALIGNED(__2M_rwdata_end, MB(2)), "__2M_rwdata_end misaligned") ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned") + +ASSERT(IS_ALIGNED(__init_begin, PAGE_SIZE), "__init_begin misaligned") +ASSERT(IS_ALIGNED(__init_end, PAGE_SIZE), "__init_end misaligned")