From patchwork Tue Mar 28 06:53:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 96110 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1570389qgd; Mon, 27 Mar 2017 23:51:15 -0700 (PDT) X-Received: by 10.84.210.167 with SMTP id a36mr34063719pli.40.1490683875542; Mon, 27 Mar 2017 23:51:15 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si3242318plb.136.2017.03.27.23.51.15; Mon, 27 Mar 2017 23:51:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754550AbdC1Gur (ORCPT + 2 others); Tue, 28 Mar 2017 02:50:47 -0400 Received: from mail-pg0-f49.google.com ([74.125.83.49]:33665 "EHLO mail-pg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754450AbdC1Guq (ORCPT ); Tue, 28 Mar 2017 02:50:46 -0400 Received: by mail-pg0-f49.google.com with SMTP id n5so55926361pgh.0 for ; Mon, 27 Mar 2017 23:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jqaCl5Aa3BHdM/EvoNSWXE7yCVErZLy2r54ci6I3RQw=; b=aUEa6kjevpvhAvnNeQ3wpdkHd/bMOktC0yqWrv/7KP2DxX12/4jUUu23rq1k5GMtNW x7QByEdU6hc5y0s80M8xRRcvTAyXl0q0C1TZ4kMVq79qH0UZASrPLi0zEzG6PzoKVKkc HXS79SyZG3Y8wNRAytT8qED3ATide17KHI0ro= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jqaCl5Aa3BHdM/EvoNSWXE7yCVErZLy2r54ci6I3RQw=; b=Bbx8jKEj9bXIp0N0Jh8jiFg945ysALrBHGu3GXAMH8xOmcKwsI2pHQp+z3O6KUvjoP RdGd+2r5uz/OF2y5B5lt/6QszDhRYjnrZru5HWBPWCf6SnAMj3FeUH/hTvA7fCLF3kIP EkSbVYHicZJ16IaFvR6Y1jYAQMpdjKMyyHkJ/ugIc8Qj5S9hoUxXySJJfgH0axIFE7U0 BJ8J2dMA6f9AVtM7/Gdm82KeCLruA5+4Ok9Q14CDgYzlXLu4YGH3+LEvGCsjaMrL0Qw+ CLCV0YkldD+Xw1xl32F/l0OdzAwZ7YqjsCC4ZI9f46R9jdBxlQeLpsS0QHGaJhGtEwgE eMvw== X-Gm-Message-State: AFeK/H1gXC8YAtETwLmUnN0UaTvZMD82X5CbUEhbdhO5w1skTkmfwSKdMTDq8p2k2eG7Q43a X-Received: by 10.84.225.18 with SMTP id t18mr20568978plj.14.1490683825944; Mon, 27 Mar 2017 23:50:25 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id y5sm4925233pgh.36.2017.03.27.23.50.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 23:50:25 -0700 (PDT) From: AKASHI Takahiro To: catalin.marinas@arm.com, will.deacon@arm.com Cc: james.morse@arm.com, geoff@infradead.org, bauerman@linux.vnet.ibm.com, dyoung@redhat.com, mark.rutland@arm.com, sgoel@codeaurora.org, jhugo@codeaurora.org, ard.biesheuvel@linaro.org, panand@redhat.com, dwmw2@infradead.org, linux-efi@vger.kernel.org, kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v34 14/14] efi/libstub/arm*: Set default address and size cells values for an empty dtb Date: Tue, 28 Mar 2017 15:53:19 +0900 Message-Id: <20170328065319.16154-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170328064831.15894-1-takahiro.akashi@linaro.org> References: <20170328064831.15894-1-takahiro.akashi@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org From: Sameer Goel In cases where a device tree is not provided (ie ACPI based system), an empty fdt is generated by efistub. #address-cells and #size-cells are not set in the empty fdt, so they default to 1 (4 byte wide). This can be an issue on 64-bit systems where values representing addresses, etc may be 8 bytes wide as the default value does not align with the general requirements for an empty DTB, and is fragile when passed to other agents as extra care is required to read the entire width of a value. This issue is observed on Qualcomm Technologies QDF24XX platforms when kexec-tools inserts 64-bit addresses into the "linux,elfcorehdr" and "linux,usable-memory-range" properties of the fdt. When the values are later consumed, they are truncated to 32-bit. Setting #address-cells and #size-cells to 2 at creation of the empty fdt resolves the observed issue, and makes the fdt less fragile. Signed-off-by: Sameer Goel Signed-off-by: Jeffrey Hugo --- drivers/firmware/efi/libstub/fdt.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) -- 2.11.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Reviewed-by: Ard Biesheuvel diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 260c4b4b492e..82973b86efe4 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -16,6 +16,22 @@ #include "efistub.h" +#define EFI_DT_ADDR_CELLS_DEFAULT 2 +#define EFI_DT_SIZE_CELLS_DEFAULT 2 + +static void fdt_update_cell_size(efi_system_table_t *sys_table, void *fdt) +{ + int offset; + + offset = fdt_path_offset(fdt, "/"); + /* Set the #address-cells and #size-cells values for an empty tree */ + + fdt_setprop_u32(fdt, offset, "#address-cells", + EFI_DT_ADDR_CELLS_DEFAULT); + + fdt_setprop_u32(fdt, offset, "#size-cells", EFI_DT_SIZE_CELLS_DEFAULT); +} + static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, unsigned long orig_fdt_size, void *fdt, int new_fdt_size, char *cmdline_ptr, @@ -42,10 +58,18 @@ static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, } } - if (orig_fdt) + if (orig_fdt) { status = fdt_open_into(orig_fdt, fdt, new_fdt_size); - else + } else { status = fdt_create_empty_tree(fdt, new_fdt_size); + if (status == 0) { + /* + * Any failure from the following function is non + * critical + */ + fdt_update_cell_size(sys_table, fdt); + } + } if (status != 0) goto fdt_set_fail;