From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD336C43461 for ; Mon, 14 Sep 2020 15:16:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8703820639 for ; Mon, 14 Sep 2020 15:16:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Zpzzic62" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8703820639 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kHqDM-0000bP-ML; Mon, 14 Sep 2020 15:16:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kHqDK-0000bB-Sv for xen-devel@lists.xenproject.org; Mon, 14 Sep 2020 15:16:18 +0000 X-Inumbo-ID: 017601da-3d09-4390-98c4-86634e7f6059 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 017601da-3d09-4390-98c4-86634e7f6059; Mon, 14 Sep 2020 15:16:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1600096577; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=46AEE+gSjE8aQ+JZhvptpm7AsVF1Q57dJvSqXqTMRAM=; b=Zpzzic62tlwqearZLXEk6aed+8IdHykx+fDQ0cklkvrLWHOr/FhUCg3r L+6p6Jf1pML1f5VWu8BorA8NgTaT8uRVogLmhVvRGPunkrxv5icYdAfrg CLR6x3REfSZNt9IQuui3hyqk6QZnx6g7ExjjKVpMHCtp5RFVDyQ0Zl73C U=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: pk0+p55F6pTM9aWwqMdrUi+sPeYrjeNB/A8536ATsf3+o/CEDaxGfCDs3bzr7P9NQLDNIisfPY XpxCBpACDhzYtwucoI5QhFCz/nlaPVhAfg3sore4ok9IbkgLOa1MlBDJAM7NzYyKTMiFwEy2Pc Vi3yEf/wJ0kqVKH4lcFcoNzY2vqbgwBzUsqvUFzwj5VTqkS9RYMIoyR7u4Ukry6ss4tE8l+C9O ICfr3hYVmHVNBqda2p82iCVB2RYrsUra8AhHZ/3QybhtittYA7QlZUulxTem8e4py3OYjkQXDL 2kI= X-SBRS: 2.7 X-MesageID: 26763887 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.76,426,1592884800"; d="scan'208";a="26763887" Date: Mon, 14 Sep 2020 17:16:08 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: Jan Beulich CC: "xen-devel@lists.xenproject.org" , "Andrew Cooper" , George Dunlap , Ian Jackson , "Julien Grall" , Wei Liu , Stefano Stabellini , Lukasz Hawrylko Subject: Re: [PATCH v2 2/2] EFI: free unused boot mem in at least some cases Message-ID: <20200914151608.GF753@Air-de-Roger> References: <5dd2fcea-d8ec-1c20-6514-c7733b59047f@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: AMSPEX02CAS02.citrite.net (10.69.22.113) To FTLPEX02CL06.citrite.net (10.13.108.179) X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Mon, Aug 24, 2020 at 02:08:11PM +0200, Jan Beulich wrote: > Address at least the primary reason why 52bba67f8b87 ("efi/boot: Don't > free ebmalloc area at all") was put in place: Make xen_in_range() aware > of the freed range. This is in particular relevant for EFI-enabled > builds not actually running on EFI, as the entire range will be unused > in this case. > > Signed-off-by: Jan Beulich Acked-by: Roger Pau Monné Just one comment below. > --- > v2: Also adjust the two places where comments point out that they need > to remain in sync with xen_in_range(). Add assertions to > xen_in_range(). > --- > The remaining issue could be addressed too, by making the area 2M in > size and 2M-aligned. > > --- a/xen/arch/x86/efi/stub.c > +++ b/xen/arch/x86/efi/stub.c > @@ -52,6 +52,12 @@ bool efi_enabled(unsigned int feature) > > void __init efi_init_memory(void) { } > > +bool efi_boot_mem_unused(unsigned long *start, unsigned long *end) > +{ > + *start = *end = (unsigned long)_end; > + return false; > +} > + > void efi_update_l4_pgtable(unsigned int l4idx, l4_pgentry_t l4e) { } > > bool efi_rs_using_pgtables(void) > --- a/xen/arch/x86/setup.c > +++ b/xen/arch/x86/setup.c > @@ -608,7 +608,7 @@ static void __init kexec_reserve_area(st > #endif > } > > -static inline bool using_2M_mapping(void) > +bool using_2M_mapping(void) > { > return !l1_table_offset((unsigned long)__2M_text_end) && > !l1_table_offset((unsigned long)__2M_rodata_start) && > @@ -830,6 +830,7 @@ void __init noreturn __start_xen(unsigne > module_t *mod; > unsigned long nr_pages, raw_max_page, modules_headroom, module_map[1]; > int i, j, e820_warn = 0, bytes = 0; > + unsigned long eb_start, eb_end; > bool acpi_boot_table_init_done = false, relocated = false; > int ret; > struct ns16550_defaults ns16550 = { > @@ -1145,7 +1146,8 @@ void __init noreturn __start_xen(unsigne > > /* > * This needs to remain in sync with xen_in_range() and the > - * respective reserve_e820_ram() invocation below. > + * respective reserve_e820_ram() invocation below. No need to > + * query efi_boot_mem_unused() here, though. > */ > mod[mbi->mods_count].mod_start = virt_to_mfn(_stext); > mod[mbi->mods_count].mod_end = __2M_rwdata_end - _stext; I find this extremely confusing, we reuse mod_start/mod_end to contain a mfn and a size (in bytes) instead of a start and end address (not something that should be fixed here, but seeing this I assumed it was wrong). > +bool efi_boot_mem_unused(unsigned long *start, unsigned long *end) > +{ > + *start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated); > + *end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem); > + > + return *start < *end; > +} > + > void __init free_ebmalloc_unused_mem(void) > { > -#if 0 /* FIXME: Putting a hole in the BSS breaks the IOMMU mappings for dom0. */ > unsigned long start, end; > > - start = (unsigned long)ebmalloc_mem + PAGE_ALIGN(ebmalloc_allocated); > - end = (unsigned long)ebmalloc_mem + sizeof(ebmalloc_mem); > +#ifdef CONFIG_X86 > + /* FIXME: Putting a hole in .bss would shatter the large page mapping. */ Could you make the ebmalloc size (EBMALLOC_SIZE) 2MB (and aligned), so that you would only shatter the malloc'ed pages but not the surrounding mappings? That would be a good compromise IMO. Roger.