From patchwork Mon Sep 8 17:01:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Salter X-Patchwork-Id: 37012 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f198.google.com (mail-yk0-f198.google.com [209.85.160.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 646582054D for ; Mon, 8 Sep 2014 17:01:53 +0000 (UTC) Received: by mail-yk0-f198.google.com with SMTP id q9sf745388ykb.1 for ; Mon, 08 Sep 2014 10:01:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=W+4pODdJ25+cqnAcp/EYYT3l4WCMMjlfuctHElXBhno=; b=N7taK0rxXg7uRwdsX3RNuo1Vc7M4QLzuyp4Z11pkhCqL/7A7Yx3qk8TCazta8eonF9 XQQXsfW9QgHsvvnpULo9+ZUjjYshjHDPVX8QDdYoWHPCbvbtxmQYQcQ+eTcfkCx5yMDR xMdt4lrNgQC6LWMTtCqS6jlN1c2gjLv+D538d8sTzIDCUXTV/MpbBGGc3z9/R4bXPYMq MX9IGpVhh6fgc51qN6MfNzJ/lDrmmz/cDN0lDfsfCxxD3aXnJBRSn1/DxrobPEHWQ4Ad eT/+5LBzpnciOLcwSakkyXqmhrinJodffc5kUkOa9KDyYftMthcwGzyAAhBUQpTy1k9q 3Kqg== X-Gm-Message-State: ALoCoQmXRNeVZGqyqyXwpTrbsXNQZPtNiqwwbnGfNA2JXLCl3GLA3yuPQDDharXYgUw8Gk+Bw4yP X-Received: by 10.236.31.68 with SMTP id l44mr17999211yha.29.1410195713173; Mon, 08 Sep 2014 10:01:53 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.210 with SMTP id l76ls337713qgd.19.gmail; Mon, 08 Sep 2014 10:01:52 -0700 (PDT) X-Received: by 10.220.88.19 with SMTP id y19mr903389vcl.70.1410195712952; Mon, 08 Sep 2014 10:01:52 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id r2si4708933vda.106.2014.09.08.10.01.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Sep 2014 10:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id hq11so16007416vcb.28 for ; Mon, 08 Sep 2014 10:01:52 -0700 (PDT) X-Received: by 10.52.38.134 with SMTP id g6mr9168567vdk.34.1410195712845; Mon, 08 Sep 2014 10:01:52 -0700 (PDT) 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.221.45.67 with SMTP id uj3csp163779vcb; Mon, 8 Sep 2014 10:01:52 -0700 (PDT) X-Received: by 10.70.59.104 with SMTP id y8mr49625126pdq.1.1410195711845; Mon, 08 Sep 2014 10:01:51 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fe1si18728740pbb.201.2014.09.08.10.01.51 for ; Mon, 08 Sep 2014 10:01:51 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754783AbaIHRBt (ORCPT + 26 others); Mon, 8 Sep 2014 13:01:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26353 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754227AbaIHRBr (ORCPT ); Mon, 8 Sep 2014 13:01:47 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s88H1GFk032316 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 8 Sep 2014 13:01:17 -0400 Received: from deneb.redhat.com (ovpn-113-116.phx2.redhat.com [10.3.113.116]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s88H1FTk007341; Mon, 8 Sep 2014 13:01:16 -0400 From: Mark Salter To: Leif Lindholm Cc: Ard Biesheuvel , matt.fleming@intel.com, Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, LKML , Mark Salter Subject: [PATCH v2] efi/arm64: fix fdt-related memory reservation Date: Mon, 8 Sep 2014 13:01:08 -0400 Message-Id: <1410195668-9975-1-git-send-email-msalter@redhat.com> In-Reply-To: <1410183102-6969-1-git-send-email-msalter@redhat.com> References: <1410183102-6969-1-git-send-email-msalter@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: msalter@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Commit 86c8b27a01cf: "arm64: ignore DT memreserve entries when booting in UEFI mode prevents early_init_fdt_scan_reserved_mem() from being called for arm64 kernels booting via UEFI. This was done because the kernel will use the UEFI memory map to determine reserved memory regions. That approach has problems in that early_init_fdt_scan_reserved_mem() also reserves the FDT itself and any node-specific reserved memory. By chance of some kernel configs, the FDT may be overwritten before it can be unflattened and the kernel will fail to boot. More subtle problems will result if the FDT has node specific reserved memory which is not really reserved. This patch has the UEFI stub remove the memory reserve map entries from the FDT as it does with the memory nodes. This allows early_init_fdt_scan_reserved_mem() to be called unconditionally so that the other needed reservations are made. Change from v1: * Acks added * Fixed loop logic to remove reserved regions Signed-off-by: Mark Salter Acked-by: Ard Biesheuvel Acked-by: Mark Rutland --- arch/arm64/mm/init.c | 3 +-- drivers/firmware/efi/libstub/fdt.c | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 5472c24..a83061f 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -149,8 +149,7 @@ void __init arm64_memblock_init(void) memblock_reserve(__virt_to_phys(initrd_start), initrd_end - initrd_start); #endif - if (!efi_enabled(EFI_MEMMAP)) - early_init_fdt_scan_reserved_mem(); + early_init_fdt_scan_reserved_mem(); /* 4GB maximum for 32-bit only capable devices */ if (IS_ENABLED(CONFIG_ZONE_DMA)) diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index a56bb35..c846a96 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -22,7 +22,7 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, unsigned long map_size, unsigned long desc_size, u32 desc_ver) { - int node, prev; + int node, prev, num_rsv; int status; u32 fdt_val32; u64 fdt_val64; @@ -73,6 +73,14 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, prev = node; } + /* + * Delete all memory reserve map entries. When booting via UEFI, + * kernel will use the UEFI memory map to find reserved regions. + */ + num_rsv = fdt_num_mem_rsv(fdt); + while (num_rsv-- > 0) + fdt_del_mem_rsv(fdt, num_rsv); + node = fdt_subnode_offset(fdt, 0, "chosen"); if (node < 0) { node = fdt_add_subnode(fdt, 0, "chosen");