From patchwork Thu Nov 6 14:13:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 40307 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 155A324237 for ; Thu, 6 Nov 2014 14:34:32 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id l18sf720730wgh.4 for ; Thu, 06 Nov 2014 06:34:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=M3xk8bzB4T4lsTpSnpQ9y3lEQIpfr3/g6bIFZTKWOr4=; b=aMhR6ywfYL9ghmNLiorpsKo2VgYNzZTXQk0AQ9fBGhpzAa8SzlYP+92p7VEq3uS9Rl ATgW9boJS0VEtCa6yopdICr3ZlYC4akEy7I8am62FAY+sgtzgvvELbM/6687HWXCyOAi fmoX5kePhCx9PVALXBfCC1LWya8Ze1YIZDKaH4oGtJNgAkFdmFwDkO/eJk70n3TUh9BF pSIbCDYR7WBI6JuKnkwOFIP21DxrnHxA90h9ycWubt7og9DVnsUn3565y+rrhKqi1XU+ 59uGDnBzK+C9Del0ckYDHchPoH2dXhJdfb0eGkCI3FYAnvv1n4M+5WDcLuv2nx/SHfKy 22KA== X-Gm-Message-State: ALoCoQmLWXSeSyq1MPrC0mhVAjX25vvFBSd1DooNx5f3A4Ii77RuhPg3cJIkXrDaBVvZaauQHfyK X-Received: by 10.112.180.71 with SMTP id dm7mr41138lbc.18.1415284471271; Thu, 06 Nov 2014 06:34:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.34 with SMTP id t2ls100428lal.2.gmail; Thu, 06 Nov 2014 06:34:30 -0800 (PST) X-Received: by 10.152.27.97 with SMTP id s1mr5314310lag.55.1415284470888; Thu, 06 Nov 2014 06:34:30 -0800 (PST) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id g9si11660147lam.64.2014.11.06.06.34.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 06:34:30 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by mail-lb0-f174.google.com with SMTP id z11so519906lbi.33 for ; Thu, 06 Nov 2014 06:34:30 -0800 (PST) X-Received: by 10.152.116.102 with SMTP id jv6mr5481079lab.40.1415284470719; Thu, 06 Nov 2014 06:34:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp52947lbc; Thu, 6 Nov 2014 06:34:29 -0800 (PST) X-Received: by 10.68.68.235 with SMTP id z11mr4772032pbt.102.1415284469068; Thu, 06 Nov 2014 06:34:29 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id qc5si5941628pac.236.2014.11.06.06.34.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Nov 2014 06:34:29 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XmO6w-0001eL-76; Thu, 06 Nov 2014 14:32:30 +0000 Received: from mail-wi0-f182.google.com ([209.85.212.182]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XmNx6-0006Hn-MD for linux-arm-kernel@lists.infradead.org; Thu, 06 Nov 2014 14:22:22 +0000 Received: by mail-wi0-f182.google.com with SMTP id d1so1632427wiv.9 for ; Thu, 06 Nov 2014 06:21:58 -0800 (PST) X-Received: by 10.180.98.170 with SMTP id ej10mr31685148wib.74.1415283251229; Thu, 06 Nov 2014 06:14:11 -0800 (PST) Received: from ards-macbook-pro.local (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id mw7sm8450413wib.14.2014.11.06.06.14.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 06:14:10 -0800 (PST) From: Ard Biesheuvel To: leif.lindholm@linaro.org, roy.franz@linaro.org, linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, msalter@redhat.com, dyoung@redhat.com, linux-efi@vger.kernel.org, matt.fleming@intel.com, will.deacon@arm.com, catalin.marinas@arm.com, grant.likely@linaro.org Subject: [PATCH v2 09/10] arm64/efi: ignore unusable regions instead of reserving them Date: Thu, 6 Nov 2014 15:13:25 +0100 Message-Id: <1415283206-14713-10-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415283206-14713-1-git-send-email-ard.biesheuvel@linaro.org> References: <1415283206-14713-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141106_062221_338516_B67E09B5 X-CRM114-Status: GOOD ( 17.03 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.182 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.182 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This changes the way memblocks are installed based on the contents of the UEFI memory map. Formerly, all regions would be memblock_add()'ed, after which unusable regions would be memblock_reserve()'d as well. To simplify things, but also to allow access to the unusable regions through mmap(/dev/mem), even with CONFIG_STRICT_DEVMEM set, change this so that only usable regions are memblock_add()'ed in the first place. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 69 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 3009c22e2620..af2214c692d3 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -40,13 +40,6 @@ static int __init uefi_debug_setup(char *str) } early_param("uefi_debug", uefi_debug_setup); -static int __init is_normal_ram(efi_memory_desc_t *md) -{ - if (md->attribute & EFI_MEMORY_WB) - return 1; - return 0; -} - static int __init uefi_init(void) { efi_char16_t *c16; @@ -105,28 +98,11 @@ out: return retval; } -/* - * Return true for RAM regions we want to permanently reserve. - */ -static __init int is_reserve_region(efi_memory_desc_t *md) -{ - switch (md->type) { - case EFI_LOADER_CODE: - case EFI_LOADER_DATA: - case EFI_BOOT_SERVICES_CODE: - case EFI_BOOT_SERVICES_DATA: - case EFI_CONVENTIONAL_MEMORY: - return 0; - default: - break; - } - return is_normal_ram(md); -} - -static __init void reserve_regions(void) +static __init void process_memory_map(void) { efi_memory_desc_t *md; u64 paddr, npages, size; + u32 lost = 0; if (uefi_debug) pr_info("Processing EFI memory map:\n"); @@ -134,31 +110,38 @@ static __init void reserve_regions(void) for_each_efi_memory_desc(&memmap, md) { paddr = md->phys_addr; npages = md->num_pages; + size = npages << EFI_PAGE_SHIFT; if (uefi_debug) { char buf[64]; - pr_info(" 0x%012llx-0x%012llx %s", - paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1, + pr_info(" 0x%012llx-0x%012llx %s\n", + paddr, paddr + size - 1, efi_md_typeattr_format(buf, sizeof(buf), md)); } - memrange_efi_to_native(&paddr, &npages); - size = npages << PAGE_SHIFT; - - if (is_normal_ram(md)) - early_init_dt_add_memory_arch(paddr, size); - - if (is_reserve_region(md)) { - memblock_reserve(paddr, size); - if (uefi_debug) - pr_cont("*"); - } - - if (uefi_debug) - pr_cont("\n"); + if (!efi_mem_is_usable_region(md)) + continue; + + early_init_dt_add_memory_arch(paddr, size); + + /* + * Keep a tally of how much memory we are losing due to + * rounding of regions that are not aligned to the page + * size. We cannot easily recover this memory without + * sorting the memory map and attempting to merge adjacent + * usable regions. + */ + if (PAGE_SHIFT != EFI_PAGE_SHIFT) + lost += (npages << EFI_PAGE_SHIFT) - + round_down(max_t(s64, size - PAGE_ALIGN(paddr) + + md->phys_addr, 0), + PAGE_SIZE); } + if (lost > SZ_1K) + pr_warn("efi: lost %u KB of RAM to rounding\n", lost / SZ_1K); + set_bit(EFI_MEMMAP, &efi.flags); } @@ -182,7 +165,7 @@ void __init efi_init(void) WARN_ON(uefi_init() < 0); - reserve_regions(); + process_memory_map(); } static int __init arm64_enter_virtual_mode(void)