From patchwork Tue Nov 18 12:57:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 41026 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D3EDA241C9 for ; Tue, 18 Nov 2014 13:03:08 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf2238772eek.1 for ; Tue, 18 Nov 2014 05:03:08 -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=+cPDJ6ZyEWvwI+3LbGYR1JKot2+iy1GWoAKFvfCnj4c=; b=j+ilTpZR28k96j48TSIvgYof3/IyGnPUMIFY+n0z+v7LtVBdvafa5L0FecickB5h67 UpEcpGbrfOfSMFI2fkZuPtyZeDSHJlUw/d07VTIU+cpntt+BOJb632sRgwW1AhvY5TQq Duw1ddBXwUSRBoT8fasaLWrLOr4/Z0qMnkrc+D55KzNrBFS40TrqwKWJiExzxRmLRVRD l08O9C598m0JoUihepe19ocGcBVyCWmLI+3EGoFOiuJ5S5z1wutGqhka9Ag78O2V2NKx 2SeSVIBc2osJUNHXhDWpvv7ejvd6Sm/S+R5DhkNG3h9+HnA5I6Lvx+Hxb3eQyxMCwXv3 dvSg== X-Gm-Message-State: ALoCoQnQzfX0nluo6HsUqKOWk002nM0luF8KRD1VdInebITrtAyYaE8edlh9+74KQure2JS28Eoq X-Received: by 10.194.178.163 with SMTP id cz3mr15230621wjc.1.1416315788104; Tue, 18 Nov 2014 05:03:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.134 with SMTP id s6ls1077323las.27.gmail; Tue, 18 Nov 2014 05:03:07 -0800 (PST) X-Received: by 10.152.2.41 with SMTP id 9mr35161810lar.47.1416315787851; Tue, 18 Nov 2014 05:03:07 -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 ay11si55473613lab.132.2014.11.18.05.03.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 05:03:07 -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 w7so9146027lbi.33 for ; Tue, 18 Nov 2014 05:03:07 -0800 (PST) X-Received: by 10.112.235.196 with SMTP id uo4mr35568151lbc.66.1416315787727; Tue, 18 Nov 2014 05:03:07 -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 ew9csp1323388lbc; Tue, 18 Nov 2014 05:03:06 -0800 (PST) X-Received: by 10.66.136.137 with SMTP id qa9mr10884921pab.129.1416315785266; Tue, 18 Nov 2014 05:03:05 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id kj8si37987936pdb.175.2014.11.18.05.03.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Nov 2014 05:03:05 -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 1XqiPH-0006Hx-U8; Tue, 18 Nov 2014 13:01:19 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqiM7-0002iC-LT for linux-arm-kernel@bombadil.infradead.org; Tue, 18 Nov 2014 12:58:03 +0000 Received: from mail-wg0-f42.google.com ([74.125.82.42]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqiM4-0001rV-DU for linux-arm-kernel@lists.infradead.org; Tue, 18 Nov 2014 12:58:01 +0000 Received: by mail-wg0-f42.google.com with SMTP id z12so9453037wgg.1 for ; Tue, 18 Nov 2014 04:57:35 -0800 (PST) X-Received: by 10.180.21.166 with SMTP id w6mr38923562wie.43.1416315455242; Tue, 18 Nov 2014 04:57:35 -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 cz3sm55726799wjb.23.2014.11.18.04.57.33 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 04:57:34 -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, geoff.levand@linaro.org Subject: [PATCH v3 11/13] arm64/efi: use plain memblock API for adding and removing reserved RAM Date: Tue, 18 Nov 2014 13:57:10 +0100 Message-Id: <1416315432-8534-12-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416315432-8534-1-git-send-email-ard.biesheuvel@linaro.org> References: <1416315432-8534-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141118_075800_590958_A607AE2E X-CRM114-Status: GOOD ( 14.70 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.42 listed in wl.mailspike.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.42 listed in list.dnswl.org] -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 The memblock API is agnostic of page size, so we can use it on both 4 KB and 64 KB granule kernels to install all UEFI memory regions (EFI_MEMORY_WB) using memblock_add(), and the memblock layer will stitch all unaligned regions together. Then we start punching holes in it for the reserved regions, this time taking the native page size into account. Finally, the reserved regions are memblock_remove()'d as well. This will ensure that the regions are accessible via mmap(/dev/mem), even when CONFIG_STRICT_DEVMEM is in effect. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 41 +++++++++-------------------------------- drivers/firmware/efi/virtmap.c | 15 +++++++++------ 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index 3009c22e2620..2c0a858f699e 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -105,24 +105,6 @@ 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) { efi_memory_desc_t *md; @@ -134,31 +116,26 @@ 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)) { + memblock_add(paddr, size); - 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 (!efi_mem_is_usable_region(md)) { + memrange_efi_to_native(&paddr, &npages); + memblock_reserve(paddr, npages << PAGE_SHIFT); + } } - if (uefi_debug) - pr_cont("\n"); } - set_bit(EFI_MEMMAP, &efi.flags); } diff --git a/drivers/firmware/efi/virtmap.c b/drivers/firmware/efi/virtmap.c index 98735fb43581..4b6a5c31629f 100644 --- a/drivers/firmware/efi/virtmap.c +++ b/drivers/firmware/efi/virtmap.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -97,8 +98,15 @@ void __init efi_virtmap_init(void) u64 paddr, npages, size; pgprot_t prot; - if (!efi_mem_is_usable_region(md)) + paddr = md->phys_addr; + npages = md->num_pages; + memrange_efi_to_native(&paddr, &npages); + size = npages << PAGE_SHIFT; + + if (!efi_mem_is_usable_region(md)) { efi_register_mem_resource(md); + memblock_remove(paddr, size); + } if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (WARN(md->virt_addr == 0, @@ -106,11 +114,6 @@ void __init efi_virtmap_init(void) md->phys_addr)) return; - paddr = md->phys_addr; - npages = md->num_pages; - memrange_efi_to_native(&paddr, &npages); - size = npages << PAGE_SHIFT; - pr_info(" EFI remap 0x%012llx => %p\n", md->phys_addr, (void *)md->virt_addr);