From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F363C433EF for ; Mon, 6 Sep 2021 10:00:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0795F6103C for ; Mon, 6 Sep 2021 10:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241494AbhIFKBu (ORCPT ); Mon, 6 Sep 2021 06:01:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231173AbhIFKBs (ORCPT ); Mon, 6 Sep 2021 06:01:48 -0400 Received: from yawp.biot.com (yawp.biot.com [IPv6:2a01:4f8:10a:8e::fce2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15BF4C061575 for ; Mon, 6 Sep 2021 03:00:43 -0700 (PDT) Received: from debian-spamd by yawp.biot.com with sa-checked (Exim 4.93) (envelope-from ) id 1mNBQf-00C7qA-AC for linux-kernel@vger.kernel.org; Mon, 06 Sep 2021 12:00:41 +0200 Received: from [2a02:578:460c:1:ae1f:6bff:fed1:9ca8] (helo=sumner.biot.com) by yawp.biot.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mNBQ3-00C7oT-15; Mon, 06 Sep 2021 12:00:03 +0200 Received: from bert by sumner.biot.com with local (Exim 4.93) (envelope-from ) id 1mNBQ2-00HYaC-AH; Mon, 06 Sep 2021 12:00:02 +0200 From: Bert Vermeulen To: Russell King , Geert Uytterhoeven , Ard Biesheuvel , Nicolas Pitre , Bert Vermeulen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: John Crispin Subject: [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory Date: Mon, 6 Sep 2021 11:59:28 +0200 Message-Id: <20210906095930.4184449-1-bert@biot.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the bootloader needs the start of memory to be preserved, for example because it dropped the Trusted Firmware blob there, this chunk of memory shouldn't be used by the kernel. To avoid adding yet another SoC-specific text offset to arch/arm/Makefile, this patch allows for a /memreserve/ entry in the DTS to mark off the memory chunk instead. Signed-off-by: Bert Vermeulen --- arch/arm/boot/compressed/fdt_check_mem_start.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c index 62450d824c3c..15a20c60155e 100644 --- a/arch/arm/boot/compressed/fdt_check_mem_start.c +++ b/arch/arm/boot/compressed/fdt_check_mem_start.c @@ -64,7 +64,7 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt) uint32_t addr_cells, size_cells, base; uint32_t fdt_mem_start = 0xffffffff; const fdt32_t *reg, *endp; - uint64_t size, end; + uint64_t rsvaddr, size, end; const char *type; int offset, len; @@ -74,6 +74,19 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt) if (fdt_magic(fdt) != FDT_MAGIC) return mem_start; + for (offset = fdt_off_mem_rsvmap(fdt); ; offset += 16) { + rsvaddr = get_val(fdt + offset, 8); + size = get_val(fdt + offset + 8, 8); + + if (!rsvaddr && !size) + break; + + end = rsvaddr + size; + if (mem_start >= rsvaddr && mem_start <= end) + /* Relocate past reserved block */ + mem_start = round_up(end, SZ_2M); + } + /* There may be multiple cells on LPAE platforms */ addr_cells = get_cells(fdt, "#address-cells"); size_cells = get_cells(fdt, "#size-cells"); -- 2.25.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1BEE5C433EF for ; Mon, 6 Sep 2021 10:02:31 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE49960E94 for ; Mon, 6 Sep 2021 10:02:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DE49960E94 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=biot.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=5q4EEWULLf8TgOkttkixqDWvjCIgeErJFlXZAVdO7aY=; b=go8m4REYXF58Ps PMnZX7lkf4v9vElGeVP/9s3FAXZ83PiZvhYTDZYNqy0vnBaelQN/PxNlues2VYt0WJdtIKMPhE2ZB 7iPwWg+oKpAseaGuFU2DKg+THcybfYy1oGlyauDiIZYYfXFtfFblvgWu80ROUROCZazwz8dibujc+ eTx1ZIuQn1H4dvOYAFlezmRx3/FuWVUcwT/38vPCtH4s/M0xCwfyQ0biC7gdlcTuqk5vX8JMcwS8S WSCTpWd9hU/jGOUGL5kGPgkr8wEfYOeJB7JRpYAeUq2fkyRhx0bYj0SBqm/IV8nJJOUcUnCJ1fyhL 16mz+Kj/+s4au2Usy8EA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNBQg-000Rt6-CN; Mon, 06 Sep 2021 10:00:42 +0000 Received: from yawp.biot.com ([2a01:4f8:10a:8e::fce2]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNBQd-000Rre-HE for linux-arm-kernel@lists.infradead.org; Mon, 06 Sep 2021 10:00:40 +0000 Received: from debian-spamd by yawp.biot.com with sa-checked (Exim 4.93) (envelope-from ) id 1mNBQY-00C7py-EG for linux-arm-kernel@lists.infradead.org; Mon, 06 Sep 2021 12:00:34 +0200 Received: from [2a02:578:460c:1:ae1f:6bff:fed1:9ca8] (helo=sumner.biot.com) by yawp.biot.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mNBQ3-00C7oT-15; Mon, 06 Sep 2021 12:00:03 +0200 Received: from bert by sumner.biot.com with local (Exim 4.93) (envelope-from ) id 1mNBQ2-00HYaC-AH; Mon, 06 Sep 2021 12:00:02 +0200 From: Bert Vermeulen To: Russell King , Geert Uytterhoeven , Ard Biesheuvel , Nicolas Pitre , Bert Vermeulen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: John Crispin Subject: [PATCH] ARM: decompress: Use /memreserve/ DTS nodes when validating memory Date: Mon, 6 Sep 2021 11:59:28 +0200 Message-Id: <20210906095930.4184449-1-bert@biot.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210906_030039_616512_C06EA925 X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the bootloader needs the start of memory to be preserved, for example because it dropped the Trusted Firmware blob there, this chunk of memory shouldn't be used by the kernel. To avoid adding yet another SoC-specific text offset to arch/arm/Makefile, this patch allows for a /memreserve/ entry in the DTS to mark off the memory chunk instead. Signed-off-by: Bert Vermeulen --- arch/arm/boot/compressed/fdt_check_mem_start.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm/boot/compressed/fdt_check_mem_start.c b/arch/arm/boot/compressed/fdt_check_mem_start.c index 62450d824c3c..15a20c60155e 100644 --- a/arch/arm/boot/compressed/fdt_check_mem_start.c +++ b/arch/arm/boot/compressed/fdt_check_mem_start.c @@ -64,7 +64,7 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt) uint32_t addr_cells, size_cells, base; uint32_t fdt_mem_start = 0xffffffff; const fdt32_t *reg, *endp; - uint64_t size, end; + uint64_t rsvaddr, size, end; const char *type; int offset, len; @@ -74,6 +74,19 @@ uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt) if (fdt_magic(fdt) != FDT_MAGIC) return mem_start; + for (offset = fdt_off_mem_rsvmap(fdt); ; offset += 16) { + rsvaddr = get_val(fdt + offset, 8); + size = get_val(fdt + offset + 8, 8); + + if (!rsvaddr && !size) + break; + + end = rsvaddr + size; + if (mem_start >= rsvaddr && mem_start <= end) + /* Relocate past reserved block */ + mem_start = round_up(end, SZ_2M); + } + /* There may be multiple cells on LPAE platforms */ addr_cells = get_cells(fdt, "#address-cells"); size_cells = get_cells(fdt, "#size-cells"); -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel