From patchwork Mon Apr 3 02:26:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 96590 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1685468qgd; Sun, 2 Apr 2017 19:23:30 -0700 (PDT) X-Received: by 10.99.159.1 with SMTP id g1mr15722645pge.88.1491186209928; Sun, 02 Apr 2017 19:23:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k10si12631212pfg.293.2017.04.02.19.23.29; Sun, 02 Apr 2017 19:23:29 -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 S1751517AbdDCCX3 (ORCPT + 2 others); Sun, 2 Apr 2017 22:23:29 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:32845 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751280AbdDCCX2 (ORCPT ); Sun, 2 Apr 2017 22:23:28 -0400 Received: by mail-pg0-f54.google.com with SMTP id x125so105509689pgb.0 for ; Sun, 02 Apr 2017 19:23:28 -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=FMNKndQ7k7FiKKitt/qH71+HuB+U1V4f2Vx2xIPStZQ=; b=RfTXldYlzbOHwi+UGMDzlpHbcyx/3/SUX6K2TBirt4FxJ3f8OuQjOxFDEt7/CN1nY/ GYbJG37LgOIrZkKx0092Wnr00FqmT+JUZboju/gm8C7Ntgz0oEzzw7bp8+wzUc6PJpRj pI3IV59ru0XKPaQjZ8qQjnaYyIQ6pGoy9F+JY= 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=FMNKndQ7k7FiKKitt/qH71+HuB+U1V4f2Vx2xIPStZQ=; b=P9eTYbbNOJqJFJiB/KjHSjDiahVAdj5LRX0QAmwb7hmlBvNGgfaE+C7f1Vfr8YCpNJ Dm+EgVRvGUYuF5DnwuwFcBd+bEdyR2sFbcZPKBsGkLFknpwJ++sF+V1SV6cCUqAl6ILV TtkoOjC11KIWwXgkMIMqEnqysgTFTY3Rli+Z1iW/tCfkxfnnH9r1eVK/3X4PEFxZ7mkm 7zQ7Gmda4BuCOes9vpQfT5ldkDp9Lr/Lj/Q6LKJkFlXmSchUa7yWh7emWC36pwEJIYff JUXK2AHt1sC/et35Qa0bLU+KzaGgez/p05Ky6T0zNvk0LiGlZ+QbQdFkzAk39zvJ7EnR WPWw== X-Gm-Message-State: AFeK/H20HSgYzneTMsb2aGM5PvobkUgrYVUYiKh1vQFa6TshZsN+H5GS++fjfNahk9K5kt1s X-Received: by 10.84.163.75 with SMTP id n11mr18311749plg.186.1491186208092; Sun, 02 Apr 2017 19:23:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v17sm22244780pgc.20.2017.04.02.19.23.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Apr 2017 19:23:27 -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, AKASHI Takahiro Subject: [PATCH v35 14/14] efi/libstub/arm*: Set default address and size cells values for an empty dtb Date: Mon, 3 Apr 2017 11:26:33 +0900 Message-Id: <20170403022633.12655-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170403022139.12383-1-takahiro.akashi@linaro.org> References: <20170403022139.12383-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 Signed-off-by: AKASHI Takahiro Reviewed-by: Ard Biesheuvel --- 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 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;