From patchwork Thu Aug 6 09:04:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11703051 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E5D3138C for ; Thu, 6 Aug 2020 12:01:30 +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 46B0222D07 for ; Thu, 6 Aug 2020 12:01:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 46B0222D07 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1k3bpN-00087P-2J; Thu, 06 Aug 2020 09:04:45 +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 1k3bpL-00087H-PO for xen-devel@lists.xenproject.org; Thu, 06 Aug 2020 09:04:43 +0000 X-Inumbo-ID: e331891c-c29d-4291-932e-303f8e4e7829 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id e331891c-c29d-4291-932e-303f8e4e7829; Thu, 06 Aug 2020 09:04:42 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 577F1AD88; Thu, 6 Aug 2020 09:04:59 +0000 (UTC) Subject: [PATCH 1/4] build: work around bash issue From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Message-ID: Date: Thu, 6 Aug 2020 11:04:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Content-Language: en-US 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: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , George Dunlap , Andrew Cooper , Anthony Perard , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Older bash fails to honor "set -e" for certain built-in commands ("while" here), despite the command's status correctly bein non-zero. The subsequent objcopy invocation now being separated by a semicolon results in no failure. Insert an explicit "exit" (replacing ; by && ought to be another possible workaround). Fixes: e321576f4047 ("xen/build: start using if_changed") Signed-off-by: Jan Beulich --- I've done a pretty light-weight audit of possible further instances of this issue, but didn't find any. --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -193,7 +193,7 @@ define cmd_obj_init_o echo "Error: size of $<:$$name is 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ esac; \ - done; \ + done || exit $$?; \ $(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@ endef From patchwork Thu Aug 6 09:05:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11703045 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78FCB138C for ; Thu, 6 Aug 2020 12:01:21 +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 5CE6522D05 for ; Thu, 6 Aug 2020 12:01:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5CE6522D05 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1k3bpt-0008BA-Ba; Thu, 06 Aug 2020 09:05:17 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1k3bps-0008B2-9j for xen-devel@lists.xenproject.org; Thu, 06 Aug 2020 09:05:16 +0000 X-Inumbo-ID: 30b871ee-f5b2-49bf-980a-550ffac0fff5 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 30b871ee-f5b2-49bf-980a-550ffac0fff5; Thu, 06 Aug 2020 09:05:15 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 12D80AC50; Thu, 6 Aug 2020 09:05:32 +0000 (UTC) Subject: [PATCH 2/4] build: correctly report non-empty section sizes upon .o -> .init.o conversion From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Message-ID: <5fcb47ec-4a0e-99a2-c548-f42ec1cc8030@suse.com> Date: Thu, 6 Aug 2020 11:05:17 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Content-Language: en-US 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: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The originally used sed expression converted not just multiple leading zeroes (as intended), but also trailing ones, rendering the error message somewhat confusing. Collapse zeroes in just the one place where we need them collapsed, and leave objdump's output as is for all other purposes. Fixes: 48115d14743e ("Move more kernel decompression bits to .init.* sections") Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -185,11 +185,11 @@ cmd_cc_o_S = $(CC) $(a_flags) -c $< -o $ quiet_cmd_obj_init_o = INIT_O $@ define cmd_obj_init_o - $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | while read idx name sz rest; do \ + $(OBJDUMP) -h $< | while read idx name sz rest; do \ case "$$name" in \ .*.local) ;; \ .text|.text.*|.data|.data.*|.bss) \ - test $$sz != 0 || continue; \ + test $$(echo $$sz | sed 's,00*,0,') != 0 || continue; \ echo "Error: size of $<:$$name is 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ esac; \ From patchwork Thu Aug 6 09:05:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11703047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ACA8814B7 for ; Thu, 6 Aug 2020 12:01:23 +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 9287522D02 for ; Thu, 6 Aug 2020 12:01:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9287522D02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1k3bqM-0008Ea-Kf; Thu, 06 Aug 2020 09:05:46 +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 1k3bqL-0008EN-Fy for xen-devel@lists.xenproject.org; Thu, 06 Aug 2020 09:05:45 +0000 X-Inumbo-ID: 6749b8c9-f48b-4ee7-bec9-6f9092d053bc Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6749b8c9-f48b-4ee7-bec9-6f9092d053bc; Thu, 06 Aug 2020 09:05:44 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 424D0AD63; Thu, 6 Aug 2020 09:06:01 +0000 (UTC) Subject: [PATCH 3/4] build: also check for empty .bss.* in .o -> .init.o conversion From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Message-ID: Date: Thu, 6 Aug 2020 11:05:46 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Content-Language: en-US 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: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" We're gaining such sections, and like .text.* and .data.* they shouldn't be present in objects subject to automatic to-init conversion. Oddly enough for quite some time we did have an instance breaking this rule, which gets fixed at this occasion, by breaking out the EFI boot allocator functions into its own translation unit. Fixes: c5b9805bc1f7 ("efi: create new early memory allocator") Signed-off-by: Jan Beulich Acked-by: Andrew Cooper Acked-by: Julien Grall --- This likely has a (weak) dependency on "x86/EFI: sanitize build logic" sent several weeks ago, due to the new source file added, as explicit dependencies upon the individual objects in x86/Makefile go away there. --- a/xen/Makefile +++ b/xen/Makefile @@ -355,7 +355,7 @@ $(TARGET): delete-unfresh-files $(MAKE) -C tools $(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h [ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm - [ -e arch/$(TARGET_ARCH)/efi ] && for f in boot.c runtime.c compat.c efi.h;\ + [ -e arch/$(TARGET_ARCH)/efi ] && for f in $$(cd common/efi; echo *.[ch]); \ do test -r arch/$(TARGET_ARCH)/efi/$$f || \ ln -nsf ../../../common/efi/$$f arch/$(TARGET_ARCH)/efi/; \ done; \ --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -188,7 +188,7 @@ define cmd_obj_init_o $(OBJDUMP) -h $< | while read idx name sz rest; do \ case "$$name" in \ .*.local) ;; \ - .text|.text.*|.data|.data.*|.bss) \ + .text|.text.*|.data|.data.*|.bss|.bss.*) \ test $$(echo $$sz | sed 's,00*,0,') != 0 || continue; \ echo "Error: size of $<:$$name is 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ --- a/xen/arch/arm/efi/Makefile +++ b/xen/arch/arm/efi/Makefile @@ -1,4 +1,4 @@ CFLAGS-y += -fshort-wchar -obj-y += boot.init.o runtime.o +obj-y += boot.init.o ebmalloc.o runtime.o obj-$(CONFIG_ACPI) += efi-dom0.init.o --- a/xen/arch/x86/efi/Makefile +++ b/xen/arch/x86/efi/Makefile @@ -8,7 +8,7 @@ cmd_objcopy_o_ihex = $(OBJCOPY) -I ihex boot.init.o: buildid.o -EFIOBJ := boot.init.o compat.o runtime.o +EFIOBJ := boot.init.o ebmalloc.o compat.o runtime.o $(call cc-option-add,cflags-stack-boundary,CC,-mpreferred-stack-boundary=4) $(EFIOBJ): CFLAGS-stack-boundary := $(cflags-stack-boundary) --- a/xen/common/efi/boot.c +++ b/xen/common/efi/boot.c @@ -112,7 +112,6 @@ static CHAR16 *FormatDec(UINT64 Val, CHA static CHAR16 *FormatHex(UINT64 Val, UINTN Width, CHAR16 *Buffer); static void DisplayUint(UINT64 Val, INTN Width); static CHAR16 *wstrcpy(CHAR16 *d, const CHAR16 *s); -static void noreturn blexit(const CHAR16 *str); static void PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode); static char *get_value(const struct file *cfg, const char *section, const char *item); @@ -155,56 +154,6 @@ static CHAR16 __initdata newline[] = L"\ #define PrintStr(s) StdOut->OutputString(StdOut, s) #define PrintErr(s) StdErr->OutputString(StdErr, s) -#ifdef CONFIG_ARM -/* - * TODO: Enable EFI boot allocator on ARM. - * This code can be common for x86 and ARM. - * Things TODO on ARM before enabling ebmalloc: - * - estimate required EBMALLOC_SIZE value, - * - where (in which section) ebmalloc_mem[] should live; if in - * .bss.page_aligned, as it is right now, then whole BSS zeroing - * have to be disabled in xen/arch/arm/arm64/head.S; though BSS - * should be initialized somehow before use of variables living there, - * - use ebmalloc() in ARM/common EFI boot code, - * - call free_ebmalloc_unused_mem() somewhere in init code. - */ -#define EBMALLOC_SIZE MB(0) -#else -#define EBMALLOC_SIZE MB(1) -#endif - -static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) - ebmalloc_mem[EBMALLOC_SIZE]; -static unsigned long __initdata ebmalloc_allocated; - -/* EFI boot allocator. */ -static void __init __maybe_unused *ebmalloc(size_t size) -{ - void *ptr = ebmalloc_mem + ebmalloc_allocated; - - ebmalloc_allocated += ROUNDUP(size, sizeof(void *)); - - if ( ebmalloc_allocated > sizeof(ebmalloc_mem) ) - blexit(L"Out of static memory\r\n"); - - return ptr; -} - -static void __init __maybe_unused 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); - - destroy_xen_mappings(start, end); - init_xenheap_pages(__pa(start), __pa(end)); - - printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10); -#endif -} - /* * Include architecture specific implementation here, which references the * static globals defined above. @@ -321,7 +270,7 @@ static bool __init match_guid(const EFI_ !memcmp(guid1->Data4, guid2->Data4, sizeof(guid1->Data4)); } -static void __init noreturn blexit(const CHAR16 *str) +void __init noreturn blexit(const CHAR16 *str) { if ( str ) PrintStr((CHAR16 *)str); --- /dev/null +++ b/xen/common/efi/ebmalloc.c @@ -0,0 +1,52 @@ +#include "efi.h" +#include + +#ifdef CONFIG_ARM +/* + * TODO: Enable EFI boot allocator on ARM. + * This code can be common for x86 and ARM. + * Things TODO on ARM before enabling ebmalloc: + * - estimate required EBMALLOC_SIZE value, + * - where (in which section) ebmalloc_mem[] should live; if in + * .bss.page_aligned, as it is right now, then whole BSS zeroing + * have to be disabled in xen/arch/arm/arm64/head.S; though BSS + * should be initialized somehow before use of variables living there, + * - use ebmalloc() in ARM/common EFI boot code, + * - call free_ebmalloc_unused_mem() somewhere in init code. + */ +#define EBMALLOC_SIZE MB(0) +#else +#define EBMALLOC_SIZE MB(1) +#endif + +static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) + ebmalloc_mem[EBMALLOC_SIZE]; +static unsigned long __initdata ebmalloc_allocated; + +/* EFI boot allocator. */ +void __init *ebmalloc(size_t size) +{ + void *ptr = ebmalloc_mem + ebmalloc_allocated; + + ebmalloc_allocated += ROUNDUP(size, sizeof(void *)); + + if ( ebmalloc_allocated > sizeof(ebmalloc_mem) ) + blexit(L"Out of static memory\r\n"); + + return ptr; +} + +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); + + destroy_xen_mappings(start, end); + init_xenheap_pages(__pa(start), __pa(end)); + + printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10); +#endif +} --- a/xen/common/efi/efi.h +++ b/xen/common/efi/efi.h @@ -40,4 +40,10 @@ extern UINT64 efi_boot_max_var_store_siz extern UINT64 efi_apple_properties_addr; extern UINTN efi_apple_properties_len; +void noreturn blexit(const CHAR16 *str); + const CHAR16 *wmemchr(const CHAR16 *s, CHAR16 c, UINTN n); + +/* EFI boot allocator. */ +void *ebmalloc(size_t size); +void free_ebmalloc_unused_mem(void); From patchwork Thu Aug 6 09:06:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11703053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18739138C for ; Thu, 6 Aug 2020 12:01:33 +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 F38BF22D05 for ; Thu, 6 Aug 2020 12:01:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F38BF22D05 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.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 1k3bqj-0008J7-Up; Thu, 06 Aug 2020 09:06:09 +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 1k3bqi-0008I9-B3 for xen-devel@lists.xenproject.org; Thu, 06 Aug 2020 09:06:08 +0000 X-Inumbo-ID: 75dab13f-ff1d-496c-afa3-bab25eb6db47 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 75dab13f-ff1d-496c-afa3-bab25eb6db47; Thu, 06 Aug 2020 09:06:07 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 276C7B1AA; Thu, 6 Aug 2020 09:06:24 +0000 (UTC) Subject: [PATCH 4/4] EFI: free unused boot mem in at least some cases From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Message-ID: <4e2d0d0a-9d85-d704-5d61-ae9efc69256a@suse.com> Date: Thu, 6 Aug 2020 11:06:09 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <305c2532-408a-9f78-61fe-c90a2e86eb8e@suse.com> Content-Language: en-US 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: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , George Dunlap , Andrew Cooper , Ian Jackson , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 --- 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 __hwdom_init 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) && @@ -1970,7 +1970,7 @@ int __hwdom_init xen_in_range(unsigned l paddr_t start, end; int i; - enum { region_s3, region_ro, region_rw, nr_regions }; + enum { region_s3, region_ro, region_rw, region_bss, nr_regions }; static struct { paddr_t s, e; } xen_regions[nr_regions] __hwdom_initdata; @@ -1994,7 +1994,14 @@ int __hwdom_init xen_in_range(unsigned l xen_regions[region_ro].e = __pa(&__2M_rodata_end); /* hypervisor .data + .bss */ xen_regions[region_rw].s = __pa(&__2M_rwdata_start); - xen_regions[region_rw].e = __pa(&__2M_rwdata_end); + if ( efi_boot_mem_unused(&start, &end) ) + { + xen_regions[region_rw].e = __pa(start); + xen_regions[region_bss].s = __pa(end); + xen_regions[region_bss].e = __pa(&__2M_rwdata_end); + } + else + xen_regions[region_rw].e = __pa(&__2M_rwdata_end); } start = (paddr_t)mfn << PAGE_SHIFT; --- a/xen/common/efi/ebmalloc.c +++ b/xen/common/efi/ebmalloc.c @@ -1,5 +1,9 @@ #include "efi.h" #include +#include +#ifdef CONFIG_X86 +#include +#endif #ifdef CONFIG_ARM /* @@ -21,7 +25,7 @@ static char __section(".bss.page_aligned") __aligned(PAGE_SIZE) ebmalloc_mem[EBMALLOC_SIZE]; -static unsigned long __initdata ebmalloc_allocated; +static unsigned long __read_mostly ebmalloc_allocated; /* EFI boot allocator. */ void __init *ebmalloc(size_t size) @@ -36,17 +40,32 @@ void __init *ebmalloc(size_t size) return ptr; } +bool __hwdom_init 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. */ + if ( using_2M_mapping() ) + { + ebmalloc_allocated = sizeof(ebmalloc_mem); + return; + } +#endif + + if ( !efi_boot_mem_unused(&start, &end) ) + return; destroy_xen_mappings(start, end); init_xenheap_pages(__pa(start), __pa(end)); printk(XENLOG_INFO "Freed %lukB unused BSS memory\n", (end - start) >> 10); -#endif } --- a/xen/include/asm-x86/setup.h +++ b/xen/include/asm-x86/setup.h @@ -9,6 +9,8 @@ extern const char __2M_rodata_start[], _ extern char __2M_init_start[], __2M_init_end[]; extern char __2M_rwdata_start[], __2M_rwdata_end[]; +bool using_2M_mapping(void); + extern unsigned long xenheap_initial_phys_start; extern uint64_t boot_tsc_stamp; --- a/xen/include/xen/efi.h +++ b/xen/include/xen/efi.h @@ -33,6 +33,7 @@ struct compat_pf_efi_runtime_call; bool efi_enabled(unsigned int feature); void efi_init_memory(void); +bool efi_boot_mem_unused(unsigned long *start, unsigned long *end); bool efi_rs_using_pgtables(void); unsigned long efi_get_time(void); void efi_halt_system(void);