From patchwork Tue Feb 7 21:19:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffrey Hugo X-Patchwork-Id: 9561201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6855D60236 for ; Tue, 7 Feb 2017 21:20:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4716D2838C for ; Tue, 7 Feb 2017 21:20:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 376762848E; Tue, 7 Feb 2017 21:20:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CFEF728488 for ; Tue, 7 Feb 2017 21:20:05 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cbDBD-0002yD-F4; Tue, 07 Feb 2017 21:20:03 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cbDB9-0002bx-6W for linux-arm-kernel@lists.infradead.org; Tue, 07 Feb 2017 21:20:01 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 67274608C5; Tue, 7 Feb 2017 21:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486502378; bh=ZIKf9c9VlCo7dfe5SHxFRk4DL/0x31bbmmPYDzpVtHQ=; h=From:To:Cc:Subject:Date:From; b=L+ycfw+0s83UyKeqYsFyPJ0+cwHFqDE3JWE3BkjV1y4vSXKd7RQDfTDNvVOLn+kaz Phi9fe7cLZLPsxztOdJly7eKD43Cs6w42k+f7lr2IPwmnq0tCywANCFsInW+ofRxTC iTg4JPMss5u4kFhAiR4CBEDPopnh5H6Z8dzJ3kII= Received: from jhugo-perf-lnx.qualcomm.com (unknown [129.46.14.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jhugo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 1131360300; Tue, 7 Feb 2017 21:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1486502377; bh=ZIKf9c9VlCo7dfe5SHxFRk4DL/0x31bbmmPYDzpVtHQ=; h=From:To:Cc:Subject:Date:From; b=TI5xEHQ0Im6a2pZHLBwrf22RV6okI1Fjje2XxwZDczqI2sEk9WbZJr1YxrIo7B+QQ xr5/Huaxq9XR2PaqP/j21hUHkdqzyyaG7ZgOj7l7RWOtnVxi5+YNeGyx8flBJuHDSc gaeGwN4uPgC31Lpfb30A9YG0eHbbnC5YE/zb0gC4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 1131360300 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jhugo@codeaurora.org From: Jeffrey Hugo To: linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] efi/libstub/arm*: Set default address and size cells values for an empty dtb Date: Tue, 7 Feb 2017 14:19:20 -0700 Message-Id: <1486502360-18071-1-git-send-email-jhugo@codeaurora.org> X-Mailer: git-send-email 1.8.5.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170207_131959_326801_A30D6104 X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, ard.biesheuvel@linaro.org, Jeffrey Hugo , timur@codeaurora.org, takahiro.akashi@linaro.org, Sameer Goel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- [v2] -Add braces to an if when the corresponding else has braces -Remove print statements -Reword commit text -Removed gerrit tag drivers/firmware/efi/libstub/fdt.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index 921dfa0..22ea73b 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;