From patchwork Tue Sep 7 14:56:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bert Vermeulen X-Patchwork-Id: 12478905 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,URIBL_BLOCKED, 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 09ED3C433F5 for ; Tue, 7 Sep 2021 14:59:30 +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 CA312610C8 for ; Tue, 7 Sep 2021 14:59:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CA312610C8 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=eKh08+ntxSg1gQ2kHH7uPkeh/IJikHU1AI/1NkgsleM=; b=klvGo0zcvEs6oC O1x4mXDNMGG2yX5aheuAGwMLvP3bZZhUoQQ8JEBAd8Xf+S+IKHkKXMAgFga+4zdn8v9f2FQTEvICc l6r4O4sCjdPh3Xams6F+VAcotDr85IRm/WH8QJEKvV/e9T1nJReKnPQvJ5BMiIOq4QepdWgb+tF95 XAquw3TXzhoLEz4YZCT6Was9/S1cDaDqSgPB2yXMq06Z1asYNc3yzIv8KV+qIHoZaxOEPobAI7Zqj a6EkYn+57LpaPAqdgcBOi9/d2Ow1SxMzAKrL31hMTbx0FULxd5BQbE4hrgQZeT1JVjt2J3s+tgbMS 1JYdb3oV0qMaM7aPeNVA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNcXh-003wfa-2K; Tue, 07 Sep 2021 14:57:45 +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 1mNcXX-003wb7-T5 for linux-arm-kernel@lists.infradead.org; Tue, 07 Sep 2021 14:57:39 +0000 Received: from debian-spamd by yawp.biot.com with sa-checked (Exim 4.93) (envelope-from ) id 1mNcXU-00CIrq-Ag for linux-arm-kernel@lists.infradead.org; Tue, 07 Sep 2021 16:57:32 +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 1mNcXG-00CIqp-E9; Tue, 07 Sep 2021 16:57:18 +0200 Received: from bert by sumner.biot.com with local (Exim 4.93) (envelope-from ) id 1mNcXF-000GVj-JY; Tue, 07 Sep 2021 16:57:17 +0200 From: Bert Vermeulen To: Russell King , Geert Uytterhoeven , Nicolas Pitre , Ard Biesheuvel , Bert Vermeulen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: John Crispin Subject: [PATCH v2] ARM: decompress: Use /memreserve/ DTS nodes when validating memory Date: Tue, 7 Sep 2021 16:56:50 +0200 Message-Id: <20210907145652.63362-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-20210907_075735_996992_C99D285C X-CRM114-Status: GOOD ( 14.31 ) 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: , 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 Reviewed-by: Geert Uytterhoeven Acked-by: Ard Biesheuvel --- 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..1d47de1e860b 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, 2); + size = get_val(fdt + offset + 8, 2); + + 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");